Skip to main content

eui_core/host/
mod.rs

1//! # The host API (VAPP-91)
2//!
3//! What a surface needs from its host, the same on all four platforms
4//! (`packages/exponential-ui/catalog/host.json`): the router turning server
5//! messages into ops, the wire decoders (JSONL, SSE, A2UI-over-MCP), the
6//! function / URL / media policy, binding sources, catalog negotiation and
7//! declarative app packages. A line-by-line port of the TypeScript reference
8//! (`packages/exponential-ui/src/host/`) over `serde_json::Value`; every
9//! output is JSON-equal to it, locked by `fixtures/host-*.json`. The I/O
10//! (transports, the runtime host) stays on each platform; the Swift and
11//! Kotlin painters reach this module through `exponential-ui-ffi`.
12
13pub mod actions;
14pub mod contract;
15pub mod decoders;
16pub mod exposes;
17pub mod expressions;
18pub mod package;
19pub mod policy;
20pub mod query;
21pub mod record_policy;
22pub mod record_store;
23pub mod records;
24pub mod router;
25pub mod signature;
26pub mod sources;
27pub mod tests;
28pub mod tools;
29
30pub use actions::{
31    action_call_name, action_var_types, apply_record_batch, apply_record_batch_as, function_effect, is_action_name, run_action, validate_package_actions, validate_package_effects, ActionContext, ACTION_CALL_PREFIX, ACTION_LIMIT_ACTIONS, ACTION_LIMIT_MAX_STEPS, ACTION_LIMIT_STEPS, ACTION_NAME_PATTERN,
32    ACTION_STEP_KINDS, RECORDS_BATCH_FUNCTION,
33};
34pub use contract::*;
35pub use expressions::{literal_type, record_row_type, records_value_type, schema_type, validate_package_expressions};
36pub use exposes::{expose_action_access, expose_issues, expose_name_destructive, expose_template_paths, validate_package_exposes, validate_upstreams, ExposeIssue};
37pub use decoders::{decode_jsonl, mcp_action_call, messages_from_mcp_result, DecodeIssue, Decoded, JsonlDecoder, SseDecoder};
38pub use package::{
39    available_extensions, client_capabilities, merge_data, package_sources, source_allowed, supported_catalog_ids, template_messages, validate_package, validate_package_with, version_satisfies, AvailableExtension, PackageIssue,
40    PACKAGE_FORMAT_VERSION,
41};
42pub use policy::{
43    combine_decisions, decide_function, decide_url, image_dimensions, image_frames, image_header, is_builtin_function, is_private_host, media_image_check, ImageHeader, matches_pattern, media_image_within_limits, media_request, media_within_limits, package_policy, svg_dimensions,
44    safe_href, FunctionDecision, FunctionPolicy, MediaOptions, MediaRequest, MediaRule, UrlDecision, UrlPolicy, BUILTIN_FUNCTIONS,
45};
46pub use router::{normalize_path, HostRouter, SurfaceInfo};
47pub use query::{
48    expand_query_source, fill_query_templates, month_days, month_label, parse_records_json, parse_records_query, parse_records_source, records_value, records_value_owned, shift_month, RecordRow, RecordRowRef, RecordsAggregate, RecordsAggregateOp, RecordsBefore, RecordsContext, RecordsDay, RecordsFilter, RecordsFilterOp, RecordsFilterValue, RecordsGroupKey, RecordsMonthView, RecordsOrder, RecordsQueryIssue, RecordsRunning, RecordsRunningOp,
49    RecordsQuery, RecordsSortKey, RECORDS_AGGREGATE_OPS, RECORDS_AGGREGATE_RESERVED, RECORDS_FILTER_OPS, RECORDS_MONTHS, RECORDS_OP_ALIASES, RECORDS_RUNNING_OPS, RECORDS_RESERVED_PARAMS, RECORDS_ROW_KEYS, RECORDS_SCHEME, RECORDS_WEEKDAYS,
50};
51pub use record_policy::{
52    readable_rows, record_allowed, record_author_of, record_policy, record_policy_copy, record_refusal, validate_record_policy, RecordOp, RecordPolicy, RecordViewer, APP_ACCESS_LEVELS, DEFAULT_RECORD_POLICY, RECORD_POLICY_LEVELS, RECORD_POLICY_OPS,
53};
54pub use record_store::RECORDS_FUNCTIONS;
55pub use records::{is_record_kind, validate_record, validate_record_schema, RECORD_FIELD_TYPES, RECORD_FORMATS, RECORD_RESERVED_KEYS};
56pub use signature::{canonical_json, package_file_signed_bytes, AUTHOR_KEY_PREFIX, AUTHOR_NAME_MAX, PACKAGE_FILE_SIGNATURE_ALG, PACKAGE_FILE_SIGNATURE_CONTEXT};
57pub use sources::{parse_source, source_with_params, ParsedSource};
58pub use tests::{
59    package_test_issues, run_package_tests, test_failure, test_matches, validate_package_tests, PackageTestResult, PACKAGE_TEST_DEFAULT_AS, PACKAGE_TEST_DEFAULT_NOW, PACKAGE_TEST_DEFAULT_ROLE, PACKAGE_TEST_ROLES, PACKAGE_TEST_KINDS, PACKAGE_TEST_LIMIT_GOT_MAX, PACKAGE_TEST_LIMIT_TESTS,
60};
61pub use tools::{tool_call, tool_consent, tool_consent_key, validate_tools, ToolCall, ToolConsentRow, TOOL_KINDS};
62
63/// JavaScript's WhiteSpace + LineTerminator (what `trim` drops, regex `\s`).
64pub(crate) fn is_js_space(c: char) -> bool {
65    matches!(c, '\u{9}' | '\u{a}' | '\u{b}' | '\u{c}' | '\u{d}' | ' ' | '\u{a0}' | '\u{1680}' | '\u{2000}'..='\u{200a}' | '\u{2028}' | '\u{2029}' | '\u{202f}' | '\u{205f}' | '\u{3000}' | '\u{feff}')
66}
67
68/// JavaScript's `String.prototype.trim` (WhiteSpace + LineTerminator).
69pub(crate) fn js_trim(s: &str) -> &str {
70    s.trim_matches(is_js_space)
71}
72
73/// JavaScript's default string order (`sort()`, `<`): by UTF-16 code units,
74/// which differs from Rust's byte order above U+FFFF.
75pub(crate) fn utf16_cmp(a: &str, b: &str) -> std::cmp::Ordering {
76    a.encode_utf16().cmp(b.encode_utf16())
77}
78
79/// JavaScript truthiness of a JSON value.
80pub(crate) fn js_truthy(value: &serde_json::Value) -> bool {
81    use serde_json::Value;
82    match value {
83        Value::Null => false,
84        Value::Bool(b) => *b,
85        Value::Number(n) => n.as_f64().is_some_and(|f| f != 0.0 && !f.is_nan()),
86        Value::String(s) => !s.is_empty(),
87        _ => true,
88    }
89}