diff --git a/.agents/skills/migrate-ts-decorator-sdk/SKILL.md b/.agents/skills/migrate-ts-decorator-sdk/SKILL.md index ab720f7684..144e10b700 100644 --- a/.agents/skills/migrate-ts-decorator-sdk/SKILL.md +++ b/.agents/skills/migrate-ts-decorator-sdk/SKILL.md @@ -39,7 +39,7 @@ import { BaseAgent, agent, prompt, description, endpoint, readonly, Config, Secr // NEW — import what you use import { z } from 'zod'; // or valibot / arktype -import { defineAgent, method, s, http, clientFor, Result } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, s, http, Result } from '@golemcloud/golem-ts-sdk'; ``` `Result` still exists (host `Result.ok` / `Result.err`). `Config` and `Secret` as **constructor parameter types** are gone — config is now a `config` record on `defineAgent` and secrets are `s.secret(...)` markers surfaced as `Secret` handles on `this.config`. @@ -195,8 +195,9 @@ removed decorator surface. **Current forms:** - **`readOnly` cache policies.** `@readonly({ cache: 'no-cache' | 'until-write' | { ttl } })` → `method({ readOnly: { cache: 'no-cache' | 'until-write' | { ttlNanos: }, usesPrincipal?: boolean } })`. Bare `readOnly: true` uses the `until-write` policy (the base default); principal-dependent caching → `usesPrincipal: true`. - **Config-on-RPC (`getWithConfig`).** `Agent.getWithConfig(id, overrides)` → - `clientFor(Def)(id, undefined, overrides)`. For a fresh phantom agent, use - `clientFor(Def).newPhantom(id, overrides)`. Non-secret override leaves are encoded and applied at + `Def.client.get(id, overrides)`. For an existing phantom agent, use + `Def.client.getPhantom(id, phantomId, overrides)`; for a fresh phantom agent, use + `Def.client.newPhantom(id, overrides)`. Non-secret override leaves are encoded and applied at call time; secret overrides are rejected because secrets remain host-provisioned. - **Cancelable / abortable RPC.** Pass `{ signal }` to an awaited client method, for example `await client.run(input, { signal })`. `client.run.schedule(at, input)` returns a diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4aff0efb7c..3f58021bc8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -817,6 +817,8 @@ jobs: build-golem-ts: runs-on: blacksmith + env: + NODE_OPTIONS: --max-old-space-size=4096 steps: - uses: actions/checkout@v5 with: diff --git a/.github/workflows/skill-harness.yaml b/.github/workflows/skill-harness.yaml index e9df91f6c7..34acd514a9 100644 --- a/.github/workflows/skill-harness.yaml +++ b/.github/workflows/skill-harness.yaml @@ -53,6 +53,8 @@ jobs: build-golem-ts: runs-on: blacksmith + env: + NODE_OPTIONS: --max-old-space-size=4096 steps: - uses: actions/checkout@v5 with: diff --git a/Cargo.lock b/Cargo.lock index 94dbaabb07..d01517a41c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3738,6 +3738,7 @@ dependencies = [ "golem-api-grpc", "golem-client", "golem-common", + "golem-schema", "heck", "http 1.5.0", "humanize-rs", @@ -4038,6 +4039,7 @@ dependencies = [ "futures", "golem-api-grpc", "golem-common", + "golem-schema", "golem-service-base", "heck", "http 1.5.0", @@ -4136,6 +4138,7 @@ dependencies = [ "chrono", "darling 0.20.11", "golem-common", + "golem-schema", "heck", "poem-openapi", "proc-macro-crate", @@ -4489,6 +4492,7 @@ dependencies = [ "futures", "golem-api-grpc", "golem-common", + "golem-schema", "golem-service-base", "golem-test-framework", "headers", diff --git a/cli/golem-cli/Cargo.toml b/cli/golem-cli/Cargo.toml index 15b3df915e..ddcce729e7 100644 --- a/cli/golem-cli/Cargo.toml +++ b/cli/golem-cli/Cargo.toml @@ -32,6 +32,7 @@ harness = false golem-api-grpc = { workspace = true } golem-client = { workspace = true } golem-common = { workspace = true, default-features = true } +golem-schema = { workspace = true } # External deps anyhow = { workspace = true } diff --git a/cli/golem-cli/src/command_handler/agent/invocation_session.rs b/cli/golem-cli/src/command_handler/agent/invocation_session.rs index a920e414ad..0e1bd339cb 100644 --- a/cli/golem-cli/src/command_handler/agent/invocation_session.rs +++ b/cli/golem-cli/src/command_handler/agent/invocation_session.rs @@ -2412,7 +2412,7 @@ fn schema_value_to_json( value: &SchemaValue, ) -> anyhow::Result { if !schema_value_contains_stream(value) { - return golem_common::schema::render::to_json_value(graph, ty, value).map_err(Into::into); + return golem_schema::schema::render::to_json_value(graph, ty, value).map_err(Into::into); } let ty = graph diff --git a/cli/golem-cli/src/model/component.rs b/cli/golem-cli/src/model/component.rs index 75234d398e..4052e0be4e 100644 --- a/cli/golem-cli/src/model/component.rs +++ b/cli/golem-cli/src/model/component.rs @@ -1195,7 +1195,7 @@ fn format_typed_config(config: &[TypedAgentConfigEntry]) -> String { .iter() .map(|entry| { let key = entry.path.join("."); - let value = golem_common::schema::render::to_json_value( + let value = golem_schema::schema::render::to_json_value( entry.value.graph(), entry.value.root_type(), entry.value.value(), diff --git a/cli/golem-cli/src/model/masking.rs b/cli/golem-cli/src/model/masking.rs index 9a6d87fe0b..98205b4697 100644 --- a/cli/golem-cli/src/model/masking.rs +++ b/cli/golem-cli/src/model/masking.rs @@ -266,7 +266,7 @@ mod tests { mask_typed_agent_config_entries(MaskingConfig::hide_secrets(), &entries, &secret_paths); assert_eq!( - golem_common::schema::render::to_json_value( + golem_schema::schema::render::to_json_value( masked[0].value.graph(), masked[0].value.root_type(), masked[0].value.value(), diff --git a/cli/golem-cli/templates/ts/common/AGENTS.md b/cli/golem-cli/templates/ts/common/AGENTS.md index 192849f87b..0dd6fe41e7 100644 --- a/cli/golem-cli/templates/ts/common/AGENTS.md +++ b/cli/golem-cli/templates/ts/common/AGENTS.md @@ -27,7 +27,9 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | +| `golem-agent-reflection` | Choosing reflection levels and identity lookup behavior | +| `golem-agent-reflection-ts` | Discovering and calling agents through runtime reflection | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -254,15 +256,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/cli/golem-cli/templates/ts/human-in-the-loop/component-dir/src/workflow-agent.ts b/cli/golem-cli/templates/ts/human-in-the-loop/component-dir/src/workflow-agent.ts index 41c886dec5..af977362ad 100644 --- a/cli/golem-cli/templates/ts/human-in-the-loop/component-dir/src/workflow-agent.ts +++ b/cli/golem-cli/templates/ts/human-in-the-loop/component-dir/src/workflow-agent.ts @@ -1,10 +1,7 @@ import { z } from 'zod'; -import { defineAgent, method, http, clientFor, createPromise, awaitPromise } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, http, createPromise, awaitPromise } from '@golemcloud/golem-ts-sdk'; import { HumanAgent, encodePromiseId } from './human-agent.js'; -// A typed RPC client factory for the remote HumanAgent (wasm-RPC under the hood). -const humanClient = clientFor(HumanAgent); - // The workflow side of the loop: it creates a promise, hands it to a human for // approval, then PAUSES until the promise is completed — the classic // human-in-the-loop pattern. Each workflow instance gets its own generated id. @@ -24,9 +21,9 @@ export const WorkflowAgentImpl = WorkflowAgent.implement({ // 1. Create a promise that represents waiting for human input. const approvalPromiseId = createPromise(); - // 2. Register the pending approval with the human (remote agent call). + // 2. Register the pending approval with the human over agent RPC. // Normally you would surface this in a UI, email, etc. - await humanClient({ username: approver }).requestApproval({ + await HumanAgent.client.get({ username: approver }).requestApproval({ workflowId: this.workflowId, promiseId: encodePromiseId(approvalPromiseId), }); diff --git a/cli/golem-cli/test-data/ts-code-first-snippets/main.ts b/cli/golem-cli/test-data/ts-code-first-snippets/main.ts index 73a523f907..415d72b9b7 100644 --- a/cli/golem-cli/test-data/ts-code-first-snippets/main.ts +++ b/cli/golem-cli/test-data/ts-code-first-snippets/main.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { defineAgent, method, s, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, s } from '@golemcloud/golem-ts-sdk'; import { ObjectType, @@ -327,9 +327,6 @@ export const BarAgentImpl = BarAgent.implement({ }, }); -// A typed RPC client factory for the remote BarAgent (mirrors `Client`). -const barAgentClient = clientFor(BarAgent); - // --------------------------------------------------------------------------- // FooAgent — forwards every call to its BarAgent client and returns the result. // --------------------------------------------------------------------------- @@ -346,11 +343,11 @@ export const FooAgent = defineAgent({ }); export const FooAgentImpl = FooAgent.implement({ - // Build the phantom BarAgent client mirroring the old `BarAgent.get("foooo", 1)` + // Build the typed RPC client for BarAgent, mirroring `BarAgent.get("foooo", 1)` // (constructor params optionalStringType = "foooo", optionalUnionType = 1). init: ({ id }) => ({ input: id.input, - barAgent: barAgentClient({ optionalStringType: 'foooo', optionalUnionType: 1 }), + barAgent: BarAgent.client.get({ optionalStringType: 'foooo', optionalUnionType: 1 }), }), methods: { funAll(input) { diff --git a/cli/golem-cli/test-data/ts-code-first-snippets/naming_extremes.ts b/cli/golem-cli/test-data/ts-code-first-snippets/naming_extremes.ts index e9375bd26a..399bdd42d7 100644 --- a/cli/golem-cli/test-data/ts-code-first-snippets/naming_extremes.ts +++ b/cli/golem-cli/test-data/ts-code-first-snippets/naming_extremes.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const StringAgent = defineAgent({ name: 'StringAgent', @@ -33,18 +33,15 @@ export const StructAgentImpl = StructAgent.implement({ }, }); -const stringClient = clientFor(StringAgent); -const structClient = clientFor(StructAgent); - async function runStringTest(): Promise { for (let i = 445; i < 450; i++) { - await stringClient({ name: ' '.repeat(i) }).test(); + await StringAgent.client.get({ name: ' '.repeat(i) }).test(); } } async function runStructTest(): Promise { for (let i = 100; i < 105; i++) { - await structClient({ + await StructAgent.client.get({ args: { x: ' '.repeat(i), y: ' '.repeat(i), z: '/'.repeat(i) }, }).test(); } diff --git a/cli/golem-cli/tests/app/agents.rs b/cli/golem-cli/tests/app/agents.rs index 03ae6b426a..405f48534d 100644 --- a/cli/golem-cli/tests/app/agents.rs +++ b/cli/golem-cli/tests/app/agents.rs @@ -3463,7 +3463,7 @@ async fn test_long_agent_id_rejected_in_invoke_repl_and_rpc() { &component_source_code_main_file, indoc! { r#" import { z } from 'zod'; - import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; + import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const TargetAgent = defineAgent({ name: 'TargetAgent', @@ -3482,8 +3482,6 @@ async fn test_long_agent_id_rejected_in_invoke_repl_and_rpc() { }, }); - const targetClient = clientFor(TargetAgent); - export const CallerAgent = defineAgent({ name: 'CallerAgent', id: { id: z.string() }, @@ -3496,7 +3494,7 @@ async fn test_long_agent_id_rejected_in_invoke_repl_and_rpc() { init: ({ id }) => ({ id: id.id }), methods: { async callTarget({ targetId }) { - return await targetClient({ id: targetId }).ping(); + return await TargetAgent.client.get({ id: targetId }).ping(); }, }, }); diff --git a/cli/golem-cli/wit/deps/golem-agent/host.wit b/cli/golem-cli/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/cli/golem-cli/wit/deps/golem-agent/host.wit +++ b/cli/golem-cli/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/docs/src/content/next/develop/rpc.mdx b/docs/src/content/next/develop/rpc.mdx index fd2bd08b89..2099c1b500 100644 --- a/docs/src/content/next/develop/rpc.mdx +++ b/docs/src/content/next/develop/rpc.mdx @@ -20,7 +20,7 @@ In the following example, we have two agents defined; a weather agent with a con ```typescript import { z } from 'zod'; - import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; + import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const WeatherAgent = defineAgent({ name: 'WeatherAgent', @@ -56,7 +56,7 @@ In the following example, we have two agents defined; a weather agent with a con init: () => ({}), methods: { async run() { - const weatherInLondon = clientFor(WeatherAgent)({ location: "London" }); + const weatherInLondon = WeatherAgent.client.get({ location: "London" }); // ... return ""; }, @@ -64,7 +64,7 @@ In the following example, we have two agents defined; a weather agent with a con }); ``` - Here `weatherInLondon` is the client for calling a remote `WeatherAgent`, obtained with `clientFor(WeatherAgent)` and the target agent's id record - it exposes the agent methods, such as `currentWeather` as its own methods. + Here `weatherInLondon` is the client for calling a remote `WeatherAgent`, obtained from `WeatherAgent.client` with the target agent's id record - it exposes the agent methods, such as `currentWeather` as its own methods. @@ -219,7 +219,7 @@ Phantom agents are created through Agent-to-Agent communication or [forking](for ```typescript - const { client: phantomAgent, phantomId } = clientFor(WeatherAgent).newPhantom({ location: "London" }); + const { client: phantomAgent, agentId, phantomId } = WeatherAgent.client.newPhantom({ location: "London" }); ``` @@ -244,8 +244,8 @@ If we know the **phantom ID** of an agent, we can create a client targeting an e ```typescript - const { client: phantomAgent, phantomId } = clientFor(WeatherAgent).newPhantom({ location: "London" }); - const samePhantomAgent = clientFor(WeatherAgent)({ location: "London" }, phantomId); + const { client: phantomAgent, agentId, phantomId } = WeatherAgent.client.newPhantom({ location: "London" }); + const samePhantomAgent = WeatherAgent.client.getPhantom({ location: "London" }, phantomId); ``` @@ -270,6 +270,52 @@ If we know the **phantom ID** of an agent, we can create a client targeting an e +### Phantom agents through TypeScript reflection + +When the target type is selected at runtime, its reflected `client` exposes the +same phantom operations as a definition client: + +```typescript +import { getReflectedAgentType } from "@golemcloud/golem-ts-sdk"; + +const weatherType = getReflectedAgentType("WeatherAgent"); +if (!weatherType) throw new Error("WeatherAgent is not registered"); + +if (weatherType.mode === "durable") { + const { client, agentId, phantomId } = weatherType.client.newPhantom({ + location: "London", + }); + const samePhantom = weatherType.client.getPhantom( + { location: "London" }, + phantomId, + ); +} +``` + +For an ephemeral reflected type, `newPhantom` returns the reflected client +directly rather than a reusable `{ client, agentId, phantomId }` wrapper. The +final one-shot agent ID and idempotency key are returned by each invocation: + +```typescript +const requestType = getReflectedAgentType("RequestAgent"); +if (!requestType || requestType.mode !== "ephemeral") { + throw new Error("RequestAgent must be ephemeral"); +} + +const request = requestType.client.newPhantom({ route: "summarize" }); +if ("client" in request) throw new Error("unexpected durable phantom wrapper"); + +const result = await request.method("run").invoke({ text: "hello" }); +console.log(result.metadata.agentId, result.metadata.idempotencyKey); +``` + +Ephemeral reflected types also expose `getPhantom` when the caller already has +the phantom ID. That explicit handle does not make a final, already-invoked +ephemeral agent ID reusable. + +See [Calling Agents with Runtime Reflection](/next/how-to-guides/ts/golem-agent-reflection-ts) +for discovery, schema inspection, concrete `AgentId` binding, and error handling. + ## Calling a remote agent method Once we have a _client_ for a remote agent, it is possible to call its methods just as if it would be a local instance. @@ -308,7 +354,7 @@ It is possible to trigger the remote execution of an agent method without awaiti To trigger an agent method and return immediately, use the `trigger` method exposed on each remote method in the client: ```typescript - const remoteAgent = clientFor(BackgroundTaskAgent)({ jobId: backgroundJobId }); + const remoteAgent = BackgroundTaskAgent.client.get({ jobId: backgroundJobId }); remoteAgent.runTask.trigger({ message: "hello", count: 1234 }); ``` @@ -351,7 +397,7 @@ An advanced case of triggering the execution of an agent method is to **schedule Similar to `.trigger`, there is a `.schedule` method as well on each remote agent method in the client: ```typescript - const remoteAgent = clientFor(BackgroundTaskAgent)({ jobId: backgroundJobId }); + const remoteAgent = BackgroundTaskAgent.client.get({ jobId: backgroundJobId }); remoteAgent.runTask.schedule({ seconds: 60n, nanoseconds: 0 }, { message: "hello", count: 1234 }); ``` diff --git a/docs/src/content/next/how-to-guides.mdx b/docs/src/content/next/how-to-guides.mdx index a977ec50b0..ee3409141c 100644 --- a/docs/src/content/next/how-to-guides.mdx +++ b/docs/src/content/next/how-to-guides.mdx @@ -5,9 +5,9 @@ import { Cards } from "nextra/components" Practical, step-by-step guides for building with Golem. Each guide covers a specific task with code examples and best practices. - + - + diff --git a/docs/src/content/next/how-to-guides/common.mdx b/docs/src/content/next/how-to-guides/common.mdx index 95071fd663..47739a9e61 100644 --- a/docs/src/content/next/how-to-guides/common.mdx +++ b/docs/src/content/next/how-to-guides/common.mdx @@ -7,6 +7,7 @@ Language-agnostic guides covering the Golem CLI, project setup, deployment, and + diff --git a/docs/src/content/next/how-to-guides/common/_meta.js b/docs/src/content/next/how-to-guides/common/_meta.js index 3b147c75a1..fd957cb005 100644 --- a/docs/src/content/next/how-to-guides/common/_meta.js +++ b/docs/src/content/next/how-to-guides/common/_meta.js @@ -1,6 +1,7 @@ export default { "golem-add-component": "Adding Components and Agent Templates to an Existing Golem Application", "golem-add-initial-files": "Adding Initial Files to Golem Agent Filesystems", + "golem-agent-reflection": "Agent Reflection", "golem-build": "Building a Golem Application with `golem build`", "golem-cancel-queued-invocation": "Canceling a Queued Invocation", "golem-configure-api-domain": "Configuring HTTP API Domain Deployments", diff --git a/docs/src/content/next/how-to-guides/common/golem-agent-reflection.mdx b/docs/src/content/next/how-to-guides/common/golem-agent-reflection.mdx new file mode 100644 index 0000000000..d48f6941dd --- /dev/null +++ b/docs/src/content/next/how-to-guides/common/golem-agent-reflection.mdx @@ -0,0 +1,16 @@ +# Agent Reflection + +Use the narrowest client surface that matches what the caller knows: + +- Use a generated or definition-owned client when the target type and methods are known in source. +- Use a caller-owned contract when the target implementation is not imported but its identity and method schemas are known. +- Use runtime reflection when the type or method is selected dynamically and the caller needs registered constructor, input, or output schemas. +- Use a schema-free dynamic client only when infrastructure deliberately works with schema-native values and arbitrary method names. + +Agent identity strings are environment-scoped. Reflection identities do not include a component ID: the runtime resolves the agent type's implementing component within the caller's environment. Component-bearing IDs belong to lower-level host-management APIs, not reflection clients. + +Discovery lookups are optional: a name or identity lookup returns no type when the deployment is missing, the identity is malformed, or the caller cannot view it. Parsing an identity is strict and reports malformed input. Identity discovery never creates the target agent. + +Reflected schema graphs are immutable snapshots of the deployed contract. Validate or pack JSON through the reflected constructor or method schema, and treat a missing or malformed declared output as a remote output error. + +Load the language-specific reflection skill for concrete SDK APIs and examples. diff --git a/docs/src/content/next/how-to-guides/ts.mdx b/docs/src/content/next/how-to-guides/ts.mdx index f0d57071d1..fc01f48fc7 100644 --- a/docs/src/content/next/how-to-guides/ts.mdx +++ b/docs/src/content/next/how-to-guides/ts.mdx @@ -15,6 +15,7 @@ Guides specific to developing Golem agents in TypeScript. + diff --git a/docs/src/content/next/how-to-guides/ts/_meta.js b/docs/src/content/next/how-to-guides/ts/_meta.js index 61f4df3e26..f434dbb9e8 100644 --- a/docs/src/content/next/how-to-guides/ts/_meta.js +++ b/docs/src/content/next/how-to-guides/ts/_meta.js @@ -9,6 +9,7 @@ export default { "golem-annotate-agent-ts": "Annotating Agents and Methods (TypeScript)", "golem-atomic-block-ts": "Atomic Blocks and Durability Controls (TypeScript)", "golem-call-from-external-ts": "Calling Agents from External TypeScript Applications", + "golem-agent-reflection-ts": "Calling Agents with Runtime Reflection (TypeScript)", "golem-call-another-agent-ts": "Calling Another Agent (TypeScript)", "golem-configure-durability-ts": "Configuring Agent Durability (TypeScript)", "golem-add-cors-ts": "Configuring CORS for TypeScript HTTP Endpoints", diff --git a/docs/src/content/next/how-to-guides/ts/golem-add-config-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-add-config-ts.mdx index 116a2213d3..c654eca8f7 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-add-config-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-add-config-ts.mdx @@ -91,5 +91,5 @@ Values set closer to the agent override those set at broader scopes. - Only object/record schemas are recursed into nested fields; unions, arrays, tuples, maps, and primitives are read whole - Optional fields use the schema's own optionality (e.g. `z.number().optional()`) - Config keys in `golem.yaml` use camelCase matching the field names -- Config values are provisioned per environment (via `golem.yaml` / CLI); a caller may ALSO override non-secret config for a remote agent at call time via `clientFor(Def)(id, phantomId?, overrides)` (config-on-RPC — secret overrides are rejected) +- Config values are provisioned per environment (via `golem.yaml` / CLI); a caller may ALSO override non-secret config for a remote agent at call time via `Def.client.get(id, overrides)` or `Def.client.getPhantom(id, phantomId, overrides)` (config-on-RPC — secret overrides are rejected) - If the config includes secret fields, mark them with `s.secret(...)` and see [`golem-add-secret-ts`](/next/how-to-guides/ts/golem-add-secret-ts) for secret-specific declaration and CLI guidance diff --git a/docs/src/content/next/how-to-guides/ts/golem-agent-reflection-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-agent-reflection-ts.mdx new file mode 100644 index 0000000000..c3694393f3 --- /dev/null +++ b/docs/src/content/next/how-to-guides/ts/golem-agent-reflection-ts.mdx @@ -0,0 +1,187 @@ +# Calling Agents with Runtime Reflection (TypeScript) + +Use reflection when the target agent type or method is chosen at runtime. When +the target is known while writing the component, prefer its definition client +(`Target.client`) because it provides compile-time input and output types. + +## Discover Agent Types + +The reflection API exposes the agent types registered for the running +component revision: + +```typescript +import { + getAllAgentTypes, + getReflectedAgentType, +} from '@golemcloud/golem-ts-sdk'; + +const available = getAllAgentTypes(); +const counterType = getReflectedAgentType('CounterAgent'); + +if (!counterType) { + throw new Error('CounterAgent is not registered'); +} + +console.log(counterType.name, counterType.mode, counterType.sourceLanguage); +console.log(counterType.methods.map((method) => method.name)); +``` + +An `AgentType` contains its constructor schema, method schemas, descriptions, +implementation identity, and lifecycle mode. Use `method(name)` when selecting +a method dynamically; it returns `undefined` for an unknown method. + +## Inspect and Validate Schemas + +Constructor and method schemas are exposed as `SchemaRef` values. They accept +canonical JSON, report structured validation issues, and can render JSON +Schema: + +```typescript +const method = counterType.method('add'); +if (!method) throw new Error('CounterAgent.add is not registered'); + +const validation = method.input.validateJson({ by: 5 }); +if (!validation.success) { + throw new Error(JSON.stringify(validation.issues)); +} + +const jsonSchema = method.input.toJsonSchema(); +``` + +Use `packJson` and `unpackJson` only when integrating with APIs that explicitly +exchange schema-native values. Normal reflected calls accept and return JSON. + +## Invoke a Durable Agent + +Use the reflected type's client factory just like a typed definition factory, +then select the method by name: + +```typescript +const counter = counterType.client.get({ name: 'main' }); +const invocation = await counter.method('add').invoke({ by: 5 }); + +console.log(invocation.value); +console.log(invocation.metadata.agentId); +console.log(invocation.metadata.idempotencyKey); +``` + +`invoke` and `invokeJson` return `{ value, metadata }`. `trigger` and `schedule` +also return identity metadata. Client creation and invocation failures are +reported as structured `RemoteCallError` values; use `isRemoteCallError` to +inspect their `cause` without parsing messages. + +## Construct an Agent ID with Caller-Owned Schemas + +A complete caller-owned contract is the Level 2 option when the target name, +constructor shape, and methods are known locally but the target implementation +is not imported. Its `agentId` helper accepts values described by any supported +Standard Schema library: + +```typescript +import { z } from 'zod'; +import { + ParsedAgentId, + defineAgentClient, + method, +} from '@golemcloud/golem-ts-sdk'; +import { v } from '@golemcloud/golem-ts-sdk/schema'; + +const CounterContract = defineAgentClient({ + name: 'CounterAgent', + id: { name: z.string() }, + methods: { + echo: method({ input: { message: z.string() }, returns: z.string() }), + }, +}); + +const schemaLibraryId = CounterContract.agentId({ name: 'main' }); +const first = await schemaLibraryId + .client(CounterContract) + .echo({ message: 'from Zod' }); + +const constructorValue = v.record([v.string('main')]); +const schemaValueId = ParsedAgentId.create({ + typeName: CounterContract.name, + constructorValue, +}); +const second = await schemaValueId + .client(CounterContract) + .echo({ message: 'from SchemaValue' }); +``` + +The first form validates and packs constructor fields through the caller's +schema library. The explicit `ParsedAgentId.create` form is for infrastructure that +already owns a Golem `SchemaValue`; record fields must be in the target +constructor's declared order. It does not validate that value against the +remote constructor schema. When runtime metadata is available, prefer +`agentType.agentId(json)` or pack with `agentType.constructorInput` before +calling `agentType.agentIdValue(value)`. + +## Bind a Concrete Agent ID + +After an agent exists, resolve the schema registered for that concrete identity +and bind it fluently: + +```typescript +import { + getAgentTypeByAgentId, + ParsedAgentId, +} from '@golemcloud/golem-ts-sdk'; + +function bindExisting(agentId: ParsedAgentId) { + const reflected = getAgentTypeByAgentId(agentId); + if (!reflected) throw new Error('Agent or registered type was not found'); + return agentId.client(reflected); +} +``` + +Lookup by `ParsedAgentId` does not create the agent. It returns `undefined` when the +identity does not exist, its type cannot be resolved, or the caller cannot view +it. `agentId.parts()` is the strict local operation when malformed identity text +must be reported instead of treated as a discovery miss. Use +`agentId.dynamicClient()` only for lifecycle-free infrastructure that already +holds schema-native values and intentionally invokes arbitrary method names +without discovery. + +## Phantom and Ephemeral Agents + +Reflected durable types expose the same three constructors as definition +clients: + +```typescript +const known = counterType.client.getPhantom({ name: 'main' }, savedPhantomId); +const { client, agentId, phantomId } = counterType.client.newPhantom({ name: 'main' }); +``` + +For an ephemeral reflected type, `get` is unavailable. `newPhantom` returns the +logical reflected client directly, and each invocation returns its allocated +one-shot identity in metadata: + +```typescript +const requestType = getReflectedAgentType('RequestAgent'); +if (!requestType || requestType.mode !== 'ephemeral') { + throw new Error('RequestAgent must be ephemeral'); +} + +const request = requestType.client.newPhantom({ route: 'summarize' }); +if ('client' in request) throw new Error('unexpected durable phantom wrapper'); + +const result = await request.method('run').invoke({ text: 'hello' }); +console.log(result.metadata.agentId, result.metadata.idempotencyKey); +``` + +`getPhantom` is also available when the caller already holds the phantom ID. +It does not make a final, already-invoked ephemeral agent ID reusable. + +Do not treat an ephemeral proxy as having a reusable final `ParsedAgentId`. A final +ephemeral identity cannot accept another invocation or be resumed. + +## Choosing the Client Surface + +| Situation | Use | +|---|---| +| Target definition and method known in source | `Target.client` | +| Type or method selected at runtime | `getReflectedAgentType` / `getAllAgentTypes` | +| Existing concrete identity needs its current schema | `getAgentTypeByAgentId` | +| Existing identity plus a caller-owned typed contract | `agentId.client(contract)` | +| Lifecycle-free invocation with schema-native values | `agentId.dynamicClient()` | diff --git a/docs/src/content/next/how-to-guides/ts/golem-call-another-agent-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-call-another-agent-ts.mdx index 95926a1ab4..73586b7baa 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-call-another-agent-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-call-another-agent-ts.mdx @@ -1,23 +1,19 @@ # Calling Another Agent (TypeScript) -There are two typed RPC APIs. Use `clientFor` when both agents are defined in the +There are two typed RPC APIs. Use a definition's `.client` when both agents are defined in the same component. Use a generated guest client when the target is in another component (including a component written in another language). -## Same Component: `clientFor` +## Same Component: Definition Client -Pass the agent's **definition** (the value returned by `defineAgent`) to -`clientFor`, then call the returned factory with the target agent's **id record**: +Use the `.client` attached to the agent's **definition** (the value returned by +`defineAgent`), then call `.get` with the target agent's **id record**: ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -// Build the factory once (module scope is fine — it caches the codecs). -const counterClient = clientFor(Counter); - // Get a handle to a specific instance by its id record. -const c1 = counterClient({ name: 'my-counter' }); +const c1 = Counter.client.get({ name: 'my-counter' }); ``` The id argument is the record declared in the target agent's `id: { … }` (for a @@ -39,10 +35,10 @@ call throws a `RemoteCallError`. ## Phantom Agents -`clientFor(Def)` accepts an optional second `phantomId` argument to address a -specific phantom instance that shares the same id record. To create a fresh -phantom, call `clientFor(Def).newPhantom(id)`; the returned details contain the -typed client and generated `phantomId`, which can be saved and reused. See the +Call `Def.client.getPhantom(id, phantomId)` to address a specific phantom +instance that shares the same id record. To create a fresh phantom, call +`Def.client.newPhantom(id)`; the returned details contain the typed client, full +`agentId`, and generated `phantomId`, which can be saved and reused. See the [`golem-multi-instance-agent-ts`](/next/how-to-guides/ts/golem-multi-instance-agent-ts) guide. ## Different Component: Generated Guest Client diff --git a/docs/src/content/next/how-to-guides/ts/golem-fire-and-forget-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-fire-and-forget-ts.mdx index 973bd9e2ca..b4f274a537 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-fire-and-forget-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-fire-and-forget-ts.mdx @@ -8,20 +8,19 @@ the invocation asynchronously. ## Usage -Every method on a `clientFor(...)` RPC client has a `.trigger()` variant. It takes +Every method on a definition RPC client has a `.trigger()` variant. It takes the same input record as the awaited call but returns `void` immediately: ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter)({ name: 'my-counter' }); +const counter = Counter.client.get({ name: 'my-counter' }); // Fire-and-forget — returns immediately counter.increment.trigger(); // input: {} // With arguments -const processor = clientFor(DataProcessor)({ name: 'pipeline-1' }); +const processor = DataProcessor.client.get({ name: 'pipeline-1' }); processor.processBatch.trigger({ batch: batchData }); ``` @@ -35,7 +34,7 @@ CounterAgent.get('my-counter').increment.trigger(); ``` See the [`golem-call-another-agent-ts`](/next/how-to-guides/ts/golem-call-another-agent-ts) skill for the required `golem.yaml` and -`tsconfig.json` setup. Do not replace `clientFor` for same-component calls. +`tsconfig.json` setup. Use the definition's `.client` for same-component calls. ## When to Use @@ -47,16 +46,15 @@ See the [`golem-call-another-agent-ts`](/next/how-to-guides/ts/golem-call-anothe ## Example: Breaking a Deadlock ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { AgentA } from './agent-a.js'; import { AgentB } from './agent-b.js'; // In AgentA — calls AgentB and waits -const b = clientFor(AgentB)({ name: 'b1' }); +const b = AgentB.client.get({ name: 'b1' }); const result = await b.doWork({ data }); // OK: awaited call // In AgentB — notifies AgentA without waiting (would deadlock if awaited) -const a = clientFor(AgentA)({ name: 'a1' }); +const a = AgentA.client.get({ name: 'a1' }); a.onWorkDone.trigger({ result }); // OK: fire-and-forget ``` diff --git a/docs/src/content/next/how-to-guides/ts/golem-multi-instance-agent-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-multi-instance-agent-ts.mdx index 366ae07c2b..618145efe0 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-multi-instance-agent-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-multi-instance-agent-ts.mdx @@ -18,21 +18,20 @@ agent-type(param1, param2) ## Creating and Addressing Phantom Agents (RPC) -You address another agent with a typed RPC client built from its `defineAgent` definition via `clientFor(Def)`. The returned factory takes the id record and an **optional phantom UUID**: +You address another agent through the typed `client` namespace attached to its `defineAgent` definition: ```typescript -clientFor(Def)(id) // non-phantom: same agent for the same id -clientFor(Def)(id, phantomUuid) // phantom: addressed by id + a specific UUID -clientFor(Def)(id, phantomUuid, config) // + per-call non-secret config overrides (config-on-RPC) -clientFor(Def).newPhantom(id, config?) // new phantom with a generated UUID +Def.client.get(id, config?) // non-phantom +Def.client.getPhantom(id, phantomUuid, config?) // known phantom +Def.client.newPhantom(id, config?) // new phantom with generated identity ``` | Call | Description | |--------|-------------| -| `client(id)` | Get or create a **non-phantom** agent identified solely by its id record | -| `client.newPhantom(id)` | Create a **new phantom** agent and return `{ client, phantomId }` | -| `client(id, savedUuid)` | Get or create a phantom agent with a **specific** UUID | -| `client(id, undefined, { foo })` | Override the target's non-secret config for this call (secrets stay host-provisioned) | +| `Def.client.get(id)` | Get or create a **non-phantom** agent identified solely by its id record | +| `Def.client.newPhantom(id)` | Create a **new phantom** agent and return `{ client, agentId, phantomId }` | +| `Def.client.getPhantom(id, savedUuid)` | Get or create a phantom agent with a **specific** UUID | +| `Def.client.get(id, { foo })` | Override the target's non-secret config for this call (secrets stay host-provisioned) | Each method on the client has, besides the awaited call: `.trigger(input)` (fire-and-forget) and `.schedule(at, input) → CancellationToken`. Cancel an awaited invocation with the normal call shape's trailing `{ signal }` option: `method(input, { signal })`, or `method({ signal })` for a method with no input. @@ -40,7 +39,7 @@ Each method on the client has, besides the awaited call: `.trigger(input)` (fire ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor, Uuid } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, Uuid } from '@golemcloud/golem-ts-sdk'; export const Counter = defineAgent({ name: 'Counter', @@ -58,25 +57,22 @@ Counter.implement({ }, }); -// --- In another agent, using the RPC client factory: --- -const counters = clientFor(Counter); - // Non-phantom: always the same agent for the same name -const shared = counters({ name: 'shared' }); +const shared = Counter.client.get({ name: 'shared' }); await shared.increment(); -// New phantom: the factory returns the client and its generated UUID. -const { client: phantom1, phantomId: phantomId1 } = counters.newPhantom({ +// New phantom: the call returns the client and its generated UUID. +const { client: phantom1, phantomId: phantomId1 } = Counter.client.newPhantom({ name: 'shared', }); -const { client: phantom2 } = counters.newPhantom({ name: 'shared' }); +const { client: phantom2 } = Counter.client.newPhantom({ name: 'shared' }); // phantom1 and phantom2 are different agents, both with name="shared" // Reconnect to an existing phantom by its UUID. -const samePhantom = counters({ name: 'shared' }, phantomId1); +const samePhantom = Counter.client.getPhantom({ name: 'shared' }, phantomId1); // A persisted UUID string can be restored later. -const restoredPhantom = counters( +const restoredPhantom = Counter.client.getPhantom( { name: 'shared' }, Uuid.parse(savedUuidString), ); @@ -87,7 +83,7 @@ Persist the phantom UUID yourself (as a string via `uuid.toString()`, reparsed w ### Phantoms in Another Component A generated durable guest client uses static `get`, `getPhantom`, and -`newPhantom` methods, with flattened id parameters rather than the `clientFor` +`newPhantom` methods, with flattened id parameters rather than the definition-client id record. For example: ```typescript @@ -99,8 +95,8 @@ const freshPhantom = CounterAgent.newPhantom('shared'); When the target declares local config, the generated client also provides `getWithConfig`, `getPhantomWithConfig`, and `newPhantomWithConfig`. See the [`golem-call-another-agent-ts`](/next/how-to-guides/ts/golem-call-another-agent-ts) skill for cross-component manifest, TypeScript -source-path, and import setup. The `clientFor` forms above remain correct within -the component that defines the agent. +source-path, and import setup. The definition-client forms above are for calls +within the component that defines the agent. ## Querying the Phantom ID from Inside an Agent diff --git a/docs/src/content/next/how-to-guides/ts/golem-parallel-workers-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-parallel-workers-ts.mdx index 805c8ed78a..415e9aa3ea 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-parallel-workers-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-parallel-workers-ts.mdx @@ -4,7 +4,7 @@ Golem agents process invocations **sequentially** — a single agent cannot run work in parallel. To execute work concurrently, distribute it across **multiple agent instances**. This skill covers two approaches: -1. **Child agents via `clientFor(AgentDef)(id)`** — spawn separate agent instances, dispatch work, and collect results +1. **Child agents via `AgentDef.client.get(id)`** — spawn separate agent instances, dispatch work, and collect results 2. **`fork()`** — clone the current agent at the current execution point for lightweight parallel execution ## Approach 1: Child Agent Fan-Out @@ -15,7 +15,7 @@ Spawn child agents, call them concurrently with `Promise.all`, and aggregate res ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const Worker = defineAgent({ name: 'Worker', @@ -34,9 +34,6 @@ export const WorkerImpl = Worker.implement({ }, }); -// A typed RPC client factory for the remote Worker (built once, caches codecs). -const workerClient = clientFor(Worker); - export const Coordinator = defineAgent({ name: 'Coordinator', id: { name: z.string() }, @@ -50,7 +47,7 @@ export const CoordinatorImpl = Coordinator.implement({ methods: { async fanOut({ items }) { // Spawn one child per item and call concurrently. - const promises = items.map((item, i) => workerClient({ id: i }).process({ data: item })); + const promises = items.map((item, i) => Worker.client.get({ id: i }).process({ data: item })); // Wait for all children to finish. return await Promise.all(promises); }, @@ -68,7 +65,7 @@ async fanOutChunked({ ids }) { const results: number[] = []; for (const chunk of chunks) { - const promises = chunk.map((id) => workerClient({ id }).compute({ n: id })); + const promises = chunk.map((id) => Worker.client.get({ id }).compute({ n: id })); results.push(...await Promise.all(promises)); } return results; @@ -92,7 +89,7 @@ agent boundary as a bigint-aware JSON string: ```typescript import { z } from 'zod'; import { - defineAgent, method, clientFor, + defineAgent, method, createPromise, awaitPromise, completePromise, PromiseId, } from '@golemcloud/golem-ts-sdk'; @@ -123,8 +120,6 @@ export const RegionWorkerImpl = RegionWorker.implement({ }, }); -const regionClient = clientFor(RegionWorker); - // Inside a coordinator method handler: async dispatchAndCollect({ regions }) { // Create one promise per child. @@ -132,7 +127,7 @@ async dispatchAndCollect({ regions }) { // Fire-and-forget: trigger each child with its (encoded) promise ID. regions.forEach((region, i) => { - regionClient({ region }).runReport.trigger({ promiseId: encodePromiseId(promiseIds[i]) }); + RegionWorker.client.get({ region }).runReport.trigger({ promiseId: encodePromiseId(promiseIds[i]) }); }); // Collect all results (the agent suspends until each promise completes). @@ -148,7 +143,7 @@ Use `Promise.allSettled` to handle partial failures: ```typescript async fanOutWithErrors({ items }) { - const promises = items.map((item, i) => workerClient({ id: i }).process({ data: item })); + const promises = items.map((item, i) => Worker.client.get({ id: i }).process({ data: item })); const settled = await Promise.allSettled(promises); const successes: string[] = []; diff --git a/docs/src/content/next/how-to-guides/ts/golem-quota-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-quota-ts.mdx index ce9fbba4cd..0808bc1ae7 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-quota-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-quota-ts.mdx @@ -121,14 +121,14 @@ if (reservationResult.isOk()) { ## 6. Splitting Tokens for Agent-to-Agent RPC -Split a portion of your quota to pass to a child agent. Call the other agent with a `clientFor(...)` client (see [`golem-call-another-agent-ts`](/next/how-to-guides/ts/golem-call-another-agent-ts)), passing the child token as an input: +Split a portion of your quota to pass to a child agent. Call the other agent through its definition client (see [`golem-call-another-agent-ts`](/next/how-to-guides/ts/golem-call-another-agent-ts)), passing the child token as an input: ```typescript -import { clientFor, QuotaToken } from '@golemcloud/golem-ts-sdk'; +import { QuotaToken } from '@golemcloud/golem-ts-sdk'; const childToken: QuotaToken = this.token.split(200n); -const summarizer = clientFor(SummarizerAgent); -const summary = await summarizer({ name: 'sum-1' }).summarize({ text, token: childToken }); +const summarizer = SummarizerAgent.client.get({ name: 'sum-1' }); +const summary = await summarizer.summarize({ text, token: childToken }); ``` The child agent declares the token input with the `s.quotaToken()` schema marker and uses it for its own reservations: diff --git a/docs/src/content/next/how-to-guides/ts/golem-recurring-task-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-recurring-task-ts.mdx index 545877edf0..39b2fd0857 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-recurring-task-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-recurring-task-ts.mdx @@ -4,7 +4,7 @@ A Golem agent can act as its own scheduler by scheduling one of its own methods to run again at the end of each invocation. This creates a durable, crash-resilient recurring task — if the agent restarts, the scheduled invocation is still pending and will fire at the designated time. -Because a method handler's `this` is bound to the agent's **state** (not to its other methods), factor the self-scheduling logic into a small module-level helper that builds an RPC client for the agent itself with `clientFor` and calls `.schedule()`. +Because a method handler's `this` is bound to the agent's **state** (not to its other methods), factor the self-scheduling logic into a small module-level helper that uses the definition's RPC client and calls `.schedule()`. ## Basic Pattern @@ -12,7 +12,7 @@ The agent schedules its own `poll` method to run again after a delay: ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const PollerAgent = defineAgent({ name: 'PollerAgent', @@ -26,7 +26,7 @@ export const PollerAgent = defineAgent({ // Self-scheduling helper: enqueue this agent's own `poll` to run after a delay. function scheduleNext(name: string, delaySecs: bigint): void { const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - clientFor(PollerAgent)({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); + PollerAgent.client.get({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); } export const PollerAgentImpl = PollerAgent.implement({ @@ -100,7 +100,7 @@ export const PollerAgentImpl = PollerAgent.implement({ if (this.cancelled) return; // stop the loop doWork(); const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - this.pending = clientFor(PollerAgent)({ name: this.name }).poll.schedule({ + this.pending = PollerAgent.client.get({ name: this.name }).poll.schedule({ seconds: nowSecs + 60n, nanoseconds: 0, }); @@ -170,12 +170,12 @@ heartbeat() { ## Helper for Scheduling Self -Keep the scheduling logic in one module-level helper so every method stays clean. `clientFor(PollerAgent)` builds a typed RPC client for this same agent type; addressing it by the agent's own id record targets this instance: +Keep the scheduling logic in one module-level helper so every method stays clean. `PollerAgent.client` is the typed RPC factory for this same agent type; addressing it by the agent's own id record targets this instance: ```typescript function scheduleNext(name: string, delaySecs: bigint): void { const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - clientFor(PollerAgent)({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); + PollerAgent.client.get({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); } ``` diff --git a/docs/src/content/next/how-to-guides/ts/golem-schedule-future-call-ts.mdx b/docs/src/content/next/how-to-guides/ts/golem-schedule-future-call-ts.mdx index 6d8a1a1f7d..f8b2e53cac 100644 --- a/docs/src/content/next/how-to-guides/ts/golem-schedule-future-call-ts.mdx +++ b/docs/src/content/next/how-to-guides/ts/golem-schedule-future-call-ts.mdx @@ -6,23 +6,22 @@ A **scheduled invocation** enqueues a method call on the target agent to be exec ## Usage -Every method on a `clientFor(...)` RPC client has a `.schedule()` variant that +Every method on a definition RPC client has a `.schedule()` variant that takes a `Datetime` as the first argument, followed by the method's input record (omit the input for methods declared with `input: {}`). It returns a `CancellationToken`; ignore the token when cancellation is not needed. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter)({ name: 'my-counter' }); +const counter = Counter.client.get({ name: 'my-counter' }); // Schedule increment to run 60 seconds from now. const nowSecs = BigInt(Math.floor(Date.now() / 1000)); counter.increment.schedule({ seconds: nowSecs + 60n, nanoseconds: 0 }); // Schedule with arguments. -const reporter = clientFor(ReportAgent)({ name: 'daily' }); +const reporter = ReportAgent.client.get({ name: 'daily' }); reporter.generateReport.schedule( { seconds: BigInt(tomorrowMidnight), nanoseconds: 0 }, { kind: 'summary' }, diff --git a/gol-122-host-call-enforcement-plan.md b/gol-122-host-call-enforcement-plan.md deleted file mode 100644 index f787ff05cd..0000000000 --- a/gol-122-host-call-enforcement-plan.md +++ /dev/null @@ -1,1028 +0,0 @@ -# GOL-122 Host-Call Enforcement Plan - -Checkboxes are intended to be updated as implementation progresses. - -## Locked decisions - -- [x] Enforcement runs only during **live execution**. -- [x] Replay never evaluates permissions, expiration, or the current effective surface. -- [x] Replay restores recorded host results and treats previously executed operations as admitted. -- [x] Live denials must be replayable as normal non-trapping host-call results through the operation's compatible typed, string, or optional channel. -- [x] Policy denial never traps. -- [x] Authorization happens before any effect, quota mutation, task spawn, stream activity, or durable `Start`. -- [x] Authorization is the linearization point; later revocation does not cancel an admitted operation. -- [x] Preserve existing guest-facing WIT signatures and shared error variants whenever policy denial can be represented through an existing result, error, string, or optional channel; add a typed result only where the existing signature cannot represent denial without trapping. -- [x] Append durable payload/function variants without reordering existing persisted tags; compatibility-only payloads introduced by this unshipped change may be removed when their host call is no longer durable. -- [x] The unchanged-authority live path must perform no service/oplog I/O and acquire no async authority lock. -- [x] `PermissionTarget` has no recipient; recipient filtering already happens when deriving the holder's effective surface. - -## Existing foundation - -- [x] Wallet installation, transfer, derivation, revocation, and expiration. -- [x] In-memory wallet and effective-surface cache. -- [x] Invocation-scope overlay. -- [x] Card-event synchronization and authority recovery. -- [x] Wallet reconstruction during replay. -- [x] Permission-card management authorization. -- [x] WASI P3 migration. - -## Live progress — 2026-08-21 - -Checkboxes track implementation completion. Validation that is still open is tracked separately in the status table and Milestones 12–13, so implemented work is not mistaken for unstarted work. - -| Area | Current status | Evidence / next gate | -|---|---|---| -| Milestone 0 scope and matrix | Complete | The matrix below covers every P2/P3 linker family, including intentionally ungated inbound/listen operations and the registered tool-RPC authorization boundary. Functional tool dispatch belongs to GOL-35. | -| Core authorization, target normalization, authority generations | Implemented; CI full suites pending | Current-snapshot checks and the executor unit-test build pass for `golem-common`, `golem-worker-executor --lib`, and `golem-worker-executor-test-utils`. Parsed network grants and runtime targets share lowercase, trailing-dot, and IPv4 normalization. RDBMS extraction uses `sqlparser` ASTs for the PostgreSQL, MySQL, and Ignite dialects; it distinguishes source-table `Query` authority from mutation targets, handles nested queries, joins, foreign keys, `CREATE TABLE ... LIKE`, and rename destinations, and fails closed for unsupported or ambiguous AST forms. | -| Durable compatible denials and replay | Complete; CI integration rerun pending | Recorded success and denial replay without current authority, incomplete admitted-call recovery, replay-to-live synchronization, and snapshot reconstruction of an admitted secret handle passed before the final WIT compatibility refinement. Live initialization/method input that fails `SecretVerb::Hold` admission is a dedicated non-retriable invocation rejection: it atomically persists `CancelPendingInvocation` plus `Error(PermissionDenied)`, completes only that invocation as `WorkerExecutorError::PermissionDenied`/`RpcError::Denied`, and leaves the worker idle. Status reconstruction indexes the rejection result, so a crash after commit returns the same denial without reauthorization. This occurs before guest execution or handle materialization. Focused protobuf, reconstruction, classification, and admission tests pass. | -| Host wrappers | Complete exact-import audit; compatibility refinement implemented | KV, blobstore, secrets, config, oplog, environment, outbound RPC/agent/tool operations, legacy agent operations, P2/P3 filesystem, P2/P3 DNS/TCP/UDP/HTTP, WebSocket, RDBMS, and card management are wired. Existing legacy channels are reused where possible: shared config denial is `upstream("permission denied")`, WebSocket denial is `other("permission denied")`, legacy metadata/strict-resolution denial is `none`, and legacy oplog enrichment denial is its existing string error. Secret `Hold` is enforced when a handle crosses from host to guest; admitted `id`/`metadata` access remains direct and `Reveal` remains independently gated. | -| Oplog payload compatibility | Complete; CI full suites pending | The payload enum keeps all pre-project variants and function mappings in their original order. The compatibility pass removes only the unshipped secret `id`/`metadata` durable payloads and WebSocket-specific denial case made unnecessary by restoring existing WIT signatures/error variants. Prepared count-based revert payloads remain append-only. Focused binary-tag and permission-denial protobuf round-trip tests pass. | -| Integration coverage | Source coverage complete; current full-suite validation delegated to CI | The pre-compatibility implementation passed its focused `scope_cards`, worker-executor, and completed integration groups. The final compatibility pass updates the affected host probes to assert legacy `none`, existing string/error mappings, and `Hold`-at-admission semantics. No integration suite or integration test will be run locally after that pass; CI owns current-tree integration validation. | -| Performance and observability | Complete | The post-fix benchmark passes with zero allocations for stable TCP allow/deny, filesystem, KV, and both refresh cases. Medium-card TCP p50/p95 is 1.292µs/1.750µs allow and 1.167µs/1.667µs deny. | -| Mandatory closure | Complete locally; CI suites and dependency publication pending | The rejected invocation-environment design is removed. In the dedicated `wasmtime-gol122` checkout, P3 `get-environment` is async in `8c427da2e6d4cea1e47b03bc95906b0cb5bb504e`, and the P2 descriptor stream constructors are async in `85a12fa3def898a4331ec6ef2530a472404a4b80`; Golem adds no invocation/snapshot/update/revert environment state. The final WIT compatibility pass preserves legacy optional/string/shared-error channels, keeps secret `id`/`metadata` direct after `Hold` admission, and synchronizes generated Rust, TypeScript, Scala, and MoonBit bindings. Platform, Rust SDK, MoonBit, focused denial/reconstruction tests, both affected test-component rebuilds, formatting/whitespace, and final Oracle review pass. Broad unit, worker-executor, and integration suites are CI-only at the user's direction. The Wasmtime dependency branch is local-only and must be pushed before CI can fetch `85a12fa3def898a4331ec6ef2530a472404a4b80`. | - -### WIT compatibility and secret-handle admission refinement — 2026-08-21 - -- [x] Review every permission-denial WIT change individually against its pre-project signature. -- [x] Restore shared `wasi:config/store.error` and encode denial as existing `upstream("permission denied")`. -- [x] Restore legacy `get-agent-metadata` and `resolve-agent-id-strict` option signatures; denial is indistinguishable from absence (`none`). -- [x] Restore legacy `enrich-oplog-entries` string error; denial is `"permission denied"`. -- [x] Restore secret `id` and `metadata` plain return values and remove their unneeded durable payloads. -- [x] Move `SecretVerb::Hold` to every host-to-guest handle admission boundary: secret-backed config, live initialization/method input, synchronous and future RPC results, tool success/custom-error results, and nested handles in reveal results. -- [x] Keep live initialization/method input `Hold` denial outside Wasmtime/`anyhow` trap classification: cancel and complete that invocation with the existing RPC denial while leaving the worker available for later invocations. -- [x] Keep `SecretVerb::Reveal` independent; a handle admitted with `Hold` remains inspectable and transferable without reauthorization, while revealing plaintext still requires `Reveal`. -- [x] Restore the WebSocket error variant and encode connect denial as existing `other("permission denied")`. -- [x] Regenerate/synchronize Rust, TypeScript, Scala, and MoonBit bindings and restore high-level Rust/MoonBit legacy option wrappers. -- [x] Compile the platform, Rust SDK, and MoonBit SDK after the compatibility reduction. -- [x] Update affected host-probe and integration-test source to the restored signatures and `Hold`-at-admission semantics. -- [x] Rebuild the affected `host-api-tests` and `agent-sdk-rust` test components without running integration tests. The copied release artifacts are SHA-256 `535d6c2692b9b590c3f28edcd75ff39b42e09955b1bbba0431c8b388378ca308` and `285155e77fb92e19a978c00798a80ba4a27f1d837bafcbe82674a70df1db9bf8`, respectively. -- [x] Pass the focused payload/config/WebSocket/secret-admission unit tests, plus permission-denial protobuf and crash-status reconstruction tests. -- [x] Pass final Oracle review. The initial review found queued-invocation fanout and reconstructed-error classification defects; both were fixed with focused regressions, and the follow-up verdict is `APPROVE`. - -Historical pre-compatibility integration checkpoint: the complete rerun passed both PostgreSQL and SQLite worker groups -(40/40 each), both environment-deletion groups (5/5 each), both API groups (150/150 each), registry -repository tests (166/166), OIDC/session tests (28/28), and debugging tests (18/18). It was stopped after -`oplog_processor_locality_recovery` exposed that the default-deny surface incorrectly treated the -executor-created oplog-processor plugin invocation as an ordinary non-agent invocation. Oplog processors -are admitted at operator-level plugin installation and deliberately are not projected onto the per-agent -permission-card model. A transient invocation execution mode now recognizes only -`ProcessOplogEntries`, admits its ordinary host permission targets (including oplog enrichment and -callback HTTP), is visible to direct and Accessor host paths, and is reset before invocation teardown on -success, error, or panic. It changes no persisted payload or snapshot/update/revert state. A long-running -focused test was terminated after its callback wait failed, but its guest invocations ran at 04:22 while -the correction was written at 05:26–05:32, so that run is retained only as the pre-fix reproducer and is -not evidence against the current tree. The next direct focused run also failed with the original denial, -but inspection proved that it spawned `golem-worker-service` last built at 04:42 while the correction -sources were written at 06:29–06:31; unlike `cargo make integration-tests-group6`, direct `cargo test` -does not rebuild the service executables. That invalid run is recorded in -`tmp/gol122-oplog-processor-locality-recovery-post-fix.log` only to preserve the diagnosis. After -`cargo make build-bins` rebuilt the service executables, the first valid current-binary end-to-end run -passed 1/1 in 34.940s (`tmp/gol122-oplog-processor-locality-recovery-current-bins.log`). This is retained -as historical evidence, not validation of the final compatibility refinement. No integration tests will -be run locally after that refinement; completion of the current full integration suite is a CI gate. - -Validation ledger (entries before the compatibility refinement are historical rather than current-tree evidence): - -```text -cargo fmt --all PASS -git diff --check PASS -cargo check -p golem-common PASS -cargo check -p golem-worker-executor --lib PASS -cargo check -p golem-worker-executor-test-utils PASS -cargo test -p golem-common --lib -- model::oplog::payload PASS (46/46) -cargo test -p golem-worker-executor --lib --no-run PASS -cargo test -p golem-worker-executor --lib -- <7 focused tests> PASS (7/7 authority/algebra/expiration/scheduled ownership) -cargo test -p golem-worker-executor --lib -- authorization::targets PASS (23/23; two RDBMS extraction defects found and fixed) -cargo test -p golem-common --lib -- card::{tests,monomorphization} PASS (16/16) -cargo test -p golem-common --lib -- card::{parsing,subsumption}_tests PASS (199/199) -cargo test -p golem-rust --features export_golem_agentic PASS -golem build -P release --force-build --yes (host-api-tests) PASS -golem build -P release --force-build --yes (expanded host probes) PASS; copied release fixture, SHA-256 f71c6316f52925bbfcb2bbd623ff9bfcc6a37f118e0a43ddfa8f75d336063c8f -cargo check -p golem-worker-executor --bench authorization PASS -cargo bench -p golem-worker-executor --bench authorization -- --test PASS; stable TCP allow/deny, filesystem, KV, one-event, and burst cases allocate zero -cargo test -p golem-worker-executor --test integration -- scope_cards:: PASS (16/16, including denial replay after authority revocation) -cargo test -p integration-tests --test integration -- filesystem_permissions_enforce_recipient_isolation_across_recovery PASS (PostgreSQL + SQLite) -cargo test -p golem-worker-executor --lib -- <6 authority tests> PASS (6/6) -cargo test -p golem-worker-executor --lib -- recorded_success_replays_without_live_expiry_or_authority_inputs PASS -cargo test -p golem-worker-executor --test integration -- keyvalue::readwrite_get_returns_the_value_that_was_set PASS (2/2 sync + streamed body with explicit test host grants) -cargo test -p golem-worker-executor --test integration -- scope_cards::protected_host_families_return_typed_default_denials PASS (1/1; eventual/cache KV, blobstore, config/environment, DNS/UDP/HTTP, WebSocket, PostgreSQL/MySQL/Ignite, legacy oplog, outbound agent RPC) -cargo test -p golem-worker-executor --test integration -- scope_cards::filesystem_permissions_isolate_resource_owners PASS (1/1; matching owner writes once, foreign owner is typed-denied with no file effect) -cargo test -p golem-worker-executor --test integration -- scope_cards::concurrent_p3_operations_authorize_independently_before_backend_access PASS (1/1; concurrent allowed TCP connects exactly once, denied TCP never reaches backend) -cargo test -p golem-worker-executor --test integration -- scope_cards::denied_tool_invocation_does_not_start_the_tool_component PASS (1/1; typed denial, one authority refresh, zero tool activation) -cargo test -p golem-worker-executor --test integration -- scope_cards::secret_reveal_authorizes_before_secret_revision_lookup PASS (1/1; denied reveal performs zero revision lookups, allowed reveal performs one) -cargo test -p golem-worker-executor --test integration -- scope_cards::snapshot_restores_admitted_secret_handle_without_reauthorization PASS (1/1; snapshot reloads, reconstructs the secret handle from the recorded wallet, and performs no extra authority refresh) -cargo test -p golem-worker-executor --test integration -- scope_cards::golem_host_agent_operations_are_typed_default_deny_and_allow_when_granted PASS (1/1; listing, strict resolution, and self-fork return typed denials before effects; listing, self metadata, strict resolution, and self-fork pass their Agent gates when granted) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_p2_and_p3_filesystem_import_enforces_permissions PASS (1/1; every protected P2/P3 descriptor method and multi-verb open mode returns typed `NotPermitted`) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_network_http_and_websocket_import_enforces_permissions PASS (1/1; every protected P2/P3 DNS, TCP, UDP, HTTP, and WebSocket entry returns its typed denial) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_storage_config_and_secret_import_enforces_permissions PASS (1/1; every protected eventual/cache KV, blobstore, config, and secret entry returns its typed denial; found and fixed swallowed blob delete-object denials) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_rdbms_agent_rpc_tool_and_oplog_import_enforces_permissions PASS (1/1; connection-level PostgreSQL/MySQL/Ignite, agent, oplog, all outbound agent RPC variants, and all tool RPC variants return typed denials) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_rdbms_transaction_import_enforces_permissions PASS (1/1; PostgreSQL/MySQL/Ignite transaction query/query-stream/execute honor negative table grants before backend execution; commit/rollback inherit admitted transaction authority) -cargo test -p golem-worker-executor --test integration -- scope_cards::remaining_host_facing_permission_classes_allow_their_backends PASS (1/1; environment, KV, config, and oplog grants reach their backends; all three granted tool modes pass authorization and reach the current unavailable-backend result rather than `Denied`) -cargo test -p golem-worker-executor --test integration -- <4 wrapper contract tests> PASS (4/4; KV/blob batches have zero partial effects, cache vacancies and blob read streams retain admission across revocation, new work is denied, and remaining class allows still reach backends) -cargo test -p golem-worker-executor --lib -- durable_host::authorization::targets::tests::kv_and_blob_targets_preserve_utf8_resource_names --exact --report-time PASS (1/1; typed targets preserve dotted and non-ASCII resource names) -cargo test -p golem-worker-executor --test integration -- scope_cards::blobstore_authorization_preserves_valid_utf8_container_names --report-time PASS (1/1; a WIT-valid dotted container name reaches the backend) -cargo test -p golem-worker-executor --lib -- --report-time PASS (3/3; grant/runtime hostname normalization, ALTER rename destination preflight, and INSERT-SELECT source Query authority) -cargo test -p golem-common --lib -- card::parsing_tests card::subsumption_tests card::rendering_tests --report-time PASS (201/201) -cargo test -p golem-common -- card::parsing_tests --report-time PASS (96/96; trailing-dot/lowercase hostname normalization and malformed-label rejection) -cargo test -p golem-worker-executor --lib -- authorization::targets PASS (33/33; dialect AST extraction, joins/subqueries, DDL/FK sources, fail-closed wrappers, fallback, and normalized network targets) -sdks/moonbit/golem_sdk/scripts/regen-bindings.sh PASS (repository-pinned Golem wit-bindgen revision 4407232) -moon fmt --check (sdks/moonbit/golem_sdk) PASS -moon check --target wasm (sdks/moonbit/golem_sdk), initial FAIL (7 hand-maintained config and scheduled-RPC wrapper type errors; fixed, then webhook typed-result use fixed) -moon check --target wasm (sdks/moonbit/golem_sdk), final PASS -moon build --target wasm (sdks/moonbit/golem_sdk) PASS -moon test --target wasm (sdks/moonbit/golem_sdk) PASS (433/433) -cargo test -p golem-registry-service --lib -- agent_initial_card_inherits_parent_ids_from_creator_surface PASS (1/1) -cargo test -p golem-common --lib -- model::oplog::payload --report-time PASS (46/46, pure GOL-122 extraction) -cargo test -p golem-worker-executor --lib -- durable_host::tool --report-time PASS (4/4, pure GOL-122 extraction) -cargo test -p golem-worker-executor --test integration -- <3 tool permission tests> PASS (3/3, pure GOL-122 extraction; denied/all three modes/granted unavailable backend) -cargo fmt --all -- --check (dedicated wasmtime-gol122 checkout) PASS -cargo check -p wasmtime-wasi --features p3 (dedicated checkout) PASS -git diff --check (dedicated wasmtime-gol122 checkout) PASS -cargo test -p wasmtime-wasi --features p3 --lib BLOCKED before test execution by the fork's test-program artifact builder under Cargo 1.97 (`CARGO_BUILD_BUILD_DIR` places the adapter outside its asserted target path); the affected crate check passes -cargo check -p golem-worker-executor --lib (async P3 fork integration) PASS -cargo check -p golem-worker-executor --lib (portable git dependency on Wasmtime commit 8c427da2e) PASS -golem build -P release --force-build --yes (host-api-tests environment fixture) PASS; component SHA-256 e33710a42fb0ae314edccc72b8b41cf3d55229f0d2a9941345dff09d3b66bdb4 -cargo test -p golem-worker-executor --test integration -- scope_cards::p2_and_p3_environment --report-time PASS (2/2; each test exercises P2 and P3 revocation-at-boundary and recorded-result replay) -cargo test -p golem-worker-executor --test integration -- scope_cards::protected_host_families_return_typed_default_denials --report-time PASS (1/1 after explicitly preserving the fixture's initialization-only self-view grant; all tested host families remain default-denied) -cargo fmt --all -- --check; git diff --check (post-environment refinement) PASS -cargo make unit-tests (post-environment refinement, portable Wasmtime dependency) PASS (3,545 passed, 2 ignored, 0 failed across 17 suites) -cargo check -p golem-worker-service -p golem-debugging-service -p golem-registry-service PASS (corrected Agent resource mappings and debug-alias expansion compile against the portable Wasmtime dependency) -cargo test -p golem-common --lib -- card::parsing_tests card::rendering_tests card::subsumption_tests --report-time PASS (209/209; includes empty-vs-wildcard Agent resources, verb-specific resources, and parse-time-only legacy debug expansion through card and scope-card deserialization) -cargo fmt --all -- --check; git diff --check (post-Agent-model correction) PASS -cargo test -p golem-worker-executor --lib -- durable_host::wasm_rpc::tests --report-time PASS (15/15 after append-only first-activation fingerprint correction) -cargo test -p golem-common --lib -- model::oplog::payload --report-time PASS (48/48; appended activation request/response/function variants and existing binary tags) -cargo test -p golem-worker-executor --test integration -- scope_cards::every_protected_rdbms_agent_rpc_tool_and_oplog_import_enforces_permissions --report-time PASS (1/1 after activation-decision correction; outbound invoke, async invoke-and-await, invoke-and-await, and schedule denials remain typed and pre-effect) -cargo test -p golem-worker-executor --test integration -- scope_cards::scope_card_delivery_and_cleanup_survive_crash_replay scope_cards::outbound_rpc_denial_replays_without_activating_the_target --report-time PASS (2/2; persisted admitted fingerprint, exactly one activation record after restart, idempotent target dispatch, denied target never created, denial replay uses no live authority) -cargo test -p golem-worker-service --lib -- <4 exact target tests> --report-time PASS (4/4; concrete invocation method, lifecycle empty resources, oplog range, filesystem paths and verbs, cancellation identifier, plugin name, and revert cutoff) -cargo test -p golem-debugging-service --lib -- debugging_requires_every_permission_in_the_legacy_alias_expansion --report-time PASS (1/1; all eight canonical constituent permissions are required) -cargo make fix (workspace and dev-tools, all targets) PASS -cargo fmt --all -- --check; git diff --check (post-fix) PASS -cargo test -p golem-common --lib -- model::oplog::payload --report-time PASS (49/49; includes appended WebSocket-error binary-tag regression) -cargo test -p golem-worker-executor --lib -- durable_host::wasm_rpc::tests --report-time PASS (15/15 post-fix) -cargo test -p golem-worker-service --lib -- <4 exact target tests> --report-time PASS (4/4 post-fix) -cargo test -p golem-debugging-service --lib -- debugging_requires_every_permission_in_the_legacy_alias_expansion --report-time PASS (1/1 post-fix) -cargo test -p golem-worker-executor --test integration -- <3 RPC authorization/replay tests> --report-time PASS (3/3 post-fix; all five RPC forms denied before activation, admitted and denied restart paths pass) -cargo check -p golem-worker-executor -p golem-worker-service -p golem-debugging-service -p golem-worker-executor-test-utils -p golem-api-grpc PASS (post-fix) -cargo make unit-tests (first final run) FAIL (one stale registry test fixture still used wildcard resources for `resume` and `update-revision`; production code was not implicated) -cargo test -p golem-registry-service --lib -- agent_initial_card_inherits_parent_ids_from_creator_surface --report-time PASS (1/1 after converting the fixture to canonical empty lifecycle resources) -cargo make unit-tests (final rerun) PASS (3,562 passed, 2 ignored, 0 failed across 17 suites) -cargo make worker-executor-tests (first final run) FAIL (771 passed, 41 failed, 4 ignored; stale test-component artifacts account for the missing `golem:agent/host@2.0.0` linker imports, with additional snapshot-authority, permission-fixture, SQL-fixture, timing, memory, and expected-oplog-count failures to diagnose before the mandatory rerun) -npx pnpm install; npx pnpm run build; npx pnpm run build-agent-template PASS (TypeScript SDK and embedded agent template rebuilt after the host WIT changes) -test-components/build-components.sh rebuild ts PASS (all five TypeScript test applications rebuilt and copied against the current SDK/template) -golem build -P release --force-build --yes; golem exec -P release copy (agent-counters) PASS (snapshot fixture rebuilt against the current Rust SDK/WIT) -cargo test -p golem-worker-executor --test integration -- <18 first-run failure regressions> FAIL (17 passed, 1 failed; the rebuilt fixtures, snapshot authority restoration, SQL setup, timing probes, memory expectation, and oplog counts pass; cross-component strict agent resolution exposed an over-restrictive owner-target shortcut, now corrected and under focused rerun) -cargo test -p golem-worker-executor --test integration -- api::resolve_components_from_name --report-time PASS (1/1; cross-component strict resolution builds the canonical target owner and honors the matching grant before checking agent existence) -cargo make worker-executor-tests (complete rerun) PASS (786 passed, 4 ignored, 0 failed; post-fixture and strict-resolution correction) -Final semantic replay audit PASS (an incomplete persisted Start remains admitted; no live authority recheck is allowed during repair) -cargo check -p golem-worker-service -p golem-worker-executor -p golem-debugging-service --tests PASS (prepared count-revert protocol) -cargo test -p golem-worker-service --lib -- revert_uses_the_concrete_cutoff_for_index_and_count_targets PASS (1/1) -cargo test -p golem-worker-executor --test integration -- <2 prepared count-revert tests> PASS (2/2; ordinary revert and stale-tip rejection with no oplog write) -cargo test -p golem-common --lib model::oplog::payload::tests PASS (49/49; includes prepared/unprepared revert round trips) -cargo test -p golem-rust --features export_golem_agentic PASS (all runtime, integration, and doc-test groups) -cargo test -p golem-rust-macro PASS (97/97; doc tests also pass) -cargo fmt --all -- --check; git diff --check (post-prepared-revert) PASS -cargo make integration-tests (first mandatory run) FAIL (39/40 in group 1; durable config access adds one expected imported-function oplog entry, so the stale assertion was corrected from 2 to 3) -cargo make integration-tests (second mandatory run) FAIL (group 1 passed 40/40 and environment deletion passed 5/5; registry service stack-overflowed in group 2 while decoding recursive component metadata, and the remaining 140 failures were connection-error cascades) -cargo test -p integration-tests --test integration -- add_new_agent_config_entry_during_update_postgres PASS (1/1 without `RUST_MIN_STACK` after setting the registry Tokio worker stack to 4 MiB) -cargo fmt --all -- --check; git diff --check (post-stack fix) PASS -cargo make build-bins (post-oplog-processor correction) PASS -cargo test -p integration-tests --test sharding -- oplog_processor_locality_recovery --report-time PASS (1/1 in 34.940s; freshly rebuilt service executables) -cargo make integration-tests (final local attempt) STOPPED by user after all completed groups passed, including worker 80/80, environment deletion 10/10, API 300/300, registry 166/166, OIDC/session 28/28, debugging 18/18, sharding 9/9, and plugin/OTLP 15/15; remaining groups move to CI -cargo make fix; cargo fmt --all -- --check; git diff --check (final) PASS -cargo test -p golem-common --lib -- model::oplog::payload --report-time PASS (49/49 after WIT compatibility reduction) -cargo test -p golem-worker-executor --lib -- permission_denial --report-time PASS (2/2 existing config/WebSocket error mappings) -cargo test -p golem-worker-executor --lib -- secret_hold_admission --report-time PASS (2/2 recursive handle discovery and invalid-snapshot rejection) -cargo test -p golem-worker-executor --lib -- permission_denied_is_a_non_retriable_invocation_rejection --report-time PASS (1/1 typed denial, invocation-rejection classification, no retry) -cargo test -p golem-common --lib -- main_payload_additions_keep_existing_p3_binary_tags_stable --report-time PASS (1/1 after final payload reduction) -cargo test -p golem-common --lib -- agent_error_permission_denied_protobuf_roundtrip --report-time PASS (1/1 exact durable error wire round trip) -cargo test -p golem-worker-executor --lib -- permission_denied_rejection_survives_status_reconstruction --report-time PASS (1/1 atomic cancellation/error reconstruction leaves the worker idle and indexes the denial) -cargo test -p golem-worker-executor --lib -- reconstructed_permission_denial_keeps_its_executor_error_type --report-time PASS (1/1 restarted lookup preserves `WorkerExecutorError::PermissionDenied`) -cargo test -p golem-worker-executor --lib -- invocation_rejection_fails_only_the_rejected_pending_key --report-time PASS (1/1 later queued invocations remain pending) -cargo check -p golem-api-grpc -p golem-common -p golem-worker-executor PASS (final denial durability changes) -golem build/exec copy -P release --force-build --yes (host-api-tests and agent-sdk-rust only) PASS; no integration tests run -Oracle final follow-up APPROVE (exact-one rejection and restarted denial equivalence) -``` - -The final registered-import audit traced every P2/P3 and Golem linker registration to its implementation. Every authority-crossing operation authorizes before backend access, quota mutation, durable `Start`, task/resource creation, body consumption, or transport; lifecycle/plumbing operations inherit a previously admitted resource or are explicitly ungated. No missing or post-effect enforcement point was found. The test framework now grants the complete host surface explicitly for legacy behavior tests, while enforcement tests opt out per agent type to preserve default-deny coverage. - -SQL review checkpoint: the previously reported SQL-review bug-finder non-convergence remains parked as -requested. Do not rerun or override that review until the separate follow-up decision. - -Current validation queue: - -- [x] Rerun `cargo make unit-tests` after the final environment payload refinement: 3,545 passed, - 2 ignored, 0 failed across 17 suites. -- [x] Compile the corrected Agent resource mappings and parse-time-only debug alias expansion across - `golem-worker-service`, `golem-debugging-service`, and `golem-registry-service`. -- [x] Run the complete focused card parsing/rendering/subsumption suite after the Agent model correction: - 209 passed, 0 failed. -- [x] Pass focused admitted and denied outbound-RPC activation crash/replay tests, including persisted - fingerprints, no duplicate activation record, no target activation for denial, and enqueue-time - idempotency under recovery: 2 passed, 0 failed. -- [x] Add and pass focused service-level tests for the corrected oplog, cancellation, plugin, filesystem, - lifecycle, and concrete debugging-permission targets: 5 passed, 0 failed. -- [x] Run the mandatory workspace lint/fix gate and recheck formatting and patch whitespace. -- [x] Rerun `cargo make unit-tests` after the final Agent model and service-target correction: - 3,562 passed, 2 ignored, 0 failed across 17 suites. -- [x] Run `cargo make worker-executor-tests` in the GOL-122 checkout. The first final run completed - with 771 passed, 41 failed, and 4 ignored. Rebuild the affected test components, diagnose every - remaining non-artifact failure, and rerun the complete suite; do not close from the partial result. - The first focused regression run passed 17/18; its sole failure showed that legacy agent-operation - authorization default-denied every cross-component target instead of constructing the target's - canonical owner. The helper now resolves component metadata before the target-agent existence lookup, - preserving pre-effect authorization while allowing a matching cross-component grant; the exact - regression passes 1/1. The complete rerun passes 786 tests with 4 ignored and 0 failed. -- [x] Replace wildcard authorization for count-based revert with a concrete prepared cutoff, preserve - that preparation in the durable request for incomplete replay repair, reject stale observed tips - under the worker instance lock before mutation, and pass the focused service/executor/payload tests. -- [x] Run the Rust SDK runtime and macro test suites after propagating compatible host denials through - the public Rust SDK APIs, including the preserved legacy option wrappers. -- [ ] Complete `cargo make integration-tests` in CI and close only from passing evidence. - The first run exposed and corrected the expected imported-function oplog count added by durable config - access. The next run passed group 1 (40/40) and environment deletion (5/5), then the registry process - stack-overflowed while decoding recursive component metadata in group 2. Raising only the registry's - Tokio worker stack from 2 MiB to 4 MiB fixes the exact failing test without an environment override. - The current complete rerun has passed PostgreSQL and SQLite worker groups (40/40 each), - environment-deletion groups (5/5 each), and API groups (150/150 each), including the former - stack-overflow reproducer, as well as registry repository (166/166), OIDC/session (28/28), and - debugging (18/18). It was stopped after the oplog-processor locality-recovery test exposed the - operator-authority gap described in the latest checkpoint. The narrow invocation-mode correction is - implemented. The first attempted focused run exercised a binary built before that correction and is - only a pre-fix reproducer. After rebuilding service executables, the exact current-binary regression - passes 1/1 in 34.940s. The final local run subsequently passed every completed group listed in the - status table before it was stopped at the user's request; the remaining groups move to CI. -- [ ] Rerun `cargo make worker-executor-tests` and `cargo make unit-tests` in CI. Complete local reruns - were explicitly waived after the prior 786/4 and 3,562/2 passing runs. -- [x] Run the final focused formatting and patch-whitespace gates after the compatibility refinement: - `cargo fmt --all -- --check` and `git diff --check` pass. The broad workspace fix gate is CI-only. -- [ ] Push the Wasmtime branch containing `85a12fa3def898a4331ec6ef2530a472404a4b80` before starting CI. -- [x] Amend the final compatibility refinement into the single local Golem commit without pushing. - -## Milestone 0 — Freeze the enforcement matrix - -Before writing interception code, enumerate every host import registered by the executor and classify it as: - -1. Protected semantic operation. -2. Resource lifecycle/plumbing operation. -3. Already protected elsewhere. -4. Out of GOL-122 scope. - -- [x] Create a working matrix with columns: - - interface/function - - permission class - - owner - - verb - - resource - - semantic authorization point - - compatible non-trapping denial result - - durable-result behavior - - replay behavior - - effect that must not begin before authorization -- [x] Audit all P2 and P3 linker registrations, not only currently obvious wrappers. -- [x] Explicitly mark drops, polls, local state inspection, and resource getters that need no gate. -- [x] Confirm that inbound RPC checks remain defense in depth but do not replace outbound caller enforcement. - -### Scope decisions to close - -- [x] **Network:** current [`NetworkVerb`](golem-common/src/base_model/card/class/network.rs) only has `Connect`. - - Default mapping: DNS, TCP connect, UDP remote destination, and HTTP dispatch use `Connect`. - - Decide whether bind/listen are intentionally outside this model or whether new `Bind`/`Listen` verbs must be added. -- [x] **Environment:** make the standard P3 environment host call async in the Golem Wasmtime fork and enforce at that durable host-call boundary as described in Milestone 7. -- [x] **RDBMS:** decide whether GOL-122 includes SQL-to-table target extraction. -- [x] **Tools:** confirm whether a functional tool invocation host boundary currently exists. -- [x] Record RDBMS/tools as explicitly included or explicitly deferred; do not leave them ambiguous. - -### Closed scope decisions - -Network authorization is outbound-only and uses the existing `NetworkVerb::Connect`. DNS resolution, -TCP connect, UDP connect or an unconnected send destination, WebSocket connect, and HTTP dispatch are -gated. Bind, listen, accept, socket creation/options/address inspection, receive, and established-stream -I/O are intentionally ungated: they do not initiate access to external authority. A connected socket or -stream inherits the admission of the operation that established it; revocation after admission does not -cancel it. `PermissionTarget` never contains a recipient. - -Environment uses an async standard P2/P3 host call. The private Wasmtime fork marks P3 -`wasi:cli/environment.get-environment` async, allowing both previews to build the established enriched -environment, authorize `EnvClass / EnvVerb::Read / ` at the host-call boundary, and -durably record the filtered result. Replay returns the recorded result without live authorization. -Invocation start and snapshot/update/revert environment state remain untouched. Arguments and initial -cwd remain ungated. - -RDBMS enforcement and tool-RPC enforcement are included, with no deferred/TBD GOL-122 surface. RDBMS -must parse each statement before any connection use and authorize every referenced -database/schema/table (`RdbmsVerb::Query` for reads, `RdbmsVerb::Mutate` for writes and DDL); statements -whose complete target set cannot be established fail closed. `golem:tool/host` is registered, but its -invocation backend is intentionally owned by [GOL-35](https://linear.app/golem-cloud/issue/GOL-35/implementation-of-the-tool-host-function-call-on-top-of-side-car). -GOL-122 resolves the bound tool and canonical command arguments, gates `tool-rpc.invoke`, -`async-invoke-and-await`, and `invoke-and-await` with `ToolVerb::Invoke`, and durably records and replays -typed permission denials. A granted call reaches the current unavailable-backend -`RemoteInternalError`; GOL-122 does not implement GOL-35 runtime dispatch. - -Inbound direct-invocation checks remain defense in depth. They do not replace caller-side authorization: -the outbound RPC/agent/tool wrapper must check the calling agent's wallet and invocation overlay before -lookup, activation, scheduling, or dispatch. - -### Registration-to-handler audit matrix - -This matrix is exhaustive for the registrations in `wasi_host::create_linker`, the P3 bulk registration -it calls, and the registrations appended by `Bootstrap::create_wasmtime_linker`. Names are exact WIT -interface/function names; semicolon-separated functions in one row share one unambiguous disposition. -For gated rows, the owner is the class's owner from the target mapping below and the resource is shown -after the verb. “Local/plumbing” includes resource drops and future/stream getters after an operation has -already been admitted. - -| Preview | Exact WIT interface / function(s) | Implementation file(s) | Permission mapping or explicit ungated reason | -|---|---|---|---| -| P3 | `wasi:cli/environment.get-environment` | Golem Wasmtime fork `crates/wasi/src/p3/{bindings.rs,cli/host.rs}`, `durable_host/p3/cli.rs`, `durable_host/cli/environment.rs` | **Env / `Read` / each variable name.** The fork makes the standard P3 host call async; authorize/filter one complete enriched view before returning and durably record that filtered result. | -| P3 | `wasi:cli/environment.get-arguments`; `get-initial-cwd` | `durable_host/p3/cli.rs` | Ungated CLI arguments/cwd; not environment authority. | -| P3 | `wasi:cli/exit.exit`; `exit-with-code` | `durable_host/p3/cli.rs` | Ungated process-control plumbing. | -| P3 | `wasi:cli/stdin.read-via-stream`; `wasi:cli/stdout.write-via-stream`; `wasi:cli/stderr.write-via-stream` | `durable_host/p3/cli.rs` | Ungated worker stdio/log capture; no gated external operation. | -| P3 | `wasi:cli/terminal-input.[drop]`; `terminal-output.[drop]`; `terminal-stdin.get-terminal-stdin`; `terminal-stdout.get-terminal-stdout`; `terminal-stderr.get-terminal-stderr` | `durable_host/p3/cli.rs` | Ungated terminal getters/resource lifecycle. | -| P3 | `wasi:clocks/types` conversions; `system-clock.now`; `get-resolution`; `monotonic-clock.now`; `get-resolution`; `wait-until`; `wait-for` | `durable_host/p3/clocks.rs` | Ungated clock/wait plumbing. | -| P3 | `wasi:random/random.get-random-bytes`; `get-random-u64`; `insecure.get-insecure-random-bytes`; `get-insecure-random-u64`; `insecure-seed.get-insecure-seed` | `durable_host/p3/random.rs` | Ungated random plumbing. | -| P3 | `wasi:filesystem/preopens.get-directories`; `types.convert-error-code`; `descriptor.[drop]` | `durable_host/p3/filesystem.rs` | Ungated preopen/error/resource plumbing; preopens expose guest paths, not backing paths. | -| P3 | `wasi:filesystem/types.descriptor.read-via-stream` | `durable_host/p3/filesystem.rs` | **Filesystem / `Read` / canonical absolute descriptor path.** | -| P3 | `descriptor.write-via-stream`; `append-via-stream`; `set-size`; `set-times`; `sync-data`; `sync` | `durable_host/p3/filesystem.rs` | **Filesystem / `Write` / canonical absolute descriptor path.** Admission is inherited by the resulting stream/task. | -| P3 | `descriptor.read-directory` | `durable_host/p3/filesystem.rs` | **Filesystem / `List` / canonical absolute directory path.** | -| P3 | `descriptor.stat`; `stat-at`; `metadata-hash`; `metadata-hash-at`; `readlink-at` | `durable_host/p3/filesystem.rs` | **Filesystem / `Stat` / canonical absolute path (descriptor-relative argument resolved first).** | -| P3 | `descriptor.create-directory-at`; `set-times-at`; `open-at` when create/write/truncate; `symlink-at` | `durable_host/p3/filesystem.rs` | **Filesystem / `Write` / resolved destination path.** `open-at` also preflights `Read`/`List` as requested by flags/type. | -| P3 | `descriptor.open-at` when read/enumerate | `durable_host/p3/filesystem.rs` | **Filesystem / `Read` or `List` / resolved opened path.** All requested verbs are preflighted together. | -| P3 | `descriptor.remove-directory-at`; `unlink-file-at` | `durable_host/p3/filesystem.rs` | **Filesystem / `Delete` / resolved target path.** | -| P3 | `descriptor.rename-at` | `durable_host/p3/filesystem.rs` | **Filesystem / `Delete` / source + Filesystem / `Write` / destination.** | -| P3 | `descriptor.link-at` | `durable_host/p3/filesystem.rs` | **Filesystem / `Read` / source + Filesystem / `Write` / destination.** | -| P3 | `descriptor.advise`; `get-flags`; `get-type`; `is-same-object` | `durable_host/p3/filesystem.rs` | Ungated local descriptor state/advisory inspection; no filesystem data or namespace effect. | -| P3 | `wasi:sockets/ip-name-lookup.resolve-addresses` | `durable_host/p3/sockets/dns.rs` | **Network / `Connect` / normalized hostname with `PortPattern::Any`.** Gate before DNS. | -| P3 | `wasi:sockets/types.tcp-socket.connect` | `durable_host/p3/sockets/tcp.rs` | **Network / `Connect` / normalized remote host and port.** Connection and derived streams inherit admission. | -| P3 | `tcp-socket.bind`; `listen`; `create`; all `get-*`/`set-*` socket options; `[drop]` | `durable_host/p3/sockets/tcp.rs` | Ungated local bind/listen/options/address inspection/resource lifecycle; no outbound authority crossing. | -| P3 | `tcp-socket.send`; `receive` | `durable_host/p3/sockets/tcp.rs` | Ungated established-stream I/O; inherits successful `connect` admission. | -| P3 | `wasi:sockets/types.udp-socket.connect`; `send` with a new/unconnected destination | `durable_host/p3/sockets/udp.rs` | **Network / `Connect` / normalized destination host and port.** Connected sends inherit admission; each unconnected destination is admitted before send. | -| P3 | `udp-socket.bind`; `create`; `disconnect`; all `get-*`/`set-*` options; `receive`; `[drop]` | `durable_host/p3/sockets/udp.rs` | Ungated local setup/options/receive/resource lifecycle; no new outbound destination. | -| P3 | `wasi:http/client.send` | `durable_host/p3/http/send.rs` | **Network / `Connect` / normalized final URI host and effective port.** Each redirect destination is separately admitted. | -| P3 | `wasi:http/types.fields.*`; `request.new`; request `get-*`/`set-*`; `request-options.*`; response `new`/`get-*`/`set-*`; request/response `consume-body`; all `[drop]`; error conversions | `durable_host/p3/http/host_types.rs`, `request_body.rs`, `response_body.rs` | Ungated HTTP object/body/resource plumbing. Outbound authority is crossed only by `client.send`; inbound HTTP objects are intentionally ungated. | -| P2 | `wasi:cli/environment.get-environment`; `get-arguments`; `initial-cwd` | `durable_host/cli/environment.rs` | Environment variables: **Env / `Read` / variable**, authorized/filtered and recorded at the async host-call boundary; args/cwd ungated CLI data. | -| P2 | `wasi:cli/exit.exit`; stdin/stdout/stderr `get-*`; terminal-input/output `[drop]`; terminal-stdin/stdout/stderr `get-terminal-*` | `durable_host/cli/{exit,stdin,stdout,stderr,terminal_input,terminal_output,terminal_stdin,terminal_stdout,terminal_stderr}.rs` | Ungated CLI/terminal plumbing and lifecycle. | -| P2 | `wasi:clocks/monotonic-clock.now`; `resolution`; `subscribe-duration`; `subscribe-instant`; `wall-clock.now`; `resolution` | `durable_host/clocks/{monotonic_clock,wall_clock}.rs` | Ungated clock/poll plumbing. | -| P2 | `wasi:io/error.to-debug-string`; `[drop]`; `poll.poll`; pollable `ready`; `block`; `[drop]`; streams input/output operations, `subscribe`, `[drop]` | `durable_host/io/{error,poll,streams}.rs` | Ungated I/O plumbing. A stream created by a gated semantic operation carries that operation's admission. | -| P2 | `wasi:random/random.get-random-bytes`; `get-random-u64`; `insecure.get-insecure-random-bytes`; `get-insecure-random-u64`; `insecure-seed.insecure-seed` | `durable_host/random/{random,insecure,insecure_seed}.rs` | Ungated random plumbing. | -| P2 | `wasi:filesystem/preopens.get-directories`; `types.descriptor.[drop]` | `durable_host/filesystem/{preopens,types}.rs` | Ungated preopen/resource lifecycle. | -| P2 | `descriptor.read`; `read-via-stream` | `durable_host/filesystem/types.rs` | **Filesystem / `Read` / canonical absolute descriptor path.** | -| P2 | `descriptor.write`; `write-via-stream`; `append-via-stream`; `set-size`; `set-times`; `sync-data`; `sync` | `durable_host/filesystem/types.rs` | **Filesystem / `Write` / canonical absolute descriptor path.** | -| P2 | `descriptor.read-directory` | `durable_host/filesystem/types.rs` | **Filesystem / `List` / canonical absolute directory path.** | -| P2 | `descriptor.stat`; `stat-at`; `metadata-hash`; `metadata-hash-at`; `readlink-at` | `durable_host/filesystem/types.rs` | **Filesystem / `Stat` / canonical resolved path.** | -| P2 | `descriptor.create-directory-at`; `set-times-at`; `open-at`; `symlink-at`; `remove-directory-at`; `unlink-file-at`; `rename-at`; `link-at` | `durable_host/filesystem/types.rs` | Same multi-target **Write/Delete/Read** filesystem mapping as the corresponding P3 rows; all targets preflight together. | -| P2 | `descriptor.advise`; `get-flags`; `get-type`; `is-same-object` | `durable_host/filesystem/types.rs` | Ungated local descriptor/advisory inspection. | -| P2 | `wasi:sockets/ip-name-lookup.resolve-addresses` | `durable_host/sockets/ip_name_lookup.rs` | **Network / `Connect` / normalized hostname with `PortPattern::Any`.** | -| P2 | `wasi:sockets/tcp.start-connect`; `finish-connect` | `durable_host/sockets/tcp.rs` | **Network / `Connect` / normalized remote host and port**, admitted at `start-connect`; resulting streams inherit admission. | -| P2 | TCP `start-bind`; `finish-bind`; `start-listen`; `finish-listen`; `accept`; create, options/address getters/setters, `subscribe`, `shutdown`, `[drop]`; `instance-network.instance-network`; `network.error-code` | `durable_host/sockets/{tcp,tcp_create_socket,instance_network,network}.rs` | Ungated local bind/listen/accept/socket options/network handle/resource plumbing. | -| P2 | `wasi:sockets/udp.start-bind`; `finish-bind`; `stream`; outgoing-datagram-stream `send` | `durable_host/sockets/udp.rs` | `stream` with remote and every datagram destination: **Network / `Connect` / normalized host and port** before outbound send; bind is ungated. | -| P2 | UDP create/options/address getters/setters; incoming stream `receive`; all `subscribe`/`check-send`/`[drop]` | `durable_host/sockets/{udp,udp_create_socket}.rs` | Ungated local/options/receive/poll/resource plumbing; connected outgoing stream inherits admission. | -| P2 | `wasi:http/outgoing-handler.handle` | `durable_host/http/outgoing_http.rs` | **Network / `Connect` / normalized final URI host and effective port**; redirects separately gated. | -| P2 | `wasi:http/types` fields/request/options/response/body/future methods and drops | `durable_host/http/types.rs` | Ungated object, body, future, inbound HTTP, and resource plumbing; outbound gate is `handle`. | -| P2 | `wasi:blobstore/blobstore.create-container`; `get-container`; `delete-container`; `container-exists`; `copy-object`; `move-object` | `durable_host/blobstore/mod.rs` | **Blob / `Write`, `Read`, `Delete` or `List` / exact bucket/key** as applicable; copy = source Read + destination Write, move also source Delete. | -| P2 | `wasi:blobstore/container.name`; `info` | `durable_host/blobstore/container.rs` | Ungated local metadata on a container handle that can only be obtained through admitted `create-container` or `get-container`; no backend access. | -| P2 | `wasi:blobstore/container.get-data`; `write-data`; `delete-object(s)`; `has-object`; `object-info`; `clear`; `list-objects` | `durable_host/blobstore/container.rs` | **Blob / Read, Write, Delete, or List / exact bucket/key or prefix.** All batch targets preflight. | -| P2 | `wasi:blobstore/types` incoming/outgoing value creation, consume/write/size and drops | `durable_host/blobstore/types.rs` | Ungated value/stream plumbing; it inherits admission from the blob operation that consumes or creates it. | -| P2 | `wasi:keyvalue/types.bucket.open-bucket` | `durable_host/keyvalue/types.rs` | Ungated local bucket handle creation; no backend access until a semantic KV operation. Other types methods/drops are plumbing. | -| P2 | `wasi:keyvalue/eventual.get`; `exists`; `set`; `delete`; `eventual-batch.get-many`; `keys`; `set-many`; `delete-many` | `durable_host/keyvalue/{eventual,eventual_batch}.rs` | **KV / Read, Write, Delete, or List / exact store/key or prefix**; batches preflight all keys. | -| P2 | `wasi:keyvalue/cache.get`; `exists`; `set`; `get-or-set`; `delete` | `durable_host/keyvalue/caching.rs` | **KV / Read, Write, Delete / exact store/key.** `get-or-set` preflights Read+Write. | -| P2 | `wasi:keyvalue/cache` future `get`/drops; vacancy `fill`/drop | `durable_host/keyvalue/caching.rs` | Ungated admitted plumbing. A `get-or-set` future or vacancy cannot exist without its original admission; the vacancy retains that permit through `fill` or drop and does not reauthorize after revocation. | -| P2 | `wasi:keyvalue/wasi-keyvalue-error.error.trace`; `[drop]` | `durable_host/keyvalue/error.rs` | Ungated local typed-error inspection/lifecycle. | -| P2 | `wasi:logging/logging.log` | `durable_host/logging/logging.rs` | Ungated logging by settled policy; must not include secrets/permission targets. | -| P2 | `wasi:config/store.get`; `get-all` | `durable_host/config/mod.rs` | **Config / `Read` / exact key**; `get-all` preflights/materializes only individually admitted keys. Denial uses existing `error.upstream("permission denied")`. | -| P2 | `golem:secrets/types.id`; `metadata`; `golem:secrets/reveal.reveal`; secret `[drop]` | `durable_host/secrets/mod.rs` | `reveal`: **Secret / `Reveal` / canonical key/version**. `id`/`metadata` are ungated inspection of an already admitted handle. **Secret / `Hold` / canonical config key** is checked before any host-to-guest handle transfer; drop is ungated. | -| P2 | `golem:rdbms/{postgres,mysql,ignite2}.connection.open` | `durable_host/rdbms/{postgres,mysql,ignite}.rs`, `rdbms/mod.rs` | Ungated parse-only local handle creation; it opens no connection, pool, client, or socket. The first statement or transaction begin performs admission before connection use. | -| P2 | `golem:rdbms/{postgres,mysql,ignite2}` connection/transaction `query`; `query-stream`; `execute`; `begin-transaction`; `commit`; `rollback` | `durable_host/rdbms/{postgres,mysql,ignite}.rs`, `rdbms/mod.rs` | **RDBMS / `Query` or `Mutate` / every parsed database/schema/table**; fail closed before connection use if complete extraction is impossible. Transaction commit/rollback inherit the transaction admission. | -| P2 | RDBMS result-stream `get-columns`; `get-next`; lazy value/type `new`; `get`; all RDBMS `[drop]` | same RDBMS files | Ungated admitted-result and local resource plumbing; no new SQL operation. | -| P2 | `golem:websocket/client.connect` | `durable_host/websocket/client.rs` | **Network / `Connect` / normalized URI host and effective port.** Denial uses existing `error.other("permission denied")`. | -| P2 | WebSocket connection `send`; `receive`; `receive-with-timeout`; `close`; `[drop]` | `durable_host/websocket/client.rs` | Ungated established connection I/O/lifecycle; inherits connect admission. | -| P2 | `golem:quota/types` token/reservation methods | `durable_host/quota/mod.rs` | Explicitly ungated quota-token plumbing; quota authority is carried by the token and validated by its existing service/lease rules, not a GOL-122 permission class. | -| P2 | `golem:agent/host.get-all-agent-types`; `get-agent-type`; `make-agent-id`; `parse-agent-id`; `create-webhook`; `get-config-value` | `durable_host/golem/agent.rs` | Discovery/ID parsing are ungated local metadata; `get-config-value`: **Config / `Read` / exact key**; `create-webhook`: **Agent / operation-specific webhook verb / promise resource** before external creation. | -| P2 | `golem:tool/host.get-all-tools`; `get-tool` | `durable_host/tool/mod.rs` | Ungated tool discovery metadata. | -| P2 | `golem:tool/host.tool-rpc.new`; `invoke`; `async-invoke-and-await`; `invoke-and-await`; future `get`; `cancel`; drops | `durable_host/tool/mod.rs` | Invoke variants: **Tool / `Invoke` / resolved command + arguments** before the invocation-backend handoff. Denials and the current unavailable-backend result are durable. `new`, future result access/cancel, and drops are local/admitted plumbing. Functional dispatch is owned by GOL-35. | -| P2 | `golem:permissions/inspect.inspect-card`; card metadata getters; `derive.derive`; `derive-from-wallet`; `derive-scope`; `revoke.revoke-card`; `wallet.self-wallet`; `self-version`; `install-card`; `kernel-introspection.list-modules`; `validate-grant`; drops | `durable_host/permissions/mod.rs` | **Already protected elsewhere:** existing card-specific authority checks (`CardVerb::Derive`, install/transfer and possession/ancestor revoke rules). Inspection/wallet/version/kernel validation and drops are card metadata/plumbing under those APIs, not silently omitted. | -| P2 | `golem:api/host` agent listing, promise operations, metadata/update/fork/revert/resolve operations | `durable_host/golem/v1x.rs` | Agent-observing/mutating operations: **Agent / matching operation-specific verb / target agent + method/index/invocation/plugin resource**. Legacy `get-agent-metadata` and `resolve-agent-id-strict` denial uses their existing `none` result; operations with result errors use `agent-operation-error.permission-denied`. Self-only oplog markers, idempotence mode/key generation, trap and promise-local plumbing are ungated. | -| P2 | `golem:api/oplog.get-oplog-index`; `set-oplog-index`; get/search iterator `new`; `get-next`; `enrich-oplog-entries`; drops | `durable_host/golem/v1x.rs` | Reads/search: **Oplog / `Read` / exact index or range** before service access. Iterator APIs return typed `oplog-read-error`; legacy enrichment preserves its string error and returns `"permission denied"`. Cursor setters and iterator reads inherit admission; drops are ungated. | -| P2 | `golem:api/retry.get-retry-policies`; `get-retry-policy-by-name`; `resolve-retry-policy`; `set-retry-policy`; `remove-retry-policy` | `durable_host/golem/retry_api.rs` | Ungated worker-local retry policy configuration; no gated external authority. | -| P2 | `golem:api/context` span/context getters/setters/start/finish/header forwarding and drops | `durable_host/golem/invocation_context_api.rs` | Ungated invocation tracing context plumbing. | -| P2 | `golem:durability/durability.observe-function-call`; `begin-custom-durable-invocation`; custom invocation `finish`; `[drop]` | `durable_host/durability.rs` | Ungated durability protocol plumbing; protected semantic operations authorize before durable `Start`. | -| P2 | `golem:schema/wire` conversion/transport functions | `golem-schema/src/schema/wit/mod.rs` | Ungated pure schema/value encoding and handle transport; handle authority remains with quota/secret/card APIs. | - -The outbound agent-RPC implementation is in `durable_host/wasm_rpc/mod.rs`; its invocation methods are -**Agent / `Invoke` / target agent owner + resolved method** and are gated at the caller before activation -or dispatch even though the low-level interface is reached through the registered agent host rather than -registered as a separate linker interface. Tool-RPC authorization is owned directly by -`durable_host/tool/mod.rs`; GOL-35 will attach functional dispatch after that boundary. - -Secret handles also cross host-to-guest boundaries that are not standalone linker imports. The complete -`Hold` admission set is: secret-backed agent config, live initialization/method input, synchronous and -future outbound-RPC results, tool success/custom-error results, and nested secret handles returned by a -reveal. Each live boundary authorizes the complete recursively discovered target set before durable -completion or guest resource minting. Completed replay remints only previously admitted snapshots and -does not consult current authority. - -**Exit criterion:** every registered host import has a row and an explicit disposition. - -## Milestone 1 — Define replay and denial durability - -### 1.1 Trusted replay - -- [x] Add an explicit replay path before permission-target construction. -- [x] During replay: - - return recorded host results where present; - - recreate local resources and streams as already admitted; - - never call `EffectiveSurface::authorize`; - - never check wall-clock expiration; - - never enter the authority synchronization boundary. -- [x] Ensure replay-created descriptors, streams, sockets, and pending operations carry reconstructed admission state when they later cross the live frontier. -- [x] Apply recorded card events only to reconstruct the wallet needed at the live frontier. -- [x] Avoid repeatedly deriving intermediate effective surfaces during replay; derive once after reconstruction or snapshot restoration. -- [x] Add a transition hook that synchronizes authority once before accepting the first new live operation. - -### 1.2 Durable denials - -A live denial is a host-call result, not an authorization event. - -- [x] For protected operations already using `CallHandle`, persist the compatible denial through their normal durable response envelope. -- [x] Ensure denial recording does not invoke the backend or mark the operation as admitted. -- [x] For protected operations without a durable response envelope, introduce the smallest operation-specific durable result at the semantic boundary. -- [x] For streams, record admission/denial at stream creation or operation start—not per chunk or poll. -- [x] Do not add a global `PermissionDecision` entry or record successful permission checks separately from the operation. -- [x] Ensure a snapshot contains enough resource/admission state to resume without reauthorization. -- [x] Ensure an incomplete operation whose live `Start` followed authorization remains admitted after recovery. - -### 1.3 Guest API errors - -- [x] Use existing standard errors: - - filesystem: `NotPermitted` - - sockets/DNS: `AccessDenied` - - HTTP: `HttpRequestDenied` - - RPC: `RpcError::Denied` -- [x] Reuse existing KV, blobstore, and secret typed errors. -- [x] Change agent `get-config-value` to return a typed result with `PermissionDenied`; keep shared `wasi:config/store.error` compatible and map denial to existing `Upstream("permission denied")`. -- [x] Use typed oplog errors for iterator APIs that previously could not represent denial; keep legacy `enrich-oplog-entries` on its existing string error. -- [x] Preserve legacy optional `get-agent-metadata` and `resolve-agent-id-strict`; map denial to `none` rather than widening either signature. -- [x] Preserve the WebSocket error variant; map connect denial to existing `Other("permission denied")`. -- [x] Preserve plain secret `id`/`metadata`; enforce `Hold` before the host transfers the handle instead of reauthorizing handle inspection. -- [x] Regenerate all affected WIT bindings and update callers. -- [x] Remove the possibility of representing policy denial as `anyhow` or a Wasmtime trap. - -**Exit criteria:** - -- A live denial followed by restart/replay returns the same non-trapping result without evaluating authority. -- An admitted incomplete call resumes without reauthorization. -- No successful permission check has its own oplog entry. - -## Milestone 2 — Add cancellation-proof authority invalidation - -The common live path cannot call the current expensive synchronization boundary on every operation. - -### 2.1 Per-worker generations - -- [x] Add a per-worker atomic `published_authority_generation`. -- [x] Add `processed_authority_generation` to durable worker state. -- [x] Keep the global authority-recovery open/closed gate separate. -- [x] Initialize restored workers as not ready for fast authorization until status/oplog reconciliation completes. - -### 2.2 Publisher integration - -For every authority-event producer: - -- [x] Append and durably commit the event. -- [x] Fold/publish worker status. -- [x] Release-publish the new worker generation from the commit/status actor. -- [x] Only then complete the producer request. - -Cover: - -- [x] card installation -- [x] revocation -- [x] transfer started -- [x] transfer received -- [x] transfer completion/confirmation -- [x] future direct wallet mutations - -Publication must happen inside cancellation-proof actor work, not in caller code after an awaited commit. - -### 2.3 Slow-path completion - -- [x] Keep `published != processed` for the entire synchronization operation. -- [x] Drain events to quiescence under the existing boundary lock. -- [x] Complete wallet mutation and corresponding terminal oplog records. -- [x] Refresh card interest. -- [x] Recompute invocation-scope state. -- [x] Rederive the effective surface only if wallet/scope contents changed. -- [x] Update the cached expiration deadline. -- [x] Adopt the latest published generation only after all state is coherent. -- [x] If another generation arrives during synchronization, continue draining before reopening the fast path. - -### 2.4 Expiration - -- [x] Cache the earliest live expiration among wallet cards and invocation-scope roots. -- [x] Fast path compares current time only with that deadline. -- [x] Scan/process expiration only when the deadline is due. -- [x] Publish/process expiration as an authority-state change before returning to the fast path. -- [x] Never use the wall clock for replay reconstruction. - -**Exit criteria:** - -- A committed event cannot exist without eventually making the generation stale. -- No fast path can observe a partially updated wallet or effective surface. -- One event burst causes one slow synchronization, after which calls return to the fast path. - -## Milestone 3 — Implement the live authorization API - -### 3.1 Direct context API - -Add a live-only API conceptually equivalent to: - -```rust -async fn authorize_live_permission( - &mut self, - target: &PermissionTarget, -) -> Result; - -async fn authorize_live_permissions( - &mut self, - targets: &[PermissionTarget], -) -> Result; -``` - -The exact error wrapper may need to preserve executor failures separately from policy denial. - -- [x] Assert or encode that these APIs cannot be used during replay. -- [x] Authorize directly against `state.agent_effective_surface`. -- [x] Do not construct `AuthCtx`. -- [x] Do not clone the effective surface. -- [x] Return a lightweight permit that proves one stable snapshot admitted the operation. -- [x] Permit lifetime does not retain the authority lock. - -### 3.2 Fast path - -Inside one stable state access: - -- [x] Verify execution is live and authority state is initialized. -- [x] Verify global authority is open. -- [x] Load published generation. -- [x] Verify `published == processed`. -- [x] Verify expiration is not due. -- [x] Authorize against the cached surface. -- [x] Recheck global-open and generation state. -- [x] If either check changed, discard allow or deny and enter the slow path. -- [x] Return policy denial only from a stable snapshot; a concurrent grant may invalidate a stale denial. - -### 3.3 Slow path - -- [x] Enter the existing serialized card-event boundary. -- [x] Wait for or recover authority if globally closed. -- [x] Synchronize events and expiration. -- [x] Authorize against the resulting surface while still at the boundary. -- [x] Release the lock before beginning the admitted operation. -- [x] Fail closed if authority cannot be recovered. - -### 3.4 P3 Accessor API - -- [x] Implement the same algorithm using one short `Accessor::with` window for fast authorization. -- [x] Add an Accessor slow path using existing serialized-access machinery. -- [x] Do not clone state out of the store to authorize. -- [x] Refactor protected `CallHandle::start_access` paths so an authorization permit prevents a second authority synchronization. -- [x] Remove unconditional authority synchronization from generic unprotected P3 calls. - -### 3.5 Observability - -- [x] Count slow-path refreshes and policy denials. -- [x] Do not render permission targets or emit per-allow logs on the hot path. -- [x] Do not attach resource names, secrets, or other high-cardinality values to metrics. - -**Exit criterion:** unchanged live authority requires no status/oplog/service I/O and no async authority mutex. - -## Milestone 4 — Centralize typed target construction - -Use the existing concrete classes rather than host-specific strings. - -### Target mapping - -| Class | Owner | Verbs/resources | -|---|---|---| -| Filesystem | agent owner | `Read`, `Write`, `List`, `Stat`, `Delete` + absolute guest path | -| Network | empty owner | `Connect` + normalized host/port | -| Env | agent owner | `Read` + variable name | -| KV | environment owner | `Read`, `Write`, `Delete`, `List` + store/key pattern | -| Blob | environment owner | `Read`, `Write`, `Delete`, `List` + bucket/key pattern | -| Secret | environment owner | `Hold` at host-to-guest handle admission and `Reveal` before plaintext access + canonical secret key path | -| Config | agent owner | `Read` + config key path | -| Oplog | agent owner | `Read` + index range | -| Agent | target agent owner | operation-specific `AgentVerb` + method/index/invocation/plugin resource | -| Card | account owner | existing permission-management targets | -| RDBMS | environment owner | `Query`/`Mutate` + database/schema/table | -| Tool | tool owner | `Invoke` + command/arguments | - -### Work items - -- [x] Add centralized builders using concrete `ClassPermissionTarget` types. -- [x] Cache monomorphized owner values in worker state where possible. -- [x] Do not re-parse rendered permission strings in host wrappers. -- [x] Reuse existing owned targets by reference before introducing borrowed target types. -- [x] Build all targets for a multi-resource operation before authorizing any of them. - -### Normalization - -- [x] Filesystem paths are canonical, absolute, guest-visible paths. -- [x] Reject attempts to escape the guest root through `..`, symlinks, or descriptor-relative paths. -- [x] Never expose executor temporary/backing paths to permission matching. -- [x] Normalize DNS/HTTP hostnames consistently in both card parsing and runtime target construction. -- [x] Normalize IPv4 and effective ports. -- [x] Decide how IPv6 is represented; the current host/port grammar does not support colon-containing hosts. -- [x] HTTP maps to the current network model's host/effective port; method and URI path are not permission resources unless the class is deliberately extended. -- [x] Use existing config/secret segment grammars. -- [x] Use exact KV store/key and blob bucket/key grammars. -- [x] Preserve typed oplog ranges rather than rendering them into strings. - -**Exit criterion:** no protected wrapper constructs a target with ad hoc formatting. - -## Milestone 5 — Key-value enforcement - -Files: - -- [`eventual.rs`](golem-worker-executor/src/durable_host/keyvalue/eventual.rs) -- [`eventual_batch.rs`](golem-worker-executor/src/durable_host/keyvalue/eventual_batch.rs) -- [`caching.rs`](golem-worker-executor/src/durable_host/keyvalue/caching.rs) - -- [x] `get`, `exists`, `get-many` → `KvVerb::Read`. -- [x] `set`, `set-many`, vacancy fill → `KvVerb::Write`. -- [x] `delete`, `delete-many` → `KvVerb::Delete`. -- [x] `keys`/listing → `KvVerb::List` with the exact store/prefix resource. -- [x] Cover caching `get`, `exists`, `set`, `get-or-set`, and `delete`. -- [x] Do not gate handle drops or completed-future reads. -- [x] Preflight every key in mutating batches under one authority snapshot. -- [x] A denied batch item prevents all backend calls. -- [x] Denied reads do not reveal existence. -- [x] Return existing typed KV denial. -- [x] Persist/replay denial through the operation's durable response. - -**Exit criterion:** backend call count is zero on denial and one on allow; no partial batch effects. - -## Milestone 6 — Blobstore and secrets - -### Blobstore - -Files: - -- [`blobstore/mod.rs`](golem-worker-executor/src/durable_host/blobstore/mod.rs) -- [`container.rs`](golem-worker-executor/src/durable_host/blobstore/container.rs) - -- [x] Read/get/has/info → `BlobVerb::Read`. -- [x] List → `BlobVerb::List`. -- [x] Write/create → `BlobVerb::Write`. -- [x] Delete/clear → `BlobVerb::Delete`. -- [x] Copy preflights source `Read` and destination `Write`. -- [x] Move preflights source `Read`/`Delete` and destination `Write`. -- [x] Multi-object deletion preflights all keys. -- [x] Carry admission into outgoing write streams/tasks. -- [x] Do not charge quota or contact storage before authorization. -- [x] Return existing typed blobstore denial. - -### Secrets - -File: [`secrets/mod.rs`](golem-worker-executor/src/durable_host/secrets/mod.rs) - -- [x] Apply `SecretVerb::Hold` at every host-to-guest handle admission/transfer boundary rather than on later handle inspection. -- [x] Recursively preflight all nested handles in config, invocation input, RPC/tool results, and revealed values under one stable authority snapshot. -- [x] Keep admitted `id` and `metadata` access direct and ungated; possession proves prior `Hold` admission. -- [x] Gate `reveal` with `SecretVerb::Reveal` before contacting the service. -- [x] Audit ID/metadata access for existence leakage: an unauthorized handle is never minted, while an admitted handle may expose only its non-plaintext identity/metadata. -- [x] Do not reveal whether a non-admitted secret exists. -- [x] Return existing `secret-error` for reveal denial and the enclosing operation's existing typed/optional error for `Hold` denial. -- [x] Never log the secret key or value on denial. - -**Exit criterion:** denied reveal causes no service call; denied `Hold` mints no guest resource and leaks no metadata. - -## Milestone 7 — Config, environment, and oplog - -### Config - -- [x] Change `get-config-value` WIT to a typed result. -- [x] Build `ConfigVerb::Read` target from agent owner and concrete key segments. -- [x] For secret-backed declarations, preflight `ConfigVerb::Read` and `SecretVerb::Hold` together before durable `Start` or handle minting. -- [x] Authorize before reading config or exposing whether the key exists. -- [x] Replay the recorded typed result without authorization. - -### Oplog - -- [x] Enumerate every guest-visible oplog read/search API. -- [x] Build `OplogVerb::Read` targets using the exact requested index/range. -- [x] Authorize before opening the oplog service or reading entries. -- [x] Change iterator APIs lacking any denial channel to typed results; preserve `enrich-oplog-entries` and its existing string error. -- [x] Ensure denied ranges reveal no entry count or boundary metadata. - -### Environment decision and implementation - -The original invocation-materialization design was rejected because it introduced a second environment -state into invocation start and snapshot/update/revert handling. Preserve the executor's established -durable environment lifecycle and make the standard P3 import async in the Golem Wasmtime fork instead. - -- [x] Remove invocation-start materialization, the invocation-scoped environment cache, - `AgentInvocationStarted.environment`, and snapshot save/load cache substitution from the design. -- [x] In the isolated `/Users/vigoo/projects/golem/wasmtime-gol122` checkout, mark - `wasi:cli/environment.get-environment` async and change the generated P3 host trait implementation to - `async fn`. `cargo fmt --all -- --check`, `cargo check -p wasmtime-wasi --features p3`, and - `git diff --check` pass there. -- [x] Make P2/P3 `get-environment` one ordinary durable host call that builds the existing enriched - environment, authorizes/filters every variable from one stable live authority view, and records the - filtered result with a dedicated append-only payload pair. -- [x] Replay the recorded environment result without live authorization or rebuilding the current - environment. -- [x] Add focused P2/P3 allow/deny, revocation, and replay tests proving denied variables are absent and - recorded results remain deterministic. -- [x] Arguments and current directory remain outside `EnvClass`. -- [x] Verify invocation start and snapshot/update/revert carry no GOL-122 environment cache or payload. - -**Exit criterion:** config/oplog denial is typed and environment never exposes a denied variable. - -## Milestone 8 — Outbound RPC and agent operations - -Files: - -- [`wasm_rpc/mod.rs`](golem-worker-executor/src/durable_host/wasm_rpc/mod.rs) -- [`golem/agent.rs`](golem-worker-executor/src/durable_host/golem/agent.rs) -- [`golem/v1x.rs`](golem-worker-executor/src/durable_host/golem/v1x.rs) - -- [x] Outbound invocation → `AgentVerb::Invoke` with target owner and method. -- [x] Map guest-accessible view/delete/interrupt/resume/fork/revert/cancel/plugin/debug operations to existing `AgentVerb` variants. Update/get-metadata/target-fork/revert, agent enumeration, self metadata, strict agent resolution, and self-fork are gated; focused legacy-host allow/deny coverage passes. -- [x] Authorize after the final target agent and resource are known. -- [x] Authorize before: - - target activation; - - scheduling; - - idempotency-key-backed request creation; - - durable `Start`; - - RPC dispatch. -- [x] Return `RpcError::Denied`. -- [x] Carry the permit into asynchronous dispatch. -- [x] Preserve downstream direct-invocation checks as defense in depth. -- [x] Verify caller-side enforcement uses the caller's wallet and invocation scope. - -**Exit criterion:** denied outbound calls never reach worker lookup, activation, scheduling, or transport. - -## Milestone 9 — P3 filesystem enforcement - -File: [`p3/filesystem.rs`](golem-worker-executor/src/durable_host/p3/filesystem.rs) - -### Resource metadata - -- [x] Associate descriptors with canonical guest-visible paths. -- [x] Preserve path metadata across descriptor duplication and replay reconstruction. -- [x] Associate admitted stream/task state with its path and permit. -- [x] Handle `/` and `.` preopens without authorizing against host backing paths. - -### Operations - -- [x] File/data reads → `Read`. -- [x] Directory enumeration → `List`. -- [x] Stat and metadata queries → `Stat`. -- [x] Create/open-for-write, write, truncate, set-size/times → `Write`. -- [x] Remove/unlink → `Delete`. -- [x] Open with multiple access flags preflights every required verb. -- [x] Rename preflights source `Delete` and destination `Write`. -- [x] Hard link preflights source `Read` and destination `Write`. -- [x] Symlink preflights the destination path and any source access required by the chosen semantic model. -- [x] Authorize before quota mutation, filesystem calls, piping, or task spawning. -- [x] Authorize once per admitted stream operation, not per chunk/poll. -- [x] Do not gate drop, polling, descriptor flags, or purely local resource inspection. -- [x] Return `NotPermitted`. - -### Tests - -- [x] Path traversal cannot escape the guest root. -- [x] Two-path operations are atomic with respect to permission preflight. -- [x] Revocation after stream admission does not cancel that stream. -- [x] A new stream after revocation is denied. -- [x] Replay-created streams are treated as previously admitted. - -**Exit criterion:** every filesystem effect has a canonical target and no denied operation touches the backing filesystem. - -## Milestone 10 — P3 network, DNS, and HTTP - -### DNS - -- [x] Normalize hostname before authorization. -- [x] Map resolution to the current network `Connect` policy, or add a distinct verb during Milestone 0. -- [x] Authorize before resolver activity. -- [x] Return `AccessDenied`. - -### TCP - -- [x] Authorize the normalized remote host/port before connect. -- [x] Treat successful connection admission as covering that connection's lifetime. -- [x] Store endpoint/admission metadata on the socket and derived streams. -- [x] Do not reauthorize individual send/receive chunks under the current `Connect` model. -- [x] Do not gate polling or socket drops. -- [x] Implement the Milestone 0 bind/listen decision. - -### UDP - -- [x] Connected UDP socket: authorize the connected endpoint once. -- [x] Unconnected `send-to`: authorize each new destination as a semantic operation. -- [x] Carry admission into the send task. -- [x] Decide whether repeated sends to the same endpoint reuse admission or represent new operations. -- [x] Return `AccessDenied`. - -### HTTP - -File: [`p3/http/send.rs`](golem-worker-executor/src/durable_host/p3/http/send.rs) - -- [x] Parse and normalize final URI host and effective port. -- [x] Build `NetworkVerb::Connect` target. -- [x] Authorize before: - - quota charging; - - pending-transmission state mutation; - - body/resource consumption; - - connection-pool activity; - - durable `Start`; - - request conversion or dispatch. -- [x] Carry the permit into the transmission task. -- [x] Authorize each redirect destination before dispatching it. -- [x] Return `HttpRequestDenied`. -- [x] Do not include method/path in the target unless the permission class is intentionally extended. - -**Exit criterion:** denied network/HTTP operations produce no DNS, socket, pool, quota, or transmission activity. - -## Milestone 11 — Remaining classes and complete audit - -### Permission cards - -- [x] Audit existing [`permissions/mod.rs`](golem-worker-executor/src/durable_host/permissions/mod.rs) checks against the new live boundary. -- [x] Reuse the shared helper where it removes duplicated synchronization. -- [x] Do not rewrite already-correct card algebra or lifecycle behavior. - -### RDBMS - -- [x] Determine tables touched by each statement. -- [x] Map read-only statements to `Query`. -- [x] Map mutations/DDL to `Mutate`. -- [x] Preflight every referenced table. -- [x] Reject statements whose resource set cannot be determined safely. -- [x] Cover PostgreSQL, MySQL, and Ignite consistently. -- [x] Authorize before connection use, statement preparation, transaction mutation, or quota charging. - -### Tools - -- [x] Locate the registered `golem:tool/host.tool-rpc` authorization boundary. -- [x] Build exact `ToolVerb::Invoke` targets from the resolved command path and canonical arguments. -- [x] Authorize before the invocation-backend handoff (and therefore before future entity/RPC/task creation in GOL-35). -- [x] Return a typed `RpcError::Denied` and persist it through the invocation's durable response. -- [x] Cover `invoke`, `async-invoke-and-await`, and `invoke-and-await` with durable typed-denial tests; verify a grant passes authorization and reaches the current unavailable-backend result rather than `Denied`. -- [x] Behavioral denial test resolves a bound tool, performs exactly one authority check, returns typed `RpcError::Denied`, and confirms no tool worker is activated (`tmp/gol122-denied-tool-invocation.log`). -- [x] Keep functional dispatch out of GOL-122; it is owned by GOL-35. - -### Final linker audit - -- [x] Revisit every P2/P3 linker registration. -- [x] Confirm every protected import has an enforcement test. -- [x] Confirm every intentionally ungated import has a reason in the matrix. -- [x] Confirm no alternate linker path bypasses wrappers. - -## Milestone 12 — Test suite - -### Permission algebra and target tests - -- [x] Owner and resource matching for every enforced class. -- [x] Lower OR semantics. -- [x] Upper AND semantics. -- [x] Negative grants. -- [x] Invocation-scope narrowing. -- [x] Wildcards, path globs, ranges, and port ranges. -- [x] Filesystem and network normalization. -- [x] Multi-target all-or-nothing authorization. - -### Authority-boundary tests - -- [x] Unchanged generation uses the no-I/O fast path. -- [x] Event generation forces exactly one slow refresh. -- [x] Concurrent generation change invalidates an in-progress allow. -- [x] Concurrent installation invalidates an in-progress deny. -- [x] Event publication survives producer cancellation. -- [x] Closed authority never allows. -- [x] Expiration is visible at the first due live boundary. -- [x] Revocation after admission does not cancel the admitted operation. -- [x] Replay never invokes the authorization helper. - -### Wrapper tests - -For each family: - -- [x] allow calls backend exactly once -- [x] deny calls backend zero times -- [x] denial uses the operation's compatible typed, string, or optional channel; no trap -- [x] no quota/resource/task mutation before allow -- [x] no unauthorized existence leakage -- [x] admitted task retains permit -- [x] new task after revocation is denied - -Closure evidence combines family-specific wrappers with the shared authority-boundary tests rather than -duplicating the same generation/revocation test for every class. Every protected import has a compatible -non-trapping denial probe, so a trap fails the test. Countable backends verify one TCP connection, one secret revision -lookup, and zero denied TCP connections, secret lookups, tool activations, or filesystem effects. KV and -blob multi-item mutations verify that one denied target leaves every allowed target untouched. Environment, -config, secret, filesystem, and owner-isolation probes verify absence/no-existence-leak behavior. Filesystem -streams, TCP connections, RDBMS transactions, cache vacancies, and blob read streams verify inherited -admission; the latter two are explicitly suspended, revoked, resumed successfully, then followed by denied -new work. Synchronous no-task families have no admitted resource to retain, and established TCP/WebSocket -I/O is intentionally ungated after connection admission. Shared generation tests plus per-family default-deny -probes cover post-revocation new operations without repeating the same authority transition in every wrapper. - -### Replay and recovery tests - -- [x] Live denial replays through the same compatible host-result channel after wallet changes. -- [x] Successful operation replays without permission evaluation. -- [x] Snapshot restore treats reconstructed resources as admitted. -- [x] Incomplete admitted operation completes without reauthorization. -- [x] First new operation after replay-to-live synchronizes and enforces current authority. -- [x] Replay does not consult current time or live card services. - -### Integration tests - -Extend: - -- [`scope_cards.rs`](golem-worker-executor/tests/scope_cards.rs) -- [`permissions.rs`](integration-tests/tests/permissions.rs) - -Cover: - -- [x] allow/deny for every confirmed host-facing class -- [x] invocation scope narrowing -- [x] revocation between operations -- [x] expiration between operations -- [x] owner isolation -- [x] recipient/holder isolation through effective-surface derivation -- [x] suspend/resume -- [x] crash/replay -- [x] snapshot/recovery -- [x] concurrent P3 operations - -## Milestone 13 — Performance validation - -### Structural requirements - -- [x] Replay constructs no permission targets and performs no checks. -- [x] Stable live call performs no status/oplog/service I/O. -- [x] Stable live call acquires no async authority mutex. -- [x] P3 stable call uses one short Accessor state window. -- [x] Effective surface is borrowed, not cloned. -- [x] `AuthCtx` is not created. -- [x] Existing resource handles reuse normalized metadata. -- [x] Streams authorize once per semantic operation, not per chunk/poll. -- [x] Batch operations cross one authority snapshot. -- [x] Successful authorization emits no logs or rendered targets. - -### Benchmarks - -- [x] Baseline representative host wrappers before enforcement. -- [x] Stable allow and stable deny. -- [x] Slow path with one event and an event burst. -- [x] Wallets with small, medium, and large grant counts. -- [x] Single-key and batch KV. -- [x] Filesystem open and stream creation. -- [x] TCP connect and HTTP dispatch wrapper overhead. -- [x] Record p50/p95 and allocation counts. -- [x] Benchmark before introducing borrowed request types or class indexing. -- [x] Add class-indexed grant surfaces only if algebra scanning remains material after synchronization overhead is removed. The measured matcher does not justify an index. - -Post-fix distribution evidence (`tmp/gol122-authorization-bench.log`): - -```text -stable TCP allow (64 grants): p50 1.292µs, p95 1.750µs, 0 allocations -stable TCP deny (64 grants): p50 1.167µs, p95 1.667µs, 0 allocations -filesystem open: p50 41ns, p95 42ns, 0 allocations -KV single key: p50 41ns, p95 42ns, 0 allocations -one-generation refresh: p50 1.167µs, p95 1.709µs, 0 allocations -eight-event refresh burst: p50 1.208µs, p95 1.834µs, 0 allocations -``` - -**Exit criterion:** measured hot-path cost consists only of state validation, target matching, and the existing short store-access window. - -## Recommended implementation sequence - -1. Milestone 0: freeze scope and matrix. -2. Milestone 1: replay/denial contracts and WIT changes. -3. Milestones 2–3: generation fast path and authorization permit. -4. Milestone 4: typed target construction. -5. Milestones 5–8: non-P3 service-backed imports. -6. Milestone 7 environment decision. -7. Milestone 9: filesystem. -8. Milestone 10: DNS/sockets/HTTP. -9. Milestone 11: RDBMS/tools decision and final import audit. -10. Milestones 12–13: integration, recovery, and performance validation. - -## Definition of done - -GOL-122 host-call enforcement is complete when: - -- every protected live host operation is authorized against one stable effective surface; -- replay performs no permission checks; -- all live denials replay through their compatible typed, string, or optional host result; -- denied calls create no external or local effect; -- multi-resource operations are fully preflighted; -- revocation/expiration is visible at the next new live semantic operation; -- previously admitted operations survive later revocation; -- every registered import is either tested as protected or explicitly classified as ungated; -- the unchanged-authority hot path has no I/O or async authority lock; -- targeted executor and integration tests, formatting, and lint checks pass. diff --git a/gol-33.md b/gol-33.md deleted file mode 100644 index 3dce6b595e..0000000000 --- a/gol-33.md +++ /dev/null @@ -1,1322 +0,0 @@ -# GOL-33 — Tool sidecar instances in the worker executor - -## Document status - -| Field | Value | -|---|---| -| Status | Detailed design draft, revised to maximize reuse of existing durable execution machinery | -| Date | 2026-08-17 | -| Scope | Runtime identity, entity slots and transient instances, invocation durability, owner-oplog replay, shared filesystem, lifecycle, resource management, and observability | -| Primary issue | [GOL-33](https://linear.app/golem-cloud/issue/GOL-33/toolmiddleware-instances-as-child-instances-of-agents-in-the-executor) | -| Depends on | GOL-29 tool deployment metadata; GOL-30 tool discovery | -| Enables | GOL-35 tool invocation; GOL-38 oplog tooling | -| Designed for | GOL-39/GOL-438/GOL-439 tool-middleware metadata, discovery, and invocation | - -## Summary - -An agent remains the unit of durable identity, placement, lifecycle, quota ownership, filesystem -ownership, and oplog ownership. A running agent is represented by an owner group containing: - -- one primary `Worker`, which executes the agent component and is externally unchanged; -- zero or more short-lived entity instances for tools and future tool middlewares, driven by the - same Store-hosting instance layer the primary already uses internally; -- one owner execution log and replay cursor shared by the primary and all entity instances; -- owner-scoped resources, including one logical filesystem and one execution lane that serializes - filesystem-capable guest bodies. - -`AgentId` and `ParsedAgentId` remain unchanged. New types pair the owner with an entity selector and, -when executing a call, the owner-oplog index that durably identifies that invocation. - -The design deliberately separates two identities: - -1. **Entity identity:** `(owner, entity)`. It addresses per-entity runtime metadata and — as a - future optimization — an optional warm Wasmtime instance. -2. **Logical durability identity:** `(owner, entity, invocation start index)`. It identifies one - tool or middleware invocation and all nested durable work performed by it. - -Tools and tool middlewares are stateless by product contract. The initial implementation creates a -fresh Store for every entity invocation and drops it afterwards; nothing ever depends on entity -memory surviving between calls. Warm-instance reuse is specified as a compatible optimization behind -the same identities, not built initially. A new live invocation always starts logically fresh and -never replays the entity's past invocations to recover tool state. - -All durable records produced while an entity executes belong to the owning agent's oplog. There are -no child oplogs, child status stores, durable child catalogs, or other execution histories. Entity -metadata and entity-specific oplog APIs are projections over the owner oplog plus current in-memory -cache state. - -Owner replay treats tool calls differently from ordinary remote calls. Encountering a completed tool -invocation executes that tool body again. Nested external durable operations consume their recorded -results, while non-persisted local effects such as filesystem operations execute again against the -owner's clean reconstructed filesystem. The currently incomplete invocation follows the same replay -until its recorded prefix ends, then continues live. - -Concurrency is governed solely by filesystem capability; invocations of the same entity are never -artificially serialized, because each runs in its own fresh Store and shares nothing. Every -invocation is classified as filesystem-capable or filesystem-incapable from durably pinned -activation inputs: the -primary is always filesystem-capable, and an entity is filesystem-capable only when its declaration -explicitly enables filesystem access or — absent an explicit setting — its activation declares -provisioned files, which imply it. A denied entity's Store -receives no preopened directories, so it cannot reach the owner root by construction — the -classification never depends on analyzing or pruning WASI imports. Filesystem-capable guest bodies -execute on one owner filesystem lane whose transfer points are causal and durable, so filesystem -effects are deterministic and replay needs no extra ordering records. Filesystem-incapable bodies — -expected to be the common case for tools such as web search — overlap freely with the lane holder -and each other in every call mode. Overlapping **filesystem-capable** execution, together with the -oplog-recorded ordering entries it requires, is specified as a compatible append-only extension and -deliberately not part of the initial implementation. - -## Hard constraints - -1. The owner oplog is the single source of truth for agent and entity execution. -2. No separate filesystem history, child oplog, or side-channel durable execution log is introduced. -3. Filesystem contents remain reconstructed by guest replay, as they are today. -4. Tool and middleware state does not persist semantically across invocations. -5. `AgentId` and `ParsedAgentId` continue to identify and parse only the owner agent. -6. Sidecars never change routing or shard selection and never outlive the owner. - -## Goals - -1. Activate component-implemented tools lazily next to their calling agent. -2. Execute each entity invocation in a fresh sidecar Store whose existence is never durable state. -3. Give each entity invocation a stable owner-oplog identity. -4. Replay completed entity invocations to reconstruct non-persisted local side effects. -5. Resume an incomplete entity invocation from its nested durable records. -6. Maximize reuse of the existing oplog, concurrent durability, replay, `DurableWorkerCtx`, Worker - instance layer, Wasmtime, and admission machinery. -7. Keep existing agent APIs, `AgentId` semantics, and primary storage shapes unchanged — as a - design-simplicity choice, not a backward-compatibility obligation (see Compatibility and - rollout). -8. Share one logical filesystem while retaining separate Store-local WASI resources. -9. Keep filesystem replay deterministic by serializing filesystem-capable guest bodies on one owner - lane, while filesystem-incapable tool bodies overlap freely in all call modes. -10. Account entity Store memory against owner limits without new eviction machinery. -11. Make middleware use the same identity, invocation scope, serialization, replay, and filesystem - paths. - -## Non-goals - -- Backward compatibility with previously persisted state: oplogs, statuses, and metadata written - before this feature do not need to remain replayable or decodable, and no migration path or - mixed-version executor support is required. -- Implementing the public `tool-rpc` WIT surface or result/error mapping; GOL-35 owns that wiring. -- Defining middleware metadata or chain traversal; GOL-39, GOL-438, and GOL-439 own those features. -- Detecting or rejecting stateful tool implementations at runtime. -- Warm entity-instance caching in the initial implementation; it is specified as a future - optimization behind unchanged identities. -- Overlapping filesystem-capable entity execution in the initial implementation; the required - oplog-recorded ordering is specified as a future extension. -- Giving entities independent public lifecycle, routing, persistence, or scheduling identities. -- Sharing a `WasiCtx`, `ResourceTable`, descriptor, stream, or Wasmtime Store between entities. -- Persisting filesystem bytes or read results beyond the records already used by current replay. -- Redesigning caller-readable tool streams tracked by GOL-337. - -## Terminology - -| Term | Meaning | -|---|---| -| Owner | The real agent identified by the existing `OwnedAgentId` | -| Entity | A named tool or named tool middleware | -| Entity ID | Owner plus entity selector; addresses per-entity runtime metadata and any future warm instance | -| Entity invocation | One call into one entity, identified by its owner-oplog `Start` index | -| Invocation scope | Per-call identity, activation, principal, and durable parent installed while an entity export runs | -| Primary | The owner's long-lived agent Worker | -| Entity instance | A short-lived sidecar Store driven by the shared instance layer for one invocation; carries no cross-call durable state | -| Owner lane | The single execution lane serializing filesystem-capable guest bodies (the primary and filesystem-granted entities) at causal, durable transfer points | -| Filesystem-capable | An invocation whose pinned activation carries an explicit filesystem grant or, absent one, declares provisioned files; the primary is always filesystem-capable | -| Filesystem-incapable | An entity invocation whose activation carries no filesystem grant (explicit denial or the deny default); its Store has no preopens and cannot reach the owner root | -| Owner execution | The oplog, replay cursor, filesystem, lifecycle, and resource accounting shared by the group | - -## Required invariants - -1. Every entity slot and invocation has exactly one owner. -2. A sidecar is never shared by two owners, even when they invoke the same registered component. -3. `AgentId` never contains an entity selector. -4. Sharding, routing, deletion, suspension, and quota ownership use only the owner. -5. A live entity invocation has one identity derived from its owner-oplog `Start` index. -6. Every nested durable operation performed by an entity is attributable to that invocation. -7. The owner oplog contains all durable facts needed to replay the owner and its entities. -8. An entity Store is transient; dropping it loses no durable state. A future warm cache must keep - this invariant. -9. Replaying a completed entity invocation reruns its body to reconstruct local side effects. -10. Replaying nested external effects consumes the recorded result instead of repeating the effect. -11. The current incomplete invocation replays its recorded prefix before continuing live. -12. Until the overlap extension exists, every filesystem-capable guest body in the group executes - on the owner lane at causal, durable transfer points; filesystem-incapable bodies may overlap - freely, including concurrent invocations of the same entity. -13. Every Store owns its own `WasiCtx`, `IoCtx`, `ResourceTable`, descriptors, and streams. -14. Every Store in the group resolves filesystem operations against the same owner root. -15. Replay always reconstructs that root from a clean, fenced materialization. -16. When filesystem-capable executions overlap, their physical filesystem order is recorded in the - owner oplog and reproduced during replay. -17. Code executing in an entity observes the calling owner through agent and secret host APIs. -18. Entity authority is no greater than the owner's effective authority. -19. Entity memory is admitted and accounted, but an entity consumes no separate concurrent-agent - permit. -20. Every source of nondeterminism inside an entity body — time, randomness, environment reads, - external effects — is intercepted by the same durable host functions as in the primary; - replay-body correctness depends on it. -21. Filesystem capability is decided from the pinned activation (explicit filesystem grant or - denial plus provision - declarations), never from WASI import analysis; the verdict is persisted in the activation - snapshot and replay uses the persisted value; a denied entity's Store receives no preopens, - making the classification true by construction. - -## Current implementation constraints - -The current executor assumes one `OwnedAgentId` identifies all of the following: - -- the active Worker and invocation queue; -- executable component lookup; -- the oplog and shared `ReplayState` cursor; -- status, pending work, promises, and scheduled actions; -- the local filesystem directory and storage meter; -- resource limits, events, and host identity. - -An entity executes a component different from `AgentId.component_id` and needs a per-call principal, -but it must not become another durable agent. The refactor must therefore separate **owner**, -**executable**, **cache entity**, and **current invocation scope** without cloning the whole durable -Worker model. - -The current `Worker` struct is dominated by owner-lifecycle machinery: the external invocation -queue, status flusher and checkpointer, the worker-state actor, snapshot policy, OOM retry, -interruption handling, and status publication. Entities must have none of that. The Store-driving -core a sidecar actually needs — component activation, Store construction, memory-grant attachment, -trap classification, and export invocation — already exists inside `Worker`'s internal instance -layer (`create_instance` and the running-instance state). The refactor reuses that inner layer -directly instead of making `Worker` itself bimodal. - -The current `DurableWorkerCtx` owns an `Arc` and a cloneable `ReplayState` whose cursor is -already shared internally. The concurrent durability implementation already supports eager `Start` -entries, nested `parent_start_index` relationships, initiation-ordered append, out-of-position -claiming, and terminal resolution. These are the foundations for entity execution in the owner oplog. - -The current filesystem intentionally persists very little. Resource-producing calls such as -`open_at` and `read_via_stream` execute again during replay to rebuild each Store's resource table. -File reads record scheduling-sensitive lengths but derive bytes again from the reconstructed root. -The sidecar design preserves that model. - -## Identity model - -### Entity selector - -Add an extensible selector without modifying `AgentId`: - -```rust -#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub enum AgentEntity { - Tool(ToolName), - ToolMiddleware(ToolMiddlewareName), -} -``` - -The primary does not need an entity selector. Where a type must represent either primary or sidecar, -use an explicit wrapper rather than `Option`: - -```rust -pub enum OwnerRuntime { - Agent, - Entity(AgentEntity), -} -``` - -The tagged selector prevents a tool and middleware with the same text from colliding and gives future -entity categories an explicit compatibility boundary. - -### Entity identity - -```rust -#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct OwnedAgentEntityId { - pub owner: OwnedAgentId, - pub entity: AgentEntity, -} -``` - -This ID addresses per-entity runtime metadata and an entity-filtered owner-oplog view. It is not another `AgentId`, routing key, oplog storage key, or promise namespace. - -`ParsedAgentId` parses the owner once. The parsed owner context is passed into entity activation and -host-call principal construction. - -### Invocation identity - -```rust -#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct EntityInvocationId { - pub entity_id: OwnedAgentEntityId, - pub start_index: OplogIndex, -} -``` - -The `start_index` is the index assigned to the owner-oplog `Start` for the tool or middleware call. -It is unique within the owner, stable on replay, and available before child dispatch. If the durable -scope's `begin_index` differs from the host-call `Start` index, persist/link both explicitly: use the -existing begin index for idempotency derivation and the host-call Start as the entity invocation and -nested-parent identity. - -For middleware, each chain-layer invocation receives its own nested `Start` and therefore its own -`EntityInvocationId`. The parent relationship identifies the outer tool call or previous middleware -layer. - -### Executable and activation snapshot - -Entity identity must not imply which component to load: - -```rust -pub struct ExecutableTarget { - pub component_id: ComponentId, - pub component_revision: ComponentRevision, -} - -pub struct EntityActivation { - pub executable: ExecutableTarget, - pub deployment_revision: DeploymentRevision, - pub policy: EntityActivationPolicy, - pub filesystem: FilesystemCapability, - pub fingerprint: EntityActivationFingerprint, -} - -pub enum FilesystemCapability { - Capable, - Incapable, -} - -pub enum EntityActivationPolicy { - Tool { - provision: ToolProvision, - binding: CompiledToolBinding, - }, - ToolMiddleware { - provision: ToolMiddlewareProvision, - binding: CompiledToolMiddlewareBinding, - }, -} -``` - -The live call resolves one coherent registered-tool/binding snapshot. The owner-oplog `Start` request -persists the exact replay-relevant subset. Replay never consults the current deployment to decide -which historical component, provision data, binding parameters, or secret policy to use. - -Middleware activation later produces the same generic structure with its middleware-specific -compiled policy. - -### Invocation scope - -Each entity export executes with an explicit scope: - -```rust -pub struct EntityInvocationScope { - pub invocation_id: EntityInvocationId, - pub parent_start_index: OplogIndex, - pub activation: Arc, - pub calling_principal: CallingAgentPrincipal, - pub mode: InvocationExecutionMode, -} - -pub enum InvocationExecutionMode { - Live, - ReplayingCompleted, - ReplayingIncomplete, -} -``` - -The scope is installed only for the duration of one export call. Nested durable host calls inherit -`parent_start_index`. Agent identity, config, secrets, audit attribution, and quotas resolve through -`calling_principal`; component loading resolves through `activation.executable`. - -## Active-agent ownership model - -Rename the conceptual active-worker service to `ActiveAgents` and key it by `OwnedAgentId`: - -```rust -pub struct ActiveAgent { - owner_id: OwnedAgentId, - primary: Arc>, - entities: Mutex>>, - execution: Arc, - resources: Arc, - lifecycle: OwnerLifecycle, -} - -pub struct OwnerExecution { - oplog: Arc, - replay: ReplayState, - commit: Arc, - lane: OwnerLane, -} -``` - -`OwnerExecution` is the only durable execution stream for the group. Entity instances receive the -same oplog and cloned shared replay cursor as the primary. `OwnerCommitController` commits the owner -oplog and publishes owner status without acquiring or polling the primary Store. An entity may be -executing while the primary Store is blocked awaiting it, so routing entity commits back through a -primary Store lock would deadlock. `OwnerLane` serializes filesystem-capable guest bodies; see the owner -filesystem lane section. - -### Entity slots - -An entity slot is an in-memory registry entry for one `(owner, entity)`: it tracks the entity's -currently active invocations for metadata, telemetry, and lifecycle fencing, and it is where the -future warm-cache extension anchors an idle cached instance. It is **not** a serialization boundary. - -Because every invocation runs in its own fresh Store and tools are stateless by contract, two -concurrent invocations of the same entity share no local state and need no mutual exclusion. Their -overlap is governed by exactly the same rule as everything else in the group: filesystem-incapable -invocations overlap freely; filesystem-capable invocations serialize on the owner filesystem lane, -which is entity-agnostic and would serialize them even if they belonged to different entities. - -Rules: - -- each invocation constructs and owns its own instance; same-entity invocations never queue behind - each other; -- activation failure fails only its own invocation and leaves concurrent invocations of the same - entity untouched; -- no slot state is persisted; -- an invoking instance is never independently evicted or replayed. - -Replay needs no per-slot ordering: each invocation is identified by its durable Start index, its -nested records are consumed by initiation identity and out-of-position claiming, and any -filesystem-relevant ordering is already fixed by the lane. - -One reentrancy shape deadlocks and must be detected through invocation ancestry: a synchronously -awaited call from an entity back into its own owner — for example through `golem:agent/host` -self-invocation — would wait on a primary Store that is itself blocked awaiting the entity, and -returns an explicit would-deadlock error. A synchronous self-call into the same entity is **not** a -deadlock: it creates another fresh instance and runs; if the entity is filesystem-capable, the lane -reaches the inner call through ordinary causal transfer along the blocking chain. Unbounded -self-recursion is bounded by memory admission and owner resource limits, like any other runaway -guest behavior. - -### Fresh instances now, warm reuse later - -The initial implementation constructs a fresh entity instance per invocation and drops it when the -call completes. This keeps the slot trivial, removes idle-eviction machinery, and makes the -stateless contract physically true. Wasmtime instantiation from the shared compiled-component cache -is cheap; a warm cache should be built only if measurement shows instantiation cost matters. - -The identity model already anticipates warm reuse: caching by `(owner, entity)` while keeping the -durability identity per invocation preserves the Wasmtime instantiation optimization, avoids -replaying earlier invocations merely to create a new live call, and isolates all durability in a -short-lived invocation scope. The cache must remain a cache, never a lock: it holds at most one idle -instance, and a concurrent same-entity call that finds it taken constructs a fresh instance instead -of queueing, so warm reuse never changes observable concurrency. Reusing a Store would mean hidden guest memory remains physically -present; the stateless tool contract states that outputs and side effects cannot depend on it, and -the runtime does not attempt to reset or verify it. None of this changes any oplog identity, so the -optimization can be added later without touching durability. - -## Instance layer instead of a bimodal Worker - -`Worker` stays what it is today: the owner-only object that owns the invocation queue, status -publication, snapshotting, interruption, and recovery for one agent. It does not gain an entity -role. Making `Worker` bimodal would drag its owner-lifecycle machinery — queue, status flusher and -checkpointer, state actor, snapshot policy, OOM retry — into every sidecar in a permanently disabled -state, and every future `Worker` change would have to reason about both modes. - -Instead, extract the Store-driving core that `Worker` already contains internally into a shared -instance layer: - -```rust -pub struct InstanceHost { - owner_id: OwnedAgentId, - executable: ExecutableTarget, - owner_execution: Arc, - owner_resources: Arc, - // Extracted Store construction, component activation, memory-grant - // attachment, trap classification, and export invocation machinery. -} -``` - -- The primary `Worker` becomes one consumer of the instance layer; its external behavior, storage, - and status are unchanged. -- An entity invocation constructs an `EntityInstance` on the same layer directly, with no queue, - status record, state actor, snapshot policy, or independent recovery — those concerns simply do - not exist on the shared layer. - -An entity instance exposes one internal operation, `invoke_scoped(scope, function, input)`, which: - -1. registers the invocation in its entity slot; -2. installs the invocation scope in its `DurableWorkerCtx`; -3. invokes the selected export; -4. clears per-call host state and the scope on return; -5. drops the Store, or — with the future warm-cache extension — returns it to the slot as a - stateless optimization. - -Entity instances still use existing component compilation, Store creation, resource limiting, trap -handling, metrics, and export invocation code, because those live in the extracted layer. The -primary and entity `DurableWorkerCtx` values are the same type attached to the same -`OwnerExecution`; nested durability, clock/random interception, and oplog attribution come from the -existing context implementation unchanged. - -## Filesystem capability classification - -Every invocation is classified before dispatch from inputs that are already durably pinned in its -activation: - -- the **primary** is always filesystem-capable — existing agent components use the filesystem - without restriction; -- an **entity** is filesystem-capable when its compiled binding carries an **explicit filesystem - grant**, or — when the declaration says nothing either way — its activation declares provisioned - files, whose activation-time writes touch the owner root regardless of what the guest body does; -- otherwise the entity is **filesystem-incapable**, enforced by construction: its Store is built - with no preopened directories. Whatever the component imports, guest code has no descriptor from - which to reach the owner root; filesystem attempts fail inside the guest with ordinary errors, not - traps. - -The user-level control is the explicit grant, not the presence of initial files. The tool or -middleware declaration (and, where bindings can narrow it, the per-agent-type binding) carries a -tri-state filesystem-access setting: - -- **allowed** — the entity is filesystem-capable whether or not files are provisioned; -- **denied** — the entity is filesystem-incapable; combining an explicit denial with declared - provisioned files is a contradiction (activation must write those files to the owner root) and is - rejected as a deterministic validation error when the deployment is compiled, never silently - overridden at runtime; -- **unset** — the default applies: filesystem-incapable, unless the activation declares provisioned - files, which imply the grant. - -The exact metadata and manifest surface of this setting belongs to GOL-29 (deployment metadata and -capability narrowing, where a binding may narrow — deny — but never widen the declared access); -GOL-33 only consumes the compiled verdict. A tool that needs scratch space but ships no initial -files sets **allowed** explicitly instead of attaching a dummy file. - -Classification deliberately does **not** use WASI import analysis. Real toolchains link -`wasi:filesystem` imports from libc and runtime glue even when the tool logic never touches a file, -and reliably pruning those imports is an open research problem that may never fully succeed. Import -pruning, if it matures, only improves ergonomics — for example suggesting that a binding can deny -filesystem — and never carries correctness weight. - -The verdict is computed once, at live dispatch, from the binding and provision data, and is -persisted as `FilesystemCapability` inside the activation snapshot in the invocation's `Start` -request. Replay reads the persisted verdict instead of re-deriving it, so a later change to the -classification rule — a new default, a new capability kind — can never re-classify a historical -invocation and silently change its replay scheduling. - -The default for an unset declaration is **deny**: tools are stateless by contract, most tools do -not need scratch files, and default-deny makes the common tool (search, HTTP APIs) overlap-eligible -without any declaration. Provisioned files lift the default only because activation physically must -write them; they are an implication, not the control surface. - -## Owner filesystem lane - -`OwnerLane` is the rule that at most one **filesystem-capable** guest body in the group executes at -a time, and that the lane changes hands only at causal, durable transfer points. -Filesystem-incapable bodies run off-lane: they overlap freely with the lane holder and each other in -every call mode, and their nested durable records use the existing concurrent durability machinery — -eager Starts, initiation-ordered append, out-of-position claiming — unchanged, because they share no -local state with anyone. - -Lane transfer for filesystem-capable bodies: - -- **Synchronous call:** the caller yields the lane at the entity-invocation `Start` and receives it - back at the terminal; middleware chains nest this recursively. -- **Asynchronous call:** the `Start` is appended eagerly as usual, but the body does not begin - executing; it queues for the lane. The lane is granted when the current holder becomes causally - blocked on that invocation — a `get` or poll of its future, directly or through a transitive - synchronous chain — or, for calls never awaited (fire-and-forget), at the holder's current - invocation end. -- **Eligibility order:** when several queued filesystem-capable bodies become eligible at one point - (a poll over several futures, several fire-and-forget calls at invocation end), the lane is - granted in ascending durable `Start` order. -- **Lane inheritance:** the holder grants the lane along its transitive blocking chain, so a - primary blocked on a filesystem-incapable tool that synchronously calls a filesystem-capable tool - does not deadlock. -- **No transfer on unrelated waits:** a holder awaiting an external durable effect (an HTTP call, an - RPC) keeps the lane. During replay that wait does not occur — the result is recorded — so - transferring there would create a live/replay scheduling divergence. This is precisely the failure - mode described in the filesystem section. - -Every transfer point above is either an owner-oplog record or a deterministic point in guest -execution, so the schedule of filesystem-capable bodies is a pure function of oplog contents plus -deterministic guest code. Replay reproduces it with no scheduler state, ordering entries, or -arrival-order races. - -The honest cost: an asynchronous call to a **filesystem-capable** tool has launch-deferred -semantics — its body starts when awaited (or at invocation end), not at `Start`, and a -filesystem-capable body holding the lane across a long external wait delays other -filesystem-capable bodies. Filesystem-incapable tools, the expected majority, get true concurrency. -Removing this restriction for filesystem-capable tools is exactly the overlap extension with its -oplog-recorded ordering entries. - -The lane serializes guest bodies, not durable waiting: a body suspended on a nested external durable -call still suspends inside its own scope as today. - -## Owner-oplog model - -### Tool invocation records - -GOL-35 implements each tool call as an eager owner-oplog durable call. Its `Start` request contains: - -- entity selector; -- immutable activation snapshot or its persisted replay form; -- operation/command path and input; -- calling principal and parent invocation correlation; -- call mode and any stream/future metadata needed to replay it. - -The assigned `Start` index becomes `EntityInvocationId.start_index`. Nested host calls from the tool -write ordinary `Start`/`End`/`Cancelled` records to the same owner oplog with the entity invocation -Start as their durable parent scope. - -The outer `End` stores the tool result. All three call modes — synchronous, asynchronous, and -fire-and-forget — are supported from the start and reuse the existing concurrent durability -principles: eager `Start` at initiation, future resources for pending results, terminal resolution, -durable cancellation, and completion-discarded semantics for dropped futures. What differs per mode -is only **when the local body runs**: filesystem-incapable bodies begin immediately at `Start` and -may overlap anything; filesystem-capable bodies queue for the owner filesystem lane as described -above. - -No `CreateEntity` entry or child oplog is added. - -### Why completed tool calls execute during replay - -An ordinary completed remote RPC can return its recorded result without redispatching because the -remote worker owns its effects. A tool is different: its WASI filesystem is the owner's local -filesystem, whose contents are reconstructed by replay. - -Therefore the tool-call durability adapter needs a replay-body mode rather than the usual -“recorded End means skip action” mode: - -```text -live Start - execute entity body - append/replay nested durable operations - execute local filesystem operations -live End(result) - -replay Start - execute entity body again - consume nested durable results - reconstruct local filesystem effects -replay End(recorded result) -``` - -The recorded outer result is authoritative. The replayed body result should be structurally compared -with it and divergence must not silently replace the recorded result. Because divergence is -deterministic — the same history replays to the same divergence — retrying recovery cannot fix it. -Divergence therefore puts the **owner** into a permanent failed status carrying the invocation and -entity diagnostics, exactly like other unrecoverable replay errors. The escape hatches are the -existing owner-level ones: fork or revert the owner oplog to a point before the diverging -invocation. This also implies the tool contract: a tool that derives output from unintercepted -nondeterminism will brick its owner on replay, which is why invariant 20 requires all nondeterminism -to pass through durable host functions. - -### Replay algorithm - -Replay combines two mechanisms, matching the two classes of bodies: - -- **filesystem-capable bodies** replay in deterministic lane order — their schedule is a function of - oplog contents plus deterministic guest code, exactly as in live execution; -- **filesystem-incapable bodies** replay through the existing concurrent-durability machinery — a - reconstruction task per eager entity `Start`, with nested records consumed by initiation identity - and out-of-position claiming, exactly as concurrent durable calls replay today. - -The walk: - -1. Open the existing owner oplog and establish its replay target. -2. Replay the primary agent normally; it initially holds the filesystem lane. -3. When replay reaches an entity-invocation `Start`, inspect its persisted resolution. A recorded - pre-dispatch failure returns its terminal without creating an instance because it has no local - effects. -4. For a dispatched **filesystem-incapable** invocation, spawn its reconstruction task immediately: - construct the persisted activation and scope, create a fresh entity instance, and run its body - concurrently, even if an outer `End` already exists. Its nested durable calls consume their - recorded results through the concurrent machinery; because the body cannot touch the owner root, - its execution order relative to other bodies is irrelevant to filesystem reconstruction. -5. For a dispatched **filesystem-capable** invocation, the body runs on the lane at its historical - transfer point: immediately for a synchronous call, at the recorded await/eligibility point for an - asynchronous call. Local filesystem operations simply execute, because lane order makes their - position a function of the walk. -6. In every case, nested completed durable calls consume their owner-oplog results; incomplete - re-executable calls use the existing incomplete-Start repair rules. -7. When a body finishes, compare its result with the recorded outer terminal, deliver the recorded - result, and drop the instance. -8. A future `get` over an entity invocation resolves the recorded terminal only after that - invocation's replay body (when one is required) has completed — the same gating that terminal - resolution applies to concurrent durable calls. -9. The owner switches to live mode only when the replay cursor passes the last recorded entry **and** - every historical entity invocation requiring local reconstruction has finished its replay body. - This includes fire-and-forget invocations whose launching invocation already completed: their - reconstruction tasks stay registered with owner replay independent of any live awaiter. - -This replays each historical tool invocation because its `Start` is in the oplog, not because any -cached entity state needs restoring. There is no instance-residency history to reproduce. - -Filesystem-incapable bodies must still be re-executed during replay even though they cannot write -the owner root, because their nested durable scopes must be consumed to keep the cursor and claiming -state coherent, and because their recorded results are verified against the replayed body. Skipping -fully completed filesystem-incapable invocations — returning the recorded terminal without running -the body — is a potential optimization, but it is only sound if the invocation verifiably has no -replay-required local effects and its nested record scope can be skipped wholesale without -perturbing claiming for its siblings. Treat it as an optimization to justify separately, not part of -this design. - -Replay cost grows with the owner's tool-call history because every completed body is re-executed. -This is the same trade current agents already make for filesystem state, and the same mitigation -applies: snapshot-based compaction of the owner oplog truncates the history that must be replayed. -Tool-heavy owners make compaction more valuable, not architecturally different; a future filesystem -checkpoint mechanism could further cut replay cost without changing this design. - -### Incomplete invocation - -If the owner crashed while a tool call was running, replay starts that invocation's body from its -beginning. It consumes every nested durable record already present. Once the invocation reaches the -end of its recorded prefix: - -- a completed nested effect returns its recorded outcome; -- a safely re-executable incomplete effect follows existing repair behavior; -- the invocation continues live under the same outer `Start` and idempotency identity; -- its final `End` closes the original call. - -“Resume” therefore means replaying the invocation-local prefix and continuing, not restoring a -sidecar Store snapshot. - -### Cancellation - -Cancellation reuses the existing durable cancellation of concurrent durable calls: - -- cancelling an asynchronous entity invocation appends the durable `Cancelled` terminal and stops - the body at its next durable boundary; replay reproduces the same truncation because the recorded - prefix ends at the same records; -- for a filesystem-capable body, the effects preceding the cancellation point were produced under - the lane, so replay reproduces them in the same order before honoring the recorded terminal; -- a dropped result future does **not** suppress the invocation (completion-discarded semantics), and - during replay it does not suppress reconstruction of the recorded local effects; -- owner-level interruption interrupts every running body — the lane holder and off-lane bodies — at - their next durable boundary, exactly as it interrupts the primary today. Recovery follows the - incomplete-invocation rules above. - -### Entity-filtered oplog views - -The per-entity oplog API required by GOL-33 is a projection over the owner oplog: - -1. Find entity-invocation Starts whose selector matches the requested `OwnedAgentEntityId`. -2. Include their terminals. -3. Include transitive nested Starts/terminals via `parent_start_index`. -4. Include logs, spans, cancellation markers, and any future ordering hints attributed to those - scopes. -5. Preserve physical owner-oplog indices in the response. - -No storage is duplicated. GOL-38 can expose the complete owner order directly and add entity -annotations rather than merging several physical oplogs. - -### Status and metadata - -Existing `AgentMetadata` and status remain primary/owner records. Entity-aware runtime metadata is a -view containing: - -- entity selector; -- active invocation IDs, possibly several; -- slot state derived from them (`vacant` or `invoking`; the warm-cache extension adds `idle`); -- executable and activation fingerprint per invoking instance; -- memory currently charged to its Stores; -- latest matching invocation metadata derived from the owner oplog when historical information is - requested. - -There is no durable entity status once an invocation completes. Durable APIs should query entity -**invocations**, not imply that a Wasmtime instance is a persistent logical object. - -## Activation flow - -### Live tool invocation - -On a live tool call for owner `A` and tool `T`: - -1. Resolve `ActiveAgent(A)` and verify owner lifecycle admission. -2. Parse `A` using unchanged `ParsedAgentId`. -3. Read one coherent environment deployment snapshot containing `RegisteredTool(T)` and the - effective `CompiledToolBinding(agent_type(A), T)`. -4. Validate registration, binding, source, executable revision, provision policy, and capability - narrowing before dispatch, retaining either the coherent activation or the exact pre-dispatch - failure to persist. -5. Begin the owner-oplog tool durable call and persist the requested entity plus replay activation or - pre-dispatch failure in its request. -6. If resolution failed, persist and return its outer error terminal without creating an instance. -7. Derive `EntityInvocationId` from the assigned Start index and classify the invocation as - filesystem-capable or filesystem-incapable from the pinned activation. -8. Register the invocation in the entity slot; same-entity calls do not queue — each concurrent - invocation gets its own instance. -9. Schedule the body: - - **filesystem-incapable:** begin immediately, off-lane, regardless of call mode; - - **filesystem-capable, synchronous:** the caller yields the filesystem lane at this durable - transfer point and the body begins (an off-lane caller instead receives the lane for its callee - through the lane-inheritance rule); - - **filesystem-capable, async/fire-and-forget:** queue the body for the lane; it begins at the - causal transfer point defined in the lane section. -10. Construct a fresh entity instance on the shared instance layer, attached to the owner execution - and resources. A filesystem-incapable Store is built with no preopens. -11. Apply activation-time provisioning against the owner root; provisioning only occurs for - filesystem-capable invocations, whose lane tenure guarantees exclusivity. -12. Invoke the tool export with an `EntityInvocationScope`. -13. Persist the outer terminal, clear the scope, and drop the instance; a filesystem-capable body - returns the lane at this transfer point. - -The registry lookup may occur before the Start because no result has yet reached the guest. Once the -call returns a resolution failure or dispatches a body, that exact resolution is durable. Tool -registration, binding, and deployment state are mutable and must never be recomputed while replaying -a completed call. - -### Replay activation - -Replay never calls current tool discovery for a historical invocation. It uses the activation stored -in that invocation's owner-oplog Start. Because every invocation gets a fresh instance, replaying a -sequence of calls against different historical revisions requires no cache invalidation — each body -instantiates exactly the revision its Start recorded. The compiled component cache continues to -deduplicate compilation by component/revision. (The warm-cache extension must replace a cached -instance whose fingerprint does not match the next activation.) - -### Provisioning - -Provisioning is local filesystem work and follows the same replay rules as the tool body: - -- provision data is pinned in the activation request; -- physical writes execute on the owner lane inside the invocation's durable scope, so their order is - determined by the oplog walk; -- repeated activation of an identical fingerprint is idempotent against the current reconstructed - owner root; -- conflicting declarations for one path fail deterministically; -- read-only policy and provision-state bookkeeping are owner-scoped. - -Do not prewarm an entity in a way that mutates the filesystem without a containing owner-oplog -invocation scope; this constraint binds the future warm-cache extension too. - -### Ephemeral owners - -Ephemeral owners use the same invocation identity, entity slots, and owner lane within their -one-shot lifetime. The initial fresh-instance-per-call behavior already matches the ephemeral -tool contract exactly. Their oplog is ephemeral and never replayed. - -### Middleware - -A middleware layer is another `AgentEntity` and another invocation scope. Its `underlying-tool` call -creates the next nested entity-invocation Start in the same owner oplog. Retry, fan-out, short-circuit, -and repeated inner calls are therefore durably represented by the actual nested calls made during -the original execution. - -GOL-439 supplies chain resolution and control flow; no slot, instance, replay, filesystem, -lifecycle, or identity branch is specific to tools. - -Each middleware layer is classified independently, like any entity. A filesystem-capable middleware -holding the lane yields it to a filesystem-capable inner tool at the nested Start and receives it -back with the inner result — ordinary recursive causal transfer. A filesystem-incapable middleware -runs off-lane, and if its inner tool is filesystem-capable, the lane reaches that tool through the -lane-inheritance rule along the blocking chain. Mixed chains therefore compose without special -cases. - -## Owner-scoped filesystem - -### Ownership and Store attachment - -Factor filesystem ownership out of `DurableWorkerCtx`: - -```rust -pub struct OwnerFilesystem { - root: Arc, - provisioned_files: RwLock, - usage: OwnerFilesystemUsage, -} -``` - -The primary initializes the owner root. Each **filesystem-capable** entity constructs a fresh -Store-local `WasiCtx`, `IoCtx`, and `ResourceTable` with preopens to the same root path. A -**filesystem-incapable** entity's Store is constructed with no preopens at all — inability to reach -the owner root is true by construction, independent of what the component imports. Descriptors and -streams never cross Stores. - -Because owner replay executes entity bodies while reconstructing the root incrementally, ordinary -WASI calls naturally recreate typed descriptors and streams at their historical point. Open-but- -unlinked files and stream cursor state follow the same Wasmtime-WASI behavior as current single-Store -replay; no resource virtualization layer is introduced. - -### Serialization by the owner lane - -In the initial implementation the owner filesystem lane is the entire filesystem-consistency -mechanism. Only filesystem-capable bodies can touch the root, at most one of them executes at a -time, and lane transfers happen only at causal, durable points, so every filesystem operation's -position relative to every other is fixed by the oplog walk plus deterministic guest code. -Filesystem-incapable bodies need no coordination at all: with no preopens they cannot produce a -filesystem effect, so their overlap is invisible to the root. No filesystem mutex, coordinator, -ordering record, or replay gate is needed; existing per-Store WASI code runs unchanged against the -shared root. - -Two non-guest access paths still need care: - -- executor-initiated filesystem inspection and component-update file replacement must not interleave - with a running guest body; they take the lane like a body does or run while the group is idle; -- storage-usage accounting goes through the shared `OwnerFilesystemUsage` so limits are owner-scoped - regardless of which Store performed the operation. - -### Why the lane must not be relaxed casually - -Causal lane transfer exists because durable Start order does not schedule bodies. Suppose two -filesystem-capable tools were allowed to overlap, with A launched asynchronously and running at its -`Start`: - -```text -owner oplog: Start tool A -tool A: start durable external call and wait -owner oplog: Start tool B -tool B: write "B" -tool A: external call finishes; read "B" -``` - -During replay, A's external result is available immediately from the oplog, so A can reach its read -before B's body is polled, reversing the live order despite stable Start order. Concurrent oplog -Start ordering determines durable-call initiation order; it does not schedule the bodies that later -race for the filesystem. Even adding a plain arrival-ordered mutex would not fix this, because -replay task arrival can differ from live arrival. - -This is exactly why an asynchronous filesystem-capable body must not launch at its `Start`: the lane -grants it execution only at a causally determined point that replay reproduces. Filesystem-incapable -bodies escape the problem entirely — with no preopens there is no filesystem race to order. -Overlapping **filesystem-capable** execution requires durable ordering records — specified next as a -future extension. - -### Future extension: overlapping execution and oplog-recorded filesystem order - -Everything in this subsection is deferred. It exists to show the lane-based design has a compatible, -append-only growth path, not to be built initially. - -Add one append-only owner-oplog hint variant: - -```rust -pub struct SharedFilesystemAccess { - pub scope: OwnerExecutionScopeId, - pub call_ordinal: u64, - pub suboperation_ordinal: u64, - pub operation_kind: FilesystemOperationKind, - pub request_digest: RequestDigest, -} - -pub enum OwnerExecutionScopeId { - AgentInvocation(OplogIndex), - EntityInvocation(OplogIndex), - OwnerOperation(OplogIndex), -} -``` - -This entry records only linearization order and divergence metadata. It is not a filesystem log: it -contains no file bytes, read result, mutation outcome, usage snapshot, or materialized state. -Filesystem effects remain derived from replaying guest code. - -`scope` identifies the primary agent invocation, entity invocation, or dedicated durable owner -operation. `call_ordinal` is allocated deterministically when that scope initiates the filesystem -host call, before contention. -`suboperation_ordinal` identifies the actual effect within streaming or internally concurrent work. -The kind and digest detect a replaying operation that reaches the right ordinal with different -inputs. - -This ordinal scheme relies on the Component Model execution contract used here: one Store initiates -guest host calls sequentially. P3 work may continue concurrently after initiation, which is why each -effect has a deterministic suboperation ordinal. If a future runtime permits two filesystem host -calls from one invocation to initiate concurrently, those calls need eager owner-oplog Start -identities like the concurrent durability framework; assigning ordinals in whichever task happens to -run first would not be replay-stable. - -Filesystem work outside an agent/entity invocation, such as update-time provisioning, executes under -a dedicated owner durable scope. Every ordered access must name an owner-oplog scope; an ambient -entity identity is not sufficient attribution. - -The extension's mechanics, in outline: live execution appends a `SharedFilesystemAccess` entry under -a physical-access mutex before performing each effect, making the assigned oplog index the durable -linearization sequence; replay pre-indexes those entries and gates each replaying operation on its -recorded turn, parking operations whose turn has not come and failing replay — never skipping — if -an expected producer cannot arrive. Enabling the extension on an existing owner requires a drain -plus an append-only `SharedFilesystemOrderingEnabled` marker so replay knows where the legacy -lane-ordered prefix ends. Because the marker and ordering entries are append-only hint variants with -reserved tags, the initial lane-based implementation stays forward-compatible: histories written -before the extension replay entirely in lane order. - -Archival, compaction, fork/revert, debugging targets, and deleted-region logic must preserve the -effective ordering sequence once the extension exists. - -### Crash, interruption, and recovery - -The root is a replay materialization, not durable truth. Recovery never continues from a root that -may contain effects newer than the committed owner-oplog prefix. - -- any crash or interruption discards the old root; owner replay reconstructs a fresh materialization - from clean history on the lane; -- a filesystem effect whose containing durable records did not commit simply never happens in the - new materialization — the body replays only as far as the committed prefix drives it; -- panic or an ambiguous partial operation poisons the current root, blocks later accesses, and - triggers owner-wide clean replay; -- suspension, deletion, and reshuffling fence any in-flight body before another root generation can - become active. - -An active entity invocation is never independently restarted against the current root. A failure -that requires replay interrupts the owner group, discards the root, and replays the owner oplog. - -## Host identity, capabilities, and secrets - -Every entity `DurableWorkerCtx` carries: - -- `owner_id` for routing, agent identity, config, quotas, and environment; -- `entity_id` for slot identity and telemetry; -- current `EntityInvocationScope` for oplog attribution and caller principal; -- `ExecutableTarget` for component loading and component-cache charging. - -Inside an entity: - -- `golem:agent/host` resolves the calling owner agent; -- agent configuration and constructor parameters are the owner's; -- tool discovery evaluates bindings as the owner agent type; -- audit and tracing identify both owner and invocation; -- `golem:secrets/*` applies GOL-29's compiled readable/revealable narrowing; -- effective authority is `owner authority ∩ entity binding restrictions`; -- a binding can never widen network, filesystem, secret, subprocess, quota, or other authority. - -Tool-to-tool and middleware-to-inner-tool calls retain the same owner principal while adding nested -entity invocation scopes. - -Guest APIs whose meaning would outlive the invocation need an explicit policy. Scheduling a durable -entity continuation or exposing an entity-owned promise is not allowed merely by projecting to the -owner. Such APIs must either be defined as owner operations or rejected in entity contexts. - -## Lifecycle and failure behavior - -### Suspension and resume - -Owner suspension closes admission for primary and entity work, drains or durably interrupts every -active invocation — the lane holder and all off-lane bodies — commits the owner oplog, and fences -any in-flight body. - -Resume is owner-addressed. No entity is independently resumed. Owner replay recreates any entity -instance required by historical or incomplete invocation Starts. - -### Memory reclamation - -The initial implementation has no idle entity Stores, so there is no entity eviction tier: an entity -Store exists exactly while its invocation runs, and dropping it on completion returns its memory -grant. An invoking Store cannot be evicted independently; if memory pressure must interrupt one, -interrupt/replay the owner group as with the primary today. - -The warm-cache extension reintroduces idle entity Stores and with them a child-first eviction tier; -eviction then drops the Store and its memory grant only and never replays past calls, modifies the -owner oplog, removes provisioned files, or changes durable metadata. - -### Deletion and shard movement - -Owner deletion and shard revocation gate the whole group: - -1. reject new primary/entity work; -2. cancel or drain the active invocation under owner-oplog rules; -3. fence any in-flight body; -4. drop any live entity Store; -5. run existing owner oplog/status/filesystem deletion or reassignment. - -There is no child catalog or child storage to enumerate. The destination executor opens the owner -oplog, creates a clean root, and reconstructs all entity effects while replaying the owner. - -### Failure table - -| Failure | Required result | -|---|---| -| Tool is unregistered or unbound | Permanent call error; no instance created | -| Registration/binding snapshot is incoherent | Permanent deployment-state error before dispatch | -| Component revision is unavailable | Normal component activation failure | -| Concurrent calls for one entity | Each runs in its own fresh instance; overlap governed only by filesystem capability | -| Filesystem call from a filesystem-incapable body | Ordinary guest-visible error (no preopened directory); no trap, no owner effect | -| Instance activation fails | Only that invocation fails; concurrent same-entity invocations unaffected; later call may retry | -| Entity body returns declared error | Persist normal outer result | -| Entity Store traps before a safe terminal | Drop the instance and apply owner retry/interruption policy | -| Replay body differs from recorded result | Permanent owner failed status with invocation/entity diagnostics; recorded result never replaced; escape via fork/revert | -| Synchronous call back into the blocked owner | Explicit would-deadlock error via ancestry check | -| Synchronous self-call into the same entity | Allowed; runs in another fresh instance (lane transfer applies if filesystem-capable) | -| Filesystem operation becomes ambiguous mid-effect | Poison root and perform owner-wide clean replay | -| Owner is deleted during activation | Owner lifecycle gate wins; discard the unadvertised instance | -| Capability narrowing would widen owner | Permanent activation error | -| Provision paths conflict | Deterministic activation error | -| Provisioned files declared with explicit filesystem denial | Deterministic validation error at deployment compilation; never reaches dispatch | - -## Admission, quotas, and accounting - -Acquire one concurrent-agent permit for the `ActiveAgent`. Entity activation reuses that owner -registration and consumes no additional active-agent permit. - -Every resident Store still acquires its actual linear-memory grant. Owner resource limits aggregate -primary and entity memory. Component-cache charges use each instance's real executable target, -allowing normal sharing of a registered tool component across owners without sharing Stores. - -Filesystem usage, disk limits, executor filesystem permits, read-only policy, and storage meters are -owned once by `OwnerFilesystem`. Entity contexts reserve/release through that shared object. - -Initially there are no idle entity Stores, so the existing owner-group eviction ordering is -unchanged. When the warm-cache extension exists, eviction preference becomes: - -1. idle entity Store; -2. idle complete owner group; -3. warm entity Store; -4. warm complete owner group. - -Age and reclaimable bytes remain tie-breakers. Executing Stores are never ordinary eviction -candidates. - -## Routing, APIs, and observability - -### Routing - -Only `OwnedAgentId` reaches shard computation, remote routing, active-group lookup, deletion, -suspension, or resume. `OwnedAgentEntityId` is accepted only by entity-aware local inspection and -invocation plumbing, which first routes by `owner`. - -### API compatibility - -Existing agent APIs and `AgentId` syntax remain unchanged. Add structured entity-aware messages only -where needed to: - -- inspect an entity slot and its current invocation; -- list known entity selectors for an active owner; -- query invocations for one entity from the owner oplog; -- identify an invocation by owner, selector, and owner-oplog Start index. - -An absent selector in existing APIs always means the primary. Never encode a selector in an agent -name or component ID. - -### Observability - -Entity events, logs, traces, and metrics add: - -- owner agent ID; -- entity kind and name; -- entity invocation Start index; -- executable component ID and revision; -- activation fingerprint; -- live/replay/incomplete execution mode. - -Metrics distinguish owner groups, primary Stores, and invoking entity Stores (plus idle entity -Stores once the warm-cache extension exists). -Do not put binding parameters, secret paths beyond existing safe labels, or secret values in ordinary -logs or metric labels. - -## Compatibility and rollout - -**Backward compatibility is explicitly not required.** Oplogs, statuses, and metadata persisted -before this feature do not need to remain replayable or decodable, no data migration is provided, -and mixed-version deployments (old executors encountering new oplog records, or new executors -required to honor old encodings) do not need to be supported. This removes any need for a -deployment-level feature flag, homogeneous-rollout gating, or reserved-tag discipline motivated by -old readers. - -What remains are design decisions and forward-compatibility within the new model: - -1. `AgentId`, `ParsedAgentId`, `Create`, primary status, and primary storage keys stay unchanged as - a simplicity choice — the primary's shape is not being redesigned, merely reused. -2. No child oplogs, child storage keys, or child status records are introduced. -3. Histories written by the initial implementation replay with lane order for filesystem-capable - bodies and existing concurrent-durability reconstruction for filesystem-incapable bodies; the - future ordering extension adds its enable marker and hints as new variants without - reinterpreting records written by the initial implementation. -4. Entity invocation Starts persist full replay activation data, so replay never depends on current - deployment state. -5. Fork, revert, archive, compression, public/raw conversion, debugging replay targets, and oplog - processors must preserve entity nesting (and, later, effective filesystem-order hints). -6. Owner deletion automatically removes all sidecar history because that history is in the owner - oplog. - -## Implementation plan - -### Phase 1 — Identity and activation types - -- [x] Add `AgentEntity`, `OwnerRuntime`, `OwnedAgentEntityId`, and `EntityInvocationId`. -- [x] Keep `AgentId` and `ParsedAgentId` unchanged and add explicit owner projections. -- [x] Add `ExecutableTarget`, generic activation snapshot, fingerprint, and invocation scope. -- [x] Add protobuf/JSON forms only for entity-aware APIs and owner-oplog requests. -- [x] Add coherent registered-tool/binding activation lookup. - -**Exit:** the executor can describe an entity and one invocation without inventing another agent or -persistent Worker identity. - -### Phase 2 — Instance layer and owner execution - -- [x] Introduce owner-keyed `ActiveAgents` and `ActiveAgent` groups. -- [x] Extract shared `OwnerExecution` with the owner's oplog, cloneable `ReplayState`, and - `OwnerCommitController` that commits without a primary Store lock. -- [x] Extract the Store-driving instance layer from `Worker` and make the primary consume it. -- [x] Allow an entity instance on that layer to attach to owner execution/resources with a different - executable than the owner's component. -- [x] Add `invoke_scoped` and per-call cleanup. -- [x] Prove primary-only behavior and storage remain unchanged. - -**Exit:** a synthetic entity export can execute in a separate, transient Store while appending -nested durable calls to the owner's oplog. - -### Phase 3 — Slots, classification, lane, and call modes - -- [x] Add a per-`(owner, entity)` slot registering active invocations for metadata and lifecycle - fencing, with no same-entity serialization. -- [x] Add filesystem-capability classification from the pinned activation, and build - filesystem-incapable Stores with no preopens. -- [x] Add the owner filesystem lane: causal transfer at Start/terminal for synchronous calls, queued - grant at await/eligibility points for async and fire-and-forget calls, ascending-Start eligibility - order, and lane inheritance along blocking chains. -- [x] Run filesystem-incapable bodies off-lane in all call modes over the existing concurrent - durability machinery. -- [x] Add invocation-ancestry deadlock detection for synchronous calls back into the blocked owner. -- [x] Charge actual entity memory and component cache costs; drop the Store on completion. - -**Exit:** live tool calls in all three modes execute in fresh sidecar Stores; filesystem-capable -bodies serialize on the lane while filesystem-incapable bodies overlap. - -### Phase 4 — Replay-body durability - -- [x] Add entity-invocation owner-oplog request/response codecs. -- [x] Add replay-body durable-call control flow that re-executes completed local entity calls: - lane-ordered for filesystem-capable bodies, reconstruction tasks over the concurrent machinery for - filesystem-incapable bodies. -- [x] Gate future `get` resolution on completed replay bodies, keep fire-and-forget reconstruction - registered independent of awaiters, and block the live-mode transition until required - reconstruction finishes. -- [x] Parent nested entity durable calls under the outer invocation Start; resolve or persist the - host-call Start index vs durability `begin_index` relationship. -- [x] Compare replay body output with the recorded outer result and surface divergence as a - permanent owner failed status. -- [x] Integrate incomplete-Start recovery (prefix replay, continue live) and durable cancellation - truncation. -- [x] Add entity-filtered owner-oplog projections. - -**Exit:** owner replay reconstructs completed and incomplete entity invocations of every call mode -from one oplog with no cached entity state and no filesystem-ordering records. - -### Phase 5 — Shared owner filesystem - -- [x] Extract `OwnerFilesystem`, shared usage/metering, and per-Store WASI attachment to one root. -- [x] Verify descriptor/stream reconstruction across primary and entity Stores during clean replay. -- [x] Fence root generations on interruption, deletion, and shard movement. -- [x] Route provisioning through invocation scopes on the lane. -- [x] Keep executor-initiated filesystem access from interleaving with a running body. - -**Exit:** primary and entities share one root deterministically, with the owner oplog as the only -durable source. - -### Phase 6 — Lifecycle, APIs, and middleware readiness - -- [x] Make suspend/delete/revocation fence entity bodies with the owner. -- [x] Add entity slot and invocation metadata APIs without durable child status. -- [x] Add owner/entity/invocation telemetry. -- [x] Verify middleware selector and nested invocation scopes use the generic path. -- [x] Document the narrow dispatch hooks consumed by GOL-35 and GOL-439. - -**Exit:** tools and middleware require only call-surface and chain behavior, not another executor -runtime model. - -### Future extensions (explicitly out of the initial scope) - -- Warm entity-instance caching (an idle cached instance per slot — a cache, not a lock; - fingerprint-based replacement; child-first eviction). -- Overlapping **filesystem-capable** execution with `SharedFilesystemOrderingEnabled` and - `SharedFilesystemAccess` records, replay pre-indexing, and park/wake gating. -- Replay-skipping fully completed filesystem-incapable invocations, if nested-scope consumption can - be proven safe. -- Filesystem checkpoints to reduce replay cost for tool-heavy owners. - -## Test plan - -### Identity and compatibility - -- existing `AgentId` and `ParsedAgentId` parsing/display are unchanged; -- tool and middleware selectors with equal text remain distinct; -- entity invocation IDs are stable across replay and unique within an owner; -- primary-only agents behave, store, and report status as before the refactor; -- no child oplog/status/catalog records are created. - -### Slots and activation - -- each call constructs a fresh entity instance and drops its Store on completion; -- a new call after any earlier call does not replay past calls; -- concurrent same-entity calls run in parallel fresh instances when filesystem-incapable, and - lane-serialize like any other filesystem-capable bodies when capable; -- a synchronous call back into the blocked owner returns a would-deadlock error; -- a synchronous self-call into the same entity succeeds in another fresh instance; -- historical replay pins executable, binding, provision, and secret policy per invocation Start; -- two owners never share a Store or entity slot. - -### Call modes and overlap - -- filesystem-incapable tool calls overlap the primary, the lane holder, and each other in async and - fire-and-forget modes; -- an asynchronous filesystem-capable call starts its body at the causal lane grant, not at `Start`; -- several queued filesystem-capable bodies become eligible in ascending Start order; -- lane inheritance lets an off-lane caller synchronously invoke a filesystem-capable tool without - deadlock; -- a dropped result future does not suppress a launched invocation; -- durable cancellation truncates an async body at a durable boundary, live and in replay. - -### Oplog and replay - -- entity body nested durable calls use the owner oplog and outer parent Start; -- completed tool calls execute again during owner replay; -- completed external effects return recorded results and are not repeated; -- completed local filesystem effects execute again; -- filesystem-incapable invocations replay via reconstruction tasks; their nested records are - consumed via existing claiming regardless of relative body scheduling; -- future `get` resolves the recorded terminal only after the required replay body completes; -- the owner does not switch live until all historical reconstruction, including fire-and-forget - bodies, has finished; -- the currently incomplete tool call replays its prefix and continues live under the same Start; -- recorded outer result remains authoritative; divergence yields a permanent owner failed status - with invocation diagnostics, and fork/revert to an earlier point recovers; -- nested middleware chains transfer the lane recursively and replay in oplog order; -- entity-filtered views contain exactly matching invocations and transitive descendants; -- fork/revert/archive/debug-target behavior preserves nested entity scopes. - -### Filesystem - -- primary and every filesystem-capable entity observe one root through separate Store resources; -- a filesystem-incapable entity Store has no preopens and its filesystem attempts fail with ordinary - guest-visible errors, regardless of what the component imports; -- classification comes only from pinned binding/provision data, never from import analysis, and is - identical live and in replay; -- retained descriptors and streams rebuild naturally during clean owner replay; -- provisioning is ordered and deterministic; -- filesystem order among the primary and filesystem-capable entities is reproduced by lane transfer - alone, independent of task scheduling and of any overlapping filesystem-incapable bodies; -- crash and interruption at any point recover from a clean root; -- active entity replay failure invalidates the whole owner root rather than replaying against - current contents; -- executor-initiated filesystem inspection does not interleave with a running body; -- storage usage and limits are owner-scoped and not double-counted. - -### Lifecycle, pressure, and security - -- owner suspend/revoke/delete prevents new entity admission and fences every active body, on-lane - and off-lane; -- no entity can be independently routed, resumed, deleted, or scheduled; -- an invoking entity Store is never independently evicted; -- one group consumes one concurrent-agent permit while all Store memory is charged; -- entity host identity is the owner plus invocation telemetry; -- capability and secret policy can narrow but never widen owner authority; -- middleware test entities use the same slots, scopes, lane, replay, and filesystem behavior. - -Warm-cache and filesystem-capable-overlap extension tests (Store reuse, eviction-history -independence, ordering entries, park/wake, enable-marker transition) belong to those extensions, not -to the initial implementation. - -## Acceptance criteria - -GOL-33 is complete when: - -1. `AgentId` and `ParsedAgentId` remain unchanged. -2. Owner-plus-entity identity and per-invocation durability identity are explicit types. -3. `ActiveAgents` owns one primary `Worker` and per-entity slots hosting transient instances on the - shared instance layer. -4. No entity Store state is ever required for correctness or recovery. -5. Every entity durable record belongs to the owner oplog and is nested under its invocation Start. -6. Completed entity bodies replay for local side effects; incomplete bodies replay their prefix and - continue live; divergence is a permanent owner-level failure. -7. Filesystem-capable bodies execute on the owner filesystem lane with causal, durable transfer - points; filesystem-incapable bodies overlap freely in every call mode over the existing - concurrent durability machinery; same-entity invocations require no serialization beyond that. -8. Filesystem capability is classified only from pinned binding/provision data — never WASI - imports — and filesystem-incapable Stores carry no preopens. -9. Primary and filesystem-capable entity Stores use separate WASI resources over one owner root, - whose consistency and replay determinism follow from the lane with no separate filesystem - history. -10. Warm caching and overlapping filesystem-capable execution remain specified as compatible, - append-only future extensions that require no change to the identities or records introduced - here. -11. Dropping an entity Store requires no replay; active invocation recovery is owner-wide. -12. Routing, lifecycle, quotas, identity, capabilities, and deletion remain owner-scoped. -13. Entity slot/invocation metadata and filtered oplog APIs do not create another durable Worker - identity. -14. Middleware can reuse the same slots, invocation scopes, oplog, replay, lane, and filesystem - mechanisms. diff --git a/gol-96.md b/gol-96.md deleted file mode 100644 index d6c5362322..0000000000 --- a/gol-96.md +++ /dev/null @@ -1,347 +0,0 @@ -# GOL-95 shared TypeScript/P3 streaming lifecycle plan - -This file uses the requested `gol-96.md` name, but tracks the shared prerequisites owned by -[GOL-95](https://linear.app/golem-cloud/issue/GOL-95/typescript-streaming-method-support). -GOL-96 owns the Scala-specific `AgentStream` implementation and fixture work. - -## Goal - -Finish and verify TypeScript guest SDK support for stream-bearing agent methods through the real -guest ABI and native `clientFor` RPC path. Provide the shared wasm-rquickjs lifecycle behavior that -other guest SDKs, including Scala, rely on. - -## Lifecycle contract - -The implementation and tests will enforce these semantics: - -1. Normal producer completion makes `next()` resolve to `{ done: true, value: undefined }`. -2. Consumer `return()` and `for await` early exit deterministically drop the P3 readable end. - Consumer `throw(reason)` also drops the readable end and rejects with the same local `reason`; - bare P3 streams provide no channel for transmitting that reason to the producer. -3. A producer observes that its peer dropped the readable end cooperatively when a subsequent P3 - write fails. It then stops pulling and invokes and awaits the source iterator's `return()` - exactly once. P3 does not interrupt an arbitrary source `next()` promise or guarantee that - cleanup finishes before a later agent invocation. -4. Accepted writes provide back-pressure: the producer does not pull another item until the prior - write has completed. -5. A JavaScript producer exception, including rejection during producer cleanup, traps the active - producer operation with its diagnostic and is never converted to clean EOF. GOL-95 does not - redefine the platform's language-neutral retry or durable-session terminal behavior. -6. Canonical P3 cancellation is an in-flight operation status, not a recoverable terminal value. - Bare P3 `stream` has no producer-supplied `error-context` terminal, and its - `stream.drop-writable` canonical function takes only the writable handle. A recoverable - stream-local error needs an explicit contract such as `stream>` or a separate - terminal-outcome future. Golem's durable session error terminal must not be presented as a new - guest P3 primitive. - -## Boundaries - -- GOL-95 owns wasm-rquickjs iterator lifecycle changes, the pinned runtime update, TypeScript target - and caller coverage, shared conformance tests, and public `AgentStream` documentation. -- GOL-96 owns Scala lifecycle/state, affine finalizer transfer, Scala schema and `MethodBinding` - cleanup, mocked JS-adapter tests, and the Scala target/caller fixture. -- Generated guest bridges remain GOL-511. -- External HTTP/JSON-WebSocket bridge clients remain GOL-100. -- Durable Streams and `openDurableStream` are out of scope. -- New Golem host functions and Wasmtime APIs are out of scope. The pinned stock Wasmtime already - passes the Rust early-consumer-drop, subsequent-invocation, and explicit cancellation tests. - -## Implementation steps - -| Step | Status | Work | -| --- | --- | --- | -| 0 | Complete | Save this plan, attach it to GOL-95, and lock the lifecycle contract. | -| 1 | Complete | Added failing wasm-rquickjs P3 conformance tests for iterator return/throw, early exit, peer readable-drop cleanup, producer failure, and pull-count back-pressure. | -| 2 | Complete | Implemented wasm-rquickjs iterator `return()`/`throw()` and readable-drop producer cleanup, including cancellation of pending pulls and awaited failures. | -| 3 | Blocked | The local wasm-rquickjs prerequisite is complete at `35b84b6ca2cc77e08c9c8d63556d04fa1728fc52` and all dedicated P3 suites pass. The revision pin cannot resolve in a fresh checkout until the one remaining upstream commit is pushed; that external action requires explicit approval. | -| 4 | Complete | Extended the existing TypeScript `agent-rpc` component with streaming target and caller agents covering input-only, output-only, mixed, nested, siblings, forwarding, producer failure, consumer return, and non-streaming compatibility. | -| 5 | Complete | Added targeted Golem worker-executor E2E tests for the direct guest ABI and native TypeScript `clientFor` RPC paths. Input/output/mixed/nested/sibling/direct-forwarding, producer-failure, early-return, and non-streaming assertions pass without a new host API or Wasmtime change. The only shared platform adjustment is the minimal unread-endpoint representation conversion. | -| 6 | Complete | Documented the public `AgentStream` lifecycle and ran focused SDK, component, executor, and regression checks. | - -## Test layering - -### wasm-rquickjs tests - -The upstream boundary tests are the source of truth for exact P3/JavaScript behavior: - -- clean EOF versus early consumer return; -- explicit `return()` and `for await` early-break behavior; -- readable-drop invoking producer cleanup exactly once, including an unread custom iterator; -- no pulls after peer drop; -- one-pull/one-accepted-write back-pressure; -- producer rejection fails the active producer/write operation rather than becoming EOF. - -### TypeScript SDK tests - -Unit tests continue to cover local `AgentStream` ownership, lazy pulling, recursive schemas, -forwarding, and delegation of `next`/`return`/`throw`. They do not substitute for P3 boundary tests. - -### Golem E2E tests - -- Directly invoke the TypeScript target to verify real guest-ABI stream inputs and outputs. -- Invoke a TypeScript caller that uses `clientFor` to verify native SDK RPC. -- Cover representative stream shapes without multiplying every shape by every lifecycle case. -- Verify both cancellation directions and successful non-streaming calls after a producer failure. -- Verify that early consumer return permits an immediate subsequent invocation; do not require the - producer's cooperative cleanup to finish first. -- Keep precise pull-count back-pressure assertions upstream; transport buffering makes them - unreliable as a platform-level assertion. - -## Verification - -1. `cargo test --test p3_async_values` in wasm-rquickjs, followed by its P3 CI test group. -2. TypeScript SDK package test, typecheck, lint, and Prettier checks. -3. Rebuild SDK bundle, P3 agent template, and the `agent-rpc` test component in that order. -4. Run the new targeted `golem-worker-executor --test integration` filters. -5. Rerun existing Rust streaming E2E and non-streaming TypeScript RPC coverage. - -## Progress log - -- 2026-08-31: Reviewed GOL-95, existing TypeScript SDK implementation, Rust streaming fixture, - wasm-rquickjs 0.4.2/current behavior, and the P3 stream API contract. -- 2026-08-31: Coordinated ownership with GOL-96 and communicated that bare P3 streams do not expose - a recoverable `error-context` terminal. -- 2026-08-31: Locked the shared lifecycle contract in this plan and prepared it for attachment to - GOL-95. -- 2026-08-31: Step 0 Oracle review clarified that a late producer failure fails the active stream - drain or consuming invocation session, not an invocation that already returned its endpoint. -- 2026-08-31: Step 1 added upstream P3 fixture and host-harness coverage for clean completion, - explicit consumer `return()`/`throw()`, `for await` early exit, peer readable-drop cleanup, exact - pull gating while a write is pending, and producer failure. The existing runtime fails the new - consumer lifecycle case because the component-backed iterator has no `return()` method. It - preserves the expected pull counts (`2` after one accepted write, `1` while the first write is - pending) but reports zero producer `return()` calls after peer drop. The producer-failure test - already traps rather than reporting clean EOF, and the existing export/import round trips remain - green. -- 2026-08-31: Step 1 Oracle review required the tests to distinguish awaited producer cleanup from - fire-and-forget cleanup, require failure diagnostics, and state the local `throw(reason)` contract - explicitly. The fixtures now await an explicit cleanup-completion promise, include an asynchronous - rejecting `return()` case that must fail the active consumer, exercise asynchronous producer - rejection, and capture WASI stderr to assert `cleanup-failed`/`producer-failed` diagnostics. -- 2026-08-31: Step 2 added idempotent `return(value)` and `throw(reason)` to component-backed JS - iterators, with both operations awaiting deterministic P3 readable-end drop. JS-to-component - pumps now preserve sync-iterator lifecycle methods and invoke and await producer `return()` after - readable drop in both imported-stream and exported-stream writer paths. The complete dedicated - P3 harness passes (9 tests), including exact pull counts and cleanup rejection; targeted Clippy, - Rust formatting, and diff checks also pass. -- 2026-08-31: Step 2 Oracle review found two lifecycle races, so the step returned to in progress. - A pending component-reader `next()` holds the serialization mutex and prevents `return()` from - dropping the readable end, and a nested exported-stream writer can release the last QuickJS - scheduler guard before its producer pump awaits `iterator.return()`. The fixes will abort an - active pull before acquiring reader ownership during close, and retain nested writer ownership - until the JavaScript pump fulfills or rejects. Focused pending-pull and nested-stream cleanup - regressions will cover both cases. -- 2026-08-31: Step 2 follow-up now marks close synchronously, aborts any active P3 read before - waiting for reader ownership, and makes queued pulls observe closure. Nested export writer - ownership now follows the JavaScript producer pump rather than the pure write task, releasing the - command sender and scheduler guard only from pump fulfillment or rejection handlers. New tests - close a genuinely pending read through a second iterator instance and observe nested async - cleanup through a dedicated host callback, including rejection diagnostics. The full P3 harness - passes (10 tests), as do targeted Clippy, Rust formatting, and diff checks. -- 2026-08-31: Step 2 follow-up Oracle review confirmed that synchronous close plus active-read - abortion resolves pending-pull deadlock without violating shared exact-once closure, and that the - pump-owned guard cannot release the final scheduler driver before asynchronous iterator cleanup - fulfills or rejects. Step 2 is complete. -- 2026-08-31: Step 3 committed the shared wasm-rquickjs implementation locally as - `5d010707a5333bf5d475442727672ea608815667`, switched the Golem Rust dependency, CI/publish/skill - harness/benchmark tool pins, and local benchmark installer to that exact revision, and regenerated - the lock entry without unrelated dependency churn. The locally installed CLI rebuilt the - TypeScript SDK bundle and all three P3 template roles. `cargo check -p golem-cli --locked`, the - 714-test TypeScript SDK run (694 passed, 20 skipped), package lint (two pre-existing warnings), - workflow diff checks, and shell validation pass. The commit is one ahead of wasm-rquickjs - `origin/main`; Step 3 remains in progress until pushing that upstream commit is explicitly - approved and the git pin is remotely resolvable. -- 2026-08-31: Step 3 Oracle review found one missed revision consumer: the Amp-orb `.agents/setup` - bootstrap still passed the 40-hex pin to `cargo binstall`. It now installs revision pins from the - wasm-rquickjs Git repository and retains the existing crates.io path for releases. TypeScript and - Scala development guidance and the corresponding repository skills now describe both pin forms - without hardcoding 0.4.2. `bash -n`, ShellCheck, skill reload, stale-pin search, and diff checks - pass. Oracle follow-up confirmed there are no remaining tracked consumers that misinterpret a - revision pin. Only the explicitly approval-gated upstream push remains for Step 3. -- 2026-08-31: Step 4 started by mapping the existing TypeScript RPC fixture, the TypeScript - `AgentStream` API, and the Rust streaming target/caller contract. The TypeScript fixture will use - the same representative stream shapes while keeping crash recovery and executor assertions in - Step 5. -- 2026-08-31: Step 4 added `TsStreamingRpcTarget` and `TsStreamingRpcCaller` fixtures for input, - output, transform, direct capability forwarding, nested and sibling streams, producer failure, - input-producer and output-producer cleanup, and stream-free state updates. Cleanup observations - are bounded and assert exactly one producer `return()` without relying on a fixed delay or an - absolute counter. The fixture type-checks and its component builds successfully with the pinned - runtime; the build also applied the expected manifest schema migration from 1.6.0-dev.7 to - 1.6.0-dev.8. -- 2026-08-31: Step 4 Oracle review first identified the output-cleanup observation race and missing - direct passthrough coverage. After the bounded baseline/delta synchronization and `forward` - method were added, follow-up review confirmed that cooperative scheduler progress is sound and - found no remaining Step 4 blocker. -- 2026-08-31: Step 5 started by mapping the existing attached invocation-session helpers and Rust - streaming E2E assertions so the TypeScript tests can reuse the same protocol-level test path. -- 2026-08-31: Step 5 added direct TypeScript guest-ABI, native TypeScript `clientFor`, and generated - Rust-client E2E coverage. The first attempt to resolve the bounded sibling-stream deadlock added - guest-side result preparation. That approach was subsequently rejected and fully removed because - existing P3 post-return stream endpoints already define the required boundary; the deadlock was - in wasm-rquickjs scheduler liveness, not the Golem host ABI. -- 2026-08-31: Wasmtime does not reliably poll a host `StreamProducer` with `finish = true` when a - guest drops a durable readable, so `DurableInputProducer` now has a teardown-aware drop fallback. - Caller-side output mirrors route cancellation using their persisted topology epoch without - requiring the callee-only `Attached` record; locally owned streams still require attachment - authority, and attempt-owned fallbacks are epoch/attempt fenced. The focused caller-mirror unit - regression and all three targeted integration tests pass. Step 5 is complete pending Oracle - review. -- 2026-08-31: Step 5 Oracle review found that reconstructed callee streams did not restore current - epoch/attempt authority and that caller-mirror cancellation inferred authority too broadly from - foreign ownership alone. Rehydration now restores authority from durable session records; - attempt-owned cancellation is fenced by both current epoch and attempt; and caller-mirror - cancellation requires the exact active output topology at the selected epoch. Unit regressions - cover missing and stale topology, takeover fencing, runtime-teardown suppression, and unread - forwarding ownership transfer. Both focused unit tests and the TypeScript cancellation E2E pass. - No guest-visible result-preparation operation is part of the final design. -- 2026-08-31: Step 5 Oracle follow-up accepted those fixes and the result-preparation test scope, - but found that attempt-owned fallback cancellation checked epoch and attempt without checking the - persisted attached state. That path now uses the same complete current-attachment authority check - as explicit-epoch cancellation. The takeover regression verifies that detached and wrong-attempt - cancellation both return `StaleEpoch` without appending an intent or terminal; it passes. -- 2026-08-31: Final Step 5 Oracle follow-up confirmed the complete attachment check resolves the - remaining blocker without changing the separate active-topology authority used by caller output - mirrors. Step 5 is complete with no remaining correctness blockers. -- 2026-08-31: Step 6 documented the exported `AgentStream` lifecycle in its generated API comments - and package README: clean EOF, local `return`/early-exit and `throw` behavior, affine transfer, - peer-drop cleanup, accepted-write back-pressure, and producer/cleanup failures. The SDK build and - typecheck pass, all 715 SDK tests pass (695 run, 20 skipped), focused Prettier checks pass, and - package lint reports only the same two pre-existing warnings. -- 2026-08-31: Step 6 Oracle review found that typed sources could expose a custom terminal iterator - value despite the documented normalized EOF, and that transport guarantees needed clearer P3 - scoping. Typed `next()` now normalizes terminal values to `undefined` with a regression. API and - README language now separates general lazy/single-reader/affine behavior, received connected-P3 - consumer behavior, and `AgentStream.from` producer behavior after it is sent through P3. Typed - `throw()` is documented as consuming the stream even when the source handles the delegated throw. -- 2026-08-31: Step 6 Oracle follow-up confirmed the normalized EOF regression and scoped lifecycle - documentation resolve all Step 6 blockers. -- 2026-08-31: Added and committed the bounded sibling-export regression in wasm-rquickjs as - `bd5aa799d9195bdd15d230cad75bd90899260349`, a descendant of the lifecycle implementation commit. - It concurrently drains two exported streams while one exceeds the channel capacity, guarding the - scheduler behavior required by durable result preparation. The focused regression, upstream Rust - formatting, and diff checks pass. All Golem dependency, CI, publish, skill-harness, and benchmark - pins now name the descendant revision. Both upstream commits remain local and unpushed pending - explicit approval, so Step 3 is blocked on that external-state action. -- 2026-08-31: Step 3 Oracle follow-up confirmed the descendant relationship, exact pin consistency, - revision-aware setup consumers, and sibling regression shape. It found no blocker other than the - expected remote-resolution failure until the approval-gated push. -- 2026-08-31: Final verification against the exact local upstream revision passes: all 11 - wasm-rquickjs P3 tests, both focused durable cancellation-authority unit tests, all three direct - TypeScript/native TypeScript/generated Rust streaming E2Es, `cargo check -p - golem-worker-executor --tests`, `cargo fmt --all -- --check`, and repository diff checks. Cargo - used a command-scoped Git URL rewrite to the sibling checkout; no repository or global Git - configuration was changed. -- 2026-08-31: The fresh bug-finder pass reported only the known unavailable remote pin. That finding - is real and deferred pending explicit approval to push; adding a fallback or compatibility path - would violate the exact-revision contract and repository policy. Its provisional reproducer was - removed after recording the finding here. -- 2026-09-01: Reconsidered the sibling-stream deadlock against the completed P3 implementation and - existing Rust streaming fixtures. Fully removed the proposed guest-visible result-preparation - operation from Golem WIT, executor, Rust, TypeScript, MoonBit, mocks, and generated surfaces. A - repository-wide search confirms that no implementation reference remains. -- 2026-09-01: Reproduced the no-host-operation deadlock at the established boundary. TypeScript - awaits the existing imported `schema-value-stream.wrap(reader)` calls; the host stores each - reader and returns its resource immediately. The corresponding JS-to-component writer was not - tied to the exporting call's scheduler lifetime, so a 64-item sibling stream filled the bounded - channel before the host could consume the stored reader after export return. -- 2026-09-01: Oracle rejected an ambient per-export writer group because overlapping exports can - clobber each other's ownership. The replacement is a runtime-global writer-count lease with an - affine scheduler driver per exporting component task. Async export completion races runtime idle - with writer activation; a retained driver waits for writer inactivity and then runtime - quiescence, retrying if another writer activates. Sync functions, methods, and constructors trap - promptly if they create a writer that requires asynchronous progress. No production WIT or host - API was added. -- 2026-09-01: Added upstream regressions for imported wrapping under sibling back-pressure, - deterministically ordered overlapping exports, delayed ref'd work surviving writer 1→0, and the - synchronous-constructor trap. Focused tests pass. The full P3 suite, final upstream commit/pin, - rebuilt TypeScript fixture, and Golem E2E rerun are in progress. -- 2026-09-01: Committed the runtime-global writer lease and affine retained-driver implementation - locally in wasm-rquickjs as `35b84b6ca2cc77e08c9c8d63556d04fa1728fc52`. All 15 dedicated P3 - async-value tests, the exported-resource tests, targeted check and Clippy, formatting, and diff - checks pass. The Golem runtime, build, CI, publish, skill-harness, and benchmark pins now name this - exact local revision. It remains unpushed pending explicit approval. -- 2026-09-01: Rebuilt the TypeScript SDK, templates, CLI, and `agent-rpc` fixture and reran the full - TypeScript streaming RPC E2E. The previous `produceSiblings` deadlock is resolved: the normal - streaming matrix reaches the producer-error case. `produceError` yields its first item and then - rejects with `ts-producer-failed`; wasm-rquickjs traps as required by current P3, but Golem retries - and replays the target after its streaming invocation result is already durable and externally - visible. The caller consequently waits for a terminal until the 120-second test timeout. -- 2026-09-01: Investigated the proposed P3 `error-context` prerequisite before adding an API. - wit-bindgen 0.58 and current main expose only write/cancel/drop on guest `StreamWriter`; - `stream.drop-writable` takes only the writer handle in both generated bindings and the Component - Model canonical ABI. Wasmtime likewise defines guest producer failure as an unrecoverable trap, - not a producer-supplied stream error terminal. A wit-bindgen-only `close(ErrorContext)` method - would therefore be invalid without a coordinated Component Model and Wasmtime extension. -- 2026-09-01: Oracle review selected the standards-compliant minimal fix: keep the JavaScript - rejection as a guest trap, but make failures non-retriable once the durable invocation result is - published. Existing Golem session teardown then records failure and terminalizes all still-open - outputs with its durable `ErrorContext`; expected recoverable stream-local failures require an - explicit WIT result/outcome contract. Oracle rejected both normal-drop-with-logging and a - Golem-specific guest host function. Step 5 remains in progress for this retry/session correction. -- 2026-09-01: Rechecked the proposed Wasmtime writer-drop observer against the existing Rust - streaming implementation instead of treating the TypeScript fixture as the contract. After - rebuilding a stale Rust fixture that still imported the already-removed `prepare-invoke-result`, - `generated_rust_client_streaming_rpc_e2e` and - `output_consumer_cancel_after_result_remains_a_valid_terminal_session` both pass on the pinned, - unmodified Wasmtime `252ab61`. The first test drops output after one item and immediately calls - `ping`; it also verifies successful scalar calls after producer failure. The TypeScript fixture's - wait for an async generator `finally` before `ping` was stronger than P3, which reports readable - drop cooperatively on the producer's next write and cannot interrupt an arbitrary pending - `next()`. -- 2026-09-01: Oracle review confirmed that GOL-95 must abandon the Wasmtime experiment and align the - platform E2E with the existing Rust contract. Removed TypeScript producer-finalizer counters, - polling methods, timeout synchronization, and the dedicated infinite producer. The fixture now - reads one item from the existing finite producer, calls `return()`, and immediately calls `ping`. - Exact iterator cleanup remains covered at the wasm-rquickjs P3 boundary. Public TypeScript docs - now state the cooperative next-write observation and explicitly avoid a cleanup-before-next-call - guarantee. The SDK typecheck and focused 12-test stream suite pass, as do focused Prettier checks, - SDK and P3 template rebuilds, TypeScript fixture rebuild and WASM validation, and the revised - `typescript_client_streaming_rpc_e2e`. Oracle found no contract regression or missing assertion - in the completed alignment. -- 2026-09-01: Isolated direct capability forwarding against a clean stock-platform worktree. The - full TypeScript E2E failed only at `forward({ input }) { return input; }` with `schema value stream - endpoint belongs to an incompatible runtime`. Existing Rust E2E pumps transformed streams and - therefore did not exercise this direct unread endpoint representation, although Rust SDK unit - tests cover local capability identity. The materializer recognized `ForwardedDurableInput` but - the real TypeScript invocation path still carried the equivalent pristine `DurableInputEndpoint`. -- 2026-09-01: An isolated A/B run showed that one affine conversion in the shared durable-session - materializer makes the complete TypeScript streaming E2E pass without cancellation fallbacks, - attachment-authority changes, retry guards, a host function, or a Wasmtime change. The final - conversion accepts only `consumer_read_ordinal == 0` with an empty replay journal, consumes the - endpoint exactly once, and moves its complete `DurableStreamHandleV1` unchanged. It does not - read, pump, re-register, drain, or cancel; existing format-version and schema-fingerprint checks - remain in place. Read or journaled endpoints are rejected. -- 2026-09-01: Removed all other experimental GOL-95 executor changes and retained only the shared - representation conversion at the three existing materialization sites. The focused unit - regression verifies exact root input/result handle preservation, no re-registration, and - rejection after either a read ordinal or replay journal appears. Rust formatting and the focused - test pass. Oracle found no fix-worthy issue and confirmed the change is minimal and correctly - scoped. No Wasmtime source change is part of GOL-95. -- 2026-09-01: Reran the complete native TypeScript `clientFor` streaming E2E with the minimal - materializer fix in the main worktree. All input/output/mixed/nested/sibling/direct-forwarding, - producer-failure, early input/output return, immediate post-return `ping`, and stream-free calls - pass. Oracle confirmed that the assertions match the existing Rust/P3 lifecycle contract and - found no missing or over-strong E2E assertion. Step 5 is complete. -- 2026-09-01: Final upstream runtime verification passed at local wasm-rquickjs revision - `35b84b6ca2cc77e08c9c8d63556d04fa1728fc52`: 15 `p3_async_values`, one - `p3_exported_resource`, and 70 `p3_generation` tests. Oracle reviewed the complete - `origin/main..HEAD` range and found no implementation or verification blocker. The abandoned - Wasmtime observer worktree and the temporary stock-platform A/B worktree were removed; no - Wasmtime source change remains. -- 2026-09-01: Final bug finding exposed two ownership-ordering defects. `AgentStream.return()` and - `throw()` now consume the SDK ownership state before source iterator initialization or delegated - cleanup, so initialization/cleanup rejection cannot reopen a stream. The focused SDK suite now - has 14 passing tests covering both rejection paths. -- 2026-09-01: The durable forwarding boundary now performs a complete non-destructive first pass - before any affine take. It rejects schema/version mismatches, read or journaled durable inputs, - consumed/incompatible leaves, and aliased stream cells while preserving every endpoint in a - rejected value. The second pass records the exact recognized host representation and must consume - that representation successfully; it cannot continue from a cloned handle after a lost transfer. - Focused regressions cover legacy and real durable endpoints, later sibling failures, aliasing, - exact handle preservation, and no re-registration. -- 2026-09-01: The bug-finder reached its design checkpoint after serial edge-case findings, so the - loop was stopped rather than overridden. The shared invariant review above was completed with - Oracle follow-ups; Oracle reports no remaining blocker. Rust formatting, TypeScript Prettier and - typecheck, the rebuilt SDK bundle and three P3 templates, rebuilt/validated TypeScript fixture, - two focused durable forwarding tests, and all four combined TypeScript/Rust streaming E2Es pass. diff --git a/golem-common/src/base_model/worker.rs b/golem-common/src/base_model/worker.rs index e5007dbf7e..c26ad63927 100644 --- a/golem-common/src/base_model/worker.rs +++ b/golem-common/src/base_model/worker.rs @@ -210,7 +210,7 @@ impl From for AgentConfigEntryDto { // adjacently-tagged `SchemaValue` wire form. Render it through the // schema graph so it round-trips with // `parse_worker_creation_agent_config` (`from_json_value`). - let json = crate::schema::render::to_json_value(&graph, &graph.root, &schema_value) + let json = golem_schema::schema::render::to_json_value(&graph, &graph.root, &schema_value) .expect("SchemaValue in TypedAgentConfigEntry must render to JSON"); Self { path: value.path, diff --git a/golem-common/src/model/agent/mod.rs b/golem-common/src/model/agent/mod.rs index 0cbef3c814..3af7fc53de 100644 --- a/golem-common/src/model/agent/mod.rs +++ b/golem-common/src/model/agent/mod.rs @@ -70,7 +70,14 @@ impl TryFrom for AgentMode { } } -#[derive(Debug, Clone, BinaryCodec)] +#[derive( + Debug, + Clone, + PartialEq, + BinaryCodec, + golem_schema_derive::IntoSchema, + golem_schema_derive::FromSchema, +)] #[allow(clippy::large_enum_variant)] pub enum AgentError { InvalidInput(String), diff --git a/golem-common/src/model/component.rs b/golem-common/src/model/component.rs index d13bc43da6..dff956f5e2 100644 --- a/golem-common/src/model/component.rs +++ b/golem-common/src/model/component.rs @@ -36,7 +36,7 @@ impl ComponentDto { Ok(( e.path.join("."), NormalizedJsonValue::new( - crate::schema::render::to_json_value( + golem_schema::schema::render::to_json_value( e.value.graph(), e.value.root_type(), e.value.value(), diff --git a/golem-common/src/model/oplog/payload/mod.rs b/golem-common/src/model/oplog/payload/mod.rs index 9ba9d0c6e0..7c459dbb07 100644 --- a/golem-common/src/model/oplog/payload/mod.rs +++ b/golem-common/src/model/oplog/payload/mod.rs @@ -348,6 +348,9 @@ oplog_payload! { call_mode: EntityCallMode, error: SerializableToolRpcError, }, + GolemAgentGetAgentTypeByAgentId { + agent_id: String + }, } } @@ -911,7 +914,8 @@ pub mod host_functions { (WasiCliEnvironmentGetEnvironment => "cli::environment", "get-environment", CliEnvironmentGetEnvironment, CliEnvironmentGetEnvironment), (GolemRpcWasmRpcActivate => "golem::rpc::wasm-rpc", "activate", GolemRpcActivate, GolemRpcActivate), (GolemEntityInvoke => "golem::entity", "invoke", EntityInvocation, EntityInvocation), - (GolemToolInvocationRejected => "golem::tool::internal", "invocation-rejected", GolemToolInvocationRejected, EntityInvocation) + (GolemToolInvocationRejected => "golem::tool::internal", "invocation-rejected", GolemToolInvocationRejected, EntityInvocation), + (GolemAgentGetAgentTypeByAgentId => "golem::agent", "get_agent_type_by_agent_id", GolemAgentGetAgentTypeByAgentId, GolemAgentAgentType) } } diff --git a/golem-common/src/model/oplog/payload/tests.rs b/golem-common/src/model/oplog/payload/tests.rs index dc02473f6b..4400ff0a5e 100644 --- a/golem-common/src/model/oplog/payload/tests.rs +++ b/golem-common/src/model/oplog/payload/tests.rs @@ -41,7 +41,8 @@ use crate::model::oplog::types::{ }; use crate::model::oplog::{ HostPayloadPair, HostRequest, HostRequestCliEnvironmentGetEnvironment, - HostRequestEntityInvocation, HostRequestFileSystemPath, HostRequestGolemApiOplogEnrich, + HostRequestEntityInvocation, HostRequestFileSystemPath, + HostRequestGolemAgentGetAgentTypeByAgentId, HostRequestGolemApiOplogEnrich, HostRequestGolemApiOplogRead, HostRequestGolemRpcActivate, HostRequestGolemToolGetTool, HostRequestGolemToolInvocationRejected, HostRequestGolemToolInvoke, HostRequestKVCacheKey, HostRequestKVCacheKeyAndTtl, HostRequestKVCacheKeyValueAndTtl, @@ -49,17 +50,18 @@ use crate::model::oplog::{ HostRequestP3HttpClientRequestBodyFrame, HostRequestP3HttpClientSend, HostRequestP3SocketsConnect, HostRequestP3SocketsUdpSend, HostRequestRandomBytes, HostResponse, HostResponseCliEnvironmentGetEnvironment, HostResponseEntityInvocation, - HostResponseGolemApiOplogChunk, HostResponseGolemApiOplogEntries, HostResponseGolemApiUnit, - HostResponseGolemRpcActivate, HostResponseGolemRpcScheduledInvocation, - HostResponseGolemRpcScheduledInvocationCompat, HostResponseGolemToolInvokeResult, - HostResponseGolemToolTool, HostResponseGolemToolTools, HostResponseGolemToolUnitOrFailure, - HostResponseKVDelete, HostResponseKVGet, HostResponseKVUnit, - HostResponseMonotonicClockTimestamp, HostResponseP3BlobstoreIncomingValueStream, - HostResponseP3FileSystemStat, HostResponseP3FileSystemWriteAdmission, - HostResponseP3HttpClientConsumeBodyChunk, HostResponseP3HttpClientConsumeBodyResult, - HostResponseP3HttpClientRequestBodyTransmission, HostResponseP3HttpClientSendResult, - HostResponseP3KeyvalueIncomingValueStream, HostResponseP3MonotonicClockUnit, - HostResponseP3SocketsConnect, HostResponseP3SocketsTcpAcquire, HostResponseP3SocketsTcpReceive, + HostResponseGolemAgentAgentType, HostResponseGolemApiOplogChunk, + HostResponseGolemApiOplogEntries, HostResponseGolemApiUnit, HostResponseGolemRpcActivate, + HostResponseGolemRpcScheduledInvocation, HostResponseGolemRpcScheduledInvocationCompat, + HostResponseGolemToolInvokeResult, HostResponseGolemToolTool, HostResponseGolemToolTools, + HostResponseGolemToolUnitOrFailure, HostResponseKVDelete, HostResponseKVGet, + HostResponseKVUnit, HostResponseMonotonicClockTimestamp, + HostResponseP3BlobstoreIncomingValueStream, HostResponseP3FileSystemStat, + HostResponseP3FileSystemWriteAdmission, HostResponseP3HttpClientConsumeBodyChunk, + HostResponseP3HttpClientConsumeBodyResult, HostResponseP3HttpClientRequestBodyTransmission, + HostResponseP3HttpClientSendResult, HostResponseP3KeyvalueIncomingValueStream, + HostResponseP3MonotonicClockUnit, HostResponseP3SocketsConnect, + HostResponseP3SocketsTcpAcquire, HostResponseP3SocketsTcpReceive, HostResponseP3SocketsTcpReceiveChunk, HostResponseP3SocketsTcpSend, HostResponseP3SocketsUdpReceive, HostResponseP3SocketsUdpSend, HostResponseRandomBytes, HostResponseRandomSeed, HostResponseRandomU64, HostResponseWallClock, host_functions, @@ -484,6 +486,16 @@ fn entity_invocation_host_payload_pair_roundtrips() { ); } +#[test] +fn agent_type_by_agent_id_host_payload_pair_roundtrips() { + assert_host_payload_pair_roundtrip::( + HostRequestGolemAgentGetAgentTypeByAgentId { + agent_id: "Counter(main)".to_string(), + }, + HostResponseGolemAgentAgentType { result: Ok(None) }, + ); +} + #[test] fn p3_clock_host_payload_pairs_roundtrip() { assert_host_payload_pair_roundtrip::( diff --git a/golem-common/src/model/oplog/payload/types.rs b/golem-common/src/model/oplog/payload/types.rs index 1930da1ed6..551c70be3d 100644 --- a/golem-common/src/model/oplog/payload/types.rs +++ b/golem-common/src/model/oplog/payload/types.rs @@ -2188,17 +2188,27 @@ pub enum SerializableHostFailureKind { Debug, Clone, PartialEq, - Eq, BinaryCodec, golem_schema_derive::IntoSchema, golem_schema_derive::FromSchema, )] #[desert(evolution())] pub enum SerializableRpcError { - ProtocolError { details: String }, - Denied { details: String }, - NotFound { details: String }, - RemoteInternalError { details: String }, + ProtocolError { + details: String, + }, + Denied { + details: String, + }, + NotFound { + details: String, + }, + RemoteInternalError { + details: String, + }, + RemoteAgentError { + error: Box, + }, } #[derive( diff --git a/golem-common/src/model/worker.rs b/golem-common/src/model/worker.rs index b5bb425428..9321830adf 100644 --- a/golem-common/src/model/worker.rs +++ b/golem-common/src/model/worker.rs @@ -25,7 +25,7 @@ impl TypedAgentConfigEntry { } pub fn to_flat_pair(&self) -> Option<(String, String)> { - crate::schema::render::to_json_value( + golem_schema::schema::render::to_json_value( self.value.graph(), self.value.root_type(), self.value.value(), diff --git a/golem-common/src/schema/public_json.rs b/golem-common/src/schema/public_json.rs index c9b34dee4c..03259dee96 100644 --- a/golem-common/src/schema/public_json.rs +++ b/golem-common/src/schema/public_json.rs @@ -15,7 +15,6 @@ use crate::model::invocation_session_public::{ MAX_COLLECTION_SIZE, MAX_JSON_DEPTH, MAX_LOGICAL_VALUE_SIZE, MAX_TOKEN_SIZE, PublicErrorCode, }; -use crate::schema::render::{from_json_value, to_json_value}; use crate::schema::stream::SchemaValueStream; use crate::schema::validation::value::validate_value; use crate::schema::{ @@ -24,6 +23,7 @@ use crate::schema::{ }; use base64::Engine; use base64::engine::general_purpose::STANDARD; +use golem_schema::schema::render::{from_json_value, to_json_value}; use serde_json::{Map, Number, Value}; use std::collections::HashSet; use std::fmt::{Display, Formatter}; diff --git a/golem-common/src/schema/render/cli_text.rs b/golem-common/src/schema/render/cli_text.rs index 8337a70e36..065c331c4d 100644 --- a/golem-common/src/schema/render/cli_text.rs +++ b/golem-common/src/schema/render/cli_text.rs @@ -22,12 +22,12 @@ use crate::schema::canonical; use crate::schema::graph::SchemaGraph; use crate::schema::host_managed::HostManagedKind; use crate::schema::metadata::TypeId; -use crate::schema::render::error::RenderError; -use crate::schema::render::walker::{SchemaWalker, walk}; use crate::schema::schema_type::{ DiscriminatorRule, ResultSpec, SchemaType, UnionBranch, VariantCaseType, }; use crate::schema::schema_value::{ResultValuePayload, SchemaValue, UnionValuePayload}; +use golem_schema::schema::render::error::RenderError; +use golem_schema::schema::render::walker::{SchemaWalker, walk}; use std::collections::HashSet; /// Render a [`SchemaType`] as a concise text description. @@ -369,9 +369,9 @@ impl SchemaWalker for CliTextRenderer { } fn drive( - res: Result>, + res: Result>, ) -> Result { - use crate::schema::render::walker::WalkerError; + use golem_schema::schema::render::walker::WalkerError; match res { Ok(v) => Ok(v), Err(WalkerError::Walker(e)) => Err(e), diff --git a/golem-common/src/schema/render/json_schema.rs b/golem-common/src/schema/render/json_schema.rs index 2c5085cd59..926a3c09c8 100644 --- a/golem-common/src/schema/render/json_schema.rs +++ b/golem-common/src/schema/render/json_schema.rs @@ -12,175 +12,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Renderer that produces a JSON Schema document from a `SchemaGraph`/ -//! `SchemaType`. +//! Platform agent-schema projections over the shared schema renderer. use crate::schema::agent::{FieldSource, InputSchema, OutputSchema}; -use crate::schema::graph::SchemaGraph; -use crate::schema::metadata::{MetadataEnvelope, TypeId}; -use crate::schema::schema_type::{ - BinaryRestrictions, DiscriminatorRule, NamedFieldType, PathSpec, PermissionCardSpec, - QuantitySpec, QuantityValue, QuotaTokenSpec, ResultSpec, SchemaType, SecretSpec, - TextRestrictions, UnionBranch, UnionSpec, UrlRestrictions, VariantCaseType, +use crate::schema::{MetadataEnvelope, NamedFieldType, SchemaGraph, SchemaType}; +use golem_schema::schema::render::json_schema::{ + JsonSchemaConfig, to_external_input_json_schema, to_external_output_json_schema, }; -use serde_json::{Map, Number, Value}; -use std::collections::{HashMap, HashSet}; +use serde_json::Value; -const JSON_SCHEMA_DRAFT: &str = "https://json-schema.org/draft/2020-12/schema"; -const MIME_TYPE_PATTERN: &str = "^[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+$"; - -/// Configuration for the JSON Schema renderer. -/// -/// The public constants select the trusted canonical representation; boundary -/// renderers additionally select their host-managed capability policy. -#[derive(Clone, Copy, Debug)] -pub struct JsonSchemaConfig { - /// Emit the `$schema` JSON Schema draft marker at the document root. - pub include_draft_marker: bool, - host_managed: HostManagedSchemaPolicy, -} - -#[derive(Clone, Copy, Debug)] -enum HostManagedSchemaPolicy { - TrustedSnapshot, - Reject, - Redact, -} - -impl JsonSchemaConfig { - /// Canonical standalone JSON Schema document (includes the `$schema` - /// draft marker). - pub const CANONICAL: Self = Self { - include_draft_marker: true, - host_managed: HostManagedSchemaPolicy::TrustedSnapshot, - }; - - /// Canonical JSON Schema document without the `$schema` draft marker, for - /// consumers that embed the schema elsewhere (e.g. tool/resource schemas). - pub const WITHOUT_DRAFT_MARKER: Self = Self { - include_draft_marker: false, - host_managed: HostManagedSchemaPolicy::TrustedSnapshot, - }; - - pub(crate) const EXTERNAL_INPUT: Self = Self { - include_draft_marker: false, - host_managed: HostManagedSchemaPolicy::Reject, - }; - - pub(crate) const EXTERNAL_OUTPUT: Self = Self { - include_draft_marker: false, - host_managed: HostManagedSchemaPolicy::Redact, - }; -} - -/// Render `(graph, ty)` to a canonical JSON Schema document (includes the -/// `$schema` draft marker). See [`to_json_schema_with_config`] for the -/// configurable form. -pub fn to_json_schema(graph: &SchemaGraph, ty: &SchemaType) -> Value { - to_json_schema_with_config(graph, ty, JsonSchemaConfig::CANONICAL) -} - -/// Render `(graph, ty)` to a JSON Schema document. When `ty` is a -/// `Ref(TypeId)` the document is `{ "$defs": {…}, "$ref": "#/$defs/" }`; -/// otherwise the root schema is emitted inline with `$defs` carrying every -/// named definition from the graph plus any union per-branch synthesised -/// schemas under tag-derived keys (see [`BranchNameTable`]). -/// -/// `config.include_draft_marker` controls whether the `$schema` draft marker -/// is added at the document root. -pub fn to_json_schema_with_config( - graph: &SchemaGraph, - ty: &SchemaType, - config: JsonSchemaConfig, -) -> Value { - let table = build_branch_name_table(graph, ty); - let mut root = render_type(graph, ty, true, &table, config); - let mut defs = render_defs(graph, &table, config); - add_union_branch_defs(graph, ty, &mut defs, &table, config); - if !defs.is_empty() { - if let Some(obj) = root.as_object_mut() { - obj.insert("$defs".to_string(), Value::Object(defs)); - } else { - let mut wrapper = Map::new(); - wrapper.insert("$defs".to_string(), Value::Object(defs)); - wrapper.insert("allOf".to_string(), Value::Array(vec![root.clone()])); - root = Value::Object(wrapper); - } - } - if config.include_draft_marker - && let Some(obj) = root.as_object_mut() - { - // Insert the JSON Schema draft marker at the top of the produced - // root schema. OpenAPI removes this; see `super::openapi`. - let mut with_schema = Map::with_capacity(obj.len() + 1); - with_schema.insert( - "$schema".to_string(), - Value::String(JSON_SCHEMA_DRAFT.to_string()), - ); - for (k, v) in obj.iter() { - with_schema.insert(k.clone(), v.clone()); - } - return Value::Object(with_schema); - } - root -} - -/// Render an [`InputSchema`] to a JSON Schema object document. -/// -/// The result is an `object` schema whose `properties` are the input's -/// **user-supplied** parameters (`FieldSource::AutoInjected` fields are host -/// provided and never surfaced to callers, so they are omitted). `required` -/// lists every user-supplied parameter whose schema is not an `option<…>`. -/// `$defs` (named definitions plus synthesised per-union-branch schemas) is -/// attached at the document root so the document is self-contained. -/// -/// This reuses the same node rendering as [`to_json_schema_with_config`] by -/// projecting the user-supplied parameter list onto a synthetic record root; -/// the record renderer already emits an option-aware `required` array. -/// Host-managed capability leaves are unsatisfiable because external callers -/// cannot construct them. +/// Render an agent input schema as an object containing only user-supplied fields. pub fn input_schema_to_json_schema( graph: &SchemaGraph, input: &InputSchema, config: JsonSchemaConfig, ) -> Value { let InputSchema::Parameters(fields) = input; - let user_fields: Vec<&crate::schema::agent::NamedField> = fields - .iter() - .filter(|f| matches!(f.source, FieldSource::UserSupplied)) - .collect(); - let record_fields: Vec = user_fields + let record_fields = fields .iter() - .map(|f| NamedFieldType { - name: f.name.clone(), - body: f.schema.clone(), - metadata: f.metadata.clone(), + .filter(|field| matches!(field.source, FieldSource::UserSupplied)) + .map(|field| NamedFieldType { + name: field.name.clone(), + body: field.schema.clone(), + metadata: field.metadata.clone(), }) .collect(); let record = SchemaType::Record { fields: record_fields, metadata: MetadataEnvelope::default(), }; - to_json_schema_with_config( - graph, - &record, - JsonSchemaConfig { - include_draft_marker: config.include_draft_marker, - ..JsonSchemaConfig::EXTERNAL_INPUT - }, - ) + to_external_input_json_schema(graph, &record, config.include_draft_marker) } -/// Render an [`OutputSchema`] to an optional JSON Schema document. -/// -/// `OutputSchema::Unit` renders to `None` (the method has no return value). -/// `OutputSchema::Single(ty)` renders `ty` via [`to_json_schema_with_config`], -/// with host-managed capability leaves represented by their redacted external -/// placeholder. -/// -/// This renderer applies no protocol policy: it does **not** suppress -/// multimodal outputs. Consumers that omit `outputSchema` for multimodal -/// (e.g. the MCP exporter) make that decision themselves. +/// Render an agent output schema, returning `None` for unit output. pub fn output_schema_to_json_schema( graph: &SchemaGraph, output: &OutputSchema, @@ -188,1287 +52,10 @@ pub fn output_schema_to_json_schema( ) -> Option { match output { OutputSchema::Unit => None, - OutputSchema::Single(ty) => Some(to_json_schema_with_config( + OutputSchema::Single(ty) => Some(to_external_output_json_schema( graph, ty, - JsonSchemaConfig { - include_draft_marker: config.include_draft_marker, - ..JsonSchemaConfig::EXTERNAL_OUTPUT - }, + config.include_draft_marker, )), } } - -/// Whether `ty`, after following any `Ref` chain against `graph`, is an -/// `option<…>`. Used to decide whether an input parameter is required. -fn resolves_to_option(graph: &SchemaGraph, ty: &SchemaType) -> bool { - let mut current = ty; - let mut visited: HashSet = HashSet::new(); - loop { - match current { - SchemaType::Option { .. } => return true, - SchemaType::Ref { id, .. } => { - if !visited.insert(id.clone()) { - return false; - } - match graph.lookup(id) { - Some(def) => current = &def.body, - None => return false, - } - } - _ => return false, - } - } -} - -/// Build a `$defs` object covering every named definition in the graph. -/// -/// Per RFC 6901 §4, JSON Pointer escaping (`~0`/`~1`) applies to the -/// *pointer string*, not to the resolved object member name. The map key -/// is therefore the **raw** `TypeId.0` string; the escaped form is only -/// used inside `$ref` pointers (see [`ref_pointer`]). -pub(super) fn render_defs( - graph: &SchemaGraph, - table: &BranchNameTable, - config: JsonSchemaConfig, -) -> Map { - let mut defs = Map::new(); - for def in &graph.defs { - // The def's metadata now lives on `def.body` directly; `render_type` - // already attaches inline-node metadata, so no extra `attach_metadata` - // call is required here. - let mut body = render_type(graph, &def.body, false, table, config); - if let Some(name) = &def.name - && let Some(obj) = body.as_object_mut() - { - obj.entry("title").or_insert(Value::String(name.clone())); - } - defs.insert(def.id.0.clone(), body); - } - defs -} - -/// Walk every union under the graph and synthesize per-branch `$defs` -/// entries so discriminator-mapping pointers always resolve. -pub(super) fn add_union_branch_defs( - graph: &SchemaGraph, - root_ty: &SchemaType, - defs: &mut Map, - table: &BranchNameTable, - config: JsonSchemaConfig, -) { - let mut emitted = HashSet::new(); - collect_union_branch_defs(graph, root_ty, defs, &mut emitted, table, config); - for def in &graph.defs { - collect_union_branch_defs(graph, &def.body, defs, &mut emitted, table, config); - } -} - -fn collect_union_branch_defs( - graph: &SchemaGraph, - ty: &SchemaType, - defs: &mut Map, - emitted: &mut HashSet, - table: &BranchNameTable, - config: JsonSchemaConfig, -) { - match ty { - SchemaType::Union { spec, .. } => { - for branch in spec.branches.iter() { - let key = table.name_for(branch).to_string(); - if emitted.insert(key.clone()) { - let mut body = render_type(graph, &branch.body, false, table, config); - attach_metadata(&mut body, &branch.metadata); - if let Some(obj) = body.as_object_mut() { - // Constrain the branch schema further with the - // discriminator. For record-shaped rules this adds - // an extra constraint on the discriminator field; - // for string rules it adds a `pattern`/`const`. - apply_discriminator_constraint(obj, &branch.discriminator); - } - defs.insert(key, body); - } - collect_union_branch_defs(graph, &branch.body, defs, emitted, table, config); - } - } - SchemaType::Record { fields, .. } => { - for f in fields { - collect_union_branch_defs(graph, &f.body, defs, emitted, table, config); - } - } - SchemaType::Variant { cases, .. } => { - for case in cases { - if let Some(p) = &case.payload { - collect_union_branch_defs(graph, p, defs, emitted, table, config); - } - } - } - SchemaType::Tuple { elements, .. } => { - for e in elements { - collect_union_branch_defs(graph, e, defs, emitted, table, config); - } - } - SchemaType::List { element, .. } - | SchemaType::FixedList { element, .. } - | SchemaType::Option { inner: element, .. } => { - collect_union_branch_defs(graph, element, defs, emitted, table, config); - } - SchemaType::Map { key, value, .. } => { - collect_union_branch_defs(graph, key, defs, emitted, table, config); - collect_union_branch_defs(graph, value, defs, emitted, table, config); - } - SchemaType::Result { spec, .. } => { - if let Some(t) = &spec.ok { - collect_union_branch_defs(graph, t, defs, emitted, table, config); - } - if let Some(t) = &spec.err { - collect_union_branch_defs(graph, t, defs, emitted, table, config); - } - } - SchemaType::Future { inner, .. } | SchemaType::Stream { inner, .. } => { - if let Some(t) = inner { - collect_union_branch_defs(graph, t, defs, emitted, table, config); - } - } - _ => {} - } -} - -/// Stable, tag-preserving `$defs` / `components.schemas` keys for every -/// union branch reachable from a render root. -/// -/// Built once per render via [`build_branch_name_table`]. The names are -/// derived primarily from each branch's `tag` (sanitised to -/// `UpperCamelCase`) so that types in a generated OpenAPI client carry -/// human-meaningful names rather than opaque content hashes. -/// -/// Collisions (two structurally distinct branches sharing a tag) are -/// resolved by progressively prepending segments from the schema-graph -/// path that reached each branch, mirroring the algorithm used by -/// `bridge_gen::type_naming`. As a last resort — when no contextual -/// disambiguation works — a short hash suffix is appended. -/// -/// Determinism: the walk visits branches in source order; collision -/// resolution iterates the resulting group deterministically. The -/// canonical structural key used internally is a `blake3` hash of the -/// branch's deterministic JSON serialisation. -pub(super) struct BranchNameTable { - names: HashMap, -} - -impl BranchNameTable { - pub(super) fn name_for(&self, branch: &UnionBranch) -> &str { - let key = canonical_branch_key(branch); - self.names.get(&key).map(String::as_str).expect( - "BranchNameTable must contain every union branch reachable from the render root \ - — `build_branch_name_table` is the source of truth for this invariant", - ) - } -} - -pub(super) fn build_branch_name_table( - graph: &SchemaGraph, - root_ty: &SchemaType, -) -> BranchNameTable { - let mut collector = BranchCollector::default(); - collector.walk_type(root_ty); - for def in &graph.defs { - // Each named def starts a fresh path rooted at its name (or - // TypeId fallback); this lets disambiguation lift names through - // the named-def boundary when needed. - collector.path.clear(); - let seg = def.name.clone().unwrap_or_else(|| def.id.0.clone()); - collector.path.push(seg); - collector.walk_type(&def.body); - } - collector.path.clear(); - // Pre-seed `taken` with every named def's TypeId so branch names - // never silently overwrite a real graph def in `$defs`. - let taken: HashSet = graph.defs.iter().map(|d| d.id.0.clone()).collect(); - collector.into_table(taken) -} - -/// Deterministic structural key for a `UnionBranch`. Internal only; -/// never appears in rendered output. -fn canonical_branch_key(branch: &UnionBranch) -> String { - let bytes = serde_json::to_vec(branch).expect("UnionBranch serializes deterministically"); - let hex = blake3::hash(&bytes).to_hex(); - // 128 bits of hash output — sufficient to uniquely identify a branch - // body within any practical schema document. - hex.as_str()[..32].to_string() -} - -#[derive(Default)] -struct BranchCollector { - /// Canonical key for every encountered branch, in walk order, with no - /// duplicates. Used both for membership and for deterministic iteration - /// during name resolution. - keys: Vec, - occurrences: HashMap, - /// Path of segments describing the current position in the schema - /// graph (record-field names, variant-case names, "key"/"value", - /// "ok"/"err", outer branch tags, …). - path: Vec, -} - -struct Occurrence { - tag: String, - /// First path at which this branch was reached. Used to disambiguate - /// colliding preferred names. - path: Vec, -} - -impl BranchCollector { - fn record(&mut self, branch: &UnionBranch) { - let key = canonical_branch_key(branch); - if let std::collections::hash_map::Entry::Vacant(slot) = self.occurrences.entry(key.clone()) - { - slot.insert(Occurrence { - tag: branch.tag.clone(), - path: self.path.clone(), - }); - self.keys.push(key); - } - } - - /// Walk a `SchemaType` subtree, pushing/popping path segments and - /// recording every encountered `UnionBranch`. - /// - /// `Ref(TypeId)` nodes are not followed: the named def they point - /// at is walked separately from `build_branch_name_table` with its - /// own fresh path, so following refs here would record duplicate - /// occurrences and pollute the disambiguation path. - fn walk_type(&mut self, ty: &SchemaType) { - match ty { - SchemaType::Union { spec, .. } => { - for branch in &spec.branches { - self.record(branch); - self.path.push(branch.tag.clone()); - self.walk_type(&branch.body); - self.path.pop(); - } - } - SchemaType::Record { fields, .. } => { - for f in fields { - self.path.push(f.name.clone()); - self.walk_type(&f.body); - self.path.pop(); - } - } - SchemaType::Variant { cases, .. } => { - for case in cases { - if let Some(p) = &case.payload { - self.path.push(case.name.clone()); - self.walk_type(p); - self.path.pop(); - } - } - } - SchemaType::Tuple { elements, .. } => { - for (i, e) in elements.iter().enumerate() { - self.path.push(format!("item{i}")); - self.walk_type(e); - self.path.pop(); - } - } - SchemaType::List { element, .. } | SchemaType::FixedList { element, .. } => { - self.path.push("item".to_string()); - self.walk_type(element); - self.path.pop(); - } - SchemaType::Option { inner, .. } => { - self.path.push("inner".to_string()); - self.walk_type(inner); - self.path.pop(); - } - SchemaType::Map { key, value, .. } => { - self.path.push("key".to_string()); - self.walk_type(key); - self.path.pop(); - self.path.push("value".to_string()); - self.walk_type(value); - self.path.pop(); - } - SchemaType::Result { spec, .. } => { - if let Some(t) = &spec.ok { - self.path.push("ok".to_string()); - self.walk_type(t); - self.path.pop(); - } - if let Some(t) = &spec.err { - self.path.push("err".to_string()); - self.walk_type(t); - self.path.pop(); - } - } - SchemaType::Future { inner, .. } | SchemaType::Stream { inner, .. } => { - if let Some(t) = inner { - self.path.push("inner".to_string()); - self.walk_type(t); - self.path.pop(); - } - } - _ => {} - } - } - - fn into_table(self, mut taken: HashSet) -> BranchNameTable { - // Compute each occurrence's preferred name (from its `tag`) and - // group by it. - let mut groups: Vec<(String, Vec)> = Vec::new(); - for key in &self.keys { - let occ = &self.occurrences[key]; - let preferred = sanitise_to_upper_camel(&occ.tag); - match groups.iter_mut().find(|(name, _)| name == &preferred) { - Some((_, members)) => members.push(key.clone()), - None => groups.push((preferred, vec![key.clone()])), - } - } - - let mut names = HashMap::::new(); - for (preferred, members) in groups { - if members.len() == 1 && !taken.contains(&preferred) { - // Unique preferred name and not colliding with a graph - // def TypeId — use it verbatim. - let only = members.into_iter().next().unwrap(); - taken.insert(preferred.clone()); - names.insert(only, preferred); - } else { - // Real collision (or shadows a graph def): every member - // is forced through location-based disambiguation so the - // assigned names are symmetric. - for key in members { - let occ = &self.occurrences[&key]; - let assigned = disambiguate(&preferred, &occ.path, &taken, &key); - taken.insert(assigned.clone()); - names.insert(key, assigned); - } - } - } - - BranchNameTable { names } - } -} - -/// Find a unique name by progressively prepending sanitised path -/// segments (innermost → outermost) to `base`. Falls back to a short -/// canonical-key suffix if no contextual disambiguation works. -fn disambiguate(base: &str, path: &[String], taken: &HashSet, canonical: &str) -> String { - let mut candidate = base.to_string(); - for seg in path.iter().rev() { - let seg_camel = sanitise_to_upper_camel(seg); - if seg_camel.is_empty() { - continue; - } - candidate = format!("{seg_camel}{candidate}"); - if !taken.contains(&candidate) { - return candidate; - } - } - let suffix_len = 6.min(canonical.len()); - format!("{base}_{}", &canonical[..suffix_len]) -} - -/// Sanitise an arbitrary string to a non-empty UpperCamelCase identifier -/// suitable for both JSON Pointer member names and OpenAPI schema names -/// (alphabet `[A-Za-z0-9]`). Non-alphanumerics are dropped and treated -/// as word separators; a leading digit is prefixed with `_`. -fn sanitise_to_upper_camel(s: &str) -> String { - let mut out = String::with_capacity(s.len()); - let mut upper_next = true; - for ch in s.chars() { - if ch.is_ascii_alphanumeric() { - if upper_next { - for u in ch.to_uppercase() { - out.push(u); - } - upper_next = false; - } else { - out.push(ch); - } - } else { - upper_next = true; - } - } - if out.is_empty() { - return "Branch".to_string(); - } - if out.starts_with(|c: char| c.is_ascii_digit()) { - format!("_{out}") - } else { - out - } -} - -fn apply_discriminator_constraint(obj: &mut Map, rule: &DiscriminatorRule) { - match rule { - DiscriminatorRule::Prefix { prefix } => { - obj.entry("pattern") - .or_insert(Value::String(format!("^{}", regex_escape(prefix)))); - } - DiscriminatorRule::Suffix { suffix } => { - obj.entry("pattern") - .or_insert(Value::String(format!("{}$", regex_escape(suffix)))); - } - DiscriminatorRule::Contains { substring } => { - obj.entry("pattern") - .or_insert(Value::String(regex_escape(substring))); - } - DiscriminatorRule::Regex { regex } => { - obj.entry("pattern").or_insert(Value::String(regex.clone())); - } - DiscriminatorRule::FieldEquals(disc) => { - // Constrain the field's value with `const` if a literal is set; - // otherwise just require the field to be present. - let mut required = obj - .get("required") - .and_then(Value::as_array) - .cloned() - .unwrap_or_default(); - if !required - .iter() - .any(|v| v.as_str() == Some(disc.field_name.as_str())) - { - required.push(Value::String(disc.field_name.clone())); - } - obj.insert("required".to_string(), Value::Array(required)); - if let Some(lit) = &disc.literal { - let props = obj - .entry("properties") - .or_insert_with(|| Value::Object(Map::new())) - .as_object_mut() - .expect("properties is object"); - let field = props - .entry(disc.field_name.clone()) - .or_insert_with(|| obj_inline([("type", Value::String("string".to_string()))])); - if let Some(field_obj) = field.as_object_mut() { - field_obj - .entry("const") - .or_insert(Value::String(lit.clone())); - } - } - } - DiscriminatorRule::FieldAbsent { field_name } => { - // Express absence via `not: { required: [field] }`. - let not = obj_inline([( - "required", - Value::Array(vec![Value::String(field_name.clone())]), - )]); - obj.insert("not".to_string(), not); - } - } -} - -pub(super) fn render_type( - graph: &SchemaGraph, - ty: &SchemaType, - root: bool, - table: &BranchNameTable, - config: JsonSchemaConfig, -) -> Value { - let mut rendered = match ty { - SchemaType::Ref { id, .. } => obj([("$ref", Value::String(ref_pointer(id, root)))]), - - SchemaType::Bool { .. } => obj([("type", Value::String("boolean".to_string()))]), - SchemaType::S8 { .. } => integer_schema(i8::MIN as i64, i8::MAX as i64), - SchemaType::S16 { .. } => integer_schema(i16::MIN as i64, i16::MAX as i64), - SchemaType::S32 { .. } => integer_schema(i32::MIN as i64, i32::MAX as i64), - SchemaType::S64 { .. } => integer_schema(i64::MIN, i64::MAX), - SchemaType::U8 { .. } => integer_schema(0, u8::MAX as i64), - SchemaType::U16 { .. } => integer_schema(0, u16::MAX as i64), - SchemaType::U32 { .. } => integer_schema(0, u32::MAX as i64), - SchemaType::U64 { .. } => unsigned_64_schema(), - SchemaType::F32 { .. } | SchemaType::F64 { .. } => { - obj([("type", Value::String("number".to_string()))]) - } - SchemaType::Char { .. } => obj([ - ("type", Value::String("string".to_string())), - ("minLength", Value::Number(1.into())), - ("maxLength", Value::Number(1.into())), - ]), - SchemaType::String { .. } => obj([("type", Value::String("string".to_string()))]), - - SchemaType::Record { fields, .. } => { - let mut props = Map::new(); - let mut required = Vec::with_capacity(fields.len()); - for field in fields { - let mut field_schema = render_type(graph, &field.body, false, table, config); - attach_metadata(&mut field_schema, &field.metadata); - props.insert(field.name.clone(), field_schema); - // `option<…>` fields are not required: the field may be omitted - // entirely, and an explicit `null` is still accepted by the - // option's `oneOf [null, T]` schema. - if !resolves_to_option(graph, &field.body) { - required.push(Value::String(field.name.clone())); - } - } - obj([ - ("type", Value::String("object".to_string())), - ("properties", Value::Object(props)), - ("required", Value::Array(required)), - ("additionalProperties", Value::Bool(false)), - ]) - } - - SchemaType::Variant { cases, .. } => { - Value::Object(variant_schema(graph, cases, table, config)) - } - - SchemaType::Enum { cases, .. } => obj([ - ("type", Value::String("string".to_string())), - ( - "enum", - Value::Array(cases.iter().cloned().map(Value::String).collect()), - ), - ]), - - SchemaType::Flags { flags, .. } => obj([ - ("type", Value::String("array".to_string())), - ( - "items", - obj([ - ("type", Value::String("string".to_string())), - ( - "enum", - Value::Array(flags.iter().cloned().map(Value::String).collect()), - ), - ]), - ), - ("uniqueItems", Value::Bool(true)), - ]), - - SchemaType::Tuple { elements, .. } => { - if elements.is_empty() { - // JSON Schema 2020-12 requires `prefixItems` to be a - // non-empty array, so the empty-tuple shape uses - // `maxItems`/`minItems` only. - obj([ - ("type", Value::String("array".to_string())), - ("minItems", Value::Number(0u64.into())), - ("maxItems", Value::Number(0u64.into())), - ]) - } else { - obj([ - ("type", Value::String("array".to_string())), - ( - "prefixItems", - Value::Array( - elements - .iter() - .map(|e| render_type(graph, e, false, table, config)) - .collect(), - ), - ), - ("items", Value::Bool(false)), - ("minItems", Value::Number((elements.len() as u64).into())), - ]) - } - } - - SchemaType::List { element, .. } => obj([ - ("type", Value::String("array".to_string())), - ("items", render_type(graph, element, false, table, config)), - ]), - - SchemaType::FixedList { - element, length, .. - } => obj([ - ("type", Value::String("array".to_string())), - ("items", render_type(graph, element, false, table, config)), - ("minItems", Value::Number((*length).into())), - ("maxItems", Value::Number((*length).into())), - ]), - - SchemaType::Map { key, value, .. } => { - let pair = obj([ - ("type", Value::String("array".to_string())), - ( - "prefixItems", - Value::Array(vec![ - render_type(graph, key, false, table, config), - render_type(graph, value, false, table, config), - ]), - ), - ("items", Value::Bool(false)), - ("minItems", Value::Number(2.into())), - ("maxItems", Value::Number(2.into())), - ]); - obj([ - ("type", Value::String("array".to_string())), - ("items", pair), - ]) - } - - SchemaType::Option { inner, .. } => obj([( - "oneOf", - Value::Array(vec![ - obj([("type", Value::String("null".to_string()))]), - render_type(graph, inner, false, table, config), - ]), - )]), - - SchemaType::Result { spec, .. } => Value::Object(result_schema(graph, spec, table, config)), - - SchemaType::Text { restrictions, .. } => Value::Object(text_schema(restrictions)), - SchemaType::Binary { restrictions, .. } => Value::Object(binary_schema(restrictions)), - SchemaType::Path { spec, .. } => Value::Object(path_schema(spec)), - SchemaType::Url { restrictions, .. } => Value::Object(url_schema(restrictions)), - SchemaType::Datetime { .. } => obj([ - ("type", Value::String("string".to_string())), - ("format", Value::String("date-time".to_string())), - ]), - SchemaType::Duration { .. } => obj([ - ("type", Value::String("string".to_string())), - ("format", Value::String("duration".to_string())), - ]), - SchemaType::Quantity { spec, .. } => Value::Object(quantity_schema(spec)), - - SchemaType::Union { spec, .. } => Value::Object(union_schema(graph, spec, table, config)), - - SchemaType::Secret { spec, .. } => { - host_managed_schema(config.host_managed, "secret", || { - Value::Object(secret_schema(spec)) - }) - } - SchemaType::QuotaToken { spec, .. } => { - host_managed_schema(config.host_managed, "quota-token", || { - Value::Object(quota_token_schema(spec)) - }) - } - SchemaType::PermissionCard { spec, .. } => { - host_managed_schema(config.host_managed, "permission-card", || { - Value::Object(permission_card_schema(spec)) - }) - } - - SchemaType::Future { .. } | SchemaType::Stream { .. } => obj([ - ("type", Value::String("null".to_string())), - ( - "description", - Value::String("WASI P3 placeholder".to_string()), - ), - ]), - }; - - // Per-node metadata: attach docs / examples / deprecated for every - // SchemaType node so inline-typed positions (record fields, list - // elements, etc.) propagate their metadata into the generated JSON - // Schema, not only named definitions. - attach_metadata(&mut rendered, ty.metadata()); - rendered -} - -fn host_managed_schema( - policy: HostManagedSchemaPolicy, - kind: &str, - trusted: impl FnOnce() -> Value, -) -> Value { - match policy { - HostManagedSchemaPolicy::TrustedSnapshot => trusted(), - HostManagedSchemaPolicy::Reject => obj([ - ("not", Value::Object(Map::new())), - ( - "description", - Value::String(format!( - "Host-managed {kind} capabilities cannot be supplied externally" - )), - ), - ]), - HostManagedSchemaPolicy::Redact => obj([ - ("type", Value::String("string".to_string())), - ("const", Value::String(format!(""))), - ( - "description", - Value::String(format!( - "Host-managed {kind} capability values are redacted" - )), - ), - ]), - } -} - -fn ref_pointer(id: &TypeId, _root: bool) -> String { - ref_to_def_key(&id.0) -} - -/// Build the `$ref` pointer string for a raw `$defs` member key. -/// -/// `key` is the raw (un-escaped) member name; this helper applies -/// RFC 6901 JSON Pointer escaping when embedding it in the pointer path. -pub(super) fn ref_to_def_key(key: &str) -> String { - format!("#/$defs/{}", escape_pointer_token(key)) -} - -fn integer_schema(min: i64, max: i64) -> Value { - obj([ - ("type", Value::String("integer".to_string())), - ("minimum", Value::Number(Number::from(min))), - ("maximum", Value::Number(Number::from(max))), - ]) -} - -fn unsigned_64_schema() -> Value { - obj([ - ("type", Value::String("integer".to_string())), - ("minimum", Value::Number(Number::from(0u64))), - ("maximum", Value::Number(Number::from(u64::MAX))), - ]) -} - -fn variant_schema( - graph: &SchemaGraph, - cases: &[VariantCaseType], - table: &BranchNameTable, - config: JsonSchemaConfig, -) -> Map { - let one_of: Vec = cases - .iter() - .map(|case| match &case.payload { - None => obj([("const", Value::String(case.name.clone()))]), - Some(payload_ty) => { - let mut props = Map::new(); - props.insert( - case.name.clone(), - render_type(graph, payload_ty, false, table, config), - ); - obj([ - ("type", Value::String("object".to_string())), - ("properties", Value::Object(props)), - ( - "required", - Value::Array(vec![Value::String(case.name.clone())]), - ), - ("additionalProperties", Value::Bool(false)), - ]) - } - }) - .collect(); - let mut out = Map::new(); - out.insert("oneOf".to_string(), Value::Array(one_of)); - out -} - -fn result_schema( - graph: &SchemaGraph, - spec: &ResultSpec, - table: &BranchNameTable, - config: JsonSchemaConfig, -) -> Map { - let ok_inner = spec - .ok - .as_deref() - .map(|t| render_type(graph, t, false, table, config)) - .unwrap_or_else(|| obj([("type", Value::String("null".to_string()))])); - let err_inner = spec - .err - .as_deref() - .map(|t| render_type(graph, t, false, table, config)) - .unwrap_or_else(|| obj([("type", Value::String("null".to_string()))])); - let one_of = vec![ - obj([ - ("type", Value::String("object".to_string())), - ( - "properties", - Value::Object({ - let mut m = Map::new(); - m.insert("ok".to_string(), ok_inner); - m - }), - ), - ("required", Value::Array(vec![Value::String("ok".into())])), - ("additionalProperties", Value::Bool(false)), - ]), - obj([ - ("type", Value::String("object".to_string())), - ( - "properties", - Value::Object({ - let mut m = Map::new(); - m.insert("err".to_string(), err_inner); - m - }), - ), - ("required", Value::Array(vec![Value::String("err".into())])), - ("additionalProperties", Value::Bool(false)), - ]), - ]; - let mut out = Map::new(); - out.insert("oneOf".to_string(), Value::Array(one_of)); - out -} - -fn text_schema(restrictions: &TextRestrictions) -> Map { - // Canonical Text JSON shape: `{ text: string, language?: string }` with - // length / pattern constraints lifted into the `text` field. - let mut text_field = Map::new(); - text_field.insert("type".to_string(), Value::String("string".to_string())); - if let Some(min) = restrictions.min_length { - text_field.insert("minLength".to_string(), Value::Number(min.into())); - } - if let Some(max) = restrictions.max_length { - text_field.insert("maxLength".to_string(), Value::Number(max.into())); - } - if let Some(regex) = &restrictions.regex { - text_field.insert("pattern".to_string(), Value::String(regex.clone())); - } - let mut properties = Map::new(); - properties.insert("text".to_string(), Value::Object(text_field)); - properties.insert( - "language".to_string(), - obj([("type", Value::String("string".to_string()))]), - ); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(properties)); - m.insert( - "required".to_string(), - Value::Array(vec![Value::String("text".to_string())]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - if let Some(langs) = &restrictions.languages { - m.insert( - "description".to_string(), - Value::String(format!("Allowed languages: {}", langs.join(", "))), - ); - } - m -} - -fn binary_schema(restrictions: &BinaryRestrictions) -> Map { - // Canonical Binary JSON shape: `{ bytes: base64url-string, mime_type?: string }`. - // `min_bytes` / `max_bytes` count *raw* bytes; the JSON field is - // base64url-no-pad-encoded, so the on-wire string length is - // `base64url_no_pad_len(n) = 4*(n/3) + match n%3 { 0=>0, 1=>2, 2=>3 }`. - let mut bytes_field = Map::new(); - bytes_field.insert("type".to_string(), Value::String("string".to_string())); - bytes_field.insert( - "contentEncoding".to_string(), - Value::String("base64url".to_string()), - ); - if let Some(min) = restrictions.min_bytes { - bytes_field.insert( - "minLength".to_string(), - Value::Number(base64url_no_pad_len(min).into()), - ); - } - if let Some(max) = restrictions.max_bytes { - bytes_field.insert( - "maxLength".to_string(), - Value::Number(base64url_no_pad_len(max).into()), - ); - } - let mut mime_field = Map::new(); - mime_field.insert("type".to_string(), Value::String("string".to_string())); - mime_field.insert( - "pattern".to_string(), - Value::String(MIME_TYPE_PATTERN.to_string()), - ); - let mut properties = Map::new(); - properties.insert("bytes".to_string(), Value::Object(bytes_field)); - properties.insert("mimeType".to_string(), Value::Object(mime_field)); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(properties)); - m.insert( - "required".to_string(), - Value::Array(vec![Value::String("bytes".to_string())]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - if let Some(mimes) = &restrictions.mime_types { - m.insert( - "description".to_string(), - Value::String(format!("Allowed MIME types: {}", mimes.join(", "))), - ); - } - m -} - -fn path_schema(spec: &PathSpec) -> Map { - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("string".to_string())); - m.insert("format".to_string(), Value::String("file-path".to_string())); - let kind = match spec.kind { - crate::schema::schema_type::PathKind::File => "file", - crate::schema::schema_type::PathKind::Directory => "directory", - crate::schema::schema_type::PathKind::Any => "any", - }; - let direction = match spec.direction { - crate::schema::schema_type::PathDirection::Input => "input", - crate::schema::schema_type::PathDirection::Output => "output", - crate::schema::schema_type::PathDirection::InOut => "inout", - }; - m.insert( - "title".to_string(), - Value::String(format!("{direction} {kind} path")), - ); - let mut description = Vec::new(); - if let Some(exts) = &spec.allowed_extensions { - description.push(format!("Allowed extensions: {}", exts.join(", "))); - } - if let Some(mimes) = &spec.allowed_mime_types { - description.push(format!("Allowed MIME types: {}", mimes.join(", "))); - } - if !description.is_empty() { - m.insert( - "description".to_string(), - Value::String(description.join("; ")), - ); - } - m -} - -fn url_schema(restrictions: &UrlRestrictions) -> Map { - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("string".to_string())); - m.insert("format".to_string(), Value::String("uri".to_string())); - m.insert("title".to_string(), Value::String("URL".to_string())); - let mut description = Vec::new(); - if let Some(schemes) = &restrictions.allowed_schemes { - description.push(format!("Allowed schemes: {}", schemes.join(", "))); - } - if let Some(hosts) = &restrictions.allowed_hosts { - description.push(format!("Allowed hosts: {}", hosts.join(", "))); - } - if !description.is_empty() { - m.insert( - "description".to_string(), - Value::String(description.join("; ")), - ); - } - m -} - -fn quantity_schema(spec: &QuantitySpec) -> Map { - let mut props = Map::new(); - props.insert( - "mantissa".to_string(), - obj([("type", Value::String("integer".to_string()))]), - ); - props.insert( - "scale".to_string(), - obj([("type", Value::String("integer".to_string()))]), - ); - props.insert( - "unit".to_string(), - obj([("type", Value::String("string".to_string()))]), - ); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(props)); - m.insert( - "required".to_string(), - Value::Array(vec![ - Value::String("mantissa".to_string()), - Value::String("scale".to_string()), - Value::String("unit".to_string()), - ]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - m.insert( - "title".to_string(), - Value::String(format!("Quantity ({})", spec.base_unit)), - ); - let mut description = Vec::new(); - if let Some(min) = &spec.min { - description.push(format!("min: {}", render_quantity(min))); - } - if let Some(max) = &spec.max { - description.push(format!("max: {}", render_quantity(max))); - } - if !description.is_empty() { - m.insert( - "description".to_string(), - Value::String(description.join("; ")), - ); - } - m -} - -fn render_quantity(q: &QuantityValue) -> String { - format!("{}e-{} {}", q.mantissa, q.scale, q.unit) -} - -fn secret_schema(_spec: &SecretSpec) -> Map { - // Canonical Secret JSON shape: see canonical/secret.rs. - let secret_id = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("uuid".to_string())), - ]); - let config_key = obj_inline([ - ("type", Value::String("array".to_string())), - ( - "items", - obj_inline([("type", Value::String("string".to_string()))]), - ), - ]); - let version = obj_inline([ - ("type", Value::String("integer".to_string())), - ("minimum", Value::Number(0.into())), - ]); - let resolved_at = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("date-time".to_string())), - ]); - let category = obj_inline([("type", Value::String("string".to_string()))]); - let mut properties = Map::new(); - properties.insert("secretId".to_string(), secret_id); - properties.insert("configKey".to_string(), config_key); - properties.insert("version".to_string(), version); - properties.insert("resolvedAt".to_string(), resolved_at); - properties.insert("category".to_string(), category); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(properties)); - m.insert( - "required".to_string(), - Value::Array(vec![ - Value::String("secretId".to_string()), - Value::String("version".to_string()), - Value::String("resolvedAt".to_string()), - ]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - m -} - -fn quota_token_schema(_spec: &QuotaTokenSpec) -> Map { - // Canonical QuotaToken JSON shape: see canonical/quota_token.rs. - let env_id = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("uuid".to_string())), - ]); - let resource_name = obj_inline([("type", Value::String("string".to_string()))]); - let expected_use = obj_inline([( - "oneOf", - Value::Array(vec![ - obj_inline([ - ("type", Value::String("string".to_string())), - ("pattern", Value::String("^[0-9]+$".to_string())), - ]), - obj_inline([ - ("type", Value::String("integer".to_string())), - ("minimum", Value::Number(0u64.into())), - ]), - ]), - )]); - let last_credit = obj_inline([( - "oneOf", - Value::Array(vec![ - obj_inline([ - ("type", Value::String("string".to_string())), - ("pattern", Value::String("^-?[0-9]+$".to_string())), - ]), - obj_inline([("type", Value::String("integer".to_string()))]), - ]), - )]); - let last_credit_at = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("date-time".to_string())), - ]); - let mut properties = Map::new(); - properties.insert("environmentId".to_string(), env_id); - properties.insert("resourceName".to_string(), resource_name); - properties.insert("expectedUse".to_string(), expected_use); - properties.insert("lastCredit".to_string(), last_credit); - properties.insert("lastCreditAt".to_string(), last_credit_at); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(properties)); - m.insert( - "required".to_string(), - Value::Array(vec![ - Value::String("environmentId".to_string()), - Value::String("resourceName".to_string()), - Value::String("expectedUse".to_string()), - Value::String("lastCredit".to_string()), - Value::String("lastCreditAt".to_string()), - ]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - m -} - -fn permission_card_schema(_spec: &PermissionCardSpec) -> Map { - // Permission-card values are opaque capability handles. The transported - // snapshot carries card_id (authoritative), parent_ids, expires_at, and - // polymorphic as trusted cache. See canonical/permission_card.rs. - let card_id = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("uuid".to_string())), - ]); - let parent_ids = obj_inline([ - ("type", Value::String("array".to_string())), - ( - "items", - obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("uuid".to_string())), - ]), - ), - ]); - let expires_at = obj_inline([ - ("type", Value::String("string".to_string())), - ("format", Value::String("date-time".to_string())), - ]); - let polymorphic = obj_inline([("type", Value::String("boolean".to_string()))]); - let mut properties = Map::new(); - properties.insert("cardId".to_string(), card_id); - properties.insert("parentIds".to_string(), parent_ids); - properties.insert("expiresAt".to_string(), expires_at); - properties.insert("polymorphic".to_string(), polymorphic); - let mut m = Map::new(); - m.insert("type".to_string(), Value::String("object".to_string())); - m.insert("properties".to_string(), Value::Object(properties)); - m.insert( - "required".to_string(), - Value::Array(vec![ - Value::String("cardId".to_string()), - Value::String("polymorphic".to_string()), - ]), - ); - m.insert("additionalProperties".to_string(), Value::Bool(false)); - m -} - -fn union_schema( - graph: &SchemaGraph, - spec: &UnionSpec, - table: &BranchNameTable, - config: JsonSchemaConfig, -) -> Map { - // Each branch gets a per-branch reference into `$defs` (synthesised - // by `add_union_branch_defs`), so the `oneOf` and any discriminator - // mapping resolves against schemas the renderer actually emits. The - // branch key is resolved through `BranchNameTable` so two unrelated - // unions sharing a tag get disambiguated names. - let one_of: Vec = spec - .branches - .iter() - .map(|b| obj([("$ref", Value::String(ref_to_def_key(table.name_for(b))))])) - .collect(); - let mut m = Map::new(); - m.insert("oneOf".to_string(), Value::Array(one_of)); - if let Some(disc_field) = openapi_discriminator(spec) { - let mut mapping = Map::new(); - for branch in spec.branches.iter() { - let literal = match &branch.discriminator { - DiscriminatorRule::FieldEquals(disc) => disc.literal.clone(), - _ => None, - }; - if let Some(lit) = literal { - mapping.insert(lit, Value::String(ref_to_def_key(table.name_for(branch)))); - } - } - let mut d = Map::new(); - d.insert("propertyName".to_string(), Value::String(disc_field)); - if !mapping.is_empty() { - d.insert("mapping".to_string(), Value::Object(mapping)); - } - m.insert("discriminator".to_string(), Value::Object(d)); - } - let _ = graph; - let _ = config; - m -} - -fn openapi_discriminator(spec: &UnionSpec) -> Option { - let mut field: Option = None; - for branch in spec.branches.iter() { - match &branch.discriminator { - DiscriminatorRule::FieldEquals(disc) => { - let _ = disc.literal.as_ref()?; - match &field { - Some(prev) if prev != &disc.field_name => return None, - Some(_) => {} - None => field = Some(disc.field_name.clone()), - } - } - _ => return None, - } - } - field -} - -fn attach_metadata(target: &mut Value, metadata: &MetadataEnvelope) { - if metadata.is_empty() { - return; - } - let Some(obj) = target.as_object_mut() else { - return; - }; - if let Some(doc) = &metadata.doc { - obj.entry("description") - .or_insert(Value::String(doc.clone())); - } - if !metadata.examples.is_empty() { - obj.entry("examples").or_insert_with(|| { - Value::Array( - metadata - .examples - .iter() - .map(|e| Value::String(e.clone())) - .collect(), - ) - }); - } - if let Some(dep) = &metadata.deprecated { - obj.entry("deprecated").or_insert(Value::Bool(true)); - obj.entry("x-golem-deprecation-note") - .or_insert(Value::String(dep.clone())); - } -} - -/// Number of base64url-no-pad characters required to encode `n` raw bytes. -/// Matches the alphabet used by [`crate::schema::canonical::binary`] which -/// uses `base64::engine::general_purpose::URL_SAFE_NO_PAD`. -fn base64url_no_pad_len(n: u32) -> u64 { - let n = n as u64; - 4 * (n / 3) - + match n % 3 { - 0 => 0, - 1 => 2, - 2 => 3, - _ => unreachable!(), - } -} - -/// Escape a string for use as a single JSON-Pointer token: `~` becomes `~0` -/// and `/` becomes `~1` per RFC 6901. -fn escape_pointer_token(s: &str) -> String { - let mut out = String::with_capacity(s.len()); - for ch in s.chars() { - match ch { - '~' => out.push_str("~0"), - '/' => out.push_str("~1"), - other => out.push(other), - } - } - out -} - -/// Escape a string for inclusion as a literal in a basic regex pattern. -fn regex_escape(s: &str) -> String { - let specials: &[char] = &[ - '\\', '^', '$', '.', '|', '?', '*', '+', '(', ')', '[', ']', '{', '}', - ]; - let mut out = String::with_capacity(s.len()); - for ch in s.chars() { - if specials.contains(&ch) { - out.push('\\'); - } - out.push(ch); - } - out -} - -fn obj>(entries: I) -> Value { - let mut map = Map::new(); - for (k, v) in entries { - map.insert(k.to_string(), v); - } - Value::Object(map) -} - -fn obj_inline>(entries: I) -> Value { - obj(entries) -} diff --git a/golem-common/src/schema/render/mod.rs b/golem-common/src/schema/render/mod.rs index e04e4c55c8..2d97cd81ea 100644 --- a/golem-common/src/schema/render/mod.rs +++ b/golem-common/src/schema/render/mod.rs @@ -21,11 +21,7 @@ pub mod cli_text; pub mod docs; -pub mod error; pub mod json_schema; -pub mod json_value; -pub mod openapi; -pub mod walker; #[cfg(test)] mod tests; @@ -35,16 +31,4 @@ pub use cli_text::{ value_to_cli_text_with_secret_metadata, }; pub use docs::graph_to_markdown; -pub use error::RenderError; -pub use json_schema::{ - JsonSchemaConfig, input_schema_to_json_schema, output_schema_to_json_schema, to_json_schema, - to_json_schema_with_config, -}; -pub use json_value::{ - from_json_value, from_untrusted_json_value, to_json_value, to_json_value_redacted, -}; -pub use openapi::{ - to_external_input_openapi_components, to_external_output_openapi_components, - to_openapi_components, -}; -pub use walker::{SchemaWalker, WalkerError, resolve_ref, walk}; +pub use json_schema::{input_schema_to_json_schema, output_schema_to_json_schema}; diff --git a/golem-common/src/schema/render/tests/json_schema_props.rs b/golem-common/src/schema/render/tests/json_schema_props.rs index f5cbe0a983..e0e5ed554f 100644 --- a/golem-common/src/schema/render/tests/json_schema_props.rs +++ b/golem-common/src/schema/render/tests/json_schema_props.rs @@ -23,9 +23,10 @@ use crate::schema::graph::SchemaTypeDef; use crate::schema::metadata::TypeId; use crate::schema::proptest_strategies::schema_graph_strategy; use crate::schema::render::json_schema::{ - JsonSchemaConfig, input_schema_to_json_schema, output_schema_to_json_schema, to_json_schema, + input_schema_to_json_schema, output_schema_to_json_schema, }; use crate::schema::schema_type::{NamedFieldType, SchemaType}; +use golem_schema::schema::render::{JsonSchemaConfig, to_json_schema}; use proptest::prelude::*; use serde_json::Value; use test_r::test; diff --git a/golem-common/src/schema/render/tests/json_schema_tests.rs b/golem-common/src/schema/render/tests/json_schema_tests.rs index 32016b22f1..7ca3d3d8ad 100644 --- a/golem-common/src/schema/render/tests/json_schema_tests.rs +++ b/golem-common/src/schema/render/tests/json_schema_tests.rs @@ -13,11 +13,11 @@ // limitations under the License. use crate::schema::graph::SchemaGraph; -use crate::schema::render::json_schema::to_json_schema; use crate::schema::schema_type::{ DiscriminatorRule, FieldDiscriminator, NamedFieldType, SchemaType, TextRestrictions, UnionBranch, UnionSpec, VariantCaseType, }; +use golem_schema::schema::render::json_schema::to_json_schema; use serde_json::{Value, json}; use test_r::test; @@ -810,9 +810,9 @@ mod agent_entry_points { }; use crate::schema::metadata::Role; use crate::schema::render::json_schema::{ - JsonSchemaConfig, input_schema_to_json_schema, output_schema_to_json_schema, - to_json_schema_with_config, + input_schema_to_json_schema, output_schema_to_json_schema, }; + use golem_schema::schema::render::json_schema::{JsonSchemaConfig, to_json_schema_with_config}; use test_r::test; #[test] diff --git a/golem-common/src/schema/render/tests/json_value_tests.rs b/golem-common/src/schema/render/tests/json_value_tests.rs index d6cbd99012..560ad06ba7 100644 --- a/golem-common/src/schema/render/tests/json_value_tests.rs +++ b/golem-common/src/schema/render/tests/json_value_tests.rs @@ -15,10 +15,6 @@ use crate::schema::graph::SchemaGraph; use crate::schema::metadata::Role; use crate::schema::proptest_strategies::schema_values_eq; -use crate::schema::render::error::RenderError; -use crate::schema::render::json_value::{ - from_json_value, from_untrusted_json_value, to_json_value, to_json_value_redacted, -}; use crate::schema::render::tests::paired_strategy::paired_strategy; use crate::schema::schema_type::{ DiscriminatorRule, FieldDiscriminator, NamedFieldType, PermissionCardSpec, QuotaTokenSpec, @@ -30,6 +26,10 @@ use crate::schema::schema_value::{ }; use crate::schema::validation::validate_graph; use chrono::{TimeZone, Utc}; +use golem_schema::schema::render::error::RenderError; +use golem_schema::schema::render::json_value::{ + from_json_value, from_untrusted_json_value, to_json_value, to_json_value_redacted, +}; use proptest::prelude::*; use serde_json::json; use test_r::test; @@ -58,7 +58,7 @@ proptest! { fn json_value_validates_against_json_schema((ty, value) in paired_strategy()) { let graph = SchemaGraph::anonymous(ty.clone()); let json = to_json_value(&graph, &ty, &value).expect("to_json_value"); - let schema = crate::schema::render::json_schema::to_json_schema(&graph, &ty); + let schema = golem_schema::schema::render::json_schema::to_json_schema(&graph, &ty); let compiled = jsonschema::draft202012::new(&schema).expect("compile schema"); prop_assert!( compiled.is_valid(&json), @@ -788,7 +788,7 @@ fn permission_card_json_round_trip_matches_schema_and_redacts() { let decoded = from_json_value(&graph, &ty, &json).expect("decode permission-card"); assert_eq!(decoded, value); - let schema = crate::schema::render::json_schema::to_json_schema(&graph, &ty); + let schema = golem_schema::schema::render::json_schema::to_json_schema(&graph, &ty); let compiled = jsonschema::draft202012::new(&schema).expect("compile permission-card schema"); assert!( compiled.is_valid(&json), diff --git a/golem-common/src/schema/render/tests/openapi_tests.rs b/golem-common/src/schema/render/tests/openapi_tests.rs index 24abbf4d03..b895769f67 100644 --- a/golem-common/src/schema/render/tests/openapi_tests.rs +++ b/golem-common/src/schema/render/tests/openapi_tests.rs @@ -14,10 +14,10 @@ use crate::schema::graph::{SchemaGraph, SchemaTypeDef}; use crate::schema::metadata::TypeId; -use crate::schema::render::openapi::to_openapi_components; use crate::schema::schema_type::{ DiscriminatorRule, FieldDiscriminator, NamedFieldType, SchemaType, UnionBranch, UnionSpec, }; +use golem_schema::schema::render::openapi::to_openapi_components; use serde_json::{Value, json}; use test_r::test; diff --git a/golem-common/src/schema/render/tests/walker_tests.rs b/golem-common/src/schema/render/tests/walker_tests.rs index 4581101562..5270843348 100644 --- a/golem-common/src/schema/render/tests/walker_tests.rs +++ b/golem-common/src/schema/render/tests/walker_tests.rs @@ -14,9 +14,9 @@ use crate::schema::graph::{SchemaGraph, SchemaTypeDef}; use crate::schema::metadata::TypeId; -use crate::schema::render::walker::{SchemaWalker, WalkerError, walk}; use crate::schema::schema_type::SchemaType; use crate::schema::schema_value::SchemaValue; +use golem_schema::schema::render::walker::{SchemaWalker, WalkerError, walk}; use test_r::test; struct CountingWalker { diff --git a/golem-common/wit/deps/golem-agent/host.wit b/golem-common/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/golem-common/wit/deps/golem-agent/host.wit +++ b/golem-common/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/golem-debugging-service/src/debug_context.rs b/golem-debugging-service/src/debug_context.rs index 251d3469eb..c5b33208b6 100644 --- a/golem-debugging-service/src/debug_context.rs +++ b/golem-debugging-service/src/debug_context.rs @@ -439,6 +439,20 @@ impl HostWasmRpc for DebugContext { .await } + async fn create( + &mut self, + agent_type_name: String, + constructor: golem_schema::schema::wit::wire::SchemaValueTree, + phantom_id: Option, + config: Vec< + golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue, + >, + ) -> anyhow::Result, RpcError>> { + self.durable_ctx + .create(agent_type_name, constructor, phantom_id, config) + .await + } + async fn invoke_and_await( &mut self, self_: Resource, diff --git a/golem-registry-service/Cargo.toml b/golem-registry-service/Cargo.toml index d3c57108d0..d2a2e1b91c 100644 --- a/golem-registry-service/Cargo.toml +++ b/golem-registry-service/Cargo.toml @@ -22,6 +22,7 @@ harness = false [dependencies] golem-api-grpc = { workspace = true } golem-common = { workspace = true, default-features = true } +golem-schema = { workspace = true } golem-service-base = { workspace = true } anyhow = { workspace = true } diff --git a/golem-registry-service/src/repo/model/component.rs b/golem-registry-service/src/repo/model/component.rs index 32d273b02c..4d95c83c37 100644 --- a/golem-registry-service/src/repo/model/component.rs +++ b/golem-registry-service/src/repo/model/component.rs @@ -180,7 +180,7 @@ impl ComponentRevisionRecord { Ok(( e.path.join("."), NormalizedJsonValue::new( - golem_common::schema::render::to_json_value( + golem_schema::schema::render::to_json_value( e.value.graph(), e.value.root_type(), e.value.value(), diff --git a/golem-registry-service/src/services/component/write.rs b/golem-registry-service/src/services/component/write.rs index 58333c82df..f0da700b97 100644 --- a/golem-registry-service/src/services/component/write.rs +++ b/golem-registry-service/src/services/component/write.rs @@ -60,10 +60,10 @@ use golem_common::model::worker::AgentConfigEntryDto; use golem_common::model::worker::TypedAgentConfigEntry; use golem_common::schema::SchemaValue; use golem_common::schema::agent::{AgentTypeSchema, typed_schema_value_with_projected_defs}; -use golem_common::schema::render::from_untrusted_json_value; use golem_common::schema::tool::Tool; use golem_common::schema::tool::validation::validate_tool; use golem_common::schema::validation::{is_equivalent_cross_graph, validate_value}; +use golem_schema::schema::render::from_untrusted_json_value; use golem_service_base::model::auth::{AuthCtx, AuthorizationError}; use golem_service_base::model::component::Component; use golem_service_base::replayable_stream::ReplayableStream; diff --git a/golem-registry-service/src/services/deployment/deployment_context.rs b/golem-registry-service/src/services/deployment/deployment_context.rs index 186e2771ea..932af04925 100644 --- a/golem-registry-service/src/services/deployment/deployment_context.rs +++ b/golem-registry-service/src/services/deployment/deployment_context.rs @@ -50,7 +50,6 @@ use golem_common::model::tool::{ use golem_common::model::tool_release::ToolReleaseId; use golem_common::schema::agent::reachable_defs; use golem_common::schema::graph::SchemaGraph; -use golem_common::schema::render; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::tool::validation::validate_tool; use golem_common::schema::validation::is_equivalent_cross_graph; @@ -1067,7 +1066,8 @@ fn compile_tool_binding( /// /// The deployment request DTO carries ergonomic, human-shaped JSON (raw /// scalars, field-named record objects). It is decoded directly into a -/// schema-native [`SchemaValue`] via [`render::from_untrusted_json_value`], which both +/// schema-native [`SchemaValue`] via +/// [`golem_schema::schema::render::from_untrusted_json_value`], which both /// type-checks the payload against the agent-declared schema and produces the /// value in one step. fn parse_default_secret_value( @@ -1077,11 +1077,14 @@ fn parse_default_secret_value( ) -> Result, DeployValidationError> { default .map(|sd| { - render::from_untrusted_json_value(schema, &schema.root, &sd.secret_value).map_err(|e| { - DeployValidationError::AgentSecretDefaultTypeMismatch { - path: path.clone(), - errors: vec![e.to_string()], - } + golem_schema::schema::render::from_untrusted_json_value( + schema, + &schema.root, + &sd.secret_value, + ) + .map_err(|e| DeployValidationError::AgentSecretDefaultTypeMismatch { + path: path.clone(), + errors: vec![e.to_string()], }) }) .transpose() diff --git a/golem-schema-derive/Cargo.toml b/golem-schema-derive/Cargo.toml index d8169a281c..f0cf77bd33 100644 --- a/golem-schema-derive/Cargo.toml +++ b/golem-schema-derive/Cargo.toml @@ -23,6 +23,7 @@ syn = { workspace = true, features = ["full"] } [dev-dependencies] chrono = { workspace = true } golem-common = { workspace = true, default-features = false, features = ["client"] } +golem-schema = { workspace = true } poem-openapi = { workspace = true } proptest = { workspace = true } serde = { workspace = true } diff --git a/golem-schema-derive/tests/derive_round_trip.rs b/golem-schema-derive/tests/derive_round_trip.rs index 733cf6583e..ecca25c96e 100644 --- a/golem-schema-derive/tests/derive_round_trip.rs +++ b/golem-schema-derive/tests/derive_round_trip.rs @@ -13,8 +13,8 @@ // limitations under the License. #![allow(dead_code)] -use golem_common::schema::render::{from_json_value, to_json_value}; use golem_common::schema::{FromSchema, IntoSchema, try_into_schema_graph}; +use golem_schema::schema::render::{from_json_value, to_json_value}; use proptest::prelude::*; use test_r::test; diff --git a/golem-schema/src/schema/mod.rs b/golem-schema/src/schema/mod.rs index cf648ad1ee..a2799bdef1 100644 --- a/golem-schema/src/schema/mod.rs +++ b/golem-schema/src/schema/mod.rs @@ -24,6 +24,7 @@ pub mod metadata; pub mod multimodal; #[cfg(feature = "full")] pub mod protobuf; +pub mod render; pub mod schema_type; pub mod schema_value; pub mod stream; diff --git a/golem-common/src/schema/render/error.rs b/golem-schema/src/schema/render/error.rs similarity index 100% rename from golem-common/src/schema/render/error.rs rename to golem-schema/src/schema/render/error.rs diff --git a/golem-schema/src/schema/render/json_schema.rs b/golem-schema/src/schema/render/json_schema.rs new file mode 100644 index 0000000000..88d2631d20 --- /dev/null +++ b/golem-schema/src/schema/render/json_schema.rs @@ -0,0 +1,1433 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Renderer that produces a JSON Schema document from a `SchemaGraph`/ +//! `SchemaType`. + +use crate::schema::graph::SchemaGraph; +use crate::schema::metadata::{MetadataEnvelope, TypeId}; +use crate::schema::schema_type::{ + BinaryRestrictions, DiscriminatorRule, PathSpec, PermissionCardSpec, QuantitySpec, + QuantityValue, QuotaTokenSpec, ResultSpec, SchemaType, SecretSpec, TextRestrictions, + UnionBranch, UnionSpec, UrlRestrictions, VariantCaseType, +}; +use serde_json::{Map, Number, Value}; +use std::collections::{HashMap, HashSet}; + +const JSON_SCHEMA_DRAFT: &str = "https://json-schema.org/draft/2020-12/schema"; +const MIME_TYPE_PATTERN: &str = "^[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+$"; + +/// Configuration for the JSON Schema renderer. +/// +/// The public constants select the trusted canonical representation; boundary +/// renderers additionally select their host-managed capability policy. +#[derive(Clone, Copy, Debug)] +pub struct JsonSchemaConfig { + /// Emit the `$schema` JSON Schema draft marker at the document root. + pub include_draft_marker: bool, + host_managed: HostManagedSchemaPolicy, +} + +#[derive(Clone, Copy, Debug)] +enum HostManagedSchemaPolicy { + TrustedSnapshot, + Reject, + Redact, +} + +impl JsonSchemaConfig { + /// Canonical standalone JSON Schema document (includes the `$schema` + /// draft marker). + pub const CANONICAL: Self = Self { + include_draft_marker: true, + host_managed: HostManagedSchemaPolicy::TrustedSnapshot, + }; + + /// Canonical JSON Schema document without the `$schema` draft marker, for + /// consumers that embed the schema elsewhere (e.g. tool/resource schemas). + pub const WITHOUT_DRAFT_MARKER: Self = Self { + include_draft_marker: false, + host_managed: HostManagedSchemaPolicy::TrustedSnapshot, + }; + + pub(crate) const EXTERNAL_INPUT: Self = Self { + include_draft_marker: false, + host_managed: HostManagedSchemaPolicy::Reject, + }; + + pub(crate) const EXTERNAL_OUTPUT: Self = Self { + include_draft_marker: false, + host_managed: HostManagedSchemaPolicy::Redact, + }; +} + +/// Render `(graph, ty)` to a canonical JSON Schema document (includes the +/// `$schema` draft marker). See [`to_json_schema_with_config`] for the +/// configurable form. +pub fn to_json_schema(graph: &SchemaGraph, ty: &SchemaType) -> Value { + to_json_schema_with_config(graph, ty, JsonSchemaConfig::CANONICAL) +} + +/// Render `(graph, ty)` to a JSON Schema document. When `ty` is a +/// `Ref(TypeId)` the document is `{ "$defs": {…}, "$ref": "#/$defs/" }`; +/// otherwise the root schema is emitted inline with `$defs` carrying every +/// named definition from the graph plus any union per-branch synthesised +/// schemas under tag-derived keys (see [`BranchNameTable`]). +/// +/// `config.include_draft_marker` controls whether the `$schema` draft marker +/// is added at the document root. +pub fn to_json_schema_with_config( + graph: &SchemaGraph, + ty: &SchemaType, + config: JsonSchemaConfig, +) -> Value { + let table = build_branch_name_table(graph, ty); + let mut root = render_type(graph, ty, true, &table, config); + let mut defs = render_defs(graph, &table, config); + add_union_branch_defs(graph, ty, &mut defs, &table, config); + if !defs.is_empty() { + if let Some(obj) = root.as_object_mut() { + obj.insert("$defs".to_string(), Value::Object(defs)); + } else { + let mut wrapper = Map::new(); + wrapper.insert("$defs".to_string(), Value::Object(defs)); + wrapper.insert("allOf".to_string(), Value::Array(vec![root.clone()])); + root = Value::Object(wrapper); + } + } + if config.include_draft_marker + && let Some(obj) = root.as_object_mut() + { + // Insert the JSON Schema draft marker at the top of the produced + // root schema. OpenAPI removes this; see `super::openapi`. + let mut with_schema = Map::with_capacity(obj.len() + 1); + with_schema.insert( + "$schema".to_string(), + Value::String(JSON_SCHEMA_DRAFT.to_string()), + ); + for (k, v) in obj.iter() { + with_schema.insert(k.clone(), v.clone()); + } + return Value::Object(with_schema); + } + root +} + +/// Render a JSON Schema for untrusted external input. Host-managed capability +/// leaves cannot be constructed by callers. +pub fn to_external_input_json_schema( + graph: &SchemaGraph, + ty: &SchemaType, + include_draft_marker: bool, +) -> Value { + to_json_schema_with_config( + graph, + ty, + JsonSchemaConfig { + include_draft_marker, + ..JsonSchemaConfig::EXTERNAL_INPUT + }, + ) +} + +/// Render a JSON Schema for externally visible output. Host-managed capability +/// leaves expose only their redacted placeholders. +pub fn to_external_output_json_schema( + graph: &SchemaGraph, + ty: &SchemaType, + include_draft_marker: bool, +) -> Value { + to_json_schema_with_config( + graph, + ty, + JsonSchemaConfig { + include_draft_marker, + ..JsonSchemaConfig::EXTERNAL_OUTPUT + }, + ) +} + +/// Whether `ty`, after following any `Ref` chain against `graph`, is an +/// `option<…>`. Used to decide whether an input parameter is required. +fn resolves_to_option(graph: &SchemaGraph, ty: &SchemaType) -> bool { + let mut current = ty; + let mut visited: HashSet = HashSet::new(); + loop { + match current { + SchemaType::Option { .. } => return true, + SchemaType::Ref { id, .. } => { + if !visited.insert(id.clone()) { + return false; + } + match graph.lookup(id) { + Some(def) => current = &def.body, + None => return false, + } + } + _ => return false, + } + } +} + +/// Build a `$defs` object covering every named definition in the graph. +/// +/// Per RFC 6901 §4, JSON Pointer escaping (`~0`/`~1`) applies to the +/// *pointer string*, not to the resolved object member name. The map key +/// is therefore the **raw** `TypeId.0` string; the escaped form is only +/// used inside `$ref` pointers (see [`ref_pointer`]). +pub(super) fn render_defs( + graph: &SchemaGraph, + table: &BranchNameTable, + config: JsonSchemaConfig, +) -> Map { + let mut defs = Map::new(); + for def in &graph.defs { + // The def's metadata now lives on `def.body` directly; `render_type` + // already attaches inline-node metadata, so no extra `attach_metadata` + // call is required here. + let mut body = render_type(graph, &def.body, false, table, config); + if let Some(name) = &def.name + && let Some(obj) = body.as_object_mut() + { + obj.entry("title").or_insert(Value::String(name.clone())); + } + defs.insert(def.id.0.clone(), body); + } + defs +} + +/// Walk every union under the graph and synthesize per-branch `$defs` +/// entries so discriminator-mapping pointers always resolve. +pub(super) fn add_union_branch_defs( + graph: &SchemaGraph, + root_ty: &SchemaType, + defs: &mut Map, + table: &BranchNameTable, + config: JsonSchemaConfig, +) { + let mut emitted = HashSet::new(); + collect_union_branch_defs(graph, root_ty, defs, &mut emitted, table, config); + for def in &graph.defs { + collect_union_branch_defs(graph, &def.body, defs, &mut emitted, table, config); + } +} + +fn collect_union_branch_defs( + graph: &SchemaGraph, + ty: &SchemaType, + defs: &mut Map, + emitted: &mut HashSet, + table: &BranchNameTable, + config: JsonSchemaConfig, +) { + match ty { + SchemaType::Union { spec, .. } => { + for branch in spec.branches.iter() { + let key = table.name_for(branch).to_string(); + if emitted.insert(key.clone()) { + let mut body = render_type(graph, &branch.body, false, table, config); + attach_metadata(&mut body, &branch.metadata); + if let Some(obj) = body.as_object_mut() { + // Constrain the branch schema further with the + // discriminator. For record-shaped rules this adds + // an extra constraint on the discriminator field; + // for string rules it adds a `pattern`/`const`. + apply_discriminator_constraint(obj, &branch.discriminator); + } + defs.insert(key, body); + } + collect_union_branch_defs(graph, &branch.body, defs, emitted, table, config); + } + } + SchemaType::Record { fields, .. } => { + for f in fields { + collect_union_branch_defs(graph, &f.body, defs, emitted, table, config); + } + } + SchemaType::Variant { cases, .. } => { + for case in cases { + if let Some(p) = &case.payload { + collect_union_branch_defs(graph, p, defs, emitted, table, config); + } + } + } + SchemaType::Tuple { elements, .. } => { + for e in elements { + collect_union_branch_defs(graph, e, defs, emitted, table, config); + } + } + SchemaType::List { element, .. } + | SchemaType::FixedList { element, .. } + | SchemaType::Option { inner: element, .. } => { + collect_union_branch_defs(graph, element, defs, emitted, table, config); + } + SchemaType::Map { key, value, .. } => { + collect_union_branch_defs(graph, key, defs, emitted, table, config); + collect_union_branch_defs(graph, value, defs, emitted, table, config); + } + SchemaType::Result { spec, .. } => { + if let Some(t) = &spec.ok { + collect_union_branch_defs(graph, t, defs, emitted, table, config); + } + if let Some(t) = &spec.err { + collect_union_branch_defs(graph, t, defs, emitted, table, config); + } + } + SchemaType::Future { inner, .. } | SchemaType::Stream { inner, .. } => { + if let Some(t) = inner { + collect_union_branch_defs(graph, t, defs, emitted, table, config); + } + } + _ => {} + } +} + +/// Stable, tag-preserving `$defs` / `components.schemas` keys for every +/// union branch reachable from a render root. +/// +/// Built once per render via [`build_branch_name_table`]. The names are +/// derived primarily from each branch's `tag` (sanitised to +/// `UpperCamelCase`) so that types in a generated OpenAPI client carry +/// human-meaningful names rather than opaque content hashes. +/// +/// Collisions (two structurally distinct branches sharing a tag) are +/// resolved by progressively prepending segments from the schema-graph +/// path that reached each branch, mirroring the algorithm used by +/// `bridge_gen::type_naming`. As a last resort — when no contextual +/// disambiguation works — a short hash suffix is appended. +/// +/// Determinism: the walk visits branches in source order; collision +/// resolution iterates the resulting group deterministically. The +/// canonical structural key used internally is a `blake3` hash of the +/// branch's deterministic JSON serialisation. +pub(super) struct BranchNameTable { + names: HashMap, +} + +impl BranchNameTable { + pub(super) fn name_for(&self, branch: &UnionBranch) -> &str { + let key = canonical_branch_key(branch); + self.names.get(&key).map(String::as_str).expect( + "BranchNameTable must contain every union branch reachable from the render root \ + — `build_branch_name_table` is the source of truth for this invariant", + ) + } +} + +pub(super) fn build_branch_name_table( + graph: &SchemaGraph, + root_ty: &SchemaType, +) -> BranchNameTable { + let mut collector = BranchCollector::default(); + collector.walk_type(root_ty); + for def in &graph.defs { + // Each named def starts a fresh path rooted at its name (or + // TypeId fallback); this lets disambiguation lift names through + // the named-def boundary when needed. + collector.path.clear(); + let seg = def.name.clone().unwrap_or_else(|| def.id.0.clone()); + collector.path.push(seg); + collector.walk_type(&def.body); + } + collector.path.clear(); + // Pre-seed `taken` with every named def's TypeId so branch names + // never silently overwrite a real graph def in `$defs`. + let taken: HashSet = graph.defs.iter().map(|d| d.id.0.clone()).collect(); + collector.into_table(taken) +} + +/// Deterministic structural key for a `UnionBranch`. Internal only; +/// never appears in rendered output. +fn canonical_branch_key(branch: &UnionBranch) -> String { + let bytes = serde_json::to_vec(branch).expect("UnionBranch serializes deterministically"); + let hex = blake3::hash(&bytes).to_hex(); + // 128 bits of hash output — sufficient to uniquely identify a branch + // body within any practical schema document. + hex.as_str()[..32].to_string() +} + +#[derive(Default)] +struct BranchCollector { + /// Canonical key for every encountered branch, in walk order, with no + /// duplicates. Used both for membership and for deterministic iteration + /// during name resolution. + keys: Vec, + occurrences: HashMap, + /// Path of segments describing the current position in the schema + /// graph (record-field names, variant-case names, "key"/"value", + /// "ok"/"err", outer branch tags, …). + path: Vec, +} + +struct Occurrence { + tag: String, + /// First path at which this branch was reached. Used to disambiguate + /// colliding preferred names. + path: Vec, +} + +impl BranchCollector { + fn record(&mut self, branch: &UnionBranch) { + let key = canonical_branch_key(branch); + if let std::collections::hash_map::Entry::Vacant(slot) = self.occurrences.entry(key.clone()) + { + slot.insert(Occurrence { + tag: branch.tag.clone(), + path: self.path.clone(), + }); + self.keys.push(key); + } + } + + /// Walk a `SchemaType` subtree, pushing/popping path segments and + /// recording every encountered `UnionBranch`. + /// + /// `Ref(TypeId)` nodes are not followed: the named def they point + /// at is walked separately from `build_branch_name_table` with its + /// own fresh path, so following refs here would record duplicate + /// occurrences and pollute the disambiguation path. + fn walk_type(&mut self, ty: &SchemaType) { + match ty { + SchemaType::Union { spec, .. } => { + for branch in &spec.branches { + self.record(branch); + self.path.push(branch.tag.clone()); + self.walk_type(&branch.body); + self.path.pop(); + } + } + SchemaType::Record { fields, .. } => { + for f in fields { + self.path.push(f.name.clone()); + self.walk_type(&f.body); + self.path.pop(); + } + } + SchemaType::Variant { cases, .. } => { + for case in cases { + if let Some(p) = &case.payload { + self.path.push(case.name.clone()); + self.walk_type(p); + self.path.pop(); + } + } + } + SchemaType::Tuple { elements, .. } => { + for (i, e) in elements.iter().enumerate() { + self.path.push(format!("item{i}")); + self.walk_type(e); + self.path.pop(); + } + } + SchemaType::List { element, .. } | SchemaType::FixedList { element, .. } => { + self.path.push("item".to_string()); + self.walk_type(element); + self.path.pop(); + } + SchemaType::Option { inner, .. } => { + self.path.push("inner".to_string()); + self.walk_type(inner); + self.path.pop(); + } + SchemaType::Map { key, value, .. } => { + self.path.push("key".to_string()); + self.walk_type(key); + self.path.pop(); + self.path.push("value".to_string()); + self.walk_type(value); + self.path.pop(); + } + SchemaType::Result { spec, .. } => { + if let Some(t) = &spec.ok { + self.path.push("ok".to_string()); + self.walk_type(t); + self.path.pop(); + } + if let Some(t) = &spec.err { + self.path.push("err".to_string()); + self.walk_type(t); + self.path.pop(); + } + } + SchemaType::Future { inner, .. } | SchemaType::Stream { inner, .. } => { + if let Some(t) = inner { + self.path.push("inner".to_string()); + self.walk_type(t); + self.path.pop(); + } + } + _ => {} + } + } + + fn into_table(self, mut taken: HashSet) -> BranchNameTable { + // Compute each occurrence's preferred name (from its `tag`) and + // group by it. + let mut groups: Vec<(String, Vec)> = Vec::new(); + for key in &self.keys { + let occ = &self.occurrences[key]; + let preferred = sanitise_to_upper_camel(&occ.tag); + match groups.iter_mut().find(|(name, _)| name == &preferred) { + Some((_, members)) => members.push(key.clone()), + None => groups.push((preferred, vec![key.clone()])), + } + } + + let mut names = HashMap::::new(); + for (preferred, members) in groups { + if members.len() == 1 && !taken.contains(&preferred) { + // Unique preferred name and not colliding with a graph + // def TypeId — use it verbatim. + let only = members.into_iter().next().unwrap(); + taken.insert(preferred.clone()); + names.insert(only, preferred); + } else { + // Real collision (or shadows a graph def): every member + // is forced through location-based disambiguation so the + // assigned names are symmetric. + for key in members { + let occ = &self.occurrences[&key]; + let assigned = disambiguate(&preferred, &occ.path, &taken, &key); + taken.insert(assigned.clone()); + names.insert(key, assigned); + } + } + } + + BranchNameTable { names } + } +} + +/// Find a unique name by progressively prepending sanitised path +/// segments (innermost → outermost) to `base`. Falls back to a short +/// canonical-key suffix if no contextual disambiguation works. +fn disambiguate(base: &str, path: &[String], taken: &HashSet, canonical: &str) -> String { + let mut candidate = base.to_string(); + for seg in path.iter().rev() { + let seg_camel = sanitise_to_upper_camel(seg); + if seg_camel.is_empty() { + continue; + } + candidate = format!("{seg_camel}{candidate}"); + if !taken.contains(&candidate) { + return candidate; + } + } + let suffix_len = 6.min(canonical.len()); + format!("{base}_{}", &canonical[..suffix_len]) +} + +/// Sanitise an arbitrary string to a non-empty UpperCamelCase identifier +/// suitable for both JSON Pointer member names and OpenAPI schema names +/// (alphabet `[A-Za-z0-9]`). Non-alphanumerics are dropped and treated +/// as word separators; a leading digit is prefixed with `_`. +fn sanitise_to_upper_camel(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + let mut upper_next = true; + for ch in s.chars() { + if ch.is_ascii_alphanumeric() { + if upper_next { + for u in ch.to_uppercase() { + out.push(u); + } + upper_next = false; + } else { + out.push(ch); + } + } else { + upper_next = true; + } + } + if out.is_empty() { + return "Branch".to_string(); + } + if out.starts_with(|c: char| c.is_ascii_digit()) { + format!("_{out}") + } else { + out + } +} + +fn apply_discriminator_constraint(obj: &mut Map, rule: &DiscriminatorRule) { + match rule { + DiscriminatorRule::Prefix { prefix } => { + obj.entry("pattern") + .or_insert(Value::String(format!("^{}", regex_escape(prefix)))); + } + DiscriminatorRule::Suffix { suffix } => { + obj.entry("pattern") + .or_insert(Value::String(format!("{}$", regex_escape(suffix)))); + } + DiscriminatorRule::Contains { substring } => { + obj.entry("pattern") + .or_insert(Value::String(regex_escape(substring))); + } + DiscriminatorRule::Regex { regex } => { + obj.entry("pattern").or_insert(Value::String(regex.clone())); + } + DiscriminatorRule::FieldEquals(disc) => { + // Constrain the field's value with `const` if a literal is set; + // otherwise just require the field to be present. + let mut required = obj + .get("required") + .and_then(Value::as_array) + .cloned() + .unwrap_or_default(); + if !required + .iter() + .any(|v| v.as_str() == Some(disc.field_name.as_str())) + { + required.push(Value::String(disc.field_name.clone())); + } + obj.insert("required".to_string(), Value::Array(required)); + if let Some(lit) = &disc.literal { + let props = obj + .entry("properties") + .or_insert_with(|| Value::Object(Map::new())) + .as_object_mut() + .expect("properties is object"); + let field = props + .entry(disc.field_name.clone()) + .or_insert_with(|| obj_inline([("type", Value::String("string".to_string()))])); + if let Some(field_obj) = field.as_object_mut() { + field_obj + .entry("const") + .or_insert(Value::String(lit.clone())); + } + } + } + DiscriminatorRule::FieldAbsent { field_name } => { + // Express absence via `not: { required: [field] }`. + let not = obj_inline([( + "required", + Value::Array(vec![Value::String(field_name.clone())]), + )]); + obj.insert("not".to_string(), not); + } + } +} + +pub(super) fn render_type( + graph: &SchemaGraph, + ty: &SchemaType, + root: bool, + table: &BranchNameTable, + config: JsonSchemaConfig, +) -> Value { + let mut rendered = match ty { + SchemaType::Ref { id, .. } => obj([("$ref", Value::String(ref_pointer(id, root)))]), + + SchemaType::Bool { .. } => obj([("type", Value::String("boolean".to_string()))]), + SchemaType::S8 { .. } => integer_schema(i8::MIN as i64, i8::MAX as i64), + SchemaType::S16 { .. } => integer_schema(i16::MIN as i64, i16::MAX as i64), + SchemaType::S32 { .. } => integer_schema(i32::MIN as i64, i32::MAX as i64), + SchemaType::S64 { .. } => integer_schema(i64::MIN, i64::MAX), + SchemaType::U8 { .. } => integer_schema(0, u8::MAX as i64), + SchemaType::U16 { .. } => integer_schema(0, u16::MAX as i64), + SchemaType::U32 { .. } => integer_schema(0, u32::MAX as i64), + SchemaType::U64 { .. } => unsigned_64_schema(), + SchemaType::F32 { .. } | SchemaType::F64 { .. } => { + obj([("type", Value::String("number".to_string()))]) + } + SchemaType::Char { .. } => obj([ + ("type", Value::String("string".to_string())), + ("minLength", Value::Number(1.into())), + ("maxLength", Value::Number(1.into())), + ]), + SchemaType::String { .. } => obj([("type", Value::String("string".to_string()))]), + + SchemaType::Record { fields, .. } => { + let mut props = Map::new(); + let mut required = Vec::with_capacity(fields.len()); + for field in fields { + let mut field_schema = render_type(graph, &field.body, false, table, config); + attach_metadata(&mut field_schema, &field.metadata); + props.insert(field.name.clone(), field_schema); + // `option<…>` fields are not required: the field may be omitted + // entirely, and an explicit `null` is still accepted by the + // option's `oneOf [null, T]` schema. + if !resolves_to_option(graph, &field.body) { + required.push(Value::String(field.name.clone())); + } + } + obj([ + ("type", Value::String("object".to_string())), + ("properties", Value::Object(props)), + ("required", Value::Array(required)), + ("additionalProperties", Value::Bool(false)), + ]) + } + + SchemaType::Variant { cases, .. } => { + Value::Object(variant_schema(graph, cases, table, config)) + } + + SchemaType::Enum { cases, .. } => obj([ + ("type", Value::String("string".to_string())), + ( + "enum", + Value::Array(cases.iter().cloned().map(Value::String).collect()), + ), + ]), + + SchemaType::Flags { flags, .. } => obj([ + ("type", Value::String("array".to_string())), + ( + "items", + obj([ + ("type", Value::String("string".to_string())), + ( + "enum", + Value::Array(flags.iter().cloned().map(Value::String).collect()), + ), + ]), + ), + ("uniqueItems", Value::Bool(true)), + ]), + + SchemaType::Tuple { elements, .. } => { + if elements.is_empty() { + // JSON Schema 2020-12 requires `prefixItems` to be a + // non-empty array, so the empty-tuple shape uses + // `maxItems`/`minItems` only. + obj([ + ("type", Value::String("array".to_string())), + ("minItems", Value::Number(0u64.into())), + ("maxItems", Value::Number(0u64.into())), + ]) + } else { + obj([ + ("type", Value::String("array".to_string())), + ( + "prefixItems", + Value::Array( + elements + .iter() + .map(|e| render_type(graph, e, false, table, config)) + .collect(), + ), + ), + ("items", Value::Bool(false)), + ("minItems", Value::Number((elements.len() as u64).into())), + ]) + } + } + + SchemaType::List { element, .. } => obj([ + ("type", Value::String("array".to_string())), + ("items", render_type(graph, element, false, table, config)), + ]), + + SchemaType::FixedList { + element, length, .. + } => obj([ + ("type", Value::String("array".to_string())), + ("items", render_type(graph, element, false, table, config)), + ("minItems", Value::Number((*length).into())), + ("maxItems", Value::Number((*length).into())), + ]), + + SchemaType::Map { key, value, .. } => { + let pair = obj([ + ("type", Value::String("array".to_string())), + ( + "prefixItems", + Value::Array(vec![ + render_type(graph, key, false, table, config), + render_type(graph, value, false, table, config), + ]), + ), + ("items", Value::Bool(false)), + ("minItems", Value::Number(2.into())), + ("maxItems", Value::Number(2.into())), + ]); + obj([ + ("type", Value::String("array".to_string())), + ("items", pair), + ]) + } + + SchemaType::Option { inner, .. } => obj([( + "oneOf", + Value::Array(vec![ + obj([("type", Value::String("null".to_string()))]), + render_type(graph, inner, false, table, config), + ]), + )]), + + SchemaType::Result { spec, .. } => Value::Object(result_schema(graph, spec, table, config)), + + SchemaType::Text { restrictions, .. } => Value::Object(text_schema(restrictions)), + SchemaType::Binary { restrictions, .. } => Value::Object(binary_schema(restrictions)), + SchemaType::Path { spec, .. } => Value::Object(path_schema(spec)), + SchemaType::Url { restrictions, .. } => Value::Object(url_schema(restrictions)), + SchemaType::Datetime { .. } => obj([ + ("type", Value::String("string".to_string())), + ("format", Value::String("date-time".to_string())), + ]), + SchemaType::Duration { .. } => obj([ + ("type", Value::String("string".to_string())), + ("format", Value::String("duration".to_string())), + ]), + SchemaType::Quantity { spec, .. } => Value::Object(quantity_schema(spec)), + + SchemaType::Union { spec, .. } => Value::Object(union_schema(graph, spec, table, config)), + + SchemaType::Secret { spec, .. } => { + host_managed_schema(config.host_managed, "secret", || { + Value::Object(secret_schema(spec)) + }) + } + SchemaType::QuotaToken { spec, .. } => { + host_managed_schema(config.host_managed, "quota-token", || { + Value::Object(quota_token_schema(spec)) + }) + } + SchemaType::PermissionCard { spec, .. } => { + host_managed_schema(config.host_managed, "permission-card", || { + Value::Object(permission_card_schema(spec)) + }) + } + + SchemaType::Future { .. } | SchemaType::Stream { .. } => obj([ + ("type", Value::String("null".to_string())), + ( + "description", + Value::String("WASI P3 placeholder".to_string()), + ), + ]), + }; + + // Per-node metadata: attach docs / examples / deprecated for every + // SchemaType node so inline-typed positions (record fields, list + // elements, etc.) propagate their metadata into the generated JSON + // Schema, not only named definitions. + attach_metadata(&mut rendered, ty.metadata()); + rendered +} + +fn host_managed_schema( + policy: HostManagedSchemaPolicy, + kind: &str, + trusted: impl FnOnce() -> Value, +) -> Value { + match policy { + HostManagedSchemaPolicy::TrustedSnapshot => trusted(), + HostManagedSchemaPolicy::Reject => obj([ + ("not", Value::Object(Map::new())), + ( + "description", + Value::String(format!( + "Host-managed {kind} capabilities cannot be supplied externally" + )), + ), + ]), + HostManagedSchemaPolicy::Redact => obj([ + ("type", Value::String("string".to_string())), + ("const", Value::String(format!(""))), + ( + "description", + Value::String(format!( + "Host-managed {kind} capability values are redacted" + )), + ), + ]), + } +} + +fn ref_pointer(id: &TypeId, _root: bool) -> String { + ref_to_def_key(&id.0) +} + +/// Build the `$ref` pointer string for a raw `$defs` member key. +/// +/// `key` is the raw (un-escaped) member name; this helper applies +/// RFC 6901 JSON Pointer escaping when embedding it in the pointer path. +pub(super) fn ref_to_def_key(key: &str) -> String { + format!("#/$defs/{}", escape_pointer_token(key)) +} + +fn integer_schema(min: i64, max: i64) -> Value { + obj([ + ("type", Value::String("integer".to_string())), + ("minimum", Value::Number(Number::from(min))), + ("maximum", Value::Number(Number::from(max))), + ]) +} + +fn unsigned_64_schema() -> Value { + obj([ + ("type", Value::String("integer".to_string())), + ("minimum", Value::Number(Number::from(0u64))), + ("maximum", Value::Number(Number::from(u64::MAX))), + ]) +} + +fn variant_schema( + graph: &SchemaGraph, + cases: &[VariantCaseType], + table: &BranchNameTable, + config: JsonSchemaConfig, +) -> Map { + let one_of: Vec = cases + .iter() + .map(|case| match &case.payload { + None => obj([("const", Value::String(case.name.clone()))]), + Some(payload_ty) => { + let mut props = Map::new(); + props.insert( + case.name.clone(), + render_type(graph, payload_ty, false, table, config), + ); + obj([ + ("type", Value::String("object".to_string())), + ("properties", Value::Object(props)), + ( + "required", + Value::Array(vec![Value::String(case.name.clone())]), + ), + ("additionalProperties", Value::Bool(false)), + ]) + } + }) + .collect(); + let mut out = Map::new(); + out.insert("oneOf".to_string(), Value::Array(one_of)); + out +} + +fn result_schema( + graph: &SchemaGraph, + spec: &ResultSpec, + table: &BranchNameTable, + config: JsonSchemaConfig, +) -> Map { + let ok_inner = spec + .ok + .as_deref() + .map(|t| render_type(graph, t, false, table, config)) + .unwrap_or_else(|| obj([("type", Value::String("null".to_string()))])); + let err_inner = spec + .err + .as_deref() + .map(|t| render_type(graph, t, false, table, config)) + .unwrap_or_else(|| obj([("type", Value::String("null".to_string()))])); + let one_of = vec![ + obj([ + ("type", Value::String("object".to_string())), + ( + "properties", + Value::Object({ + let mut m = Map::new(); + m.insert("ok".to_string(), ok_inner); + m + }), + ), + ("required", Value::Array(vec![Value::String("ok".into())])), + ("additionalProperties", Value::Bool(false)), + ]), + obj([ + ("type", Value::String("object".to_string())), + ( + "properties", + Value::Object({ + let mut m = Map::new(); + m.insert("err".to_string(), err_inner); + m + }), + ), + ("required", Value::Array(vec![Value::String("err".into())])), + ("additionalProperties", Value::Bool(false)), + ]), + ]; + let mut out = Map::new(); + out.insert("oneOf".to_string(), Value::Array(one_of)); + out +} + +fn text_schema(restrictions: &TextRestrictions) -> Map { + // Canonical Text JSON shape: `{ text: string, language?: string }` with + // length / pattern constraints lifted into the `text` field. + let mut text_field = Map::new(); + text_field.insert("type".to_string(), Value::String("string".to_string())); + if let Some(min) = restrictions.min_length { + text_field.insert("minLength".to_string(), Value::Number(min.into())); + } + if let Some(max) = restrictions.max_length { + text_field.insert("maxLength".to_string(), Value::Number(max.into())); + } + if let Some(regex) = &restrictions.regex { + text_field.insert("pattern".to_string(), Value::String(regex.clone())); + } + let mut properties = Map::new(); + properties.insert("text".to_string(), Value::Object(text_field)); + properties.insert( + "language".to_string(), + obj([("type", Value::String("string".to_string()))]), + ); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(properties)); + m.insert( + "required".to_string(), + Value::Array(vec![Value::String("text".to_string())]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + if let Some(langs) = &restrictions.languages { + m.insert( + "description".to_string(), + Value::String(format!("Allowed languages: {}", langs.join(", "))), + ); + } + m +} + +fn binary_schema(restrictions: &BinaryRestrictions) -> Map { + // Canonical Binary JSON shape: `{ bytes: base64url-string, mime_type?: string }`. + // `min_bytes` / `max_bytes` count *raw* bytes; the JSON field is + // base64url-no-pad-encoded, so the on-wire string length is + // `base64url_no_pad_len(n) = 4*(n/3) + match n%3 { 0=>0, 1=>2, 2=>3 }`. + let mut bytes_field = Map::new(); + bytes_field.insert("type".to_string(), Value::String("string".to_string())); + bytes_field.insert( + "contentEncoding".to_string(), + Value::String("base64url".to_string()), + ); + if let Some(min) = restrictions.min_bytes { + bytes_field.insert( + "minLength".to_string(), + Value::Number(base64url_no_pad_len(min).into()), + ); + } + if let Some(max) = restrictions.max_bytes { + bytes_field.insert( + "maxLength".to_string(), + Value::Number(base64url_no_pad_len(max).into()), + ); + } + let mut mime_field = Map::new(); + mime_field.insert("type".to_string(), Value::String("string".to_string())); + mime_field.insert( + "pattern".to_string(), + Value::String(MIME_TYPE_PATTERN.to_string()), + ); + let mut properties = Map::new(); + properties.insert("bytes".to_string(), Value::Object(bytes_field)); + properties.insert("mimeType".to_string(), Value::Object(mime_field)); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(properties)); + m.insert( + "required".to_string(), + Value::Array(vec![Value::String("bytes".to_string())]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + if let Some(mimes) = &restrictions.mime_types { + m.insert( + "description".to_string(), + Value::String(format!("Allowed MIME types: {}", mimes.join(", "))), + ); + } + m +} + +fn path_schema(spec: &PathSpec) -> Map { + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("string".to_string())); + m.insert("format".to_string(), Value::String("file-path".to_string())); + let kind = match spec.kind { + crate::schema::schema_type::PathKind::File => "file", + crate::schema::schema_type::PathKind::Directory => "directory", + crate::schema::schema_type::PathKind::Any => "any", + }; + let direction = match spec.direction { + crate::schema::schema_type::PathDirection::Input => "input", + crate::schema::schema_type::PathDirection::Output => "output", + crate::schema::schema_type::PathDirection::InOut => "inout", + }; + m.insert( + "title".to_string(), + Value::String(format!("{direction} {kind} path")), + ); + let mut description = Vec::new(); + if let Some(exts) = &spec.allowed_extensions { + description.push(format!("Allowed extensions: {}", exts.join(", "))); + } + if let Some(mimes) = &spec.allowed_mime_types { + description.push(format!("Allowed MIME types: {}", mimes.join(", "))); + } + if !description.is_empty() { + m.insert( + "description".to_string(), + Value::String(description.join("; ")), + ); + } + m +} + +fn url_schema(restrictions: &UrlRestrictions) -> Map { + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("string".to_string())); + m.insert("format".to_string(), Value::String("uri".to_string())); + m.insert("title".to_string(), Value::String("URL".to_string())); + let mut description = Vec::new(); + if let Some(schemes) = &restrictions.allowed_schemes { + description.push(format!("Allowed schemes: {}", schemes.join(", "))); + } + if let Some(hosts) = &restrictions.allowed_hosts { + description.push(format!("Allowed hosts: {}", hosts.join(", "))); + } + if !description.is_empty() { + m.insert( + "description".to_string(), + Value::String(description.join("; ")), + ); + } + m +} + +fn quantity_schema(spec: &QuantitySpec) -> Map { + let mut props = Map::new(); + props.insert( + "mantissa".to_string(), + obj([("type", Value::String("integer".to_string()))]), + ); + props.insert( + "scale".to_string(), + obj([("type", Value::String("integer".to_string()))]), + ); + props.insert( + "unit".to_string(), + obj([("type", Value::String("string".to_string()))]), + ); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(props)); + m.insert( + "required".to_string(), + Value::Array(vec![ + Value::String("mantissa".to_string()), + Value::String("scale".to_string()), + Value::String("unit".to_string()), + ]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + m.insert( + "title".to_string(), + Value::String(format!("Quantity ({})", spec.base_unit)), + ); + let mut description = Vec::new(); + if let Some(min) = &spec.min { + description.push(format!("min: {}", render_quantity(min))); + } + if let Some(max) = &spec.max { + description.push(format!("max: {}", render_quantity(max))); + } + if !description.is_empty() { + m.insert( + "description".to_string(), + Value::String(description.join("; ")), + ); + } + m +} + +fn render_quantity(q: &QuantityValue) -> String { + format!("{}e-{} {}", q.mantissa, q.scale, q.unit) +} + +fn secret_schema(_spec: &SecretSpec) -> Map { + // Canonical Secret JSON shape: see canonical/secret.rs. + let secret_id = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("uuid".to_string())), + ]); + let config_key = obj_inline([ + ("type", Value::String("array".to_string())), + ( + "items", + obj_inline([("type", Value::String("string".to_string()))]), + ), + ]); + let version = obj_inline([ + ("type", Value::String("integer".to_string())), + ("minimum", Value::Number(0.into())), + ]); + let resolved_at = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("date-time".to_string())), + ]); + let category = obj_inline([("type", Value::String("string".to_string()))]); + let mut properties = Map::new(); + properties.insert("secretId".to_string(), secret_id); + properties.insert("configKey".to_string(), config_key); + properties.insert("version".to_string(), version); + properties.insert("resolvedAt".to_string(), resolved_at); + properties.insert("category".to_string(), category); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(properties)); + m.insert( + "required".to_string(), + Value::Array(vec![ + Value::String("secretId".to_string()), + Value::String("version".to_string()), + Value::String("resolvedAt".to_string()), + ]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + m +} + +fn quota_token_schema(_spec: &QuotaTokenSpec) -> Map { + // Canonical QuotaToken JSON shape: see canonical/quota_token.rs. + let env_id = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("uuid".to_string())), + ]); + let resource_name = obj_inline([("type", Value::String("string".to_string()))]); + let expected_use = obj_inline([( + "oneOf", + Value::Array(vec![ + obj_inline([ + ("type", Value::String("string".to_string())), + ("pattern", Value::String("^[0-9]+$".to_string())), + ]), + obj_inline([ + ("type", Value::String("integer".to_string())), + ("minimum", Value::Number(0u64.into())), + ]), + ]), + )]); + let last_credit = obj_inline([( + "oneOf", + Value::Array(vec![ + obj_inline([ + ("type", Value::String("string".to_string())), + ("pattern", Value::String("^-?[0-9]+$".to_string())), + ]), + obj_inline([("type", Value::String("integer".to_string()))]), + ]), + )]); + let last_credit_at = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("date-time".to_string())), + ]); + let mut properties = Map::new(); + properties.insert("environmentId".to_string(), env_id); + properties.insert("resourceName".to_string(), resource_name); + properties.insert("expectedUse".to_string(), expected_use); + properties.insert("lastCredit".to_string(), last_credit); + properties.insert("lastCreditAt".to_string(), last_credit_at); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(properties)); + m.insert( + "required".to_string(), + Value::Array(vec![ + Value::String("environmentId".to_string()), + Value::String("resourceName".to_string()), + Value::String("expectedUse".to_string()), + Value::String("lastCredit".to_string()), + Value::String("lastCreditAt".to_string()), + ]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + m +} + +fn permission_card_schema(_spec: &PermissionCardSpec) -> Map { + // Permission-card values are opaque capability handles. The transported + // snapshot carries card_id (authoritative), parent_ids, expires_at, and + // polymorphic as trusted cache. See canonical/permission_card.rs. + let card_id = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("uuid".to_string())), + ]); + let parent_ids = obj_inline([ + ("type", Value::String("array".to_string())), + ( + "items", + obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("uuid".to_string())), + ]), + ), + ]); + let expires_at = obj_inline([ + ("type", Value::String("string".to_string())), + ("format", Value::String("date-time".to_string())), + ]); + let polymorphic = obj_inline([("type", Value::String("boolean".to_string()))]); + let mut properties = Map::new(); + properties.insert("cardId".to_string(), card_id); + properties.insert("parentIds".to_string(), parent_ids); + properties.insert("expiresAt".to_string(), expires_at); + properties.insert("polymorphic".to_string(), polymorphic); + let mut m = Map::new(); + m.insert("type".to_string(), Value::String("object".to_string())); + m.insert("properties".to_string(), Value::Object(properties)); + m.insert( + "required".to_string(), + Value::Array(vec![ + Value::String("cardId".to_string()), + Value::String("polymorphic".to_string()), + ]), + ); + m.insert("additionalProperties".to_string(), Value::Bool(false)); + m +} + +fn union_schema( + graph: &SchemaGraph, + spec: &UnionSpec, + table: &BranchNameTable, + config: JsonSchemaConfig, +) -> Map { + // Each branch gets a per-branch reference into `$defs` (synthesised + // by `add_union_branch_defs`), so the `oneOf` and any discriminator + // mapping resolves against schemas the renderer actually emits. The + // branch key is resolved through `BranchNameTable` so two unrelated + // unions sharing a tag get disambiguated names. + let one_of: Vec = spec + .branches + .iter() + .map(|b| obj([("$ref", Value::String(ref_to_def_key(table.name_for(b))))])) + .collect(); + let mut m = Map::new(); + m.insert("oneOf".to_string(), Value::Array(one_of)); + if let Some(disc_field) = openapi_discriminator(spec) { + let mut mapping = Map::new(); + for branch in spec.branches.iter() { + let literal = match &branch.discriminator { + DiscriminatorRule::FieldEquals(disc) => disc.literal.clone(), + _ => None, + }; + if let Some(lit) = literal { + mapping.insert(lit, Value::String(ref_to_def_key(table.name_for(branch)))); + } + } + let mut d = Map::new(); + d.insert("propertyName".to_string(), Value::String(disc_field)); + if !mapping.is_empty() { + d.insert("mapping".to_string(), Value::Object(mapping)); + } + m.insert("discriminator".to_string(), Value::Object(d)); + } + let _ = graph; + let _ = config; + m +} + +fn openapi_discriminator(spec: &UnionSpec) -> Option { + let mut field: Option = None; + for branch in spec.branches.iter() { + match &branch.discriminator { + DiscriminatorRule::FieldEquals(disc) => { + let _ = disc.literal.as_ref()?; + match &field { + Some(prev) if prev != &disc.field_name => return None, + Some(_) => {} + None => field = Some(disc.field_name.clone()), + } + } + _ => return None, + } + } + field +} + +fn attach_metadata(target: &mut Value, metadata: &MetadataEnvelope) { + if metadata.is_empty() { + return; + } + let Some(obj) = target.as_object_mut() else { + return; + }; + if let Some(doc) = &metadata.doc { + obj.entry("description") + .or_insert(Value::String(doc.clone())); + } + if !metadata.examples.is_empty() { + obj.entry("examples").or_insert_with(|| { + Value::Array( + metadata + .examples + .iter() + .map(|e| Value::String(e.clone())) + .collect(), + ) + }); + } + if let Some(dep) = &metadata.deprecated { + obj.entry("deprecated").or_insert(Value::Bool(true)); + obj.entry("x-golem-deprecation-note") + .or_insert(Value::String(dep.clone())); + } +} + +/// Number of base64url-no-pad characters required to encode `n` raw bytes. +/// Matches the alphabet used by [`crate::schema::canonical::binary`] which +/// uses `base64::engine::general_purpose::URL_SAFE_NO_PAD`. +fn base64url_no_pad_len(n: u32) -> u64 { + let n = n as u64; + 4 * (n / 3) + + match n % 3 { + 0 => 0, + 1 => 2, + 2 => 3, + _ => unreachable!(), + } +} + +/// Escape a string for use as a single JSON-Pointer token: `~` becomes `~0` +/// and `/` becomes `~1` per RFC 6901. +fn escape_pointer_token(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + for ch in s.chars() { + match ch { + '~' => out.push_str("~0"), + '/' => out.push_str("~1"), + other => out.push(other), + } + } + out +} + +/// Escape a string for inclusion as a literal in a basic regex pattern. +fn regex_escape(s: &str) -> String { + let specials: &[char] = &[ + '\\', '^', '$', '.', '|', '?', '*', '+', '(', ')', '[', ']', '{', '}', + ]; + let mut out = String::with_capacity(s.len()); + for ch in s.chars() { + if specials.contains(&ch) { + out.push('\\'); + } + out.push(ch); + } + out +} + +fn obj>(entries: I) -> Value { + let mut map = Map::new(); + for (k, v) in entries { + map.insert(k.to_string(), v); + } + Value::Object(map) +} + +fn obj_inline>(entries: I) -> Value { + obj(entries) +} diff --git a/golem-common/src/schema/render/json_value.rs b/golem-schema/src/schema/render/json_value.rs similarity index 97% rename from golem-common/src/schema/render/json_value.rs rename to golem-schema/src/schema/render/json_value.rs index e39f56a494..d0f2867f10 100644 --- a/golem-common/src/schema/render/json_value.rs +++ b/golem-schema/src/schema/render/json_value.rs @@ -200,15 +200,27 @@ fn encode( (SchemaType::Quantity { .. }, SchemaValue::Quantity(q)) => { Ok(canonical::quantity::to_json(q)) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] (SchemaType::Secret { .. }, SchemaValue::Secret(p)) => { canonical::secret::to_json(p).map_err(RenderError::from) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] (SchemaType::QuotaToken { .. }, SchemaValue::QuotaToken(p)) => { canonical::quota_token::to_json(p).map_err(RenderError::from) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] (SchemaType::PermissionCard { .. }, SchemaValue::PermissionCard(p)) => { canonical::permission_card::to_json(p).map_err(RenderError::from) } + #[cfg(all(feature = "guest", not(feature = "host")))] + ( + SchemaType::Secret { .. } + | SchemaType::QuotaToken { .. } + | SchemaType::PermissionCard { .. }, + SchemaValue::Secret(_) | SchemaValue::QuotaToken(_) | SchemaValue::PermissionCard(_), + ) => Err(RenderError::Unsupported( + "opaque host-managed capabilities cannot be rendered by a guest", + )), (SchemaType::Record { fields, .. }, SchemaValue::Record { fields: vs }) => { if fields.len() != vs.len() { @@ -623,18 +635,27 @@ fn from_json_body( let q = canonical::quantity::from_json(json)?; Ok(SchemaValue::Quantity(q)) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] SchemaType::Secret { .. } => { let p = canonical::secret::from_json(json)?; Ok(SchemaValue::Secret(p)) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] SchemaType::QuotaToken { .. } => { let p = canonical::quota_token::from_json(json)?; Ok(SchemaValue::QuotaToken(p)) } + #[cfg(not(all(feature = "guest", not(feature = "host"))))] SchemaType::PermissionCard { .. } => { let p = canonical::permission_card::from_json(json)?; Ok(SchemaValue::PermissionCard(p)) } + #[cfg(all(feature = "guest", not(feature = "host")))] + SchemaType::Secret { .. } + | SchemaType::QuotaToken { .. } + | SchemaType::PermissionCard { .. } => Err(RenderError::Unsupported( + "opaque host-managed capabilities cannot be constructed by a guest", + )), SchemaType::Record { fields, .. } => { let obj = json diff --git a/golem-schema/src/schema/render/mod.rs b/golem-schema/src/schema/render/mod.rs new file mode 100644 index 0000000000..ffaf622cd1 --- /dev/null +++ b/golem-schema/src/schema/render/mod.rs @@ -0,0 +1,38 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Guest-safe canonical schema and value rendering. + +pub mod error; +pub mod json_schema; +pub mod json_value; +pub mod openapi; +pub mod walker; + +pub use error::RenderError; +pub use json_schema::{ + JsonSchemaConfig, to_external_input_json_schema, to_external_output_json_schema, + to_json_schema, to_json_schema_with_config, +}; +pub use json_value::{ + from_json_value, from_untrusted_json_value, to_json_value, to_json_value_redacted, +}; +pub use openapi::{ + to_external_input_openapi_components, to_external_output_openapi_components, + to_openapi_components, +}; +pub use walker::{SchemaWalker, WalkerError, resolve_ref, walk}; + +#[cfg(test)] +mod tests; diff --git a/golem-common/src/schema/render/openapi.rs b/golem-schema/src/schema/render/openapi.rs similarity index 100% rename from golem-common/src/schema/render/openapi.rs rename to golem-schema/src/schema/render/openapi.rs diff --git a/golem-schema/src/schema/render/tests.rs b/golem-schema/src/schema/render/tests.rs new file mode 100644 index 0000000000..1bb2e32abf --- /dev/null +++ b/golem-schema/src/schema/render/tests.rs @@ -0,0 +1,134 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::{RenderError, from_json_value, to_json_schema, to_json_value}; +use crate::schema::{ + MetadataEnvelope, NamedFieldType, SchemaGraph, SchemaType, SchemaTypeDef, SchemaValue, + TextRestrictions, TextValuePayload, TypeId, VariantCaseType, VariantValuePayload, +}; +use serde_json::{Value, json}; +use test_r::test; + +#[test] +fn canonical_record_round_trips_through_json() { + let ty = SchemaType::record(vec![ + NamedFieldType { + name: "id".to_string(), + body: SchemaType::u64(), + metadata: MetadataEnvelope::default(), + }, + NamedFieldType { + name: "name".to_string(), + body: SchemaType::text(TextRestrictions::default()), + metadata: MetadataEnvelope::default(), + }, + ]); + let graph = SchemaGraph::anonymous(ty.clone()); + let value = SchemaValue::Record { + fields: vec![ + SchemaValue::U64(u64::MAX), + SchemaValue::Text(TextValuePayload { + text: "Ada".to_string(), + language: Some("en".to_string()), + }), + ], + }; + + let rendered = to_json_value(&graph, &ty, &value).expect("render record"); + assert_eq!( + rendered, + json!({ + "id": u64::MAX, + "name": { "text": "Ada", "language": "en" } + }) + ); + assert_eq!( + from_json_value(&graph, &ty, &rendered).expect("decode record"), + value + ); +} + +#[test] +fn refs_variants_and_options_share_one_graph() { + let payload_id = TypeId::new("example.payload"); + let payload = SchemaType::record(vec![NamedFieldType { + name: "value".to_string(), + body: SchemaType::option(SchemaType::string()), + metadata: MetadataEnvelope::default(), + }]); + let root = SchemaType::variant(vec![ + VariantCaseType { + name: "empty".to_string(), + payload: None, + metadata: MetadataEnvelope::default(), + }, + VariantCaseType { + name: "payload".to_string(), + payload: Some(SchemaType::ref_to(payload_id.clone())), + metadata: MetadataEnvelope::default(), + }, + ]); + let graph = SchemaGraph { + defs: vec![SchemaTypeDef { + id: payload_id, + name: Some("Payload".to_string()), + body: payload, + }], + root: root.clone(), + }; + let value = SchemaValue::Variant(VariantValuePayload { + case: 1, + payload: Some(Box::new(SchemaValue::Record { + fields: vec![SchemaValue::Option { + inner: Some(Box::new(SchemaValue::String("x".to_string()))), + }], + })), + }); + + let rendered = to_json_value(&graph, &root, &value).expect("render variant"); + assert_eq!(rendered, json!({ "payload": { "value": "x" } })); + assert_eq!( + from_json_value(&graph, &root, &rendered).expect("decode variant"), + value + ); + + let schema = to_json_schema(&graph, &root); + assert_eq!( + schema["$schema"], + json!("https://json-schema.org/draft/2020-12/schema") + ); + assert!(schema["$defs"].get("example.payload").is_some()); + let required = schema["$defs"]["example.payload"]["required"] + .as_array() + .expect("required list"); + assert!(!required.contains(&Value::String("value".to_string()))); +} + +#[test] +fn malformed_json_and_schema_values_are_typed_errors() { + let ty = SchemaType::record(vec![NamedFieldType { + name: "id".to_string(), + body: SchemaType::u32(), + metadata: MetadataEnvelope::default(), + }]); + let graph = SchemaGraph::anonymous(ty.clone()); + + let unexpected = from_json_value(&graph, &ty, &json!({ "id": 1, "extra": true })) + .expect_err("extra field must fail"); + assert!(matches!(unexpected, RenderError::UnexpectedField { .. })); + + let mismatch = to_json_value(&graph, &ty, &SchemaValue::Bool(true)) + .expect_err("wrong value shape must fail"); + assert!(matches!(mismatch, RenderError::ValueMismatch { .. })); +} diff --git a/golem-common/src/schema/render/walker.rs b/golem-schema/src/schema/render/walker.rs similarity index 100% rename from golem-common/src/schema/render/walker.rs rename to golem-schema/src/schema/render/walker.rs diff --git a/golem-skills/skills/common/golem-agent-reflection/SKILL.md b/golem-skills/skills/common/golem-agent-reflection/SKILL.md new file mode 100644 index 0000000000..4f8d4c62d8 --- /dev/null +++ b/golem-skills/skills/common/golem-agent-reflection/SKILL.md @@ -0,0 +1,21 @@ +--- +name: golem-agent-reflection +description: "Choosing Golem agent reflection levels and identity lookup behavior across SDKs. Use when agent types or methods are discovered dynamically, schemas are inspected at runtime, or an environment-scoped agent identity must be resolved." +--- + +# Agent Reflection + +Use the narrowest client surface that matches what the caller knows: + +- Use a generated or definition-owned client when the target type and methods are known in source. +- Use a caller-owned contract when the target implementation is not imported but its identity and method schemas are known. +- Use runtime reflection when the type or method is selected dynamically and the caller needs registered constructor, input, or output schemas. +- Use a schema-free dynamic client only when infrastructure deliberately works with schema-native values and arbitrary method names. + +Agent identity strings are environment-scoped. Reflection identities do not include a component ID: the runtime resolves the agent type's implementing component within the caller's environment. Component-bearing IDs belong to lower-level host-management APIs, not reflection clients. + +Discovery lookups are optional: a name or identity lookup returns no type when the deployment is missing, the identity is malformed, or the caller cannot view it. Parsing an identity is strict and reports malformed input. Identity discovery never creates the target agent. + +Reflected schema graphs are immutable snapshots of the deployed contract. Validate or pack JSON through the reflected constructor or method schema, and treat a missing or malformed declared output as a remote output error. + +Load the language-specific reflection skill for concrete SDK APIs and examples. diff --git a/golem-skills/skills/ts/golem-add-config-ts/SKILL.md b/golem-skills/skills/ts/golem-add-config-ts/SKILL.md index 0fdcba64c0..174785623e 100644 --- a/golem-skills/skills/ts/golem-add-config-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-add-config-ts/SKILL.md @@ -96,5 +96,5 @@ Values set closer to the agent override those set at broader scopes. - Only object/record schemas are recursed into nested fields; unions, arrays, tuples, maps, and primitives are read whole - Optional fields use the schema's own optionality (e.g. `z.number().optional()`) - Config keys in `golem.yaml` use camelCase matching the field names -- Config values are provisioned per environment (via `golem.yaml` / CLI); a caller may ALSO override non-secret config for a remote agent at call time via `clientFor(Def)(id, phantomId?, overrides)` (config-on-RPC — secret overrides are rejected) +- Config values are provisioned per environment (via `golem.yaml` / CLI); a caller may ALSO override non-secret config for a remote agent at call time via `Def.client.get(id, overrides)` or `Def.client.getPhantom(id, phantomId, overrides)` (config-on-RPC — secret overrides are rejected) - If the config includes secret fields, mark them with `s.secret(...)` and see `golem-add-secret-ts` for secret-specific declaration and CLI guidance diff --git a/golem-skills/skills/ts/golem-agent-reflection-ts/SKILL.md b/golem-skills/skills/ts/golem-agent-reflection-ts/SKILL.md new file mode 100644 index 0000000000..38d1b45de4 --- /dev/null +++ b/golem-skills/skills/ts/golem-agent-reflection-ts/SKILL.md @@ -0,0 +1,192 @@ +--- +name: golem-agent-reflection-ts +description: "Discovering and calling Golem agents through runtime reflection in TypeScript. Use when agent types or methods are selected dynamically, schemas must be inspected at runtime, or only a ParsedAgentId is available." +--- + +# Calling Agents with Runtime Reflection (TypeScript) + +Use reflection when the target agent type or method is chosen at runtime. When +the target is known while writing the component, prefer its definition client +(`Target.client`) because it provides compile-time input and output types. + +## Discover Agent Types + +The reflection API exposes the agent types registered for the running +component revision: + +```typescript +import { + getAllAgentTypes, + getReflectedAgentType, +} from '@golemcloud/golem-ts-sdk'; + +const available = getAllAgentTypes(); +const counterType = getReflectedAgentType('CounterAgent'); + +if (!counterType) { + throw new Error('CounterAgent is not registered'); +} + +console.log(counterType.name, counterType.mode, counterType.sourceLanguage); +console.log(counterType.methods.map((method) => method.name)); +``` + +An `AgentType` contains its constructor schema, method schemas, descriptions, +implementation identity, and lifecycle mode. Use `method(name)` when selecting +a method dynamically; it returns `undefined` for an unknown method. + +## Inspect and Validate Schemas + +Constructor and method schemas are exposed as `SchemaRef` values. They accept +canonical JSON, report structured validation issues, and can render JSON +Schema: + +```typescript +const method = counterType.method('add'); +if (!method) throw new Error('CounterAgent.add is not registered'); + +const validation = method.input.validateJson({ by: 5 }); +if (!validation.success) { + throw new Error(JSON.stringify(validation.issues)); +} + +const jsonSchema = method.input.toJsonSchema(); +``` + +Use `packJson` and `unpackJson` only when integrating with APIs that explicitly +exchange schema-native values. Normal reflected calls accept and return JSON. + +## Invoke a Durable Agent + +Use the reflected type's client factory just like a typed definition factory, +then select the method by name: + +```typescript +const counter = counterType.client.get({ name: 'main' }); +const invocation = await counter.method('add').invoke({ by: 5 }); + +console.log(invocation.value); +console.log(invocation.metadata.agentId); +console.log(invocation.metadata.idempotencyKey); +``` + +`invoke` and `invokeJson` return `{ value, metadata }`. `trigger` and `schedule` +also return identity metadata. Client creation and invocation failures are +reported as structured `RemoteCallError` values; use `isRemoteCallError` to +inspect their `cause` without parsing messages. + +## Construct an Agent ID with Caller-Owned Schemas + +A complete caller-owned contract is the Level 2 option when the target name, +constructor shape, and methods are known locally but the target implementation +is not imported. Its `agentId` helper accepts values described by any supported +Standard Schema library: + +```typescript +import { z } from 'zod'; +import { + ParsedAgentId, + defineAgentClient, + method, +} from '@golemcloud/golem-ts-sdk'; +import { v } from '@golemcloud/golem-ts-sdk/schema'; + +const CounterContract = defineAgentClient({ + name: 'CounterAgent', + id: { name: z.string() }, + methods: { + echo: method({ input: { message: z.string() }, returns: z.string() }), + }, +}); + +const schemaLibraryId = CounterContract.agentId({ name: 'main' }); +const first = await schemaLibraryId + .client(CounterContract) + .echo({ message: 'from Zod' }); + +const constructorValue = v.record([v.string('main')]); +const schemaValueId = ParsedAgentId.create({ + typeName: CounterContract.name, + constructorValue, +}); +const second = await schemaValueId + .client(CounterContract) + .echo({ message: 'from SchemaValue' }); +``` + +The first form validates and packs constructor fields through the caller's +schema library. The explicit `ParsedAgentId.create` form is for infrastructure that +already owns a Golem `SchemaValue`; record fields must be in the target +constructor's declared order. It does not validate that value against the +remote constructor schema. When runtime metadata is available, prefer +`agentType.agentId(json)` or pack with `agentType.constructorInput` before +calling `agentType.agentIdValue(value)`. + +## Bind a Concrete Agent ID + +After an agent exists, resolve the schema registered for that concrete identity +and bind it fluently: + +```typescript +import { + getAgentTypeByAgentId, + ParsedAgentId, +} from '@golemcloud/golem-ts-sdk'; + +function bindExisting(agentId: ParsedAgentId) { + const reflected = getAgentTypeByAgentId(agentId); + if (!reflected) throw new Error('Agent or registered type was not found'); + return agentId.client(reflected); +} +``` + +Lookup by `ParsedAgentId` does not create the agent. It returns `undefined` when the +identity does not exist, its type cannot be resolved, or the caller cannot view +it. `agentId.parts()` is the strict local operation when malformed identity text +must be reported instead of treated as a discovery miss. Use +`agentId.dynamicClient()` only for lifecycle-free infrastructure that already +holds schema-native values and intentionally invokes arbitrary method names +without discovery. + +## Phantom and Ephemeral Agents + +Reflected durable types expose the same three constructors as definition +clients: + +```typescript +const known = counterType.client.getPhantom({ name: 'main' }, savedPhantomId); +const { client, agentId, phantomId } = counterType.client.newPhantom({ name: 'main' }); +``` + +For an ephemeral reflected type, `get` is unavailable. `newPhantom` returns the +logical reflected client directly, and each invocation returns its allocated +one-shot identity in metadata: + +```typescript +const requestType = getReflectedAgentType('RequestAgent'); +if (!requestType || requestType.mode !== 'ephemeral') { + throw new Error('RequestAgent must be ephemeral'); +} + +const request = requestType.client.newPhantom({ route: 'summarize' }); +if ('client' in request) throw new Error('unexpected durable phantom wrapper'); + +const result = await request.method('run').invoke({ text: 'hello' }); +console.log(result.metadata.agentId, result.metadata.idempotencyKey); +``` + +`getPhantom` is also available when the caller already holds the phantom ID. +It does not make a final, already-invoked ephemeral agent ID reusable. + +Do not treat an ephemeral proxy as having a reusable final `ParsedAgentId`. A final +ephemeral identity cannot accept another invocation or be resumed. + +## Choosing the Client Surface + +| Situation | Use | +|---|---| +| Target definition and method known in source | `Target.client` | +| Type or method selected at runtime | `getReflectedAgentType` / `getAllAgentTypes` | +| Existing concrete identity needs its current schema | `getAgentTypeByAgentId` | +| Existing identity plus a caller-owned typed contract | `agentId.client(contract)` | +| Lifecycle-free invocation with schema-native values | `agentId.dynamicClient()` | diff --git a/golem-skills/skills/ts/golem-call-another-agent-ts/SKILL.md b/golem-skills/skills/ts/golem-call-another-agent-ts/SKILL.md index fd9c940d17..f261abb96e 100644 --- a/golem-skills/skills/ts/golem-call-another-agent-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-call-another-agent-ts/SKILL.md @@ -5,24 +5,20 @@ description: "Calling another agent and awaiting the result in a TypeScript Gole # Calling Another Agent (TypeScript) -There are two typed RPC APIs. Use `clientFor` when both agents are defined in the +There are two typed RPC APIs. Use a definition's `.client` when both agents are defined in the same component. Use a generated guest client when the target is in another component (including a component written in another language). -## Same Component: `clientFor` +## Same Component: Definition Client -Pass the agent's **definition** (the value returned by `defineAgent`) to -`clientFor`, then call the returned factory with the target agent's **id record**: +Use the `.client` attached to the agent's **definition** (the value returned by +`defineAgent`), then call `.get` with the target agent's **id record**: ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -// Build the factory once (module scope is fine — it caches the codecs). -const counterClient = clientFor(Counter); - // Get a handle to a specific instance by its id record. -const c1 = counterClient({ name: 'my-counter' }); +const c1 = Counter.client.get({ name: 'my-counter' }); ``` The id argument is the record declared in the target agent's `id: { … }` (for a @@ -44,10 +40,10 @@ call throws a `RemoteCallError`. ## Phantom Agents -`clientFor(Def)` accepts an optional second `phantomId` argument to address a -specific phantom instance that shares the same id record. To create a fresh -phantom, call `clientFor(Def).newPhantom(id)`; the returned details contain the -typed client and generated `phantomId`, which can be saved and reused. See the +Call `Def.client.getPhantom(id, phantomId)` to address a specific phantom +instance that shares the same id record. To create a fresh phantom, call +`Def.client.newPhantom(id)`; the returned details contain the typed client, full +`agentId`, and generated `phantomId`, which can be saved and reused. See the `golem-multi-instance-agent-ts` skill. ## Different Component: Generated Guest Client diff --git a/golem-skills/skills/ts/golem-fire-and-forget-ts/SKILL.md b/golem-skills/skills/ts/golem-fire-and-forget-ts/SKILL.md index 5a3536df50..459486e76d 100644 --- a/golem-skills/skills/ts/golem-fire-and-forget-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-fire-and-forget-ts/SKILL.md @@ -13,20 +13,19 @@ the invocation asynchronously. ## Usage -Every method on a `clientFor(...)` RPC client has a `.trigger()` variant. It takes +Every method on a definition RPC client has a `.trigger()` variant. It takes the same input record as the awaited call but returns `void` immediately: ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter)({ name: 'my-counter' }); +const counter = Counter.client.get({ name: 'my-counter' }); // Fire-and-forget — returns immediately counter.increment.trigger(); // input: {} // With arguments -const processor = clientFor(DataProcessor)({ name: 'pipeline-1' }); +const processor = DataProcessor.client.get({ name: 'pipeline-1' }); processor.processBatch.trigger({ batch: batchData }); ``` @@ -40,7 +39,7 @@ CounterAgent.get('my-counter').increment.trigger(); ``` See the `golem-call-another-agent-ts` skill for the required `golem.yaml` and -`tsconfig.json` setup. Do not replace `clientFor` for same-component calls. +`tsconfig.json` setup. Use the definition's `.client` for same-component calls. ## When to Use @@ -52,16 +51,15 @@ See the `golem-call-another-agent-ts` skill for the required `golem.yaml` and ## Example: Breaking a Deadlock ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { AgentA } from './agent-a.js'; import { AgentB } from './agent-b.js'; // In AgentA — calls AgentB and waits -const b = clientFor(AgentB)({ name: 'b1' }); +const b = AgentB.client.get({ name: 'b1' }); const result = await b.doWork({ data }); // OK: awaited call // In AgentB — notifies AgentA without waiting (would deadlock if awaited) -const a = clientFor(AgentA)({ name: 'a1' }); +const a = AgentA.client.get({ name: 'a1' }); a.onWorkDone.trigger({ result }); // OK: fire-and-forget ``` diff --git a/golem-skills/skills/ts/golem-multi-instance-agent-ts/SKILL.md b/golem-skills/skills/ts/golem-multi-instance-agent-ts/SKILL.md index b2ed2dcf12..2348577d42 100644 --- a/golem-skills/skills/ts/golem-multi-instance-agent-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-multi-instance-agent-ts/SKILL.md @@ -23,21 +23,20 @@ agent-type(param1, param2) ## Creating and Addressing Phantom Agents (RPC) -You address another agent with a typed RPC client built from its `defineAgent` definition via `clientFor(Def)`. The returned factory takes the id record and an **optional phantom UUID**: +You address another agent through the typed `client` namespace attached to its `defineAgent` definition: ```typescript -clientFor(Def)(id) // non-phantom: same agent for the same id -clientFor(Def)(id, phantomUuid) // phantom: addressed by id + a specific UUID -clientFor(Def)(id, phantomUuid, config) // + per-call non-secret config overrides (config-on-RPC) -clientFor(Def).newPhantom(id, config?) // new phantom with a generated UUID +Def.client.get(id, config?) // non-phantom +Def.client.getPhantom(id, phantomUuid, config?) // known phantom +Def.client.newPhantom(id, config?) // new phantom with generated identity ``` | Call | Description | |--------|-------------| -| `client(id)` | Get or create a **non-phantom** agent identified solely by its id record | -| `client.newPhantom(id)` | Create a **new phantom** agent and return `{ client, phantomId }` | -| `client(id, savedUuid)` | Get or create a phantom agent with a **specific** UUID | -| `client(id, undefined, { foo })` | Override the target's non-secret config for this call (secrets stay host-provisioned) | +| `Def.client.get(id)` | Get or create a **non-phantom** agent identified solely by its id record | +| `Def.client.newPhantom(id)` | Create a **new phantom** agent and return `{ client, agentId, phantomId }` | +| `Def.client.getPhantom(id, savedUuid)` | Get or create a phantom agent with a **specific** UUID | +| `Def.client.get(id, { foo })` | Override the target's non-secret config for this call (secrets stay host-provisioned) | Each method on the client has, besides the awaited call: `.trigger(input)` (fire-and-forget) and `.schedule(at, input) → CancellationToken`. Cancel an awaited invocation with the normal call shape's trailing `{ signal }` option: `method(input, { signal })`, or `method({ signal })` for a method with no input. @@ -45,7 +44,7 @@ Each method on the client has, besides the awaited call: `.trigger(input)` (fire ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor, Uuid } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, Uuid } from '@golemcloud/golem-ts-sdk'; export const Counter = defineAgent({ name: 'Counter', @@ -63,25 +62,22 @@ Counter.implement({ }, }); -// --- In another agent, using the RPC client factory: --- -const counters = clientFor(Counter); - // Non-phantom: always the same agent for the same name -const shared = counters({ name: 'shared' }); +const shared = Counter.client.get({ name: 'shared' }); await shared.increment(); -// New phantom: the factory returns the client and its generated UUID. -const { client: phantom1, phantomId: phantomId1 } = counters.newPhantom({ +// New phantom: the call returns the client and its generated UUID. +const { client: phantom1, phantomId: phantomId1 } = Counter.client.newPhantom({ name: 'shared', }); -const { client: phantom2 } = counters.newPhantom({ name: 'shared' }); +const { client: phantom2 } = Counter.client.newPhantom({ name: 'shared' }); // phantom1 and phantom2 are different agents, both with name="shared" // Reconnect to an existing phantom by its UUID. -const samePhantom = counters({ name: 'shared' }, phantomId1); +const samePhantom = Counter.client.getPhantom({ name: 'shared' }, phantomId1); // A persisted UUID string can be restored later. -const restoredPhantom = counters( +const restoredPhantom = Counter.client.getPhantom( { name: 'shared' }, Uuid.parse(savedUuidString), ); @@ -92,7 +88,7 @@ Persist the phantom UUID yourself (as a string via `uuid.toString()`, reparsed w ### Phantoms in Another Component A generated durable guest client uses static `get`, `getPhantom`, and -`newPhantom` methods, with flattened id parameters rather than the `clientFor` +`newPhantom` methods, with flattened id parameters rather than the definition-client id record. For example: ```typescript @@ -104,8 +100,8 @@ const freshPhantom = CounterAgent.newPhantom('shared'); When the target declares local config, the generated client also provides `getWithConfig`, `getPhantomWithConfig`, and `newPhantomWithConfig`. See the `golem-call-another-agent-ts` skill for cross-component manifest, TypeScript -source-path, and import setup. The `clientFor` forms above remain correct within -the component that defines the agent. +source-path, and import setup. The definition-client forms above are for calls +within the component that defines the agent. ## Querying the Phantom ID from Inside an Agent diff --git a/golem-skills/skills/ts/golem-parallel-workers-ts/SKILL.md b/golem-skills/skills/ts/golem-parallel-workers-ts/SKILL.md index f60a4b0aab..2c0896b74f 100644 --- a/golem-skills/skills/ts/golem-parallel-workers-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-parallel-workers-ts/SKILL.md @@ -9,7 +9,7 @@ description: "Fan out work to multiple parallel agents and collect results in a Golem agents process invocations **sequentially** — a single agent cannot run work in parallel. To execute work concurrently, distribute it across **multiple agent instances**. This skill covers two approaches: -1. **Child agents via `clientFor(AgentDef)(id)`** — spawn separate agent instances, dispatch work, and collect results +1. **Child agents via `AgentDef.client.get(id)`** — spawn separate agent instances, dispatch work, and collect results 2. **`fork()`** — clone the current agent at the current execution point for lightweight parallel execution ## Approach 1: Child Agent Fan-Out @@ -20,7 +20,7 @@ Spawn child agents, call them concurrently with `Promise.all`, and aggregate res ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const Worker = defineAgent({ name: 'Worker', @@ -39,9 +39,6 @@ export const WorkerImpl = Worker.implement({ }, }); -// A typed RPC client factory for the remote Worker (built once, caches codecs). -const workerClient = clientFor(Worker); - export const Coordinator = defineAgent({ name: 'Coordinator', id: { name: z.string() }, @@ -55,7 +52,7 @@ export const CoordinatorImpl = Coordinator.implement({ methods: { async fanOut({ items }) { // Spawn one child per item and call concurrently. - const promises = items.map((item, i) => workerClient({ id: i }).process({ data: item })); + const promises = items.map((item, i) => Worker.client.get({ id: i }).process({ data: item })); // Wait for all children to finish. return await Promise.all(promises); }, @@ -73,7 +70,7 @@ async fanOutChunked({ ids }) { const results: number[] = []; for (const chunk of chunks) { - const promises = chunk.map((id) => workerClient({ id }).compute({ n: id })); + const promises = chunk.map((id) => Worker.client.get({ id }).compute({ n: id })); results.push(...await Promise.all(promises)); } return results; @@ -97,7 +94,7 @@ agent boundary as a bigint-aware JSON string: ```typescript import { z } from 'zod'; import { - defineAgent, method, clientFor, + defineAgent, method, createPromise, awaitPromise, completePromise, PromiseId, } from '@golemcloud/golem-ts-sdk'; @@ -128,8 +125,6 @@ export const RegionWorkerImpl = RegionWorker.implement({ }, }); -const regionClient = clientFor(RegionWorker); - // Inside a coordinator method handler: async dispatchAndCollect({ regions }) { // Create one promise per child. @@ -137,7 +132,7 @@ async dispatchAndCollect({ regions }) { // Fire-and-forget: trigger each child with its (encoded) promise ID. regions.forEach((region, i) => { - regionClient({ region }).runReport.trigger({ promiseId: encodePromiseId(promiseIds[i]) }); + RegionWorker.client.get({ region }).runReport.trigger({ promiseId: encodePromiseId(promiseIds[i]) }); }); // Collect all results (the agent suspends until each promise completes). @@ -153,7 +148,7 @@ Use `Promise.allSettled` to handle partial failures: ```typescript async fanOutWithErrors({ items }) { - const promises = items.map((item, i) => workerClient({ id: i }).process({ data: item })); + const promises = items.map((item, i) => Worker.client.get({ id: i }).process({ data: item })); const settled = await Promise.allSettled(promises); const successes: string[] = []; diff --git a/golem-skills/skills/ts/golem-quota-ts/SKILL.md b/golem-skills/skills/ts/golem-quota-ts/SKILL.md index ef0c4ec0e2..366e8fc0d7 100644 --- a/golem-skills/skills/ts/golem-quota-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-quota-ts/SKILL.md @@ -126,14 +126,14 @@ if (reservationResult.isOk()) { ## 6. Splitting Tokens for Agent-to-Agent RPC -Split a portion of your quota to pass to a child agent. Call the other agent with a `clientFor(...)` client (see `golem-call-another-agent-ts`), passing the child token as an input: +Split a portion of your quota to pass to a child agent. Call the other agent through its definition client (see `golem-call-another-agent-ts`), passing the child token as an input: ```typescript -import { clientFor, QuotaToken } from '@golemcloud/golem-ts-sdk'; +import { QuotaToken } from '@golemcloud/golem-ts-sdk'; const childToken: QuotaToken = this.token.split(200n); -const summarizer = clientFor(SummarizerAgent); -const summary = await summarizer({ name: 'sum-1' }).summarize({ text, token: childToken }); +const summarizer = SummarizerAgent.client.get({ name: 'sum-1' }); +const summary = await summarizer.summarize({ text, token: childToken }); ``` The child agent declares the token input with the `s.quotaToken()` schema marker and uses it for its own reservations: diff --git a/golem-skills/skills/ts/golem-recurring-task-ts/SKILL.md b/golem-skills/skills/ts/golem-recurring-task-ts/SKILL.md index 888a264a5d..eb500c410c 100644 --- a/golem-skills/skills/ts/golem-recurring-task-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-recurring-task-ts/SKILL.md @@ -9,7 +9,7 @@ description: "Implementing a recurring (cron-like) task in a TypeScript Golem ag A Golem agent can act as its own scheduler by scheduling one of its own methods to run again at the end of each invocation. This creates a durable, crash-resilient recurring task — if the agent restarts, the scheduled invocation is still pending and will fire at the designated time. -Because a method handler's `this` is bound to the agent's **state** (not to its other methods), factor the self-scheduling logic into a small module-level helper that builds an RPC client for the agent itself with `clientFor` and calls `.schedule()`. +Because a method handler's `this` is bound to the agent's **state** (not to its other methods), factor the self-scheduling logic into a small module-level helper that uses the definition's RPC client and calls `.schedule()`. ## Basic Pattern @@ -17,7 +17,7 @@ The agent schedules its own `poll` method to run again after a delay: ```typescript import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const PollerAgent = defineAgent({ name: 'PollerAgent', @@ -31,7 +31,7 @@ export const PollerAgent = defineAgent({ // Self-scheduling helper: enqueue this agent's own `poll` to run after a delay. function scheduleNext(name: string, delaySecs: bigint): void { const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - clientFor(PollerAgent)({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); + PollerAgent.client.get({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); } export const PollerAgentImpl = PollerAgent.implement({ @@ -105,7 +105,7 @@ export const PollerAgentImpl = PollerAgent.implement({ if (this.cancelled) return; // stop the loop doWork(); const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - this.pending = clientFor(PollerAgent)({ name: this.name }).poll.schedule({ + this.pending = PollerAgent.client.get({ name: this.name }).poll.schedule({ seconds: nowSecs + 60n, nanoseconds: 0, }); @@ -175,12 +175,12 @@ heartbeat() { ## Helper for Scheduling Self -Keep the scheduling logic in one module-level helper so every method stays clean. `clientFor(PollerAgent)` builds a typed RPC client for this same agent type; addressing it by the agent's own id record targets this instance: +Keep the scheduling logic in one module-level helper so every method stays clean. `PollerAgent.client` is the typed RPC factory for this same agent type; addressing it by the agent's own id record targets this instance: ```typescript function scheduleNext(name: string, delaySecs: bigint): void { const nowSecs = BigInt(Math.floor(Date.now() / 1000)); - clientFor(PollerAgent)({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); + PollerAgent.client.get({ name }).poll.schedule({ seconds: nowSecs + delaySecs, nanoseconds: 0 }); } ``` diff --git a/golem-skills/skills/ts/golem-schedule-future-call-ts/SKILL.md b/golem-skills/skills/ts/golem-schedule-future-call-ts/SKILL.md index a4eb85f118..dc8e7eaec4 100644 --- a/golem-skills/skills/ts/golem-schedule-future-call-ts/SKILL.md +++ b/golem-skills/skills/ts/golem-schedule-future-call-ts/SKILL.md @@ -11,23 +11,22 @@ A **scheduled invocation** enqueues a method call on the target agent to be exec ## Usage -Every method on a `clientFor(...)` RPC client has a `.schedule()` variant that +Every method on a definition RPC client has a `.schedule()` variant that takes a `Datetime` as the first argument, followed by the method's input record (omit the input for methods declared with `input: {}`). It returns a `CancellationToken`; ignore the token when cancellation is not needed. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter)({ name: 'my-counter' }); +const counter = Counter.client.get({ name: 'my-counter' }); // Schedule increment to run 60 seconds from now. const nowSecs = BigInt(Math.floor(Date.now() / 1000)); counter.increment.schedule({ seconds: nowSecs + 60n, nanoseconds: 0 }); // Schedule with arguments. -const reporter = clientFor(ReportAgent)({ name: 'daily' }); +const reporter = ReportAgent.client.get({ name: 'daily' }); reporter.generateReport.schedule( { seconds: BigInt(tomorrowMidnight), nanoseconds: 0 }, { kind: 'summary' }, diff --git a/golem-skills/tests/harness/scenarios/rpc-5-runtime-reflection.yaml b/golem-skills/tests/harness/scenarios/rpc-5-runtime-reflection.yaml new file mode 100644 index 0000000000..c8351044b5 --- /dev/null +++ b/golem-skills/tests/harness/scenarios/rpc-5-runtime-reflection.yaml @@ -0,0 +1,72 @@ +name: "rpc-5-runtime-reflection" +steps: + - id: "create-project" + only_if: + language: "ts" + create_project: + name: test-app + verify: + build: true + + - id: "add-reflected-rpc" + only_if: + language: "ts" + prompt: > + In the TypeScript test-app project, add a durable `ReflectionTarget` agent + identified by a string `name`. Give it an `echo` method that accepts a string + `message` and returns that message. + + Add a second durable `ReflectionCaller` agent with a `run` method. In `run`, use + the Golem TypeScript SDK runtime reflection APIs to list the registered agent + types, look up `ReflectionTarget` by name, inspect its `echo` method, and invoke + `ReflectionTarget("target")` through the reflected client with `"hello"`. + + Also define a complete caller-owned `ReflectionTarget` client contract whose + string ID uses a Standard Schema library. Construct the same target AgentId in + two ways: first through the contract's `agentId` helper, and then explicitly + with `ParsedAgentId.create` and a Golem `SchemaValue` built with the SDK's `v` helpers. + Bind the contract to each ID and invoke `echo` with `"schema library"` and + `"schema value"` respectively. + + Construct the target's concrete AgentId from the reflected type, resolve its + current type with `getAgentTypeByAgentId` after the first invocation, bind that + reflected type to the AgentId, and invoke `echo` again with `"again"`. + + Return exactly an object with fields `listed`, `typeName`, `methodName`, `first`, + `second`, `schemaIdsMatch`, `schemaLibrary`, and `schemaValue`. They must + respectively contain whether `ReflectionTarget` appeared in the discovered + list, the discovered type name, the reflected method name, the two reflected + echoed values, whether both caller-constructed identities have the same agent ID + string, and the two contract-call results. Make sure the project builds + successfully. + expectedSkills: + - "golem-agent-reflection" + - "golem-agent-reflection-ts" + verify: + build: true + deploy: true + + - id: "verify-reflected-rpc" + only_if: + language: "ts" + invoke_json: + agent: 'ReflectionCaller("main")' + method: "run" + expect: + result_json: + - path: "$.listed" + equals: true + - path: "$.typeName" + equals: "ReflectionTarget" + - path: "$.methodName" + equals: "echo" + - path: "$.first" + equals: "hello" + - path: "$.second" + equals: "again" + - path: "$.schemaIdsMatch" + equals: true + - path: "$.schemaLibrary" + equals: "schema library" + - path: "$.schemaValue" + equals: "schema value" diff --git a/golem-worker-executor-test-utils/src/dsl_impl.rs b/golem-worker-executor-test-utils/src/dsl_impl.rs index 27ec07baba..ac7177eaf0 100644 --- a/golem-worker-executor-test-utils/src/dsl_impl.rs +++ b/golem-worker-executor-test-utils/src/dsl_impl.rs @@ -55,10 +55,10 @@ use golem_common::model::worker::{ use golem_common::model::{AgentFilter, IdempotencyKey, ScanCursor}; use golem_common::model::{AgentId, OplogIndex}; use golem_common::schema::AgentTypeSchema; -use golem_common::schema::render::from_json_value; use golem_common::schema::validation::validate_value; use golem_common::schema::{SchemaGraph, SchemaValue, TypedSchemaValue}; use golem_common::widen_infallible; +use golem_schema::schema::render::from_json_value; use golem_service_base::error::worker_executor::WorkerExecutorError; use golem_service_base::model::ComponentFileSystemNode; use golem_service_base::replayable_stream::ReplayableStream; diff --git a/golem-worker-executor-test-utils/src/lib.rs b/golem-worker-executor-test-utils/src/lib.rs index 1b4885cb6a..1b63425f91 100644 --- a/golem-worker-executor-test-utils/src/lib.rs +++ b/golem-worker-executor-test-utils/src/lib.rs @@ -2349,6 +2349,20 @@ impl HostWasmRpc for TestWorkerCtx { .await } + async fn create( + &mut self, + agent_type_name: String, + constructor: golem_schema::schema::wit::wire::SchemaValueTree, + phantom_id: Option, + config: Vec< + golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue, + >, + ) -> anyhow::Result, RpcError>> { + self.durable_ctx + .create(agent_type_name, constructor, phantom_id, config) + .await + } + async fn invoke_and_await( &mut self, self_: Resource, diff --git a/golem-worker-executor/src/durable_host/config/mod.rs b/golem-worker-executor/src/durable_host/config/mod.rs index 1e47b8a4c3..92a5f63896 100644 --- a/golem-worker-executor/src/durable_host/config/mod.rs +++ b/golem-worker-executor/src/durable_host/config/mod.rs @@ -24,7 +24,7 @@ use golem_common::model::oplog::{ HostResponseConfigGetAllResponse, HostResponseConfigGetResponse, }; use golem_common::schema::TypedSchemaValue; -use golem_common::schema::render::json_value::to_json_value; +use golem_schema::schema::render::json_value::to_json_value; const CONFIG_PERMISSION_DENIED: &str = "permission denied"; diff --git a/golem-worker-executor/src/durable_host/golem/agent.rs b/golem-worker-executor/src/durable_host/golem/agent.rs index 8dba5f67c0..06f61b237a 100644 --- a/golem-worker-executor/src/durable_host/golem/agent.rs +++ b/golem-worker-executor/src/durable_host/golem/agent.rs @@ -20,25 +20,27 @@ use crate::durable_host::durability::HostFailureKind; use crate::durable_host::secrets::secret_hold_target_for_path; use crate::durable_host::{DurabilityHost, DurableWorkerCtx, InternalRetryResult}; use crate::preview2::golem::agent::host::{ConfigValueError, Host, WebhookError}; +use crate::services::HasWorkerService; use crate::workerctx::WorkerCtx; use anyhow::anyhow; use chrono::Utc; -use golem_common::model::PromiseId; use golem_common::model::agent::{ AgentConfigSource, AgentTypeName, ParsedAgentId, typed_constructor_parameters, }; use golem_common::model::agent_secret::CanonicalAgentSecretPath; use golem_common::model::card::AgentVerb; use golem_common::model::oplog::host_functions::{ - GolemAgentCreateWebhook, GolemAgentGetAgentType, GolemAgentGetAllAgentTypes, - GolemAgentGetConfigValue, + GolemAgentCreateWebhook, GolemAgentGetAgentType, GolemAgentGetAgentTypeByAgentId, + GolemAgentGetAllAgentTypes, GolemAgentGetConfigValue, }; use golem_common::model::oplog::{ - DurableFunctionType, HostRequestGolemAgentGetAgentType, HostRequestGolemAgentGetConfigValue, + DurableFunctionType, HostRequestGolemAgentGetAgentType, + HostRequestGolemAgentGetAgentTypeByAgentId, HostRequestGolemAgentGetConfigValue, HostRequestGolemApiPromiseId, HostRequestNoInput, HostResponseGolemAgentAgentType, HostResponseGolemAgentAgentTypes, HostResponseGolemAgentGetConfigValue, HostResponseGolemAgentWebhookUrl, }; +use golem_common::model::{AgentId, OwnedAgentId, PromiseId}; use golem_common::schema::agent::wit::{encode_registered_agent_type, wire}; use golem_common::schema::agent::{AgentTypeSchema, RegisteredAgentTypeSchema}; use golem_common::schema::graph::SchemaGraph; @@ -400,6 +402,108 @@ impl DurableWorkerCtx { Err(err) => Err(anyhow!(err)), } } + + pub(crate) async fn get_agent_type_by_agent_id( + &mut self, + agent_id: String, + ) -> anyhow::Result> { + let mut handle = + DurableCallSession::::start( + self, + HostRequestGolemAgentGetAgentTypeByAgentId { + agent_id: agent_id.clone(), + }, + DurableFunctionType::ReadRemote, + ) + .await?; + + let response = 'result: { + if !handle.is_live() { + match handle.replay(self).await? { + CallReplayOutcome::Replayed(replayed) => break 'result replayed, + CallReplayOutcome::Incomplete(live) => handle = live, + } + } + + let result = loop { + let result: anyhow::Result> = async { + let Ok(agent_type_name) = ParsedAgentId::parse_agent_type_name(&agent_id) + else { + return Ok(None); + }; + let Some(registered_agent_type) = self + .agent_types_service() + .get( + self.owned_agent_id.environment_id, + self.owned_agent_id.agent_id.component_id, + self.state.component_metadata.revision, + &agent_type_name, + ) + .await? + else { + return Ok(None); + }; + let target_agent_id = AgentId { + component_id: registered_agent_type.implemented_by.component_id, + agent_id: agent_id.clone(), + }; + if super::v1x::agent_operation_denied( + self, + &target_agent_id, + AgentVerb::View, + golem_common::model::card::AgentResourcePattern::Empty, + ) + .await? + { + return Ok(None); + } + let owned_agent_id = + OwnedAgentId::new(self.owned_agent_id.environment_id, &target_agent_id); + let metadata = self.state.worker_service().get(&owned_agent_id).await?; + let Some(metadata) = metadata else { + return Ok(None); + }; + let component_revision = metadata + .last_known_status + .as_ref() + .map(|status| status.component_revision) + .unwrap_or( + metadata + .initial_worker_metadata + .last_known_status + .component_revision, + ); + Ok(self + .agent_types_service() + .get( + self.owned_agent_id.environment_id, + target_agent_id.component_id, + component_revision, + &agent_type_name, + ) + .await?) + } + .await; + let result = result.map_err(|err| err.to_string()); + + match handle + .try_trigger_retry_or_loop(self, &result, |_| HostFailureKind::Transient) + .await? + { + InternalRetryResult::Persist => break result, + InternalRetryResult::RetryInternally => continue, + } + }; + handle + .complete(self, HostResponseGolemAgentAgentType { result }) + .await? + }; + + match response.result { + Ok(result) => Ok(result), + Err(err) => Err(anyhow!(err)), + } + } } /// Cross-graph structural type equality, resolving any [`SchemaType::Ref`] @@ -470,6 +574,16 @@ impl Host for DurableWorkerCtx { .transpose() } + async fn get_agent_type_by_agent_id( + &mut self, + agent_id: String, + ) -> anyhow::Result> { + DurableWorkerCtx::get_agent_type_by_agent_id(self, agent_id) + .await? + .map(encode_registered_agent_type_schema_wire) + .transpose() + } + async fn make_agent_id( &mut self, agent_type_name: String, diff --git a/golem-worker-executor/src/durable_host/golem/v1x.rs b/golem-worker-executor/src/durable_host/golem/v1x.rs index 66b6593131..8c52d532c1 100644 --- a/golem-worker-executor/src/durable_host/golem/v1x.rs +++ b/golem-worker-executor/src/durable_host/golem/v1x.rs @@ -123,7 +123,7 @@ fn classify_worker_executor_error(err: &WorkerExecutorError) -> HostFailureKind } } -async fn resolve_agent_owner( +pub(super) async fn resolve_agent_owner( ctx: &DurableWorkerCtx, component_id: &ComponentId, agent: Option<&str>, @@ -155,7 +155,7 @@ async fn resolve_agent_owner( Ok((owner, environment_id)) } -async fn agent_operation_denied( +pub(super) async fn agent_operation_denied( ctx: &mut DurableWorkerCtx, agent_id: &AgentId, verb: AgentVerb, diff --git a/golem-worker-executor/src/durable_host/wasm_rpc/mod.rs b/golem-worker-executor/src/durable_host/wasm_rpc/mod.rs index 8ca83696e1..d9708a66ae 100644 --- a/golem-worker-executor/src/durable_host/wasm_rpc/mod.rs +++ b/golem-worker-executor/src/durable_host/wasm_rpc/mod.rs @@ -26,6 +26,7 @@ use crate::durable_host::durable_session::{ use crate::durable_host::permissions::resolve_invocation_scope_card; use crate::durable_host::secrets::secret_hold_targets_for_value; use crate::durable_host::{DurabilityHost, DurableWorkerCtx, InternalRetryResult}; +use crate::preview2::golem::agent::common::AgentError as WitAgentError; use crate::preview2::golem::agent::host::{ AsyncInvocationWithMetadata, CancelableScheduledInvocationReceipt, CancellationToken, FutureInvokeResult, HostCancellationToken, HostFutureInvokeResult, @@ -174,7 +175,8 @@ fn classify_rpc_error(err: &InternalRpcError) -> HostFailureKind { match err { InternalRpcError::ProtocolError { .. } | InternalRpcError::Denied { .. } - | InternalRpcError::NotFound { .. } => HostFailureKind::Permanent, + | InternalRpcError::NotFound { .. } + | InternalRpcError::RemoteAgentError { .. } => HostFailureKind::Permanent, InternalRpcError::RemoteInternalError { .. } => HostFailureKind::Transient, } } @@ -196,6 +198,17 @@ where let _ = reject_quota_handles_in_value_tree(input, dropper); } +fn discard_owned_rpc_config( + config: Vec, + dropper: &mut D, +) where + D: QuotaTokenHandleDropper + SecretHandleDropper + PermissionCardHandleDropper, +{ + for entry in config { + let _ = decode_typed_rejecting_quota_with(entry.value, dropper); + } +} + fn reject_non_await_scope_card( scope_card: &Option>, input: core_wire::SchemaValueTree, @@ -223,23 +236,50 @@ impl HostWasmRpc for DurableWorkerCtx { golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue, >, ) -> anyhow::Result> { + ::create(self, agent_type_name, constructor, phantom_id, config) + .await? + .map_err(|error| anyhow::anyhow!(InternalRpcError::from(error).to_string())) + } + + async fn create( + &mut self, + agent_type_name: String, + constructor: core_wire::SchemaValueTree, + phantom_id: Option, + config: Vec< + golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue, + >, + ) -> anyhow::Result, RpcError>> { let mut env = wasmtime_wasi::p2::bindings::cli::environment::Host::get_environment(self).await?; crate::model::AgentConfig::remove_dynamic_vars(&mut env); - let registered_agent_type = self + let Some(registered_agent_type) = self .get_agent_type_schema_model(golem_common::model::agent::AgentTypeName( agent_type_name.clone(), )) .await? - .ok_or_else(|| anyhow::anyhow!("Agent type '{}' not found", agent_type_name))?; + else { + discard_owned_rpc_input(constructor, self); + discard_owned_rpc_config(config, self); + return Ok(Err(RpcError::RemoteAgentError(WitAgentError::InvalidType( + agent_type_name, + )))); + }; - let input = schema_value_tree_to_typed_constructor_parameters( + let input = match schema_value_tree_to_typed_constructor_parameters( constructor, ®istered_agent_type.agent_type, self, - ) - .map_err(|err| anyhow::anyhow!("Invalid constructor input: {err}"))?; + ) { + Ok(input) => input, + Err(err) => { + discard_owned_rpc_config(config, self); + return Ok(Err(RpcError::RemoteAgentError( + WitAgentError::InvalidInput(format!("Invalid constructor input: {err}")), + ))); + } + }; let component_id: golem_common::model::component::ComponentId = registered_agent_type.implemented_by.component_id; @@ -290,14 +330,29 @@ impl HostWasmRpc for DurableWorkerCtx { // than cloning the whole schema graph. let remote_agent_type: Arc = Arc::new(registered_agent_type.agent_type); - let agent_id = golem_common::model::agent::ParsedAgentId::try_new( + let agent_id = match golem_common::model::agent::ParsedAgentId::try_new( golem_common::model::agent::AgentTypeName(agent_type_name), input, phantom_id.map(|id| id.into()), - ) - .map_err(|e| anyhow::anyhow!("{e}"))?; - let remote_agent_id = golem_common::model::AgentId::from_agent_id(component_id, &agent_id) - .map_err(|err| anyhow::anyhow!("{err}"))?; + ) { + Ok(agent_id) => agent_id, + Err(err) => { + discard_owned_rpc_config(config, self); + return Ok(Err(RpcError::RemoteAgentError( + WitAgentError::InvalidAgentId(err.to_string()), + ))); + } + }; + let remote_agent_id = + match golem_common::model::AgentId::from_agent_id(component_id, &agent_id) { + Ok(agent_id) => agent_id, + Err(err) => { + discard_owned_rpc_config(config, self); + return Ok(Err(RpcError::RemoteAgentError( + WitAgentError::InvalidAgentId(err.to_string()), + ))); + } + }; // Each config value is a guest-owned `typed-schema-value` and never // legally carries a quota token. Decode through the rejecting path so any @@ -318,7 +373,7 @@ impl HostWasmRpc for DurableWorkerCtx { // DTO carries plain user JSON which // `parse_worker_creation_agent_config` decodes with the // schema graph (`from_json_value`). - match golem_common::schema::render::to_json_value( + match golem_schema::schema::render::to_json_value( typed.graph(), typed.root_type(), typed.value(), @@ -342,24 +397,22 @@ impl HostWasmRpc for DurableWorkerCtx { } } if let Some(err) = config_error { - return Err(err); + return Ok(Err(RpcError::RemoteAgentError( + WitAgentError::InvalidInput(err.to_string()), + ))); } let config = decoded_config; - if agent_mode == AgentMode::Ephemeral - && agent_id.phantom_id.is_some() - && self.state.is_live() - { - return Err(anyhow::anyhow!( - "An ephemeral RPC proxy cannot select a phantom ID" - )); - } - self.check_read_only_allows("golem::rpc::wasm-rpc::new") .map_err(wasmtime::Error::from)?; - let span = create_rpc_connection_span(self, &remote_agent_id).await?; - - if agent_mode == AgentMode::Ephemeral { + let pinned_ephemeral_identity = + agent_mode == AgentMode::Ephemeral && agent_id.phantom_id.is_some(); + + // A phantom-less ephemeral address is a logical proxy: every invocation + // receives a fresh final identity. A supplied phantom is already a final + // observation/control identity, so preserve it as a fixed target and let + // the normal invocation path reject attempts to reuse the terminal agent. + if agent_mode == AgentMode::Ephemeral && agent_id.phantom_id.is_none() { let logical_agent_id = agent_id .with_phantom_id(None) .map_err(|err| anyhow::anyhow!(err))?; @@ -417,7 +470,8 @@ impl HostWasmRpc for DurableWorkerCtx { remote_method_streams, component_revision, remote_owner, - ); + ) + .map(Ok); } let handle = @@ -445,8 +499,10 @@ impl HostWasmRpc for DurableWorkerCtx { remote_method_streams, component_revision, remote_owner, + pinned_ephemeral_identity, ) - .await; + .await + .map(Ok); } CallReplayOutcome::Incomplete(live) => { return construct_wasm_rpc_resource( @@ -460,8 +516,10 @@ impl HostWasmRpc for DurableWorkerCtx { remote_method_streams, component_revision, remote_owner, + pinned_ephemeral_identity, ) - .await; + .await + .map(Ok); } } } @@ -477,8 +535,10 @@ impl HostWasmRpc for DurableWorkerCtx { remote_method_streams, component_revision, remote_owner, + pinned_ephemeral_identity, ) .await + .map(Ok) } async fn invoke_and_await( @@ -3623,6 +3683,7 @@ pub async fn construct_wasm_rpc_resource( remote_method_streams: Arc>, remote_component_revision: ComponentRevision, remote_owner: AgentOwnerPattern, + pinned_ephemeral_identity: bool, ) -> anyhow::Result> { let target_environment_id = ctx.owned_agent_id.environment_id; let remote_agent_id = OwnedAgentId::new(target_environment_id, &remote_agent_id); @@ -3642,10 +3703,11 @@ pub async fn construct_wasm_rpc_resource( remote_agent_id, ephemeral_logical_agent_id: None, span_id: span.span_id().clone(), - target_activation: WasmRpcTargetActivation::DeferredDurable { - env: env.to_vec(), + target_activation: initial_target_activation( + env.to_vec(), config, - }, + pinned_ephemeral_identity, + ), remote_agent_type, remote_method_streams, remote_component_revision, @@ -3667,10 +3729,11 @@ async fn reconstruct_wasm_rpc_resource( remote_method_streams: Arc>, remote_component_revision: ComponentRevision, remote_owner: AgentOwnerPattern, + pinned_ephemeral_identity: bool, ) -> anyhow::Result> { let remote_agent_id = OwnedAgentId::new(target_environment_id, &remote_agent_id); - let target_activation = if target_fingerprint.0.is_nil() { - WasmRpcTargetActivation::DeferredDurable { env, config } + let target_activation = if pinned_ephemeral_identity || target_fingerprint.0.is_nil() { + initial_target_activation(env, config, pinned_ephemeral_identity) } else { WasmRpcTargetActivation::ReplayPending { target_fingerprint, @@ -4220,6 +4283,18 @@ pub enum WasmRpcTargetActivation { }, } +fn initial_target_activation( + env: Vec<(String, String)>, + config: Vec, + pinned_ephemeral_identity: bool, +) -> WasmRpcTargetActivation { + if pinned_ephemeral_identity { + WasmRpcTargetActivation::DeferredEphemeral { env, config } + } else { + WasmRpcTargetActivation::DeferredDurable { env, config } + } +} + impl WasmRpcTargetActivation { fn target_creation_data(&self) -> (Vec<(String, String)>, Vec) { match self { @@ -4339,11 +4414,13 @@ fn resolve_method_and_lift_input( .methods .iter() .find(|m| m.name == method_name) - .ok_or_else(|| InternalRpcError::NotFound { - details: format!( - "Method '{method_name}' not found on agent type '{}'", - agent_type.type_name - ), + .ok_or_else(|| InternalRpcError::RemoteAgentError { + error: Box::new(golem_common::model::agent::AgentError::InvalidMethod( + format!( + "Method '{method_name}' not found on agent type '{}'", + agent_type.type_name + ), + )), })?; method .validate_input(&agent_type.schema, &input_value) @@ -5094,6 +5171,58 @@ mod tests { ); } + #[test] + fn rejected_rpc_creation_drains_every_config_handle() { + let mut dropper = TableCapabilityDropper { + table: ResourceTable::new(), + }; + let first = dropper + .table + .push(QuotaTokenHandleRep::new(())) + .expect("first config quota token should be inserted"); + let second = dropper + .table + .push(QuotaTokenHandleRep::new(())) + .expect("second config quota token should be inserted"); + let first_rep = first.rep(); + let second_rep = second.rep(); + let config = [first, second] + .into_iter() + .enumerate() + .map(|(index, handle)| { + golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue { + path: vec![format!("config-{index}")], + value: core_wire::TypedSchemaValue { + graph: core_wire::SchemaGraph { + type_nodes: vec![], + defs: vec![], + root: 0, + }, + value: core_wire::SchemaValueTree { + value_nodes: vec![core_wire::SchemaValueNode::QuotaTokenHandle(handle)], + root: 0, + }, + }, + } + }) + .collect(); + + discard_owned_rpc_config(config, &mut dropper); + + assert!( + dropper + .table + .get(&Resource::::new_borrow(first_rep)) + .is_err() + ); + assert!( + dropper + .table + .get(&Resource::::new_borrow(second_rep)) + .is_err() + ); + } + #[test] fn ephemeral_invocation_target_is_derived_from_the_host_call_key() { let environment_id = EnvironmentId::new(); @@ -5168,6 +5297,17 @@ mod tests { ); } + #[test] + fn pinned_ephemeral_identity_skips_durable_activation() { + let target = initial_target_activation(vec![], vec![], true); + + assert!(matches!( + target, + WasmRpcTargetActivation::DeferredEphemeral { .. } + )); + assert!(target.deferred_activation().is_none()); + } + #[test] fn deferred_durable_target_activates_without_a_replay_fingerprint() { let target = WasmRpcTargetActivation::DeferredDurable { diff --git a/golem-worker-executor/src/grpc/mod.rs b/golem-worker-executor/src/grpc/mod.rs index cb6940d7ab..377ce94020 100644 --- a/golem-worker-executor/src/grpc/mod.rs +++ b/golem-worker-executor/src/grpc/mod.rs @@ -308,7 +308,7 @@ impl + UsesAllDeps + Send + Sync + } // Compare the existing entry's plain (schema-guided) JSON (the same // form the request DTO carries) against the requested value. - let existing_json = golem_common::schema::render::to_json_value( + let existing_json = golem_schema::schema::render::to_json_value( existing_entry.value.graph(), existing_entry.value.root_type(), existing_entry.value.value(), diff --git a/golem-worker-executor/src/services/rpc.rs b/golem-worker-executor/src/services/rpc.rs index 67b644c5a9..46941f36c8 100644 --- a/golem-worker-executor/src/services/rpc.rs +++ b/golem-worker-executor/src/services/rpc.rs @@ -53,7 +53,8 @@ use golem_common::base_model::durable_stream::{ }; use golem_common::model::account::AccountId; use golem_common::model::agent::{ - AgentInvocationMode, AgentPrincipal, InvocationFreshnessDisposition, ParsedAgentId, Principal, + AgentError as ModelAgentError, AgentInvocationMode, AgentPrincipal, + InvocationFreshnessDisposition, ParsedAgentId, Principal, }; use golem_common::model::card::{AgentMethodName, AgentResourcePattern, AgentVerb, ScopeCard}; use golem_common::model::component::ComponentRevision; @@ -198,12 +199,13 @@ pub struct DurableRpcInvocationResult { pub output_mappings: Vec, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq)] pub enum RpcError { ProtocolError { details: String }, Denied { details: String }, NotFound { details: String }, RemoteInternalError { details: String }, + RemoteAgentError { error: Box }, } impl From for RpcError { @@ -215,6 +217,7 @@ impl From for RpcError { SerializableRpcError::RemoteInternalError { details } => { Self::RemoteInternalError { details } } + SerializableRpcError::RemoteAgentError { error } => Self::RemoteAgentError { error }, } } } @@ -228,6 +231,9 @@ impl From for SerializableRpcError { RpcError::RemoteInternalError { details } => { SerializableRpcError::RemoteInternalError { details } } + RpcError::RemoteAgentError { error } => { + SerializableRpcError::RemoteAgentError { error } + } } } } @@ -241,6 +247,7 @@ impl Display for RpcError { RpcError::RemoteInternalError { details } => { write!(f, "Remote internal error: {details}") } + RpcError::RemoteAgentError { error } => write!(f, "Remote agent error: {error}"), } } } @@ -279,7 +286,9 @@ impl From for RpcError { details: "Invalid account".to_string(), }, WorkerExecutorError::PermissionDenied { details } => RpcError::Denied { details }, - WorkerExecutorError::InvalidRequest { details } => RpcError::ProtocolError { details }, + WorkerExecutorError::InvalidRequest { details } => RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidInput(details)), + }, _ => RpcError::RemoteInternalError { details: value.to_string(), }, @@ -290,8 +299,8 @@ impl From for RpcError { impl From for RpcError { fn from(value: WorkerProxyError) -> Self { match value { - WorkerProxyError::BadRequest(errors) => RpcError::ProtocolError { - details: errors.join(", "), + WorkerProxyError::BadRequest(errors) => RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidInput(errors.join(", "))), }, WorkerProxyError::Unauthorized(error) => RpcError::Denied { details: error }, WorkerProxyError::LimitExceeded(error) => RpcError::Denied { details: error }, @@ -310,9 +319,16 @@ impl From for RpcError { WitRpcError::Denied(details) => Self::Denied { details }, WitRpcError::NotFound(details) => Self::NotFound { details }, WitRpcError::RemoteInternalError(details) => Self::RemoteInternalError { details }, - WitRpcError::RemoteAgentError(err) => Self::RemoteInternalError { - details: format!("{err:?}"), - }, + WitRpcError::RemoteAgentError(err) => { + match golem_common::schema::agent::wit::decode_agent_error(err) { + Ok(error) => Self::RemoteAgentError { + error: Box::new(error), + }, + Err(err) => Self::RemoteInternalError { + details: format!("Failed to decode remote agent error: {err}"), + }, + } + } } } } @@ -324,6 +340,14 @@ impl From for crate::preview2::golem::agent::host::RpcError { RpcError::Denied { details } => Self::Denied(details), RpcError::NotFound { details } => Self::NotFound(details), RpcError::RemoteInternalError { details } => Self::RemoteInternalError(details), + RpcError::RemoteAgentError { error } => { + match golem_common::schema::agent::wit::encode_agent_error(&error) { + Ok(error) => Self::RemoteAgentError(error), + Err(err) => Self::RemoteInternalError(format!( + "Failed to encode remote agent error: {err}" + )), + } + } } } } @@ -1812,9 +1836,13 @@ impl Rpc for DirectWorkerInvocationRpc { #[cfg(test)] mod protocol_tests { use super::{RpcError, method_validation_revision, rpc_error_from_failure}; + use crate::services::worker_proxy::WorkerProxyError; use golem_api_grpc::proto::golem::worker::{InvocationFailure, InvocationFailureKind}; - use golem_common::model::agent::InvocationFreshnessDisposition; + use golem_common::model::agent::{ + AgentError as ModelAgentError, InvocationFreshnessDisposition, + }; use golem_common::model::component::ComponentRevision; + use golem_common::model::oplog::types::SerializableRpcError; use golem_service_base::error::worker_executor::WorkerExecutorError; use std::cell::Cell; use test_r::test; @@ -1882,9 +1910,58 @@ mod protocol_tests { assert_eq!( error, - RpcError::ProtocolError { - details: "bad invocation".to_string(), + RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidInput("bad invocation".to_string(),)), } ); } + #[test] + fn invalid_remote_request_is_an_agent_input_error() { + let error = RpcError::from(WorkerExecutorError::invalid_request("wrong argument shape")); + + assert_eq!( + error, + RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidInput( + "wrong argument shape".to_string() + )), + } + ); + } + + #[test] + fn proxied_bad_request_is_an_agent_input_error() { + let error = RpcError::from(WorkerProxyError::BadRequest(vec![ + "wrong argument shape".to_string(), + ])); + + assert_eq!( + error, + RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidInput( + "wrong argument shape".to_string() + )), + } + ); + } + + #[test] + fn remote_agent_error_survives_serializable_roundtrip() { + let error = RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidMethod("missing".to_string())), + }; + + let serialized = SerializableRpcError::from(error.clone()); + assert_eq!(RpcError::from(serialized), error); + } + + #[test] + fn remote_agent_error_survives_wit_roundtrip() { + let error = RpcError::RemoteAgentError { + error: Box::new(ModelAgentError::InvalidAgentId("invalid".to_string())), + }; + + let wit = crate::preview2::golem::agent::host::RpcError::from(error.clone()); + assert_eq!(RpcError::from(wit), error); + } } diff --git a/golem-worker-executor/src/services/worker.rs b/golem-worker-executor/src/services/worker.rs index fc1b43c27a..c05dd91460 100644 --- a/golem-worker-executor/src/services/worker.rs +++ b/golem-worker-executor/src/services/worker.rs @@ -2578,7 +2578,8 @@ mod tests { service .set_assignment_tracking(&owned_agent_id, &status) - .await; + .await + .unwrap(); assert_eq!( assignment_tracking_members(&key_value_storage, &owned_agent_id, number_of_shards) @@ -2599,7 +2600,8 @@ mod tests { service .set_assignment_tracking(&owned_agent_id, &status) - .await; + .await + .unwrap(); assert!( assignment_tracking_members(&key_value_storage, &owned_agent_id, number_of_shards) diff --git a/golem-worker-executor/src/worker/agent_config.rs b/golem-worker-executor/src/worker/agent_config.rs index 2899379d10..6a5cd1b0ec 100644 --- a/golem-worker-executor/src/worker/agent_config.rs +++ b/golem-worker-executor/src/worker/agent_config.rs @@ -16,12 +16,12 @@ use golem_common::model::agent::{AgentConfigSource, ParsedAgentId}; use golem_common::model::agent_secret::CanonicalAgentSecretPath; use golem_common::model::worker::{AgentConfigEntryDto, TypedAgentConfigEntry}; use golem_common::schema::agent::typed_schema_value_with_projected_defs; -use golem_common::schema::render::from_untrusted_json_value; use golem_common::schema::schema_type::SecretSpec; use golem_common::schema::validation::{is_equivalent_cross_graph, validate_value}; use golem_common::schema::{ AgentTypeSchema, SchemaGraph, SchemaType, SchemaValue, TypedSchemaValue, }; +use golem_schema::schema::render::from_untrusted_json_value; use golem_service_base::error::worker_executor::WorkerExecutorError; use golem_service_base::model::agent_secret::AgentSecret; use golem_service_base::model::component::Component; diff --git a/golem-worker-executor/src/workerctx/default.rs b/golem-worker-executor/src/workerctx/default.rs index c64829217e..7f72230cd2 100644 --- a/golem-worker-executor/src/workerctx/default.rs +++ b/golem-worker-executor/src/workerctx/default.rs @@ -708,6 +708,20 @@ impl HostWasmRpc for Context { .await } + async fn create( + &mut self, + agent_type_name: String, + constructor: golem_schema::schema::wit::wire::SchemaValueTree, + phantom_id: Option, + config: Vec< + golem_common::schema::agent::bindings::golem::agent::common::TypedAgentConfigValue, + >, + ) -> anyhow::Result, RpcError>> { + self.durable_ctx + .create(agent_type_name, constructor, phantom_id, config) + .await + } + async fn invoke_and_await( &mut self, self_: Resource, @@ -809,6 +823,15 @@ impl AgentHost for Context { AgentHost::get_agent_type(&mut self.durable_ctx, agent_type_name).await } + async fn get_agent_type_by_agent_id( + &mut self, + agent_id: String, + ) -> anyhow::Result< + Option, + > { + AgentHost::get_agent_type_by_agent_id(&mut self.durable_ctx, agent_id).await + } + async fn make_agent_id( &mut self, agent_type_name: String, diff --git a/golem-worker-executor/tests/rpc.rs b/golem-worker-executor/tests/rpc.rs index 8b7b858bb9..ae2ada1b6e 100644 --- a/golem-worker-executor/tests/rpc.rs +++ b/golem-worker-executor/tests/rpc.rs @@ -2604,6 +2604,60 @@ async fn rust_rpc_missing_target( .contains("Agent type not registered") ); + let oplog = executor + .get_oplog(&parent, golem_common::model::oplog::OplogIndex::INITIAL) + .await?; + assert!(oplog.iter().any(|entry| matches!( + entry.entry, + golem_common::model::oplog::PublicOplogEntry::Error(_) + ))); + + Ok(()) +} + +#[test] +#[tracing::instrument] +async fn rust_rpc_missing_target_is_recoverable_with_fallible_create( + last_unique_id: &LastUniqueId, + deps: &WorkerExecutorTestDependencies, + #[tagged_as("agent_rpc_rust")] agent_rpc_rust: &PrecompiledComponent, + _tracing: &Tracing, +) -> anyhow::Result<()> { + let context = TestContext::new(last_unique_id); + let executor = start(deps, &context).await?; + + let component = executor + .component_dep(&context.default_environment_id, agent_rpc_rust) + .store() + .await?; + + let parent_agent_id = agent_id!("RustParent", "fallible-create-missing-target"); + let parent = executor + .start_agent(&component.id, parent_agent_id.clone()) + .await?; + + let result = executor + .invoke_and_await_agent( + &component, + &parent_agent_id, + "inspect_missing_rpc_type", + data_value!(), + ) + .await? + .into_typed::()?; + + assert!(result.contains("RemoteAgentError")); + assert!(result.contains("InvalidType")); + assert!(result.contains("MissingReflectedType")); + + let oplog = executor + .get_oplog(&parent, golem_common::model::oplog::OplogIndex::INITIAL) + .await?; + assert!(oplog.iter().all(|entry| !matches!( + entry.entry, + golem_common::model::oplog::PublicOplogEntry::Error(_) + ))); + Ok(()) } @@ -3431,6 +3485,185 @@ async fn ts_abort_after_complete_is_noop( Ok(()) } +#[test] +#[timeout("60s")] +#[tracing::instrument] +async fn ts_ephemeral_final_identity_cannot_be_reused( + last_unique_id: &LastUniqueId, + deps: &WorkerExecutorTestDependencies, + #[tagged_as("agent_rpc")] agent_rpc: &PrecompiledComponent, + _tracing: &Tracing, +) -> anyhow::Result<()> { + let context = TestContext::new(last_unique_id); + let executor = start(deps, &context).await?; + let component = executor + .component_dep(&context.default_environment_id, agent_rpc) + .store() + .await?; + let agent_id = agent_id!("TestAgent", "ts_ephemeral_final_identity_cannot_be_reused"); + + let report = executor + .invoke_and_await_agent(&component, &agent_id, "ephemeralReuseTest", data_value!()) + .await? + .into_return_value() + .expect("expected an ephemeral reuse report"); + let SchemaValue::Record { fields } = report else { + panic!("expected an ephemeral reuse report record"); + }; + let [ + value, + final_agent_id, + idempotency_key, + category, + error_tag, + details, + ] = fields.as_slice() + else { + panic!("expected six fields in the ephemeral reuse report"); + }; + + assert_eq!(value, &SchemaValue::String("captured".to_string())); + assert!( + matches!(final_agent_id, SchemaValue::String(value) if !value.is_empty()), + "final ephemeral agent ID must be non-empty" + ); + assert!( + matches!(idempotency_key, SchemaValue::String(value) if !value.is_empty()), + "ephemeral invocation idempotency key must be non-empty" + ); + assert_eq!( + category, + &SchemaValue::String("remote-agent-error".to_string()) + ); + assert_eq!(error_tag, &SchemaValue::String("invalid-input".to_string())); + assert!( + matches!(details, SchemaValue::String(value) if value.contains("An ephemeral agent cannot accept another invocation or be resumed")), + "unexpected ephemeral reuse details: {details:?}" + ); + + Ok(()) +} + +#[test] +#[timeout("60s")] +#[tracing::instrument] +async fn ts_reflection_discovers_binds_and_invokes_durable_agent( + last_unique_id: &LastUniqueId, + deps: &WorkerExecutorTestDependencies, + #[tagged_as("agent_rpc")] agent_rpc: &PrecompiledComponent, + #[tagged_as("agent_rpc_rust")] agent_rpc_rust: &PrecompiledComponent, + _tracing: &Tracing, +) -> anyhow::Result<()> { + let context = TestContext::new(last_unique_id); + let executor = start(deps, &context).await?; + let component = executor + .component_dep(&context.default_environment_id, agent_rpc) + .store() + .await?; + let target_component = executor + .component_dep(&context.default_environment_id, agent_rpc_rust) + .store() + .await?; + assert_ne!(component.id, target_component.id); + let agent_id = agent_id!( + "TestAgent", + "ts_reflection_discovers_binds_and_invokes_durable_agent" + ); + + let report = executor + .invoke_and_await_agent( + &component, + &agent_id, + "reflectionDiscoveryTest", + data_value!(), + ) + .await? + .into_return_value() + .expect("expected a reflection discovery report"); + let SchemaValue::Record { fields } = report else { + panic!("expected a reflection discovery report record"); + }; + let [ + listed, + type_name, + method_name, + first_value, + second_value, + missing_name, + missing_id, + ] = fields.as_slice() + else { + panic!("expected seven fields in the reflection discovery report"); + }; + + assert_eq!(listed, &SchemaValue::Bool(true)); + assert_eq!(type_name, &SchemaValue::String("Counter".to_string())); + assert_eq!(method_name, &SchemaValue::String("get_value".to_string())); + assert_eq!( + first_value, + &SchemaValue::String( + "counter-reflection-ts_reflection_discovers_binds_and_invokes_durable_agent" + .to_string() + ) + ); + assert_eq!(second_value, first_value); + assert_eq!(missing_name, &SchemaValue::Bool(true)); + assert_eq!(missing_id, &SchemaValue::Bool(true)); + + Ok(()) +} + +#[test] +#[timeout("60s")] +#[tracing::instrument] +async fn ts_reflected_ephemeral_invocation_returns_final_metadata( + last_unique_id: &LastUniqueId, + deps: &WorkerExecutorTestDependencies, + #[tagged_as("agent_rpc")] agent_rpc: &PrecompiledComponent, + _tracing: &Tracing, +) -> anyhow::Result<()> { + let context = TestContext::new(last_unique_id); + let executor = start(deps, &context).await?; + let component = executor + .component_dep(&context.default_environment_id, agent_rpc) + .store() + .await?; + let agent_id = agent_id!( + "TestAgent", + "ts_reflected_ephemeral_invocation_returns_final_metadata" + ); + + let report = executor + .invoke_and_await_agent( + &component, + &agent_id, + "reflectedEphemeralTest", + data_value!(), + ) + .await? + .into_return_value() + .expect("expected a reflected ephemeral report"); + let SchemaValue::Record { fields } = report else { + panic!("expected a reflected ephemeral report record"); + }; + let [value, final_agent_id, idempotency_key, proxy_has_agent_id] = fields.as_slice() else { + panic!("expected four fields in the reflected ephemeral report"); + }; + + assert_eq!(value, &SchemaValue::String("reflected".to_string())); + assert!( + matches!(final_agent_id, SchemaValue::String(value) if !value.is_empty()), + "final reflected ephemeral agent ID must be non-empty" + ); + assert!( + matches!(idempotency_key, SchemaValue::String(value) if !value.is_empty()), + "reflected ephemeral idempotency key must be non-empty" + ); + assert_eq!(proxy_has_agent_id, &SchemaValue::Bool(false)); + + Ok(()) +} + fn extract_oplog_idx_from_promise_id(promise_id_value: &SchemaValue) -> OplogIndex { let SchemaValue::Record { fields } = promise_id_value else { panic!("Expected a record for PromiseId"); diff --git a/golem-worker-service/Cargo.toml b/golem-worker-service/Cargo.toml index fdbc62176c..16cf17b9ae 100644 --- a/golem-worker-service/Cargo.toml +++ b/golem-worker-service/Cargo.toml @@ -37,6 +37,7 @@ harness = false [dependencies] golem-api-grpc = { workspace = true } golem-common = { workspace = true, default-features = true } +golem-schema = { workspace = true } golem-service-base = { workspace = true } anyhow = { workspace = true } diff --git a/golem-worker-service/src/custom_api/openapi/schema_mapping.rs b/golem-worker-service/src/custom_api/openapi/schema_mapping.rs index 085d870dad..c1d0b19a86 100644 --- a/golem-worker-service/src/custom_api/openapi/schema_mapping.rs +++ b/golem-worker-service/src/custom_api/openapi/schema_mapping.rs @@ -18,10 +18,10 @@ //! entries, and provides the handful of fixed JSON schemas the emitter needs. use golem_common::schema::graph::SchemaGraph; -use golem_common::schema::render::{ +use golem_common::schema::schema_type::SchemaType; +use golem_schema::schema::render::{ to_external_input_openapi_components, to_external_output_openapi_components, }; -use golem_common::schema::schema_type::SchemaType; use serde_json::{Map, Value, json}; /// Render a schema for an untrusted external request. Host-managed capability diff --git a/golem-worker-service/src/custom_api/request_handler.rs b/golem-worker-service/src/custom_api/request_handler.rs index 76f4578a93..ea723376bf 100644 --- a/golem-worker-service/src/custom_api/request_handler.rs +++ b/golem-worker-service/src/custom_api/request_handler.rs @@ -23,7 +23,7 @@ use super::webhooks::WebhookCallbackHandler; use super::{OidcCallbackBehaviour, ResponseBody, RouteExecutionResult}; use crate::custom_api::RichRequest; use anyhow::anyhow; -use golem_common::schema::render::json_value::to_json_value_redacted; +use golem_schema::schema::render::json_value::to_json_value_redacted; use golem_service_base::custom_api::OpenApiSpecBehaviour; use golem_service_base::custom_api::OpenApiSpecFormat; use http::StatusCode; diff --git a/golem-worker-service/src/custom_api/rich_request.rs b/golem-worker-service/src/custom_api/rich_request.rs index 250e4b93a3..7c303e2540 100644 --- a/golem-worker-service/src/custom_api/rich_request.rs +++ b/golem-worker-service/src/custom_api/rich_request.rs @@ -22,8 +22,8 @@ use golem_common::model::invocation_context::{ }; use golem_common::model::{IdempotencyKey, invocation_context}; use golem_common::schema::SchemaGraph; -use golem_common::schema::render::from_untrusted_json_value; use golem_common::schema::unstructured::{binary_body_restrictions, text_body_restrictions}; +use golem_schema::schema::render::from_untrusted_json_value; use golem_service_base::custom_api::RequestBodySchema; use golem_service_base::headers::TraceContextHeaders; use http::HeaderMap; diff --git a/golem-worker-service/src/mcp/invoke/agent_method_input.rs b/golem-worker-service/src/mcp/invoke/agent_method_input.rs index 78b97ae03a..6f38e2d463 100644 --- a/golem-worker-service/src/mcp/invoke/agent_method_input.rs +++ b/golem-worker-service/src/mcp/invoke/agent_method_input.rs @@ -17,9 +17,9 @@ use crate::mcp::invoke::{schema_binary_value_from_json, schema_text_value_from_j use golem_common::schema::agent::{FieldSource, InputSchema, NamedField}; use golem_common::schema::graph::SchemaGraph; use golem_common::schema::multimodal::multimodal_variant_cases; -use golem_common::schema::render::json_value::from_untrusted_json_value; use golem_common::schema::schema_type::{SchemaType, VariantCaseType}; use golem_common::schema::schema_value::{SchemaValue, VariantValuePayload}; +use golem_schema::schema::render::json_value::from_untrusted_json_value; use rmcp::model::JsonObject; use std::collections::HashMap; diff --git a/golem-worker-service/src/mcp/invoke/constructor_param_extraction.rs b/golem-worker-service/src/mcp/invoke/constructor_param_extraction.rs index c46302627d..e779266652 100644 --- a/golem-worker-service/src/mcp/invoke/constructor_param_extraction.rs +++ b/golem-worker-service/src/mcp/invoke/constructor_param_extraction.rs @@ -16,9 +16,9 @@ use golem_common::schema::agent::{FieldSource, InputSchema, NamedField}; use golem_common::schema::graph::SchemaGraph; use golem_common::schema::host_managed::find_host_managed_type; use golem_common::schema::multimodal::multimodal_variant_cases; -use golem_common::schema::render::json_value::from_untrusted_json_value; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::schema_value::SchemaValue; +use golem_schema::schema::render::json_value::from_untrusted_json_value; /// Validate that a constructor [`InputSchema`] can be supplied through MCP, /// without requiring actual argument values. This mirrors the structural rules diff --git a/golem-worker-service/src/mcp/invoke/mod.rs b/golem-worker-service/src/mcp/invoke/mod.rs index ef65fb17f4..b9cd76eb68 100644 --- a/golem-worker-service/src/mcp/invoke/mod.rs +++ b/golem-worker-service/src/mcp/invoke/mod.rs @@ -130,8 +130,8 @@ mod codec_tests { use golem_common::schema::graph::SchemaGraph; use golem_common::schema::metadata::MetadataEnvelope; - use golem_common::schema::render::json_value::{from_json_value, to_json_value}; use golem_common::schema::schema_type::{NamedFieldType, SchemaType, VariantCaseType}; + use golem_schema::schema::render::json_value::{from_json_value, to_json_value}; use serde_json::json; use test_r::test; diff --git a/golem-worker-service/src/mcp/invoke/multimodal_params_extraction.rs b/golem-worker-service/src/mcp/invoke/multimodal_params_extraction.rs index ed44abf68b..da884b8505 100644 --- a/golem-worker-service/src/mcp/invoke/multimodal_params_extraction.rs +++ b/golem-worker-service/src/mcp/invoke/multimodal_params_extraction.rs @@ -14,9 +14,9 @@ use crate::mcp::invoke::{schema_binary_value_from_json, schema_text_value_from_json}; use golem_common::schema::graph::SchemaGraph; -use golem_common::schema::render::json_value::from_untrusted_json_value; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::schema_value::SchemaValue; +use golem_schema::schema::render::json_value::from_untrusted_json_value; /// Extract a single multimodal part value, typed by the multimodal variant /// case's payload schema (resolved against `graph`). diff --git a/golem-worker-service/src/mcp/invoke/resource.rs b/golem-worker-service/src/mcp/invoke/resource.rs index e604405dc8..181fff0e4c 100644 --- a/golem-worker-service/src/mcp/invoke/resource.rs +++ b/golem-worker-service/src/mcp/invoke/resource.rs @@ -23,12 +23,12 @@ use golem_common::model::agent::ParsedAgentId; use golem_common::schema::agent::OutputSchema; use golem_common::schema::graph::SchemaGraph; use golem_common::schema::multimodal::multimodal_variant_cases; -use golem_common::schema::render::json_value::to_json_value_redacted; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::schema_value::{ BinaryValuePayload, SchemaValue, TextValuePayload, VariantValuePayload, }; use golem_common::schema::unstructured::{UnstructuredOutput, decode_unstructured_output}; +use golem_schema::schema::render::json_value::to_json_value_redacted; use rmcp::ErrorData; use rmcp::model::{JsonObject, ReadResourceResult, ResourceContents}; use std::sync::Arc; diff --git a/golem-worker-service/src/mcp/invoke/tool.rs b/golem-worker-service/src/mcp/invoke/tool.rs index b04d49b9b7..d559723fce 100644 --- a/golem-worker-service/src/mcp/invoke/tool.rs +++ b/golem-worker-service/src/mcp/invoke/tool.rs @@ -26,12 +26,12 @@ use golem_common::schema::FALLBACK_OUTPUT_FIELD_NAME; use golem_common::schema::agent::OutputSchema; use golem_common::schema::graph::SchemaGraph; use golem_common::schema::multimodal::multimodal_variant_cases; -use golem_common::schema::render::json_value::to_json_value_redacted; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::schema_value::{ BinaryValuePayload, SchemaValue, TextValuePayload, VariantValuePayload, }; use golem_common::schema::unstructured::{UnstructuredOutput, decode_unstructured_output}; +use golem_schema::schema::render::json_value::to_json_value_redacted; use rmcp::ErrorData; use rmcp::model::{ AnnotateAble, CallToolResult, Content, JsonObject, RawAudioContent, RawContent, diff --git a/golem-worker-service/src/mcp/schema/mcp_tool_schema.rs b/golem-worker-service/src/mcp/schema/mcp_tool_schema.rs index f4b23f11f8..ee52345247 100644 --- a/golem-worker-service/src/mcp/schema/mcp_tool_schema.rs +++ b/golem-worker-service/src/mcp/schema/mcp_tool_schema.rs @@ -30,11 +30,10 @@ use golem_common::schema::agent::{ }; use golem_common::schema::graph::SchemaGraph; use golem_common::schema::multimodal::is_multimodal_schema_type; -use golem_common::schema::render::{ - JsonSchemaConfig, input_schema_to_json_schema, output_schema_to_json_schema, -}; +use golem_common::schema::render::{input_schema_to_json_schema, output_schema_to_json_schema}; use golem_common::schema::schema_type::SchemaType; use golem_common::schema::unstructured::unstructured_or_raw_kind; +use golem_schema::schema::render::JsonSchemaConfig; use rmcp::model::JsonObject; use serde_json::{Value, json}; diff --git a/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/guest/ffi.mbt b/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/guest/ffi.mbt index cb02ed24a4..6bad447cdc 100644 --- a/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/guest/ffi.mbt +++ b/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/guest/ffi.mbt @@ -20,7 +20,7 @@ pub fn wasmExportDiscoverTools() -> Int { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Tool = (payload)[(index)] let iter_base = address + (index * 36); - __wit_bindgen_lower_t527((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t528((iter_base) + 0, iter_elem) } mbt_ffi_store32((return_area) + 8, (payload).length()) @@ -30,7 +30,7 @@ pub fn wasmExportDiscoverTools() -> Int { } Err(payload0) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload0) + __wit_bindgen_lower_t533((return_area) + 4, payload0) () } @@ -3279,13 +3279,13 @@ pub fn wasmExportGetTool(p0 : Int, p1 : Int) -> Int { match result0 { Ok(payload) => { mbt_ffi_store8((return_area) + 0, (0)) - __wit_bindgen_lower_t527((return_area) + 4, payload) + __wit_bindgen_lower_t528((return_area) + 4, payload) () } Err(payload1) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload1) + __wit_bindgen_lower_t533((return_area) + 4, payload1) () } @@ -10930,7 +10930,7 @@ fn __wit_bindgen_lower_t79(ptr : Int, value : @types.TypedSchemaValue) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Unit { +fn __wit_bindgen_lower_t475(ptr : Int, value : @common.CommandAnnotations) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).read_only { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).destructive { 1 } else { 0 })) mbt_ffi_store8((ptr) + 2, (if (value).idempotent { 1 } else { 0 })) @@ -10940,7 +10940,7 @@ fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { +fn __wit_bindgen_lower_t477(ptr : Int, value : @common.Repetition) -> Unit { match value { Repeated => { @@ -10966,16 +10966,16 @@ fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t477(ptr : Int, value : @common.RepeatableListShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableListShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).item_type) } ///| #doc(hidden) -fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t479(ptr : Int, value : @common.RepeatableMapShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).map_type) mbt_ffi_store8((ptr) + 12, (value).duplicate_key_policy.ordinal()) @@ -10983,7 +10983,7 @@ fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { +fn __wit_bindgen_lower_t480(ptr : Int, value : @common.OptionShape) -> Unit { match value { Scalar(payload) => { @@ -11000,13 +11000,13 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { } RepeatableList(payload1) => { mbt_ffi_store8((ptr) + 0, (2)) - __wit_bindgen_lower_t477((ptr) + 4, payload1) + __wit_bindgen_lower_t478((ptr) + 4, payload1) () } RepeatableMap(payload2) => { mbt_ffi_store8((ptr) + 0, (3)) - __wit_bindgen_lower_t478((ptr) + 4, payload2) + __wit_bindgen_lower_t479((ptr) + 4, payload2) () } @@ -11016,7 +11016,7 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { +fn __wit_bindgen_lower_t481(ptr : Int, value : @common.BoolFlagShape) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).default { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).negatable { 1 } else { 0 })) @@ -11024,12 +11024,12 @@ fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { +fn __wit_bindgen_lower_t483(ptr : Int, value : @common.FlagShape) -> Unit { match value { BoolFlag(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t480((ptr) + 4, payload) + __wit_bindgen_lower_t481((ptr) + 4, payload) () } @@ -11058,7 +11058,7 @@ fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { +fn __wit_bindgen_lower_t484(ptr : Int, value : @common.ValueIsRef) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -11069,7 +11069,7 @@ fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { +fn __wit_bindgen_lower_t485(ptr : Int, value : @common.Ref) -> Unit { match value { Present(payload) => { @@ -11083,7 +11083,7 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { } ValueIs(payload1) => { mbt_ffi_store8((ptr) + 0, (1)) - __wit_bindgen_lower_t483((ptr) + 4, payload1) + __wit_bindgen_lower_t484((ptr) + 4, payload1) () } @@ -11093,13 +11093,13 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { +fn __wit_bindgen_lower_t487(ptr : Int, value : @common.RefGroup) -> Unit { let address = mbt_ffi_malloc(((value).refs).length() * 24); for index = 0; index < ((value).refs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).refs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).refs).length()) @@ -11109,14 +11109,14 @@ fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { +fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ImpliesC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -11127,7 +11127,7 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).rhs).length()) @@ -11137,14 +11137,14 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { +fn __wit_bindgen_lower_t490(ptr : Int, value : @common.ForbidsC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -11154,7 +11154,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 16, ((value).rhs).length()) @@ -11164,7 +11164,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { +fn __wit_bindgen_lower_t492(ptr : Int, value : @common.Constraint) -> Unit { match value { RequiresAll(payload) => { @@ -11174,7 +11174,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Ref = (payload)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload).length()) @@ -11189,7 +11189,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index2 = 0; index2 < (payload0).length(); index2 = index2 + 1 { let iter_elem : @common.Ref = (payload0)[(index2)] let iter_base = address1 + (index2 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload0).length()) @@ -11204,7 +11204,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index5 = 0; index5 < (payload3).length(); index5 = index5 + 1 { let iter_elem : @common.Ref = (payload3)[(index5)] let iter_base = address4 + (index5 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload3).length()) @@ -11219,7 +11219,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index8 = 0; index8 < (payload6).length(); index8 = index8 + 1 { let iter_elem : @common.RefGroup = (payload6)[(index8)] let iter_base = address7 + (index8 * 8); - __wit_bindgen_lower_t486((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t487((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload6).length()) @@ -11229,13 +11229,13 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { } Implies(payload9) => { mbt_ffi_store8((ptr) + 0, (4)) - __wit_bindgen_lower_t488((ptr) + 4, payload9) + __wit_bindgen_lower_t489((ptr) + 4, payload9) () } Forbids(payload10) => { mbt_ffi_store8((ptr) + 0, (5)) - __wit_bindgen_lower_t489((ptr) + 4, payload10) + __wit_bindgen_lower_t490((ptr) + 4, payload10) () } @@ -11245,7 +11245,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { +fn __wit_bindgen_lower_t494(ptr : Int, value : @common.Example) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).title) mbt_ffi_store32((ptr) + 4, (value).title.length()) @@ -11259,7 +11259,7 @@ fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { +fn __wit_bindgen_lower_t496(ptr : Int, value : @common.Doc) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).summary) mbt_ffi_store32((ptr) + 4, (value).summary.length()) @@ -11273,7 +11273,7 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { for index = 0; index < ((value).examples).length(); index = index + 1 { let iter_elem : @common.Example = ((value).examples)[(index)] let iter_base = address + (index * 16); - __wit_bindgen_lower_t493((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t494((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).examples).length()) @@ -11283,12 +11283,12 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { +fn __wit_bindgen_lower_t499(ptr : Int, value : @common.Positional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -11328,12 +11328,12 @@ fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { +fn __wit_bindgen_lower_t500(ptr : Int, value : @common.TailPositional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -11391,13 +11391,13 @@ fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { +fn __wit_bindgen_lower_t503(ptr : Int, value : @common.Positionals) -> Unit { let address = mbt_ffi_malloc(((value).fixed).length() * 68); for index = 0; index < ((value).fixed).length(); index = index + 1 { let iter_elem : @common.Positional = ((value).fixed)[(index)] let iter_base = address + (index * 68); - __wit_bindgen_lower_t498((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t499((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).fixed).length()) @@ -11411,7 +11411,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { } Some(payload0) => { mbt_ffi_store8((ptr) + 8, (1)) - __wit_bindgen_lower_t499((ptr) + 12, payload0) + __wit_bindgen_lower_t500((ptr) + 12, payload0) () } @@ -11421,7 +11421,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { +fn __wit_bindgen_lower_t506(ptr : Int, value : @common.OptionSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -11453,7 +11453,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) match ((value).value_name) { None => { @@ -11471,7 +11471,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { () } } - __wit_bindgen_lower_t479((ptr) + 60, (value).shape) + __wit_bindgen_lower_t480((ptr) + 60, (value).shape) match ((value).default) { None => { @@ -11509,7 +11509,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { +fn __wit_bindgen_lower_t507(ptr : Int, value : @common.FlagSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -11541,8 +11541,8 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) - __wit_bindgen_lower_t482((ptr) + 48, (value).shape) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) + __wit_bindgen_lower_t483((ptr) + 48, (value).shape) match ((value).env_var) { None => { @@ -11565,13 +11565,13 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { +fn __wit_bindgen_lower_t510(ptr : Int, value : @common.Globals) -> Unit { let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).options).length()) @@ -11581,7 +11581,7 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 12, ((value).flags).length()) @@ -11591,8 +11591,8 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { - __wit_bindgen_lower_t495((ptr) + 0, (value).doc) +fn __wit_bindgen_lower_t511(ptr : Int, value : @common.StreamSpec) -> Unit { + __wit_bindgen_lower_t496((ptr) + 0, (value).doc) let address = mbt_ffi_malloc(((value).mime).length() * 8); for index = 0; index < ((value).mime).length(); index = index + 1 { @@ -11612,26 +11612,26 @@ fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t511(ptr : Int, value : @common.Formatter) -> Unit { +fn __wit_bindgen_lower_t512(ptr : Int, value : @common.Formatter) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) } ///| #doc(hidden) -fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { +fn __wit_bindgen_lower_t514(ptr : Int, value : @common.ResultSpec) -> Unit { mbt_ffi_store32((ptr) + 0, (value).type_) - __wit_bindgen_lower_t495((ptr) + 4, (value).doc) + __wit_bindgen_lower_t496((ptr) + 4, (value).doc) let address = mbt_ffi_malloc(((value).formatters).length() * 32); for index = 0; index < ((value).formatters).length(); index = index + 1 { let iter_elem : @common.Formatter = ((value).formatters)[(index)] let iter_base = address + (index * 32); - __wit_bindgen_lower_t511((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t512((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 32, ((value).formatters).length()) @@ -11645,12 +11645,12 @@ fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { +fn __wit_bindgen_lower_t516(ptr : Int, value : @common.ErrorCase) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) mbt_ffi_store8((ptr) + 32, (value).kind.ordinal()) mbt_ffi_store8((ptr) + 33, ((value).exit_code).to_int()) @@ -11672,14 +11672,14 @@ fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { - __wit_bindgen_lower_t502((ptr) + 0, (value).positionals) +fn __wit_bindgen_lower_t522(ptr : Int, value : @common.CommandBody) -> Unit { + __wit_bindgen_lower_t503((ptr) + 0, (value).positionals) let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 92, ((value).options).length()) @@ -11689,7 +11689,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 100, ((value).flags).length()) @@ -11699,7 +11699,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index3 = 0; index3 < ((value).constraints).length(); index3 = index3 + 1 { let iter_elem : @common.Constraint = ((value).constraints)[(index3)] let iter_base = address2 + (index3 * 28); - __wit_bindgen_lower_t491((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t492((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 108, ((value).constraints).length()) @@ -11713,7 +11713,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 112, (1)) - __wit_bindgen_lower_t510((ptr) + 116, payload4) + __wit_bindgen_lower_t511((ptr) + 116, payload4) () } @@ -11727,7 +11727,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload6) => { mbt_ffi_store8((ptr) + 152, (1)) - __wit_bindgen_lower_t510((ptr) + 156, payload6) + __wit_bindgen_lower_t511((ptr) + 156, payload6) () } @@ -11741,7 +11741,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload8) => { mbt_ffi_store8((ptr) + 192, (1)) - __wit_bindgen_lower_t513((ptr) + 196, payload8) + __wit_bindgen_lower_t514((ptr) + 196, payload8) () } @@ -11751,7 +11751,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index10 = 0; index10 < ((value).errors).length(); index10 = index10 + 1 { let iter_elem : @common.ErrorCase = ((value).errors)[(index10)] let iter_base = address9 + (index10 * 44); - __wit_bindgen_lower_t515((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t516((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 244, ((value).errors).length()) @@ -11765,7 +11765,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload12) => { mbt_ffi_store8((ptr) + 248, (1)) - __wit_bindgen_lower_t474((ptr) + 249, payload12) + __wit_bindgen_lower_t475((ptr) + 249, payload12) () } @@ -11775,7 +11775,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { +fn __wit_bindgen_lower_t525(ptr : Int, value : @common.CommandNode) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -11793,8 +11793,8 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t509((ptr) + 40, (value).globals) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t510((ptr) + 40, (value).globals) let address2 = mbt_ffi_malloc(((value).subcommands).length() * 4); for index3 = 0; index3 < ((value).subcommands).length(); index3 = index3 + 1 { @@ -11814,7 +11814,7 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 64, (1)) - __wit_bindgen_lower_t521((ptr) + 68, payload4) + __wit_bindgen_lower_t522((ptr) + 68, payload4) () } @@ -11824,13 +11824,13 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { +fn __wit_bindgen_lower_t527(ptr : Int, value : @common.CommandTree) -> Unit { let address = mbt_ffi_malloc(((value).nodes).length() * 324); for index = 0; index < ((value).nodes).length(); index = index + 1 { let iter_elem : @common.CommandNode = ((value).nodes)[(index)] let iter_base = address + (index * 324); - __wit_bindgen_lower_t524((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t525((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).nodes).length()) @@ -11840,19 +11840,19 @@ fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t527(ptr : Int, value : @common.Tool) -> Unit { +fn __wit_bindgen_lower_t528(ptr : Int, value : @common.Tool) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).version) mbt_ffi_store32((ptr) + 4, (value).version.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t526((ptr) + 8, (value).commands) + __wit_bindgen_lower_t527((ptr) + 8, (value).commands) __wit_bindgen_lower_t59((ptr) + 16, (value).schema) } ///| #doc(hidden) -fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolError) -> Unit { +fn __wit_bindgen_lower_t533(ptr : Int, value : @common.ToolError) -> Unit { match value { InvalidToolName(payload) => { diff --git a/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt b/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt index 260d4756cd..bf2095f977 100644 --- a/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt +++ b/sdks/moonbit/golem_sdk/gen-agent-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt @@ -20,7 +20,7 @@ pub fn wasmExportDiscoverToolMiddlewares() -> Int { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.ToolMiddleware = (payload)[(index)] let iter_base = address + (index * 120); - __wit_bindgen_lower_t531((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t532((iter_base) + 0, iter_elem) } mbt_ffi_store32((return_area) + 8, (payload).length()) @@ -30,7 +30,7 @@ pub fn wasmExportDiscoverToolMiddlewares() -> Int { } Err(payload0) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload0) + __wit_bindgen_lower_t533((return_area) + 4, payload0) () } @@ -5686,13 +5686,13 @@ pub fn wasmExportGetToolMiddleware(p0 : Int, p1 : Int) -> Int { match result0 { Ok(payload) => { mbt_ffi_store8((return_area) + 0, (0)) - __wit_bindgen_lower_t531((return_area) + 4, payload) + __wit_bindgen_lower_t532((return_area) + 4, payload) () } Err(payload1) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload1) + __wit_bindgen_lower_t533((return_area) + 4, payload1) () } @@ -21343,7 +21343,7 @@ fn __wit_bindgen_lower_t79(ptr : Int, value : @types.TypedSchemaValue) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Unit { +fn __wit_bindgen_lower_t475(ptr : Int, value : @common.CommandAnnotations) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).read_only { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).destructive { 1 } else { 0 })) mbt_ffi_store8((ptr) + 2, (if (value).idempotent { 1 } else { 0 })) @@ -21353,7 +21353,7 @@ fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { +fn __wit_bindgen_lower_t477(ptr : Int, value : @common.Repetition) -> Unit { match value { Repeated => { @@ -21379,16 +21379,16 @@ fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t477(ptr : Int, value : @common.RepeatableListShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableListShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).item_type) } ///| #doc(hidden) -fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t479(ptr : Int, value : @common.RepeatableMapShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).map_type) mbt_ffi_store8((ptr) + 12, (value).duplicate_key_policy.ordinal()) @@ -21396,7 +21396,7 @@ fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { +fn __wit_bindgen_lower_t480(ptr : Int, value : @common.OptionShape) -> Unit { match value { Scalar(payload) => { @@ -21413,13 +21413,13 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { } RepeatableList(payload1) => { mbt_ffi_store8((ptr) + 0, (2)) - __wit_bindgen_lower_t477((ptr) + 4, payload1) + __wit_bindgen_lower_t478((ptr) + 4, payload1) () } RepeatableMap(payload2) => { mbt_ffi_store8((ptr) + 0, (3)) - __wit_bindgen_lower_t478((ptr) + 4, payload2) + __wit_bindgen_lower_t479((ptr) + 4, payload2) () } @@ -21429,7 +21429,7 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { +fn __wit_bindgen_lower_t481(ptr : Int, value : @common.BoolFlagShape) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).default { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).negatable { 1 } else { 0 })) @@ -21437,12 +21437,12 @@ fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { +fn __wit_bindgen_lower_t483(ptr : Int, value : @common.FlagShape) -> Unit { match value { BoolFlag(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t480((ptr) + 4, payload) + __wit_bindgen_lower_t481((ptr) + 4, payload) () } @@ -21471,7 +21471,7 @@ fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { +fn __wit_bindgen_lower_t484(ptr : Int, value : @common.ValueIsRef) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -21482,7 +21482,7 @@ fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { +fn __wit_bindgen_lower_t485(ptr : Int, value : @common.Ref) -> Unit { match value { Present(payload) => { @@ -21496,7 +21496,7 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { } ValueIs(payload1) => { mbt_ffi_store8((ptr) + 0, (1)) - __wit_bindgen_lower_t483((ptr) + 4, payload1) + __wit_bindgen_lower_t484((ptr) + 4, payload1) () } @@ -21506,13 +21506,13 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { +fn __wit_bindgen_lower_t487(ptr : Int, value : @common.RefGroup) -> Unit { let address = mbt_ffi_malloc(((value).refs).length() * 24); for index = 0; index < ((value).refs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).refs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).refs).length()) @@ -21522,14 +21522,14 @@ fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { +fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ImpliesC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -21540,7 +21540,7 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).rhs).length()) @@ -21550,14 +21550,14 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { +fn __wit_bindgen_lower_t490(ptr : Int, value : @common.ForbidsC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -21567,7 +21567,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 16, ((value).rhs).length()) @@ -21577,7 +21577,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { +fn __wit_bindgen_lower_t492(ptr : Int, value : @common.Constraint) -> Unit { match value { RequiresAll(payload) => { @@ -21587,7 +21587,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Ref = (payload)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload).length()) @@ -21602,7 +21602,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index2 = 0; index2 < (payload0).length(); index2 = index2 + 1 { let iter_elem : @common.Ref = (payload0)[(index2)] let iter_base = address1 + (index2 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload0).length()) @@ -21617,7 +21617,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index5 = 0; index5 < (payload3).length(); index5 = index5 + 1 { let iter_elem : @common.Ref = (payload3)[(index5)] let iter_base = address4 + (index5 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload3).length()) @@ -21632,7 +21632,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index8 = 0; index8 < (payload6).length(); index8 = index8 + 1 { let iter_elem : @common.RefGroup = (payload6)[(index8)] let iter_base = address7 + (index8 * 8); - __wit_bindgen_lower_t486((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t487((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload6).length()) @@ -21642,13 +21642,13 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { } Implies(payload9) => { mbt_ffi_store8((ptr) + 0, (4)) - __wit_bindgen_lower_t488((ptr) + 4, payload9) + __wit_bindgen_lower_t489((ptr) + 4, payload9) () } Forbids(payload10) => { mbt_ffi_store8((ptr) + 0, (5)) - __wit_bindgen_lower_t489((ptr) + 4, payload10) + __wit_bindgen_lower_t490((ptr) + 4, payload10) () } @@ -21658,7 +21658,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { +fn __wit_bindgen_lower_t494(ptr : Int, value : @common.Example) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).title) mbt_ffi_store32((ptr) + 4, (value).title.length()) @@ -21672,7 +21672,7 @@ fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { +fn __wit_bindgen_lower_t496(ptr : Int, value : @common.Doc) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).summary) mbt_ffi_store32((ptr) + 4, (value).summary.length()) @@ -21686,7 +21686,7 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { for index = 0; index < ((value).examples).length(); index = index + 1 { let iter_elem : @common.Example = ((value).examples)[(index)] let iter_base = address + (index * 16); - __wit_bindgen_lower_t493((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t494((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).examples).length()) @@ -21696,12 +21696,12 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { +fn __wit_bindgen_lower_t499(ptr : Int, value : @common.Positional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -21741,12 +21741,12 @@ fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { +fn __wit_bindgen_lower_t500(ptr : Int, value : @common.TailPositional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -21804,13 +21804,13 @@ fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { +fn __wit_bindgen_lower_t503(ptr : Int, value : @common.Positionals) -> Unit { let address = mbt_ffi_malloc(((value).fixed).length() * 68); for index = 0; index < ((value).fixed).length(); index = index + 1 { let iter_elem : @common.Positional = ((value).fixed)[(index)] let iter_base = address + (index * 68); - __wit_bindgen_lower_t498((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t499((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).fixed).length()) @@ -21824,7 +21824,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { } Some(payload0) => { mbt_ffi_store8((ptr) + 8, (1)) - __wit_bindgen_lower_t499((ptr) + 12, payload0) + __wit_bindgen_lower_t500((ptr) + 12, payload0) () } @@ -21834,7 +21834,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { +fn __wit_bindgen_lower_t506(ptr : Int, value : @common.OptionSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -21866,7 +21866,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) match ((value).value_name) { None => { @@ -21884,7 +21884,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { () } } - __wit_bindgen_lower_t479((ptr) + 60, (value).shape) + __wit_bindgen_lower_t480((ptr) + 60, (value).shape) match ((value).default) { None => { @@ -21922,7 +21922,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { +fn __wit_bindgen_lower_t507(ptr : Int, value : @common.FlagSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -21954,8 +21954,8 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) - __wit_bindgen_lower_t482((ptr) + 48, (value).shape) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) + __wit_bindgen_lower_t483((ptr) + 48, (value).shape) match ((value).env_var) { None => { @@ -21978,13 +21978,13 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { +fn __wit_bindgen_lower_t510(ptr : Int, value : @common.Globals) -> Unit { let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).options).length()) @@ -21994,7 +21994,7 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 12, ((value).flags).length()) @@ -22004,8 +22004,8 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { - __wit_bindgen_lower_t495((ptr) + 0, (value).doc) +fn __wit_bindgen_lower_t511(ptr : Int, value : @common.StreamSpec) -> Unit { + __wit_bindgen_lower_t496((ptr) + 0, (value).doc) let address = mbt_ffi_malloc(((value).mime).length() * 8); for index = 0; index < ((value).mime).length(); index = index + 1 { @@ -22025,26 +22025,26 @@ fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t511(ptr : Int, value : @common.Formatter) -> Unit { +fn __wit_bindgen_lower_t512(ptr : Int, value : @common.Formatter) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) } ///| #doc(hidden) -fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { +fn __wit_bindgen_lower_t514(ptr : Int, value : @common.ResultSpec) -> Unit { mbt_ffi_store32((ptr) + 0, (value).type_) - __wit_bindgen_lower_t495((ptr) + 4, (value).doc) + __wit_bindgen_lower_t496((ptr) + 4, (value).doc) let address = mbt_ffi_malloc(((value).formatters).length() * 32); for index = 0; index < ((value).formatters).length(); index = index + 1 { let iter_elem : @common.Formatter = ((value).formatters)[(index)] let iter_base = address + (index * 32); - __wit_bindgen_lower_t511((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t512((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 32, ((value).formatters).length()) @@ -22058,12 +22058,12 @@ fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { +fn __wit_bindgen_lower_t516(ptr : Int, value : @common.ErrorCase) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) mbt_ffi_store8((ptr) + 32, (value).kind.ordinal()) mbt_ffi_store8((ptr) + 33, ((value).exit_code).to_int()) @@ -22085,14 +22085,14 @@ fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { - __wit_bindgen_lower_t502((ptr) + 0, (value).positionals) +fn __wit_bindgen_lower_t522(ptr : Int, value : @common.CommandBody) -> Unit { + __wit_bindgen_lower_t503((ptr) + 0, (value).positionals) let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 92, ((value).options).length()) @@ -22102,7 +22102,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 100, ((value).flags).length()) @@ -22112,7 +22112,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index3 = 0; index3 < ((value).constraints).length(); index3 = index3 + 1 { let iter_elem : @common.Constraint = ((value).constraints)[(index3)] let iter_base = address2 + (index3 * 28); - __wit_bindgen_lower_t491((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t492((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 108, ((value).constraints).length()) @@ -22126,7 +22126,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 112, (1)) - __wit_bindgen_lower_t510((ptr) + 116, payload4) + __wit_bindgen_lower_t511((ptr) + 116, payload4) () } @@ -22140,7 +22140,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload6) => { mbt_ffi_store8((ptr) + 152, (1)) - __wit_bindgen_lower_t510((ptr) + 156, payload6) + __wit_bindgen_lower_t511((ptr) + 156, payload6) () } @@ -22154,7 +22154,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload8) => { mbt_ffi_store8((ptr) + 192, (1)) - __wit_bindgen_lower_t513((ptr) + 196, payload8) + __wit_bindgen_lower_t514((ptr) + 196, payload8) () } @@ -22164,7 +22164,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index10 = 0; index10 < ((value).errors).length(); index10 = index10 + 1 { let iter_elem : @common.ErrorCase = ((value).errors)[(index10)] let iter_base = address9 + (index10 * 44); - __wit_bindgen_lower_t515((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t516((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 244, ((value).errors).length()) @@ -22178,7 +22178,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload12) => { mbt_ffi_store8((ptr) + 248, (1)) - __wit_bindgen_lower_t474((ptr) + 249, payload12) + __wit_bindgen_lower_t475((ptr) + 249, payload12) () } @@ -22188,7 +22188,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { +fn __wit_bindgen_lower_t525(ptr : Int, value : @common.CommandNode) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -22206,8 +22206,8 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t509((ptr) + 40, (value).globals) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t510((ptr) + 40, (value).globals) let address2 = mbt_ffi_malloc(((value).subcommands).length() * 4); for index3 = 0; index3 < ((value).subcommands).length(); index3 = index3 + 1 { @@ -22227,7 +22227,7 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 64, (1)) - __wit_bindgen_lower_t521((ptr) + 68, payload4) + __wit_bindgen_lower_t522((ptr) + 68, payload4) () } @@ -22237,13 +22237,13 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { +fn __wit_bindgen_lower_t527(ptr : Int, value : @common.CommandTree) -> Unit { let address = mbt_ffi_malloc(((value).nodes).length() * 324); for index = 0; index < ((value).nodes).length(); index = index + 1 { let iter_elem : @common.CommandNode = ((value).nodes)[(index)] let iter_base = address + (index * 324); - __wit_bindgen_lower_t524((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t525((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).nodes).length()) @@ -22253,20 +22253,20 @@ fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t527(ptr : Int, value : @common.Tool) -> Unit { +fn __wit_bindgen_lower_t528(ptr : Int, value : @common.Tool) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).version) mbt_ffi_store32((ptr) + 4, (value).version.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t526((ptr) + 8, (value).commands) + __wit_bindgen_lower_t527((ptr) + 8, (value).commands) __wit_bindgen_lower_t59((ptr) + 16, (value).schema) } ///| #doc(hidden) -fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit { - __wit_bindgen_lower_t527((ptr) + 0, (value).presented) +fn __wit_bindgen_lower_t530(ptr : Int, value : @common.MonomorphicScope) -> Unit { + __wit_bindgen_lower_t528((ptr) + 0, (value).presented) match ((value).expected) { None => { @@ -22276,7 +22276,7 @@ fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit } Some(payload0) => { mbt_ffi_store8((ptr) + 36, (1)) - __wit_bindgen_lower_t527((ptr) + 40, payload0) + __wit_bindgen_lower_t528((ptr) + 40, payload0) () } @@ -22286,12 +22286,12 @@ fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit ///| #doc(hidden) -fn __wit_bindgen_lower_t530(ptr : Int, value : @common.ToolMiddlewareScope) -> Unit { +fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddlewareScope) -> Unit { match value { Monomorphic(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t529((ptr) + 4, payload) + __wit_bindgen_lower_t530((ptr) + 4, payload) () } @@ -22306,7 +22306,7 @@ fn __wit_bindgen_lower_t530(ptr : Int, value : @common.ToolMiddlewareScope) -> U ///| #doc(hidden) -fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddleware) -> Unit { +fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolMiddleware) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -22324,14 +22324,14 @@ fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddleware) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t530((ptr) + 40, (value).scope) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t531((ptr) + 40, (value).scope) } ///| #doc(hidden) -fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolError) -> Unit { +fn __wit_bindgen_lower_t533(ptr : Int, value : @common.ToolError) -> Unit { match value { InvalidToolName(payload) => { diff --git a/sdks/moonbit/golem_sdk/gen-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt b/sdks/moonbit/golem_sdk/gen-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt index 260d4756cd..bf2095f977 100644 --- a/sdks/moonbit/golem_sdk/gen-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt +++ b/sdks/moonbit/golem_sdk/gen-tool-middleware/interface/golem/tool/tool-middleware-guest/ffi.mbt @@ -20,7 +20,7 @@ pub fn wasmExportDiscoverToolMiddlewares() -> Int { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.ToolMiddleware = (payload)[(index)] let iter_base = address + (index * 120); - __wit_bindgen_lower_t531((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t532((iter_base) + 0, iter_elem) } mbt_ffi_store32((return_area) + 8, (payload).length()) @@ -30,7 +30,7 @@ pub fn wasmExportDiscoverToolMiddlewares() -> Int { } Err(payload0) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload0) + __wit_bindgen_lower_t533((return_area) + 4, payload0) () } @@ -5686,13 +5686,13 @@ pub fn wasmExportGetToolMiddleware(p0 : Int, p1 : Int) -> Int { match result0 { Ok(payload) => { mbt_ffi_store8((return_area) + 0, (0)) - __wit_bindgen_lower_t531((return_area) + 4, payload) + __wit_bindgen_lower_t532((return_area) + 4, payload) () } Err(payload1) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload1) + __wit_bindgen_lower_t533((return_area) + 4, payload1) () } @@ -21343,7 +21343,7 @@ fn __wit_bindgen_lower_t79(ptr : Int, value : @types.TypedSchemaValue) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Unit { +fn __wit_bindgen_lower_t475(ptr : Int, value : @common.CommandAnnotations) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).read_only { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).destructive { 1 } else { 0 })) mbt_ffi_store8((ptr) + 2, (if (value).idempotent { 1 } else { 0 })) @@ -21353,7 +21353,7 @@ fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { +fn __wit_bindgen_lower_t477(ptr : Int, value : @common.Repetition) -> Unit { match value { Repeated => { @@ -21379,16 +21379,16 @@ fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t477(ptr : Int, value : @common.RepeatableListShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableListShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).item_type) } ///| #doc(hidden) -fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t479(ptr : Int, value : @common.RepeatableMapShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).map_type) mbt_ffi_store8((ptr) + 12, (value).duplicate_key_policy.ordinal()) @@ -21396,7 +21396,7 @@ fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { +fn __wit_bindgen_lower_t480(ptr : Int, value : @common.OptionShape) -> Unit { match value { Scalar(payload) => { @@ -21413,13 +21413,13 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { } RepeatableList(payload1) => { mbt_ffi_store8((ptr) + 0, (2)) - __wit_bindgen_lower_t477((ptr) + 4, payload1) + __wit_bindgen_lower_t478((ptr) + 4, payload1) () } RepeatableMap(payload2) => { mbt_ffi_store8((ptr) + 0, (3)) - __wit_bindgen_lower_t478((ptr) + 4, payload2) + __wit_bindgen_lower_t479((ptr) + 4, payload2) () } @@ -21429,7 +21429,7 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { +fn __wit_bindgen_lower_t481(ptr : Int, value : @common.BoolFlagShape) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).default { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).negatable { 1 } else { 0 })) @@ -21437,12 +21437,12 @@ fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { +fn __wit_bindgen_lower_t483(ptr : Int, value : @common.FlagShape) -> Unit { match value { BoolFlag(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t480((ptr) + 4, payload) + __wit_bindgen_lower_t481((ptr) + 4, payload) () } @@ -21471,7 +21471,7 @@ fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { +fn __wit_bindgen_lower_t484(ptr : Int, value : @common.ValueIsRef) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -21482,7 +21482,7 @@ fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { +fn __wit_bindgen_lower_t485(ptr : Int, value : @common.Ref) -> Unit { match value { Present(payload) => { @@ -21496,7 +21496,7 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { } ValueIs(payload1) => { mbt_ffi_store8((ptr) + 0, (1)) - __wit_bindgen_lower_t483((ptr) + 4, payload1) + __wit_bindgen_lower_t484((ptr) + 4, payload1) () } @@ -21506,13 +21506,13 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { +fn __wit_bindgen_lower_t487(ptr : Int, value : @common.RefGroup) -> Unit { let address = mbt_ffi_malloc(((value).refs).length() * 24); for index = 0; index < ((value).refs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).refs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).refs).length()) @@ -21522,14 +21522,14 @@ fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { +fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ImpliesC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -21540,7 +21540,7 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).rhs).length()) @@ -21550,14 +21550,14 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { +fn __wit_bindgen_lower_t490(ptr : Int, value : @common.ForbidsC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -21567,7 +21567,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 16, ((value).rhs).length()) @@ -21577,7 +21577,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { +fn __wit_bindgen_lower_t492(ptr : Int, value : @common.Constraint) -> Unit { match value { RequiresAll(payload) => { @@ -21587,7 +21587,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Ref = (payload)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload).length()) @@ -21602,7 +21602,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index2 = 0; index2 < (payload0).length(); index2 = index2 + 1 { let iter_elem : @common.Ref = (payload0)[(index2)] let iter_base = address1 + (index2 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload0).length()) @@ -21617,7 +21617,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index5 = 0; index5 < (payload3).length(); index5 = index5 + 1 { let iter_elem : @common.Ref = (payload3)[(index5)] let iter_base = address4 + (index5 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload3).length()) @@ -21632,7 +21632,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index8 = 0; index8 < (payload6).length(); index8 = index8 + 1 { let iter_elem : @common.RefGroup = (payload6)[(index8)] let iter_base = address7 + (index8 * 8); - __wit_bindgen_lower_t486((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t487((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload6).length()) @@ -21642,13 +21642,13 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { } Implies(payload9) => { mbt_ffi_store8((ptr) + 0, (4)) - __wit_bindgen_lower_t488((ptr) + 4, payload9) + __wit_bindgen_lower_t489((ptr) + 4, payload9) () } Forbids(payload10) => { mbt_ffi_store8((ptr) + 0, (5)) - __wit_bindgen_lower_t489((ptr) + 4, payload10) + __wit_bindgen_lower_t490((ptr) + 4, payload10) () } @@ -21658,7 +21658,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { +fn __wit_bindgen_lower_t494(ptr : Int, value : @common.Example) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).title) mbt_ffi_store32((ptr) + 4, (value).title.length()) @@ -21672,7 +21672,7 @@ fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { +fn __wit_bindgen_lower_t496(ptr : Int, value : @common.Doc) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).summary) mbt_ffi_store32((ptr) + 4, (value).summary.length()) @@ -21686,7 +21686,7 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { for index = 0; index < ((value).examples).length(); index = index + 1 { let iter_elem : @common.Example = ((value).examples)[(index)] let iter_base = address + (index * 16); - __wit_bindgen_lower_t493((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t494((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).examples).length()) @@ -21696,12 +21696,12 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { +fn __wit_bindgen_lower_t499(ptr : Int, value : @common.Positional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -21741,12 +21741,12 @@ fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { +fn __wit_bindgen_lower_t500(ptr : Int, value : @common.TailPositional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -21804,13 +21804,13 @@ fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { +fn __wit_bindgen_lower_t503(ptr : Int, value : @common.Positionals) -> Unit { let address = mbt_ffi_malloc(((value).fixed).length() * 68); for index = 0; index < ((value).fixed).length(); index = index + 1 { let iter_elem : @common.Positional = ((value).fixed)[(index)] let iter_base = address + (index * 68); - __wit_bindgen_lower_t498((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t499((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).fixed).length()) @@ -21824,7 +21824,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { } Some(payload0) => { mbt_ffi_store8((ptr) + 8, (1)) - __wit_bindgen_lower_t499((ptr) + 12, payload0) + __wit_bindgen_lower_t500((ptr) + 12, payload0) () } @@ -21834,7 +21834,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { +fn __wit_bindgen_lower_t506(ptr : Int, value : @common.OptionSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -21866,7 +21866,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) match ((value).value_name) { None => { @@ -21884,7 +21884,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { () } } - __wit_bindgen_lower_t479((ptr) + 60, (value).shape) + __wit_bindgen_lower_t480((ptr) + 60, (value).shape) match ((value).default) { None => { @@ -21922,7 +21922,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { +fn __wit_bindgen_lower_t507(ptr : Int, value : @common.FlagSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -21954,8 +21954,8 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) - __wit_bindgen_lower_t482((ptr) + 48, (value).shape) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) + __wit_bindgen_lower_t483((ptr) + 48, (value).shape) match ((value).env_var) { None => { @@ -21978,13 +21978,13 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { +fn __wit_bindgen_lower_t510(ptr : Int, value : @common.Globals) -> Unit { let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).options).length()) @@ -21994,7 +21994,7 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 12, ((value).flags).length()) @@ -22004,8 +22004,8 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { - __wit_bindgen_lower_t495((ptr) + 0, (value).doc) +fn __wit_bindgen_lower_t511(ptr : Int, value : @common.StreamSpec) -> Unit { + __wit_bindgen_lower_t496((ptr) + 0, (value).doc) let address = mbt_ffi_malloc(((value).mime).length() * 8); for index = 0; index < ((value).mime).length(); index = index + 1 { @@ -22025,26 +22025,26 @@ fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t511(ptr : Int, value : @common.Formatter) -> Unit { +fn __wit_bindgen_lower_t512(ptr : Int, value : @common.Formatter) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) } ///| #doc(hidden) -fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { +fn __wit_bindgen_lower_t514(ptr : Int, value : @common.ResultSpec) -> Unit { mbt_ffi_store32((ptr) + 0, (value).type_) - __wit_bindgen_lower_t495((ptr) + 4, (value).doc) + __wit_bindgen_lower_t496((ptr) + 4, (value).doc) let address = mbt_ffi_malloc(((value).formatters).length() * 32); for index = 0; index < ((value).formatters).length(); index = index + 1 { let iter_elem : @common.Formatter = ((value).formatters)[(index)] let iter_base = address + (index * 32); - __wit_bindgen_lower_t511((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t512((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 32, ((value).formatters).length()) @@ -22058,12 +22058,12 @@ fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { +fn __wit_bindgen_lower_t516(ptr : Int, value : @common.ErrorCase) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) mbt_ffi_store8((ptr) + 32, (value).kind.ordinal()) mbt_ffi_store8((ptr) + 33, ((value).exit_code).to_int()) @@ -22085,14 +22085,14 @@ fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { - __wit_bindgen_lower_t502((ptr) + 0, (value).positionals) +fn __wit_bindgen_lower_t522(ptr : Int, value : @common.CommandBody) -> Unit { + __wit_bindgen_lower_t503((ptr) + 0, (value).positionals) let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 92, ((value).options).length()) @@ -22102,7 +22102,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 100, ((value).flags).length()) @@ -22112,7 +22112,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index3 = 0; index3 < ((value).constraints).length(); index3 = index3 + 1 { let iter_elem : @common.Constraint = ((value).constraints)[(index3)] let iter_base = address2 + (index3 * 28); - __wit_bindgen_lower_t491((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t492((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 108, ((value).constraints).length()) @@ -22126,7 +22126,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 112, (1)) - __wit_bindgen_lower_t510((ptr) + 116, payload4) + __wit_bindgen_lower_t511((ptr) + 116, payload4) () } @@ -22140,7 +22140,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload6) => { mbt_ffi_store8((ptr) + 152, (1)) - __wit_bindgen_lower_t510((ptr) + 156, payload6) + __wit_bindgen_lower_t511((ptr) + 156, payload6) () } @@ -22154,7 +22154,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload8) => { mbt_ffi_store8((ptr) + 192, (1)) - __wit_bindgen_lower_t513((ptr) + 196, payload8) + __wit_bindgen_lower_t514((ptr) + 196, payload8) () } @@ -22164,7 +22164,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index10 = 0; index10 < ((value).errors).length(); index10 = index10 + 1 { let iter_elem : @common.ErrorCase = ((value).errors)[(index10)] let iter_base = address9 + (index10 * 44); - __wit_bindgen_lower_t515((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t516((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 244, ((value).errors).length()) @@ -22178,7 +22178,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload12) => { mbt_ffi_store8((ptr) + 248, (1)) - __wit_bindgen_lower_t474((ptr) + 249, payload12) + __wit_bindgen_lower_t475((ptr) + 249, payload12) () } @@ -22188,7 +22188,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { +fn __wit_bindgen_lower_t525(ptr : Int, value : @common.CommandNode) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -22206,8 +22206,8 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t509((ptr) + 40, (value).globals) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t510((ptr) + 40, (value).globals) let address2 = mbt_ffi_malloc(((value).subcommands).length() * 4); for index3 = 0; index3 < ((value).subcommands).length(); index3 = index3 + 1 { @@ -22227,7 +22227,7 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 64, (1)) - __wit_bindgen_lower_t521((ptr) + 68, payload4) + __wit_bindgen_lower_t522((ptr) + 68, payload4) () } @@ -22237,13 +22237,13 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { +fn __wit_bindgen_lower_t527(ptr : Int, value : @common.CommandTree) -> Unit { let address = mbt_ffi_malloc(((value).nodes).length() * 324); for index = 0; index < ((value).nodes).length(); index = index + 1 { let iter_elem : @common.CommandNode = ((value).nodes)[(index)] let iter_base = address + (index * 324); - __wit_bindgen_lower_t524((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t525((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).nodes).length()) @@ -22253,20 +22253,20 @@ fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t527(ptr : Int, value : @common.Tool) -> Unit { +fn __wit_bindgen_lower_t528(ptr : Int, value : @common.Tool) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).version) mbt_ffi_store32((ptr) + 4, (value).version.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t526((ptr) + 8, (value).commands) + __wit_bindgen_lower_t527((ptr) + 8, (value).commands) __wit_bindgen_lower_t59((ptr) + 16, (value).schema) } ///| #doc(hidden) -fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit { - __wit_bindgen_lower_t527((ptr) + 0, (value).presented) +fn __wit_bindgen_lower_t530(ptr : Int, value : @common.MonomorphicScope) -> Unit { + __wit_bindgen_lower_t528((ptr) + 0, (value).presented) match ((value).expected) { None => { @@ -22276,7 +22276,7 @@ fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit } Some(payload0) => { mbt_ffi_store8((ptr) + 36, (1)) - __wit_bindgen_lower_t527((ptr) + 40, payload0) + __wit_bindgen_lower_t528((ptr) + 40, payload0) () } @@ -22286,12 +22286,12 @@ fn __wit_bindgen_lower_t529(ptr : Int, value : @common.MonomorphicScope) -> Unit ///| #doc(hidden) -fn __wit_bindgen_lower_t530(ptr : Int, value : @common.ToolMiddlewareScope) -> Unit { +fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddlewareScope) -> Unit { match value { Monomorphic(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t529((ptr) + 4, payload) + __wit_bindgen_lower_t530((ptr) + 4, payload) () } @@ -22306,7 +22306,7 @@ fn __wit_bindgen_lower_t530(ptr : Int, value : @common.ToolMiddlewareScope) -> U ///| #doc(hidden) -fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddleware) -> Unit { +fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolMiddleware) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -22324,14 +22324,14 @@ fn __wit_bindgen_lower_t531(ptr : Int, value : @common.ToolMiddleware) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t530((ptr) + 40, (value).scope) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t531((ptr) + 40, (value).scope) } ///| #doc(hidden) -fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolError) -> Unit { +fn __wit_bindgen_lower_t533(ptr : Int, value : @common.ToolError) -> Unit { match value { InvalidToolName(payload) => { diff --git a/sdks/moonbit/golem_sdk/gen/interface/golem/tool/guest/ffi.mbt b/sdks/moonbit/golem_sdk/gen/interface/golem/tool/guest/ffi.mbt index cb02ed24a4..6bad447cdc 100644 --- a/sdks/moonbit/golem_sdk/gen/interface/golem/tool/guest/ffi.mbt +++ b/sdks/moonbit/golem_sdk/gen/interface/golem/tool/guest/ffi.mbt @@ -20,7 +20,7 @@ pub fn wasmExportDiscoverTools() -> Int { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Tool = (payload)[(index)] let iter_base = address + (index * 36); - __wit_bindgen_lower_t527((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t528((iter_base) + 0, iter_elem) } mbt_ffi_store32((return_area) + 8, (payload).length()) @@ -30,7 +30,7 @@ pub fn wasmExportDiscoverTools() -> Int { } Err(payload0) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload0) + __wit_bindgen_lower_t533((return_area) + 4, payload0) () } @@ -3279,13 +3279,13 @@ pub fn wasmExportGetTool(p0 : Int, p1 : Int) -> Int { match result0 { Ok(payload) => { mbt_ffi_store8((return_area) + 0, (0)) - __wit_bindgen_lower_t527((return_area) + 4, payload) + __wit_bindgen_lower_t528((return_area) + 4, payload) () } Err(payload1) => { mbt_ffi_store8((return_area) + 0, (1)) - __wit_bindgen_lower_t532((return_area) + 4, payload1) + __wit_bindgen_lower_t533((return_area) + 4, payload1) () } @@ -10930,7 +10930,7 @@ fn __wit_bindgen_lower_t79(ptr : Int, value : @types.TypedSchemaValue) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Unit { +fn __wit_bindgen_lower_t475(ptr : Int, value : @common.CommandAnnotations) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).read_only { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).destructive { 1 } else { 0 })) mbt_ffi_store8((ptr) + 2, (if (value).idempotent { 1 } else { 0 })) @@ -10940,7 +10940,7 @@ fn __wit_bindgen_lower_t474(ptr : Int, value : @common.CommandAnnotations) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { +fn __wit_bindgen_lower_t477(ptr : Int, value : @common.Repetition) -> Unit { match value { Repeated => { @@ -10966,16 +10966,16 @@ fn __wit_bindgen_lower_t476(ptr : Int, value : @common.Repetition) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t477(ptr : Int, value : @common.RepeatableListShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableListShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).item_type) } ///| #doc(hidden) -fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Unit { - __wit_bindgen_lower_t476((ptr) + 0, (value).repetition) +fn __wit_bindgen_lower_t479(ptr : Int, value : @common.RepeatableMapShape) -> Unit { + __wit_bindgen_lower_t477((ptr) + 0, (value).repetition) mbt_ffi_store32((ptr) + 8, (value).map_type) mbt_ffi_store8((ptr) + 12, (value).duplicate_key_policy.ordinal()) @@ -10983,7 +10983,7 @@ fn __wit_bindgen_lower_t478(ptr : Int, value : @common.RepeatableMapShape) -> Un ///| #doc(hidden) -fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { +fn __wit_bindgen_lower_t480(ptr : Int, value : @common.OptionShape) -> Unit { match value { Scalar(payload) => { @@ -11000,13 +11000,13 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { } RepeatableList(payload1) => { mbt_ffi_store8((ptr) + 0, (2)) - __wit_bindgen_lower_t477((ptr) + 4, payload1) + __wit_bindgen_lower_t478((ptr) + 4, payload1) () } RepeatableMap(payload2) => { mbt_ffi_store8((ptr) + 0, (3)) - __wit_bindgen_lower_t478((ptr) + 4, payload2) + __wit_bindgen_lower_t479((ptr) + 4, payload2) () } @@ -11016,7 +11016,7 @@ fn __wit_bindgen_lower_t479(ptr : Int, value : @common.OptionShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { +fn __wit_bindgen_lower_t481(ptr : Int, value : @common.BoolFlagShape) -> Unit { mbt_ffi_store8((ptr) + 0, (if (value).default { 1 } else { 0 })) mbt_ffi_store8((ptr) + 1, (if (value).negatable { 1 } else { 0 })) @@ -11024,12 +11024,12 @@ fn __wit_bindgen_lower_t480(ptr : Int, value : @common.BoolFlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { +fn __wit_bindgen_lower_t483(ptr : Int, value : @common.FlagShape) -> Unit { match value { BoolFlag(payload) => { mbt_ffi_store8((ptr) + 0, (0)) - __wit_bindgen_lower_t480((ptr) + 4, payload) + __wit_bindgen_lower_t481((ptr) + 4, payload) () } @@ -11058,7 +11058,7 @@ fn __wit_bindgen_lower_t482(ptr : Int, value : @common.FlagShape) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { +fn __wit_bindgen_lower_t484(ptr : Int, value : @common.ValueIsRef) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -11069,7 +11069,7 @@ fn __wit_bindgen_lower_t483(ptr : Int, value : @common.ValueIsRef) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { +fn __wit_bindgen_lower_t485(ptr : Int, value : @common.Ref) -> Unit { match value { Present(payload) => { @@ -11083,7 +11083,7 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { } ValueIs(payload1) => { mbt_ffi_store8((ptr) + 0, (1)) - __wit_bindgen_lower_t483((ptr) + 4, payload1) + __wit_bindgen_lower_t484((ptr) + 4, payload1) () } @@ -11093,13 +11093,13 @@ fn __wit_bindgen_lower_t484(ptr : Int, value : @common.Ref) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { +fn __wit_bindgen_lower_t487(ptr : Int, value : @common.RefGroup) -> Unit { let address = mbt_ffi_malloc(((value).refs).length() * 24); for index = 0; index < ((value).refs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).refs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).refs).length()) @@ -11109,14 +11109,14 @@ fn __wit_bindgen_lower_t486(ptr : Int, value : @common.RefGroup) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { +fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ImpliesC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -11127,7 +11127,7 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).rhs).length()) @@ -11137,14 +11137,14 @@ fn __wit_bindgen_lower_t488(ptr : Int, value : @common.ImpliesC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { +fn __wit_bindgen_lower_t490(ptr : Int, value : @common.ForbidsC) -> Unit { mbt_ffi_store8((ptr) + 0, (value).lhs_quant.ordinal()) let address = mbt_ffi_malloc(((value).lhs).length() * 24); for index = 0; index < ((value).lhs).length(); index = index + 1 { let iter_elem : @common.Ref = ((value).lhs)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, ((value).lhs).length()) @@ -11154,7 +11154,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { for index1 = 0; index1 < ((value).rhs).length(); index1 = index1 + 1 { let iter_elem : @common.Ref = ((value).rhs)[(index1)] let iter_base = address0 + (index1 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 16, ((value).rhs).length()) @@ -11164,7 +11164,7 @@ fn __wit_bindgen_lower_t489(ptr : Int, value : @common.ForbidsC) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { +fn __wit_bindgen_lower_t492(ptr : Int, value : @common.Constraint) -> Unit { match value { RequiresAll(payload) => { @@ -11174,7 +11174,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index = 0; index < (payload).length(); index = index + 1 { let iter_elem : @common.Ref = (payload)[(index)] let iter_base = address + (index * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload).length()) @@ -11189,7 +11189,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index2 = 0; index2 < (payload0).length(); index2 = index2 + 1 { let iter_elem : @common.Ref = (payload0)[(index2)] let iter_base = address1 + (index2 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload0).length()) @@ -11204,7 +11204,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index5 = 0; index5 < (payload3).length(); index5 = index5 + 1 { let iter_elem : @common.Ref = (payload3)[(index5)] let iter_base = address4 + (index5 * 24); - __wit_bindgen_lower_t484((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t485((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload3).length()) @@ -11219,7 +11219,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { for index8 = 0; index8 < (payload6).length(); index8 = index8 + 1 { let iter_elem : @common.RefGroup = (payload6)[(index8)] let iter_base = address7 + (index8 * 8); - __wit_bindgen_lower_t486((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t487((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 8, (payload6).length()) @@ -11229,13 +11229,13 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { } Implies(payload9) => { mbt_ffi_store8((ptr) + 0, (4)) - __wit_bindgen_lower_t488((ptr) + 4, payload9) + __wit_bindgen_lower_t489((ptr) + 4, payload9) () } Forbids(payload10) => { mbt_ffi_store8((ptr) + 0, (5)) - __wit_bindgen_lower_t489((ptr) + 4, payload10) + __wit_bindgen_lower_t490((ptr) + 4, payload10) () } @@ -11245,7 +11245,7 @@ fn __wit_bindgen_lower_t491(ptr : Int, value : @common.Constraint) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { +fn __wit_bindgen_lower_t494(ptr : Int, value : @common.Example) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).title) mbt_ffi_store32((ptr) + 4, (value).title.length()) @@ -11259,7 +11259,7 @@ fn __wit_bindgen_lower_t493(ptr : Int, value : @common.Example) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { +fn __wit_bindgen_lower_t496(ptr : Int, value : @common.Doc) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).summary) mbt_ffi_store32((ptr) + 4, (value).summary.length()) @@ -11273,7 +11273,7 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { for index = 0; index < ((value).examples).length(); index = index + 1 { let iter_elem : @common.Example = ((value).examples)[(index)] let iter_base = address + (index * 16); - __wit_bindgen_lower_t493((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t494((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 20, ((value).examples).length()) @@ -11283,12 +11283,12 @@ fn __wit_bindgen_lower_t495(ptr : Int, value : @common.Doc) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { +fn __wit_bindgen_lower_t499(ptr : Int, value : @common.Positional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -11328,12 +11328,12 @@ fn __wit_bindgen_lower_t498(ptr : Int, value : @common.Positional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { +fn __wit_bindgen_lower_t500(ptr : Int, value : @common.TailPositional) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) match ((value).value_name) { None => { @@ -11391,13 +11391,13 @@ fn __wit_bindgen_lower_t499(ptr : Int, value : @common.TailPositional) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { +fn __wit_bindgen_lower_t503(ptr : Int, value : @common.Positionals) -> Unit { let address = mbt_ffi_malloc(((value).fixed).length() * 68); for index = 0; index < ((value).fixed).length(); index = index + 1 { let iter_elem : @common.Positional = ((value).fixed)[(index)] let iter_base = address + (index * 68); - __wit_bindgen_lower_t498((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t499((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).fixed).length()) @@ -11411,7 +11411,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { } Some(payload0) => { mbt_ffi_store8((ptr) + 8, (1)) - __wit_bindgen_lower_t499((ptr) + 12, payload0) + __wit_bindgen_lower_t500((ptr) + 12, payload0) () } @@ -11421,7 +11421,7 @@ fn __wit_bindgen_lower_t502(ptr : Int, value : @common.Positionals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { +fn __wit_bindgen_lower_t506(ptr : Int, value : @common.OptionSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -11453,7 +11453,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) match ((value).value_name) { None => { @@ -11471,7 +11471,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { () } } - __wit_bindgen_lower_t479((ptr) + 60, (value).shape) + __wit_bindgen_lower_t480((ptr) + 60, (value).shape) match ((value).default) { None => { @@ -11509,7 +11509,7 @@ fn __wit_bindgen_lower_t505(ptr : Int, value : @common.OptionSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { +fn __wit_bindgen_lower_t507(ptr : Int, value : @common.FlagSpec) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).long) mbt_ffi_store32((ptr) + 4, (value).long.length()) @@ -11541,8 +11541,8 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { } mbt_ffi_store32((ptr) + 20, ((value).aliases).length()) mbt_ffi_store32((ptr) + 16, address) - __wit_bindgen_lower_t495((ptr) + 24, (value).doc) - __wit_bindgen_lower_t482((ptr) + 48, (value).shape) + __wit_bindgen_lower_t496((ptr) + 24, (value).doc) + __wit_bindgen_lower_t483((ptr) + 48, (value).shape) match ((value).env_var) { None => { @@ -11565,13 +11565,13 @@ fn __wit_bindgen_lower_t506(ptr : Int, value : @common.FlagSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { +fn __wit_bindgen_lower_t510(ptr : Int, value : @common.Globals) -> Unit { let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).options).length()) @@ -11581,7 +11581,7 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 12, ((value).flags).length()) @@ -11591,8 +11591,8 @@ fn __wit_bindgen_lower_t509(ptr : Int, value : @common.Globals) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { - __wit_bindgen_lower_t495((ptr) + 0, (value).doc) +fn __wit_bindgen_lower_t511(ptr : Int, value : @common.StreamSpec) -> Unit { + __wit_bindgen_lower_t496((ptr) + 0, (value).doc) let address = mbt_ffi_malloc(((value).mime).length() * 8); for index = 0; index < ((value).mime).length(); index = index + 1 { @@ -11612,26 +11612,26 @@ fn __wit_bindgen_lower_t510(ptr : Int, value : @common.StreamSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t511(ptr : Int, value : @common.Formatter) -> Unit { +fn __wit_bindgen_lower_t512(ptr : Int, value : @common.Formatter) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) } ///| #doc(hidden) -fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { +fn __wit_bindgen_lower_t514(ptr : Int, value : @common.ResultSpec) -> Unit { mbt_ffi_store32((ptr) + 0, (value).type_) - __wit_bindgen_lower_t495((ptr) + 4, (value).doc) + __wit_bindgen_lower_t496((ptr) + 4, (value).doc) let address = mbt_ffi_malloc(((value).formatters).length() * 32); for index = 0; index < ((value).formatters).length(); index = index + 1 { let iter_elem : @common.Formatter = ((value).formatters)[(index)] let iter_base = address + (index * 32); - __wit_bindgen_lower_t511((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t512((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 32, ((value).formatters).length()) @@ -11645,12 +11645,12 @@ fn __wit_bindgen_lower_t513(ptr : Int, value : @common.ResultSpec) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { +fn __wit_bindgen_lower_t516(ptr : Int, value : @common.ErrorCase) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t495((ptr) + 8, (value).doc) + __wit_bindgen_lower_t496((ptr) + 8, (value).doc) mbt_ffi_store8((ptr) + 32, (value).kind.ordinal()) mbt_ffi_store8((ptr) + 33, ((value).exit_code).to_int()) @@ -11672,14 +11672,14 @@ fn __wit_bindgen_lower_t515(ptr : Int, value : @common.ErrorCase) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { - __wit_bindgen_lower_t502((ptr) + 0, (value).positionals) +fn __wit_bindgen_lower_t522(ptr : Int, value : @common.CommandBody) -> Unit { + __wit_bindgen_lower_t503((ptr) + 0, (value).positionals) let address = mbt_ffi_malloc(((value).options).length() * 112); for index = 0; index < ((value).options).length(); index = index + 1 { let iter_elem : @common.OptionSpec = ((value).options)[(index)] let iter_base = address + (index * 112); - __wit_bindgen_lower_t505((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 92, ((value).options).length()) @@ -11689,7 +11689,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index1 = 0; index1 < ((value).flags).length(); index1 = index1 + 1 { let iter_elem : @common.FlagSpec = ((value).flags)[(index1)] let iter_base = address0 + (index1 * 72); - __wit_bindgen_lower_t506((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t507((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 100, ((value).flags).length()) @@ -11699,7 +11699,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index3 = 0; index3 < ((value).constraints).length(); index3 = index3 + 1 { let iter_elem : @common.Constraint = ((value).constraints)[(index3)] let iter_base = address2 + (index3 * 28); - __wit_bindgen_lower_t491((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t492((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 108, ((value).constraints).length()) @@ -11713,7 +11713,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 112, (1)) - __wit_bindgen_lower_t510((ptr) + 116, payload4) + __wit_bindgen_lower_t511((ptr) + 116, payload4) () } @@ -11727,7 +11727,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload6) => { mbt_ffi_store8((ptr) + 152, (1)) - __wit_bindgen_lower_t510((ptr) + 156, payload6) + __wit_bindgen_lower_t511((ptr) + 156, payload6) () } @@ -11741,7 +11741,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload8) => { mbt_ffi_store8((ptr) + 192, (1)) - __wit_bindgen_lower_t513((ptr) + 196, payload8) + __wit_bindgen_lower_t514((ptr) + 196, payload8) () } @@ -11751,7 +11751,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { for index10 = 0; index10 < ((value).errors).length(); index10 = index10 + 1 { let iter_elem : @common.ErrorCase = ((value).errors)[(index10)] let iter_base = address9 + (index10 * 44); - __wit_bindgen_lower_t515((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t516((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 244, ((value).errors).length()) @@ -11765,7 +11765,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { } Some(payload12) => { mbt_ffi_store8((ptr) + 248, (1)) - __wit_bindgen_lower_t474((ptr) + 249, payload12) + __wit_bindgen_lower_t475((ptr) + 249, payload12) () } @@ -11775,7 +11775,7 @@ fn __wit_bindgen_lower_t521(ptr : Int, value : @common.CommandBody) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { +fn __wit_bindgen_lower_t525(ptr : Int, value : @common.CommandNode) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).name) mbt_ffi_store32((ptr) + 4, (value).name.length()) @@ -11793,8 +11793,8 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } mbt_ffi_store32((ptr) + 12, ((value).aliases).length()) mbt_ffi_store32((ptr) + 8, address) - __wit_bindgen_lower_t495((ptr) + 16, (value).doc) - __wit_bindgen_lower_t509((ptr) + 40, (value).globals) + __wit_bindgen_lower_t496((ptr) + 16, (value).doc) + __wit_bindgen_lower_t510((ptr) + 40, (value).globals) let address2 = mbt_ffi_malloc(((value).subcommands).length() * 4); for index3 = 0; index3 < ((value).subcommands).length(); index3 = index3 + 1 { @@ -11814,7 +11814,7 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { } Some(payload4) => { mbt_ffi_store8((ptr) + 64, (1)) - __wit_bindgen_lower_t521((ptr) + 68, payload4) + __wit_bindgen_lower_t522((ptr) + 68, payload4) () } @@ -11824,13 +11824,13 @@ fn __wit_bindgen_lower_t524(ptr : Int, value : @common.CommandNode) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { +fn __wit_bindgen_lower_t527(ptr : Int, value : @common.CommandTree) -> Unit { let address = mbt_ffi_malloc(((value).nodes).length() * 324); for index = 0; index < ((value).nodes).length(); index = index + 1 { let iter_elem : @common.CommandNode = ((value).nodes)[(index)] let iter_base = address + (index * 324); - __wit_bindgen_lower_t524((iter_base) + 0, iter_elem) + __wit_bindgen_lower_t525((iter_base) + 0, iter_elem) } mbt_ffi_store32((ptr) + 4, ((value).nodes).length()) @@ -11840,19 +11840,19 @@ fn __wit_bindgen_lower_t526(ptr : Int, value : @common.CommandTree) -> Unit { ///| #doc(hidden) -fn __wit_bindgen_lower_t527(ptr : Int, value : @common.Tool) -> Unit { +fn __wit_bindgen_lower_t528(ptr : Int, value : @common.Tool) -> Unit { let ptr0 = mbt_ffi_str2ptr((value).version) mbt_ffi_store32((ptr) + 4, (value).version.length()) mbt_ffi_store32((ptr) + 0, ptr0) - __wit_bindgen_lower_t526((ptr) + 8, (value).commands) + __wit_bindgen_lower_t527((ptr) + 8, (value).commands) __wit_bindgen_lower_t59((ptr) + 16, (value).schema) } ///| #doc(hidden) -fn __wit_bindgen_lower_t532(ptr : Int, value : @common.ToolError) -> Unit { +fn __wit_bindgen_lower_t533(ptr : Int, value : @common.ToolError) -> Unit { match value { InvalidToolName(payload) => { diff --git a/sdks/moonbit/golem_sdk/interface/golem/agent/host/ffi.mbt b/sdks/moonbit/golem_sdk/interface/golem/agent/host/ffi.mbt index bd34795d1d..5ab3f37ae2 100644 --- a/sdks/moonbit/golem_sdk/interface/golem/agent/host/ffi.mbt +++ b/sdks/moonbit/golem_sdk/interface/golem/agent/host/ffi.mbt @@ -15,6 +15,9 @@ fn wasmImportGetAllAgentTypes(p0 : Int) = "golem:agent/host@2.0.0" "get-all-age ///| fn wasmImportGetAgentType(p0 : Int, p1 : Int, p2 : Int) = "golem:agent/host@2.0.0" "get-agent-type" +///| +fn wasmImportGetAgentTypeByAgentId(p0 : Int, p1 : Int, p2 : Int) = "golem:agent/host@2.0.0" "get-agent-type-by-agent-id" + ///| fn wasmImportMakeAgentId(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int64, p7 : Int64, p8 : Int) = "golem:agent/host@2.0.0" "make-agent-id" @@ -27,6 +30,9 @@ fn wasmImportCreateWebhook(p0 : Int64, p1 : Int64, p2 : Int, p3 : Int, p4 : Int6 ///| fn wasmImportConstructorWasmRpc(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int64, p7 : Int64, p8 : Int, p9 : Int) -> Int = "golem:agent/host@2.0.0" "[constructor]wasm-rpc" +///| +fn wasmImportStaticWasmRpcCreate(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int64, p7 : Int64, p8 : Int, p9 : Int, p10 : Int) = "golem:agent/host@2.0.0" "[static]wasm-rpc.create" + ///| fn wasmImportMethodWasmRpcInvokeAndAwait(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int) = "golem:agent/host@2.0.0" "[method]wasm-rpc.invoke-and-await" diff --git a/sdks/moonbit/golem_sdk/interface/golem/agent/host/pkg.generated.mbti b/sdks/moonbit/golem_sdk/interface/golem/agent/host/pkg.generated.mbti index 5c8dad844e..25b61fd854 100644 --- a/sdks/moonbit/golem_sdk/interface/golem/agent/host/pkg.generated.mbti +++ b/sdks/moonbit/golem_sdk/interface/golem/agent/host/pkg.generated.mbti @@ -13,6 +13,8 @@ pub fn create_webhook(@types.PromiseId) -> Result[String, WebhookError] pub fn get_agent_type(String) -> @common.RegisteredAgentType? +pub fn get_agent_type_by_agent_id(String) -> @common.RegisteredAgentType? + pub fn get_all_agent_types() -> Array[@common.RegisteredAgentType] pub fn get_config_value(Array[String], @types.SchemaGraph) -> Result[@types.SchemaValueTree, ConfigValueError] @@ -75,6 +77,7 @@ pub(all) struct ScheduledInvocationReceipt { pub(all) struct WasmRpc(Int) derive(Eq, @debug.Debug) pub fn WasmRpc::async_invoke_and_await(Self, String, @types.SchemaValueTree, @types.PermissionCard?) -> AsyncInvocationWithMetadata +pub fn WasmRpc::create(String, @types.SchemaValueTree, @types.Uuid?, Array[@common.TypedAgentConfigValue]) -> Result[Self, RpcError] pub fn WasmRpc::drop(Self) -> Unit pub fn WasmRpc::invoke(Self, String, @types.SchemaValueTree, @types.PermissionCard?) -> Result[InvocationMetadata, RpcError] pub fn WasmRpc::invoke_and_await(Self, String, @types.SchemaValueTree, @types.PermissionCard?) -> Result[InvocationResultWithMetadata, RpcError] diff --git a/sdks/moonbit/golem_sdk/interface/golem/agent/host/top.mbt b/sdks/moonbit/golem_sdk/interface/golem/agent/host/top.mbt index 29980bad3d..5d980a91e3 100644 --- a/sdks/moonbit/golem_sdk/interface/golem/agent/host/top.mbt +++ b/sdks/moonbit/golem_sdk/interface/golem/agent/host/top.mbt @@ -8330,1982 +8330,1659 @@ pub fn get_agent_type(agent_type_name : String) -> @common.RegisteredAgentType? } ///| -/// Constructs a string agent-id from the agent type and its constructor parameters -/// and an optional phantom ID. -/// -/// `input` is a value tree whose root encodes the constructor's parameter list. -pub fn make_agent_id(agent_type_name : String, input : @types.SchemaValueTree, phantom_id : @types.Uuid?) -> Result[String, @common.AgentError] { - let cleanup_list : Array[Int] = [] +/// Gets the registered agent type used by an existing agent, identified by its agent ID. +pub fn get_agent_type_by_agent_id(agent_id : String) -> @common.RegisteredAgentType? { - let ptr = mbt_ffi_str2ptr(agent_type_name) + let ptr = mbt_ffi_str2ptr(agent_id) + let return_area = mbt_ffi_malloc(200) + wasmImportGetAgentTypeByAgentId(ptr, agent_id.length(), return_area); - let address70 = mbt_ffi_malloc(((input).value_nodes).length() * 32); - for index71 = 0; index71 < ((input).value_nodes).length(); index71 = index71 + 1 { - let iter_elem : @types.SchemaValueNode = ((input).value_nodes)[(index71)] - let iter_base = address70 + (index71 * 32); + let lifted578 : @common.RegisteredAgentType? = match mbt_ffi_load8_u((return_area) + 0) { + 0 => Option::None + 1 => { - match iter_elem { - BoolValue(payload) => { - mbt_ffi_store8((iter_base) + 0, (0)) - mbt_ffi_store8((iter_base) + 8, (if payload { 1 } else { 0 })) + let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - () - } - S8Value(payload0) => { - mbt_ffi_store8((iter_base) + 0, (1)) - mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload0)) + let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 16), mbt_ffi_load32((return_area) + 20)) - () - } - S16Value(payload1) => { - mbt_ffi_store8((iter_base) + 0, (2)) - mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload1)) + let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 24), mbt_ffi_load32((return_area) + 28)) - () - } - S32Value(payload2) => { - mbt_ffi_store8((iter_base) + 0, (3)) - mbt_ffi_store32((iter_base) + 8, payload2) + let array195 : Array[@types.SchemaTypeNode] = []; + for index196 = 0; index196 < (mbt_ffi_load32((return_area) + 36)); index196 = index196 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 32)) + (index196 * 144) - () - } - S64Value(payload3) => { - mbt_ffi_store8((iter_base) + 0, (4)) - mbt_ffi_store64((iter_base) + 8, payload3) + let lifted181 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - () - } - U8Value(payload4) => { - mbt_ffi_store8((iter_base) + 0, (5)) - mbt_ffi_store8((iter_base) + 8, (payload4).to_int()) + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { - () - } - U16Value(payload5) => { - mbt_ffi_store8((iter_base) + 0, (6)) - mbt_ffi_store16((iter_base) + 8, (payload5).reinterpret_as_int()) + @types.SchemaTypeBody::BoolType + } + 2 => { - () - } - U32Value(payload6) => { - mbt_ffi_store8((iter_base) + 0, (7)) - mbt_ffi_store32((iter_base) + 8, (payload6).reinterpret_as_int()) + let lifted7 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - U64Value(payload7) => { - mbt_ffi_store8((iter_base) + 0, (8)) - mbt_ffi_store64((iter_base) + 8, (payload7).reinterpret_as_int64()) + let lifted2 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - F32Value(payload8) => { - mbt_ffi_store8((iter_base) + 0, (9)) - mbt_ffi_storef32((iter_base) + 8, payload8) + let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - F64Value(payload9) => { - mbt_ffi_store8((iter_base) + 0, (10)) - mbt_ffi_storef64((iter_base) + 8, payload9) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - CharValue(payload10) => { - mbt_ffi_store8((iter_base) + 0, (11)) - mbt_ffi_store32((iter_base) + 8, (payload10).to_int()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - StringValue(payload11) => { - mbt_ffi_store8((iter_base) + 0, (12)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - let ptr12 = mbt_ffi_str2ptr(payload11) - mbt_ffi_store32((iter_base) + 12, payload11.length()) - mbt_ffi_store32((iter_base) + 8, ptr12) - cleanup_list.push(ptr12) + Option::Some(lifted) + } + _ => panic() + } - () - } - RecordValue(payload13) => { - mbt_ffi_store8((iter_base) + 0, (13)) + let lifted4 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let address = mbt_ffi_malloc((payload13).length() * 4); - for index = 0; index < (payload13).length(); index = index + 1 { - let iter_elem : Int = (payload13)[(index)] - let iter_base = address + (index * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + let lifted3 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - } - mbt_ffi_store32((iter_base) + 12, (payload13).length()) - mbt_ffi_store32((iter_base) + 8, address) - cleanup_list.push(address) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - VariantValue(payload14) => { - mbt_ffi_store8((iter_base) + 0, (14)) - mbt_ffi_store32((iter_base) + 8, ((payload14).case).reinterpret_as_int()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - match ((payload14).payload) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - Some(payload16) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload16) + Option::Some(lifted3) + } + _ => panic() + } - () - } - } + let lifted6 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - EnumValue(payload17) => { - mbt_ffi_store8((iter_base) + 0, (15)) - mbt_ffi_store32((iter_base) + 8, (payload17).reinterpret_as_int()) + let result5 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - FlagsValue(payload18) => { - mbt_ffi_store8((iter_base) + 0, (16)) + Option::Some(result5) + } + _ => panic() + } - let address19 = mbt_ffi_malloc((payload18).length() * 1); - for index20 = 0; index20 < (payload18).length(); index20 = index20 + 1 { - let iter_elem : Bool = (payload18)[(index20)] - let iter_base = address19 + (index20 * 1); - mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + Option::Some(@types.NumericRestrictions::{min : lifted2, max : lifted4, unit : lifted6}) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 12, (payload18).length()) - mbt_ffi_store32((iter_base) + 8, address19) - cleanup_list.push(address19) + @types.SchemaTypeBody::S8Type(lifted7) + } + 3 => { - () - } - TupleValue(payload21) => { - mbt_ffi_store8((iter_base) + 0, (17)) + let lifted14 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let address22 = mbt_ffi_malloc((payload21).length() * 4); - for index23 = 0; index23 < (payload21).length(); index23 = index23 + 1 { - let iter_elem : Int = (payload21)[(index23)] - let iter_base = address22 + (index23 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + let lifted9 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload21).length()) - mbt_ffi_store32((iter_base) + 8, address22) - cleanup_list.push(address22) + let lifted8 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - ListValue(payload24) => { - mbt_ffi_store8((iter_base) + 0, (18)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let address25 = mbt_ffi_malloc((payload24).length() * 4); - for index26 = 0; index26 < (payload24).length(); index26 = index26 + 1 { - let iter_elem : Int = (payload24)[(index26)] - let iter_base = address25 + (index26 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - } - mbt_ffi_store32((iter_base) + 12, (payload24).length()) - mbt_ffi_store32((iter_base) + 8, address25) - cleanup_list.push(address25) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - FixedListValue(payload27) => { - mbt_ffi_store8((iter_base) + 0, (19)) + Option::Some(lifted8) + } + _ => panic() + } - let address28 = mbt_ffi_malloc((payload27).length() * 4); - for index29 = 0; index29 < (payload27).length(); index29 = index29 + 1 { - let iter_elem : Int = (payload27)[(index29)] - let iter_base = address28 + (index29 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) - - } - mbt_ffi_store32((iter_base) + 12, (payload27).length()) - mbt_ffi_store32((iter_base) + 8, address28) - cleanup_list.push(address28) - - () - } - MapValue(payload30) => { - mbt_ffi_store8((iter_base) + 0, (20)) - - let address31 = mbt_ffi_malloc((payload30).length() * 8); - for index32 = 0; index32 < (payload30).length(); index32 = index32 + 1 { - let iter_elem : @types.MapEntry = (payload30)[(index32)] - let iter_base = address31 + (index32 * 8); - mbt_ffi_store32((iter_base) + 0, (iter_elem).key) - mbt_ffi_store32((iter_base) + 4, (iter_elem).value) - - } - mbt_ffi_store32((iter_base) + 12, (payload30).length()) - mbt_ffi_store32((iter_base) + 8, address31) - cleanup_list.push(address31) + let lifted11 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - OptionValue(payload33) => { - mbt_ffi_store8((iter_base) + 0, (21)) + let lifted10 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - match (payload33) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - Some(payload35) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload35) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - ResultValue(payload36) => { - mbt_ffi_store8((iter_base) + 0, (22)) + Option::Some(lifted10) + } + _ => panic() + } - match payload36 { - OkValue(payload37) => { - mbt_ffi_store8((iter_base) + 8, (0)) + let lifted13 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match (payload37) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + let result12 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Some(payload39) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload39) + Option::Some(result12) + } + _ => panic() + } - () + Option::Some(@types.NumericRestrictions::{min : lifted9, max : lifted11, unit : lifted13}) } + _ => panic() } - () + @types.SchemaTypeBody::S16Type(lifted14) } - ErrValue(payload40) => { - mbt_ffi_store8((iter_base) + 8, (1)) + 4 => { - match (payload40) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + let lifted21 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Some(payload42) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload42) + let lifted16 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - } + let lifted15 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - } + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - TextValue(payload43) => { - mbt_ffi_store8((iter_base) + 0, (23)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - let ptr44 = mbt_ffi_str2ptr((payload43).text) - mbt_ffi_store32((iter_base) + 12, (payload43).text.length()) - mbt_ffi_store32((iter_base) + 8, ptr44) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - match ((payload43).language) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + Option::Some(lifted15) + } + _ => panic() + } - () - } - Some(payload46) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let lifted18 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let ptr47 = mbt_ffi_str2ptr(payload46) - mbt_ffi_store32((iter_base) + 24, payload46.length()) - mbt_ffi_store32((iter_base) + 20, ptr47) - cleanup_list.push(ptr47) + let lifted17 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - } - cleanup_list.push(ptr44) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - BinaryValue(payload48) => { - mbt_ffi_store8((iter_base) + 0, (24)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - let ptr49 = mbt_ffi_bytes2ptr((payload48).bytes) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - mbt_ffi_store32((iter_base) + 12, (payload48).bytes.length()) - mbt_ffi_store32((iter_base) + 8, ptr49) + Option::Some(lifted17) + } + _ => panic() + } - match ((payload48).mime_type) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let lifted20 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - Some(payload51) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let result19 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - let ptr52 = mbt_ffi_str2ptr(payload51) - mbt_ffi_store32((iter_base) + 24, payload51.length()) - mbt_ffi_store32((iter_base) + 20, ptr52) - cleanup_list.push(ptr52) + Option::Some(result19) + } + _ => panic() + } - () + Option::Some(@types.NumericRestrictions::{min : lifted16, max : lifted18, unit : lifted20}) + } + _ => panic() + } + + @types.SchemaTypeBody::S32Type(lifted21) } - } - cleanup_list.push(ptr49) + 5 => { - () - } - PathValue(payload53) => { - mbt_ffi_store8((iter_base) + 0, (25)) + let lifted28 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let ptr54 = mbt_ffi_str2ptr(payload53) - mbt_ffi_store32((iter_base) + 12, payload53.length()) - mbt_ffi_store32((iter_base) + 8, ptr54) - cleanup_list.push(ptr54) + let lifted23 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - UrlValue(payload55) => { - mbt_ffi_store8((iter_base) + 0, (26)) + let lifted22 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let ptr56 = mbt_ffi_str2ptr(payload55) - mbt_ffi_store32((iter_base) + 12, payload55.length()) - mbt_ffi_store32((iter_base) + 8, ptr56) - cleanup_list.push(ptr56) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - DatetimeValue(payload57) => { - mbt_ffi_store8((iter_base) + 0, (27)) - mbt_ffi_store64((iter_base) + 8, (payload57).seconds) - mbt_ffi_store32((iter_base) + 16, ((payload57).nanoseconds).reinterpret_as_int()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - DurationValue(payload58) => { - mbt_ffi_store8((iter_base) + 0, (28)) - mbt_ffi_store64((iter_base) + 8, (payload58).nanoseconds) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - QuantityValueNode(payload59) => { - mbt_ffi_store8((iter_base) + 0, (29)) - mbt_ffi_store64((iter_base) + 8, (payload59).mantissa) - mbt_ffi_store32((iter_base) + 16, (payload59).scale) + Option::Some(lifted22) + } + _ => panic() + } - let ptr60 = mbt_ffi_str2ptr((payload59).unit) - mbt_ffi_store32((iter_base) + 24, (payload59).unit.length()) - mbt_ffi_store32((iter_base) + 20, ptr60) - cleanup_list.push(ptr60) - - () - } - UnionValue(payload61) => { - mbt_ffi_store8((iter_base) + 0, (30)) + let lifted25 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let ptr62 = mbt_ffi_str2ptr((payload61).tag) - mbt_ffi_store32((iter_base) + 12, (payload61).tag.length()) - mbt_ffi_store32((iter_base) + 8, ptr62) - mbt_ffi_store32((iter_base) + 16, (payload61).body) - cleanup_list.push(ptr62) + let lifted24 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - SecretValue(payload63) => { - mbt_ffi_store8((iter_base) + 0, (31)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let @types.Secret(handle) = payload63 - mbt_ffi_store32((iter_base) + 8, handle) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - QuotaTokenHandle(payload64) => { - mbt_ffi_store8((iter_base) + 0, (32)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - let @types.QuotaToken(handle65) = payload64 - mbt_ffi_store32((iter_base) + 8, handle65) + Option::Some(lifted24) + } + _ => panic() + } - () - } - PermissionCardHandle(payload66) => { - mbt_ffi_store8((iter_base) + 0, (33)) + let lifted27 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let @types.PermissionCard(handle67) = payload66 - mbt_ffi_store32((iter_base) + 8, handle67) + let result26 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - StreamValue(payload68) => { - mbt_ffi_store8((iter_base) + 0, (34)) + Option::Some(result26) + } + _ => panic() + } - let @types.SchemaValueStream(handle69) = payload68 - mbt_ffi_store32((iter_base) + 8, handle69) + Option::Some(@types.NumericRestrictions::{min : lifted23, max : lifted25, unit : lifted27}) + } + _ => panic() + } - () - } - } + @types.SchemaTypeBody::S64Type(lifted28) + } + 6 => { - } + let lifted35 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let (lowered, lowered74, lowered75) = match (phantom_id) { - None => { + let lifted30 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - ((0), 0L, 0L) - } - Some(payload73) => { + let lifted29 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - ((1), ((payload73).high_bits).reinterpret_as_int64(), ((payload73).low_bits).reinterpret_as_int64()) - } - } - let return_area = mbt_ffi_malloc(40) - wasmImportMakeAgentId(ptr, agent_type_name.length(), address70, ((input).value_nodes).length(), (input).root, lowered, lowered74, lowered75, return_area); + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let lifted313 = match (mbt_ffi_load8_u((return_area) + 0)) { - 0 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - Result::Ok(result) - } - 1 => { + Option::Some(lifted29) + } + _ => panic() + } - let lifted312 = match (mbt_ffi_load8_u((return_area) + 4)) { - 0 => { + let lifted32 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let result76 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + let lifted31 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @common.AgentError::InvalidInput(result76) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let result77 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @common.AgentError::InvalidMethod(result77) - } - 2 => { + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - let result78 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + Option::Some(lifted31) + } + _ => panic() + } - @common.AgentError::InvalidType(result78) - } - 3 => { + let lifted34 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result79 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + let result33 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - @common.AgentError::InvalidAgentId(result79) - } - 4 => { + Option::Some(result33) + } + _ => panic() + } - let array274 : Array[@types.SchemaTypeNode] = []; - for index275 = 0; index275 < (mbt_ffi_load32((return_area) + 12)); index275 = index275 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 8)) + (index275 * 144) + Option::Some(@types.NumericRestrictions::{min : lifted30, max : lifted32, unit : lifted34}) + } + _ => panic() + } - let lifted260 = match (mbt_ffi_load8_u((iter_base) + 0)) { - 0 => { + @types.SchemaTypeBody::U8Type(lifted35) + } + 7 => { - @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) - } + let lifted42 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None 1 => { - @types.SchemaTypeBody::BoolType - } - 2 => { - - let lifted85 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted37 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted80 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { - - let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let lifted36 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(lifted) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) } _ => panic() } - let lifted82 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { - - let lifted81 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + Option::Some(lifted36) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted39 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted38 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - Option::Some(lifted81) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) } - _ => panic() - } - - let lifted84 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None 1 => { - let result83 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(result83) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted80, max : lifted82, unit : lifted84}) + Option::Some(lifted38) } _ => panic() } - @types.SchemaTypeBody::S8Type(lifted85) - } - 3 => { - - let lifted92 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted41 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let lifted87 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { - - let lifted86 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { - - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { - - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + let result40 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(lifted86) - } - _ => panic() - } + Option::Some(result40) + } + _ => panic() + } - let lifted89 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + Option::Some(@types.NumericRestrictions::{min : lifted37, max : lifted39, unit : lifted41}) + } + _ => panic() + } - let lifted88 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + @types.SchemaTypeBody::U16Type(lifted42) + } + 8 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let lifted49 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted44 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted43 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - Option::Some(lifted88) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) } - _ => panic() - } - - let lifted91 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None 1 => { - let result90 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(result90) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted87, max : lifted89, unit : lifted91}) + Option::Some(lifted43) } _ => panic() } - @types.SchemaTypeBody::S16Type(lifted92) - } - 4 => { - - let lifted99 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted46 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted94 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { - - let lifted93 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { - - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { - - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted45 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - Option::Some(lifted93) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) } - _ => panic() - } - - let lifted96 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None 1 => { - let lifted95 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { - - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { - - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(lifted95) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) } _ => panic() } - let lifted98 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + Option::Some(lifted45) + } + _ => panic() + } - let result97 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let lifted48 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - Option::Some(result97) - } - _ => panic() - } + let result47 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(@types.NumericRestrictions::{min : lifted94, max : lifted96, unit : lifted98}) + Option::Some(result47) } _ => panic() } - @types.SchemaTypeBody::S32Type(lifted99) + Option::Some(@types.NumericRestrictions::{min : lifted44, max : lifted46, unit : lifted48}) } - 5 => { + _ => panic() + } - let lifted106 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::U32Type(lifted49) + } + 9 => { - let lifted101 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted56 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted100 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let lifted51 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let lifted50 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(lifted100) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) } _ => panic() } - let lifted103 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { - - let lifted102 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + Option::Some(lifted50) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted53 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted52 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - Option::Some(lifted102) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) } - _ => panic() - } - - let lifted105 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None 1 => { - let result104 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(result104) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted101, max : lifted103, unit : lifted105}) + Option::Some(lifted52) } _ => panic() } - @types.SchemaTypeBody::S64Type(lifted106) - } - 6 => { - - let lifted113 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted55 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let lifted108 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let result54 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - let lifted107 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + Option::Some(result54) + } + _ => panic() + } - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + Option::Some(@types.NumericRestrictions::{min : lifted51, max : lifted53, unit : lifted55}) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + @types.SchemaTypeBody::U64Type(lifted56) + } + 10 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } - - Option::Some(lifted107) - } - _ => panic() - } - - let lifted110 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { - - let lifted109 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let lifted63 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted58 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted57 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - Option::Some(lifted109) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) } - _ => panic() - } - - let lifted112 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None 1 => { - let result111 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(result111) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted108, max : lifted110, unit : lifted112}) + Option::Some(lifted57) } _ => panic() } - @types.SchemaTypeBody::U8Type(lifted113) - } - 7 => { - - let lifted120 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted60 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted115 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { - - let lifted114 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { - - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { - - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted59 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - Option::Some(lifted114) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) } - _ => panic() - } - - let lifted117 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None 1 => { - let lifted116 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { - - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { - - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(lifted116) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) } _ => panic() } - let lifted119 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + Option::Some(lifted59) + } + _ => panic() + } - let result118 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let lifted62 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - Option::Some(result118) - } - _ => panic() - } + let result61 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(@types.NumericRestrictions::{min : lifted115, max : lifted117, unit : lifted119}) + Option::Some(result61) } _ => panic() } - @types.SchemaTypeBody::U16Type(lifted120) + Option::Some(@types.NumericRestrictions::{min : lifted58, max : lifted60, unit : lifted62}) } - 8 => { + _ => panic() + } - let lifted127 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::F32Type(lifted63) + } + 11 => { - let lifted122 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted70 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted121 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let lifted65 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let lifted64 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(lifted121) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) } _ => panic() } - let lifted124 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { - - let lifted123 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { - - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + Option::Some(lifted64) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted67 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + let lifted66 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - Option::Some(lifted123) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) } - _ => panic() - } - - let lifted126 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None 1 => { - let result125 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - Option::Some(result125) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted122, max : lifted124, unit : lifted126}) + Option::Some(lifted66) } _ => panic() } - @types.SchemaTypeBody::U32Type(lifted127) - } - 9 => { - - let lifted134 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted69 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let lifted129 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let result68 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - let lifted128 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + Option::Some(result68) + } + _ => panic() + } - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + Option::Some(@types.NumericRestrictions::{min : lifted65, max : lifted67, unit : lifted69}) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + @types.SchemaTypeBody::F64Type(lifted70) + } + 12 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.SchemaTypeBody::CharType + } + 13 => { - Option::Some(lifted128) - } - _ => panic() - } + @types.SchemaTypeBody::StringType + } + 14 => { - let lifted131 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let array83 : Array[@types.NamedFieldType] = []; + for index84 = 0; index84 < (mbt_ffi_load32((iter_base) + 12)); index84 = index84 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index84 * 68) - let lifted130 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let result71 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let lifted73 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let result72 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + Option::Some(result72) + } + _ => panic() + } - Option::Some(lifted130) - } - _ => panic() - } + let array : Array[String] = []; + for index = 0; index < (mbt_ffi_load32((iter_base) + 28)); index = index + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index * 8) - let lifted133 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let result74 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result132 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + array.push(result74) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - Option::Some(result132) - } - _ => panic() - } + let array76 : Array[String] = []; + for index77 = 0; index77 < (mbt_ffi_load32((iter_base) + 36)); index77 = index77 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index77 * 8) - Option::Some(@types.NumericRestrictions::{min : lifted129, max : lifted131, unit : lifted133}) - } - _ => panic() - } + let result75 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::U64Type(lifted134) + array76.push(result75) } - 10 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) - let lifted141 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted79 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted136 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let result78 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - let lifted135 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + Option::Some(result78) + } + _ => panic() + } - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let lifted82 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + let lifted81 = match (mbt_ffi_load8_u((iter_base) + 56)) { + 0 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.Role::Multimodal + } + 1 => { - Option::Some(lifted135) - } - _ => panic() + @types.Role::UnstructuredText } + 2 => { - let lifted138 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredBinary + } + 3 => { - let lifted137 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let result80 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.Role::Other(result80) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + Option::Some(lifted81) + } + _ => panic() + } - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + array83.push(@types.NamedFieldType::{name : result71, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted73, aliases : array, examples : array76, deprecated : lifted79, role : lifted82}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - Option::Some(lifted137) - } - _ => panic() - } + @types.SchemaTypeBody::RecordType(array83) + } + 15 => { - let lifted140 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let array100 : Array[@types.VariantCaseType] = []; + for index101 = 0; index101 < (mbt_ffi_load32((iter_base) + 12)); index101 = index101 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index101 * 72) - let result139 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result85 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(result139) - } - _ => panic() - } + let lifted86 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - Option::Some(@types.NumericRestrictions::{min : lifted136, max : lifted138, unit : lifted140}) - } - _ => panic() + Option::Some(mbt_ffi_load32((iter_base) + 12)) } + _ => panic() + } - @types.SchemaTypeBody::F32Type(lifted141) + let lifted88 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result87 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result87) + } + _ => panic() } - 11 => { - let lifted148 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let array90 : Array[String] = []; + for index91 = 0; index91 < (mbt_ffi_load32((iter_base) + 32)); index91 = index91 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index91 * 8) - let lifted143 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let result89 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted142 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + array90.push(result89) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let array93 : Array[String] = []; + for index94 = 0; index94 < (mbt_ffi_load32((iter_base) + 40)); index94 = index94 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index94 * 8) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + let result92 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + array93.push(result92) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - Option::Some(lifted142) - } - _ => panic() - } + let lifted96 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - let lifted145 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let result95 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - let lifted144 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + Option::Some(result95) + } + _ => panic() + } - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let lifted99 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + let lifted98 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + @types.Role::Multimodal + } + 1 => { - Option::Some(lifted144) - } - _ => panic() + @types.Role::UnstructuredText } + 2 => { - let lifted147 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredBinary + } + 3 => { - let result146 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result97 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - Option::Some(result146) - } - _ => panic() + @types.Role::Other(result97) } - - Option::Some(@types.NumericRestrictions::{min : lifted143, max : lifted145, unit : lifted147}) + _ => panic() } - _ => panic() - } - - @types.SchemaTypeBody::F64Type(lifted148) - } - 12 => { - @types.SchemaTypeBody::CharType + Option::Some(lifted98) + } + _ => panic() } - 13 => { - @types.SchemaTypeBody::StringType - } - 14 => { + array100.push(@types.VariantCaseType::{name : result85, payload : lifted86, metadata : @types.MetadataEnvelope::{doc : lifted88, aliases : array90, examples : array93, deprecated : lifted96, role : lifted99}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let array162 : Array[@types.NamedFieldType] = []; - for index163 = 0; index163 < (mbt_ffi_load32((iter_base) + 12)); index163 = index163 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index163 * 68) + @types.SchemaTypeBody::VariantType(array100) + } + 16 => { - let result149 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let array103 : Array[String] = []; + for index104 = 0; index104 < (mbt_ffi_load32((iter_base) + 12)); index104 = index104 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index104 * 8) - let lifted151 : String? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let result102 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result150 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + array103.push(result102) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - Option::Some(result150) - } - _ => panic() - } + @types.SchemaTypeBody::EnumType(array103) + } + 17 => { - let array : Array[String] = []; - for index153 = 0; index153 < (mbt_ffi_load32((iter_base) + 28)); index153 = index153 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index153 * 8) + let array106 : Array[String] = []; + for index107 = 0; index107 < (mbt_ffi_load32((iter_base) + 12)); index107 = index107 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index107 * 8) - let result152 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result105 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array.push(result152) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + array106.push(result105) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let array155 : Array[String] = []; - for index156 = 0; index156 < (mbt_ffi_load32((iter_base) + 36)); index156 = index156 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index156 * 8) + @types.SchemaTypeBody::FlagsType(array106) + } + 18 => { - let result154 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let array108 : Array[Int] = []; + for index109 = 0; index109 < (mbt_ffi_load32((iter_base) + 12)); index109 = index109 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index109 * 4) - array155.push(result154) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) + array108.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let lifted158 : String? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::TupleType(array108) + } + 19 => { - let result157 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) + } + 20 => { - Option::Some(result157) - } - _ => panic() - } + @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) + } + 21 => { - let lifted161 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) + } + 22 => { - let lifted160 = match (mbt_ffi_load8_u((iter_base) + 56)) { - 0 => { + @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) + } + 23 => { - @types.Role::Multimodal - } - 1 => { + let lifted110 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.Role::UnstructuredText - } - 2 => { + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - @types.Role::UnstructuredBinary - } - 3 => { + let lifted111 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let result159 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + Option::Some(mbt_ffi_load32((iter_base) + 20)) + } + _ => panic() + } - @types.Role::Other(result159) - } - _ => panic() - } + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted110, err : lifted111}) + } + 24 => { - Option::Some(lifted160) - } - _ => panic() - } + let lifted115 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - array162.push(@types.NamedFieldType::{name : result149, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted151, aliases : array, examples : array155, deprecated : lifted158, role : lifted161}}) + let array113 : Array[String] = []; + for index114 = 0; index114 < (mbt_ffi_load32((iter_base) + 16)); index114 = index114 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index114 * 8) + + let result112 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array113.push(result112) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - @types.SchemaTypeBody::RecordType(array162) + Option::Some(array113) } - 15 => { + _ => panic() + } - let array179 : Array[@types.VariantCaseType] = []; - for index180 = 0; index180 < (mbt_ffi_load32((iter_base) + 12)); index180 = index180 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index180 * 72) + let lifted116 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let result164 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - let lifted165 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted117 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } - let lifted167 : String? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted119 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - let result166 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result118 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - Option::Some(result166) - } - _ => panic() - } + Option::Some(result118) + } + _ => panic() + } - let array169 : Array[String] = []; - for index170 = 0; index170 < (mbt_ffi_load32((iter_base) + 32)); index170 = index170 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index170 * 8) + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted115, min_length : lifted116, max_length : lifted117, regex : lifted119}) + } + 25 => { - let result168 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted123 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - array169.push(result168) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + let array121 : Array[String] = []; + for index122 = 0; index122 < (mbt_ffi_load32((iter_base) + 16)); index122 = index122 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index122 * 8) - let array172 : Array[String] = []; - for index173 = 0; index173 < (mbt_ffi_load32((iter_base) + 40)); index173 = index173 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index173 * 8) + let result120 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result171 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + array121.push(result120) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - array172.push(result171) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) + Option::Some(array121) + } + _ => panic() + } - let lifted175 : String? = match mbt_ffi_load8_u((iter_base) + 44) { - 0 => Option::None - 1 => { + let lifted124 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let result174 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - Option::Some(result174) - } - _ => panic() - } + let lifted125 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { - let lifted178 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { - 0 => Option::None - 1 => { + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } - let lifted177 = match (mbt_ffi_load8_u((iter_base) + 60)) { - 0 => { + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted123, min_bytes : lifted124, max_bytes : lifted125}) + } + 26 => { - @types.Role::Multimodal - } - 1 => { + let lifted129 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - @types.Role::UnstructuredText - } - 2 => { + let array127 : Array[String] = []; + for index128 = 0; index128 < (mbt_ffi_load32((iter_base) + 20)); index128 = index128 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index128 * 8) - @types.Role::UnstructuredBinary - } - 3 => { + let result126 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result176 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + array127.push(result126) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - @types.Role::Other(result176) - } - _ => panic() - } + Option::Some(array127) + } + _ => panic() + } - Option::Some(lifted177) - } - _ => panic() - } + let lifted133 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - array179.push(@types.VariantCaseType::{name : result164, payload : lifted165, metadata : @types.MetadataEnvelope::{doc : lifted167, aliases : array169, examples : array172, deprecated : lifted175, role : lifted178}}) + let array131 : Array[String] = []; + for index132 = 0; index132 < (mbt_ffi_load32((iter_base) + 32)); index132 = index132 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index132 * 8) + + let result130 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array131.push(result130) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - @types.SchemaTypeBody::VariantType(array179) + Option::Some(array131) } - 16 => { + _ => panic() + } - let array182 : Array[String] = []; - for index183 = 0; index183 < (mbt_ffi_load32((iter_base) + 12)); index183 = index183 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index183 * 8) + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted129, allowed_extensions : lifted133}) + } + 27 => { - let result181 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted137 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - array182.push(result181) + let array135 : Array[String] = []; + for index136 = 0; index136 < (mbt_ffi_load32((iter_base) + 16)); index136 = index136 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index136 * 8) + + let result134 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array135.push(result134) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - @types.SchemaTypeBody::EnumType(array182) + Option::Some(array135) } - 17 => { + _ => panic() + } - let array185 : Array[String] = []; - for index186 = 0; index186 < (mbt_ffi_load32((iter_base) + 12)); index186 = index186 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index186 * 8) + let lifted141 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let result184 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let array139 : Array[String] = []; + for index140 = 0; index140 < (mbt_ffi_load32((iter_base) + 28)); index140 = index140 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index140 * 8) - array185.push(result184) + let result138 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array139.push(result138) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - @types.SchemaTypeBody::FlagsType(array185) + Option::Some(array139) } - 18 => { + _ => panic() + } - let array187 : Array[Int] = []; - for index188 = 0; index188 < (mbt_ffi_load32((iter_base) + 12)); index188 = index188 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index188 * 4) + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted137, allowed_hosts : lifted141}) + } + 28 => { - array187.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + @types.SchemaTypeBody::DatetimeType + } + 29 => { - @types.SchemaTypeBody::TupleType(array187) - } - 19 => { + @types.SchemaTypeBody::DurationType + } + 30 => { - @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) - } - 20 => { + let result142 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) - } - 21 => { + let array144 : Array[String] = []; + for index145 = 0; index145 < (mbt_ffi_load32((iter_base) + 20)); index145 = index145 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index145 * 8) - @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) - } - 22 => { + let result143 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) - } - 23 => { + array144.push(result143) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let lifted189 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted147 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + let result146 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - let lifted190 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result146}) + } + _ => panic() + } - Option::Some(mbt_ffi_load32((iter_base) + 20)) - } - _ => panic() - } + let lifted149 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted189, err : lifted190}) + let result148 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result148}) } - 24 => { + _ => panic() + } - let lifted194 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result142, allowed_suffixes : array144, min : lifted147, max : lifted149}) + } + 31 => { - let array192 : Array[String] = []; - for index193 = 0; index193 < (mbt_ffi_load32((iter_base) + 16)); index193 = index193 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index193 * 8) + let array173 : Array[@types.UnionBranch] = []; + for index174 = 0; index174 < (mbt_ffi_load32((iter_base) + 12)); index174 = index174 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index174 * 92) - let result191 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result150 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array192.push(result191) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + let lifted159 = match (mbt_ffi_load8_u((iter_base) + 12)) { + 0 => { - Option::Some(array192) - } - _ => panic() + let result151 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Prefix(result151) } + 1 => { - let lifted195 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { + let result152 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) - } - _ => panic() + @types.DiscriminatorRule::Suffix(result152) } + 2 => { - let lifted196 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { - 0 => Option::None - 1 => { + let result153 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) - } - _ => panic() + @types.DiscriminatorRule::Contains(result153) } + 3 => { - let lifted198 : String? = match mbt_ffi_load8_u((iter_base) + 36) { - 0 => Option::None - 1 => { - - let result197 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + let result154 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some(result197) - } - _ => panic() + @types.DiscriminatorRule::Regex(result154) } + 4 => { - @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted194, min_length : lifted195, max_length : lifted196, regex : lifted198}) - } - 25 => { - - let lifted202 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let result155 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let array200 : Array[String] = []; - for index201 = 0; index201 < (mbt_ffi_load32((iter_base) + 16)); index201 = index201 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index201 * 8) + let lifted157 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - let result199 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result156 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - array200.push(result199) + Option::Some(result156) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - - Option::Some(array200) + _ => panic() } - _ => panic() - } - - let lifted203 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { - Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) - } - _ => panic() + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result155, literal : lifted157}) } + 5 => { - let lifted204 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { - 0 => Option::None - 1 => { + let result158 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) - } - _ => panic() + @types.DiscriminatorRule::FieldAbsent(result158) } - - @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted202, min_bytes : lifted203, max_bytes : lifted204}) + _ => panic() } - 26 => { - let lifted208 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { - - let array206 : Array[String] = []; - for index207 = 0; index207 < (mbt_ffi_load32((iter_base) + 20)); index207 = index207 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index207 * 8) - - let result205 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted161 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - array206.push(result205) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + let result160 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - Option::Some(array206) - } - _ => panic() + Option::Some(result160) } + _ => panic() + } - let lifted212 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { + let array163 : Array[String] = []; + for index164 = 0; index164 < (mbt_ffi_load32((iter_base) + 52)); index164 = index164 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index164 * 8) - let array210 : Array[String] = []; - for index211 = 0; index211 < (mbt_ffi_load32((iter_base) + 32)); index211 = index211 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index211 * 8) + let result162 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result209 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + array163.push(result162) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) - array210.push(result209) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + let array166 : Array[String] = []; + for index167 = 0; index167 < (mbt_ffi_load32((iter_base) + 60)); index167 = index167 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index167 * 8) - Option::Some(array210) - } - _ => panic() - } + let result165 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted208, allowed_extensions : lifted212}) + array166.push(result165) } - 27 => { - - let lifted216 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { - - let array214 : Array[String] = []; - for index215 = 0; index215 < (mbt_ffi_load32((iter_base) + 16)); index215 = index215 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index215 * 8) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) - let result213 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted169 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - array214.push(result213) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + let result168 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(array214) - } - _ => panic() + Option::Some(result168) } + _ => panic() + } - let lifted220 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { + let lifted172 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + 0 => Option::None + 1 => { - let array218 : Array[String] = []; - for index219 = 0; index219 < (mbt_ffi_load32((iter_base) + 28)); index219 = index219 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index219 * 8) + let lifted171 = match (mbt_ffi_load8_u((iter_base) + 80)) { + 0 => { - let result217 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.Role::Multimodal + } + 1 => { - array218.push(result217) + @types.Role::UnstructuredText } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + 2 => { - Option::Some(array218) + @types.Role::UnstructuredBinary + } + 3 => { + + let result170 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + + @types.Role::Other(result170) + } + _ => panic() } - _ => panic() - } - @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted216, allowed_hosts : lifted220}) + Option::Some(lifted171) + } + _ => panic() } - 28 => { - @types.SchemaTypeBody::DatetimeType - } - 29 => { + array173.push(@types.UnionBranch::{tag : result150, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted159, metadata : @types.MetadataEnvelope::{doc : lifted161, aliases : array163, examples : array166, deprecated : lifted169, role : lifted172}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::DurationType - } - 30 => { + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array173}) + } + 32 => { - let result221 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let lifted176 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - let array223 : Array[String] = []; - for index224 = 0; index224 < (mbt_ffi_load32((iter_base) + 20)); index224 = index224 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index224 * 8) + let result175 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let result222 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + Option::Some(result175) + } + _ => panic() + } - array223.push(result222) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted176}) + } + 33 => { - let lifted226 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { + let lifted178 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let result225 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + let result177 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result225}) - } - _ => panic() - } + Option::Some(result177) + } + _ => panic() + } - let lifted228 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted178}) + } + 34 => { - let result227 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) + } + 35 => { - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result227}) - } - _ => panic() - } + let lifted179 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result221, allowed_suffixes : array223, min : lifted226, max : lifted228}) + Option::Some(mbt_ffi_load32((iter_base) + 12)) } - 31 => { - - let array252 : Array[@types.UnionBranch] = []; - for index253 = 0; index253 < (mbt_ffi_load32((iter_base) + 12)); index253 = index253 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index253 * 92) + _ => panic() + } - let result229 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.SchemaTypeBody::FutureType(lifted179) + } + 36 => { - let lifted238 = match (mbt_ffi_load8_u((iter_base) + 12)) { - 0 => { + let lifted180 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let result230 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - @types.DiscriminatorRule::Prefix(result230) - } - 1 => { + @types.SchemaTypeBody::StreamType(lifted180) + } + _ => panic() + } - let result231 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let lifted183 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + 0 => Option::None + 1 => { - @types.DiscriminatorRule::Suffix(result231) - } - 2 => { + let result182 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) - let result232 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + Option::Some(result182) + } + _ => panic() + } - @types.DiscriminatorRule::Contains(result232) - } - 3 => { + let array185 : Array[String] = []; + for index186 = 0; index186 < (mbt_ffi_load32((iter_base) + 104)); index186 = index186 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index186 * 8) - let result233 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result184 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.DiscriminatorRule::Regex(result233) - } - 4 => { + array185.push(result184) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) - let result234 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let array188 : Array[String] = []; + for index189 = 0; index189 < (mbt_ffi_load32((iter_base) + 112)); index189 = index189 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index189 * 8) - let lifted236 : String? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { + let result187 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result235 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) + array188.push(result187) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) - Option::Some(result235) - } - _ => panic() - } + let lifted191 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + 0 => Option::None + 1 => { - @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result234, literal : lifted236}) - } - 5 => { + let result190 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) - let result237 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + Option::Some(result190) + } + _ => panic() + } - @types.DiscriminatorRule::FieldAbsent(result237) - } - _ => panic() - } - - let lifted240 : String? = match mbt_ffi_load8_u((iter_base) + 36) { - 0 => Option::None - 1 => { - - let result239 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - - Option::Some(result239) - } - _ => panic() - } - - let array242 : Array[String] = []; - for index243 = 0; index243 < (mbt_ffi_load32((iter_base) + 52)); index243 = index243 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index243 * 8) - - let result241 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - - array242.push(result241) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) - - let array245 : Array[String] = []; - for index246 = 0; index246 < (mbt_ffi_load32((iter_base) + 60)); index246 = index246 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index246 * 8) - - let result244 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted194 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + 0 => Option::None + 1 => { - array245.push(result244) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) + let lifted193 = match (mbt_ffi_load8_u((iter_base) + 132)) { + 0 => { - let lifted248 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + @types.Role::Multimodal + } + 1 => { - let result247 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + @types.Role::UnstructuredText + } + 2 => { - Option::Some(result247) - } - _ => panic() - } + @types.Role::UnstructuredBinary + } + 3 => { - let lifted251 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { - 0 => Option::None - 1 => { + let result192 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) - let lifted250 = match (mbt_ffi_load8_u((iter_base) + 80)) { - 0 => { + @types.Role::Other(result192) + } + _ => panic() + } - @types.Role::Multimodal - } - 1 => { + Option::Some(lifted193) + } + _ => panic() + } - @types.Role::UnstructuredText - } - 2 => { + array195.push(@types.SchemaTypeNode::{body : lifted181, metadata : @types.MetadataEnvelope::{doc : lifted183, aliases : array185, examples : array188, deprecated : lifted191, role : lifted194}}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 32)) - @types.Role::UnstructuredBinary - } - 3 => { + let array200 : Array[@types.SchemaTypeDef] = []; + for index201 = 0; index201 < (mbt_ffi_load32((return_area) + 44)); index201 = index201 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 40)) + (index201 * 24) - let result249 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + let result197 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.Role::Other(result249) - } - _ => panic() - } + let lifted199 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - Option::Some(lifted250) - } - _ => panic() - } + let result198 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - array252.push(@types.UnionBranch::{tag : result229, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted238, metadata : @types.MetadataEnvelope::{doc : lifted240, aliases : array242, examples : array245, deprecated : lifted248, role : lifted251}}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + Option::Some(result198) + } + _ => panic() + } - @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array252}) - } - 32 => { + array200.push(@types.SchemaTypeDef::{id : result197, name : lifted199, body : mbt_ffi_load32((iter_base) + 20)}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 40)) - let lifted255 : String? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let lifted203 : String? = match mbt_ffi_load8_u((return_area) + 52) { + 0 => Option::None + 1 => { - let result254 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result202 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 56), mbt_ffi_load32((return_area) + 60)) - Option::Some(result254) - } - _ => panic() - } + Option::Some(result202) + } + _ => panic() + } - @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted255}) - } - 33 => { + let result204 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 64), mbt_ffi_load32((return_area) + 68)) - let lifted257 : String? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted206 : String? = match mbt_ffi_load8_u((return_area) + 72) { + 0 => Option::None + 1 => { - let result256 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + let result205 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 76), mbt_ffi_load32((return_area) + 80)) - Option::Some(result256) - } - _ => panic() - } + Option::Some(result205) + } + _ => panic() + } - @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted257}) - } - 34 => { + let lifted224 = match (mbt_ffi_load8_u((return_area) + 84)) { + 0 => { - @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) - } - 35 => { + let array222 : Array[@common.NamedField] = []; + for index223 = 0; index223 < (mbt_ffi_load32((return_area) + 92)); index223 = index223 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 88)) + (index223 * 72) - let lifted258 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let result207 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + let lifted208 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { - @types.SchemaTypeBody::FutureType(lifted258) + @common.FieldSource::UserSupplied } - 36 => { - - let lifted259 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { - - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + 1 => { - @types.SchemaTypeBody::StreamType(lifted259) + @common.FieldSource::AutoInjected(@common.AutoInjectedKind::from(mbt_ffi_load8_u((iter_base) + 9))) } _ => panic() } - let lifted262 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + let lifted210 : String? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let result261 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) + let result209 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - Option::Some(result261) + Option::Some(result209) } _ => panic() } - let array264 : Array[String] = []; - for index265 = 0; index265 < (mbt_ffi_load32((iter_base) + 104)); index265 = index265 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index265 * 8) + let array212 : Array[String] = []; + for index213 = 0; index213 < (mbt_ffi_load32((iter_base) + 32)); index213 = index213 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index213 * 8) - let result263 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result211 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array264.push(result263) + array212.push(result211) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - let array267 : Array[String] = []; - for index268 = 0; index268 < (mbt_ffi_load32((iter_base) + 112)); index268 = index268 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index268 * 8) + let array215 : Array[String] = []; + for index216 = 0; index216 < (mbt_ffi_load32((iter_base) + 40)); index216 = index216 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index216 * 8) - let result266 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result214 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array267.push(result266) + array215.push(result214) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let lifted270 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + let lifted218 : String? = match mbt_ffi_load8_u((iter_base) + 44) { 0 => Option::None 1 => { - let result269 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) + let result217 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - Option::Some(result269) + Option::Some(result217) } _ => panic() } - let lifted273 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + let lifted221 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { 0 => Option::None 1 => { - let lifted272 = match (mbt_ffi_load8_u((iter_base) + 132)) { + let lifted220 = match (mbt_ffi_load8_u((iter_base) + 60)) { 0 => { @types.Role::Multimodal @@ -10320,1220 +9997,1341 @@ pub fn make_agent_id(agent_type_name : String, input : @types.SchemaValueTree, p } 3 => { - let result271 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) + let result219 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - @types.Role::Other(result271) + @types.Role::Other(result219) } _ => panic() } - Option::Some(lifted272) + Option::Some(lifted220) } _ => panic() } - array274.push(@types.SchemaTypeNode::{body : lifted260, metadata : @types.MetadataEnvelope::{doc : lifted262, aliases : array264, examples : array267, deprecated : lifted270, role : lifted273}}) + array222.push(@common.NamedField::{name : result207, source : lifted208, schema : mbt_ffi_load32((iter_base) + 12), metadata : @types.MetadataEnvelope::{doc : lifted210, aliases : array212, examples : array215, deprecated : lifted218, role : lifted221}}) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 8)) - - let array279 : Array[@types.SchemaTypeDef] = []; - for index280 = 0; index280 < (mbt_ffi_load32((return_area) + 20)); index280 = index280 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 16)) + (index280 * 24) + mbt_ffi_free(mbt_ffi_load32((return_area) + 88)) - let result276 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @common.InputSchema::Parameters(array222) + } + _ => panic() + } - let lifted278 : String? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let array272 : Array[@common.AgentMethod] = []; + for index273 = 0; index273 < (mbt_ffi_load32((return_area) + 100)); index273 = index273 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 96)) + (index273 * 88) - let result277 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + let result225 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(result277) - } - _ => panic() - } + let result226 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - array279.push(@types.SchemaTypeDef::{id : result276, name : lifted278, body : mbt_ffi_load32((iter_base) + 20)}) + let array247 : Array[@common.HttpEndpointDetails] = []; + for index248 = 0; index248 < (mbt_ffi_load32((iter_base) + 20)); index248 = index248 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index248 * 48) + + let lifted228 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { + + @common.HttpMethod::Get + } + 1 => { + + @common.HttpMethod::Head + } + 2 => { + + @common.HttpMethod::Post + } + 3 => { + + @common.HttpMethod::Put + } + 4 => { + + @common.HttpMethod::Delete + } + 5 => { + + @common.HttpMethod::Connect + } + 6 => { + + @common.HttpMethod::Options + } + 7 => { + + @common.HttpMethod::Trace + } + 8 => { + + @common.HttpMethod::Patch + } + 9 => { + + let result227 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) + + @common.HttpMethod::Custom(result227) + } + _ => panic() } - mbt_ffi_free(mbt_ffi_load32((return_area) + 16)) - let array310 : Array[@types.SchemaValueNode] = []; - for index311 = 0; index311 < (mbt_ffi_load32((return_area) + 32)); index311 = index311 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 28)) + (index311 * 32) + let array233 : Array[@common.PathSegment] = []; + for index234 = 0; index234 < (mbt_ffi_load32((iter_base) + 16)); index234 = index234 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index234 * 12) - let lifted309 = match (mbt_ffi_load8_u((iter_base) + 0)) { + let lifted232 = match (mbt_ffi_load8_u((iter_base) + 0)) { 0 => { - @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) + let result229 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) + + @common.PathSegment::Literal(result229) } 1 => { - @types.SchemaValueNode::S8Value((mbt_ffi_load8((iter_base) + 8))) + @common.PathSegment::SystemVariable(@common.SystemVariable::from(mbt_ffi_load8_u((iter_base) + 4))) } 2 => { - @types.SchemaValueNode::S16Value((mbt_ffi_load16((iter_base) + 8))) - } - 3 => { + let result230 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::S32Value(mbt_ffi_load32((iter_base) + 8)) + @common.PathSegment::PathVariable(@common.PathVariable::{variable_name : result230}) } - 4 => { + 3 => { - @types.SchemaValueNode::S64Value(mbt_ffi_load64((iter_base) + 8)) - } - 5 => { + let result231 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::U8Value((mbt_ffi_load8_u((iter_base) + 8)).to_byte()) + @common.PathSegment::RemainingPathVariable(@common.PathVariable::{variable_name : result231}) } - 6 => { + _ => panic() + } - @types.SchemaValueNode::U16Value((mbt_ffi_load16_u((iter_base) + 8).land(0xFFFF).reinterpret_as_uint())) - } - 7 => { + array233.push(lifted232) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::U32Value((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) - } - 8 => { + let array237 : Array[@common.HeaderVariable] = []; + for index238 = 0; index238 < (mbt_ffi_load32((iter_base) + 24)); index238 = index238 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 20)) + (index238 * 16) - @types.SchemaValueNode::U64Value((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64()) - } - 9 => { + let result235 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::F32Value(mbt_ffi_loadf32((iter_base) + 8)) - } - 10 => { + let result236 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::F64Value(mbt_ffi_loadf64((iter_base) + 8)) - } - 11 => { + array237.push(@common.HeaderVariable::{header_name : result235, variable_name : result236}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 20)) - @types.SchemaValueNode::CharValue(Int::unsafe_to_char(mbt_ffi_load32((iter_base) + 8))) - } - 12 => { + let array241 : Array[@common.QueryVariable] = []; + for index242 = 0; index242 < (mbt_ffi_load32((iter_base) + 32)); index242 = index242 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index242 * 16) - let result281 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result239 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::StringValue(result281) - } - 13 => { + let result240 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let array282 : Array[Int] = []; - for index283 = 0; index283 < (mbt_ffi_load32((iter_base) + 12)); index283 = index283 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index283 * 4) + array241.push(@common.QueryVariable::{query_param_name : result239, variable_name : result240}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - array282.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let lifted243 : @common.AuthDetails? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - @types.SchemaValueNode::RecordValue(array282) - } - 14 => { + Option::Some(@common.AuthDetails::{required : (mbt_ffi_load8_u((iter_base) + 37) != 0)}) + } + _ => panic() + } - let lifted284 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let array245 : Array[String] = []; + for index246 = 0; index246 < (mbt_ffi_load32((iter_base) + 44)); index246 = index246 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 40)) + (index246 * 8) - Option::Some(mbt_ffi_load32((iter_base) + 16)) - } - _ => panic() - } + let result244 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted284}) - } - 15 => { + array245.push(result244) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 40)) - @types.SchemaValueNode::EnumValue((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) - } - 16 => { + array247.push(@common.HttpEndpointDetails::{http_method : lifted228, path_suffix : array233, header_vars : array237, query_vars : array241, auth_details : lifted243, cors_options : @common.CorsOptions::{allowed_patterns : array245}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let array285 : Array[Bool] = []; - for index286 = 0; index286 < (mbt_ffi_load32((iter_base) + 12)); index286 = index286 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index286 * 1) + let lifted250 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - array285.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let result249 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - @types.SchemaValueNode::FlagsValue(array285) - } - 17 => { + Option::Some(result249) + } + _ => panic() + } - let array287 : Array[Int] = []; - for index288 = 0; index288 < (mbt_ffi_load32((iter_base) + 12)); index288 = index288 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index288 * 4) + let lifted268 = match (mbt_ffi_load8_u((iter_base) + 36)) { + 0 => { - array287.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let array266 : Array[@common.NamedField] = []; + for index267 = 0; index267 < (mbt_ffi_load32((iter_base) + 44)); index267 = index267 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 40)) + (index267 * 72) - @types.SchemaValueNode::TupleValue(array287) - } - 18 => { + let result251 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let array289 : Array[Int] = []; - for index290 = 0; index290 < (mbt_ffi_load32((iter_base) + 12)); index290 = index290 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index290 * 4) + let lifted252 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { - array289.push(mbt_ffi_load32((iter_base) + 0)) + @common.FieldSource::UserSupplied } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + 1 => { - @types.SchemaValueNode::ListValue(array289) + @common.FieldSource::AutoInjected(@common.AutoInjectedKind::from(mbt_ffi_load8_u((iter_base) + 9))) + } + _ => panic() } - 19 => { - let array291 : Array[Int] = []; - for index292 = 0; index292 < (mbt_ffi_load32((iter_base) + 12)); index292 = index292 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index292 * 4) + let lifted254 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - array291.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let result253 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - @types.SchemaValueNode::FixedListValue(array291) + Option::Some(result253) + } + _ => panic() } - 20 => { - let array293 : Array[@types.MapEntry] = []; - for index294 = 0; index294 < (mbt_ffi_load32((iter_base) + 12)); index294 = index294 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index294 * 8) + let array256 : Array[String] = []; + for index257 = 0; index257 < (mbt_ffi_load32((iter_base) + 32)); index257 = index257 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index257 * 8) - array293.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let result255 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::MapValue(array293) + array256.push(result255) } - 21 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - let lifted295 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let array259 : Array[String] = []; + for index260 = 0; index260 < (mbt_ffi_load32((iter_base) + 40)); index260 = index260 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index260 * 8) - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + let result258 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::OptionValue(lifted295) + array259.push(result258) } - 22 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let lifted298 = match (mbt_ffi_load8_u((iter_base) + 8)) { - 0 => { + let lifted262 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - let lifted296 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { - - Option::Some(mbt_ffi_load32((iter_base) + 16)) - } - _ => panic() - } - - @types.ResultValuePayload::OkValue(lifted296) - } - 1 => { - - let lifted297 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { - - Option::Some(mbt_ffi_load32((iter_base) + 16)) - } - _ => panic() - } + let result261 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - @types.ResultValuePayload::ErrValue(lifted297) - } - _ => panic() + Option::Some(result261) } - - @types.SchemaValueNode::ResultValue(lifted298) + _ => panic() } - 23 => { - - let result299 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let lifted301 : String? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { - - let result300 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let lifted265 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - Option::Some(result300) - } - _ => panic() - } + let lifted264 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result299, language : lifted301}) - } - 24 => { + @types.Role::Multimodal + } + 1 => { - let result302 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + @types.Role::UnstructuredText + } + 2 => { - let lifted304 : String? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredBinary + } + 3 => { - let result303 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result263 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - Option::Some(result303) + @types.Role::Other(result263) + } + _ => panic() } - _ => panic() - } - - @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result302, mime_type : lifted304}) - } - 25 => { - - let result305 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - - @types.SchemaValueNode::PathValue(result305) - } - 26 => { - let result306 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - - @types.SchemaValueNode::UrlValue(result306) + Option::Some(lifted264) + } + _ => panic() } - 27 => { - @types.SchemaValueNode::DatetimeValue(@types.Datetime::{seconds : mbt_ffi_load64((iter_base) + 8), nanoseconds : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}) - } - 28 => { + array266.push(@common.NamedField::{name : result251, source : lifted252, schema : mbt_ffi_load32((iter_base) + 12), metadata : @types.MetadataEnvelope::{doc : lifted254, aliases : array256, examples : array259, deprecated : lifted262, role : lifted265}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 40)) - @types.SchemaValueNode::DurationValue(@types.DurationValuePayload::{nanoseconds : mbt_ffi_load64((iter_base) + 8)}) - } - 29 => { + @common.InputSchema::Parameters(array266) + } + _ => panic() + } - let result307 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let lifted269 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result307}) - } - 30 => { + @common.OutputSchema::Unit + } + 1 => { - let result308 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + @common.OutputSchema::Single(mbt_ffi_load32((iter_base) + 52)) + } + _ => panic() + } - @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result308, body : mbt_ffi_load32((iter_base) + 16)}) - } - 31 => { + let lifted271 : @common.ReadOnlyConfig? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - @types.SchemaValueNode::SecretValue(@types.Secret::Secret(mbt_ffi_load32((iter_base) + 8))) - } - 32 => { + let lifted270 = match (mbt_ffi_load8_u((iter_base) + 64)) { + 0 => { - @types.SchemaValueNode::QuotaTokenHandle(@types.QuotaToken::QuotaToken(mbt_ffi_load32((iter_base) + 8))) + @common.CachePolicy::NoCache } - 33 => { + 1 => { - @types.SchemaValueNode::PermissionCardHandle(@types.PermissionCard::PermissionCard(mbt_ffi_load32((iter_base) + 8))) + @common.CachePolicy::UntilWrite } - 34 => { + 2 => { - @types.SchemaValueNode::StreamValue(@types.SchemaValueStream::SchemaValueStream(mbt_ffi_load32((iter_base) + 8))) + @common.CachePolicy::Ttl((mbt_ffi_load64((iter_base) + 72)).reinterpret_as_uint64()) } _ => panic() } - array310.push(lifted309) + Option::Some(@common.ReadOnlyConfig::{cache_policy : lifted270, uses_principal : (mbt_ffi_load8_u((iter_base) + 80) != 0)}) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 28)) - - @common.AgentError::CustomError(@types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array274, defs : array279, root : mbt_ffi_load32((return_area) + 24)}, value : @types.SchemaValueTree::{value_nodes : array310, root : mbt_ffi_load32((return_area) + 36)}}) + _ => panic() } - _ => panic() + + array272.push(@common.AgentMethod::{name : result225, description : result226, http_endpoint : array247, prompt_hint : lifted250, input_schema : lifted268, output_schema : lifted269, read_only : lifted271}) } + mbt_ffi_free(mbt_ffi_load32((return_area) + 96)) - Result::Err(lifted312) - } - _ => panic() - } - let ret = lifted313 - mbt_ffi_free(ptr) - mbt_ffi_free(address70) - mbt_ffi_free(return_area) + let array552 : Array[@common.AgentDependency] = []; + for index553 = 0; index553 < (mbt_ffi_load32((return_area) + 108)); index553 = index553 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 104)) + (index553 * 92) - cleanup_list.each(mbt_ffi_free) - return ret + let result274 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) -} -///| -/// Parses an agent-id (created by `make-agent-id`) into an agent type name and its constructor parameters -/// and an optional phantom ID. -/// -/// The constructor parameters are returned as a self-contained typed value -/// (graph + value tree) so the receiver can interpret them without an -/// external schema registry. -pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaValue, @types.Uuid?), @common.AgentError] { + let lifted276 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let ptr = mbt_ffi_str2ptr(agent_id) - let return_area = mbt_ffi_malloc(72) - wasmImportParseAgentId(ptr, agent_id.length(), return_area); + let result275 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - let lifted471 = match (mbt_ffi_load8_u((return_area) + 0)) { - 0 => { + Option::Some(result275) + } + _ => panic() + } - let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + let array473 : Array[@types.SchemaTypeNode] = []; + for index474 = 0; index474 < (mbt_ffi_load32((iter_base) + 24)); index474 = index474 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 20)) + (index474 * 144) - let array193 : Array[@types.SchemaTypeNode] = []; - for index194 = 0; index194 < (mbt_ffi_load32((return_area) + 20)); index194 = index194 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 16)) + (index194 * 144) + let lifted459 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - let lifted179 = match (mbt_ffi_load8_u((iter_base) + 0)) { - 0 => { + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { - @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) - } - 1 => { + @types.SchemaTypeBody::BoolType + } + 2 => { - @types.SchemaTypeBody::BoolType - } - 2 => { + let lifted283 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted5 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted278 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted0 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted277 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted277) } - - Option::Some(lifted) + _ => panic() } - _ => panic() - } - let lifted2 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted280 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted1 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted279 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted1) + Option::Some(lifted279) + } + _ => panic() } - _ => panic() - } - let lifted4 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted282 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result281 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result3) + Option::Some(result281) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted0, max : lifted2, unit : lifted4}) + Option::Some(@types.NumericRestrictions::{min : lifted278, max : lifted280, unit : lifted282}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::S8Type(lifted283) } + 3 => { - @types.SchemaTypeBody::S8Type(lifted5) - } - 3 => { + let lifted290 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted12 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted285 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted7 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted284 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted6 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted284) } - - Option::Some(lifted6) + _ => panic() } - _ => panic() - } - let lifted9 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted287 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted8 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted286 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted8) + Option::Some(lifted286) + } + _ => panic() } - _ => panic() - } - let lifted11 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted289 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result10 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result288 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result10) + Option::Some(result288) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted7, max : lifted9, unit : lifted11}) + Option::Some(@types.NumericRestrictions::{min : lifted285, max : lifted287, unit : lifted289}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::S16Type(lifted290) } + 4 => { - @types.SchemaTypeBody::S16Type(lifted12) - } - 4 => { + let lifted297 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted19 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted292 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted14 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted291 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted13 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted291) } - - Option::Some(lifted13) + _ => panic() } - _ => panic() - } - let lifted16 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted294 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted15 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted293 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted15) + Option::Some(lifted293) + } + _ => panic() } - _ => panic() - } - let lifted18 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted296 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result17 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result295 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result17) + Option::Some(result295) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted14, max : lifted16, unit : lifted18}) + Option::Some(@types.NumericRestrictions::{min : lifted292, max : lifted294, unit : lifted296}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::S32Type(lifted297) } + 5 => { - @types.SchemaTypeBody::S32Type(lifted19) - } - 5 => { + let lifted304 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted26 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted299 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted21 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted298 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted20 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted298) } - - Option::Some(lifted20) + _ => panic() } - _ => panic() - } - let lifted23 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted301 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted22 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted300 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted22) + Option::Some(lifted300) + } + _ => panic() } - _ => panic() - } - let lifted25 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted303 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result24 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result302 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result24) + Option::Some(result302) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted21, max : lifted23, unit : lifted25}) + Option::Some(@types.NumericRestrictions::{min : lifted299, max : lifted301, unit : lifted303}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::S64Type(lifted304) } + 6 => { - @types.SchemaTypeBody::S64Type(lifted26) - } - 6 => { + let lifted311 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted33 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted306 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted28 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted305 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted27 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted305) } - - Option::Some(lifted27) + _ => panic() } - _ => panic() - } - let lifted30 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted308 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted29 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted307 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted29) + Option::Some(lifted307) + } + _ => panic() } - _ => panic() - } - let lifted32 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted310 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result31 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result309 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result31) + Option::Some(result309) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted28, max : lifted30, unit : lifted32}) + Option::Some(@types.NumericRestrictions::{min : lifted306, max : lifted308, unit : lifted310}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::U8Type(lifted311) } + 7 => { - @types.SchemaTypeBody::U8Type(lifted33) - } - 7 => { + let lifted318 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted40 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted313 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted35 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted312 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted34 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted312) } - - Option::Some(lifted34) + _ => panic() } - _ => panic() - } - let lifted37 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted315 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted36 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted314 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted36) + Option::Some(lifted314) + } + _ => panic() } - _ => panic() - } - let lifted39 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted317 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result38 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result316 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result38) + Option::Some(result316) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted35, max : lifted37, unit : lifted39}) + Option::Some(@types.NumericRestrictions::{min : lifted313, max : lifted315, unit : lifted317}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::U16Type(lifted318) } + 8 => { - @types.SchemaTypeBody::U16Type(lifted40) - } - 8 => { + let lifted325 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted47 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted320 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted42 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted319 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted41 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted319) } - - Option::Some(lifted41) + _ => panic() } - _ => panic() - } - let lifted44 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted322 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted43 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted321 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted43) + Option::Some(lifted321) + } + _ => panic() } - _ => panic() - } - let lifted46 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted324 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result45 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result323 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result45) + Option::Some(result323) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted42, max : lifted44, unit : lifted46}) + Option::Some(@types.NumericRestrictions::{min : lifted320, max : lifted322, unit : lifted324}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::U32Type(lifted325) } + 9 => { - @types.SchemaTypeBody::U32Type(lifted47) - } - 9 => { + let lifted332 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted54 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted327 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted49 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted326 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted48 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted326) } - - Option::Some(lifted48) + _ => panic() } - _ => panic() - } - let lifted51 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted329 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let lifted50 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted328 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted50) + Option::Some(lifted328) + } + _ => panic() } - _ => panic() - } - let lifted53 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let lifted331 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result52 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result330 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result52) + Option::Some(result330) + } + _ => panic() } - _ => panic() - } - Option::Some(@types.NumericRestrictions::{min : lifted49, max : lifted51, unit : lifted53}) + Option::Some(@types.NumericRestrictions::{min : lifted327, max : lifted329, unit : lifted331}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::U64Type(lifted332) } + 10 => { - @types.SchemaTypeBody::U64Type(lifted54) - } - 10 => { + let lifted339 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted61 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let lifted334 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let lifted56 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let lifted333 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let lifted55 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() + Option::Some(lifted333) } + _ => panic() + } - Option::Some(lifted55) + let lifted336 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted335 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted335) + } + _ => panic() } - _ => panic() + + let lifted338 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result337 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result337) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted334, max : lifted336, unit : lifted338}) } + _ => panic() + } - let lifted58 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::F32Type(lifted339) + } + 11 => { - let lifted57 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted346 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let lifted341 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + let lifted340 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + Option::Some(lifted340) + } + _ => panic() + } + + let lifted343 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted342 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() + + Option::Some(lifted342) } + _ => panic() + } - Option::Some(lifted57) + let lifted345 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result344 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result344) + } + _ => panic() } - _ => panic() + + Option::Some(@types.NumericRestrictions::{min : lifted341, max : lifted343, unit : lifted345}) } + _ => panic() + } - let lifted60 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + @types.SchemaTypeBody::F64Type(lifted346) + } + 12 => { + + @types.SchemaTypeBody::CharType + } + 13 => { + + @types.SchemaTypeBody::StringType + } + 14 => { + + let array361 : Array[@types.NamedFieldType] = []; + for index362 = 0; index362 < (mbt_ffi_load32((iter_base) + 12)); index362 = index362 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index362 * 68) + + let result347 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted349 : String? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { - let result59 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result348 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some(result59) + Option::Some(result348) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted56, max : lifted58, unit : lifted60}) - } - _ => panic() - } + let array351 : Array[String] = []; + for index352 = 0; index352 < (mbt_ffi_load32((iter_base) + 28)); index352 = index352 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index352 * 8) - @types.SchemaTypeBody::F32Type(lifted61) - } - 11 => { + let result350 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted68 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + array351.push(result350) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - let lifted63 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let array354 : Array[String] = []; + for index355 = 0; index355 < (mbt_ffi_load32((iter_base) + 36)); index355 = index355 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index355 * 8) - let lifted62 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let result353 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + array354.push(result353) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + let lifted357 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + let result356 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - Option::Some(lifted62) + Option::Some(result356) } _ => panic() } - let lifted65 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted360 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { 0 => Option::None 1 => { - let lifted64 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted359 = match (mbt_ffi_load8_u((iter_base) + 56)) { 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + @types.Role::Multimodal } 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.Role::UnstructuredText } 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + @types.Role::UnstructuredBinary + } + 3 => { + + let result358 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + + @types.Role::Other(result358) } _ => panic() } - Option::Some(lifted64) + Option::Some(lifted359) } _ => panic() } - let lifted67 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + array361.push(@types.NamedFieldType::{name : result347, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted349, aliases : array351, examples : array354, deprecated : lifted357, role : lifted360}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::RecordType(array361) + } + 15 => { + + let array378 : Array[@types.VariantCaseType] = []; + for index379 = 0; index379 < (mbt_ffi_load32((iter_base) + 12)); index379 = index379 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index379 * 72) + + let result363 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted364 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let result66 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - - Option::Some(result66) + Option::Some(mbt_ffi_load32((iter_base) + 12)) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted63, max : lifted65, unit : lifted67}) - } - _ => panic() - } + let lifted366 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::F64Type(lifted68) - } - 12 => { + let result365 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - @types.SchemaTypeBody::CharType - } - 13 => { + Option::Some(result365) + } + _ => panic() + } - @types.SchemaTypeBody::StringType - } - 14 => { + let array368 : Array[String] = []; + for index369 = 0; index369 < (mbt_ffi_load32((iter_base) + 32)); index369 = index369 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index369 * 8) - let array81 : Array[@types.NamedFieldType] = []; - for index82 = 0; index82 < (mbt_ffi_load32((iter_base) + 12)); index82 = index82 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index82 * 68) + let result367 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result69 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + array368.push(result367) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - let lifted71 : String? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let array371 : Array[String] = []; + for index372 = 0; index372 < (mbt_ffi_load32((iter_base) + 40)); index372 = index372 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index372 * 8) - let result70 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result370 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(result70) + array371.push(result370) } - _ => panic() - } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let array : Array[String] = []; - for index = 0; index < (mbt_ffi_load32((iter_base) + 28)); index = index + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index * 8) + let lifted374 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - let result72 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result373 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - array.push(result72) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + Option::Some(result373) + } + _ => panic() + } - let array74 : Array[String] = []; - for index75 = 0; index75 < (mbt_ffi_load32((iter_base) + 36)); index75 = index75 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index75 * 8) + let lifted377 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - let result73 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted376 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - array74.push(result73) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) + @types.Role::Multimodal + } + 1 => { - let lifted77 : String? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredText + } + 2 => { - let result76 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + @types.Role::UnstructuredBinary + } + 3 => { - Option::Some(result76) + let result375 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + + @types.Role::Other(result375) + } + _ => panic() + } + + Option::Some(lifted376) + } + _ => panic() } - _ => panic() + + array378.push(@types.VariantCaseType::{name : result363, payload : lifted364, metadata : @types.MetadataEnvelope::{doc : lifted366, aliases : array368, examples : array371, deprecated : lifted374, role : lifted377}}) } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let lifted80 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::VariantType(array378) + } + 16 => { - let lifted79 = match (mbt_ffi_load8_u((iter_base) + 56)) { - 0 => { + let array381 : Array[String] = []; + for index382 = 0; index382 < (mbt_ffi_load32((iter_base) + 12)); index382 = index382 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index382 * 8) - @types.Role::Multimodal - } - 1 => { + let result380 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.Role::UnstructuredText - } - 2 => { + array381.push(result380) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.Role::UnstructuredBinary - } - 3 => { + @types.SchemaTypeBody::EnumType(array381) + } + 17 => { - let result78 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + let array384 : Array[String] = []; + for index385 = 0; index385 < (mbt_ffi_load32((iter_base) + 12)); index385 = index385 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index385 * 8) - @types.Role::Other(result78) - } - _ => panic() - } + let result383 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(lifted79) - } - _ => panic() + array384.push(result383) } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - array81.push(@types.NamedFieldType::{name : result69, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted71, aliases : array, examples : array74, deprecated : lifted77, role : lifted80}}) + @types.SchemaTypeBody::FlagsType(array384) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + 18 => { - @types.SchemaTypeBody::RecordType(array81) - } - 15 => { + let array386 : Array[Int] = []; + for index387 = 0; index387 < (mbt_ffi_load32((iter_base) + 12)); index387 = index387 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index387 * 4) - let array98 : Array[@types.VariantCaseType] = []; - for index99 = 0; index99 < (mbt_ffi_load32((iter_base) + 12)); index99 = index99 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index99 * 72) + array386.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let result83 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.SchemaTypeBody::TupleType(array386) + } + 19 => { - let lifted84 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) + } + 20 => { + + @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) + } + 21 => { + + @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) + } + 22 => { + + @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) + } + 23 => { + + let lifted388 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { @@ -11542,1332 +11340,1627 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - let lifted86 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted389 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let result85 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - - Option::Some(result85) + Option::Some(mbt_ffi_load32((iter_base) + 20)) } _ => panic() } - let array88 : Array[String] = []; - for index89 = 0; index89 < (mbt_ffi_load32((iter_base) + 32)); index89 = index89 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index89 * 8) + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted388, err : lifted389}) + } + 24 => { - let result87 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted393 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - array88.push(result87) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + let array391 : Array[String] = []; + for index392 = 0; index392 < (mbt_ffi_load32((iter_base) + 16)); index392 = index392 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index392 * 8) - let array91 : Array[String] = []; - for index92 = 0; index92 < (mbt_ffi_load32((iter_base) + 40)); index92 = index92 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index92 * 8) + let result390 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result90 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + array391.push(result390) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - array91.push(result90) + Option::Some(array391) + } + _ => panic() } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let lifted94 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + let lifted394 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { 0 => Option::None 1 => { - let result93 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - Option::Some(result93) + let lifted395 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) } _ => panic() } - let lifted97 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + let lifted397 : String? = match mbt_ffi_load8_u((iter_base) + 36) { 0 => Option::None 1 => { - let lifted96 = match (mbt_ffi_load8_u((iter_base) + 60)) { - 0 => { + let result396 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - @types.Role::Multimodal - } - 1 => { + Option::Some(result396) + } + _ => panic() + } - @types.Role::UnstructuredText - } - 2 => { + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted393, min_length : lifted394, max_length : lifted395, regex : lifted397}) + } + 25 => { - @types.Role::UnstructuredBinary - } - 3 => { + let lifted401 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let result95 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + let array399 : Array[String] = []; + for index400 = 0; index400 < (mbt_ffi_load32((iter_base) + 16)); index400 = index400 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index400 * 8) - @types.Role::Other(result95) - } - _ => panic() + let result398 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array399.push(result398) } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - Option::Some(lifted96) + Option::Some(array399) } _ => panic() } - array98.push(@types.VariantCaseType::{name : result83, payload : lifted84, metadata : @types.MetadataEnvelope::{doc : lifted86, aliases : array88, examples : array91, deprecated : lifted94, role : lifted97}}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let lifted402 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::VariantType(array98) - } - 16 => { + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - let array101 : Array[String] = []; - for index102 = 0; index102 < (mbt_ffi_load32((iter_base) + 12)); index102 = index102 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index102 * 8) + let lifted403 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { - let result100 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } - array101.push(result100) + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted401, min_bytes : lifted402, max_bytes : lifted403}) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + 26 => { - @types.SchemaTypeBody::EnumType(array101) - } - 17 => { + let lifted407 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - let array104 : Array[String] = []; - for index105 = 0; index105 < (mbt_ffi_load32((iter_base) + 12)); index105 = index105 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index105 * 8) + let array405 : Array[String] = []; + for index406 = 0; index406 < (mbt_ffi_load32((iter_base) + 20)); index406 = index406 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index406 * 8) - let result103 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result404 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array104.push(result103) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + array405.push(result404) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - @types.SchemaTypeBody::FlagsType(array104) - } - 18 => { + Option::Some(array405) + } + _ => panic() + } - let array106 : Array[Int] = []; - for index107 = 0; index107 < (mbt_ffi_load32((iter_base) + 12)); index107 = index107 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index107 * 4) + let lifted411 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - array106.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let array409 : Array[String] = []; + for index410 = 0; index410 < (mbt_ffi_load32((iter_base) + 32)); index410 = index410 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index410 * 8) - @types.SchemaTypeBody::TupleType(array106) - } - 19 => { + let result408 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) - } - 20 => { + array409.push(result408) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) - } - 21 => { + Option::Some(array409) + } + _ => panic() + } - @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) - } - 22 => { + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted407, allowed_extensions : lifted411}) + } + 27 => { - @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) - } - 23 => { + let lifted415 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted108 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let array413 : Array[String] = []; + for index414 = 0; index414 < (mbt_ffi_load32((iter_base) + 16)); index414 = index414 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index414 * 8) - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + let result412 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted109 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + array413.push(result412) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - Option::Some(mbt_ffi_load32((iter_base) + 20)) + Option::Some(array413) + } + _ => panic() } - _ => panic() - } - @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted108, err : lifted109}) - } - 24 => { + let lifted419 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let lifted113 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let array417 : Array[String] = []; + for index418 = 0; index418 < (mbt_ffi_load32((iter_base) + 28)); index418 = index418 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index418 * 8) - let array111 : Array[String] = []; - for index112 = 0; index112 < (mbt_ffi_load32((iter_base) + 16)); index112 = index112 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index112 * 8) + let result416 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let result110 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + array417.push(result416) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - array111.push(result110) + Option::Some(array417) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - - Option::Some(array111) + _ => panic() } - _ => panic() - } - - let lifted114 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { - Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) - } - _ => panic() + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted415, allowed_hosts : lifted419}) } + 28 => { - let lifted115 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { - 0 => Option::None - 1 => { - - Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) - } - _ => panic() + @types.SchemaTypeBody::DatetimeType } + 29 => { - let lifted117 : String? = match mbt_ffi_load8_u((iter_base) + 36) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::DurationType + } + 30 => { - let result116 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + let result420 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - Option::Some(result116) - } - _ => panic() - } + let array422 : Array[String] = []; + for index423 = 0; index423 < (mbt_ffi_load32((iter_base) + 20)); index423 = index423 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index423 * 8) - @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted113, min_length : lifted114, max_length : lifted115, regex : lifted117}) - } - 25 => { + let result421 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted121 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + array422.push(result421) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let array119 : Array[String] = []; - for index120 = 0; index120 < (mbt_ffi_load32((iter_base) + 16)); index120 = index120 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index120 * 8) + let lifted425 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - let result118 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result424 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - array119.push(result118) + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result424}) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - - Option::Some(array119) + _ => panic() } - _ => panic() - } - let lifted122 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { + let lifted427 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + let result426 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result426}) + } + _ => panic() } - _ => panic() + + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result420, allowed_suffixes : array422, min : lifted425, max : lifted427}) } + 31 => { - let lifted123 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { - 0 => Option::None - 1 => { + let array451 : Array[@types.UnionBranch] = []; + for index452 = 0; index452 < (mbt_ffi_load32((iter_base) + 12)); index452 = index452 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index452 * 92) - Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) - } - _ => panic() - } + let result428 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted121, min_bytes : lifted122, max_bytes : lifted123}) - } - 26 => { + let lifted437 = match (mbt_ffi_load8_u((iter_base) + 12)) { + 0 => { - let lifted127 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let result429 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let array125 : Array[String] = []; - for index126 = 0; index126 < (mbt_ffi_load32((iter_base) + 20)); index126 = index126 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index126 * 8) + @types.DiscriminatorRule::Prefix(result429) + } + 1 => { - let result124 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result430 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - array125.push(result124) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + @types.DiscriminatorRule::Suffix(result430) + } + 2 => { - Option::Some(array125) - } - _ => panic() - } + let result431 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let lifted131 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { + @types.DiscriminatorRule::Contains(result431) + } + 3 => { - let array129 : Array[String] = []; - for index130 = 0; index130 < (mbt_ffi_load32((iter_base) + 32)); index130 = index130 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index130 * 8) + let result432 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let result128 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.DiscriminatorRule::Regex(result432) + } + 4 => { - array129.push(result128) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + let result433 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some(array129) - } - _ => panic() - } + let lifted435 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted127, allowed_extensions : lifted131}) - } - 27 => { + let result434 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - let lifted135 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + Option::Some(result434) + } + _ => panic() + } - let array133 : Array[String] = []; - for index134 = 0; index134 < (mbt_ffi_load32((iter_base) + 16)); index134 = index134 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index134 * 8) + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result433, literal : lifted435}) + } + 5 => { - let result132 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result436 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - array133.push(result132) + @types.DiscriminatorRule::FieldAbsent(result436) + } + _ => panic() } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - - Option::Some(array133) - } - _ => panic() - } - - let lifted139 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { - 0 => Option::None - 1 => { - let array137 : Array[String] = []; - for index138 = 0; index138 < (mbt_ffi_load32((iter_base) + 28)); index138 = index138 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index138 * 8) + let lifted439 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - let result136 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result438 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - array137.push(result136) + Option::Some(result438) + } + _ => panic() } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - Option::Some(array137) - } - _ => panic() - } + let array441 : Array[String] = []; + for index442 = 0; index442 < (mbt_ffi_load32((iter_base) + 52)); index442 = index442 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index442 * 8) - @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted135, allowed_hosts : lifted139}) - } - 28 => { + let result440 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::DatetimeType - } - 29 => { + array441.push(result440) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) - @types.SchemaTypeBody::DurationType - } - 30 => { + let array444 : Array[String] = []; + for index445 = 0; index445 < (mbt_ffi_load32((iter_base) + 60)); index445 = index445 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index445 * 8) - let result140 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result443 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let array142 : Array[String] = []; - for index143 = 0; index143 < (mbt_ffi_load32((iter_base) + 20)); index143 = index143 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index143 * 8) + array444.push(result443) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) - let result141 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted447 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - array142.push(result141) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + let result446 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - let lifted145 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { + Option::Some(result446) + } + _ => panic() + } - let result144 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + let lifted450 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + 0 => Option::None + 1 => { - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result144}) - } - _ => panic() - } + let lifted449 = match (mbt_ffi_load8_u((iter_base) + 80)) { + 0 => { - let lifted147 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { - 0 => Option::None - 1 => { + @types.Role::Multimodal + } + 1 => { - let result146 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + @types.Role::UnstructuredText + } + 2 => { - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result146}) - } - _ => panic() - } + @types.Role::UnstructuredBinary + } + 3 => { - @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result140, allowed_suffixes : array142, min : lifted145, max : lifted147}) - } - 31 => { + let result448 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) - let array171 : Array[@types.UnionBranch] = []; - for index172 = 0; index172 < (mbt_ffi_load32((iter_base) + 12)); index172 = index172 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index172 * 92) + @types.Role::Other(result448) + } + _ => panic() + } - let result148 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + Option::Some(lifted449) + } + _ => panic() + } - let lifted157 = match (mbt_ffi_load8_u((iter_base) + 12)) { - 0 => { + array451.push(@types.UnionBranch::{tag : result428, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted437, metadata : @types.MetadataEnvelope::{doc : lifted439, aliases : array441, examples : array444, deprecated : lifted447, role : lifted450}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let result149 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array451}) + } + 32 => { - @types.DiscriminatorRule::Prefix(result149) - } + let lifted454 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None 1 => { - let result150 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result453 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::Suffix(result150) + Option::Some(result453) } - 2 => { + _ => panic() + } - let result151 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted454}) + } + 33 => { - @types.DiscriminatorRule::Contains(result151) - } - 3 => { + let lifted456 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let result152 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result455 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - @types.DiscriminatorRule::Regex(result152) + Option::Some(result455) } - 4 => { - - let result153 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - - let lifted155 : String? = match mbt_ffi_load8_u((iter_base) + 24) { - 0 => Option::None - 1 => { - - let result154 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) + _ => panic() + } - Option::Some(result154) - } - _ => panic() - } + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted456}) + } + 34 => { - @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result153, literal : lifted155}) - } - 5 => { + @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) + } + 35 => { - let result156 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let lifted457 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.DiscriminatorRule::FieldAbsent(result156) + Option::Some(mbt_ffi_load32((iter_base) + 12)) } _ => panic() } - let lifted159 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + @types.SchemaTypeBody::FutureType(lifted457) + } + 36 => { + + let lifted458 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let result158 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - - Option::Some(result158) + Option::Some(mbt_ffi_load32((iter_base) + 12)) } _ => panic() } - let array161 : Array[String] = []; - for index162 = 0; index162 < (mbt_ffi_load32((iter_base) + 52)); index162 = index162 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index162 * 8) + @types.SchemaTypeBody::StreamType(lifted458) + } + _ => panic() + } - let result160 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted461 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + 0 => Option::None + 1 => { - array161.push(result160) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) + let result460 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) - let array164 : Array[String] = []; - for index165 = 0; index165 < (mbt_ffi_load32((iter_base) + 60)); index165 = index165 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index165 * 8) + Option::Some(result460) + } + _ => panic() + } - let result163 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let array463 : Array[String] = []; + for index464 = 0; index464 < (mbt_ffi_load32((iter_base) + 104)); index464 = index464 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index464 * 8) - array164.push(result163) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) + let result462 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted167 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + array463.push(result462) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) - let result166 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let array466 : Array[String] = []; + for index467 = 0; index467 < (mbt_ffi_load32((iter_base) + 112)); index467 = index467 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index467 * 8) - Option::Some(result166) - } - _ => panic() - } - - let lifted170 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { - 0 => Option::None - 1 => { + let result465 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted169 = match (mbt_ffi_load8_u((iter_base) + 80)) { - 0 => { + array466.push(result465) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) - @types.Role::Multimodal - } - 1 => { + let lifted469 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + 0 => Option::None + 1 => { - @types.Role::UnstructuredText - } - 2 => { + let result468 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) - @types.Role::UnstructuredBinary - } - 3 => { + Option::Some(result468) + } + _ => panic() + } - let result168 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + let lifted472 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + 0 => Option::None + 1 => { - @types.Role::Other(result168) - } - _ => panic() - } + let lifted471 = match (mbt_ffi_load8_u((iter_base) + 132)) { + 0 => { - Option::Some(lifted169) + @types.Role::Multimodal } - _ => panic() - } - - array171.push(@types.UnionBranch::{tag : result148, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted157, metadata : @types.MetadataEnvelope::{doc : lifted159, aliases : array161, examples : array164, deprecated : lifted167, role : lifted170}}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + 1 => { - @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array171}) - } - 32 => { + @types.Role::UnstructuredText + } + 2 => { - let lifted174 : String? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredBinary + } + 3 => { - let result173 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result470 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) - Option::Some(result173) + @types.Role::Other(result470) + } + _ => panic() } - _ => panic() - } - @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted174}) + Option::Some(lifted471) + } + _ => panic() } - 33 => { - - let lifted176 : String? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { - let result175 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + array473.push(@types.SchemaTypeNode::{body : lifted459, metadata : @types.MetadataEnvelope::{doc : lifted461, aliases : array463, examples : array466, deprecated : lifted469, role : lifted472}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 20)) - Option::Some(result175) - } - _ => panic() - } + let array478 : Array[@types.SchemaTypeDef] = []; + for index479 = 0; index479 < (mbt_ffi_load32((iter_base) + 32)); index479 = index479 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index479 * 24) - @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted176}) - } - 34 => { + let result475 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) - } - 35 => { + let lifted477 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let lifted177 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let result476 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() + Option::Some(result476) } - - @types.SchemaTypeBody::FutureType(lifted177) + _ => panic() } - 36 => { - let lifted178 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + array478.push(@types.SchemaTypeDef::{id : result475, name : lifted477, body : mbt_ffi_load32((iter_base) + 20)}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - Option::Some(mbt_ffi_load32((iter_base) + 12)) - } - _ => panic() - } + let lifted481 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::StreamType(lifted178) + let result480 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + + Option::Some(result480) } _ => panic() } - let lifted181 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + let result482 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 52), mbt_ffi_load32((iter_base) + 56)) + + let lifted484 : String? = match mbt_ffi_load8_u((iter_base) + 60) { 0 => Option::None 1 => { - let result180 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) + let result483 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - Option::Some(result180) + Option::Some(result483) } _ => panic() } - let array183 : Array[String] = []; - for index184 = 0; index184 < (mbt_ffi_load32((iter_base) + 104)); index184 = index184 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index184 * 8) + let lifted502 = match (mbt_ffi_load8_u((iter_base) + 72)) { + 0 => { - let result182 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let array500 : Array[@common.NamedField] = []; + for index501 = 0; index501 < (mbt_ffi_load32((iter_base) + 80)); index501 = index501 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 76)) + (index501 * 72) - array183.push(result182) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) + let result485 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let array186 : Array[String] = []; - for index187 = 0; index187 < (mbt_ffi_load32((iter_base) + 112)); index187 = index187 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index187 * 8) + let lifted486 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { - let result185 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @common.FieldSource::UserSupplied + } + 1 => { - array186.push(result185) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) + @common.FieldSource::AutoInjected(@common.AutoInjectedKind::from(mbt_ffi_load8_u((iter_base) + 9))) + } + _ => panic() + } - let lifted189 : String? = match mbt_ffi_load8_u((iter_base) + 116) { - 0 => Option::None - 1 => { + let lifted488 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let result188 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) + let result487 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - Option::Some(result188) - } - _ => panic() - } + Option::Some(result487) + } + _ => panic() + } - let lifted192 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { - 0 => Option::None - 1 => { + let array490 : Array[String] = []; + for index491 = 0; index491 < (mbt_ffi_load32((iter_base) + 32)); index491 = index491 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index491 * 8) - let lifted191 = match (mbt_ffi_load8_u((iter_base) + 132)) { - 0 => { + let result489 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.Role::Multimodal + array490.push(result489) } - 1 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - @types.Role::UnstructuredText - } - 2 => { + let array493 : Array[String] = []; + for index494 = 0; index494 < (mbt_ffi_load32((iter_base) + 40)); index494 = index494 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index494 * 8) - @types.Role::UnstructuredBinary + let result492 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array493.push(result492) } - 3 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let result190 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) + let lifted496 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - @types.Role::Other(result190) + let result495 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + + Option::Some(result495) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted191) - } - _ => panic() - } + let lifted499 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - array193.push(@types.SchemaTypeNode::{body : lifted179, metadata : @types.MetadataEnvelope::{doc : lifted181, aliases : array183, examples : array186, deprecated : lifted189, role : lifted192}}) - } - mbt_ffi_free(mbt_ffi_load32((return_area) + 16)) + let lifted498 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - let array198 : Array[@types.SchemaTypeDef] = []; - for index199 = 0; index199 < (mbt_ffi_load32((return_area) + 28)); index199 = index199 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 24)) + (index199 * 24) + @types.Role::Multimodal + } + 1 => { - let result195 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.Role::UnstructuredText + } + 2 => { - let lifted197 : String? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + @types.Role::UnstructuredBinary + } + 3 => { - let result196 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + let result497 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - Option::Some(result196) - } - _ => panic() - } + @types.Role::Other(result497) + } + _ => panic() + } - array198.push(@types.SchemaTypeDef::{id : result195, name : lifted197, body : mbt_ffi_load32((iter_base) + 20)}) - } - mbt_ffi_free(mbt_ffi_load32((return_area) + 24)) - - let array229 : Array[@types.SchemaValueNode] = []; - for index230 = 0; index230 < (mbt_ffi_load32((return_area) + 40)); index230 = index230 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 36)) + (index230 * 32) - - let lifted228 = match (mbt_ffi_load8_u((iter_base) + 0)) { - 0 => { - - @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) - } - 1 => { + Option::Some(lifted498) + } + _ => panic() + } - @types.SchemaValueNode::S8Value((mbt_ffi_load8((iter_base) + 8))) - } - 2 => { + array500.push(@common.NamedField::{name : result485, source : lifted486, schema : mbt_ffi_load32((iter_base) + 12), metadata : @types.MetadataEnvelope::{doc : lifted488, aliases : array490, examples : array493, deprecated : lifted496, role : lifted499}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 76)) - @types.SchemaValueNode::S16Value((mbt_ffi_load16((iter_base) + 8))) + @common.InputSchema::Parameters(array500) } - 3 => { + _ => panic() + } - @types.SchemaValueNode::S32Value(mbt_ffi_load32((iter_base) + 8)) - } - 4 => { + let array550 : Array[@common.AgentMethod] = []; + for index551 = 0; index551 < (mbt_ffi_load32((iter_base) + 88)); index551 = index551 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 84)) + (index551 * 88) - @types.SchemaValueNode::S64Value(mbt_ffi_load64((iter_base) + 8)) - } - 5 => { + let result503 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - @types.SchemaValueNode::U8Value((mbt_ffi_load8_u((iter_base) + 8)).to_byte()) - } - 6 => { + let result504 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::U16Value((mbt_ffi_load16_u((iter_base) + 8).land(0xFFFF).reinterpret_as_uint())) - } - 7 => { + let array525 : Array[@common.HttpEndpointDetails] = []; + for index526 = 0; index526 < (mbt_ffi_load32((iter_base) + 20)); index526 = index526 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index526 * 48) - @types.SchemaValueNode::U32Value((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) - } - 8 => { + let lifted506 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - @types.SchemaValueNode::U64Value((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64()) - } - 9 => { + @common.HttpMethod::Get + } + 1 => { - @types.SchemaValueNode::F32Value(mbt_ffi_loadf32((iter_base) + 8)) - } - 10 => { + @common.HttpMethod::Head + } + 2 => { - @types.SchemaValueNode::F64Value(mbt_ffi_loadf64((iter_base) + 8)) - } - 11 => { + @common.HttpMethod::Post + } + 3 => { - @types.SchemaValueNode::CharValue(Int::unsafe_to_char(mbt_ffi_load32((iter_base) + 8))) - } - 12 => { + @common.HttpMethod::Put + } + 4 => { - let result200 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + @common.HttpMethod::Delete + } + 5 => { - @types.SchemaValueNode::StringValue(result200) - } - 13 => { + @common.HttpMethod::Connect + } + 6 => { - let array201 : Array[Int] = []; - for index202 = 0; index202 < (mbt_ffi_load32((iter_base) + 12)); index202 = index202 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index202 * 4) + @common.HttpMethod::Options + } + 7 => { - array201.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + @common.HttpMethod::Trace + } + 8 => { - @types.SchemaValueNode::RecordValue(array201) - } - 14 => { + @common.HttpMethod::Patch + } + 9 => { - let lifted203 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let result505 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - Option::Some(mbt_ffi_load32((iter_base) + 16)) + @common.HttpMethod::Custom(result505) } _ => panic() } - @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted203}) - } - 15 => { + let array511 : Array[@common.PathSegment] = []; + for index512 = 0; index512 < (mbt_ffi_load32((iter_base) + 16)); index512 = index512 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index512 * 12) - @types.SchemaValueNode::EnumValue((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) - } - 16 => { + let lifted510 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - let array204 : Array[Bool] = []; - for index205 = 0; index205 < (mbt_ffi_load32((iter_base) + 12)); index205 = index205 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index205 * 1) + let result507 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - array204.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + @common.PathSegment::Literal(result507) + } + 1 => { - @types.SchemaValueNode::FlagsValue(array204) - } - 17 => { + @common.PathSegment::SystemVariable(@common.SystemVariable::from(mbt_ffi_load8_u((iter_base) + 4))) + } + 2 => { - let array206 : Array[Int] = []; - for index207 = 0; index207 < (mbt_ffi_load32((iter_base) + 12)); index207 = index207 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index207 * 4) + let result508 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - array206.push(mbt_ffi_load32((iter_base) + 0)) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + @common.PathSegment::PathVariable(@common.PathVariable::{variable_name : result508}) + } + 3 => { - @types.SchemaValueNode::TupleValue(array206) - } - 18 => { + let result509 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - let array208 : Array[Int] = []; - for index209 = 0; index209 < (mbt_ffi_load32((iter_base) + 12)); index209 = index209 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index209 * 4) + @common.PathSegment::RemainingPathVariable(@common.PathVariable::{variable_name : result509}) + } + _ => panic() + } - array208.push(mbt_ffi_load32((iter_base) + 0)) + array511.push(lifted510) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::ListValue(array208) - } - 19 => { + let array515 : Array[@common.HeaderVariable] = []; + for index516 = 0; index516 < (mbt_ffi_load32((iter_base) + 24)); index516 = index516 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 20)) + (index516 * 16) - let array210 : Array[Int] = []; - for index211 = 0; index211 < (mbt_ffi_load32((iter_base) + 12)); index211 = index211 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index211 * 4) + let result513 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array210.push(mbt_ffi_load32((iter_base) + 0)) + let result514 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + array515.push(@common.HeaderVariable::{header_name : result513, variable_name : result514}) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 20)) - @types.SchemaValueNode::FixedListValue(array210) - } - 20 => { + let array519 : Array[@common.QueryVariable] = []; + for index520 = 0; index520 < (mbt_ffi_load32((iter_base) + 32)); index520 = index520 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index520 * 16) - let array212 : Array[@types.MapEntry] = []; - for index213 = 0; index213 < (mbt_ffi_load32((iter_base) + 12)); index213 = index213 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index213 * 8) + let result517 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array212.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let result518 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::MapValue(array212) - } - 21 => { + array519.push(@common.QueryVariable::{query_param_name : result517, variable_name : result518}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - let lifted214 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted521 : @common.AuthDetails? = match mbt_ffi_load8_u((iter_base) + 36) { 0 => Option::None 1 => { - Option::Some(mbt_ffi_load32((iter_base) + 12)) + Option::Some(@common.AuthDetails::{required : (mbt_ffi_load8_u((iter_base) + 37) != 0)}) } _ => panic() } - @types.SchemaValueNode::OptionValue(lifted214) + let array523 : Array[String] = []; + for index524 = 0; index524 < (mbt_ffi_load32((iter_base) + 44)); index524 = index524 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 40)) + (index524 * 8) + + let result522 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array523.push(result522) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 40)) + + array525.push(@common.HttpEndpointDetails::{http_method : lifted506, path_suffix : array511, header_vars : array515, query_vars : array519, auth_details : lifted521, cors_options : @common.CorsOptions::{allowed_patterns : array523}}) } - 22 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let lifted217 = match (mbt_ffi_load8_u((iter_base) + 8)) { - 0 => { + let lifted528 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - let lifted215 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + let result527 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - Option::Some(mbt_ffi_load32((iter_base) + 16)) - } - _ => panic() - } + Option::Some(result527) + } + _ => panic() + } - @types.ResultValuePayload::OkValue(lifted215) - } - 1 => { + let lifted546 = match (mbt_ffi_load8_u((iter_base) + 36)) { + 0 => { - let lifted216 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None + let array544 : Array[@common.NamedField] = []; + for index545 = 0; index545 < (mbt_ffi_load32((iter_base) + 44)); index545 = index545 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 40)) + (index545 * 72) + + let result529 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted530 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { + + @common.FieldSource::UserSupplied + } 1 => { - Option::Some(mbt_ffi_load32((iter_base) + 16)) + @common.FieldSource::AutoInjected(@common.AutoInjectedKind::from(mbt_ffi_load8_u((iter_base) + 9))) } _ => panic() } - @types.ResultValuePayload::ErrValue(lifted216) - } - _ => panic() - } + let lifted532 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.SchemaValueNode::ResultValue(lifted217) - } - 23 => { + let result531 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - let result218 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + Option::Some(result531) + } + _ => panic() + } - let lifted220 : String? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let array534 : Array[String] = []; + for index535 = 0; index535 < (mbt_ffi_load32((iter_base) + 32)); index535 = index535 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index535 * 8) - let result219 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result533 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(result219) - } - _ => panic() - } + array534.push(result533) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result218, language : lifted220}) - } - 24 => { + let array537 : Array[String] = []; + for index538 = 0; index538 < (mbt_ffi_load32((iter_base) + 40)); index538 = index538 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index538 * 8) - let result221 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result536 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted223 : String? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + array537.push(result536) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - let result222 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let lifted540 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - Option::Some(result222) - } - _ => panic() - } + let result539 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result221, mime_type : lifted223}) - } - 25 => { + Option::Some(result539) + } + _ => panic() + } - let result224 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let lifted543 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - @types.SchemaValueNode::PathValue(result224) - } - 26 => { + let lifted542 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - let result225 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + @types.Role::Multimodal + } + 1 => { - @types.SchemaValueNode::UrlValue(result225) - } - 27 => { + @types.Role::UnstructuredText + } + 2 => { - @types.SchemaValueNode::DatetimeValue(@types.Datetime::{seconds : mbt_ffi_load64((iter_base) + 8), nanoseconds : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}) - } - 28 => { + @types.Role::UnstructuredBinary + } + 3 => { - @types.SchemaValueNode::DurationValue(@types.DurationValuePayload::{nanoseconds : mbt_ffi_load64((iter_base) + 8)}) - } - 29 => { + let result541 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - let result226 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + @types.Role::Other(result541) + } + _ => panic() + } - @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result226}) - } - 30 => { + Option::Some(lifted542) + } + _ => panic() + } - let result227 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + array544.push(@common.NamedField::{name : result529, source : lifted530, schema : mbt_ffi_load32((iter_base) + 12), metadata : @types.MetadataEnvelope::{doc : lifted532, aliases : array534, examples : array537, deprecated : lifted540, role : lifted543}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 40)) - @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result227, body : mbt_ffi_load32((iter_base) + 16)}) + @common.InputSchema::Parameters(array544) + } + _ => panic() } - 31 => { - @types.SchemaValueNode::SecretValue(@types.Secret::Secret(mbt_ffi_load32((iter_base) + 8))) - } - 32 => { + let lifted547 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - @types.SchemaValueNode::QuotaTokenHandle(@types.QuotaToken::QuotaToken(mbt_ffi_load32((iter_base) + 8))) - } - 33 => { + @common.OutputSchema::Unit + } + 1 => { - @types.SchemaValueNode::PermissionCardHandle(@types.PermissionCard::PermissionCard(mbt_ffi_load32((iter_base) + 8))) + @common.OutputSchema::Single(mbt_ffi_load32((iter_base) + 52)) + } + _ => panic() } - 34 => { - @types.SchemaValueNode::StreamValue(@types.SchemaValueStream::SchemaValueStream(mbt_ffi_load32((iter_base) + 8))) + let lifted549 : @common.ReadOnlyConfig? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let lifted548 = match (mbt_ffi_load8_u((iter_base) + 64)) { + 0 => { + + @common.CachePolicy::NoCache + } + 1 => { + + @common.CachePolicy::UntilWrite + } + 2 => { + + @common.CachePolicy::Ttl((mbt_ffi_load64((iter_base) + 72)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(@common.ReadOnlyConfig::{cache_policy : lifted548, uses_principal : (mbt_ffi_load8_u((iter_base) + 80) != 0)}) + } + _ => panic() } - _ => panic() + + array550.push(@common.AgentMethod::{name : result503, description : result504, http_endpoint : array525, prompt_hint : lifted528, input_schema : lifted546, output_schema : lifted547, read_only : lifted549}) } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 84)) - array229.push(lifted228) + array552.push(@common.AgentDependency::{type_name : result274, description : lifted276, schema : @types.SchemaGraph::{type_nodes : array473, defs : array478, root : mbt_ffi_load32((iter_base) + 36)}, constructor_ : @common.AgentConstructor::{name : lifted481, description : result482, prompt_hint : lifted484, input_schema : lifted502}, methods : array550}) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 36)) + mbt_ffi_free(mbt_ffi_load32((return_area) + 104)) - let lifted231 : @types.Uuid? = match mbt_ffi_load8_u((return_area) + 48) { + let lifted570 : @common.HttpMountDetails? = match mbt_ffi_load8_u((return_area) + 116) { 0 => Option::None 1 => { - Option::Some(@types.Uuid::{high_bits : (mbt_ffi_load64((return_area) + 56)).reinterpret_as_uint64(), low_bits : (mbt_ffi_load64((return_area) + 64)).reinterpret_as_uint64()}) - } - _ => panic() - } + let array558 : Array[@common.PathSegment] = []; + for index559 = 0; index559 < (mbt_ffi_load32((return_area) + 124)); index559 = index559 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 120)) + (index559 * 12) - Result::Ok((result, @types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array193, defs : array198, root : mbt_ffi_load32((return_area) + 32)}, value : @types.SchemaValueTree::{value_nodes : array229, root : mbt_ffi_load32((return_area) + 44)}}, lifted231)) - } - 1 => { + let lifted557 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - let lifted470 = match (mbt_ffi_load8_u((return_area) + 8)) { - 0 => { + let result554 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - let result232 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + @common.PathSegment::Literal(result554) + } + 1 => { - @common.AgentError::InvalidInput(result232) - } - 1 => { + @common.PathSegment::SystemVariable(@common.SystemVariable::from(mbt_ffi_load8_u((iter_base) + 4))) + } + 2 => { - let result233 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + let result555 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - @common.AgentError::InvalidMethod(result233) - } - 2 => { + @common.PathSegment::PathVariable(@common.PathVariable::{variable_name : result555}) + } + 3 => { - let result234 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + let result556 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - @common.AgentError::InvalidType(result234) - } - 3 => { + @common.PathSegment::RemainingPathVariable(@common.PathVariable::{variable_name : result556}) + } + _ => panic() + } - let result235 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + array558.push(lifted557) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 120)) - @common.AgentError::InvalidAgentId(result235) - } - 4 => { + let lifted560 : @common.AuthDetails? = match mbt_ffi_load8_u((return_area) + 128) { + 0 => Option::None + 1 => { - let array432 : Array[@types.SchemaTypeNode] = []; - for index433 = 0; index433 < (mbt_ffi_load32((return_area) + 16)); index433 = index433 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 12)) + (index433 * 144) + Option::Some(@common.AuthDetails::{required : (mbt_ffi_load8_u((return_area) + 129) != 0)}) + } + _ => panic() + } - let lifted418 = match (mbt_ffi_load8_u((iter_base) + 0)) { + let array562 : Array[String] = []; + for index563 = 0; index563 < (mbt_ffi_load32((return_area) + 136)); index563 = index563 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 132)) + (index563 * 8) + + let result561 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array562.push(result561) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 132)) + + let array568 : Array[@common.PathSegment] = []; + for index569 = 0; index569 < (mbt_ffi_load32((return_area) + 144)); index569 = index569 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 140)) + (index569 * 12) + + let lifted567 = match (mbt_ffi_load8_u((iter_base) + 0)) { 0 => { - @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + let result564 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) + + @common.PathSegment::Literal(result564) } 1 => { - @types.SchemaTypeBody::BoolType + @common.PathSegment::SystemVariable(@common.SystemVariable::from(mbt_ffi_load8_u((iter_base) + 4))) } 2 => { - let lifted242 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let result565 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - let lifted237 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + @common.PathSegment::PathVariable(@common.PathVariable::{variable_name : result565}) + } + 3 => { - let lifted236 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let result566 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + @common.PathSegment::RemainingPathVariable(@common.PathVariable::{variable_name : result566}) + } + _ => panic() + } - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + array568.push(lifted567) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 140)) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + Option::Some(@common.HttpMountDetails::{path_prefix : array558, auth_details : lifted560, phantom_agent : (mbt_ffi_load8_u((return_area) + 130) != 0), cors_options : @common.CorsOptions::{allowed_patterns : array562}, webhook_suffix : array568}) + } + _ => panic() + } - Option::Some(lifted236) - } - _ => panic() - } + let lifted572 = match (mbt_ffi_load8_u((return_area) + 152)) { + 0 => { - let lifted239 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + @common.Snapshotting::Disabled + } + 1 => { - let lifted238 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + let lifted571 = match (mbt_ffi_load8_u((return_area) + 160)) { + 0 => { - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + @common.SnapshottingConfig::Default + } + 1 => { - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + @common.SnapshottingConfig::Periodic((mbt_ffi_load64((return_area) + 168)).reinterpret_as_uint64()) + } + 2 => { - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + @common.SnapshottingConfig::EveryNInvocation((mbt_ffi_load16_u((return_area) + 168).land(0xFFFF).reinterpret_as_uint())) + } + _ => panic() + } - Option::Some(lifted238) - } - _ => panic() - } + @common.Snapshotting::Enabled(lifted571) + } + _ => panic() + } - let lifted241 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + let array576 : Array[@common.AgentConfigDeclaration] = []; + for index577 = 0; index577 < (mbt_ffi_load32((return_area) + 180)); index577 = index577 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 176)) + (index577 * 16) - let result240 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let array574 : Array[String] = []; + for index575 = 0; index575 < (mbt_ffi_load32((iter_base) + 8)); index575 = index575 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 4)) + (index575 * 8) - Option::Some(result240) - } - _ => panic() - } + let result573 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - Option::Some(@types.NumericRestrictions::{min : lifted237, max : lifted239, unit : lifted241}) - } - _ => panic() - } + array574.push(result573) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 4)) - @types.SchemaTypeBody::S8Type(lifted242) - } - 3 => { + array576.push(@common.AgentConfigDeclaration::{source : @common.AgentConfigSource::from(mbt_ffi_load8_u((iter_base) + 0)), path : array574, value_type : mbt_ffi_load32((iter_base) + 12)}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 176)) - let lifted249 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + Option::Some(@common.RegisteredAgentType::{agent_type : @common.AgentType::{type_name : result, description : result0, source_language : result1, schema : @types.SchemaGraph::{type_nodes : array195, defs : array200, root : mbt_ffi_load32((return_area) + 48)}, constructor_ : @common.AgentConstructor::{name : lifted203, description : result204, prompt_hint : lifted206, input_schema : lifted224}, methods : array272, dependencies : array552, mode : @common.AgentMode::from(mbt_ffi_load8_u((return_area) + 112)), http_mount : lifted570, snapshotting : lifted572, config : array576}, implemented_by : @types.ComponentId::{uuid : @types.Uuid::{high_bits : (mbt_ffi_load64((return_area) + 184)).reinterpret_as_uint64(), low_bits : (mbt_ffi_load64((return_area) + 192)).reinterpret_as_uint64()}}}) + } + _ => panic() + } + let ret = lifted578 + mbt_ffi_free(ptr) + mbt_ffi_free(return_area) + return ret - let lifted244 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { +} +///| +/// Constructs a string agent-id from the agent type and its constructor parameters +/// and an optional phantom ID. +/// +/// `input` is a value tree whose root encodes the constructor's parameter list. +pub fn make_agent_id(agent_type_name : String, input : @types.SchemaValueTree, phantom_id : @types.Uuid?) -> Result[String, @common.AgentError] { + let cleanup_list : Array[Int] = [] - let lifted243 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let ptr = mbt_ffi_str2ptr(agent_type_name) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let address70 = mbt_ffi_malloc(((input).value_nodes).length() * 32); + for index71 = 0; index71 < ((input).value_nodes).length(); index71 = index71 + 1 { + let iter_elem : @types.SchemaValueNode = ((input).value_nodes)[(index71)] + let iter_base = address70 + (index71 * 32); - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + match iter_elem { + BoolValue(payload) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store8((iter_base) + 8, (if payload { 1 } else { 0 })) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + () + } + S8Value(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload0)) - Option::Some(lifted243) - } - _ => panic() - } + () + } + S16Value(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload1)) - let lifted246 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + () + } + S32Value(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 8, payload2) - let lifted245 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + () + } + S64Value(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store64((iter_base) + 8, payload3) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + () + } + U8Value(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store8((iter_base) + 8, (payload4).to_int()) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + () + } + U16Value(payload5) => { + mbt_ffi_store8((iter_base) + 0, (6)) + mbt_ffi_store16((iter_base) + 8, (payload5).reinterpret_as_int()) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + () + } + U32Value(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 8, (payload6).reinterpret_as_int()) - Option::Some(lifted245) - } - _ => panic() - } + () + } + U64Value(payload7) => { + mbt_ffi_store8((iter_base) + 0, (8)) + mbt_ffi_store64((iter_base) + 8, (payload7).reinterpret_as_int64()) - let lifted248 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + () + } + F32Value(payload8) => { + mbt_ffi_store8((iter_base) + 0, (9)) + mbt_ffi_storef32((iter_base) + 8, payload8) - let result247 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + () + } + F64Value(payload9) => { + mbt_ffi_store8((iter_base) + 0, (10)) + mbt_ffi_storef64((iter_base) + 8, payload9) - Option::Some(result247) - } - _ => panic() - } + () + } + CharValue(payload10) => { + mbt_ffi_store8((iter_base) + 0, (11)) + mbt_ffi_store32((iter_base) + 8, (payload10).to_int()) - Option::Some(@types.NumericRestrictions::{min : lifted244, max : lifted246, unit : lifted248}) - } - _ => panic() - } + () + } + StringValue(payload11) => { + mbt_ffi_store8((iter_base) + 0, (12)) - @types.SchemaTypeBody::S16Type(lifted249) - } - 4 => { + let ptr12 = mbt_ffi_str2ptr(payload11) + mbt_ffi_store32((iter_base) + 12, payload11.length()) + mbt_ffi_store32((iter_base) + 8, ptr12) + cleanup_list.push(ptr12) - let lifted256 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + () + } + RecordValue(payload13) => { + mbt_ffi_store8((iter_base) + 0, (13)) - let lifted251 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + let address = mbt_ffi_malloc((payload13).length() * 4); + for index = 0; index < (payload13).length(); index = index + 1 { + let iter_elem : Int = (payload13)[(index)] + let iter_base = address + (index * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - let lifted250 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + } + mbt_ffi_store32((iter_base) + 12, (payload13).length()) + mbt_ffi_store32((iter_base) + 8, address) + cleanup_list.push(address) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + () + } + VariantValue(payload14) => { + mbt_ffi_store8((iter_base) + 0, (14)) + mbt_ffi_store32((iter_base) + 8, ((payload14).case).reinterpret_as_int()) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + match ((payload14).payload) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + () + } + Some(payload16) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload16) - Option::Some(lifted250) - } - _ => panic() - } + () + } + } - let lifted253 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + () + } + EnumValue(payload17) => { + mbt_ffi_store8((iter_base) + 0, (15)) + mbt_ffi_store32((iter_base) + 8, (payload17).reinterpret_as_int()) - let lifted252 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + () + } + FlagsValue(payload18) => { + mbt_ffi_store8((iter_base) + 0, (16)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + let address19 = mbt_ffi_malloc((payload18).length() * 1); + for index20 = 0; index20 < (payload18).length(); index20 = index20 + 1 { + let iter_elem : Bool = (payload18)[(index20)] + let iter_base = address19 + (index20 * 1); + mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + } + mbt_ffi_store32((iter_base) + 12, (payload18).length()) + mbt_ffi_store32((iter_base) + 8, address19) + cleanup_list.push(address19) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + () + } + TupleValue(payload21) => { + mbt_ffi_store8((iter_base) + 0, (17)) - Option::Some(lifted252) - } - _ => panic() - } + let address22 = mbt_ffi_malloc((payload21).length() * 4); + for index23 = 0; index23 < (payload21).length(); index23 = index23 + 1 { + let iter_elem : Int = (payload21)[(index23)] + let iter_base = address22 + (index23 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - let lifted255 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + } + mbt_ffi_store32((iter_base) + 12, (payload21).length()) + mbt_ffi_store32((iter_base) + 8, address22) + cleanup_list.push(address22) - let result254 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + () + } + ListValue(payload24) => { + mbt_ffi_store8((iter_base) + 0, (18)) - Option::Some(result254) - } - _ => panic() - } + let address25 = mbt_ffi_malloc((payload24).length() * 4); + for index26 = 0; index26 < (payload24).length(); index26 = index26 + 1 { + let iter_elem : Int = (payload24)[(index26)] + let iter_base = address25 + (index26 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - Option::Some(@types.NumericRestrictions::{min : lifted251, max : lifted253, unit : lifted255}) - } - _ => panic() - } + } + mbt_ffi_store32((iter_base) + 12, (payload24).length()) + mbt_ffi_store32((iter_base) + 8, address25) + cleanup_list.push(address25) - @types.SchemaTypeBody::S32Type(lifted256) - } - 5 => { + () + } + FixedListValue(payload27) => { + mbt_ffi_store8((iter_base) + 0, (19)) - let lifted263 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + let address28 = mbt_ffi_malloc((payload27).length() * 4); + for index29 = 0; index29 < (payload27).length(); index29 = index29 + 1 { + let iter_elem : Int = (payload27)[(index29)] + let iter_base = address28 + (index29 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - let lifted258 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + } + mbt_ffi_store32((iter_base) + 12, (payload27).length()) + mbt_ffi_store32((iter_base) + 8, address28) + cleanup_list.push(address28) - let lifted257 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + () + } + MapValue(payload30) => { + mbt_ffi_store8((iter_base) + 0, (20)) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) - } - 1 => { + let address31 = mbt_ffi_malloc((payload30).length() * 8); + for index32 = 0; index32 < (payload30).length(); index32 = index32 + 1 { + let iter_elem : @types.MapEntry = (payload30)[(index32)] + let iter_base = address31 + (index32 * 8); + mbt_ffi_store32((iter_base) + 0, (iter_elem).key) + mbt_ffi_store32((iter_base) + 4, (iter_elem).value) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - 2 => { + } + mbt_ffi_store32((iter_base) + 12, (payload30).length()) + mbt_ffi_store32((iter_base) + 8, address31) + cleanup_list.push(address31) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) - } - _ => panic() - } + () + } + OptionValue(payload33) => { + mbt_ffi_store8((iter_base) + 0, (21)) - Option::Some(lifted257) - } - _ => panic() - } + match (payload33) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) - let lifted260 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + () + } + Some(payload35) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload35) - let lifted259 = match (mbt_ffi_load8_u((iter_base) + 48)) { - 0 => { + () + } + } - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) - } - 1 => { + () + } + ResultValue(payload36) => { + mbt_ffi_store8((iter_base) + 0, (22)) - @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - 2 => { + match payload36 { + OkValue(payload37) => { + mbt_ffi_store8((iter_base) + 8, (0)) - @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) - } - _ => panic() - } + match (payload37) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) - Option::Some(lifted259) - } - _ => panic() - } + () + } + Some(payload39) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload39) - let lifted262 : String? = match mbt_ffi_load8_u((iter_base) + 64) { - 0 => Option::None - 1 => { + () + } + } - let result261 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + () + } + ErrValue(payload40) => { + mbt_ffi_store8((iter_base) + 8, (1)) - Option::Some(result261) - } - _ => panic() - } + match (payload40) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) - Option::Some(@types.NumericRestrictions::{min : lifted258, max : lifted260, unit : lifted262}) - } - _ => panic() - } + () + } + Some(payload42) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload42) - @types.SchemaTypeBody::S64Type(lifted263) + () } - 6 => { + } - let lifted270 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + () + } + } - let lifted265 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { - 0 => Option::None - 1 => { + () + } + TextValue(payload43) => { + mbt_ffi_store8((iter_base) + 0, (23)) - let lifted264 = match (mbt_ffi_load8_u((iter_base) + 24)) { - 0 => { + let ptr44 = mbt_ffi_str2ptr((payload43).text) + mbt_ffi_store32((iter_base) + 12, (payload43).text.length()) + mbt_ffi_store32((iter_base) + 8, ptr44) - @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + match ((payload43).language) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload46) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr47 = mbt_ffi_str2ptr(payload46) + mbt_ffi_store32((iter_base) + 24, payload46.length()) + mbt_ffi_store32((iter_base) + 20, ptr47) + cleanup_list.push(ptr47) + + () + } + } + cleanup_list.push(ptr44) + + () + } + BinaryValue(payload48) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + let ptr49 = mbt_ffi_bytes2ptr((payload48).bytes) + + mbt_ffi_store32((iter_base) + 12, (payload48).bytes.length()) + mbt_ffi_store32((iter_base) + 8, ptr49) + + match ((payload48).mime_type) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload51) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr52 = mbt_ffi_str2ptr(payload51) + mbt_ffi_store32((iter_base) + 24, payload51.length()) + mbt_ffi_store32((iter_base) + 20, ptr52) + cleanup_list.push(ptr52) + + () + } + } + cleanup_list.push(ptr49) + + () + } + PathValue(payload53) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + let ptr54 = mbt_ffi_str2ptr(payload53) + mbt_ffi_store32((iter_base) + 12, payload53.length()) + mbt_ffi_store32((iter_base) + 8, ptr54) + cleanup_list.push(ptr54) + + () + } + UrlValue(payload55) => { + mbt_ffi_store8((iter_base) + 0, (26)) + + let ptr56 = mbt_ffi_str2ptr(payload55) + mbt_ffi_store32((iter_base) + 12, payload55.length()) + mbt_ffi_store32((iter_base) + 8, ptr56) + cleanup_list.push(ptr56) + + () + } + DatetimeValue(payload57) => { + mbt_ffi_store8((iter_base) + 0, (27)) + mbt_ffi_store64((iter_base) + 8, (payload57).seconds) + mbt_ffi_store32((iter_base) + 16, ((payload57).nanoseconds).reinterpret_as_int()) + + () + } + DurationValue(payload58) => { + mbt_ffi_store8((iter_base) + 0, (28)) + mbt_ffi_store64((iter_base) + 8, (payload58).nanoseconds) + + () + } + QuantityValueNode(payload59) => { + mbt_ffi_store8((iter_base) + 0, (29)) + mbt_ffi_store64((iter_base) + 8, (payload59).mantissa) + mbt_ffi_store32((iter_base) + 16, (payload59).scale) + + let ptr60 = mbt_ffi_str2ptr((payload59).unit) + mbt_ffi_store32((iter_base) + 24, (payload59).unit.length()) + mbt_ffi_store32((iter_base) + 20, ptr60) + cleanup_list.push(ptr60) + + () + } + UnionValue(payload61) => { + mbt_ffi_store8((iter_base) + 0, (30)) + + let ptr62 = mbt_ffi_str2ptr((payload61).tag) + mbt_ffi_store32((iter_base) + 12, (payload61).tag.length()) + mbt_ffi_store32((iter_base) + 8, ptr62) + mbt_ffi_store32((iter_base) + 16, (payload61).body) + cleanup_list.push(ptr62) + + () + } + SecretValue(payload63) => { + mbt_ffi_store8((iter_base) + 0, (31)) + + let @types.Secret(handle) = payload63 + mbt_ffi_store32((iter_base) + 8, handle) + + () + } + QuotaTokenHandle(payload64) => { + mbt_ffi_store8((iter_base) + 0, (32)) + + let @types.QuotaToken(handle65) = payload64 + mbt_ffi_store32((iter_base) + 8, handle65) + + () + } + PermissionCardHandle(payload66) => { + mbt_ffi_store8((iter_base) + 0, (33)) + + let @types.PermissionCard(handle67) = payload66 + mbt_ffi_store32((iter_base) + 8, handle67) + + () + } + StreamValue(payload68) => { + mbt_ffi_store8((iter_base) + 0, (34)) + + let @types.SchemaValueStream(handle69) = payload68 + mbt_ffi_store32((iter_base) + 8, handle69) + + () + } + } + + } + + let (lowered, lowered74, lowered75) = match (phantom_id) { + None => { + + ((0), 0L, 0L) + } + Some(payload73) => { + + ((1), ((payload73).high_bits).reinterpret_as_int64(), ((payload73).low_bits).reinterpret_as_int64()) + } + } + let return_area = mbt_ffi_malloc(40) + wasmImportMakeAgentId(ptr, agent_type_name.length(), address70, ((input).value_nodes).length(), (input).root, lowered, lowered74, lowered75, return_area); + + let lifted313 = match (mbt_ffi_load8_u((return_area) + 0)) { + 0 => { + + let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8)) + + Result::Ok(result) + } + 1 => { + + let lifted312 = match (mbt_ffi_load8_u((return_area) + 4)) { + 0 => { + + let result76 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + + @common.AgentError::InvalidInput(result76) + } + 1 => { + + let result77 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + + @common.AgentError::InvalidMethod(result77) + } + 2 => { + + let result78 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + + @common.AgentError::InvalidType(result78) + } + 3 => { + + let result79 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + + @common.AgentError::InvalidAgentId(result79) + } + 4 => { + + let array274 : Array[@types.SchemaTypeNode] = []; + for index275 = 0; index275 < (mbt_ffi_load32((return_area) + 12)); index275 = index275 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 8)) + (index275 * 144) + + let lifted260 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { + + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { + + @types.SchemaTypeBody::BoolType + } + 2 => { + + let lifted85 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted80 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) } 1 => { @@ -12880,16 +12973,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted264) + Option::Some(lifted) } _ => panic() } - let lifted267 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted82 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted266 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted81 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -12905,40 +12998,40 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted266) + Option::Some(lifted81) } _ => panic() } - let lifted269 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted84 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result268 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result83 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result268) + Option::Some(result83) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted265, max : lifted267, unit : lifted269}) + Option::Some(@types.NumericRestrictions::{min : lifted80, max : lifted82, unit : lifted84}) } _ => panic() } - @types.SchemaTypeBody::U8Type(lifted270) + @types.SchemaTypeBody::S8Type(lifted85) } - 7 => { + 3 => { - let lifted277 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted92 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let lifted272 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted87 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted271 = match (mbt_ffi_load8_u((iter_base) + 24)) { + let lifted86 = match (mbt_ffi_load8_u((iter_base) + 24)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) @@ -12954,16 +13047,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted271) + Option::Some(lifted86) } _ => panic() } - let lifted274 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted89 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted273 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted88 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -12979,40 +13072,40 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted273) + Option::Some(lifted88) } _ => panic() } - let lifted276 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted91 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result275 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result90 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result275) + Option::Some(result90) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted272, max : lifted274, unit : lifted276}) + Option::Some(@types.NumericRestrictions::{min : lifted87, max : lifted89, unit : lifted91}) } _ => panic() } - @types.SchemaTypeBody::U16Type(lifted277) + @types.SchemaTypeBody::S16Type(lifted92) } - 8 => { + 4 => { - let lifted284 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted99 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let lifted279 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted94 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted278 = match (mbt_ffi_load8_u((iter_base) + 24)) { + let lifted93 = match (mbt_ffi_load8_u((iter_base) + 24)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) @@ -13028,16 +13121,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted278) + Option::Some(lifted93) } _ => panic() } - let lifted281 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted96 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted280 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted95 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -13053,40 +13146,40 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted280) + Option::Some(lifted95) } _ => panic() } - let lifted283 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted98 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result282 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result97 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result282) + Option::Some(result97) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted279, max : lifted281, unit : lifted283}) + Option::Some(@types.NumericRestrictions::{min : lifted94, max : lifted96, unit : lifted98}) } _ => panic() } - @types.SchemaTypeBody::U32Type(lifted284) + @types.SchemaTypeBody::S32Type(lifted99) } - 9 => { + 5 => { - let lifted291 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted106 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let lifted286 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted101 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted285 = match (mbt_ffi_load8_u((iter_base) + 24)) { + let lifted100 = match (mbt_ffi_load8_u((iter_base) + 24)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) @@ -13102,16 +13195,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted285) + Option::Some(lifted100) } _ => panic() } - let lifted288 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted103 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted287 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted102 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -13127,40 +13220,40 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted287) + Option::Some(lifted102) } _ => panic() } - let lifted290 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted105 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result289 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result104 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result289) + Option::Some(result104) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted286, max : lifted288, unit : lifted290}) + Option::Some(@types.NumericRestrictions::{min : lifted101, max : lifted103, unit : lifted105}) } _ => panic() } - @types.SchemaTypeBody::U64Type(lifted291) + @types.SchemaTypeBody::S64Type(lifted106) } - 10 => { + 6 => { - let lifted298 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted113 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let lifted293 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted108 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted292 = match (mbt_ffi_load8_u((iter_base) + 24)) { + let lifted107 = match (mbt_ffi_load8_u((iter_base) + 24)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) @@ -13176,16 +13269,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted292) + Option::Some(lifted107) } _ => panic() } - let lifted295 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted110 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted294 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted109 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -13201,40 +13294,40 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted294) + Option::Some(lifted109) } _ => panic() } - let lifted297 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted112 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result296 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result111 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result296) + Option::Some(result111) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted293, max : lifted295, unit : lifted297}) + Option::Some(@types.NumericRestrictions::{min : lifted108, max : lifted110, unit : lifted112}) } _ => panic() } - @types.SchemaTypeBody::F32Type(lifted298) + @types.SchemaTypeBody::U8Type(lifted113) } - 11 => { + 7 => { - let lifted305 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted120 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let lifted300 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted115 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let lifted299 = match (mbt_ffi_load8_u((iter_base) + 24)) { + let lifted114 = match (mbt_ffi_load8_u((iter_base) + 24)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) @@ -13250,16 +13343,16 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted299) + Option::Some(lifted114) } _ => panic() } - let lifted302 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + let lifted117 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let lifted301 = match (mbt_ffi_load8_u((iter_base) + 48)) { + let lifted116 = match (mbt_ffi_load8_u((iter_base) + 48)) { 0 => { @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) @@ -13275,188 +13368,388 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - Option::Some(lifted301) + Option::Some(lifted116) } _ => panic() } - let lifted304 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted119 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result303 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result118 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result303) + Option::Some(result118) } _ => panic() } - Option::Some(@types.NumericRestrictions::{min : lifted300, max : lifted302, unit : lifted304}) + Option::Some(@types.NumericRestrictions::{min : lifted115, max : lifted117, unit : lifted119}) } _ => panic() } - @types.SchemaTypeBody::F64Type(lifted305) + @types.SchemaTypeBody::U16Type(lifted120) } - 12 => { + 8 => { - @types.SchemaTypeBody::CharType - } - 13 => { + let lifted127 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::StringType - } - 14 => { + let lifted122 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let array320 : Array[@types.NamedFieldType] = []; - for index321 = 0; index321 < (mbt_ffi_load32((iter_base) + 12)); index321 = index321 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index321 * 68) + let lifted121 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let result306 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let lifted308 : String? = match mbt_ffi_load8_u((iter_base) + 12) { - 0 => Option::None - 1 => { + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - let result307 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - Option::Some(result307) + Option::Some(lifted121) + } + _ => panic() } - _ => panic() - } - let array310 : Array[String] = []; - for index311 = 0; index311 < (mbt_ffi_load32((iter_base) + 28)); index311 = index311 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index311 * 8) + let lifted124 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let result309 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let lifted123 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - array310.push(result309) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let array313 : Array[String] = []; - for index314 = 0; index314 < (mbt_ffi_load32((iter_base) + 36)); index314 = index314 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index314 * 8) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - let result312 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - array313.push(result312) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) + Option::Some(lifted123) + } + _ => panic() + } - let lifted316 : String? = match mbt_ffi_load8_u((iter_base) + 40) { - 0 => Option::None - 1 => { + let lifted126 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let result315 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + let result125 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result315) + Option::Some(result125) + } + _ => panic() } - _ => panic() + + Option::Some(@types.NumericRestrictions::{min : lifted122, max : lifted124, unit : lifted126}) } + _ => panic() + } - let lifted319 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { - 0 => Option::None - 1 => { + @types.SchemaTypeBody::U32Type(lifted127) + } + 9 => { - let lifted318 = match (mbt_ffi_load8_u((iter_base) + 56)) { - 0 => { + let lifted134 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - @types.Role::Multimodal - } - 1 => { + let lifted129 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - @types.Role::UnstructuredText - } - 2 => { + let lifted128 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - @types.Role::UnstructuredBinary - } - 3 => { + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let result317 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - @types.Role::Other(result317) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() } - _ => panic() - } - Option::Some(lifted318) + Option::Some(lifted128) + } + _ => panic() } - _ => panic() - } - array320.push(@types.NamedFieldType::{name : result306, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted308, aliases : array310, examples : array313, deprecated : lifted316, role : lifted319}}) - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + let lifted131 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - @types.SchemaTypeBody::RecordType(array320) - } - 15 => { + let lifted130 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - let array337 : Array[@types.VariantCaseType] = []; - for index338 = 0; index338 < (mbt_ffi_load32((iter_base) + 12)); index338 = index338 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index338 * 72) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let result322 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - let lifted323 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { - 0 => Option::None - 1 => { + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - Option::Some(mbt_ffi_load32((iter_base) + 12)) + Option::Some(lifted130) + } + _ => panic() } - _ => panic() + + let lifted133 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result132 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result132) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted129, max : lifted131, unit : lifted133}) } + _ => panic() + } - let lifted325 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + @types.SchemaTypeBody::U64Type(lifted134) + } + 10 => { + + let lifted141 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted136 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted135 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted135) + } + _ => panic() + } + + let lifted138 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted137 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted137) + } + _ => panic() + } + + let lifted140 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result139 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result139) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted136, max : lifted138, unit : lifted140}) + } + _ => panic() + } + + @types.SchemaTypeBody::F32Type(lifted141) + } + 11 => { + + let lifted148 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted143 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted142 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted142) + } + _ => panic() + } + + let lifted145 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted144 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted144) + } + _ => panic() + } + + let lifted147 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result146 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result146) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted143, max : lifted145, unit : lifted147}) + } + _ => panic() + } + + @types.SchemaTypeBody::F64Type(lifted148) + } + 12 => { + + @types.SchemaTypeBody::CharType + } + 13 => { + + @types.SchemaTypeBody::StringType + } + 14 => { + + let array162 : Array[@types.NamedFieldType] = []; + for index163 = 0; index163 < (mbt_ffi_load32((iter_base) + 12)); index163 = index163 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index163 * 68) + + let result149 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted151 : String? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { - let result324 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result150 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some(result324) + Option::Some(result150) } _ => panic() } - let array327 : Array[String] = []; - for index328 = 0; index328 < (mbt_ffi_load32((iter_base) + 32)); index328 = index328 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index328 * 8) + let array : Array[String] = []; + for index153 = 0; index153 < (mbt_ffi_load32((iter_base) + 28)); index153 = index153 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index153 * 8) - let result326 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result152 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array327.push(result326) + array.push(result152) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - let array330 : Array[String] = []; - for index331 = 0; index331 < (mbt_ffi_load32((iter_base) + 40)); index331 = index331 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index331 * 8) + let array155 : Array[String] = []; + for index156 = 0; index156 < (mbt_ffi_load32((iter_base) + 36)); index156 = index156 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index156 * 8) - let result329 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result154 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array330.push(result329) + array155.push(result154) } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) - let lifted333 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + let lifted158 : String? = match mbt_ffi_load8_u((iter_base) + 40) { 0 => Option::None 1 => { - let result332 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + let result157 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - Option::Some(result332) + Option::Some(result157) } _ => panic() } - let lifted336 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + let lifted161 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { 0 => Option::None 1 => { - let lifted335 = match (mbt_ffi_load8_u((iter_base) + 60)) { + let lifted160 = match (mbt_ffi_load8_u((iter_base) + 56)) { 0 => { @types.Role::Multimodal @@ -13471,63 +13764,159 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 3 => { - let result334 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + let result159 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) - @types.Role::Other(result334) + @types.Role::Other(result159) } _ => panic() } - Option::Some(lifted335) + Option::Some(lifted160) } _ => panic() } - array337.push(@types.VariantCaseType::{name : result322, payload : lifted323, metadata : @types.MetadataEnvelope::{doc : lifted325, aliases : array327, examples : array330, deprecated : lifted333, role : lifted336}}) + array162.push(@types.NamedFieldType::{name : result149, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted151, aliases : array, examples : array155, deprecated : lifted158, role : lifted161}}) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::VariantType(array337) + @types.SchemaTypeBody::RecordType(array162) } - 16 => { + 15 => { - let array340 : Array[String] = []; - for index341 = 0; index341 < (mbt_ffi_load32((iter_base) + 12)); index341 = index341 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index341 * 8) + let array179 : Array[@types.VariantCaseType] = []; + for index180 = 0; index180 < (mbt_ffi_load32((iter_base) + 12)); index180 = index180 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index180 * 72) - let result339 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result164 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array340.push(result339) + let lifted165 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + let lifted167 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result166 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result166) + } + _ => panic() + } + + let array169 : Array[String] = []; + for index170 = 0; index170 < (mbt_ffi_load32((iter_base) + 32)); index170 = index170 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index170 * 8) + + let result168 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array169.push(result168) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + + let array172 : Array[String] = []; + for index173 = 0; index173 < (mbt_ffi_load32((iter_base) + 40)); index173 = index173 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index173 * 8) + + let result171 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array172.push(result171) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) + + let lifted175 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { + + let result174 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + + Option::Some(result174) + } + _ => panic() + } + + let lifted178 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let lifted177 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result176 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + + @types.Role::Other(result176) + } + _ => panic() + } + + Option::Some(lifted177) + } + _ => panic() + } + + array179.push(@types.VariantCaseType::{name : result164, payload : lifted165, metadata : @types.MetadataEnvelope::{doc : lifted167, aliases : array169, examples : array172, deprecated : lifted175, role : lifted178}}) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::EnumType(array340) + @types.SchemaTypeBody::VariantType(array179) + } + 16 => { + + let array182 : Array[String] = []; + for index183 = 0; index183 < (mbt_ffi_load32((iter_base) + 12)); index183 = index183 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index183 * 8) + + let result181 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array182.push(result181) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::EnumType(array182) } 17 => { - let array343 : Array[String] = []; - for index344 = 0; index344 < (mbt_ffi_load32((iter_base) + 12)); index344 = index344 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index344 * 8) + let array185 : Array[String] = []; + for index186 = 0; index186 < (mbt_ffi_load32((iter_base) + 12)); index186 = index186 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index186 * 8) - let result342 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result184 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array343.push(result342) + array185.push(result184) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::FlagsType(array343) + @types.SchemaTypeBody::FlagsType(array185) } 18 => { - let array345 : Array[Int] = []; - for index346 = 0; index346 < (mbt_ffi_load32((iter_base) + 12)); index346 = index346 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index346 * 4) + let array187 : Array[Int] = []; + for index188 = 0; index188 < (mbt_ffi_load32((iter_base) + 12)); index188 = index188 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index188 * 4) - array345.push(mbt_ffi_load32((iter_base) + 0)) + array187.push(mbt_ffi_load32((iter_base) + 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::TupleType(array345) + @types.SchemaTypeBody::TupleType(array187) } 19 => { @@ -13547,7 +13936,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 23 => { - let lifted347 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted189 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { @@ -13556,7 +13945,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - let lifted348 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted190 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { @@ -13565,30 +13954,30 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted347, err : lifted348}) + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted189, err : lifted190}) } 24 => { - let lifted352 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted194 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let array350 : Array[String] = []; - for index351 = 0; index351 < (mbt_ffi_load32((iter_base) + 16)); index351 = index351 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index351 * 8) + let array192 : Array[String] = []; + for index193 = 0; index193 < (mbt_ffi_load32((iter_base) + 16)); index193 = index193 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index193 * 8) - let result349 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result191 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array350.push(result349) + array192.push(result191) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - Option::Some(array350) + Option::Some(array192) } _ => panic() } - let lifted353 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + let lifted195 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { 0 => Option::None 1 => { @@ -13597,7 +13986,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - let lifted354 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + let lifted196 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { 0 => Option::None 1 => { @@ -13606,41 +13995,41 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - let lifted356 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + let lifted198 : String? = match mbt_ffi_load8_u((iter_base) + 36) { 0 => Option::None 1 => { - let result355 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + let result197 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - Option::Some(result355) + Option::Some(result197) } _ => panic() } - @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted352, min_length : lifted353, max_length : lifted354, regex : lifted356}) + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted194, min_length : lifted195, max_length : lifted196, regex : lifted198}) } 25 => { - let lifted360 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted202 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let array358 : Array[String] = []; - for index359 = 0; index359 < (mbt_ffi_load32((iter_base) + 16)); index359 = index359 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index359 * 8) + let array200 : Array[String] = []; + for index201 = 0; index201 < (mbt_ffi_load32((iter_base) + 16)); index201 = index201 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index201 * 8) - let result357 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result199 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array358.push(result357) + array200.push(result199) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - Option::Some(array358) + Option::Some(array200) } _ => panic() } - let lifted361 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + let lifted203 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { 0 => Option::None 1 => { @@ -13649,7 +14038,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - let lifted362 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + let lifted204 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { 0 => Option::None 1 => { @@ -13658,91 +14047,91 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted360, min_bytes : lifted361, max_bytes : lifted362}) + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted202, min_bytes : lifted203, max_bytes : lifted204}) } 26 => { - let lifted366 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + let lifted208 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { - let array364 : Array[String] = []; - for index365 = 0; index365 < (mbt_ffi_load32((iter_base) + 20)); index365 = index365 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index365 * 8) + let array206 : Array[String] = []; + for index207 = 0; index207 < (mbt_ffi_load32((iter_base) + 20)); index207 = index207 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index207 * 8) - let result363 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result205 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array364.push(result363) + array206.push(result205) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - Option::Some(array364) + Option::Some(array206) } _ => panic() } - let lifted370 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + let lifted212 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { 0 => Option::None 1 => { - let array368 : Array[String] = []; - for index369 = 0; index369 < (mbt_ffi_load32((iter_base) + 32)); index369 = index369 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index369 * 8) + let array210 : Array[String] = []; + for index211 = 0; index211 < (mbt_ffi_load32((iter_base) + 32)); index211 = index211 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index211 * 8) - let result367 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result209 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array368.push(result367) + array210.push(result209) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - Option::Some(array368) + Option::Some(array210) } _ => panic() } - @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted366, allowed_extensions : lifted370}) + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted208, allowed_extensions : lifted212}) } 27 => { - let lifted374 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted216 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let array372 : Array[String] = []; - for index373 = 0; index373 < (mbt_ffi_load32((iter_base) + 16)); index373 = index373 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index373 * 8) + let array214 : Array[String] = []; + for index215 = 0; index215 < (mbt_ffi_load32((iter_base) + 16)); index215 = index215 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index215 * 8) - let result371 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result213 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array372.push(result371) + array214.push(result213) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - Option::Some(array372) + Option::Some(array214) } _ => panic() } - let lifted378 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + let lifted220 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { 0 => Option::None 1 => { - let array376 : Array[String] = []; - for index377 = 0; index377 < (mbt_ffi_load32((iter_base) + 28)); index377 = index377 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index377 * 8) + let array218 : Array[String] = []; + for index219 = 0; index219 < (mbt_ffi_load32((iter_base) + 28)); index219 = index219 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index219 * 8) - let result375 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result217 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array376.push(result375) + array218.push(result217) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - Option::Some(array376) + Option::Some(array218) } _ => panic() } - @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted374, allowed_hosts : lifted378}) + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted216, allowed_hosts : lifted220}) } 28 => { @@ -13754,148 +14143,148 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 30 => { - let result379 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result221 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let array381 : Array[String] = []; - for index382 = 0; index382 < (mbt_ffi_load32((iter_base) + 20)); index382 = index382 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index382 * 8) + let array223 : Array[String] = []; + for index224 = 0; index224 < (mbt_ffi_load32((iter_base) + 20)); index224 = index224 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index224 * 8) - let result380 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result222 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array381.push(result380) + array223.push(result222) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let lifted384 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + let lifted226 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { 0 => Option::None 1 => { - let result383 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + let result225 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result383}) + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result225}) } _ => panic() } - let lifted386 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + let lifted228 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { 0 => Option::None 1 => { - let result385 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + let result227 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) - Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result385}) + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result227}) } _ => panic() } - @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result379, allowed_suffixes : array381, min : lifted384, max : lifted386}) + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result221, allowed_suffixes : array223, min : lifted226, max : lifted228}) } 31 => { - let array410 : Array[@types.UnionBranch] = []; - for index411 = 0; index411 < (mbt_ffi_load32((iter_base) + 12)); index411 = index411 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index411 * 92) + let array252 : Array[@types.UnionBranch] = []; + for index253 = 0; index253 < (mbt_ffi_load32((iter_base) + 12)); index253 = index253 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index253 * 92) - let result387 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result229 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted396 = match (mbt_ffi_load8_u((iter_base) + 12)) { + let lifted238 = match (mbt_ffi_load8_u((iter_base) + 12)) { 0 => { - let result388 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result230 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::Prefix(result388) + @types.DiscriminatorRule::Prefix(result230) } 1 => { - let result389 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result231 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::Suffix(result389) + @types.DiscriminatorRule::Suffix(result231) } 2 => { - let result390 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result232 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::Contains(result390) + @types.DiscriminatorRule::Contains(result232) } 3 => { - let result391 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result233 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::Regex(result391) + @types.DiscriminatorRule::Regex(result233) } 4 => { - let result392 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result234 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let lifted394 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + let lifted236 : String? = match mbt_ffi_load8_u((iter_base) + 24) { 0 => Option::None 1 => { - let result393 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) + let result235 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - Option::Some(result393) + Option::Some(result235) } _ => panic() } - @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result392, literal : lifted394}) + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result234, literal : lifted236}) } 5 => { - let result395 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result237 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - @types.DiscriminatorRule::FieldAbsent(result395) + @types.DiscriminatorRule::FieldAbsent(result237) } _ => panic() } - let lifted398 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + let lifted240 : String? = match mbt_ffi_load8_u((iter_base) + 36) { 0 => Option::None 1 => { - let result397 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + let result239 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - Option::Some(result397) + Option::Some(result239) } _ => panic() } - let array400 : Array[String] = []; - for index401 = 0; index401 < (mbt_ffi_load32((iter_base) + 52)); index401 = index401 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index401 * 8) + let array242 : Array[String] = []; + for index243 = 0; index243 < (mbt_ffi_load32((iter_base) + 52)); index243 = index243 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index243 * 8) - let result399 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result241 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array400.push(result399) + array242.push(result241) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) - let array403 : Array[String] = []; - for index404 = 0; index404 < (mbt_ffi_load32((iter_base) + 60)); index404 = index404 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index404 * 8) + let array245 : Array[String] = []; + for index246 = 0; index246 < (mbt_ffi_load32((iter_base) + 60)); index246 = index246 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index246 * 8) - let result402 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result244 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array403.push(result402) + array245.push(result244) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) - let lifted406 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + let lifted248 : String? = match mbt_ffi_load8_u((iter_base) + 64) { 0 => Option::None 1 => { - let result405 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + let result247 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - Option::Some(result405) + Option::Some(result247) } _ => panic() } - let lifted409 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + let lifted251 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { 0 => Option::None 1 => { - let lifted408 = match (mbt_ffi_load8_u((iter_base) + 80)) { + let lifted250 = match (mbt_ffi_load8_u((iter_base) + 80)) { 0 => { @types.Role::Multimodal @@ -13910,53 +14299,53 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 3 => { - let result407 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + let result249 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) - @types.Role::Other(result407) + @types.Role::Other(result249) } _ => panic() } - Option::Some(lifted408) + Option::Some(lifted250) } _ => panic() } - array410.push(@types.UnionBranch::{tag : result387, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted396, metadata : @types.MetadataEnvelope::{doc : lifted398, aliases : array400, examples : array403, deprecated : lifted406, role : lifted409}}) + array252.push(@types.UnionBranch::{tag : result229, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted238, metadata : @types.MetadataEnvelope::{doc : lifted240, aliases : array242, examples : array245, deprecated : lifted248, role : lifted251}}) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array410}) + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array252}) } 32 => { - let lifted413 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + let lifted255 : String? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { - let result412 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + let result254 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - Option::Some(result412) + Option::Some(result254) } _ => panic() } - @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted413}) + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted255}) } 33 => { - let lifted415 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted257 : String? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let result414 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + let result256 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - Option::Some(result414) + Option::Some(result256) } _ => panic() } - @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted415}) + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted257}) } 34 => { @@ -13964,7 +14353,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 35 => { - let lifted416 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted258 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { @@ -13973,11 +14362,11 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaTypeBody::FutureType(lifted416) + @types.SchemaTypeBody::FutureType(lifted258) } 36 => { - let lifted417 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted259 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { @@ -13986,58 +14375,58 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaTypeBody::StreamType(lifted417) + @types.SchemaTypeBody::StreamType(lifted259) } _ => panic() } - let lifted420 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + let lifted262 : String? = match mbt_ffi_load8_u((iter_base) + 88) { 0 => Option::None 1 => { - let result419 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) + let result261 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) - Option::Some(result419) + Option::Some(result261) } _ => panic() } - let array422 : Array[String] = []; - for index423 = 0; index423 < (mbt_ffi_load32((iter_base) + 104)); index423 = index423 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index423 * 8) + let array264 : Array[String] = []; + for index265 = 0; index265 < (mbt_ffi_load32((iter_base) + 104)); index265 = index265 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index265 * 8) - let result421 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result263 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array422.push(result421) + array264.push(result263) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) - let array425 : Array[String] = []; - for index426 = 0; index426 < (mbt_ffi_load32((iter_base) + 112)); index426 = index426 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index426 * 8) + let array267 : Array[String] = []; + for index268 = 0; index268 < (mbt_ffi_load32((iter_base) + 112)); index268 = index268 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index268 * 8) - let result424 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result266 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - array425.push(result424) + array267.push(result266) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) - let lifted428 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + let lifted270 : String? = match mbt_ffi_load8_u((iter_base) + 116) { 0 => Option::None 1 => { - let result427 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) + let result269 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) - Option::Some(result427) + Option::Some(result269) } _ => panic() } - let lifted431 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + let lifted273 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { 0 => Option::None 1 => { - let lifted430 = match (mbt_ffi_load8_u((iter_base) + 132)) { + let lifted272 = match (mbt_ffi_load8_u((iter_base) + 132)) { 0 => { @types.Role::Multimodal @@ -14052,48 +14441,48 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 3 => { - let result429 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) + let result271 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) - @types.Role::Other(result429) + @types.Role::Other(result271) } _ => panic() } - Option::Some(lifted430) + Option::Some(lifted272) } _ => panic() } - array432.push(@types.SchemaTypeNode::{body : lifted418, metadata : @types.MetadataEnvelope::{doc : lifted420, aliases : array422, examples : array425, deprecated : lifted428, role : lifted431}}) + array274.push(@types.SchemaTypeNode::{body : lifted260, metadata : @types.MetadataEnvelope::{doc : lifted262, aliases : array264, examples : array267, deprecated : lifted270, role : lifted273}}) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 12)) + mbt_ffi_free(mbt_ffi_load32((return_area) + 8)) - let array437 : Array[@types.SchemaTypeDef] = []; - for index438 = 0; index438 < (mbt_ffi_load32((return_area) + 24)); index438 = index438 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 20)) + (index438 * 24) + let array279 : Array[@types.SchemaTypeDef] = []; + for index280 = 0; index280 < (mbt_ffi_load32((return_area) + 20)); index280 = index280 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 16)) + (index280 * 24) - let result434 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + let result276 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let lifted436 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted278 : String? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { - let result435 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + let result277 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - Option::Some(result435) + Option::Some(result277) } _ => panic() } - array437.push(@types.SchemaTypeDef::{id : result434, name : lifted436, body : mbt_ffi_load32((iter_base) + 20)}) + array279.push(@types.SchemaTypeDef::{id : result276, name : lifted278, body : mbt_ffi_load32((iter_base) + 20)}) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 20)) + mbt_ffi_free(mbt_ffi_load32((return_area) + 16)) - let array468 : Array[@types.SchemaValueNode] = []; - for index469 = 0; index469 < (mbt_ffi_load32((return_area) + 36)); index469 = index469 + 1 { - let iter_base = (mbt_ffi_load32((return_area) + 32)) + (index469 * 32) + let array310 : Array[@types.SchemaValueNode] = []; + for index311 = 0; index311 < (mbt_ffi_load32((return_area) + 32)); index311 = index311 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 28)) + (index311 * 32) - let lifted467 = match (mbt_ffi_load8_u((iter_base) + 0)) { + let lifted309 = match (mbt_ffi_load8_u((iter_base) + 0)) { 0 => { @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) @@ -14144,25 +14533,25 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 12 => { - let result439 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result281 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::StringValue(result439) + @types.SchemaValueNode::StringValue(result281) } 13 => { - let array440 : Array[Int] = []; - for index441 = 0; index441 < (mbt_ffi_load32((iter_base) + 12)); index441 = index441 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index441 * 4) + let array282 : Array[Int] = []; + for index283 = 0; index283 < (mbt_ffi_load32((iter_base) + 12)); index283 = index283 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index283 * 4) - array440.push(mbt_ffi_load32((iter_base) + 0)) + array282.push(mbt_ffi_load32((iter_base) + 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::RecordValue(array440) + @types.SchemaValueNode::RecordValue(array282) } 14 => { - let lifted442 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + let lifted284 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { @@ -14171,7 +14560,7 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted442}) + @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted284}) } 15 => { @@ -14179,67 +14568,67 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 16 => { - let array443 : Array[Bool] = []; - for index444 = 0; index444 < (mbt_ffi_load32((iter_base) + 12)); index444 = index444 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index444 * 1) + let array285 : Array[Bool] = []; + for index286 = 0; index286 < (mbt_ffi_load32((iter_base) + 12)); index286 = index286 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index286 * 1) - array443.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) + array285.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::FlagsValue(array443) + @types.SchemaValueNode::FlagsValue(array285) } 17 => { - let array445 : Array[Int] = []; - for index446 = 0; index446 < (mbt_ffi_load32((iter_base) + 12)); index446 = index446 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index446 * 4) + let array287 : Array[Int] = []; + for index288 = 0; index288 < (mbt_ffi_load32((iter_base) + 12)); index288 = index288 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index288 * 4) - array445.push(mbt_ffi_load32((iter_base) + 0)) + array287.push(mbt_ffi_load32((iter_base) + 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::TupleValue(array445) + @types.SchemaValueNode::TupleValue(array287) } 18 => { - let array447 : Array[Int] = []; - for index448 = 0; index448 < (mbt_ffi_load32((iter_base) + 12)); index448 = index448 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index448 * 4) + let array289 : Array[Int] = []; + for index290 = 0; index290 < (mbt_ffi_load32((iter_base) + 12)); index290 = index290 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index290 * 4) - array447.push(mbt_ffi_load32((iter_base) + 0)) + array289.push(mbt_ffi_load32((iter_base) + 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::ListValue(array447) + @types.SchemaValueNode::ListValue(array289) } 19 => { - let array449 : Array[Int] = []; - for index450 = 0; index450 < (mbt_ffi_load32((iter_base) + 12)); index450 = index450 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index450 * 4) + let array291 : Array[Int] = []; + for index292 = 0; index292 < (mbt_ffi_load32((iter_base) + 12)); index292 = index292 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index292 * 4) - array449.push(mbt_ffi_load32((iter_base) + 0)) + array291.push(mbt_ffi_load32((iter_base) + 0)) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::FixedListValue(array449) + @types.SchemaValueNode::FixedListValue(array291) } 20 => { - let array451 : Array[@types.MapEntry] = []; - for index452 = 0; index452 < (mbt_ffi_load32((iter_base) + 12)); index452 = index452 + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index452 * 8) + let array293 : Array[@types.MapEntry] = []; + for index294 = 0; index294 < (mbt_ffi_load32((iter_base) + 12)); index294 = index294 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index294 * 8) - array451.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) + array293.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) } mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - @types.SchemaValueNode::MapValue(array451) + @types.SchemaValueNode::MapValue(array293) } 21 => { - let lifted453 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + let lifted295 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { 0 => Option::None 1 => { @@ -14248,14 +14637,14 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.SchemaValueNode::OptionValue(lifted453) + @types.SchemaValueNode::OptionValue(lifted295) } 22 => { - let lifted456 = match (mbt_ffi_load8_u((iter_base) + 8)) { + let lifted298 = match (mbt_ffi_load8_u((iter_base) + 8)) { 0 => { - let lifted454 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + let lifted296 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { @@ -14264,11 +14653,11 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.ResultValuePayload::OkValue(lifted454) + @types.ResultValuePayload::OkValue(lifted296) } 1 => { - let lifted455 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + let lifted297 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { 0 => Option::None 1 => { @@ -14277,58 +14666,58 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - @types.ResultValuePayload::ErrValue(lifted455) + @types.ResultValuePayload::ErrValue(lifted297) } _ => panic() } - @types.SchemaValueNode::ResultValue(lifted456) + @types.SchemaValueNode::ResultValue(lifted298) } 23 => { - let result457 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result299 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let lifted459 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted301 : String? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let result458 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result300 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - Option::Some(result458) + Option::Some(result300) } _ => panic() } - @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result457, language : lifted459}) + @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result299, language : lifted301}) } 24 => { - let result460 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result302 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let lifted462 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + let lifted304 : String? = match mbt_ffi_load8_u((iter_base) + 16) { 0 => Option::None 1 => { - let result461 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result303 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - Option::Some(result461) + Option::Some(result303) } _ => panic() } - @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result460, mime_type : lifted462}) + @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result302, mime_type : lifted304}) } 25 => { - let result463 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result305 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::PathValue(result463) + @types.SchemaValueNode::PathValue(result305) } 26 => { - let result464 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result306 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::UrlValue(result464) + @types.SchemaValueNode::UrlValue(result306) } 27 => { @@ -14340,15 +14729,15 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa } 29 => { - let result465 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + let result307 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result465}) + @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result307}) } 30 => { - let result466 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + let result308 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result466, body : mbt_ffi_load32((iter_base) + 16)}) + @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result308, body : mbt_ffi_load32((iter_base) + 16)}) } 31 => { @@ -14369,744 +14758,9912 @@ pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaVa _ => panic() } - array468.push(lifted467) + array310.push(lifted309) } - mbt_ffi_free(mbt_ffi_load32((return_area) + 32)) + mbt_ffi_free(mbt_ffi_load32((return_area) + 28)) - @common.AgentError::CustomError(@types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array432, defs : array437, root : mbt_ffi_load32((return_area) + 28)}, value : @types.SchemaValueTree::{value_nodes : array468, root : mbt_ffi_load32((return_area) + 40)}}) + @common.AgentError::CustomError(@types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array274, defs : array279, root : mbt_ffi_load32((return_area) + 24)}, value : @types.SchemaValueTree::{value_nodes : array310, root : mbt_ffi_load32((return_area) + 36)}}) } _ => panic() } - Result::Err(lifted470) + Result::Err(lifted312) } _ => panic() } - let ret = lifted471 + let ret = lifted313 mbt_ffi_free(ptr) + mbt_ffi_free(address70) mbt_ffi_free(return_area) + + cleanup_list.each(mbt_ffi_free) return ret } ///| -pub fn create_webhook(promise_id : @types.PromiseId) -> Result[String, WebhookError] { +/// Parses an agent-id (created by `make-agent-id`) into an agent type name and its constructor parameters +/// and an optional phantom ID. +/// +/// The constructor parameters are returned as a self-contained typed value +/// (graph + value tree) so the receiver can interpret them without an +/// external schema registry. +pub fn parse_agent_id(agent_id : String) -> Result[(String, @types.TypedSchemaValue, @types.Uuid?), @common.AgentError] { - let ptr = mbt_ffi_str2ptr(((promise_id).agent_id).agent_id) - let return_area = mbt_ffi_malloc(16) - wasmImportCreateWebhook((((((promise_id).agent_id).component_id).uuid).high_bits).reinterpret_as_int64(), (((((promise_id).agent_id).component_id).uuid).low_bits).reinterpret_as_int64(), ptr, ((promise_id).agent_id).agent_id.length(), ((promise_id).oplog_idx).reinterpret_as_int64(), return_area); + let ptr = mbt_ffi_str2ptr(agent_id) + let return_area = mbt_ffi_malloc(72) + wasmImportParseAgentId(ptr, agent_id.length(), return_area); - let lifted1 = match (mbt_ffi_load8_u((return_area) + 0)) { + let lifted471 = match (mbt_ffi_load8_u((return_area) + 0)) { 0 => { - let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8)) + let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - Result::Ok(result) - } - 1 => { + let array193 : Array[@types.SchemaTypeNode] = []; + for index194 = 0; index194 < (mbt_ffi_load32((return_area) + 20)); index194 = index194 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 16)) + (index194 * 144) - let lifted = match (mbt_ffi_load8_u((return_area) + 4)) { - 0 => { + let lifted179 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - WebhookError::PermissionDenied - } - 1 => { + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { - let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + @types.SchemaTypeBody::BoolType + } + 2 => { - WebhookError::InternalError(result0) - } - _ => panic() - } + let lifted5 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - Result::Err(lifted) - } - _ => panic() - } - let ret = lifted1 - mbt_ffi_free(ptr) - mbt_ffi_free(return_area) - return ret + let lifted0 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { -} -///| -/// Constructs the RPC client connecting to the given target agent. -/// -/// `constructor` is a value tree whose root encodes the target agent -/// constructor's parameter list. -pub fn WasmRpc::wasm_rpc(agent_type_name : String, constructor_ : @types.SchemaValueTree, phantom_id : @types.Uuid?, agent_config : Array[@common.TypedAgentConfigValue]) -> WasmRpc { - let cleanup_list : Array[Int] = [] + let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let ptr = mbt_ffi_str2ptr(agent_type_name) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let address70 = mbt_ffi_malloc(((constructor_).value_nodes).length() * 32); - for index71 = 0; index71 < ((constructor_).value_nodes).length(); index71 = index71 + 1 { - let iter_elem : @types.SchemaValueNode = ((constructor_).value_nodes)[(index71)] - let iter_base = address70 + (index71 * 32); + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - match iter_elem { - BoolValue(payload) => { - mbt_ffi_store8((iter_base) + 0, (0)) - mbt_ffi_store8((iter_base) + 8, (if payload { 1 } else { 0 })) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - S8Value(payload0) => { - mbt_ffi_store8((iter_base) + 0, (1)) - mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload0)) + Option::Some(lifted) + } + _ => panic() + } - () - } - S16Value(payload1) => { - mbt_ffi_store8((iter_base) + 0, (2)) - mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload1)) + let lifted2 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - S32Value(payload2) => { - mbt_ffi_store8((iter_base) + 0, (3)) - mbt_ffi_store32((iter_base) + 8, payload2) + let lifted1 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - S64Value(payload3) => { - mbt_ffi_store8((iter_base) + 0, (4)) - mbt_ffi_store64((iter_base) + 8, payload3) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - U8Value(payload4) => { - mbt_ffi_store8((iter_base) + 0, (5)) - mbt_ffi_store8((iter_base) + 8, (payload4).to_int()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - U16Value(payload5) => { - mbt_ffi_store8((iter_base) + 0, (6)) - mbt_ffi_store16((iter_base) + 8, (payload5).reinterpret_as_int()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - U32Value(payload6) => { - mbt_ffi_store8((iter_base) + 0, (7)) - mbt_ffi_store32((iter_base) + 8, (payload6).reinterpret_as_int()) + Option::Some(lifted1) + } + _ => panic() + } - () - } - U64Value(payload7) => { - mbt_ffi_store8((iter_base) + 0, (8)) - mbt_ffi_store64((iter_base) + 8, (payload7).reinterpret_as_int64()) + let lifted4 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - F32Value(payload8) => { - mbt_ffi_store8((iter_base) + 0, (9)) - mbt_ffi_storef32((iter_base) + 8, payload8) + let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - F64Value(payload9) => { - mbt_ffi_store8((iter_base) + 0, (10)) - mbt_ffi_storef64((iter_base) + 8, payload9) + Option::Some(result3) + } + _ => panic() + } - () - } - CharValue(payload10) => { - mbt_ffi_store8((iter_base) + 0, (11)) - mbt_ffi_store32((iter_base) + 8, (payload10).to_int()) + Option::Some(@types.NumericRestrictions::{min : lifted0, max : lifted2, unit : lifted4}) + } + _ => panic() + } - () - } - StringValue(payload11) => { - mbt_ffi_store8((iter_base) + 0, (12)) + @types.SchemaTypeBody::S8Type(lifted5) + } + 3 => { - let ptr12 = mbt_ffi_str2ptr(payload11) - mbt_ffi_store32((iter_base) + 12, payload11.length()) - mbt_ffi_store32((iter_base) + 8, ptr12) - cleanup_list.push(ptr12) + let lifted12 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted7 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted6 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted6) + } + _ => panic() + } + + let lifted9 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted8 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted8) + } + _ => panic() + } + + let lifted11 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result10 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result10) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted7, max : lifted9, unit : lifted11}) + } + _ => panic() + } + + @types.SchemaTypeBody::S16Type(lifted12) + } + 4 => { + + let lifted19 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted14 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted13 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted13) + } + _ => panic() + } + + let lifted16 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted15 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted15) + } + _ => panic() + } + + let lifted18 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result17 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result17) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted14, max : lifted16, unit : lifted18}) + } + _ => panic() + } + + @types.SchemaTypeBody::S32Type(lifted19) + } + 5 => { + + let lifted26 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted21 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted20 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted20) + } + _ => panic() + } + + let lifted23 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted22 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted22) + } + _ => panic() + } + + let lifted25 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result24 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result24) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted21, max : lifted23, unit : lifted25}) + } + _ => panic() + } + + @types.SchemaTypeBody::S64Type(lifted26) + } + 6 => { + + let lifted33 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted28 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted27 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted27) + } + _ => panic() + } + + let lifted30 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted29 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted29) + } + _ => panic() + } + + let lifted32 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result31 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result31) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted28, max : lifted30, unit : lifted32}) + } + _ => panic() + } + + @types.SchemaTypeBody::U8Type(lifted33) + } + 7 => { + + let lifted40 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted35 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted34 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted34) + } + _ => panic() + } + + let lifted37 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted36 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted36) + } + _ => panic() + } + + let lifted39 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result38 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result38) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted35, max : lifted37, unit : lifted39}) + } + _ => panic() + } + + @types.SchemaTypeBody::U16Type(lifted40) + } + 8 => { + + let lifted47 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted42 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted41 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted41) + } + _ => panic() + } + + let lifted44 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted43 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted43) + } + _ => panic() + } + + let lifted46 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result45 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result45) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted42, max : lifted44, unit : lifted46}) + } + _ => panic() + } + + @types.SchemaTypeBody::U32Type(lifted47) + } + 9 => { + + let lifted54 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted49 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted48 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted48) + } + _ => panic() + } + + let lifted51 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted50 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted50) + } + _ => panic() + } + + let lifted53 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result52 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result52) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted49, max : lifted51, unit : lifted53}) + } + _ => panic() + } + + @types.SchemaTypeBody::U64Type(lifted54) + } + 10 => { + + let lifted61 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted56 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted55 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted55) + } + _ => panic() + } + + let lifted58 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted57 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted57) + } + _ => panic() + } + + let lifted60 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result59 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result59) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted56, max : lifted58, unit : lifted60}) + } + _ => panic() + } + + @types.SchemaTypeBody::F32Type(lifted61) + } + 11 => { + + let lifted68 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted63 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted62 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted62) + } + _ => panic() + } + + let lifted65 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted64 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted64) + } + _ => panic() + } + + let lifted67 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result66 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result66) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted63, max : lifted65, unit : lifted67}) + } + _ => panic() + } + + @types.SchemaTypeBody::F64Type(lifted68) + } + 12 => { + + @types.SchemaTypeBody::CharType + } + 13 => { + + @types.SchemaTypeBody::StringType + } + 14 => { + + let array81 : Array[@types.NamedFieldType] = []; + for index82 = 0; index82 < (mbt_ffi_load32((iter_base) + 12)); index82 = index82 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index82 * 68) + + let result69 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted71 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let result70 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + Option::Some(result70) + } + _ => panic() + } + + let array : Array[String] = []; + for index = 0; index < (mbt_ffi_load32((iter_base) + 28)); index = index + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index * 8) + + let result72 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array.push(result72) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + + let array74 : Array[String] = []; + for index75 = 0; index75 < (mbt_ffi_load32((iter_base) + 36)); index75 = index75 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index75 * 8) + + let result73 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array74.push(result73) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) + + let lifted77 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let result76 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + + Option::Some(result76) + } + _ => panic() + } + + let lifted80 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { + 0 => Option::None + 1 => { + + let lifted79 = match (mbt_ffi_load8_u((iter_base) + 56)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result78 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + + @types.Role::Other(result78) + } + _ => panic() + } + + Option::Some(lifted79) + } + _ => panic() + } + + array81.push(@types.NamedFieldType::{name : result69, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted71, aliases : array, examples : array74, deprecated : lifted77, role : lifted80}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::RecordType(array81) + } + 15 => { + + let array98 : Array[@types.VariantCaseType] = []; + for index99 = 0; index99 < (mbt_ffi_load32((iter_base) + 12)); index99 = index99 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index99 * 72) + + let result83 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted84 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + let lifted86 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result85 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result85) + } + _ => panic() + } + + let array88 : Array[String] = []; + for index89 = 0; index89 < (mbt_ffi_load32((iter_base) + 32)); index89 = index89 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index89 * 8) + + let result87 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array88.push(result87) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + + let array91 : Array[String] = []; + for index92 = 0; index92 < (mbt_ffi_load32((iter_base) + 40)); index92 = index92 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index92 * 8) + + let result90 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array91.push(result90) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) + + let lifted94 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { + + let result93 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + + Option::Some(result93) + } + _ => panic() + } + + let lifted97 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let lifted96 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result95 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + + @types.Role::Other(result95) + } + _ => panic() + } + + Option::Some(lifted96) + } + _ => panic() + } + + array98.push(@types.VariantCaseType::{name : result83, payload : lifted84, metadata : @types.MetadataEnvelope::{doc : lifted86, aliases : array88, examples : array91, deprecated : lifted94, role : lifted97}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::VariantType(array98) + } + 16 => { + + let array101 : Array[String] = []; + for index102 = 0; index102 < (mbt_ffi_load32((iter_base) + 12)); index102 = index102 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index102 * 8) + + let result100 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array101.push(result100) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::EnumType(array101) + } + 17 => { + + let array104 : Array[String] = []; + for index105 = 0; index105 < (mbt_ffi_load32((iter_base) + 12)); index105 = index105 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index105 * 8) + + let result103 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array104.push(result103) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::FlagsType(array104) + } + 18 => { + + let array106 : Array[Int] = []; + for index107 = 0; index107 < (mbt_ffi_load32((iter_base) + 12)); index107 = index107 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index107 * 4) + + array106.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::TupleType(array106) + } + 19 => { + + @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) + } + 20 => { + + @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) + } + 21 => { + + @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) + } + 22 => { + + @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) + } + 23 => { + + let lifted108 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + let lifted109 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 20)) + } + _ => panic() + } + + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted108, err : lifted109}) + } + 24 => { + + let lifted113 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array111 : Array[String] = []; + for index112 = 0; index112 < (mbt_ffi_load32((iter_base) + 16)); index112 = index112 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index112 * 8) + + let result110 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array111.push(result110) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array111) + } + _ => panic() + } + + let lifted114 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted115 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted117 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { + + let result116 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + + Option::Some(result116) + } + _ => panic() + } + + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted113, min_length : lifted114, max_length : lifted115, regex : lifted117}) + } + 25 => { + + let lifted121 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array119 : Array[String] = []; + for index120 = 0; index120 < (mbt_ffi_load32((iter_base) + 16)); index120 = index120 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index120 * 8) + + let result118 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array119.push(result118) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array119) + } + _ => panic() + } + + let lifted122 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted123 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } + + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted121, min_bytes : lifted122, max_bytes : lifted123}) + } + 26 => { + + let lifted127 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let array125 : Array[String] = []; + for index126 = 0; index126 < (mbt_ffi_load32((iter_base) + 20)); index126 = index126 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index126 * 8) + + let result124 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array125.push(result124) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + + Option::Some(array125) + } + _ => panic() + } + + let lifted131 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let array129 : Array[String] = []; + for index130 = 0; index130 < (mbt_ffi_load32((iter_base) + 32)); index130 = index130 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index130 * 8) + + let result128 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array129.push(result128) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + + Option::Some(array129) + } + _ => panic() + } + + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted127, allowed_extensions : lifted131}) + } + 27 => { + + let lifted135 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array133 : Array[String] = []; + for index134 = 0; index134 < (mbt_ffi_load32((iter_base) + 16)); index134 = index134 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index134 * 8) + + let result132 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array133.push(result132) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array133) + } + _ => panic() + } + + let lifted139 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + let array137 : Array[String] = []; + for index138 = 0; index138 < (mbt_ffi_load32((iter_base) + 28)); index138 = index138 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index138 * 8) + + let result136 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array137.push(result136) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + + Option::Some(array137) + } + _ => panic() + } + + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted135, allowed_hosts : lifted139}) + } + 28 => { + + @types.SchemaTypeBody::DatetimeType + } + 29 => { + + @types.SchemaTypeBody::DurationType + } + 30 => { + + let result140 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let array142 : Array[String] = []; + for index143 = 0; index143 < (mbt_ffi_load32((iter_base) + 20)); index143 = index143 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index143 * 8) + + let result141 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array142.push(result141) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + + let lifted145 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let result144 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result144}) + } + _ => panic() + } + + let lifted147 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let result146 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result146}) + } + _ => panic() + } + + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result140, allowed_suffixes : array142, min : lifted145, max : lifted147}) + } + 31 => { + + let array171 : Array[@types.UnionBranch] = []; + for index172 = 0; index172 < (mbt_ffi_load32((iter_base) + 12)); index172 = index172 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index172 * 92) + + let result148 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted157 = match (mbt_ffi_load8_u((iter_base) + 12)) { + 0 => { + + let result149 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Prefix(result149) + } + 1 => { + + let result150 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Suffix(result150) + } + 2 => { + + let result151 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Contains(result151) + } + 3 => { + + let result152 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Regex(result152) + } + 4 => { + + let result153 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + let lifted155 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let result154 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) + + Option::Some(result154) + } + _ => panic() + } + + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result153, literal : lifted155}) + } + 5 => { + + let result156 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::FieldAbsent(result156) + } + _ => panic() + } + + let lifted159 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { + + let result158 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + + Option::Some(result158) + } + _ => panic() + } + + let array161 : Array[String] = []; + for index162 = 0; index162 < (mbt_ffi_load32((iter_base) + 52)); index162 = index162 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index162 * 8) + + let result160 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array161.push(result160) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) + + let array164 : Array[String] = []; + for index165 = 0; index165 < (mbt_ffi_load32((iter_base) + 60)); index165 = index165 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index165 * 8) + + let result163 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array164.push(result163) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) + + let lifted167 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result166 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result166) + } + _ => panic() + } + + let lifted170 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + 0 => Option::None + 1 => { + + let lifted169 = match (mbt_ffi_load8_u((iter_base) + 80)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result168 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + + @types.Role::Other(result168) + } + _ => panic() + } + + Option::Some(lifted169) + } + _ => panic() + } + + array171.push(@types.UnionBranch::{tag : result148, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted157, metadata : @types.MetadataEnvelope::{doc : lifted159, aliases : array161, examples : array164, deprecated : lifted167, role : lifted170}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array171}) + } + 32 => { + + let lifted174 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let result173 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + Option::Some(result173) + } + _ => panic() + } + + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted174}) + } + 33 => { + + let lifted176 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let result175 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + + Option::Some(result175) + } + _ => panic() + } + + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted176}) + } + 34 => { + + @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) + } + 35 => { + + let lifted177 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaTypeBody::FutureType(lifted177) + } + 36 => { + + let lifted178 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaTypeBody::StreamType(lifted178) + } + _ => panic() + } + + let lifted181 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + 0 => Option::None + 1 => { + + let result180 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) + + Option::Some(result180) + } + _ => panic() + } + + let array183 : Array[String] = []; + for index184 = 0; index184 < (mbt_ffi_load32((iter_base) + 104)); index184 = index184 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index184 * 8) + + let result182 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array183.push(result182) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) + + let array186 : Array[String] = []; + for index187 = 0; index187 < (mbt_ffi_load32((iter_base) + 112)); index187 = index187 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index187 * 8) + + let result185 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array186.push(result185) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) + + let lifted189 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + 0 => Option::None + 1 => { + + let result188 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) + + Option::Some(result188) + } + _ => panic() + } + + let lifted192 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + 0 => Option::None + 1 => { + + let lifted191 = match (mbt_ffi_load8_u((iter_base) + 132)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result190 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) + + @types.Role::Other(result190) + } + _ => panic() + } + + Option::Some(lifted191) + } + _ => panic() + } + + array193.push(@types.SchemaTypeNode::{body : lifted179, metadata : @types.MetadataEnvelope::{doc : lifted181, aliases : array183, examples : array186, deprecated : lifted189, role : lifted192}}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 16)) + + let array198 : Array[@types.SchemaTypeDef] = []; + for index199 = 0; index199 < (mbt_ffi_load32((return_area) + 28)); index199 = index199 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 24)) + (index199 * 24) + + let result195 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted197 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let result196 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + + Option::Some(result196) + } + _ => panic() + } + + array198.push(@types.SchemaTypeDef::{id : result195, name : lifted197, body : mbt_ffi_load32((iter_base) + 20)}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 24)) + + let array229 : Array[@types.SchemaValueNode] = []; + for index230 = 0; index230 < (mbt_ffi_load32((return_area) + 40)); index230 = index230 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 36)) + (index230 * 32) + + let lifted228 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { + + @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) + } + 1 => { + + @types.SchemaValueNode::S8Value((mbt_ffi_load8((iter_base) + 8))) + } + 2 => { + + @types.SchemaValueNode::S16Value((mbt_ffi_load16((iter_base) + 8))) + } + 3 => { + + @types.SchemaValueNode::S32Value(mbt_ffi_load32((iter_base) + 8)) + } + 4 => { + + @types.SchemaValueNode::S64Value(mbt_ffi_load64((iter_base) + 8)) + } + 5 => { + + @types.SchemaValueNode::U8Value((mbt_ffi_load8_u((iter_base) + 8)).to_byte()) + } + 6 => { + + @types.SchemaValueNode::U16Value((mbt_ffi_load16_u((iter_base) + 8).land(0xFFFF).reinterpret_as_uint())) + } + 7 => { + + @types.SchemaValueNode::U32Value((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 8 => { + + @types.SchemaValueNode::U64Value((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64()) + } + 9 => { + + @types.SchemaValueNode::F32Value(mbt_ffi_loadf32((iter_base) + 8)) + } + 10 => { + + @types.SchemaValueNode::F64Value(mbt_ffi_loadf64((iter_base) + 8)) + } + 11 => { + + @types.SchemaValueNode::CharValue(Int::unsafe_to_char(mbt_ffi_load32((iter_base) + 8))) + } + 12 => { + + let result200 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::StringValue(result200) + } + 13 => { + + let array201 : Array[Int] = []; + for index202 = 0; index202 < (mbt_ffi_load32((iter_base) + 12)); index202 = index202 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index202 * 4) + + array201.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::RecordValue(array201) + } + 14 => { + + let lifted203 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted203}) + } + 15 => { + + @types.SchemaValueNode::EnumValue((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 16 => { + + let array204 : Array[Bool] = []; + for index205 = 0; index205 < (mbt_ffi_load32((iter_base) + 12)); index205 = index205 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index205 * 1) + + array204.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::FlagsValue(array204) + } + 17 => { + + let array206 : Array[Int] = []; + for index207 = 0; index207 < (mbt_ffi_load32((iter_base) + 12)); index207 = index207 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index207 * 4) + + array206.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::TupleValue(array206) + } + 18 => { + + let array208 : Array[Int] = []; + for index209 = 0; index209 < (mbt_ffi_load32((iter_base) + 12)); index209 = index209 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index209 * 4) + + array208.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::ListValue(array208) + } + 19 => { + + let array210 : Array[Int] = []; + for index211 = 0; index211 < (mbt_ffi_load32((iter_base) + 12)); index211 = index211 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index211 * 4) + + array210.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::FixedListValue(array210) + } + 20 => { + + let array212 : Array[@types.MapEntry] = []; + for index213 = 0; index213 < (mbt_ffi_load32((iter_base) + 12)); index213 = index213 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index213 * 8) + + array212.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::MapValue(array212) + } + 21 => { + + let lifted214 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaValueNode::OptionValue(lifted214) + } + 22 => { + + let lifted217 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { + + let lifted215 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.ResultValuePayload::OkValue(lifted215) + } + 1 => { + + let lifted216 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.ResultValuePayload::ErrValue(lifted216) + } + _ => panic() + } + + @types.SchemaValueNode::ResultValue(lifted217) + } + 23 => { + + let result218 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let lifted220 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result219 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result219) + } + _ => panic() + } + + @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result218, language : lifted220}) + } + 24 => { + + let result221 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let lifted223 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result222 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result222) + } + _ => panic() + } + + @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result221, mime_type : lifted223}) + } + 25 => { + + let result224 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::PathValue(result224) + } + 26 => { + + let result225 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::UrlValue(result225) + } + 27 => { + + @types.SchemaValueNode::DatetimeValue(@types.Datetime::{seconds : mbt_ffi_load64((iter_base) + 8), nanoseconds : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}) + } + 28 => { + + @types.SchemaValueNode::DurationValue(@types.DurationValuePayload::{nanoseconds : mbt_ffi_load64((iter_base) + 8)}) + } + 29 => { + + let result226 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result226}) + } + 30 => { + + let result227 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result227, body : mbt_ffi_load32((iter_base) + 16)}) + } + 31 => { + + @types.SchemaValueNode::SecretValue(@types.Secret::Secret(mbt_ffi_load32((iter_base) + 8))) + } + 32 => { + + @types.SchemaValueNode::QuotaTokenHandle(@types.QuotaToken::QuotaToken(mbt_ffi_load32((iter_base) + 8))) + } + 33 => { + + @types.SchemaValueNode::PermissionCardHandle(@types.PermissionCard::PermissionCard(mbt_ffi_load32((iter_base) + 8))) + } + 34 => { + + @types.SchemaValueNode::StreamValue(@types.SchemaValueStream::SchemaValueStream(mbt_ffi_load32((iter_base) + 8))) + } + _ => panic() + } + + array229.push(lifted228) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 36)) + + let lifted231 : @types.Uuid? = match mbt_ffi_load8_u((return_area) + 48) { + 0 => Option::None + 1 => { + + Option::Some(@types.Uuid::{high_bits : (mbt_ffi_load64((return_area) + 56)).reinterpret_as_uint64(), low_bits : (mbt_ffi_load64((return_area) + 64)).reinterpret_as_uint64()}) + } + _ => panic() + } + + Result::Ok((result, @types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array193, defs : array198, root : mbt_ffi_load32((return_area) + 32)}, value : @types.SchemaValueTree::{value_nodes : array229, root : mbt_ffi_load32((return_area) + 44)}}, lifted231)) + } + 1 => { + + let lifted470 = match (mbt_ffi_load8_u((return_area) + 8)) { + 0 => { + + let result232 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + + @common.AgentError::InvalidInput(result232) + } + 1 => { + + let result233 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + + @common.AgentError::InvalidMethod(result233) + } + 2 => { + + let result234 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + + @common.AgentError::InvalidType(result234) + } + 3 => { + + let result235 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) + + @common.AgentError::InvalidAgentId(result235) + } + 4 => { + + let array432 : Array[@types.SchemaTypeNode] = []; + for index433 = 0; index433 < (mbt_ffi_load32((return_area) + 16)); index433 = index433 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 12)) + (index433 * 144) + + let lifted418 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { + + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { + + @types.SchemaTypeBody::BoolType + } + 2 => { + + let lifted242 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted237 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted236 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted236) + } + _ => panic() + } + + let lifted239 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted238 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted238) + } + _ => panic() + } + + let lifted241 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result240 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result240) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted237, max : lifted239, unit : lifted241}) + } + _ => panic() + } + + @types.SchemaTypeBody::S8Type(lifted242) + } + 3 => { + + let lifted249 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted244 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted243 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted243) + } + _ => panic() + } + + let lifted246 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted245 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted245) + } + _ => panic() + } + + let lifted248 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result247 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result247) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted244, max : lifted246, unit : lifted248}) + } + _ => panic() + } + + @types.SchemaTypeBody::S16Type(lifted249) + } + 4 => { + + let lifted256 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted251 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted250 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted250) + } + _ => panic() + } + + let lifted253 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted252 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted252) + } + _ => panic() + } + + let lifted255 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result254 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result254) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted251, max : lifted253, unit : lifted255}) + } + _ => panic() + } + + @types.SchemaTypeBody::S32Type(lifted256) + } + 5 => { + + let lifted263 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted258 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted257 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted257) + } + _ => panic() + } + + let lifted260 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted259 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted259) + } + _ => panic() + } + + let lifted262 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result261 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result261) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted258, max : lifted260, unit : lifted262}) + } + _ => panic() + } + + @types.SchemaTypeBody::S64Type(lifted263) + } + 6 => { + + let lifted270 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted265 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted264 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted264) + } + _ => panic() + } + + let lifted267 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted266 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted266) + } + _ => panic() + } + + let lifted269 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result268 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result268) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted265, max : lifted267, unit : lifted269}) + } + _ => panic() + } + + @types.SchemaTypeBody::U8Type(lifted270) + } + 7 => { + + let lifted277 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted272 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted271 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted271) + } + _ => panic() + } + + let lifted274 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted273 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted273) + } + _ => panic() + } + + let lifted276 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result275 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result275) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted272, max : lifted274, unit : lifted276}) + } + _ => panic() + } + + @types.SchemaTypeBody::U16Type(lifted277) + } + 8 => { + + let lifted284 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted279 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted278 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted278) + } + _ => panic() + } + + let lifted281 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted280 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted280) + } + _ => panic() + } + + let lifted283 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result282 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result282) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted279, max : lifted281, unit : lifted283}) + } + _ => panic() + } + + @types.SchemaTypeBody::U32Type(lifted284) + } + 9 => { + + let lifted291 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted286 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted285 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted285) + } + _ => panic() + } + + let lifted288 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted287 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted287) + } + _ => panic() + } + + let lifted290 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result289 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result289) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted286, max : lifted288, unit : lifted290}) + } + _ => panic() + } + + @types.SchemaTypeBody::U64Type(lifted291) + } + 10 => { + + let lifted298 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted293 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted292 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted292) + } + _ => panic() + } + + let lifted295 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted294 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted294) + } + _ => panic() + } + + let lifted297 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result296 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result296) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted293, max : lifted295, unit : lifted297}) + } + _ => panic() + } + + @types.SchemaTypeBody::F32Type(lifted298) + } + 11 => { + + let lifted305 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted300 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted299 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted299) + } + _ => panic() + } + + let lifted302 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let lifted301 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { + + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted301) + } + _ => panic() + } + + let lifted304 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result303 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result303) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted300, max : lifted302, unit : lifted304}) + } + _ => panic() + } + + @types.SchemaTypeBody::F64Type(lifted305) + } + 12 => { + + @types.SchemaTypeBody::CharType + } + 13 => { + + @types.SchemaTypeBody::StringType + } + 14 => { + + let array320 : Array[@types.NamedFieldType] = []; + for index321 = 0; index321 < (mbt_ffi_load32((iter_base) + 12)); index321 = index321 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index321 * 68) + + let result306 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted308 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let result307 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + Option::Some(result307) + } + _ => panic() + } + + let array310 : Array[String] = []; + for index311 = 0; index311 < (mbt_ffi_load32((iter_base) + 28)); index311 = index311 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index311 * 8) + + let result309 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array310.push(result309) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + + let array313 : Array[String] = []; + for index314 = 0; index314 < (mbt_ffi_load32((iter_base) + 36)); index314 = index314 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index314 * 8) + + let result312 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array313.push(result312) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) + + let lifted316 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { + + let result315 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + + Option::Some(result315) + } + _ => panic() + } + + let lifted319 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { + 0 => Option::None + 1 => { + + let lifted318 = match (mbt_ffi_load8_u((iter_base) + 56)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result317 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) + + @types.Role::Other(result317) + } + _ => panic() + } + + Option::Some(lifted318) + } + _ => panic() + } + + array320.push(@types.NamedFieldType::{name : result306, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted308, aliases : array310, examples : array313, deprecated : lifted316, role : lifted319}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::RecordType(array320) + } + 15 => { + + let array337 : Array[@types.VariantCaseType] = []; + for index338 = 0; index338 < (mbt_ffi_load32((iter_base) + 12)); index338 = index338 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index338 * 72) + + let result322 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted323 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + let lifted325 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result324 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result324) + } + _ => panic() + } + + let array327 : Array[String] = []; + for index328 = 0; index328 < (mbt_ffi_load32((iter_base) + 32)); index328 = index328 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index328 * 8) + + let result326 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array327.push(result326) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + + let array330 : Array[String] = []; + for index331 = 0; index331 < (mbt_ffi_load32((iter_base) + 40)); index331 = index331 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index331 * 8) + + let result329 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array330.push(result329) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) + + let lifted333 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { + + let result332 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) + + Option::Some(result332) + } + _ => panic() + } + + let lifted336 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let lifted335 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result334 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) + + @types.Role::Other(result334) + } + _ => panic() + } + + Option::Some(lifted335) + } + _ => panic() + } + + array337.push(@types.VariantCaseType::{name : result322, payload : lifted323, metadata : @types.MetadataEnvelope::{doc : lifted325, aliases : array327, examples : array330, deprecated : lifted333, role : lifted336}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::VariantType(array337) + } + 16 => { + + let array340 : Array[String] = []; + for index341 = 0; index341 < (mbt_ffi_load32((iter_base) + 12)); index341 = index341 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index341 * 8) + + let result339 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array340.push(result339) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::EnumType(array340) + } + 17 => { + + let array343 : Array[String] = []; + for index344 = 0; index344 < (mbt_ffi_load32((iter_base) + 12)); index344 = index344 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index344 * 8) + + let result342 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array343.push(result342) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::FlagsType(array343) + } + 18 => { + + let array345 : Array[Int] = []; + for index346 = 0; index346 < (mbt_ffi_load32((iter_base) + 12)); index346 = index346 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index346 * 4) + + array345.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::TupleType(array345) + } + 19 => { + + @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) + } + 20 => { + + @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) + } + 21 => { + + @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) + } + 22 => { + + @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) + } + 23 => { + + let lifted347 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + let lifted348 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 20)) + } + _ => panic() + } + + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted347, err : lifted348}) + } + 24 => { + + let lifted352 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array350 : Array[String] = []; + for index351 = 0; index351 < (mbt_ffi_load32((iter_base) + 16)); index351 = index351 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index351 * 8) + + let result349 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array350.push(result349) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array350) + } + _ => panic() + } + + let lifted353 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted354 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted356 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { + + let result355 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + + Option::Some(result355) + } + _ => panic() + } + + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted352, min_length : lifted353, max_length : lifted354, regex : lifted356}) + } + 25 => { + + let lifted360 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array358 : Array[String] = []; + for index359 = 0; index359 < (mbt_ffi_load32((iter_base) + 16)); index359 = index359 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index359 * 8) + + let result357 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array358.push(result357) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array358) + } + _ => panic() + } + + let lifted361 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } + + let lifted362 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { + + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } + + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted360, min_bytes : lifted361, max_bytes : lifted362}) + } + 26 => { + + let lifted366 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let array364 : Array[String] = []; + for index365 = 0; index365 < (mbt_ffi_load32((iter_base) + 20)); index365 = index365 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index365 * 8) + + let result363 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array364.push(result363) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + + Option::Some(array364) + } + _ => panic() + } + + let lifted370 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let array368 : Array[String] = []; + for index369 = 0; index369 < (mbt_ffi_load32((iter_base) + 32)); index369 = index369 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index369 * 8) + + let result367 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array368.push(result367) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) + + Option::Some(array368) + } + _ => panic() + } + + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted366, allowed_extensions : lifted370}) + } + 27 => { + + let lifted374 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let array372 : Array[String] = []; + for index373 = 0; index373 < (mbt_ffi_load32((iter_base) + 16)); index373 = index373 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index373 * 8) + + let result371 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array372.push(result371) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + Option::Some(array372) + } + _ => panic() + } + + let lifted378 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { + + let array376 : Array[String] = []; + for index377 = 0; index377 < (mbt_ffi_load32((iter_base) + 28)); index377 = index377 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index377 * 8) + + let result375 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array376.push(result375) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) + + Option::Some(array376) + } + _ => panic() + } + + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted374, allowed_hosts : lifted378}) + } + 28 => { + + @types.SchemaTypeBody::DatetimeType + } + 29 => { + + @types.SchemaTypeBody::DurationType + } + 30 => { + + let result379 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let array381 : Array[String] = []; + for index382 = 0; index382 < (mbt_ffi_load32((iter_base) + 20)); index382 = index382 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index382 * 8) + + let result380 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array381.push(result380) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) + + let lifted384 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let result383 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result383}) + } + _ => panic() + } + + let lifted386 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { + + let result385 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) + + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result385}) + } + _ => panic() + } + + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result379, allowed_suffixes : array381, min : lifted384, max : lifted386}) + } + 31 => { + + let array410 : Array[@types.UnionBranch] = []; + for index411 = 0; index411 < (mbt_ffi_load32((iter_base) + 12)); index411 = index411 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index411 * 92) + + let result387 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted396 = match (mbt_ffi_load8_u((iter_base) + 12)) { + 0 => { + + let result388 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Prefix(result388) + } + 1 => { + + let result389 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Suffix(result389) + } + 2 => { + + let result390 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Contains(result390) + } + 3 => { + + let result391 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::Regex(result391) + } + 4 => { + + let result392 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + let lifted394 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { + + let result393 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) + + Option::Some(result393) + } + _ => panic() + } + + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result392, literal : lifted394}) + } + 5 => { + + let result395 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + @types.DiscriminatorRule::FieldAbsent(result395) + } + _ => panic() + } + + let lifted398 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { + + let result397 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) + + Option::Some(result397) + } + _ => panic() + } + + let array400 : Array[String] = []; + for index401 = 0; index401 < (mbt_ffi_load32((iter_base) + 52)); index401 = index401 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index401 * 8) + + let result399 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array400.push(result399) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) + + let array403 : Array[String] = []; + for index404 = 0; index404 < (mbt_ffi_load32((iter_base) + 60)); index404 = index404 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index404 * 8) + + let result402 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array403.push(result402) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) + + let lifted406 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { + + let result405 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result405) + } + _ => panic() + } + + let lifted409 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + 0 => Option::None + 1 => { + + let lifted408 = match (mbt_ffi_load8_u((iter_base) + 80)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result407 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) + + @types.Role::Other(result407) + } + _ => panic() + } + + Option::Some(lifted408) + } + _ => panic() + } + + array410.push(@types.UnionBranch::{tag : result387, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted396, metadata : @types.MetadataEnvelope::{doc : lifted398, aliases : array400, examples : array403, deprecated : lifted406, role : lifted409}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array410}) + } + 32 => { + + let lifted413 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + let result412 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) + + Option::Some(result412) + } + _ => panic() + } + + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted413}) + } + 33 => { + + let lifted415 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let result414 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + + Option::Some(result414) + } + _ => panic() + } + + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted415}) + } + 34 => { + + @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) + } + 35 => { + + let lifted416 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaTypeBody::FutureType(lifted416) + } + 36 => { + + let lifted417 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaTypeBody::StreamType(lifted417) + } + _ => panic() + } + + let lifted420 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + 0 => Option::None + 1 => { + + let result419 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) + + Option::Some(result419) + } + _ => panic() + } + + let array422 : Array[String] = []; + for index423 = 0; index423 < (mbt_ffi_load32((iter_base) + 104)); index423 = index423 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index423 * 8) + + let result421 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array422.push(result421) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) + + let array425 : Array[String] = []; + for index426 = 0; index426 < (mbt_ffi_load32((iter_base) + 112)); index426 = index426 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index426 * 8) + + let result424 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array425.push(result424) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) + + let lifted428 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + 0 => Option::None + 1 => { + + let result427 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) + + Option::Some(result427) + } + _ => panic() + } + + let lifted431 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + 0 => Option::None + 1 => { + + let lifted430 = match (mbt_ffi_load8_u((iter_base) + 132)) { + 0 => { + + @types.Role::Multimodal + } + 1 => { + + @types.Role::UnstructuredText + } + 2 => { + + @types.Role::UnstructuredBinary + } + 3 => { + + let result429 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) + + @types.Role::Other(result429) + } + _ => panic() + } + + Option::Some(lifted430) + } + _ => panic() + } + + array432.push(@types.SchemaTypeNode::{body : lifted418, metadata : @types.MetadataEnvelope::{doc : lifted420, aliases : array422, examples : array425, deprecated : lifted428, role : lifted431}}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 12)) + + let array437 : Array[@types.SchemaTypeDef] = []; + for index438 = 0; index438 < (mbt_ffi_load32((return_area) + 24)); index438 = index438 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 20)) + (index438 * 24) + + let result434 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + let lifted436 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let result435 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) + + Option::Some(result435) + } + _ => panic() + } + + array437.push(@types.SchemaTypeDef::{id : result434, name : lifted436, body : mbt_ffi_load32((iter_base) + 20)}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 20)) + + let array468 : Array[@types.SchemaValueNode] = []; + for index469 = 0; index469 < (mbt_ffi_load32((return_area) + 36)); index469 = index469 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 32)) + (index469 * 32) + + let lifted467 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { + + @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) + } + 1 => { + + @types.SchemaValueNode::S8Value((mbt_ffi_load8((iter_base) + 8))) + } + 2 => { + + @types.SchemaValueNode::S16Value((mbt_ffi_load16((iter_base) + 8))) + } + 3 => { + + @types.SchemaValueNode::S32Value(mbt_ffi_load32((iter_base) + 8)) + } + 4 => { + + @types.SchemaValueNode::S64Value(mbt_ffi_load64((iter_base) + 8)) + } + 5 => { + + @types.SchemaValueNode::U8Value((mbt_ffi_load8_u((iter_base) + 8)).to_byte()) + } + 6 => { + + @types.SchemaValueNode::U16Value((mbt_ffi_load16_u((iter_base) + 8).land(0xFFFF).reinterpret_as_uint())) + } + 7 => { + + @types.SchemaValueNode::U32Value((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 8 => { + + @types.SchemaValueNode::U64Value((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64()) + } + 9 => { + + @types.SchemaValueNode::F32Value(mbt_ffi_loadf32((iter_base) + 8)) + } + 10 => { + + @types.SchemaValueNode::F64Value(mbt_ffi_loadf64((iter_base) + 8)) + } + 11 => { + + @types.SchemaValueNode::CharValue(Int::unsafe_to_char(mbt_ffi_load32((iter_base) + 8))) + } + 12 => { + + let result439 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::StringValue(result439) + } + 13 => { + + let array440 : Array[Int] = []; + for index441 = 0; index441 < (mbt_ffi_load32((iter_base) + 12)); index441 = index441 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index441 * 4) + + array440.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::RecordValue(array440) + } + 14 => { + + let lifted442 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted442}) + } + 15 => { + + @types.SchemaValueNode::EnumValue((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 16 => { + + let array443 : Array[Bool] = []; + for index444 = 0; index444 < (mbt_ffi_load32((iter_base) + 12)); index444 = index444 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index444 * 1) + + array443.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::FlagsValue(array443) + } + 17 => { + + let array445 : Array[Int] = []; + for index446 = 0; index446 < (mbt_ffi_load32((iter_base) + 12)); index446 = index446 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index446 * 4) + + array445.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::TupleValue(array445) + } + 18 => { + + let array447 : Array[Int] = []; + for index448 = 0; index448 < (mbt_ffi_load32((iter_base) + 12)); index448 = index448 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index448 * 4) + + array447.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::ListValue(array447) + } + 19 => { + + let array449 : Array[Int] = []; + for index450 = 0; index450 < (mbt_ffi_load32((iter_base) + 12)); index450 = index450 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index450 * 4) + + array449.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::FixedListValue(array449) + } + 20 => { + + let array451 : Array[@types.MapEntry] = []; + for index452 = 0; index452 < (mbt_ffi_load32((iter_base) + 12)); index452 = index452 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index452 * 8) + + array451.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) + + @types.SchemaValueNode::MapValue(array451) + } + 21 => { + + let lifted453 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } + + @types.SchemaValueNode::OptionValue(lifted453) + } + 22 => { + + let lifted456 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { + + let lifted454 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.ResultValuePayload::OkValue(lifted454) + } + 1 => { + + let lifted455 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { + + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } + + @types.ResultValuePayload::ErrValue(lifted455) + } + _ => panic() + } + + @types.SchemaValueNode::ResultValue(lifted456) + } + 23 => { + + let result457 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let lifted459 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result458 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result458) + } + _ => panic() + } + + @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result457, language : lifted459}) + } + 24 => { + + let result460 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + let lifted462 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let result461 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + Option::Some(result461) + } + _ => panic() + } + + @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result460, mime_type : lifted462}) + } + 25 => { + + let result463 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::PathValue(result463) + } + 26 => { + + let result464 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::UrlValue(result464) + } + 27 => { + + @types.SchemaValueNode::DatetimeValue(@types.Datetime::{seconds : mbt_ffi_load64((iter_base) + 8), nanoseconds : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}) + } + 28 => { + + @types.SchemaValueNode::DurationValue(@types.DurationValuePayload::{nanoseconds : mbt_ffi_load64((iter_base) + 8)}) + } + 29 => { + + let result465 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) + + @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result465}) + } + 30 => { + + let result466 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) + + @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result466, body : mbt_ffi_load32((iter_base) + 16)}) + } + 31 => { + + @types.SchemaValueNode::SecretValue(@types.Secret::Secret(mbt_ffi_load32((iter_base) + 8))) + } + 32 => { + + @types.SchemaValueNode::QuotaTokenHandle(@types.QuotaToken::QuotaToken(mbt_ffi_load32((iter_base) + 8))) + } + 33 => { + + @types.SchemaValueNode::PermissionCardHandle(@types.PermissionCard::PermissionCard(mbt_ffi_load32((iter_base) + 8))) + } + 34 => { + + @types.SchemaValueNode::StreamValue(@types.SchemaValueStream::SchemaValueStream(mbt_ffi_load32((iter_base) + 8))) + } + _ => panic() + } + + array468.push(lifted467) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 32)) + + @common.AgentError::CustomError(@types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array432, defs : array437, root : mbt_ffi_load32((return_area) + 28)}, value : @types.SchemaValueTree::{value_nodes : array468, root : mbt_ffi_load32((return_area) + 40)}}) + } + _ => panic() + } + + Result::Err(lifted470) + } + _ => panic() + } + let ret = lifted471 + mbt_ffi_free(ptr) + mbt_ffi_free(return_area) + return ret + +} +///| +pub fn create_webhook(promise_id : @types.PromiseId) -> Result[String, WebhookError] { + + let ptr = mbt_ffi_str2ptr(((promise_id).agent_id).agent_id) + let return_area = mbt_ffi_malloc(16) + wasmImportCreateWebhook((((((promise_id).agent_id).component_id).uuid).high_bits).reinterpret_as_int64(), (((((promise_id).agent_id).component_id).uuid).low_bits).reinterpret_as_int64(), ptr, ((promise_id).agent_id).agent_id.length(), ((promise_id).oplog_idx).reinterpret_as_int64(), return_area); + + let lifted1 = match (mbt_ffi_load8_u((return_area) + 0)) { + 0 => { + + let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8)) + + Result::Ok(result) + } + 1 => { + + let lifted = match (mbt_ffi_load8_u((return_area) + 4)) { + 0 => { + + WebhookError::PermissionDenied + } + 1 => { + + let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) + + WebhookError::InternalError(result0) + } + _ => panic() + } + + Result::Err(lifted) + } + _ => panic() + } + let ret = lifted1 + mbt_ffi_free(ptr) + mbt_ffi_free(return_area) + return ret + +} +///| +/// Creates an RPC client connecting to the given target agent. +/// +/// `constructor` is a value tree whose root encodes the target agent +/// constructor's parameter list. This fail-fast form traps if the client +/// cannot be created and is intended for statically generated clients. +pub fn WasmRpc::wasm_rpc(agent_type_name : String, constructor_ : @types.SchemaValueTree, phantom_id : @types.Uuid?, agent_config : Array[@common.TypedAgentConfigValue]) -> WasmRpc { + let cleanup_list : Array[Int] = [] + + let ptr = mbt_ffi_str2ptr(agent_type_name) + + let address70 = mbt_ffi_malloc(((constructor_).value_nodes).length() * 32); + for index71 = 0; index71 < ((constructor_).value_nodes).length(); index71 = index71 + 1 { + let iter_elem : @types.SchemaValueNode = ((constructor_).value_nodes)[(index71)] + let iter_base = address70 + (index71 * 32); + + match iter_elem { + BoolValue(payload) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store8((iter_base) + 8, (if payload { 1 } else { 0 })) + + () + } + S8Value(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload0)) + + () + } + S16Value(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload1)) + + () + } + S32Value(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 8, payload2) + + () + } + S64Value(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store64((iter_base) + 8, payload3) + + () + } + U8Value(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store8((iter_base) + 8, (payload4).to_int()) + + () + } + U16Value(payload5) => { + mbt_ffi_store8((iter_base) + 0, (6)) + mbt_ffi_store16((iter_base) + 8, (payload5).reinterpret_as_int()) + + () + } + U32Value(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 8, (payload6).reinterpret_as_int()) + + () + } + U64Value(payload7) => { + mbt_ffi_store8((iter_base) + 0, (8)) + mbt_ffi_store64((iter_base) + 8, (payload7).reinterpret_as_int64()) + + () + } + F32Value(payload8) => { + mbt_ffi_store8((iter_base) + 0, (9)) + mbt_ffi_storef32((iter_base) + 8, payload8) + + () + } + F64Value(payload9) => { + mbt_ffi_store8((iter_base) + 0, (10)) + mbt_ffi_storef64((iter_base) + 8, payload9) + + () + } + CharValue(payload10) => { + mbt_ffi_store8((iter_base) + 0, (11)) + mbt_ffi_store32((iter_base) + 8, (payload10).to_int()) + + () + } + StringValue(payload11) => { + mbt_ffi_store8((iter_base) + 0, (12)) + + let ptr12 = mbt_ffi_str2ptr(payload11) + mbt_ffi_store32((iter_base) + 12, payload11.length()) + mbt_ffi_store32((iter_base) + 8, ptr12) + cleanup_list.push(ptr12) + + () + } + RecordValue(payload13) => { + mbt_ffi_store8((iter_base) + 0, (13)) + + let address = mbt_ffi_malloc((payload13).length() * 4); + for index = 0; index < (payload13).length(); index = index + 1 { + let iter_elem : Int = (payload13)[(index)] + let iter_base = address + (index * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload13).length()) + mbt_ffi_store32((iter_base) + 8, address) + cleanup_list.push(address) + + () + } + VariantValue(payload14) => { + mbt_ffi_store8((iter_base) + 0, (14)) + mbt_ffi_store32((iter_base) + 8, ((payload14).case).reinterpret_as_int()) + + match ((payload14).payload) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload16) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload16) + + () + } + } + + () + } + EnumValue(payload17) => { + mbt_ffi_store8((iter_base) + 0, (15)) + mbt_ffi_store32((iter_base) + 8, (payload17).reinterpret_as_int()) + + () + } + FlagsValue(payload18) => { + mbt_ffi_store8((iter_base) + 0, (16)) + + let address19 = mbt_ffi_malloc((payload18).length() * 1); + for index20 = 0; index20 < (payload18).length(); index20 = index20 + 1 { + let iter_elem : Bool = (payload18)[(index20)] + let iter_base = address19 + (index20 * 1); + mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + + } + mbt_ffi_store32((iter_base) + 12, (payload18).length()) + mbt_ffi_store32((iter_base) + 8, address19) + cleanup_list.push(address19) + + () + } + TupleValue(payload21) => { + mbt_ffi_store8((iter_base) + 0, (17)) + + let address22 = mbt_ffi_malloc((payload21).length() * 4); + for index23 = 0; index23 < (payload21).length(); index23 = index23 + 1 { + let iter_elem : Int = (payload21)[(index23)] + let iter_base = address22 + (index23 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload21).length()) + mbt_ffi_store32((iter_base) + 8, address22) + cleanup_list.push(address22) + + () + } + ListValue(payload24) => { + mbt_ffi_store8((iter_base) + 0, (18)) + + let address25 = mbt_ffi_malloc((payload24).length() * 4); + for index26 = 0; index26 < (payload24).length(); index26 = index26 + 1 { + let iter_elem : Int = (payload24)[(index26)] + let iter_base = address25 + (index26 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload24).length()) + mbt_ffi_store32((iter_base) + 8, address25) + cleanup_list.push(address25) + + () + } + FixedListValue(payload27) => { + mbt_ffi_store8((iter_base) + 0, (19)) + + let address28 = mbt_ffi_malloc((payload27).length() * 4); + for index29 = 0; index29 < (payload27).length(); index29 = index29 + 1 { + let iter_elem : Int = (payload27)[(index29)] + let iter_base = address28 + (index29 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload27).length()) + mbt_ffi_store32((iter_base) + 8, address28) + cleanup_list.push(address28) + + () + } + MapValue(payload30) => { + mbt_ffi_store8((iter_base) + 0, (20)) + + let address31 = mbt_ffi_malloc((payload30).length() * 8); + for index32 = 0; index32 < (payload30).length(); index32 = index32 + 1 { + let iter_elem : @types.MapEntry = (payload30)[(index32)] + let iter_base = address31 + (index32 * 8); + mbt_ffi_store32((iter_base) + 0, (iter_elem).key) + mbt_ffi_store32((iter_base) + 4, (iter_elem).value) + + } + mbt_ffi_store32((iter_base) + 12, (payload30).length()) + mbt_ffi_store32((iter_base) + 8, address31) + cleanup_list.push(address31) + + () + } + OptionValue(payload33) => { + mbt_ffi_store8((iter_base) + 0, (21)) + + match (payload33) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload35) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload35) + + () + } + } + + () + } + ResultValue(payload36) => { + mbt_ffi_store8((iter_base) + 0, (22)) + + match payload36 { + OkValue(payload37) => { + mbt_ffi_store8((iter_base) + 8, (0)) + + match (payload37) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload39) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload39) + + () + } + } + + () + } + ErrValue(payload40) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match (payload40) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload42) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload42) + + () + } + } + + () + } + } + + () + } + TextValue(payload43) => { + mbt_ffi_store8((iter_base) + 0, (23)) + + let ptr44 = mbt_ffi_str2ptr((payload43).text) + mbt_ffi_store32((iter_base) + 12, (payload43).text.length()) + mbt_ffi_store32((iter_base) + 8, ptr44) + + match ((payload43).language) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload46) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr47 = mbt_ffi_str2ptr(payload46) + mbt_ffi_store32((iter_base) + 24, payload46.length()) + mbt_ffi_store32((iter_base) + 20, ptr47) + cleanup_list.push(ptr47) + + () + } + } + cleanup_list.push(ptr44) + + () + } + BinaryValue(payload48) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + let ptr49 = mbt_ffi_bytes2ptr((payload48).bytes) + + mbt_ffi_store32((iter_base) + 12, (payload48).bytes.length()) + mbt_ffi_store32((iter_base) + 8, ptr49) + + match ((payload48).mime_type) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload51) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr52 = mbt_ffi_str2ptr(payload51) + mbt_ffi_store32((iter_base) + 24, payload51.length()) + mbt_ffi_store32((iter_base) + 20, ptr52) + cleanup_list.push(ptr52) + + () + } + } + cleanup_list.push(ptr49) + + () + } + PathValue(payload53) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + let ptr54 = mbt_ffi_str2ptr(payload53) + mbt_ffi_store32((iter_base) + 12, payload53.length()) + mbt_ffi_store32((iter_base) + 8, ptr54) + cleanup_list.push(ptr54) + + () + } + UrlValue(payload55) => { + mbt_ffi_store8((iter_base) + 0, (26)) + + let ptr56 = mbt_ffi_str2ptr(payload55) + mbt_ffi_store32((iter_base) + 12, payload55.length()) + mbt_ffi_store32((iter_base) + 8, ptr56) + cleanup_list.push(ptr56) + + () + } + DatetimeValue(payload57) => { + mbt_ffi_store8((iter_base) + 0, (27)) + mbt_ffi_store64((iter_base) + 8, (payload57).seconds) + mbt_ffi_store32((iter_base) + 16, ((payload57).nanoseconds).reinterpret_as_int()) + + () + } + DurationValue(payload58) => { + mbt_ffi_store8((iter_base) + 0, (28)) + mbt_ffi_store64((iter_base) + 8, (payload58).nanoseconds) + + () + } + QuantityValueNode(payload59) => { + mbt_ffi_store8((iter_base) + 0, (29)) + mbt_ffi_store64((iter_base) + 8, (payload59).mantissa) + mbt_ffi_store32((iter_base) + 16, (payload59).scale) + + let ptr60 = mbt_ffi_str2ptr((payload59).unit) + mbt_ffi_store32((iter_base) + 24, (payload59).unit.length()) + mbt_ffi_store32((iter_base) + 20, ptr60) + cleanup_list.push(ptr60) + + () + } + UnionValue(payload61) => { + mbt_ffi_store8((iter_base) + 0, (30)) + + let ptr62 = mbt_ffi_str2ptr((payload61).tag) + mbt_ffi_store32((iter_base) + 12, (payload61).tag.length()) + mbt_ffi_store32((iter_base) + 8, ptr62) + mbt_ffi_store32((iter_base) + 16, (payload61).body) + cleanup_list.push(ptr62) + + () + } + SecretValue(payload63) => { + mbt_ffi_store8((iter_base) + 0, (31)) + + let @types.Secret(handle) = payload63 + mbt_ffi_store32((iter_base) + 8, handle) + + () + } + QuotaTokenHandle(payload64) => { + mbt_ffi_store8((iter_base) + 0, (32)) + + let @types.QuotaToken(handle65) = payload64 + mbt_ffi_store32((iter_base) + 8, handle65) + + () + } + PermissionCardHandle(payload66) => { + mbt_ffi_store8((iter_base) + 0, (33)) + + let @types.PermissionCard(handle67) = payload66 + mbt_ffi_store32((iter_base) + 8, handle67) + + () + } + StreamValue(payload68) => { + mbt_ffi_store8((iter_base) + 0, (34)) + + let @types.SchemaValueStream(handle69) = payload68 + mbt_ffi_store32((iter_base) + 8, handle69) + + () + } + } + + } + + let (lowered, lowered74, lowered75) = match (phantom_id) { + None => { + + ((0), 0L, 0L) + } + Some(payload73) => { + + ((1), ((payload73).high_bits).reinterpret_as_int64(), ((payload73).low_bits).reinterpret_as_int64()) + } + } + + let address525 = mbt_ffi_malloc((agent_config).length() * 40); + for index526 = 0; index526 < (agent_config).length(); index526 = index526 + 1 { + let iter_elem : @common.TypedAgentConfigValue = (agent_config)[(index526)] + let iter_base = address525 + (index526 * 40); + + let address77 = mbt_ffi_malloc(((iter_elem).path).length() * 8); + for index78 = 0; index78 < ((iter_elem).path).length(); index78 = index78 + 1 { + let iter_elem : String = ((iter_elem).path)[(index78)] + let iter_base = address77 + (index78 * 8); + + let ptr76 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr76) + cleanup_list.push(ptr76) + + } + mbt_ffi_store32((iter_base) + 4, ((iter_elem).path).length()) + mbt_ffi_store32((iter_base) + 0, address77) + + let address441 = mbt_ffi_malloc(((((iter_elem).value).graph).type_nodes).length() * 144); + for index442 = 0; index442 < ((((iter_elem).value).graph).type_nodes).length(); index442 = index442 + 1 { + let iter_elem : @types.SchemaTypeNode = ((((iter_elem).value).graph).type_nodes)[(index442)] + let iter_base = address441 + (index442 * 144); + + match (iter_elem).body { + RefType(payload79) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 8, payload79) + + () + } + BoolType => { + mbt_ffi_store8((iter_base) + 0, (1)) + + () + } + S8Type(payload81) => { + mbt_ffi_store8((iter_base) + 0, (2)) + + match (payload81) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload83) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload83).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload85) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload85 { + Signed(payload86) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload86) + + () + } + Unsigned(payload87) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload87).reinterpret_as_int64()) + + () + } + FloatBits(payload88) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload88).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload83).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload90) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload90 { + Signed(payload91) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload91) + + () + } + Unsigned(payload92) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload92).reinterpret_as_int64()) + + () + } + FloatBits(payload93) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload93).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload83).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload95) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr96 = mbt_ffi_str2ptr(payload95) + mbt_ffi_store32((iter_base) + 72, payload95.length()) + mbt_ffi_store32((iter_base) + 68, ptr96) + cleanup_list.push(ptr96) + + () + } + } + + () + } + } + + () + } + S16Type(payload97) => { + mbt_ffi_store8((iter_base) + 0, (3)) + + match (payload97) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload99) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload99).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload101) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload101 { + Signed(payload102) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload102) + + () + } + Unsigned(payload103) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload103).reinterpret_as_int64()) + + () + } + FloatBits(payload104) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload104).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload99).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload106) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload106 { + Signed(payload107) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload107) + + () + } + Unsigned(payload108) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload108).reinterpret_as_int64()) + + () + } + FloatBits(payload109) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload109).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload99).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload111) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr112 = mbt_ffi_str2ptr(payload111) + mbt_ffi_store32((iter_base) + 72, payload111.length()) + mbt_ffi_store32((iter_base) + 68, ptr112) + cleanup_list.push(ptr112) + + () + } + } + + () + } + } + + () + } + S32Type(payload113) => { + mbt_ffi_store8((iter_base) + 0, (4)) + + match (payload113) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload115) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload115).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload117) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload117 { + Signed(payload118) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload118) + + () + } + Unsigned(payload119) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload119).reinterpret_as_int64()) + + () + } + FloatBits(payload120) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload120).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload115).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload122) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload122 { + Signed(payload123) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload123) + + () + } + Unsigned(payload124) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload124).reinterpret_as_int64()) + + () + } + FloatBits(payload125) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload125).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload115).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload127) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr128 = mbt_ffi_str2ptr(payload127) + mbt_ffi_store32((iter_base) + 72, payload127.length()) + mbt_ffi_store32((iter_base) + 68, ptr128) + cleanup_list.push(ptr128) + + () + } + } + + () + } + } + + () + } + S64Type(payload129) => { + mbt_ffi_store8((iter_base) + 0, (5)) + + match (payload129) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload131) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload131).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload133) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload133 { + Signed(payload134) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload134) + + () + } + Unsigned(payload135) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload135).reinterpret_as_int64()) + + () + } + FloatBits(payload136) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload136).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload131).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload138) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload138 { + Signed(payload139) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload139) + + () + } + Unsigned(payload140) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload140).reinterpret_as_int64()) + + () + } + FloatBits(payload141) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload141).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload131).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload143) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr144 = mbt_ffi_str2ptr(payload143) + mbt_ffi_store32((iter_base) + 72, payload143.length()) + mbt_ffi_store32((iter_base) + 68, ptr144) + cleanup_list.push(ptr144) + + () + } + } + + () + } + } + + () + } + U8Type(payload145) => { + mbt_ffi_store8((iter_base) + 0, (6)) + + match (payload145) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload147) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload147).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload149) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload149 { + Signed(payload150) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload150) + + () + } + Unsigned(payload151) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload151).reinterpret_as_int64()) + + () + } + FloatBits(payload152) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload152).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload147).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload154) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload154 { + Signed(payload155) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload155) + + () + } + Unsigned(payload156) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload156).reinterpret_as_int64()) + + () + } + FloatBits(payload157) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload157).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload147).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload159) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr160 = mbt_ffi_str2ptr(payload159) + mbt_ffi_store32((iter_base) + 72, payload159.length()) + mbt_ffi_store32((iter_base) + 68, ptr160) + cleanup_list.push(ptr160) + + () + } + } + + () + } + } + + () + } + U16Type(payload161) => { + mbt_ffi_store8((iter_base) + 0, (7)) + + match (payload161) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload163) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload163).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload165) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload165 { + Signed(payload166) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload166) + + () + } + Unsigned(payload167) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload167).reinterpret_as_int64()) + + () + } + FloatBits(payload168) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload168).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload163).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload170) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload170 { + Signed(payload171) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload171) + + () + } + Unsigned(payload172) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload172).reinterpret_as_int64()) + + () + } + FloatBits(payload173) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload173).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload163).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload175) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr176 = mbt_ffi_str2ptr(payload175) + mbt_ffi_store32((iter_base) + 72, payload175.length()) + mbt_ffi_store32((iter_base) + 68, ptr176) + cleanup_list.push(ptr176) + + () + } + } + + () + } + } + + () + } + U32Type(payload177) => { + mbt_ffi_store8((iter_base) + 0, (8)) + + match (payload177) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload179) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload179).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload181) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload181 { + Signed(payload182) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload182) + + () + } + Unsigned(payload183) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload183).reinterpret_as_int64()) + + () + } + FloatBits(payload184) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload184).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload179).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload186) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload186 { + Signed(payload187) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload187) + + () + } + Unsigned(payload188) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload188).reinterpret_as_int64()) + + () + } + FloatBits(payload189) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload189).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload179).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload191) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr192 = mbt_ffi_str2ptr(payload191) + mbt_ffi_store32((iter_base) + 72, payload191.length()) + mbt_ffi_store32((iter_base) + 68, ptr192) + cleanup_list.push(ptr192) + + () + } + } + + () + } + } + + () + } + U64Type(payload193) => { + mbt_ffi_store8((iter_base) + 0, (9)) + + match (payload193) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload195) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload195).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload197) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload197 { + Signed(payload198) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload198) + + () + } + Unsigned(payload199) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload199).reinterpret_as_int64()) + + () + } + FloatBits(payload200) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload200).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload195).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload202) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload202 { + Signed(payload203) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload203) + + () + } + Unsigned(payload204) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload204).reinterpret_as_int64()) + + () + } + FloatBits(payload205) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload205).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload195).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload207) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr208 = mbt_ffi_str2ptr(payload207) + mbt_ffi_store32((iter_base) + 72, payload207.length()) + mbt_ffi_store32((iter_base) + 68, ptr208) + cleanup_list.push(ptr208) + + () + } + } + + () + } + } + + () + } + F32Type(payload209) => { + mbt_ffi_store8((iter_base) + 0, (10)) + + match (payload209) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload211) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload211).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload213) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload213 { + Signed(payload214) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload214) + + () + } + Unsigned(payload215) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload215).reinterpret_as_int64()) + + () + } + FloatBits(payload216) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload216).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload211).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload218) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload218 { + Signed(payload219) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload219) + + () + } + Unsigned(payload220) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload220).reinterpret_as_int64()) + + () + } + FloatBits(payload221) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload221).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload211).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload223) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr224 = mbt_ffi_str2ptr(payload223) + mbt_ffi_store32((iter_base) + 72, payload223.length()) + mbt_ffi_store32((iter_base) + 68, ptr224) + cleanup_list.push(ptr224) + + () + } + } + + () + } + } + + () + } + F64Type(payload225) => { + mbt_ffi_store8((iter_base) + 0, (11)) + + match (payload225) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload227) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload227).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload229) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload229 { + Signed(payload230) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload230) + + () + } + Unsigned(payload231) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload231).reinterpret_as_int64()) + + () + } + FloatBits(payload232) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload232).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload227).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload234) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload234 { + Signed(payload235) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload235) + + () + } + Unsigned(payload236) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload236).reinterpret_as_int64()) + + () + } + FloatBits(payload237) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload237).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload227).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload239) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr240 = mbt_ffi_str2ptr(payload239) + mbt_ffi_store32((iter_base) + 72, payload239.length()) + mbt_ffi_store32((iter_base) + 68, ptr240) + cleanup_list.push(ptr240) + + () + } + } + + () + } + } + + () + } + CharType => { + mbt_ffi_store8((iter_base) + 0, (12)) + + () + } + StringType => { + mbt_ffi_store8((iter_base) + 0, (13)) + + () + } + RecordType(payload243) => { + mbt_ffi_store8((iter_base) + 0, (14)) + + let address264 = mbt_ffi_malloc((payload243).length() * 68); + for index265 = 0; index265 < (payload243).length(); index265 = index265 + 1 { + let iter_elem : @types.NamedFieldType = (payload243)[(index265)] + let iter_base = address264 + (index265 * 68); + + let ptr244 = mbt_ffi_str2ptr((iter_elem).name) + mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) + mbt_ffi_store32((iter_base) + 0, ptr244) + mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload246) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let ptr247 = mbt_ffi_str2ptr(payload246) + mbt_ffi_store32((iter_base) + 20, payload246.length()) + mbt_ffi_store32((iter_base) + 16, ptr247) + cleanup_list.push(ptr247) + + () + } + } + + let address249 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index250 = 0; index250 < (((iter_elem).metadata).aliases).length(); index250 = index250 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index250)] + let iter_base = address249 + (index250 * 8); + + let ptr248 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr248) + cleanup_list.push(ptr248) + + } + mbt_ffi_store32((iter_base) + 28, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 24, address249) + + let address252 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index253 = 0; index253 < (((iter_elem).metadata).examples).length(); index253 = index253 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index253)] + let iter_base = address252 + (index253 * 8); + + let ptr251 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr251) + cleanup_list.push(ptr251) + + } + mbt_ffi_store32((iter_base) + 36, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 32, address252) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload255) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + let ptr256 = mbt_ffi_str2ptr(payload255) + mbt_ffi_store32((iter_base) + 48, payload255.length()) + mbt_ffi_store32((iter_base) + 44, ptr256) + cleanup_list.push(ptr256) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 52, (0)) + + () + } + Some(payload258) => { + mbt_ffi_store8((iter_base) + 52, (1)) + + match payload258 { + Multimodal => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 56, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 56, (2)) + + () + } + Other(payload262) => { + mbt_ffi_store8((iter_base) + 56, (3)) + + let ptr263 = mbt_ffi_str2ptr(payload262) + mbt_ffi_store32((iter_base) + 64, payload262.length()) + mbt_ffi_store32((iter_base) + 60, ptr263) + cleanup_list.push(ptr263) + + () + } + } + + () + } + } + cleanup_list.push(ptr244) + cleanup_list.push(address249) + cleanup_list.push(address252) + + } + mbt_ffi_store32((iter_base) + 12, (payload243).length()) + mbt_ffi_store32((iter_base) + 8, address264) + cleanup_list.push(address264) + + () + } + VariantType(payload266) => { + mbt_ffi_store8((iter_base) + 0, (15)) + + let address289 = mbt_ffi_malloc((payload266).length() * 72); + for index290 = 0; index290 < (payload266).length(); index290 = index290 + 1 { + let iter_elem : @types.VariantCaseType = (payload266)[(index290)] + let iter_base = address289 + (index290 * 72); + + let ptr267 = mbt_ffi_str2ptr((iter_elem).name) + mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) + mbt_ffi_store32((iter_base) + 0, ptr267) + + match ((iter_elem).payload) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload269) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload269) + + () + } + } + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload271) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr272 = mbt_ffi_str2ptr(payload271) + mbt_ffi_store32((iter_base) + 24, payload271.length()) + mbt_ffi_store32((iter_base) + 20, ptr272) + cleanup_list.push(ptr272) + + () + } + } + + let address274 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index275 = 0; index275 < (((iter_elem).metadata).aliases).length(); index275 = index275 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index275)] + let iter_base = address274 + (index275 * 8); + + let ptr273 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr273) + cleanup_list.push(ptr273) + + } + mbt_ffi_store32((iter_base) + 32, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 28, address274) + + let address277 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index278 = 0; index278 < (((iter_elem).metadata).examples).length(); index278 = index278 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index278)] + let iter_base = address277 + (index278 * 8); + + let ptr276 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr276) + cleanup_list.push(ptr276) + + } + mbt_ffi_store32((iter_base) + 40, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 36, address277) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 44, (0)) + + () + } + Some(payload280) => { + mbt_ffi_store8((iter_base) + 44, (1)) + + let ptr281 = mbt_ffi_str2ptr(payload280) + mbt_ffi_store32((iter_base) + 52, payload280.length()) + mbt_ffi_store32((iter_base) + 48, ptr281) + cleanup_list.push(ptr281) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + Some(payload283) => { + mbt_ffi_store8((iter_base) + 56, (1)) + + match payload283 { + Multimodal => { + mbt_ffi_store8((iter_base) + 60, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 60, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 60, (2)) + + () + } + Other(payload287) => { + mbt_ffi_store8((iter_base) + 60, (3)) + + let ptr288 = mbt_ffi_str2ptr(payload287) + mbt_ffi_store32((iter_base) + 68, payload287.length()) + mbt_ffi_store32((iter_base) + 64, ptr288) + cleanup_list.push(ptr288) + + () + } + } + + () + } + } + cleanup_list.push(ptr267) + cleanup_list.push(address274) + cleanup_list.push(address277) + + } + mbt_ffi_store32((iter_base) + 12, (payload266).length()) + mbt_ffi_store32((iter_base) + 8, address289) + cleanup_list.push(address289) + + () + } + EnumType(payload291) => { + mbt_ffi_store8((iter_base) + 0, (16)) + + let address293 = mbt_ffi_malloc((payload291).length() * 8); + for index294 = 0; index294 < (payload291).length(); index294 = index294 + 1 { + let iter_elem : String = (payload291)[(index294)] + let iter_base = address293 + (index294 * 8); + + let ptr292 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr292) + cleanup_list.push(ptr292) + + } + mbt_ffi_store32((iter_base) + 12, (payload291).length()) + mbt_ffi_store32((iter_base) + 8, address293) + cleanup_list.push(address293) + + () + } + FlagsType(payload295) => { + mbt_ffi_store8((iter_base) + 0, (17)) + + let address297 = mbt_ffi_malloc((payload295).length() * 8); + for index298 = 0; index298 < (payload295).length(); index298 = index298 + 1 { + let iter_elem : String = (payload295)[(index298)] + let iter_base = address297 + (index298 * 8); + + let ptr296 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr296) + cleanup_list.push(ptr296) + + } + mbt_ffi_store32((iter_base) + 12, (payload295).length()) + mbt_ffi_store32((iter_base) + 8, address297) + cleanup_list.push(address297) + + () + } + TupleType(payload299) => { + mbt_ffi_store8((iter_base) + 0, (18)) + + let address300 = mbt_ffi_malloc((payload299).length() * 4); + for index301 = 0; index301 < (payload299).length(); index301 = index301 + 1 { + let iter_elem : Int = (payload299)[(index301)] + let iter_base = address300 + (index301 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload299).length()) + mbt_ffi_store32((iter_base) + 8, address300) + cleanup_list.push(address300) + + () + } + ListType(payload302) => { + mbt_ffi_store8((iter_base) + 0, (19)) + mbt_ffi_store32((iter_base) + 8, payload302) + + () + } + FixedListType(payload303) => { + mbt_ffi_store8((iter_base) + 0, (20)) + mbt_ffi_store32((iter_base) + 8, (payload303).element) + mbt_ffi_store32((iter_base) + 12, ((payload303).length).reinterpret_as_int()) + + () + } + MapType(payload304) => { + mbt_ffi_store8((iter_base) + 0, (21)) + mbt_ffi_store32((iter_base) + 8, (payload304).key) + mbt_ffi_store32((iter_base) + 12, (payload304).value) + + () + } + OptionType(payload305) => { + mbt_ffi_store8((iter_base) + 0, (22)) + mbt_ffi_store32((iter_base) + 8, payload305) + + () + } + ResultType(payload306) => { + mbt_ffi_store8((iter_base) + 0, (23)) + + match ((payload306).ok) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload308) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload308) + + () + } + } + + match ((payload306).err) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload310) => { + mbt_ffi_store8((iter_base) + 16, (1)) + mbt_ffi_store32((iter_base) + 20, payload310) + + () + } + } + + () + } + TextType(payload311) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + match ((payload311).languages) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload313) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address315 = mbt_ffi_malloc((payload313).length() * 8); + for index316 = 0; index316 < (payload313).length(); index316 = index316 + 1 { + let iter_elem : String = (payload313)[(index316)] + let iter_base = address315 + (index316 * 8); + + let ptr314 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr314) + cleanup_list.push(ptr314) + + } + mbt_ffi_store32((iter_base) + 16, (payload313).length()) + mbt_ffi_store32((iter_base) + 12, address315) + cleanup_list.push(address315) + + () + } + } + + match ((payload311).min_length) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload318) => { + mbt_ffi_store8((iter_base) + 20, (1)) + mbt_ffi_store32((iter_base) + 24, (payload318).reinterpret_as_int()) + + () + } + } + + match ((payload311).max_length) { + None => { + mbt_ffi_store8((iter_base) + 28, (0)) + + () + } + Some(payload320) => { + mbt_ffi_store8((iter_base) + 28, (1)) + mbt_ffi_store32((iter_base) + 32, (payload320).reinterpret_as_int()) + + () + } + } + + match ((payload311).regex) { + None => { + mbt_ffi_store8((iter_base) + 36, (0)) + + () + } + Some(payload322) => { + mbt_ffi_store8((iter_base) + 36, (1)) + + let ptr323 = mbt_ffi_str2ptr(payload322) + mbt_ffi_store32((iter_base) + 44, payload322.length()) + mbt_ffi_store32((iter_base) + 40, ptr323) + cleanup_list.push(ptr323) + + () + } + } + + () + } + BinaryType(payload324) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + match ((payload324).mime_types) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload326) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address328 = mbt_ffi_malloc((payload326).length() * 8); + for index329 = 0; index329 < (payload326).length(); index329 = index329 + 1 { + let iter_elem : String = (payload326)[(index329)] + let iter_base = address328 + (index329 * 8); + + let ptr327 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr327) + cleanup_list.push(ptr327) + + } + mbt_ffi_store32((iter_base) + 16, (payload326).length()) + mbt_ffi_store32((iter_base) + 12, address328) + cleanup_list.push(address328) + + () + } + } + + match ((payload324).min_bytes) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload331) => { + mbt_ffi_store8((iter_base) + 20, (1)) + mbt_ffi_store32((iter_base) + 24, (payload331).reinterpret_as_int()) + + () + } + } + + match ((payload324).max_bytes) { + None => { + mbt_ffi_store8((iter_base) + 28, (0)) + + () + } + Some(payload333) => { + mbt_ffi_store8((iter_base) + 28, (1)) + mbt_ffi_store32((iter_base) + 32, (payload333).reinterpret_as_int()) + + () + } + } + + () + } + PathType(payload334) => { + mbt_ffi_store8((iter_base) + 0, (26)) + mbt_ffi_store8((iter_base) + 8, (payload334).direction.ordinal()) + mbt_ffi_store8((iter_base) + 9, (payload334).kind.ordinal()) + + match ((payload334).allowed_mime_types) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload336) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let address338 = mbt_ffi_malloc((payload336).length() * 8); + for index339 = 0; index339 < (payload336).length(); index339 = index339 + 1 { + let iter_elem : String = (payload336)[(index339)] + let iter_base = address338 + (index339 * 8); + + let ptr337 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr337) + cleanup_list.push(ptr337) + + } + mbt_ffi_store32((iter_base) + 20, (payload336).length()) + mbt_ffi_store32((iter_base) + 16, address338) + cleanup_list.push(address338) + + () + } + } + + match ((payload334).allowed_extensions) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload341) => { + mbt_ffi_store8((iter_base) + 24, (1)) + + let address343 = mbt_ffi_malloc((payload341).length() * 8); + for index344 = 0; index344 < (payload341).length(); index344 = index344 + 1 { + let iter_elem : String = (payload341)[(index344)] + let iter_base = address343 + (index344 * 8); + + let ptr342 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr342) + cleanup_list.push(ptr342) + + } + mbt_ffi_store32((iter_base) + 32, (payload341).length()) + mbt_ffi_store32((iter_base) + 28, address343) + cleanup_list.push(address343) + + () + } + } + + () + } + UrlType(payload345) => { + mbt_ffi_store8((iter_base) + 0, (27)) + + match ((payload345).allowed_schemes) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload347) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address349 = mbt_ffi_malloc((payload347).length() * 8); + for index350 = 0; index350 < (payload347).length(); index350 = index350 + 1 { + let iter_elem : String = (payload347)[(index350)] + let iter_base = address349 + (index350 * 8); + + let ptr348 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr348) + cleanup_list.push(ptr348) + + } + mbt_ffi_store32((iter_base) + 16, (payload347).length()) + mbt_ffi_store32((iter_base) + 12, address349) + cleanup_list.push(address349) + + () + } + } + + match ((payload345).allowed_hosts) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload352) => { + mbt_ffi_store8((iter_base) + 20, (1)) + + let address354 = mbt_ffi_malloc((payload352).length() * 8); + for index355 = 0; index355 < (payload352).length(); index355 = index355 + 1 { + let iter_elem : String = (payload352)[(index355)] + let iter_base = address354 + (index355 * 8); + + let ptr353 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr353) + cleanup_list.push(ptr353) + + } + mbt_ffi_store32((iter_base) + 28, (payload352).length()) + mbt_ffi_store32((iter_base) + 24, address354) + cleanup_list.push(address354) + + () + } + } + + () + } + DatetimeType => { + mbt_ffi_store8((iter_base) + 0, (28)) + + () + } + DurationType => { + mbt_ffi_store8((iter_base) + 0, (29)) + + () + } + QuantityType(payload358) => { + mbt_ffi_store8((iter_base) + 0, (30)) + + let ptr359 = mbt_ffi_str2ptr((payload358).base_unit) + mbt_ffi_store32((iter_base) + 12, (payload358).base_unit.length()) + mbt_ffi_store32((iter_base) + 8, ptr359) + + let address361 = mbt_ffi_malloc(((payload358).allowed_suffixes).length() * 8); + for index362 = 0; index362 < ((payload358).allowed_suffixes).length(); index362 = index362 + 1 { + let iter_elem : String = ((payload358).allowed_suffixes)[(index362)] + let iter_base = address361 + (index362 * 8); + + let ptr360 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr360) + cleanup_list.push(ptr360) + + } + mbt_ffi_store32((iter_base) + 20, ((payload358).allowed_suffixes).length()) + mbt_ffi_store32((iter_base) + 16, address361) + + match ((payload358).min) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload364) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload364).mantissa) + mbt_ffi_store32((iter_base) + 40, (payload364).scale) + + let ptr365 = mbt_ffi_str2ptr((payload364).unit) + mbt_ffi_store32((iter_base) + 48, (payload364).unit.length()) + mbt_ffi_store32((iter_base) + 44, ptr365) + cleanup_list.push(ptr365) + + () + } + } + + match ((payload358).max) { + None => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + Some(payload367) => { + mbt_ffi_store8((iter_base) + 56, (1)) + mbt_ffi_store64((iter_base) + 64, (payload367).mantissa) + mbt_ffi_store32((iter_base) + 72, (payload367).scale) + + let ptr368 = mbt_ffi_str2ptr((payload367).unit) + mbt_ffi_store32((iter_base) + 80, (payload367).unit.length()) + mbt_ffi_store32((iter_base) + 76, ptr368) + cleanup_list.push(ptr368) + + () + } + } + cleanup_list.push(ptr359) + cleanup_list.push(address361) + + () + } + UnionType(payload369) => { + mbt_ffi_store8((iter_base) + 0, (31)) + + let address405 = mbt_ffi_malloc(((payload369).branches).length() * 92); + for index406 = 0; index406 < ((payload369).branches).length(); index406 = index406 + 1 { + let iter_elem : @types.UnionBranch = ((payload369).branches)[(index406)] + let iter_base = address405 + (index406 * 92); + + let ptr370 = mbt_ffi_str2ptr((iter_elem).tag) + mbt_ffi_store32((iter_base) + 4, (iter_elem).tag.length()) + mbt_ffi_store32((iter_base) + 0, ptr370) + mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + + match (iter_elem).discriminator { + Prefix(payload371) => { + mbt_ffi_store8((iter_base) + 12, (0)) + + let ptr372 = mbt_ffi_str2ptr(payload371) + mbt_ffi_store32((iter_base) + 20, payload371.length()) + mbt_ffi_store32((iter_base) + 16, ptr372) + cleanup_list.push(ptr372) + + () + } + Suffix(payload373) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let ptr374 = mbt_ffi_str2ptr(payload373) + mbt_ffi_store32((iter_base) + 20, payload373.length()) + mbt_ffi_store32((iter_base) + 16, ptr374) + cleanup_list.push(ptr374) + + () + } + Contains(payload375) => { + mbt_ffi_store8((iter_base) + 12, (2)) + + let ptr376 = mbt_ffi_str2ptr(payload375) + mbt_ffi_store32((iter_base) + 20, payload375.length()) + mbt_ffi_store32((iter_base) + 16, ptr376) + cleanup_list.push(ptr376) + + () + } + Regex(payload377) => { + mbt_ffi_store8((iter_base) + 12, (3)) + + let ptr378 = mbt_ffi_str2ptr(payload377) + mbt_ffi_store32((iter_base) + 20, payload377.length()) + mbt_ffi_store32((iter_base) + 16, ptr378) + cleanup_list.push(ptr378) + + () + } + FieldEquals(payload379) => { + mbt_ffi_store8((iter_base) + 12, (4)) + + let ptr380 = mbt_ffi_str2ptr((payload379).field_name) + mbt_ffi_store32((iter_base) + 20, (payload379).field_name.length()) + mbt_ffi_store32((iter_base) + 16, ptr380) + + match ((payload379).literal) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload382) => { + mbt_ffi_store8((iter_base) + 24, (1)) + + let ptr383 = mbt_ffi_str2ptr(payload382) + mbt_ffi_store32((iter_base) + 32, payload382.length()) + mbt_ffi_store32((iter_base) + 28, ptr383) + cleanup_list.push(ptr383) + + () + } + } + cleanup_list.push(ptr380) + + () + } + FieldAbsent(payload384) => { + mbt_ffi_store8((iter_base) + 12, (5)) + + let ptr385 = mbt_ffi_str2ptr(payload384) + mbt_ffi_store32((iter_base) + 20, payload384.length()) + mbt_ffi_store32((iter_base) + 16, ptr385) + cleanup_list.push(ptr385) + + () + } + } + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 36, (0)) + + () + } + Some(payload387) => { + mbt_ffi_store8((iter_base) + 36, (1)) + + let ptr388 = mbt_ffi_str2ptr(payload387) + mbt_ffi_store32((iter_base) + 44, payload387.length()) + mbt_ffi_store32((iter_base) + 40, ptr388) + cleanup_list.push(ptr388) + + () + } + } + + let address390 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index391 = 0; index391 < (((iter_elem).metadata).aliases).length(); index391 = index391 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index391)] + let iter_base = address390 + (index391 * 8); + + let ptr389 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr389) + cleanup_list.push(ptr389) + + } + mbt_ffi_store32((iter_base) + 52, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 48, address390) + + let address393 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index394 = 0; index394 < (((iter_elem).metadata).examples).length(); index394 = index394 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index394)] + let iter_base = address393 + (index394 * 8); + + let ptr392 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr392) + cleanup_list.push(ptr392) + + } + mbt_ffi_store32((iter_base) + 60, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 56, address393) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload396) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr397 = mbt_ffi_str2ptr(payload396) + mbt_ffi_store32((iter_base) + 72, payload396.length()) + mbt_ffi_store32((iter_base) + 68, ptr397) + cleanup_list.push(ptr397) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 76, (0)) + + () + } + Some(payload399) => { + mbt_ffi_store8((iter_base) + 76, (1)) + + match payload399 { + Multimodal => { + mbt_ffi_store8((iter_base) + 80, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 80, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 80, (2)) + + () + } + Other(payload403) => { + mbt_ffi_store8((iter_base) + 80, (3)) + + let ptr404 = mbt_ffi_str2ptr(payload403) + mbt_ffi_store32((iter_base) + 88, payload403.length()) + mbt_ffi_store32((iter_base) + 84, ptr404) + cleanup_list.push(ptr404) + + () + } + } + + () + } + } + cleanup_list.push(ptr370) + cleanup_list.push(address390) + cleanup_list.push(address393) + + } + mbt_ffi_store32((iter_base) + 12, ((payload369).branches).length()) + mbt_ffi_store32((iter_base) + 8, address405) + cleanup_list.push(address405) + + () + } + SecretType(payload407) => { + mbt_ffi_store8((iter_base) + 0, (32)) + mbt_ffi_store32((iter_base) + 8, (payload407).inner) + + match ((payload407).category) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload409) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let ptr410 = mbt_ffi_str2ptr(payload409) + mbt_ffi_store32((iter_base) + 20, payload409.length()) + mbt_ffi_store32((iter_base) + 16, ptr410) + cleanup_list.push(ptr410) + + () + } + } + + () + } + QuotaTokenType(payload411) => { + mbt_ffi_store8((iter_base) + 0, (33)) + + match ((payload411).resource_name) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload413) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let ptr414 = mbt_ffi_str2ptr(payload413) + mbt_ffi_store32((iter_base) + 16, payload413.length()) + mbt_ffi_store32((iter_base) + 12, ptr414) + cleanup_list.push(ptr414) + + () + } + } + + () + } + PermissionCardType(payload415) => { + mbt_ffi_store8((iter_base) + 0, (34)) + mbt_ffi_store8((iter_base) + 8, (if (payload415).polymorphic { 1 } else { 0 })) + + () + } + FutureType(payload416) => { + mbt_ffi_store8((iter_base) + 0, (35)) + + match (payload416) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload418) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload418) + + () + } + } + + () + } + StreamType(payload419) => { + mbt_ffi_store8((iter_base) + 0, (36)) + + match (payload419) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload421) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload421) + + () + } + } + + () + } + } + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 88, (0)) + + () + } + Some(payload423) => { + mbt_ffi_store8((iter_base) + 88, (1)) + + let ptr424 = mbt_ffi_str2ptr(payload423) + mbt_ffi_store32((iter_base) + 96, payload423.length()) + mbt_ffi_store32((iter_base) + 92, ptr424) + cleanup_list.push(ptr424) + + () + } + } + + let address426 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index427 = 0; index427 < (((iter_elem).metadata).aliases).length(); index427 = index427 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index427)] + let iter_base = address426 + (index427 * 8); + + let ptr425 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr425) + cleanup_list.push(ptr425) + + } + mbt_ffi_store32((iter_base) + 104, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 100, address426) + + let address429 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index430 = 0; index430 < (((iter_elem).metadata).examples).length(); index430 = index430 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index430)] + let iter_base = address429 + (index430 * 8); + + let ptr428 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr428) + cleanup_list.push(ptr428) + + } + mbt_ffi_store32((iter_base) + 112, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 108, address429) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 116, (0)) + + () + } + Some(payload432) => { + mbt_ffi_store8((iter_base) + 116, (1)) + + let ptr433 = mbt_ffi_str2ptr(payload432) + mbt_ffi_store32((iter_base) + 124, payload432.length()) + mbt_ffi_store32((iter_base) + 120, ptr433) + cleanup_list.push(ptr433) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 128, (0)) + + () + } + Some(payload435) => { + mbt_ffi_store8((iter_base) + 128, (1)) + + match payload435 { + Multimodal => { + mbt_ffi_store8((iter_base) + 132, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 132, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 132, (2)) + + () + } + Other(payload439) => { + mbt_ffi_store8((iter_base) + 132, (3)) + + let ptr440 = mbt_ffi_str2ptr(payload439) + mbt_ffi_store32((iter_base) + 140, payload439.length()) + mbt_ffi_store32((iter_base) + 136, ptr440) + cleanup_list.push(ptr440) + + () + } + } + + () + } + } + cleanup_list.push(address426) + cleanup_list.push(address429) + + } + mbt_ffi_store32((iter_base) + 12, ((((iter_elem).value).graph).type_nodes).length()) + mbt_ffi_store32((iter_base) + 8, address441) + + let address447 = mbt_ffi_malloc(((((iter_elem).value).graph).defs).length() * 24); + for index448 = 0; index448 < ((((iter_elem).value).graph).defs).length(); index448 = index448 + 1 { + let iter_elem : @types.SchemaTypeDef = ((((iter_elem).value).graph).defs)[(index448)] + let iter_base = address447 + (index448 * 24); + + let ptr443 = mbt_ffi_str2ptr((iter_elem).id) + mbt_ffi_store32((iter_base) + 4, (iter_elem).id.length()) + mbt_ffi_store32((iter_base) + 0, ptr443) + + match ((iter_elem).name) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload445) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let ptr446 = mbt_ffi_str2ptr(payload445) + mbt_ffi_store32((iter_base) + 16, payload445.length()) + mbt_ffi_store32((iter_base) + 12, ptr446) + cleanup_list.push(ptr446) + + () + } + } + mbt_ffi_store32((iter_base) + 20, (iter_elem).body) + cleanup_list.push(ptr443) + + } + mbt_ffi_store32((iter_base) + 20, ((((iter_elem).value).graph).defs).length()) + mbt_ffi_store32((iter_base) + 16, address447) + mbt_ffi_store32((iter_base) + 24, (((iter_elem).value).graph).root) + + let address523 = mbt_ffi_malloc(((((iter_elem).value).value).value_nodes).length() * 32); + for index524 = 0; index524 < ((((iter_elem).value).value).value_nodes).length(); index524 = index524 + 1 { + let iter_elem : @types.SchemaValueNode = ((((iter_elem).value).value).value_nodes)[(index524)] + let iter_base = address523 + (index524 * 32); + + match iter_elem { + BoolValue(payload449) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store8((iter_base) + 8, (if payload449 { 1 } else { 0 })) + + () + } + S8Value(payload450) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload450)) + + () + } + S16Value(payload451) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload451)) + + () + } + S32Value(payload452) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 8, payload452) + + () + } + S64Value(payload453) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store64((iter_base) + 8, payload453) + + () + } + U8Value(payload454) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store8((iter_base) + 8, (payload454).to_int()) + + () + } + U16Value(payload455) => { + mbt_ffi_store8((iter_base) + 0, (6)) + mbt_ffi_store16((iter_base) + 8, (payload455).reinterpret_as_int()) + + () + } + U32Value(payload456) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 8, (payload456).reinterpret_as_int()) + + () + } + U64Value(payload457) => { + mbt_ffi_store8((iter_base) + 0, (8)) + mbt_ffi_store64((iter_base) + 8, (payload457).reinterpret_as_int64()) + + () + } + F32Value(payload458) => { + mbt_ffi_store8((iter_base) + 0, (9)) + mbt_ffi_storef32((iter_base) + 8, payload458) + + () + } + F64Value(payload459) => { + mbt_ffi_store8((iter_base) + 0, (10)) + mbt_ffi_storef64((iter_base) + 8, payload459) + + () + } + CharValue(payload460) => { + mbt_ffi_store8((iter_base) + 0, (11)) + mbt_ffi_store32((iter_base) + 8, (payload460).to_int()) + + () + } + StringValue(payload461) => { + mbt_ffi_store8((iter_base) + 0, (12)) + + let ptr462 = mbt_ffi_str2ptr(payload461) + mbt_ffi_store32((iter_base) + 12, payload461.length()) + mbt_ffi_store32((iter_base) + 8, ptr462) + cleanup_list.push(ptr462) + + () + } + RecordValue(payload463) => { + mbt_ffi_store8((iter_base) + 0, (13)) + + let address464 = mbt_ffi_malloc((payload463).length() * 4); + for index465 = 0; index465 < (payload463).length(); index465 = index465 + 1 { + let iter_elem : Int = (payload463)[(index465)] + let iter_base = address464 + (index465 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload463).length()) + mbt_ffi_store32((iter_base) + 8, address464) + cleanup_list.push(address464) + + () + } + VariantValue(payload466) => { + mbt_ffi_store8((iter_base) + 0, (14)) + mbt_ffi_store32((iter_base) + 8, ((payload466).case).reinterpret_as_int()) + + match ((payload466).payload) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload468) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload468) + + () + } + } + + () + } + EnumValue(payload469) => { + mbt_ffi_store8((iter_base) + 0, (15)) + mbt_ffi_store32((iter_base) + 8, (payload469).reinterpret_as_int()) + + () + } + FlagsValue(payload470) => { + mbt_ffi_store8((iter_base) + 0, (16)) + + let address471 = mbt_ffi_malloc((payload470).length() * 1); + for index472 = 0; index472 < (payload470).length(); index472 = index472 + 1 { + let iter_elem : Bool = (payload470)[(index472)] + let iter_base = address471 + (index472 * 1); + mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + + } + mbt_ffi_store32((iter_base) + 12, (payload470).length()) + mbt_ffi_store32((iter_base) + 8, address471) + cleanup_list.push(address471) + + () + } + TupleValue(payload473) => { + mbt_ffi_store8((iter_base) + 0, (17)) + + let address474 = mbt_ffi_malloc((payload473).length() * 4); + for index475 = 0; index475 < (payload473).length(); index475 = index475 + 1 { + let iter_elem : Int = (payload473)[(index475)] + let iter_base = address474 + (index475 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload473).length()) + mbt_ffi_store32((iter_base) + 8, address474) + cleanup_list.push(address474) + + () + } + ListValue(payload476) => { + mbt_ffi_store8((iter_base) + 0, (18)) + + let address477 = mbt_ffi_malloc((payload476).length() * 4); + for index478 = 0; index478 < (payload476).length(); index478 = index478 + 1 { + let iter_elem : Int = (payload476)[(index478)] + let iter_base = address477 + (index478 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload476).length()) + mbt_ffi_store32((iter_base) + 8, address477) + cleanup_list.push(address477) + + () + } + FixedListValue(payload479) => { + mbt_ffi_store8((iter_base) + 0, (19)) + + let address480 = mbt_ffi_malloc((payload479).length() * 4); + for index481 = 0; index481 < (payload479).length(); index481 = index481 + 1 { + let iter_elem : Int = (payload479)[(index481)] + let iter_base = address480 + (index481 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload479).length()) + mbt_ffi_store32((iter_base) + 8, address480) + cleanup_list.push(address480) + + () + } + MapValue(payload482) => { + mbt_ffi_store8((iter_base) + 0, (20)) + + let address483 = mbt_ffi_malloc((payload482).length() * 8); + for index484 = 0; index484 < (payload482).length(); index484 = index484 + 1 { + let iter_elem : @types.MapEntry = (payload482)[(index484)] + let iter_base = address483 + (index484 * 8); + mbt_ffi_store32((iter_base) + 0, (iter_elem).key) + mbt_ffi_store32((iter_base) + 4, (iter_elem).value) + + } + mbt_ffi_store32((iter_base) + 12, (payload482).length()) + mbt_ffi_store32((iter_base) + 8, address483) + cleanup_list.push(address483) + + () + } + OptionValue(payload485) => { + mbt_ffi_store8((iter_base) + 0, (21)) + + match (payload485) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload487) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload487) + + () + } + } + + () + } + ResultValue(payload488) => { + mbt_ffi_store8((iter_base) + 0, (22)) + + match payload488 { + OkValue(payload489) => { + mbt_ffi_store8((iter_base) + 8, (0)) + + match (payload489) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload491) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload491) + + () + } + } + + () + } + ErrValue(payload492) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match (payload492) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload494) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload494) + + () + } + } + + () + } + } + + () + } + TextValue(payload495) => { + mbt_ffi_store8((iter_base) + 0, (23)) + + let ptr496 = mbt_ffi_str2ptr((payload495).text) + mbt_ffi_store32((iter_base) + 12, (payload495).text.length()) + mbt_ffi_store32((iter_base) + 8, ptr496) + + match ((payload495).language) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload498) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr499 = mbt_ffi_str2ptr(payload498) + mbt_ffi_store32((iter_base) + 24, payload498.length()) + mbt_ffi_store32((iter_base) + 20, ptr499) + cleanup_list.push(ptr499) + + () + } + } + cleanup_list.push(ptr496) + + () + } + BinaryValue(payload500) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + let ptr501 = mbt_ffi_bytes2ptr((payload500).bytes) + + mbt_ffi_store32((iter_base) + 12, (payload500).bytes.length()) + mbt_ffi_store32((iter_base) + 8, ptr501) + + match ((payload500).mime_type) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload503) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr504 = mbt_ffi_str2ptr(payload503) + mbt_ffi_store32((iter_base) + 24, payload503.length()) + mbt_ffi_store32((iter_base) + 20, ptr504) + cleanup_list.push(ptr504) + + () + } + } + cleanup_list.push(ptr501) + + () + } + PathValue(payload505) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + let ptr506 = mbt_ffi_str2ptr(payload505) + mbt_ffi_store32((iter_base) + 12, payload505.length()) + mbt_ffi_store32((iter_base) + 8, ptr506) + cleanup_list.push(ptr506) + + () + } + UrlValue(payload507) => { + mbt_ffi_store8((iter_base) + 0, (26)) + + let ptr508 = mbt_ffi_str2ptr(payload507) + mbt_ffi_store32((iter_base) + 12, payload507.length()) + mbt_ffi_store32((iter_base) + 8, ptr508) + cleanup_list.push(ptr508) + + () + } + DatetimeValue(payload509) => { + mbt_ffi_store8((iter_base) + 0, (27)) + mbt_ffi_store64((iter_base) + 8, (payload509).seconds) + mbt_ffi_store32((iter_base) + 16, ((payload509).nanoseconds).reinterpret_as_int()) + + () + } + DurationValue(payload510) => { + mbt_ffi_store8((iter_base) + 0, (28)) + mbt_ffi_store64((iter_base) + 8, (payload510).nanoseconds) + + () + } + QuantityValueNode(payload511) => { + mbt_ffi_store8((iter_base) + 0, (29)) + mbt_ffi_store64((iter_base) + 8, (payload511).mantissa) + mbt_ffi_store32((iter_base) + 16, (payload511).scale) + + let ptr512 = mbt_ffi_str2ptr((payload511).unit) + mbt_ffi_store32((iter_base) + 24, (payload511).unit.length()) + mbt_ffi_store32((iter_base) + 20, ptr512) + cleanup_list.push(ptr512) + + () + } + UnionValue(payload513) => { + mbt_ffi_store8((iter_base) + 0, (30)) + + let ptr514 = mbt_ffi_str2ptr((payload513).tag) + mbt_ffi_store32((iter_base) + 12, (payload513).tag.length()) + mbt_ffi_store32((iter_base) + 8, ptr514) + mbt_ffi_store32((iter_base) + 16, (payload513).body) + cleanup_list.push(ptr514) + + () + } + SecretValue(payload515) => { + mbt_ffi_store8((iter_base) + 0, (31)) + + let @types.Secret(handle516) = payload515 + mbt_ffi_store32((iter_base) + 8, handle516) + + () + } + QuotaTokenHandle(payload517) => { + mbt_ffi_store8((iter_base) + 0, (32)) + + let @types.QuotaToken(handle518) = payload517 + mbt_ffi_store32((iter_base) + 8, handle518) + + () + } + PermissionCardHandle(payload519) => { + mbt_ffi_store8((iter_base) + 0, (33)) + + let @types.PermissionCard(handle520) = payload519 + mbt_ffi_store32((iter_base) + 8, handle520) + + () + } + StreamValue(payload521) => { + mbt_ffi_store8((iter_base) + 0, (34)) + + let @types.SchemaValueStream(handle522) = payload521 + mbt_ffi_store32((iter_base) + 8, handle522) + + () + } + } + + } + mbt_ffi_store32((iter_base) + 32, ((((iter_elem).value).value).value_nodes).length()) + mbt_ffi_store32((iter_base) + 28, address523) + mbt_ffi_store32((iter_base) + 36, (((iter_elem).value).value).root) + cleanup_list.push(address77) + cleanup_list.push(address441) + cleanup_list.push(address447) + cleanup_list.push(address523) + + } + let result : Int = wasmImportConstructorWasmRpc(ptr, agent_type_name.length(), address70, ((constructor_).value_nodes).length(), (constructor_).root, lowered, lowered74, lowered75, address525, (agent_config).length()); + let ret = WasmRpc::WasmRpc(result) + mbt_ffi_free(ptr) + mbt_ffi_free(address70) + mbt_ffi_free(address525) + + cleanup_list.each(mbt_ffi_free) + return ret + +} +///| +/// Creates an RPC client connecting to the given target agent. +/// +/// `constructor` is a value tree whose root encodes the target agent +/// constructor's parameter list. This fallible form returns an RPC error +/// if the client cannot be created and is intended for reflective and +/// other dynamic clients. +pub fn WasmRpc::create(agent_type_name : String, constructor_ : @types.SchemaValueTree, phantom_id : @types.Uuid?, agent_config : Array[@common.TypedAgentConfigValue]) -> Result[WasmRpc, RpcError] { + let cleanup_list : Array[Int] = [] + + let ptr = mbt_ffi_str2ptr(agent_type_name) + + let address70 = mbt_ffi_malloc(((constructor_).value_nodes).length() * 32); + for index71 = 0; index71 < ((constructor_).value_nodes).length(); index71 = index71 + 1 { + let iter_elem : @types.SchemaValueNode = ((constructor_).value_nodes)[(index71)] + let iter_base = address70 + (index71 * 32); + + match iter_elem { + BoolValue(payload) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store8((iter_base) + 8, (if payload { 1 } else { 0 })) + + () + } + S8Value(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload0)) + + () + } + S16Value(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload1)) + + () + } + S32Value(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 8, payload2) + + () + } + S64Value(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store64((iter_base) + 8, payload3) + + () + } + U8Value(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store8((iter_base) + 8, (payload4).to_int()) + + () + } + U16Value(payload5) => { + mbt_ffi_store8((iter_base) + 0, (6)) + mbt_ffi_store16((iter_base) + 8, (payload5).reinterpret_as_int()) + + () + } + U32Value(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 8, (payload6).reinterpret_as_int()) + + () + } + U64Value(payload7) => { + mbt_ffi_store8((iter_base) + 0, (8)) + mbt_ffi_store64((iter_base) + 8, (payload7).reinterpret_as_int64()) + + () + } + F32Value(payload8) => { + mbt_ffi_store8((iter_base) + 0, (9)) + mbt_ffi_storef32((iter_base) + 8, payload8) + + () + } + F64Value(payload9) => { + mbt_ffi_store8((iter_base) + 0, (10)) + mbt_ffi_storef64((iter_base) + 8, payload9) + + () + } + CharValue(payload10) => { + mbt_ffi_store8((iter_base) + 0, (11)) + mbt_ffi_store32((iter_base) + 8, (payload10).to_int()) + + () + } + StringValue(payload11) => { + mbt_ffi_store8((iter_base) + 0, (12)) + + let ptr12 = mbt_ffi_str2ptr(payload11) + mbt_ffi_store32((iter_base) + 12, payload11.length()) + mbt_ffi_store32((iter_base) + 8, ptr12) + cleanup_list.push(ptr12) + + () + } + RecordValue(payload13) => { + mbt_ffi_store8((iter_base) + 0, (13)) + + let address = mbt_ffi_malloc((payload13).length() * 4); + for index = 0; index < (payload13).length(); index = index + 1 { + let iter_elem : Int = (payload13)[(index)] + let iter_base = address + (index * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload13).length()) + mbt_ffi_store32((iter_base) + 8, address) + cleanup_list.push(address) + + () + } + VariantValue(payload14) => { + mbt_ffi_store8((iter_base) + 0, (14)) + mbt_ffi_store32((iter_base) + 8, ((payload14).case).reinterpret_as_int()) + + match ((payload14).payload) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload16) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload16) + + () + } + } + + () + } + EnumValue(payload17) => { + mbt_ffi_store8((iter_base) + 0, (15)) + mbt_ffi_store32((iter_base) + 8, (payload17).reinterpret_as_int()) + + () + } + FlagsValue(payload18) => { + mbt_ffi_store8((iter_base) + 0, (16)) + + let address19 = mbt_ffi_malloc((payload18).length() * 1); + for index20 = 0; index20 < (payload18).length(); index20 = index20 + 1 { + let iter_elem : Bool = (payload18)[(index20)] + let iter_base = address19 + (index20 * 1); + mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + + } + mbt_ffi_store32((iter_base) + 12, (payload18).length()) + mbt_ffi_store32((iter_base) + 8, address19) + cleanup_list.push(address19) + + () + } + TupleValue(payload21) => { + mbt_ffi_store8((iter_base) + 0, (17)) + + let address22 = mbt_ffi_malloc((payload21).length() * 4); + for index23 = 0; index23 < (payload21).length(); index23 = index23 + 1 { + let iter_elem : Int = (payload21)[(index23)] + let iter_base = address22 + (index23 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload21).length()) + mbt_ffi_store32((iter_base) + 8, address22) + cleanup_list.push(address22) + + () + } + ListValue(payload24) => { + mbt_ffi_store8((iter_base) + 0, (18)) + + let address25 = mbt_ffi_malloc((payload24).length() * 4); + for index26 = 0; index26 < (payload24).length(); index26 = index26 + 1 { + let iter_elem : Int = (payload24)[(index26)] + let iter_base = address25 + (index26 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload24).length()) + mbt_ffi_store32((iter_base) + 8, address25) + cleanup_list.push(address25) + + () + } + FixedListValue(payload27) => { + mbt_ffi_store8((iter_base) + 0, (19)) + + let address28 = mbt_ffi_malloc((payload27).length() * 4); + for index29 = 0; index29 < (payload27).length(); index29 = index29 + 1 { + let iter_elem : Int = (payload27)[(index29)] + let iter_base = address28 + (index29 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload27).length()) + mbt_ffi_store32((iter_base) + 8, address28) + cleanup_list.push(address28) + + () + } + MapValue(payload30) => { + mbt_ffi_store8((iter_base) + 0, (20)) + + let address31 = mbt_ffi_malloc((payload30).length() * 8); + for index32 = 0; index32 < (payload30).length(); index32 = index32 + 1 { + let iter_elem : @types.MapEntry = (payload30)[(index32)] + let iter_base = address31 + (index32 * 8); + mbt_ffi_store32((iter_base) + 0, (iter_elem).key) + mbt_ffi_store32((iter_base) + 4, (iter_elem).value) + + } + mbt_ffi_store32((iter_base) + 12, (payload30).length()) + mbt_ffi_store32((iter_base) + 8, address31) + cleanup_list.push(address31) + + () + } + OptionValue(payload33) => { + mbt_ffi_store8((iter_base) + 0, (21)) + + match (payload33) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload35) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload35) + + () + } + } + + () + } + ResultValue(payload36) => { + mbt_ffi_store8((iter_base) + 0, (22)) + + match payload36 { + OkValue(payload37) => { + mbt_ffi_store8((iter_base) + 8, (0)) + + match (payload37) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload39) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload39) + + () + } + } + + () + } + ErrValue(payload40) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match (payload40) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload42) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload42) + + () + } + } + + () + } + } + + () + } + TextValue(payload43) => { + mbt_ffi_store8((iter_base) + 0, (23)) + + let ptr44 = mbt_ffi_str2ptr((payload43).text) + mbt_ffi_store32((iter_base) + 12, (payload43).text.length()) + mbt_ffi_store32((iter_base) + 8, ptr44) + + match ((payload43).language) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload46) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr47 = mbt_ffi_str2ptr(payload46) + mbt_ffi_store32((iter_base) + 24, payload46.length()) + mbt_ffi_store32((iter_base) + 20, ptr47) + cleanup_list.push(ptr47) + + () + } + } + cleanup_list.push(ptr44) + + () + } + BinaryValue(payload48) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + let ptr49 = mbt_ffi_bytes2ptr((payload48).bytes) + + mbt_ffi_store32((iter_base) + 12, (payload48).bytes.length()) + mbt_ffi_store32((iter_base) + 8, ptr49) + + match ((payload48).mime_type) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload51) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr52 = mbt_ffi_str2ptr(payload51) + mbt_ffi_store32((iter_base) + 24, payload51.length()) + mbt_ffi_store32((iter_base) + 20, ptr52) + cleanup_list.push(ptr52) + + () + } + } + cleanup_list.push(ptr49) + + () + } + PathValue(payload53) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + let ptr54 = mbt_ffi_str2ptr(payload53) + mbt_ffi_store32((iter_base) + 12, payload53.length()) + mbt_ffi_store32((iter_base) + 8, ptr54) + cleanup_list.push(ptr54) + + () + } + UrlValue(payload55) => { + mbt_ffi_store8((iter_base) + 0, (26)) + + let ptr56 = mbt_ffi_str2ptr(payload55) + mbt_ffi_store32((iter_base) + 12, payload55.length()) + mbt_ffi_store32((iter_base) + 8, ptr56) + cleanup_list.push(ptr56) + + () + } + DatetimeValue(payload57) => { + mbt_ffi_store8((iter_base) + 0, (27)) + mbt_ffi_store64((iter_base) + 8, (payload57).seconds) + mbt_ffi_store32((iter_base) + 16, ((payload57).nanoseconds).reinterpret_as_int()) + + () + } + DurationValue(payload58) => { + mbt_ffi_store8((iter_base) + 0, (28)) + mbt_ffi_store64((iter_base) + 8, (payload58).nanoseconds) + + () + } + QuantityValueNode(payload59) => { + mbt_ffi_store8((iter_base) + 0, (29)) + mbt_ffi_store64((iter_base) + 8, (payload59).mantissa) + mbt_ffi_store32((iter_base) + 16, (payload59).scale) + + let ptr60 = mbt_ffi_str2ptr((payload59).unit) + mbt_ffi_store32((iter_base) + 24, (payload59).unit.length()) + mbt_ffi_store32((iter_base) + 20, ptr60) + cleanup_list.push(ptr60) + + () + } + UnionValue(payload61) => { + mbt_ffi_store8((iter_base) + 0, (30)) + + let ptr62 = mbt_ffi_str2ptr((payload61).tag) + mbt_ffi_store32((iter_base) + 12, (payload61).tag.length()) + mbt_ffi_store32((iter_base) + 8, ptr62) + mbt_ffi_store32((iter_base) + 16, (payload61).body) + cleanup_list.push(ptr62) () } - RecordValue(payload13) => { - mbt_ffi_store8((iter_base) + 0, (13)) + SecretValue(payload63) => { + mbt_ffi_store8((iter_base) + 0, (31)) + + let @types.Secret(handle) = payload63 + mbt_ffi_store32((iter_base) + 8, handle) + + () + } + QuotaTokenHandle(payload64) => { + mbt_ffi_store8((iter_base) + 0, (32)) + + let @types.QuotaToken(handle65) = payload64 + mbt_ffi_store32((iter_base) + 8, handle65) + + () + } + PermissionCardHandle(payload66) => { + mbt_ffi_store8((iter_base) + 0, (33)) + + let @types.PermissionCard(handle67) = payload66 + mbt_ffi_store32((iter_base) + 8, handle67) + + () + } + StreamValue(payload68) => { + mbt_ffi_store8((iter_base) + 0, (34)) + + let @types.SchemaValueStream(handle69) = payload68 + mbt_ffi_store32((iter_base) + 8, handle69) + + () + } + } + + } + + let (lowered, lowered74, lowered75) = match (phantom_id) { + None => { + + ((0), 0L, 0L) + } + Some(payload73) => { + + ((1), ((payload73).high_bits).reinterpret_as_int64(), ((payload73).low_bits).reinterpret_as_int64()) + } + } + + let address525 = mbt_ffi_malloc((agent_config).length() * 40); + for index526 = 0; index526 < (agent_config).length(); index526 = index526 + 1 { + let iter_elem : @common.TypedAgentConfigValue = (agent_config)[(index526)] + let iter_base = address525 + (index526 * 40); + + let address77 = mbt_ffi_malloc(((iter_elem).path).length() * 8); + for index78 = 0; index78 < ((iter_elem).path).length(); index78 = index78 + 1 { + let iter_elem : String = ((iter_elem).path)[(index78)] + let iter_base = address77 + (index78 * 8); + + let ptr76 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr76) + cleanup_list.push(ptr76) + + } + mbt_ffi_store32((iter_base) + 4, ((iter_elem).path).length()) + mbt_ffi_store32((iter_base) + 0, address77) + + let address441 = mbt_ffi_malloc(((((iter_elem).value).graph).type_nodes).length() * 144); + for index442 = 0; index442 < ((((iter_elem).value).graph).type_nodes).length(); index442 = index442 + 1 { + let iter_elem : @types.SchemaTypeNode = ((((iter_elem).value).graph).type_nodes)[(index442)] + let iter_base = address441 + (index442 * 144); + + match (iter_elem).body { + RefType(payload79) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 8, payload79) + + () + } + BoolType => { + mbt_ffi_store8((iter_base) + 0, (1)) + + () + } + S8Type(payload81) => { + mbt_ffi_store8((iter_base) + 0, (2)) + + match (payload81) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload83) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload83).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload85) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload85 { + Signed(payload86) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload86) + + () + } + Unsigned(payload87) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload87).reinterpret_as_int64()) + + () + } + FloatBits(payload88) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload88).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload83).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload90) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload90 { + Signed(payload91) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload91) + + () + } + Unsigned(payload92) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload92).reinterpret_as_int64()) + + () + } + FloatBits(payload93) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload93).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload83).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload95) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr96 = mbt_ffi_str2ptr(payload95) + mbt_ffi_store32((iter_base) + 72, payload95.length()) + mbt_ffi_store32((iter_base) + 68, ptr96) + cleanup_list.push(ptr96) + + () + } + } + + () + } + } + + () + } + S16Type(payload97) => { + mbt_ffi_store8((iter_base) + 0, (3)) + + match (payload97) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload99) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload99).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload101) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload101 { + Signed(payload102) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload102) + + () + } + Unsigned(payload103) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload103).reinterpret_as_int64()) + + () + } + FloatBits(payload104) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload104).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload99).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload106) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload106 { + Signed(payload107) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload107) + + () + } + Unsigned(payload108) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload108).reinterpret_as_int64()) + + () + } + FloatBits(payload109) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload109).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload99).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload111) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr112 = mbt_ffi_str2ptr(payload111) + mbt_ffi_store32((iter_base) + 72, payload111.length()) + mbt_ffi_store32((iter_base) + 68, ptr112) + cleanup_list.push(ptr112) + + () + } + } + + () + } + } + + () + } + S32Type(payload113) => { + mbt_ffi_store8((iter_base) + 0, (4)) + + match (payload113) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload115) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload115).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload117) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload117 { + Signed(payload118) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload118) + + () + } + Unsigned(payload119) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload119).reinterpret_as_int64()) + + () + } + FloatBits(payload120) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload120).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload115).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload122) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload122 { + Signed(payload123) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload123) + + () + } + Unsigned(payload124) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload124).reinterpret_as_int64()) + + () + } + FloatBits(payload125) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload125).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload115).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload127) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr128 = mbt_ffi_str2ptr(payload127) + mbt_ffi_store32((iter_base) + 72, payload127.length()) + mbt_ffi_store32((iter_base) + 68, ptr128) + cleanup_list.push(ptr128) + + () + } + } + + () + } + } + + () + } + S64Type(payload129) => { + mbt_ffi_store8((iter_base) + 0, (5)) + + match (payload129) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload131) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload131).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload133) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload133 { + Signed(payload134) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload134) + + () + } + Unsigned(payload135) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload135).reinterpret_as_int64()) + + () + } + FloatBits(payload136) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload136).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload131).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload138) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload138 { + Signed(payload139) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload139) + + () + } + Unsigned(payload140) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload140).reinterpret_as_int64()) + + () + } + FloatBits(payload141) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload141).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload131).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload143) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr144 = mbt_ffi_str2ptr(payload143) + mbt_ffi_store32((iter_base) + 72, payload143.length()) + mbt_ffi_store32((iter_base) + 68, ptr144) + cleanup_list.push(ptr144) + + () + } + } + + () + } + } + + () + } + U8Type(payload145) => { + mbt_ffi_store8((iter_base) + 0, (6)) + + match (payload145) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload147) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload147).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload149) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload149 { + Signed(payload150) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload150) + + () + } + Unsigned(payload151) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload151).reinterpret_as_int64()) + + () + } + FloatBits(payload152) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload152).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload147).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload154) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload154 { + Signed(payload155) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload155) + + () + } + Unsigned(payload156) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload156).reinterpret_as_int64()) + + () + } + FloatBits(payload157) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload157).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload147).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload159) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr160 = mbt_ffi_str2ptr(payload159) + mbt_ffi_store32((iter_base) + 72, payload159.length()) + mbt_ffi_store32((iter_base) + 68, ptr160) + cleanup_list.push(ptr160) + + () + } + } + + () + } + } + + () + } + U16Type(payload161) => { + mbt_ffi_store8((iter_base) + 0, (7)) + + match (payload161) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload163) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload163).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload165) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload165 { + Signed(payload166) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload166) + + () + } + Unsigned(payload167) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload167).reinterpret_as_int64()) + + () + } + FloatBits(payload168) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload168).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload163).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload170) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload170 { + Signed(payload171) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload171) + + () + } + Unsigned(payload172) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload172).reinterpret_as_int64()) + + () + } + FloatBits(payload173) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload173).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload163).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload175) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr176 = mbt_ffi_str2ptr(payload175) + mbt_ffi_store32((iter_base) + 72, payload175.length()) + mbt_ffi_store32((iter_base) + 68, ptr176) + cleanup_list.push(ptr176) + + () + } + } + + () + } + } + + () + } + U32Type(payload177) => { + mbt_ffi_store8((iter_base) + 0, (8)) + + match (payload177) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload179) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload179).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload181) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload181 { + Signed(payload182) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload182) + + () + } + Unsigned(payload183) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload183).reinterpret_as_int64()) + + () + } + FloatBits(payload184) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload184).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload179).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload186) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload186 { + Signed(payload187) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload187) + + () + } + Unsigned(payload188) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload188).reinterpret_as_int64()) + + () + } + FloatBits(payload189) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload189).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload179).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload191) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr192 = mbt_ffi_str2ptr(payload191) + mbt_ffi_store32((iter_base) + 72, payload191.length()) + mbt_ffi_store32((iter_base) + 68, ptr192) + cleanup_list.push(ptr192) + + () + } + } + + () + } + } + + () + } + U64Type(payload193) => { + mbt_ffi_store8((iter_base) + 0, (9)) + + match (payload193) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload195) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload195).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload197) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload197 { + Signed(payload198) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload198) + + () + } + Unsigned(payload199) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload199).reinterpret_as_int64()) + + () + } + FloatBits(payload200) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload200).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload195).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload202) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload202 { + Signed(payload203) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload203) + + () + } + Unsigned(payload204) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload204).reinterpret_as_int64()) + + () + } + FloatBits(payload205) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload205).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload195).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload207) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr208 = mbt_ffi_str2ptr(payload207) + mbt_ffi_store32((iter_base) + 72, payload207.length()) + mbt_ffi_store32((iter_base) + 68, ptr208) + cleanup_list.push(ptr208) + + () + } + } + + () + } + } + + () + } + F32Type(payload209) => { + mbt_ffi_store8((iter_base) + 0, (10)) + + match (payload209) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload211) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload211).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload213) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload213 { + Signed(payload214) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload214) + + () + } + Unsigned(payload215) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload215).reinterpret_as_int64()) + + () + } + FloatBits(payload216) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload216).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload211).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload218) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload218 { + Signed(payload219) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload219) + + () + } + Unsigned(payload220) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload220).reinterpret_as_int64()) + + () + } + FloatBits(payload221) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload221).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload211).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload223) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr224 = mbt_ffi_str2ptr(payload223) + mbt_ffi_store32((iter_base) + 72, payload223.length()) + mbt_ffi_store32((iter_base) + 68, ptr224) + cleanup_list.push(ptr224) + + () + } + } + + () + } + } + + () + } + F64Type(payload225) => { + mbt_ffi_store8((iter_base) + 0, (11)) + + match (payload225) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload227) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match ((payload227).min) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload229) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + match payload229 { + Signed(payload230) => { + mbt_ffi_store8((iter_base) + 24, (0)) + mbt_ffi_store64((iter_base) + 32, payload230) + + () + } + Unsigned(payload231) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload231).reinterpret_as_int64()) + + () + } + FloatBits(payload232) => { + mbt_ffi_store8((iter_base) + 24, (2)) + mbt_ffi_store64((iter_base) + 32, (payload232).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload227).max) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload234) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + match payload234 { + Signed(payload235) => { + mbt_ffi_store8((iter_base) + 48, (0)) + mbt_ffi_store64((iter_base) + 56, payload235) + + () + } + Unsigned(payload236) => { + mbt_ffi_store8((iter_base) + 48, (1)) + mbt_ffi_store64((iter_base) + 56, (payload236).reinterpret_as_int64()) + + () + } + FloatBits(payload237) => { + mbt_ffi_store8((iter_base) + 48, (2)) + mbt_ffi_store64((iter_base) + 56, (payload237).reinterpret_as_int64()) + + () + } + } + + () + } + } + + match ((payload227).unit) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload239) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr240 = mbt_ffi_str2ptr(payload239) + mbt_ffi_store32((iter_base) + 72, payload239.length()) + mbt_ffi_store32((iter_base) + 68, ptr240) + cleanup_list.push(ptr240) + + () + } + } + + () + } + } + + () + } + CharType => { + mbt_ffi_store8((iter_base) + 0, (12)) + + () + } + StringType => { + mbt_ffi_store8((iter_base) + 0, (13)) + + () + } + RecordType(payload243) => { + mbt_ffi_store8((iter_base) + 0, (14)) + + let address264 = mbt_ffi_malloc((payload243).length() * 68); + for index265 = 0; index265 < (payload243).length(); index265 = index265 + 1 { + let iter_elem : @types.NamedFieldType = (payload243)[(index265)] + let iter_base = address264 + (index265 * 68); + + let ptr244 = mbt_ffi_str2ptr((iter_elem).name) + mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) + mbt_ffi_store32((iter_base) + 0, ptr244) + mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload246) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let ptr247 = mbt_ffi_str2ptr(payload246) + mbt_ffi_store32((iter_base) + 20, payload246.length()) + mbt_ffi_store32((iter_base) + 16, ptr247) + cleanup_list.push(ptr247) + + () + } + } + + let address249 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index250 = 0; index250 < (((iter_elem).metadata).aliases).length(); index250 = index250 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index250)] + let iter_base = address249 + (index250 * 8); + + let ptr248 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr248) + cleanup_list.push(ptr248) + + } + mbt_ffi_store32((iter_base) + 28, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 24, address249) + + let address252 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index253 = 0; index253 < (((iter_elem).metadata).examples).length(); index253 = index253 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index253)] + let iter_base = address252 + (index253 * 8); + + let ptr251 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr251) + cleanup_list.push(ptr251) + + } + mbt_ffi_store32((iter_base) + 36, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 32, address252) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 40, (0)) + + () + } + Some(payload255) => { + mbt_ffi_store8((iter_base) + 40, (1)) + + let ptr256 = mbt_ffi_str2ptr(payload255) + mbt_ffi_store32((iter_base) + 48, payload255.length()) + mbt_ffi_store32((iter_base) + 44, ptr256) + cleanup_list.push(ptr256) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 52, (0)) + + () + } + Some(payload258) => { + mbt_ffi_store8((iter_base) + 52, (1)) + + match payload258 { + Multimodal => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 56, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 56, (2)) + + () + } + Other(payload262) => { + mbt_ffi_store8((iter_base) + 56, (3)) + + let ptr263 = mbt_ffi_str2ptr(payload262) + mbt_ffi_store32((iter_base) + 64, payload262.length()) + mbt_ffi_store32((iter_base) + 60, ptr263) + cleanup_list.push(ptr263) + + () + } + } + + () + } + } + cleanup_list.push(ptr244) + cleanup_list.push(address249) + cleanup_list.push(address252) + + } + mbt_ffi_store32((iter_base) + 12, (payload243).length()) + mbt_ffi_store32((iter_base) + 8, address264) + cleanup_list.push(address264) + + () + } + VariantType(payload266) => { + mbt_ffi_store8((iter_base) + 0, (15)) + + let address289 = mbt_ffi_malloc((payload266).length() * 72); + for index290 = 0; index290 < (payload266).length(); index290 = index290 + 1 { + let iter_elem : @types.VariantCaseType = (payload266)[(index290)] + let iter_base = address289 + (index290 * 72); + + let ptr267 = mbt_ffi_str2ptr((iter_elem).name) + mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) + mbt_ffi_store32((iter_base) + 0, ptr267) + + match ((iter_elem).payload) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload269) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload269) + + () + } + } + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload271) => { + mbt_ffi_store8((iter_base) + 16, (1)) + + let ptr272 = mbt_ffi_str2ptr(payload271) + mbt_ffi_store32((iter_base) + 24, payload271.length()) + mbt_ffi_store32((iter_base) + 20, ptr272) + cleanup_list.push(ptr272) + + () + } + } + + let address274 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index275 = 0; index275 < (((iter_elem).metadata).aliases).length(); index275 = index275 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index275)] + let iter_base = address274 + (index275 * 8); + + let ptr273 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr273) + cleanup_list.push(ptr273) + + } + mbt_ffi_store32((iter_base) + 32, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 28, address274) + + let address277 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index278 = 0; index278 < (((iter_elem).metadata).examples).length(); index278 = index278 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index278)] + let iter_base = address277 + (index278 * 8); + + let ptr276 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr276) + cleanup_list.push(ptr276) + + } + mbt_ffi_store32((iter_base) + 40, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 36, address277) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 44, (0)) + + () + } + Some(payload280) => { + mbt_ffi_store8((iter_base) + 44, (1)) + + let ptr281 = mbt_ffi_str2ptr(payload280) + mbt_ffi_store32((iter_base) + 52, payload280.length()) + mbt_ffi_store32((iter_base) + 48, ptr281) + cleanup_list.push(ptr281) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + Some(payload283) => { + mbt_ffi_store8((iter_base) + 56, (1)) + + match payload283 { + Multimodal => { + mbt_ffi_store8((iter_base) + 60, (0)) + + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 60, (1)) + + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 60, (2)) + + () + } + Other(payload287) => { + mbt_ffi_store8((iter_base) + 60, (3)) + + let ptr288 = mbt_ffi_str2ptr(payload287) + mbt_ffi_store32((iter_base) + 68, payload287.length()) + mbt_ffi_store32((iter_base) + 64, ptr288) + cleanup_list.push(ptr288) + + () + } + } + + () + } + } + cleanup_list.push(ptr267) + cleanup_list.push(address274) + cleanup_list.push(address277) + + } + mbt_ffi_store32((iter_base) + 12, (payload266).length()) + mbt_ffi_store32((iter_base) + 8, address289) + cleanup_list.push(address289) + + () + } + EnumType(payload291) => { + mbt_ffi_store8((iter_base) + 0, (16)) + + let address293 = mbt_ffi_malloc((payload291).length() * 8); + for index294 = 0; index294 < (payload291).length(); index294 = index294 + 1 { + let iter_elem : String = (payload291)[(index294)] + let iter_base = address293 + (index294 * 8); + + let ptr292 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr292) + cleanup_list.push(ptr292) + + } + mbt_ffi_store32((iter_base) + 12, (payload291).length()) + mbt_ffi_store32((iter_base) + 8, address293) + cleanup_list.push(address293) + + () + } + FlagsType(payload295) => { + mbt_ffi_store8((iter_base) + 0, (17)) + + let address297 = mbt_ffi_malloc((payload295).length() * 8); + for index298 = 0; index298 < (payload295).length(); index298 = index298 + 1 { + let iter_elem : String = (payload295)[(index298)] + let iter_base = address297 + (index298 * 8); + + let ptr296 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr296) + cleanup_list.push(ptr296) + + } + mbt_ffi_store32((iter_base) + 12, (payload295).length()) + mbt_ffi_store32((iter_base) + 8, address297) + cleanup_list.push(address297) + + () + } + TupleType(payload299) => { + mbt_ffi_store8((iter_base) + 0, (18)) + + let address300 = mbt_ffi_malloc((payload299).length() * 4); + for index301 = 0; index301 < (payload299).length(); index301 = index301 + 1 { + let iter_elem : Int = (payload299)[(index301)] + let iter_base = address300 + (index301 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload299).length()) + mbt_ffi_store32((iter_base) + 8, address300) + cleanup_list.push(address300) + + () + } + ListType(payload302) => { + mbt_ffi_store8((iter_base) + 0, (19)) + mbt_ffi_store32((iter_base) + 8, payload302) + + () + } + FixedListType(payload303) => { + mbt_ffi_store8((iter_base) + 0, (20)) + mbt_ffi_store32((iter_base) + 8, (payload303).element) + mbt_ffi_store32((iter_base) + 12, ((payload303).length).reinterpret_as_int()) + + () + } + MapType(payload304) => { + mbt_ffi_store8((iter_base) + 0, (21)) + mbt_ffi_store32((iter_base) + 8, (payload304).key) + mbt_ffi_store32((iter_base) + 12, (payload304).value) + + () + } + OptionType(payload305) => { + mbt_ffi_store8((iter_base) + 0, (22)) + mbt_ffi_store32((iter_base) + 8, payload305) + + () + } + ResultType(payload306) => { + mbt_ffi_store8((iter_base) + 0, (23)) + + match ((payload306).ok) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload308) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload308) + + () + } + } + + match ((payload306).err) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) + + () + } + Some(payload310) => { + mbt_ffi_store8((iter_base) + 16, (1)) + mbt_ffi_store32((iter_base) + 20, payload310) + + () + } + } + + () + } + TextType(payload311) => { + mbt_ffi_store8((iter_base) + 0, (24)) + + match ((payload311).languages) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload313) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address315 = mbt_ffi_malloc((payload313).length() * 8); + for index316 = 0; index316 < (payload313).length(); index316 = index316 + 1 { + let iter_elem : String = (payload313)[(index316)] + let iter_base = address315 + (index316 * 8); + + let ptr314 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr314) + cleanup_list.push(ptr314) + + } + mbt_ffi_store32((iter_base) + 16, (payload313).length()) + mbt_ffi_store32((iter_base) + 12, address315) + cleanup_list.push(address315) + + () + } + } + + match ((payload311).min_length) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload318) => { + mbt_ffi_store8((iter_base) + 20, (1)) + mbt_ffi_store32((iter_base) + 24, (payload318).reinterpret_as_int()) + + () + } + } + + match ((payload311).max_length) { + None => { + mbt_ffi_store8((iter_base) + 28, (0)) + + () + } + Some(payload320) => { + mbt_ffi_store8((iter_base) + 28, (1)) + mbt_ffi_store32((iter_base) + 32, (payload320).reinterpret_as_int()) + + () + } + } + + match ((payload311).regex) { + None => { + mbt_ffi_store8((iter_base) + 36, (0)) + + () + } + Some(payload322) => { + mbt_ffi_store8((iter_base) + 36, (1)) + + let ptr323 = mbt_ffi_str2ptr(payload322) + mbt_ffi_store32((iter_base) + 44, payload322.length()) + mbt_ffi_store32((iter_base) + 40, ptr323) + cleanup_list.push(ptr323) + + () + } + } + + () + } + BinaryType(payload324) => { + mbt_ffi_store8((iter_base) + 0, (25)) + + match ((payload324).mime_types) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload326) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address328 = mbt_ffi_malloc((payload326).length() * 8); + for index329 = 0; index329 < (payload326).length(); index329 = index329 + 1 { + let iter_elem : String = (payload326)[(index329)] + let iter_base = address328 + (index329 * 8); + + let ptr327 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr327) + cleanup_list.push(ptr327) + + } + mbt_ffi_store32((iter_base) + 16, (payload326).length()) + mbt_ffi_store32((iter_base) + 12, address328) + cleanup_list.push(address328) + + () + } + } + + match ((payload324).min_bytes) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload331) => { + mbt_ffi_store8((iter_base) + 20, (1)) + mbt_ffi_store32((iter_base) + 24, (payload331).reinterpret_as_int()) + + () + } + } + + match ((payload324).max_bytes) { + None => { + mbt_ffi_store8((iter_base) + 28, (0)) + + () + } + Some(payload333) => { + mbt_ffi_store8((iter_base) + 28, (1)) + mbt_ffi_store32((iter_base) + 32, (payload333).reinterpret_as_int()) + + () + } + } + + () + } + PathType(payload334) => { + mbt_ffi_store8((iter_base) + 0, (26)) + mbt_ffi_store8((iter_base) + 8, (payload334).direction.ordinal()) + mbt_ffi_store8((iter_base) + 9, (payload334).kind.ordinal()) + + match ((payload334).allowed_mime_types) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) + + () + } + Some(payload336) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let address338 = mbt_ffi_malloc((payload336).length() * 8); + for index339 = 0; index339 < (payload336).length(); index339 = index339 + 1 { + let iter_elem : String = (payload336)[(index339)] + let iter_base = address338 + (index339 * 8); + + let ptr337 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr337) + cleanup_list.push(ptr337) + + } + mbt_ffi_store32((iter_base) + 20, (payload336).length()) + mbt_ffi_store32((iter_base) + 16, address338) + cleanup_list.push(address338) + + () + } + } + + match ((payload334).allowed_extensions) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload341) => { + mbt_ffi_store8((iter_base) + 24, (1)) + + let address343 = mbt_ffi_malloc((payload341).length() * 8); + for index344 = 0; index344 < (payload341).length(); index344 = index344 + 1 { + let iter_elem : String = (payload341)[(index344)] + let iter_base = address343 + (index344 * 8); + + let ptr342 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr342) + cleanup_list.push(ptr342) + + } + mbt_ffi_store32((iter_base) + 32, (payload341).length()) + mbt_ffi_store32((iter_base) + 28, address343) + cleanup_list.push(address343) + + () + } + } + + () + } + UrlType(payload345) => { + mbt_ffi_store8((iter_base) + 0, (27)) + + match ((payload345).allowed_schemes) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) + + () + } + Some(payload347) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + let address349 = mbt_ffi_malloc((payload347).length() * 8); + for index350 = 0; index350 < (payload347).length(); index350 = index350 + 1 { + let iter_elem : String = (payload347)[(index350)] + let iter_base = address349 + (index350 * 8); + + let ptr348 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr348) + cleanup_list.push(ptr348) + + } + mbt_ffi_store32((iter_base) + 16, (payload347).length()) + mbt_ffi_store32((iter_base) + 12, address349) + cleanup_list.push(address349) + + () + } + } + + match ((payload345).allowed_hosts) { + None => { + mbt_ffi_store8((iter_base) + 20, (0)) + + () + } + Some(payload352) => { + mbt_ffi_store8((iter_base) + 20, (1)) + + let address354 = mbt_ffi_malloc((payload352).length() * 8); + for index355 = 0; index355 < (payload352).length(); index355 = index355 + 1 { + let iter_elem : String = (payload352)[(index355)] + let iter_base = address354 + (index355 * 8); + + let ptr353 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr353) + cleanup_list.push(ptr353) + + } + mbt_ffi_store32((iter_base) + 28, (payload352).length()) + mbt_ffi_store32((iter_base) + 24, address354) + cleanup_list.push(address354) + + () + } + } + + () + } + DatetimeType => { + mbt_ffi_store8((iter_base) + 0, (28)) - let address = mbt_ffi_malloc((payload13).length() * 4); - for index = 0; index < (payload13).length(); index = index + 1 { - let iter_elem : Int = (payload13)[(index)] - let iter_base = address + (index * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + () + } + DurationType => { + mbt_ffi_store8((iter_base) + 0, (29)) + () } - mbt_ffi_store32((iter_base) + 12, (payload13).length()) - mbt_ffi_store32((iter_base) + 8, address) - cleanup_list.push(address) + QuantityType(payload358) => { + mbt_ffi_store8((iter_base) + 0, (30)) - () - } - VariantValue(payload14) => { - mbt_ffi_store8((iter_base) + 0, (14)) - mbt_ffi_store32((iter_base) + 8, ((payload14).case).reinterpret_as_int()) + let ptr359 = mbt_ffi_str2ptr((payload358).base_unit) + mbt_ffi_store32((iter_base) + 12, (payload358).base_unit.length()) + mbt_ffi_store32((iter_base) + 8, ptr359) - match ((payload14).payload) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + let address361 = mbt_ffi_malloc(((payload358).allowed_suffixes).length() * 8); + for index362 = 0; index362 < ((payload358).allowed_suffixes).length(); index362 = index362 + 1 { + let iter_elem : String = ((payload358).allowed_suffixes)[(index362)] + let iter_base = address361 + (index362 * 8); + + let ptr360 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr360) + cleanup_list.push(ptr360) - () } - Some(payload16) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload16) + mbt_ffi_store32((iter_base) + 20, ((payload358).allowed_suffixes).length()) + mbt_ffi_store32((iter_base) + 16, address361) - () + match ((payload358).min) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload364) => { + mbt_ffi_store8((iter_base) + 24, (1)) + mbt_ffi_store64((iter_base) + 32, (payload364).mantissa) + mbt_ffi_store32((iter_base) + 40, (payload364).scale) + + let ptr365 = mbt_ffi_str2ptr((payload364).unit) + mbt_ffi_store32((iter_base) + 48, (payload364).unit.length()) + mbt_ffi_store32((iter_base) + 44, ptr365) + cleanup_list.push(ptr365) + + () + } + } + + match ((payload358).max) { + None => { + mbt_ffi_store8((iter_base) + 56, (0)) + + () + } + Some(payload367) => { + mbt_ffi_store8((iter_base) + 56, (1)) + mbt_ffi_store64((iter_base) + 64, (payload367).mantissa) + mbt_ffi_store32((iter_base) + 72, (payload367).scale) + + let ptr368 = mbt_ffi_str2ptr((payload367).unit) + mbt_ffi_store32((iter_base) + 80, (payload367).unit.length()) + mbt_ffi_store32((iter_base) + 76, ptr368) + cleanup_list.push(ptr368) + + () + } } + cleanup_list.push(ptr359) + cleanup_list.push(address361) + + () } + UnionType(payload369) => { + mbt_ffi_store8((iter_base) + 0, (31)) - () - } - EnumValue(payload17) => { - mbt_ffi_store8((iter_base) + 0, (15)) - mbt_ffi_store32((iter_base) + 8, (payload17).reinterpret_as_int()) + let address405 = mbt_ffi_malloc(((payload369).branches).length() * 92); + for index406 = 0; index406 < ((payload369).branches).length(); index406 = index406 + 1 { + let iter_elem : @types.UnionBranch = ((payload369).branches)[(index406)] + let iter_base = address405 + (index406 * 92); + + let ptr370 = mbt_ffi_str2ptr((iter_elem).tag) + mbt_ffi_store32((iter_base) + 4, (iter_elem).tag.length()) + mbt_ffi_store32((iter_base) + 0, ptr370) + mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + + match (iter_elem).discriminator { + Prefix(payload371) => { + mbt_ffi_store8((iter_base) + 12, (0)) + + let ptr372 = mbt_ffi_str2ptr(payload371) + mbt_ffi_store32((iter_base) + 20, payload371.length()) + mbt_ffi_store32((iter_base) + 16, ptr372) + cleanup_list.push(ptr372) + + () + } + Suffix(payload373) => { + mbt_ffi_store8((iter_base) + 12, (1)) + + let ptr374 = mbt_ffi_str2ptr(payload373) + mbt_ffi_store32((iter_base) + 20, payload373.length()) + mbt_ffi_store32((iter_base) + 16, ptr374) + cleanup_list.push(ptr374) + + () + } + Contains(payload375) => { + mbt_ffi_store8((iter_base) + 12, (2)) + + let ptr376 = mbt_ffi_str2ptr(payload375) + mbt_ffi_store32((iter_base) + 20, payload375.length()) + mbt_ffi_store32((iter_base) + 16, ptr376) + cleanup_list.push(ptr376) + + () + } + Regex(payload377) => { + mbt_ffi_store8((iter_base) + 12, (3)) + + let ptr378 = mbt_ffi_str2ptr(payload377) + mbt_ffi_store32((iter_base) + 20, payload377.length()) + mbt_ffi_store32((iter_base) + 16, ptr378) + cleanup_list.push(ptr378) + + () + } + FieldEquals(payload379) => { + mbt_ffi_store8((iter_base) + 12, (4)) + + let ptr380 = mbt_ffi_str2ptr((payload379).field_name) + mbt_ffi_store32((iter_base) + 20, (payload379).field_name.length()) + mbt_ffi_store32((iter_base) + 16, ptr380) + + match ((payload379).literal) { + None => { + mbt_ffi_store8((iter_base) + 24, (0)) + + () + } + Some(payload382) => { + mbt_ffi_store8((iter_base) + 24, (1)) + + let ptr383 = mbt_ffi_str2ptr(payload382) + mbt_ffi_store32((iter_base) + 32, payload382.length()) + mbt_ffi_store32((iter_base) + 28, ptr383) + cleanup_list.push(ptr383) + + () + } + } + cleanup_list.push(ptr380) + + () + } + FieldAbsent(payload384) => { + mbt_ffi_store8((iter_base) + 12, (5)) + + let ptr385 = mbt_ffi_str2ptr(payload384) + mbt_ffi_store32((iter_base) + 20, payload384.length()) + mbt_ffi_store32((iter_base) + 16, ptr385) + cleanup_list.push(ptr385) + + () + } + } + + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 36, (0)) + + () + } + Some(payload387) => { + mbt_ffi_store8((iter_base) + 36, (1)) + + let ptr388 = mbt_ffi_str2ptr(payload387) + mbt_ffi_store32((iter_base) + 44, payload387.length()) + mbt_ffi_store32((iter_base) + 40, ptr388) + cleanup_list.push(ptr388) + + () + } + } + + let address390 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index391 = 0; index391 < (((iter_elem).metadata).aliases).length(); index391 = index391 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index391)] + let iter_base = address390 + (index391 * 8); + + let ptr389 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr389) + cleanup_list.push(ptr389) + + } + mbt_ffi_store32((iter_base) + 52, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 48, address390) + + let address393 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index394 = 0; index394 < (((iter_elem).metadata).examples).length(); index394 = index394 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index394)] + let iter_base = address393 + (index394 * 8); + + let ptr392 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr392) + cleanup_list.push(ptr392) + + } + mbt_ffi_store32((iter_base) + 60, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 56, address393) + + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 64, (0)) + + () + } + Some(payload396) => { + mbt_ffi_store8((iter_base) + 64, (1)) + + let ptr397 = mbt_ffi_str2ptr(payload396) + mbt_ffi_store32((iter_base) + 72, payload396.length()) + mbt_ffi_store32((iter_base) + 68, ptr397) + cleanup_list.push(ptr397) + + () + } + } + + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 76, (0)) + + () + } + Some(payload399) => { + mbt_ffi_store8((iter_base) + 76, (1)) - () - } - FlagsValue(payload18) => { - mbt_ffi_store8((iter_base) + 0, (16)) + match payload399 { + Multimodal => { + mbt_ffi_store8((iter_base) + 80, (0)) - let address19 = mbt_ffi_malloc((payload18).length() * 1); - for index20 = 0; index20 < (payload18).length(); index20 = index20 + 1 { - let iter_elem : Bool = (payload18)[(index20)] - let iter_base = address19 + (index20 * 1); - mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 80, (1)) - } - mbt_ffi_store32((iter_base) + 12, (payload18).length()) - mbt_ffi_store32((iter_base) + 8, address19) - cleanup_list.push(address19) + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 80, (2)) - () - } - TupleValue(payload21) => { - mbt_ffi_store8((iter_base) + 0, (17)) + () + } + Other(payload403) => { + mbt_ffi_store8((iter_base) + 80, (3)) - let address22 = mbt_ffi_malloc((payload21).length() * 4); - for index23 = 0; index23 < (payload21).length(); index23 = index23 + 1 { - let iter_elem : Int = (payload21)[(index23)] - let iter_base = address22 + (index23 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + let ptr404 = mbt_ffi_str2ptr(payload403) + mbt_ffi_store32((iter_base) + 88, payload403.length()) + mbt_ffi_store32((iter_base) + 84, ptr404) + cleanup_list.push(ptr404) - } - mbt_ffi_store32((iter_base) + 12, (payload21).length()) - mbt_ffi_store32((iter_base) + 8, address22) - cleanup_list.push(address22) + () + } + } - () - } - ListValue(payload24) => { - mbt_ffi_store8((iter_base) + 0, (18)) + () + } + } + cleanup_list.push(ptr370) + cleanup_list.push(address390) + cleanup_list.push(address393) - let address25 = mbt_ffi_malloc((payload24).length() * 4); - for index26 = 0; index26 < (payload24).length(); index26 = index26 + 1 { - let iter_elem : Int = (payload24)[(index26)] - let iter_base = address25 + (index26 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + } + mbt_ffi_store32((iter_base) + 12, ((payload369).branches).length()) + mbt_ffi_store32((iter_base) + 8, address405) + cleanup_list.push(address405) + () } - mbt_ffi_store32((iter_base) + 12, (payload24).length()) - mbt_ffi_store32((iter_base) + 8, address25) - cleanup_list.push(address25) - - () - } - FixedListValue(payload27) => { - mbt_ffi_store8((iter_base) + 0, (19)) + SecretType(payload407) => { + mbt_ffi_store8((iter_base) + 0, (32)) + mbt_ffi_store32((iter_base) + 8, (payload407).inner) - let address28 = mbt_ffi_malloc((payload27).length() * 4); - for index29 = 0; index29 < (payload27).length(); index29 = index29 + 1 { - let iter_elem : Int = (payload27)[(index29)] - let iter_base = address28 + (index29 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + match ((payload407).category) { + None => { + mbt_ffi_store8((iter_base) + 12, (0)) - } - mbt_ffi_store32((iter_base) + 12, (payload27).length()) - mbt_ffi_store32((iter_base) + 8, address28) - cleanup_list.push(address28) + () + } + Some(payload409) => { + mbt_ffi_store8((iter_base) + 12, (1)) - () - } - MapValue(payload30) => { - mbt_ffi_store8((iter_base) + 0, (20)) + let ptr410 = mbt_ffi_str2ptr(payload409) + mbt_ffi_store32((iter_base) + 20, payload409.length()) + mbt_ffi_store32((iter_base) + 16, ptr410) + cleanup_list.push(ptr410) - let address31 = mbt_ffi_malloc((payload30).length() * 8); - for index32 = 0; index32 < (payload30).length(); index32 = index32 + 1 { - let iter_elem : @types.MapEntry = (payload30)[(index32)] - let iter_base = address31 + (index32 * 8); - mbt_ffi_store32((iter_base) + 0, (iter_elem).key) - mbt_ffi_store32((iter_base) + 4, (iter_elem).value) + () + } + } + () } - mbt_ffi_store32((iter_base) + 12, (payload30).length()) - mbt_ffi_store32((iter_base) + 8, address31) - cleanup_list.push(address31) + QuotaTokenType(payload411) => { + mbt_ffi_store8((iter_base) + 0, (33)) - () - } - OptionValue(payload33) => { - mbt_ffi_store8((iter_base) + 0, (21)) + match ((payload411).resource_name) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) - match (payload33) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + () + } + Some(payload413) => { + mbt_ffi_store8((iter_base) + 8, (1)) - () - } - Some(payload35) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload35) + let ptr414 = mbt_ffi_str2ptr(payload413) + mbt_ffi_store32((iter_base) + 16, payload413.length()) + mbt_ffi_store32((iter_base) + 12, ptr414) + cleanup_list.push(ptr414) - () + () + } } - } - - () - } - ResultValue(payload36) => { - mbt_ffi_store8((iter_base) + 0, (22)) - match payload36 { - OkValue(payload37) => { - mbt_ffi_store8((iter_base) + 8, (0)) + () + } + PermissionCardType(payload415) => { + mbt_ffi_store8((iter_base) + 0, (34)) + mbt_ffi_store8((iter_base) + 8, (if (payload415).polymorphic { 1 } else { 0 })) - match (payload37) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + () + } + FutureType(payload416) => { + mbt_ffi_store8((iter_base) + 0, (35)) - () - } - Some(payload39) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload39) + match (payload416) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) - () - } + () } + Some(payload418) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload418) - () + () + } } - ErrValue(payload40) => { - mbt_ffi_store8((iter_base) + 8, (1)) - match (payload40) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + () + } + StreamType(payload419) => { + mbt_ffi_store8((iter_base) + 0, (36)) - () - } - Some(payload42) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload42) + match (payload419) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) - () - } + () } + Some(payload421) => { + mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload421) - () + () + } } - } - () + () + } } - TextValue(payload43) => { - mbt_ffi_store8((iter_base) + 0, (23)) - - let ptr44 = mbt_ffi_str2ptr((payload43).text) - mbt_ffi_store32((iter_base) + 12, (payload43).text.length()) - mbt_ffi_store32((iter_base) + 8, ptr44) - match ((payload43).language) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + match (((iter_elem).metadata).doc) { + None => { + mbt_ffi_store8((iter_base) + 88, (0)) - () - } - Some(payload46) => { - mbt_ffi_store8((iter_base) + 16, (1)) + () + } + Some(payload423) => { + mbt_ffi_store8((iter_base) + 88, (1)) - let ptr47 = mbt_ffi_str2ptr(payload46) - mbt_ffi_store32((iter_base) + 24, payload46.length()) - mbt_ffi_store32((iter_base) + 20, ptr47) - cleanup_list.push(ptr47) + let ptr424 = mbt_ffi_str2ptr(payload423) + mbt_ffi_store32((iter_base) + 96, payload423.length()) + mbt_ffi_store32((iter_base) + 92, ptr424) + cleanup_list.push(ptr424) - () - } + () } - cleanup_list.push(ptr44) + } + + let address426 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); + for index427 = 0; index427 < (((iter_elem).metadata).aliases).length(); index427 = index427 + 1 { + let iter_elem : String = (((iter_elem).metadata).aliases)[(index427)] + let iter_base = address426 + (index427 * 8); + + let ptr425 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr425) + cleanup_list.push(ptr425) - () } - BinaryValue(payload48) => { - mbt_ffi_store8((iter_base) + 0, (24)) - - let ptr49 = mbt_ffi_bytes2ptr((payload48).bytes) + mbt_ffi_store32((iter_base) + 104, (((iter_elem).metadata).aliases).length()) + mbt_ffi_store32((iter_base) + 100, address426) - mbt_ffi_store32((iter_base) + 12, (payload48).bytes.length()) - mbt_ffi_store32((iter_base) + 8, ptr49) + let address429 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); + for index430 = 0; index430 < (((iter_elem).metadata).examples).length(); index430 = index430 + 1 { + let iter_elem : String = (((iter_elem).metadata).examples)[(index430)] + let iter_base = address429 + (index430 * 8); - match ((payload48).mime_type) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let ptr428 = mbt_ffi_str2ptr(iter_elem) + mbt_ffi_store32((iter_base) + 4, iter_elem.length()) + mbt_ffi_store32((iter_base) + 0, ptr428) + cleanup_list.push(ptr428) - () - } - Some(payload51) => { - mbt_ffi_store8((iter_base) + 16, (1)) + } + mbt_ffi_store32((iter_base) + 112, (((iter_elem).metadata).examples).length()) + mbt_ffi_store32((iter_base) + 108, address429) - let ptr52 = mbt_ffi_str2ptr(payload51) - mbt_ffi_store32((iter_base) + 24, payload51.length()) - mbt_ffi_store32((iter_base) + 20, ptr52) - cleanup_list.push(ptr52) + match (((iter_elem).metadata).deprecated) { + None => { + mbt_ffi_store8((iter_base) + 116, (0)) - () - } + () } - cleanup_list.push(ptr49) + Some(payload432) => { + mbt_ffi_store8((iter_base) + 116, (1)) - () + let ptr433 = mbt_ffi_str2ptr(payload432) + mbt_ffi_store32((iter_base) + 124, payload432.length()) + mbt_ffi_store32((iter_base) + 120, ptr433) + cleanup_list.push(ptr433) + + () + } } - PathValue(payload53) => { - mbt_ffi_store8((iter_base) + 0, (25)) - let ptr54 = mbt_ffi_str2ptr(payload53) - mbt_ffi_store32((iter_base) + 12, payload53.length()) - mbt_ffi_store32((iter_base) + 8, ptr54) - cleanup_list.push(ptr54) + match (((iter_elem).metadata).role) { + None => { + mbt_ffi_store8((iter_base) + 128, (0)) - () - } - UrlValue(payload55) => { - mbt_ffi_store8((iter_base) + 0, (26)) + () + } + Some(payload435) => { + mbt_ffi_store8((iter_base) + 128, (1)) - let ptr56 = mbt_ffi_str2ptr(payload55) - mbt_ffi_store32((iter_base) + 12, payload55.length()) - mbt_ffi_store32((iter_base) + 8, ptr56) - cleanup_list.push(ptr56) + match payload435 { + Multimodal => { + mbt_ffi_store8((iter_base) + 132, (0)) - () - } - DatetimeValue(payload57) => { - mbt_ffi_store8((iter_base) + 0, (27)) - mbt_ffi_store64((iter_base) + 8, (payload57).seconds) - mbt_ffi_store32((iter_base) + 16, ((payload57).nanoseconds).reinterpret_as_int()) + () + } + UnstructuredText => { + mbt_ffi_store8((iter_base) + 132, (1)) - () - } - DurationValue(payload58) => { - mbt_ffi_store8((iter_base) + 0, (28)) - mbt_ffi_store64((iter_base) + 8, (payload58).nanoseconds) + () + } + UnstructuredBinary => { + mbt_ffi_store8((iter_base) + 132, (2)) - () - } - QuantityValueNode(payload59) => { - mbt_ffi_store8((iter_base) + 0, (29)) - mbt_ffi_store64((iter_base) + 8, (payload59).mantissa) - mbt_ffi_store32((iter_base) + 16, (payload59).scale) + () + } + Other(payload439) => { + mbt_ffi_store8((iter_base) + 132, (3)) - let ptr60 = mbt_ffi_str2ptr((payload59).unit) - mbt_ffi_store32((iter_base) + 24, (payload59).unit.length()) - mbt_ffi_store32((iter_base) + 20, ptr60) - cleanup_list.push(ptr60) + let ptr440 = mbt_ffi_str2ptr(payload439) + mbt_ffi_store32((iter_base) + 140, payload439.length()) + mbt_ffi_store32((iter_base) + 136, ptr440) + cleanup_list.push(ptr440) - () + () + } + } + + () + } } - UnionValue(payload61) => { - mbt_ffi_store8((iter_base) + 0, (30)) + cleanup_list.push(address426) + cleanup_list.push(address429) - let ptr62 = mbt_ffi_str2ptr((payload61).tag) - mbt_ffi_store32((iter_base) + 12, (payload61).tag.length()) - mbt_ffi_store32((iter_base) + 8, ptr62) - mbt_ffi_store32((iter_base) + 16, (payload61).body) - cleanup_list.push(ptr62) + } + mbt_ffi_store32((iter_base) + 12, ((((iter_elem).value).graph).type_nodes).length()) + mbt_ffi_store32((iter_base) + 8, address441) - () - } - SecretValue(payload63) => { - mbt_ffi_store8((iter_base) + 0, (31)) + let address447 = mbt_ffi_malloc(((((iter_elem).value).graph).defs).length() * 24); + for index448 = 0; index448 < ((((iter_elem).value).graph).defs).length(); index448 = index448 + 1 { + let iter_elem : @types.SchemaTypeDef = ((((iter_elem).value).graph).defs)[(index448)] + let iter_base = address447 + (index448 * 24); - let @types.Secret(handle) = payload63 - mbt_ffi_store32((iter_base) + 8, handle) + let ptr443 = mbt_ffi_str2ptr((iter_elem).id) + mbt_ffi_store32((iter_base) + 4, (iter_elem).id.length()) + mbt_ffi_store32((iter_base) + 0, ptr443) - () - } - QuotaTokenHandle(payload64) => { - mbt_ffi_store8((iter_base) + 0, (32)) + match ((iter_elem).name) { + None => { + mbt_ffi_store8((iter_base) + 8, (0)) - let @types.QuotaToken(handle65) = payload64 - mbt_ffi_store32((iter_base) + 8, handle65) + () + } + Some(payload445) => { + mbt_ffi_store8((iter_base) + 8, (1)) - () + let ptr446 = mbt_ffi_str2ptr(payload445) + mbt_ffi_store32((iter_base) + 16, payload445.length()) + mbt_ffi_store32((iter_base) + 12, ptr446) + cleanup_list.push(ptr446) + + () + } } - PermissionCardHandle(payload66) => { - mbt_ffi_store8((iter_base) + 0, (33)) + mbt_ffi_store32((iter_base) + 20, (iter_elem).body) + cleanup_list.push(ptr443) - let @types.PermissionCard(handle67) = payload66 - mbt_ffi_store32((iter_base) + 8, handle67) + } + mbt_ffi_store32((iter_base) + 20, ((((iter_elem).value).graph).defs).length()) + mbt_ffi_store32((iter_base) + 16, address447) + mbt_ffi_store32((iter_base) + 24, (((iter_elem).value).graph).root) - () - } - StreamValue(payload68) => { - mbt_ffi_store8((iter_base) + 0, (34)) + let address523 = mbt_ffi_malloc(((((iter_elem).value).value).value_nodes).length() * 32); + for index524 = 0; index524 < ((((iter_elem).value).value).value_nodes).length(); index524 = index524 + 1 { + let iter_elem : @types.SchemaValueNode = ((((iter_elem).value).value).value_nodes)[(index524)] + let iter_base = address523 + (index524 * 32); - let @types.SchemaValueStream(handle69) = payload68 - mbt_ffi_store32((iter_base) + 8, handle69) + match iter_elem { + BoolValue(payload449) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store8((iter_base) + 8, (if payload449 { 1 } else { 0 })) - () - } - } + () + } + S8Value(payload450) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload450)) - } + () + } + S16Value(payload451) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload451)) - let (lowered, lowered74, lowered75) = match (phantom_id) { - None => { + () + } + S32Value(payload452) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 8, payload452) - ((0), 0L, 0L) - } - Some(payload73) => { + () + } + S64Value(payload453) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store64((iter_base) + 8, payload453) - ((1), ((payload73).high_bits).reinterpret_as_int64(), ((payload73).low_bits).reinterpret_as_int64()) - } - } + () + } + U8Value(payload454) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store8((iter_base) + 8, (payload454).to_int()) - let address525 = mbt_ffi_malloc((agent_config).length() * 40); - for index526 = 0; index526 < (agent_config).length(); index526 = index526 + 1 { - let iter_elem : @common.TypedAgentConfigValue = (agent_config)[(index526)] - let iter_base = address525 + (index526 * 40); + () + } + U16Value(payload455) => { + mbt_ffi_store8((iter_base) + 0, (6)) + mbt_ffi_store16((iter_base) + 8, (payload455).reinterpret_as_int()) - let address77 = mbt_ffi_malloc(((iter_elem).path).length() * 8); - for index78 = 0; index78 < ((iter_elem).path).length(); index78 = index78 + 1 { - let iter_elem : String = ((iter_elem).path)[(index78)] - let iter_base = address77 + (index78 * 8); + () + } + U32Value(payload456) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 8, (payload456).reinterpret_as_int()) - let ptr76 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr76) - cleanup_list.push(ptr76) + () + } + U64Value(payload457) => { + mbt_ffi_store8((iter_base) + 0, (8)) + mbt_ffi_store64((iter_base) + 8, (payload457).reinterpret_as_int64()) + + () + } + F32Value(payload458) => { + mbt_ffi_store8((iter_base) + 0, (9)) + mbt_ffi_storef32((iter_base) + 8, payload458) - } - mbt_ffi_store32((iter_base) + 4, ((iter_elem).path).length()) - mbt_ffi_store32((iter_base) + 0, address77) + () + } + F64Value(payload459) => { + mbt_ffi_store8((iter_base) + 0, (10)) + mbt_ffi_storef64((iter_base) + 8, payload459) - let address441 = mbt_ffi_malloc(((((iter_elem).value).graph).type_nodes).length() * 144); - for index442 = 0; index442 < ((((iter_elem).value).graph).type_nodes).length(); index442 = index442 + 1 { - let iter_elem : @types.SchemaTypeNode = ((((iter_elem).value).graph).type_nodes)[(index442)] - let iter_base = address441 + (index442 * 144); + () + } + CharValue(payload460) => { + mbt_ffi_store8((iter_base) + 0, (11)) + mbt_ffi_store32((iter_base) + 8, (payload460).to_int()) - match (iter_elem).body { - RefType(payload79) => { - mbt_ffi_store8((iter_base) + 0, (0)) - mbt_ffi_store32((iter_base) + 8, payload79) + () + } + StringValue(payload461) => { + mbt_ffi_store8((iter_base) + 0, (12)) + + let ptr462 = mbt_ffi_str2ptr(payload461) + mbt_ffi_store32((iter_base) + 12, payload461.length()) + mbt_ffi_store32((iter_base) + 8, ptr462) + cleanup_list.push(ptr462) () } - BoolType => { - mbt_ffi_store8((iter_base) + 0, (1)) + RecordValue(payload463) => { + mbt_ffi_store8((iter_base) + 0, (13)) + + let address464 = mbt_ffi_malloc((payload463).length() * 4); + for index465 = 0; index465 < (payload463).length(); index465 = index465 + 1 { + let iter_elem : Int = (payload463)[(index465)] + let iter_base = address464 + (index465 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) + + } + mbt_ffi_store32((iter_base) + 12, (payload463).length()) + mbt_ffi_store32((iter_base) + 8, address464) + cleanup_list.push(address464) () } - S8Type(payload81) => { - mbt_ffi_store8((iter_base) + 0, (2)) + VariantValue(payload466) => { + mbt_ffi_store8((iter_base) + 0, (14)) + mbt_ffi_store32((iter_base) + 8, ((payload466).case).reinterpret_as_int()) - match (payload81) { + match ((payload466).payload) { None => { - mbt_ffi_store8((iter_base) + 8, (0)) + mbt_ffi_store8((iter_base) + 12, (0)) () } - Some(payload83) => { - mbt_ffi_store8((iter_base) + 8, (1)) - - match ((payload83).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) - - () - } - Some(payload85) => { - mbt_ffi_store8((iter_base) + 16, (1)) + Some(payload468) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload468) - match payload85 { - Signed(payload86) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload86) + () + } + } - () - } - Unsigned(payload87) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload87).reinterpret_as_int64()) + () + } + EnumValue(payload469) => { + mbt_ffi_store8((iter_base) + 0, (15)) + mbt_ffi_store32((iter_base) + 8, (payload469).reinterpret_as_int()) - () - } - FloatBits(payload88) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload88).reinterpret_as_int64()) + () + } + FlagsValue(payload470) => { + mbt_ffi_store8((iter_base) + 0, (16)) - () - } - } + let address471 = mbt_ffi_malloc((payload470).length() * 1); + for index472 = 0; index472 < (payload470).length(); index472 = index472 + 1 { + let iter_elem : Bool = (payload470)[(index472)] + let iter_base = address471 + (index472 * 1); + mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) - () - } - } + } + mbt_ffi_store32((iter_base) + 12, (payload470).length()) + mbt_ffi_store32((iter_base) + 8, address471) + cleanup_list.push(address471) - match ((payload83).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + () + } + TupleValue(payload473) => { + mbt_ffi_store8((iter_base) + 0, (17)) - () - } - Some(payload90) => { - mbt_ffi_store8((iter_base) + 40, (1)) + let address474 = mbt_ffi_malloc((payload473).length() * 4); + for index475 = 0; index475 < (payload473).length(); index475 = index475 + 1 { + let iter_elem : Int = (payload473)[(index475)] + let iter_base = address474 + (index475 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - match payload90 { - Signed(payload91) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload91) + } + mbt_ffi_store32((iter_base) + 12, (payload473).length()) + mbt_ffi_store32((iter_base) + 8, address474) + cleanup_list.push(address474) - () - } - Unsigned(payload92) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload92).reinterpret_as_int64()) + () + } + ListValue(payload476) => { + mbt_ffi_store8((iter_base) + 0, (18)) - () - } - FloatBits(payload93) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload93).reinterpret_as_int64()) + let address477 = mbt_ffi_malloc((payload476).length() * 4); + for index478 = 0; index478 < (payload476).length(); index478 = index478 + 1 { + let iter_elem : Int = (payload476)[(index478)] + let iter_base = address477 + (index478 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - () - } - } + } + mbt_ffi_store32((iter_base) + 12, (payload476).length()) + mbt_ffi_store32((iter_base) + 8, address477) + cleanup_list.push(address477) - () - } - } + () + } + FixedListValue(payload479) => { + mbt_ffi_store8((iter_base) + 0, (19)) - match ((payload83).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let address480 = mbt_ffi_malloc((payload479).length() * 4); + for index481 = 0; index481 < (payload479).length(); index481 = index481 + 1 { + let iter_elem : Int = (payload479)[(index481)] + let iter_base = address480 + (index481 * 4); + mbt_ffi_store32((iter_base) + 0, iter_elem) - () - } - Some(payload95) => { - mbt_ffi_store8((iter_base) + 64, (1)) + } + mbt_ffi_store32((iter_base) + 12, (payload479).length()) + mbt_ffi_store32((iter_base) + 8, address480) + cleanup_list.push(address480) - let ptr96 = mbt_ffi_str2ptr(payload95) - mbt_ffi_store32((iter_base) + 72, payload95.length()) - mbt_ffi_store32((iter_base) + 68, ptr96) - cleanup_list.push(ptr96) + () + } + MapValue(payload482) => { + mbt_ffi_store8((iter_base) + 0, (20)) - () - } - } + let address483 = mbt_ffi_malloc((payload482).length() * 8); + for index484 = 0; index484 < (payload482).length(); index484 = index484 + 1 { + let iter_elem : @types.MapEntry = (payload482)[(index484)] + let iter_base = address483 + (index484 * 8); + mbt_ffi_store32((iter_base) + 0, (iter_elem).key) + mbt_ffi_store32((iter_base) + 4, (iter_elem).value) - () - } } + mbt_ffi_store32((iter_base) + 12, (payload482).length()) + mbt_ffi_store32((iter_base) + 8, address483) + cleanup_list.push(address483) () } - S16Type(payload97) => { - mbt_ffi_store8((iter_base) + 0, (3)) + OptionValue(payload485) => { + mbt_ffi_store8((iter_base) + 0, (21)) - match (payload97) { + match (payload485) { None => { mbt_ffi_store8((iter_base) + 8, (0)) () } - Some(payload99) => { + Some(payload487) => { mbt_ffi_store8((iter_base) + 8, (1)) + mbt_ffi_store32((iter_base) + 12, payload487) - match ((payload99).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) - - () - } - Some(payload101) => { - mbt_ffi_store8((iter_base) + 16, (1)) - - match payload101 { - Signed(payload102) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload102) - - () - } - Unsigned(payload103) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload103).reinterpret_as_int64()) - - () - } - FloatBits(payload104) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload104).reinterpret_as_int64()) + () + } + } - () - } - } + () + } + ResultValue(payload488) => { + mbt_ffi_store8((iter_base) + 0, (22)) - () - } - } + match payload488 { + OkValue(payload489) => { + mbt_ffi_store8((iter_base) + 8, (0)) - match ((payload99).max) { + match (payload489) { None => { - mbt_ffi_store8((iter_base) + 40, (0)) + mbt_ffi_store8((iter_base) + 12, (0)) () } - Some(payload106) => { - mbt_ffi_store8((iter_base) + 40, (1)) - - match payload106 { - Signed(payload107) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload107) - - () - } - Unsigned(payload108) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload108).reinterpret_as_int64()) - - () - } - FloatBits(payload109) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload109).reinterpret_as_int64()) - - () - } - } + Some(payload491) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload491) () } } - match ((payload99).unit) { + () + } + ErrValue(payload492) => { + mbt_ffi_store8((iter_base) + 8, (1)) + + match (payload492) { None => { - mbt_ffi_store8((iter_base) + 64, (0)) + mbt_ffi_store8((iter_base) + 12, (0)) () } - Some(payload111) => { - mbt_ffi_store8((iter_base) + 64, (1)) - - let ptr112 = mbt_ffi_str2ptr(payload111) - mbt_ffi_store32((iter_base) + 72, payload111.length()) - mbt_ffi_store32((iter_base) + 68, ptr112) - cleanup_list.push(ptr112) + Some(payload494) => { + mbt_ffi_store8((iter_base) + 12, (1)) + mbt_ffi_store32((iter_base) + 16, payload494) () } @@ -15118,2456 +24675,2074 @@ pub fn WasmRpc::wasm_rpc(agent_type_name : String, constructor_ : @types.SchemaV () } - S32Type(payload113) => { - mbt_ffi_store8((iter_base) + 0, (4)) + TextValue(payload495) => { + mbt_ffi_store8((iter_base) + 0, (23)) - match (payload113) { + let ptr496 = mbt_ffi_str2ptr((payload495).text) + mbt_ffi_store32((iter_base) + 12, (payload495).text.length()) + mbt_ffi_store32((iter_base) + 8, ptr496) + + match ((payload495).language) { None => { - mbt_ffi_store8((iter_base) + 8, (0)) + mbt_ffi_store8((iter_base) + 16, (0)) () } - Some(payload115) => { - mbt_ffi_store8((iter_base) + 8, (1)) - - match ((payload115).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) - - () - } - Some(payload117) => { - mbt_ffi_store8((iter_base) + 16, (1)) + Some(payload498) => { + mbt_ffi_store8((iter_base) + 16, (1)) - match payload117 { - Signed(payload118) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload118) + let ptr499 = mbt_ffi_str2ptr(payload498) + mbt_ffi_store32((iter_base) + 24, payload498.length()) + mbt_ffi_store32((iter_base) + 20, ptr499) + cleanup_list.push(ptr499) - () - } - Unsigned(payload119) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload119).reinterpret_as_int64()) + () + } + } + cleanup_list.push(ptr496) - () - } - FloatBits(payload120) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload120).reinterpret_as_int64()) + () + } + BinaryValue(payload500) => { + mbt_ffi_store8((iter_base) + 0, (24)) - () - } - } + let ptr501 = mbt_ffi_bytes2ptr((payload500).bytes) - () - } - } + mbt_ffi_store32((iter_base) + 12, (payload500).bytes.length()) + mbt_ffi_store32((iter_base) + 8, ptr501) - match ((payload115).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + match ((payload500).mime_type) { + None => { + mbt_ffi_store8((iter_base) + 16, (0)) - () - } - Some(payload122) => { - mbt_ffi_store8((iter_base) + 40, (1)) + () + } + Some(payload503) => { + mbt_ffi_store8((iter_base) + 16, (1)) - match payload122 { - Signed(payload123) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload123) + let ptr504 = mbt_ffi_str2ptr(payload503) + mbt_ffi_store32((iter_base) + 24, payload503.length()) + mbt_ffi_store32((iter_base) + 20, ptr504) + cleanup_list.push(ptr504) - () - } - Unsigned(payload124) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload124).reinterpret_as_int64()) + () + } + } + cleanup_list.push(ptr501) - () - } - FloatBits(payload125) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload125).reinterpret_as_int64()) + () + } + PathValue(payload505) => { + mbt_ffi_store8((iter_base) + 0, (25)) - () - } - } + let ptr506 = mbt_ffi_str2ptr(payload505) + mbt_ffi_store32((iter_base) + 12, payload505.length()) + mbt_ffi_store32((iter_base) + 8, ptr506) + cleanup_list.push(ptr506) - () - } - } + () + } + UrlValue(payload507) => { + mbt_ffi_store8((iter_base) + 0, (26)) - match ((payload115).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let ptr508 = mbt_ffi_str2ptr(payload507) + mbt_ffi_store32((iter_base) + 12, payload507.length()) + mbt_ffi_store32((iter_base) + 8, ptr508) + cleanup_list.push(ptr508) - () - } - Some(payload127) => { - mbt_ffi_store8((iter_base) + 64, (1)) + () + } + DatetimeValue(payload509) => { + mbt_ffi_store8((iter_base) + 0, (27)) + mbt_ffi_store64((iter_base) + 8, (payload509).seconds) + mbt_ffi_store32((iter_base) + 16, ((payload509).nanoseconds).reinterpret_as_int()) - let ptr128 = mbt_ffi_str2ptr(payload127) - mbt_ffi_store32((iter_base) + 72, payload127.length()) - mbt_ffi_store32((iter_base) + 68, ptr128) - cleanup_list.push(ptr128) + () + } + DurationValue(payload510) => { + mbt_ffi_store8((iter_base) + 0, (28)) + mbt_ffi_store64((iter_base) + 8, (payload510).nanoseconds) - () - } - } + () + } + QuantityValueNode(payload511) => { + mbt_ffi_store8((iter_base) + 0, (29)) + mbt_ffi_store64((iter_base) + 8, (payload511).mantissa) + mbt_ffi_store32((iter_base) + 16, (payload511).scale) - () - } - } + let ptr512 = mbt_ffi_str2ptr((payload511).unit) + mbt_ffi_store32((iter_base) + 24, (payload511).unit.length()) + mbt_ffi_store32((iter_base) + 20, ptr512) + cleanup_list.push(ptr512) () } - S64Type(payload129) => { - mbt_ffi_store8((iter_base) + 0, (5)) - - match (payload129) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + UnionValue(payload513) => { + mbt_ffi_store8((iter_base) + 0, (30)) - () - } - Some(payload131) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let ptr514 = mbt_ffi_str2ptr((payload513).tag) + mbt_ffi_store32((iter_base) + 12, (payload513).tag.length()) + mbt_ffi_store32((iter_base) + 8, ptr514) + mbt_ffi_store32((iter_base) + 16, (payload513).body) + cleanup_list.push(ptr514) - match ((payload131).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + () + } + SecretValue(payload515) => { + mbt_ffi_store8((iter_base) + 0, (31)) - () - } - Some(payload133) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let @types.Secret(handle516) = payload515 + mbt_ffi_store32((iter_base) + 8, handle516) - match payload133 { - Signed(payload134) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload134) + () + } + QuotaTokenHandle(payload517) => { + mbt_ffi_store8((iter_base) + 0, (32)) - () - } - Unsigned(payload135) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload135).reinterpret_as_int64()) + let @types.QuotaToken(handle518) = payload517 + mbt_ffi_store32((iter_base) + 8, handle518) - () - } - FloatBits(payload136) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload136).reinterpret_as_int64()) + () + } + PermissionCardHandle(payload519) => { + mbt_ffi_store8((iter_base) + 0, (33)) - () - } - } + let @types.PermissionCard(handle520) = payload519 + mbt_ffi_store32((iter_base) + 8, handle520) - () - } - } + () + } + StreamValue(payload521) => { + mbt_ffi_store8((iter_base) + 0, (34)) - match ((payload131).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + let @types.SchemaValueStream(handle522) = payload521 + mbt_ffi_store32((iter_base) + 8, handle522) - () - } - Some(payload138) => { - mbt_ffi_store8((iter_base) + 40, (1)) + () + } + } - match payload138 { - Signed(payload139) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload139) + } + mbt_ffi_store32((iter_base) + 32, ((((iter_elem).value).value).value_nodes).length()) + mbt_ffi_store32((iter_base) + 28, address523) + mbt_ffi_store32((iter_base) + 36, (((iter_elem).value).value).root) + cleanup_list.push(address77) + cleanup_list.push(address441) + cleanup_list.push(address447) + cleanup_list.push(address523) - () - } - Unsigned(payload140) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload140).reinterpret_as_int64()) + } + let return_area = mbt_ffi_malloc(44) + wasmImportStaticWasmRpcCreate(ptr, agent_type_name.length(), address70, ((constructor_).value_nodes).length(), (constructor_).root, lowered, lowered74, lowered75, address525, (agent_config).length(), return_area); - () - } - FloatBits(payload141) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload141).reinterpret_as_int64()) + let lifted768 = match (mbt_ffi_load8_u((return_area) + 0)) { + 0 => { - () - } - } + Result::Ok(WasmRpc::WasmRpc(mbt_ffi_load32((return_area) + 4))) + } + 1 => { - () - } - } + let lifted767 = match (mbt_ffi_load8_u((return_area) + 4)) { + 0 => { - match ((payload131).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - () - } - Some(payload143) => { - mbt_ffi_store8((iter_base) + 64, (1)) + RpcError::ProtocolError(result) + } + 1 => { - let ptr144 = mbt_ffi_str2ptr(payload143) - mbt_ffi_store32((iter_base) + 72, payload143.length()) - mbt_ffi_store32((iter_base) + 68, ptr144) - cleanup_list.push(ptr144) + let result527 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - () - } - } + RpcError::Denied(result527) + } + 2 => { - () - } - } + let result528 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - () + RpcError::NotFound(result528) } - U8Type(payload145) => { - mbt_ffi_store8((iter_base) + 0, (6)) + 3 => { - match (payload145) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result529 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12)) - () - } - Some(payload147) => { - mbt_ffi_store8((iter_base) + 8, (1)) + RpcError::RemoteInternalError(result529) + } + 4 => { - match ((payload147).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let lifted766 = match (mbt_ffi_load8_u((return_area) + 8)) { + 0 => { - () - } - Some(payload149) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let result530 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) - match payload149 { - Signed(payload150) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload150) + @common.AgentError::InvalidInput(result530) + } + 1 => { - () - } - Unsigned(payload151) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload151).reinterpret_as_int64()) + let result531 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) - () - } - FloatBits(payload152) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload152).reinterpret_as_int64()) + @common.AgentError::InvalidMethod(result531) + } + 2 => { - () - } - } + let result532 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) - () - } - } + @common.AgentError::InvalidType(result532) + } + 3 => { - match ((payload147).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + let result533 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16)) - () - } - Some(payload154) => { - mbt_ffi_store8((iter_base) + 40, (1)) + @common.AgentError::InvalidAgentId(result533) + } + 4 => { - match payload154 { - Signed(payload155) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload155) + let array728 : Array[@types.SchemaTypeNode] = []; + for index729 = 0; index729 < (mbt_ffi_load32((return_area) + 16)); index729 = index729 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 12)) + (index729 * 144) - () - } - Unsigned(payload156) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload156).reinterpret_as_int64()) + let lifted714 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - () - } - FloatBits(payload157) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload157).reinterpret_as_int64()) + @types.SchemaTypeBody::RefType(mbt_ffi_load32((iter_base) + 8)) + } + 1 => { - () - } + @types.SchemaTypeBody::BoolType } + 2 => { - () - } - } + let lifted539 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - match ((payload147).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let lifted534 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - Some(payload159) => { - mbt_ffi_store8((iter_base) + 64, (1)) + let lifted = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let ptr160 = mbt_ffi_str2ptr(payload159) - mbt_ffi_store32((iter_base) + 72, payload159.length()) - mbt_ffi_store32((iter_base) + 68, ptr160) - cleanup_list.push(ptr160) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - U16Type(payload161) => { - mbt_ffi_store8((iter_base) + 0, (7)) + Option::Some(lifted) + } + _ => panic() + } - match (payload161) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let lifted536 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - Some(payload163) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let lifted535 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - match ((payload163).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - Some(payload165) => { - mbt_ffi_store8((iter_base) + 16, (1)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - match payload165 { - Signed(payload166) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload166) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - Unsigned(payload167) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload167).reinterpret_as_int64()) + Option::Some(lifted535) + } + _ => panic() + } - () - } - FloatBits(payload168) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload168).reinterpret_as_int64()) + let lifted538 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () + let result537 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) + + Option::Some(result537) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted534, max : lifted536, unit : lifted538}) + } + _ => panic() } + + @types.SchemaTypeBody::S8Type(lifted539) } + 3 => { - () - } - } + let lifted546 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - match ((payload163).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + let lifted541 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - Some(payload170) => { - mbt_ffi_store8((iter_base) + 40, (1)) + let lifted540 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - match payload170 { - Signed(payload171) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload171) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - Unsigned(payload172) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload172).reinterpret_as_int64()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - FloatBits(payload173) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload173).reinterpret_as_int64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - } + Option::Some(lifted540) + } + _ => panic() + } - () - } - } + let lifted543 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - match ((payload163).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let lifted542 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - Some(payload175) => { - mbt_ffi_store8((iter_base) + 64, (1)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let ptr176 = mbt_ffi_str2ptr(payload175) - mbt_ffi_store32((iter_base) + 72, payload175.length()) - mbt_ffi_store32((iter_base) + 68, ptr176) - cleanup_list.push(ptr176) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - } + Option::Some(lifted542) + } + _ => panic() + } - () - } - U32Type(payload177) => { - mbt_ffi_store8((iter_base) + 0, (8)) + let lifted545 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match (payload177) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result544 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Some(payload179) => { - mbt_ffi_store8((iter_base) + 8, (1)) + Option::Some(result544) + } + _ => panic() + } - match ((payload179).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + Option::Some(@types.NumericRestrictions::{min : lifted541, max : lifted543, unit : lifted545}) + } + _ => panic() + } - () - } - Some(payload181) => { - mbt_ffi_store8((iter_base) + 16, (1)) + @types.SchemaTypeBody::S16Type(lifted546) + } + 4 => { - match payload181 { - Signed(payload182) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload182) + let lifted553 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Unsigned(payload183) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload183).reinterpret_as_int64()) + let lifted548 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - FloatBits(payload184) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload184).reinterpret_as_int64()) + let lifted547 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - } + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - match ((payload179).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - Some(payload186) => { - mbt_ffi_store8((iter_base) + 40, (1)) + Option::Some(lifted547) + } + _ => panic() + } - match payload186 { - Signed(payload187) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload187) + let lifted550 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - Unsigned(payload188) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload188).reinterpret_as_int64()) + let lifted549 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - FloatBits(payload189) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload189).reinterpret_as_int64()) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - match ((payload179).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + Option::Some(lifted549) + } + _ => panic() + } - () - } - Some(payload191) => { - mbt_ffi_store8((iter_base) + 64, (1)) + let lifted552 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - let ptr192 = mbt_ffi_str2ptr(payload191) - mbt_ffi_store32((iter_base) + 72, payload191.length()) - mbt_ffi_store32((iter_base) + 68, ptr192) - cleanup_list.push(ptr192) + let result551 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - } + Option::Some(result551) + } + _ => panic() + } - () - } - } + Option::Some(@types.NumericRestrictions::{min : lifted548, max : lifted550, unit : lifted552}) + } + _ => panic() + } - () - } - U64Type(payload193) => { - mbt_ffi_store8((iter_base) + 0, (9)) + @types.SchemaTypeBody::S32Type(lifted553) + } + 5 => { - match (payload193) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let lifted560 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Some(payload195) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let lifted555 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - match ((payload195).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let lifted554 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - Some(payload197) => { - mbt_ffi_store8((iter_base) + 16, (1)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { + + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { + + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } + + Option::Some(lifted554) + } + _ => panic() + } - match payload197 { - Signed(payload198) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload198) + let lifted557 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - Unsigned(payload199) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload199).reinterpret_as_int64()) + let lifted556 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - FloatBits(payload200) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload200).reinterpret_as_int64()) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - match ((payload195).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + Option::Some(lifted556) + } + _ => panic() + } - () - } - Some(payload202) => { - mbt_ffi_store8((iter_base) + 40, (1)) + let lifted559 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match payload202 { - Signed(payload203) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload203) + let result558 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Unsigned(payload204) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload204).reinterpret_as_int64()) + Option::Some(result558) + } + _ => panic() + } - () + Option::Some(@types.NumericRestrictions::{min : lifted555, max : lifted557, unit : lifted559}) + } + _ => panic() } - FloatBits(payload205) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload205).reinterpret_as_int64()) - () - } + @types.SchemaTypeBody::S64Type(lifted560) } + 6 => { - () - } - } - - match ((payload195).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let lifted567 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Some(payload207) => { - mbt_ffi_store8((iter_base) + 64, (1)) + let lifted562 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let ptr208 = mbt_ffi_str2ptr(payload207) - mbt_ffi_store32((iter_base) + 72, payload207.length()) - mbt_ffi_store32((iter_base) + 68, ptr208) - cleanup_list.push(ptr208) + let lifted561 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - } + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - } + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - F32Type(payload209) => { - mbt_ffi_store8((iter_base) + 0, (10)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - match (payload209) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + Option::Some(lifted561) + } + _ => panic() + } - () - } - Some(payload211) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let lifted564 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - match ((payload211).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let lifted563 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - Some(payload213) => { - mbt_ffi_store8((iter_base) + 16, (1)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - match payload213 { - Signed(payload214) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload214) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - Unsigned(payload215) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload215).reinterpret_as_int64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - FloatBits(payload216) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload216).reinterpret_as_int64()) + Option::Some(lifted563) + } + _ => panic() + } - () - } - } + let lifted566 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - } + let result565 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - match ((payload211).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + Option::Some(result565) + } + _ => panic() + } - () - } - Some(payload218) => { - mbt_ffi_store8((iter_base) + 40, (1)) + Option::Some(@types.NumericRestrictions::{min : lifted562, max : lifted564, unit : lifted566}) + } + _ => panic() + } - match payload218 { - Signed(payload219) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload219) + @types.SchemaTypeBody::U8Type(lifted567) + } + 7 => { - () - } - Unsigned(payload220) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload220).reinterpret_as_int64()) + let lifted574 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - FloatBits(payload221) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload221).reinterpret_as_int64()) + let lifted569 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - } + let lifted568 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - } + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - match ((payload211).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - Some(payload223) => { - mbt_ffi_store8((iter_base) + 64, (1)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - let ptr224 = mbt_ffi_str2ptr(payload223) - mbt_ffi_store32((iter_base) + 72, payload223.length()) - mbt_ffi_store32((iter_base) + 68, ptr224) - cleanup_list.push(ptr224) + Option::Some(lifted568) + } + _ => panic() + } - () - } - } + let lifted571 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - } + let lifted570 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - F64Type(payload225) => { - mbt_ffi_store8((iter_base) + 0, (11)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - match (payload225) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - Some(payload227) => { - mbt_ffi_store8((iter_base) + 8, (1)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - match ((payload227).min) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + Option::Some(lifted570) + } + _ => panic() + } - () - } - Some(payload229) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let lifted573 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match payload229 { - Signed(payload230) => { - mbt_ffi_store8((iter_base) + 24, (0)) - mbt_ffi_store64((iter_base) + 32, payload230) + let result572 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Unsigned(payload231) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload231).reinterpret_as_int64()) + Option::Some(result572) + } + _ => panic() + } - () + Option::Some(@types.NumericRestrictions::{min : lifted569, max : lifted571, unit : lifted573}) + } + _ => panic() } - FloatBits(payload232) => { - mbt_ffi_store8((iter_base) + 24, (2)) - mbt_ffi_store64((iter_base) + 32, (payload232).reinterpret_as_int64()) - () - } + @types.SchemaTypeBody::U16Type(lifted574) } + 8 => { - () - } - } + let lifted581 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - match ((payload227).max) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + let lifted576 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - Some(payload234) => { - mbt_ffi_store8((iter_base) + 40, (1)) + let lifted575 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - match payload234 { - Signed(payload235) => { - mbt_ffi_store8((iter_base) + 48, (0)) - mbt_ffi_store64((iter_base) + 56, payload235) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - Unsigned(payload236) => { - mbt_ffi_store8((iter_base) + 48, (1)) - mbt_ffi_store64((iter_base) + 56, (payload236).reinterpret_as_int64()) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - FloatBits(payload237) => { - mbt_ffi_store8((iter_base) + 48, (2)) - mbt_ffi_store64((iter_base) + 56, (payload237).reinterpret_as_int64()) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - } + Option::Some(lifted575) + } + _ => panic() + } - () - } - } + let lifted578 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - match ((payload227).unit) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let lifted577 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - Some(payload239) => { - mbt_ffi_store8((iter_base) + 64, (1)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - let ptr240 = mbt_ffi_str2ptr(payload239) - mbt_ffi_store32((iter_base) + 72, payload239.length()) - mbt_ffi_store32((iter_base) + 68, ptr240) - cleanup_list.push(ptr240) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - } + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - } + Option::Some(lifted577) + } + _ => panic() + } - () - } - CharType => { - mbt_ffi_store8((iter_base) + 0, (12)) + let lifted580 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - StringType => { - mbt_ffi_store8((iter_base) + 0, (13)) + let result579 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - RecordType(payload243) => { - mbt_ffi_store8((iter_base) + 0, (14)) + Option::Some(result579) + } + _ => panic() + } - let address264 = mbt_ffi_malloc((payload243).length() * 68); - for index265 = 0; index265 < (payload243).length(); index265 = index265 + 1 { - let iter_elem : @types.NamedFieldType = (payload243)[(index265)] - let iter_base = address264 + (index265 * 68); + Option::Some(@types.NumericRestrictions::{min : lifted576, max : lifted578, unit : lifted580}) + } + _ => panic() + } - let ptr244 = mbt_ffi_str2ptr((iter_elem).name) - mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) - mbt_ffi_store32((iter_base) + 0, ptr244) - mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + @types.SchemaTypeBody::U32Type(lifted581) + } + 9 => { - match (((iter_elem).metadata).doc) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + let lifted588 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Some(payload246) => { - mbt_ffi_store8((iter_base) + 12, (1)) + let lifted583 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let ptr247 = mbt_ffi_str2ptr(payload246) - mbt_ffi_store32((iter_base) + 20, payload246.length()) - mbt_ffi_store32((iter_base) + 16, ptr247) - cleanup_list.push(ptr247) + let lifted582 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - () - } - } + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let address249 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); - for index250 = 0; index250 < (((iter_elem).metadata).aliases).length(); index250 = index250 + 1 { - let iter_elem : String = (((iter_elem).metadata).aliases)[(index250)] - let iter_base = address249 + (index250 * 8); + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - let ptr248 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr248) - cleanup_list.push(ptr248) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 28, (((iter_elem).metadata).aliases).length()) - mbt_ffi_store32((iter_base) + 24, address249) + Option::Some(lifted582) + } + _ => panic() + } - let address252 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); - for index253 = 0; index253 < (((iter_elem).metadata).examples).length(); index253 = index253 + 1 { - let iter_elem : String = (((iter_elem).metadata).examples)[(index253)] - let iter_base = address252 + (index253 * 8); + let lifted585 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - let ptr251 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr251) - cleanup_list.push(ptr251) + let lifted584 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - } - mbt_ffi_store32((iter_base) + 36, (((iter_elem).metadata).examples).length()) - mbt_ffi_store32((iter_base) + 32, address252) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - match (((iter_elem).metadata).deprecated) { - None => { - mbt_ffi_store8((iter_base) + 40, (0)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - Some(payload255) => { - mbt_ffi_store8((iter_base) + 40, (1)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - let ptr256 = mbt_ffi_str2ptr(payload255) - mbt_ffi_store32((iter_base) + 48, payload255.length()) - mbt_ffi_store32((iter_base) + 44, ptr256) - cleanup_list.push(ptr256) + Option::Some(lifted584) + } + _ => panic() + } - () - } - } + let lifted587 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match (((iter_elem).metadata).role) { - None => { - mbt_ffi_store8((iter_base) + 52, (0)) + let result586 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Some(payload258) => { - mbt_ffi_store8((iter_base) + 52, (1)) + Option::Some(result586) + } + _ => panic() + } + + Option::Some(@types.NumericRestrictions::{min : lifted583, max : lifted585, unit : lifted587}) + } + _ => panic() + } + + @types.SchemaTypeBody::U64Type(lifted588) + } + 10 => { + + let lifted595 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { + + let lifted590 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { + + let lifted589 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - match payload258 { - Multimodal => { - mbt_ffi_store8((iter_base) + 56, (0)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - () - } - UnstructuredText => { - mbt_ffi_store8((iter_base) + 56, (1)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - () - } - UnstructuredBinary => { - mbt_ffi_store8((iter_base) + 56, (2)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - Other(payload262) => { - mbt_ffi_store8((iter_base) + 56, (3)) + Option::Some(lifted589) + } + _ => panic() + } - let ptr263 = mbt_ffi_str2ptr(payload262) - mbt_ffi_store32((iter_base) + 64, payload262.length()) - mbt_ffi_store32((iter_base) + 60, ptr263) - cleanup_list.push(ptr263) + let lifted592 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - () - } - } + let lifted591 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - () - } - } - cleanup_list.push(ptr244) - cleanup_list.push(address249) - cleanup_list.push(address252) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload243).length()) - mbt_ffi_store32((iter_base) + 8, address264) - cleanup_list.push(address264) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - () - } - VariantType(payload266) => { - mbt_ffi_store8((iter_base) + 0, (15)) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - let address289 = mbt_ffi_malloc((payload266).length() * 72); - for index290 = 0; index290 < (payload266).length(); index290 = index290 + 1 { - let iter_elem : @types.VariantCaseType = (payload266)[(index290)] - let iter_base = address289 + (index290 * 72); + Option::Some(lifted591) + } + _ => panic() + } - let ptr267 = mbt_ffi_str2ptr((iter_elem).name) - mbt_ffi_store32((iter_base) + 4, (iter_elem).name.length()) - mbt_ffi_store32((iter_base) + 0, ptr267) + let lifted594 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - match ((iter_elem).payload) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result593 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - () - } - Some(payload269) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload269) + Option::Some(result593) + } + _ => panic() + } - () - } - } + Option::Some(@types.NumericRestrictions::{min : lifted590, max : lifted592, unit : lifted594}) + } + _ => panic() + } - match (((iter_elem).metadata).doc) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + @types.SchemaTypeBody::F32Type(lifted595) + } + 11 => { - () - } - Some(payload271) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let lifted602 : @types.NumericRestrictions? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let ptr272 = mbt_ffi_str2ptr(payload271) - mbt_ffi_store32((iter_base) + 24, payload271.length()) - mbt_ffi_store32((iter_base) + 20, ptr272) - cleanup_list.push(ptr272) + let lifted597 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - } + let lifted596 = match (mbt_ffi_load8_u((iter_base) + 24)) { + 0 => { - let address274 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); - for index275 = 0; index275 < (((iter_elem).metadata).aliases).length(); index275 = index275 + 1 { - let iter_elem : String = (((iter_elem).metadata).aliases)[(index275)] - let iter_base = address274 + (index275 * 8); + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 32)) + } + 1 => { - let ptr273 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr273) - cleanup_list.push(ptr273) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + 2 => { - } - mbt_ffi_store32((iter_base) + 32, (((iter_elem).metadata).aliases).length()) - mbt_ffi_store32((iter_base) + 28, address274) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 32)).reinterpret_as_uint64()) + } + _ => panic() + } - let address277 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); - for index278 = 0; index278 < (((iter_elem).metadata).examples).length(); index278 = index278 + 1 { - let iter_elem : String = (((iter_elem).metadata).examples)[(index278)] - let iter_base = address277 + (index278 * 8); + Option::Some(lifted596) + } + _ => panic() + } - let ptr276 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr276) - cleanup_list.push(ptr276) + let lifted599 : @types.NumericBound? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 40, (((iter_elem).metadata).examples).length()) - mbt_ffi_store32((iter_base) + 36, address277) + let lifted598 = match (mbt_ffi_load8_u((iter_base) + 48)) { + 0 => { - match (((iter_elem).metadata).deprecated) { - None => { - mbt_ffi_store8((iter_base) + 44, (0)) + @types.NumericBound::Signed(mbt_ffi_load64((iter_base) + 56)) + } + 1 => { - () - } - Some(payload280) => { - mbt_ffi_store8((iter_base) + 44, (1)) + @types.NumericBound::Unsigned((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + 2 => { - let ptr281 = mbt_ffi_str2ptr(payload280) - mbt_ffi_store32((iter_base) + 52, payload280.length()) - mbt_ffi_store32((iter_base) + 48, ptr281) - cleanup_list.push(ptr281) + @types.NumericBound::FloatBits((mbt_ffi_load64((iter_base) + 56)).reinterpret_as_uint64()) + } + _ => panic() + } - () - } - } + Option::Some(lifted598) + } + _ => panic() + } - match (((iter_elem).metadata).role) { - None => { - mbt_ffi_store8((iter_base) + 56, (0)) + let lifted601 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - Some(payload283) => { - mbt_ffi_store8((iter_base) + 56, (1)) + let result600 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - match payload283 { - Multimodal => { - mbt_ffi_store8((iter_base) + 60, (0)) + Option::Some(result600) + } + _ => panic() + } - () + Option::Some(@types.NumericRestrictions::{min : lifted597, max : lifted599, unit : lifted601}) + } + _ => panic() + } + + @types.SchemaTypeBody::F64Type(lifted602) } - UnstructuredText => { - mbt_ffi_store8((iter_base) + 60, (1)) + 12 => { - () + @types.SchemaTypeBody::CharType } - UnstructuredBinary => { - mbt_ffi_store8((iter_base) + 60, (2)) + 13 => { - () + @types.SchemaTypeBody::StringType } - Other(payload287) => { - mbt_ffi_store8((iter_base) + 60, (3)) + 14 => { - let ptr288 = mbt_ffi_str2ptr(payload287) - mbt_ffi_store32((iter_base) + 68, payload287.length()) - mbt_ffi_store32((iter_base) + 64, ptr288) - cleanup_list.push(ptr288) + let array616 : Array[@types.NamedFieldType] = []; + for index617 = 0; index617 < (mbt_ffi_load32((iter_base) + 12)); index617 = index617 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index617 * 68) - () - } - } + let result603 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - } - cleanup_list.push(ptr267) - cleanup_list.push(address274) - cleanup_list.push(address277) + let lifted605 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload266).length()) - mbt_ffi_store32((iter_base) + 8, address289) - cleanup_list.push(address289) + let result604 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - () - } - EnumType(payload291) => { - mbt_ffi_store8((iter_base) + 0, (16)) + Option::Some(result604) + } + _ => panic() + } - let address293 = mbt_ffi_malloc((payload291).length() * 8); - for index294 = 0; index294 < (payload291).length(); index294 = index294 + 1 { - let iter_elem : String = (payload291)[(index294)] - let iter_base = address293 + (index294 * 8); + let array : Array[String] = []; + for index607 = 0; index607 < (mbt_ffi_load32((iter_base) + 28)); index607 = index607 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index607 * 8) - let ptr292 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr292) - cleanup_list.push(ptr292) + let result606 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - } - mbt_ffi_store32((iter_base) + 12, (payload291).length()) - mbt_ffi_store32((iter_base) + 8, address293) - cleanup_list.push(address293) + array.push(result606) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - () - } - FlagsType(payload295) => { - mbt_ffi_store8((iter_base) + 0, (17)) + let array609 : Array[String] = []; + for index610 = 0; index610 < (mbt_ffi_load32((iter_base) + 36)); index610 = index610 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 32)) + (index610 * 8) + + let result608 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let address297 = mbt_ffi_malloc((payload295).length() * 8); - for index298 = 0; index298 < (payload295).length(); index298 = index298 + 1 { - let iter_elem : String = (payload295)[(index298)] - let iter_base = address297 + (index298 * 8); + array609.push(result608) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 32)) - let ptr296 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr296) - cleanup_list.push(ptr296) + let lifted612 : String? = match mbt_ffi_load8_u((iter_base) + 40) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload295).length()) - mbt_ffi_store32((iter_base) + 8, address297) - cleanup_list.push(address297) + let result611 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - () - } - TupleType(payload299) => { - mbt_ffi_store8((iter_base) + 0, (18)) + Option::Some(result611) + } + _ => panic() + } - let address300 = mbt_ffi_malloc((payload299).length() * 4); - for index301 = 0; index301 < (payload299).length(); index301 = index301 + 1 { - let iter_elem : Int = (payload299)[(index301)] - let iter_base = address300 + (index301 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + let lifted615 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 52) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload299).length()) - mbt_ffi_store32((iter_base) + 8, address300) - cleanup_list.push(address300) + let lifted614 = match (mbt_ffi_load8_u((iter_base) + 56)) { + 0 => { - () - } - ListType(payload302) => { - mbt_ffi_store8((iter_base) + 0, (19)) - mbt_ffi_store32((iter_base) + 8, payload302) + @types.Role::Multimodal + } + 1 => { - () - } - FixedListType(payload303) => { - mbt_ffi_store8((iter_base) + 0, (20)) - mbt_ffi_store32((iter_base) + 8, (payload303).element) - mbt_ffi_store32((iter_base) + 12, ((payload303).length).reinterpret_as_int()) + @types.Role::UnstructuredText + } + 2 => { - () - } - MapType(payload304) => { - mbt_ffi_store8((iter_base) + 0, (21)) - mbt_ffi_store32((iter_base) + 8, (payload304).key) - mbt_ffi_store32((iter_base) + 12, (payload304).value) + @types.Role::UnstructuredBinary + } + 3 => { - () - } - OptionType(payload305) => { - mbt_ffi_store8((iter_base) + 0, (22)) - mbt_ffi_store32((iter_base) + 8, payload305) + let result613 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 60), mbt_ffi_load32((iter_base) + 64)) - () - } - ResultType(payload306) => { - mbt_ffi_store8((iter_base) + 0, (23)) + @types.Role::Other(result613) + } + _ => panic() + } - match ((payload306).ok) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + Option::Some(lifted614) + } + _ => panic() + } - () - } - Some(payload308) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload308) + array616.push(@types.NamedFieldType::{name : result603, body : mbt_ffi_load32((iter_base) + 8), metadata : @types.MetadataEnvelope::{doc : lifted605, aliases : array, examples : array609, deprecated : lifted612, role : lifted615}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - } + @types.SchemaTypeBody::RecordType(array616) + } + 15 => { - match ((payload306).err) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + let array633 : Array[@types.VariantCaseType] = []; + for index634 = 0; index634 < (mbt_ffi_load32((iter_base) + 12)); index634 = index634 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index634 * 72) - () - } - Some(payload310) => { - mbt_ffi_store8((iter_base) + 16, (1)) - mbt_ffi_store32((iter_base) + 20, payload310) + let result618 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - } + let lifted619 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - TextType(payload311) => { - mbt_ffi_store8((iter_base) + 0, (24)) + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - match ((payload311).languages) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let lifted621 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - Some(payload313) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let result620 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - let address315 = mbt_ffi_malloc((payload313).length() * 8); - for index316 = 0; index316 < (payload313).length(); index316 = index316 + 1 { - let iter_elem : String = (payload313)[(index316)] - let iter_base = address315 + (index316 * 8); + Option::Some(result620) + } + _ => panic() + } - let ptr314 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr314) - cleanup_list.push(ptr314) + let array623 : Array[String] = []; + for index624 = 0; index624 < (mbt_ffi_load32((iter_base) + 32)); index624 = index624 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index624 * 8) - } - mbt_ffi_store32((iter_base) + 16, (payload313).length()) - mbt_ffi_store32((iter_base) + 12, address315) - cleanup_list.push(address315) + let result622 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - } + array623.push(result622) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - match ((payload311).min_length) { - None => { - mbt_ffi_store8((iter_base) + 20, (0)) + let array626 : Array[String] = []; + for index627 = 0; index627 < (mbt_ffi_load32((iter_base) + 40)); index627 = index627 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 36)) + (index627 * 8) - () - } - Some(payload318) => { - mbt_ffi_store8((iter_base) + 20, (1)) - mbt_ffi_store32((iter_base) + 24, (payload318).reinterpret_as_int()) + let result625 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - } + array626.push(result625) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 36)) - match ((payload311).max_length) { - None => { - mbt_ffi_store8((iter_base) + 28, (0)) + let lifted629 : String? = match mbt_ffi_load8_u((iter_base) + 44) { + 0 => Option::None + 1 => { - () - } - Some(payload320) => { - mbt_ffi_store8((iter_base) + 28, (1)) - mbt_ffi_store32((iter_base) + 32, (payload320).reinterpret_as_int()) + let result628 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 48), mbt_ffi_load32((iter_base) + 52)) - () - } - } + Option::Some(result628) + } + _ => panic() + } - match ((payload311).regex) { - None => { - mbt_ffi_store8((iter_base) + 36, (0)) + let lifted632 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - () - } - Some(payload322) => { - mbt_ffi_store8((iter_base) + 36, (1)) + let lifted631 = match (mbt_ffi_load8_u((iter_base) + 60)) { + 0 => { - let ptr323 = mbt_ffi_str2ptr(payload322) - mbt_ffi_store32((iter_base) + 44, payload322.length()) - mbt_ffi_store32((iter_base) + 40, ptr323) - cleanup_list.push(ptr323) + @types.Role::Multimodal + } + 1 => { - () - } - } + @types.Role::UnstructuredText + } + 2 => { - () - } - BinaryType(payload324) => { - mbt_ffi_store8((iter_base) + 0, (25)) + @types.Role::UnstructuredBinary + } + 3 => { - match ((payload324).mime_types) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result630 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 64), mbt_ffi_load32((iter_base) + 68)) - () - } - Some(payload326) => { - mbt_ffi_store8((iter_base) + 8, (1)) + @types.Role::Other(result630) + } + _ => panic() + } - let address328 = mbt_ffi_malloc((payload326).length() * 8); - for index329 = 0; index329 < (payload326).length(); index329 = index329 + 1 { - let iter_elem : String = (payload326)[(index329)] - let iter_base = address328 + (index329 * 8); + Option::Some(lifted631) + } + _ => panic() + } - let ptr327 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr327) - cleanup_list.push(ptr327) + array633.push(@types.VariantCaseType::{name : result618, payload : lifted619, metadata : @types.MetadataEnvelope::{doc : lifted621, aliases : array623, examples : array626, deprecated : lifted629, role : lifted632}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - } - mbt_ffi_store32((iter_base) + 16, (payload326).length()) - mbt_ffi_store32((iter_base) + 12, address328) - cleanup_list.push(address328) + @types.SchemaTypeBody::VariantType(array633) + } + 16 => { - () - } - } + let array636 : Array[String] = []; + for index637 = 0; index637 < (mbt_ffi_load32((iter_base) + 12)); index637 = index637 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index637 * 8) - match ((payload324).min_bytes) { - None => { - mbt_ffi_store8((iter_base) + 20, (0)) + let result635 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - Some(payload331) => { - mbt_ffi_store8((iter_base) + 20, (1)) - mbt_ffi_store32((iter_base) + 24, (payload331).reinterpret_as_int()) + array636.push(result635) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - } + @types.SchemaTypeBody::EnumType(array636) + } + 17 => { - match ((payload324).max_bytes) { - None => { - mbt_ffi_store8((iter_base) + 28, (0)) + let array639 : Array[String] = []; + for index640 = 0; index640 < (mbt_ffi_load32((iter_base) + 12)); index640 = index640 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index640 * 8) - () - } - Some(payload333) => { - mbt_ffi_store8((iter_base) + 28, (1)) - mbt_ffi_store32((iter_base) + 32, (payload333).reinterpret_as_int()) + let result638 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array639.push(result638) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - } + @types.SchemaTypeBody::FlagsType(array639) + } + 18 => { - () - } - PathType(payload334) => { - mbt_ffi_store8((iter_base) + 0, (26)) - mbt_ffi_store8((iter_base) + 8, (payload334).direction.ordinal()) - mbt_ffi_store8((iter_base) + 9, (payload334).kind.ordinal()) + let array641 : Array[Int] = []; + for index642 = 0; index642 < (mbt_ffi_load32((iter_base) + 12)); index642 = index642 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index642 * 4) - match ((payload334).allowed_mime_types) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + array641.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - Some(payload336) => { - mbt_ffi_store8((iter_base) + 12, (1)) + @types.SchemaTypeBody::TupleType(array641) + } + 19 => { - let address338 = mbt_ffi_malloc((payload336).length() * 8); - for index339 = 0; index339 < (payload336).length(); index339 = index339 + 1 { - let iter_elem : String = (payload336)[(index339)] - let iter_base = address338 + (index339 * 8); + @types.SchemaTypeBody::ListType(mbt_ffi_load32((iter_base) + 8)) + } + 20 => { - let ptr337 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr337) - cleanup_list.push(ptr337) + @types.SchemaTypeBody::FixedListType(@types.FixedListSpec::{element : mbt_ffi_load32((iter_base) + 8), length : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}) + } + 21 => { - } - mbt_ffi_store32((iter_base) + 20, (payload336).length()) - mbt_ffi_store32((iter_base) + 16, address338) - cleanup_list.push(address338) + @types.SchemaTypeBody::MapType(@types.MapSpec::{key : mbt_ffi_load32((iter_base) + 8), value : mbt_ffi_load32((iter_base) + 12)}) + } + 22 => { - () - } - } + @types.SchemaTypeBody::OptionType(mbt_ffi_load32((iter_base) + 8)) + } + 23 => { - match ((payload334).allowed_extensions) { - None => { - mbt_ffi_store8((iter_base) + 24, (0)) + let lifted643 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Some(payload341) => { - mbt_ffi_store8((iter_base) + 24, (1)) + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - let address343 = mbt_ffi_malloc((payload341).length() * 8); - for index344 = 0; index344 < (payload341).length(); index344 = index344 + 1 { - let iter_elem : String = (payload341)[(index344)] - let iter_base = address343 + (index344 * 8); + let lifted644 : Int? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let ptr342 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr342) - cleanup_list.push(ptr342) + Option::Some(mbt_ffi_load32((iter_base) + 20)) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 32, (payload341).length()) - mbt_ffi_store32((iter_base) + 28, address343) - cleanup_list.push(address343) + @types.SchemaTypeBody::ResultType(@types.ResultSpec::{ok : lifted643, err : lifted644}) + } + 24 => { - () - } - } + let lifted648 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - UrlType(payload345) => { - mbt_ffi_store8((iter_base) + 0, (27)) + let array646 : Array[String] = []; + for index647 = 0; index647 < (mbt_ffi_load32((iter_base) + 16)); index647 = index647 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index647 * 8) - match ((payload345).allowed_schemes) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result645 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - Some(payload347) => { - mbt_ffi_store8((iter_base) + 8, (1)) + array646.push(result645) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - let address349 = mbt_ffi_malloc((payload347).length() * 8); - for index350 = 0; index350 < (payload347).length(); index350 = index350 + 1 { - let iter_elem : String = (payload347)[(index350)] - let iter_base = address349 + (index350 * 8); + Option::Some(array646) + } + _ => panic() + } - let ptr348 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr348) - cleanup_list.push(ptr348) + let lifted649 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 16, (payload347).length()) - mbt_ffi_store32((iter_base) + 12, address349) - cleanup_list.push(address349) + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - () - } - } + let lifted650 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { - match ((payload345).allowed_hosts) { - None => { - mbt_ffi_store8((iter_base) + 20, (0)) + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } - () - } - Some(payload352) => { - mbt_ffi_store8((iter_base) + 20, (1)) + let lifted652 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - let address354 = mbt_ffi_malloc((payload352).length() * 8); - for index355 = 0; index355 < (payload352).length(); index355 = index355 + 1 { - let iter_elem : String = (payload352)[(index355)] - let iter_base = address354 + (index355 * 8); + let result651 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - let ptr353 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr353) - cleanup_list.push(ptr353) + Option::Some(result651) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 28, (payload352).length()) - mbt_ffi_store32((iter_base) + 24, address354) - cleanup_list.push(address354) + @types.SchemaTypeBody::TextType(@types.TextRestrictions::{languages : lifted648, min_length : lifted649, max_length : lifted650, regex : lifted652}) + } + 25 => { - () - } - } + let lifted656 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - DatetimeType => { - mbt_ffi_store8((iter_base) + 0, (28)) + let array654 : Array[String] = []; + for index655 = 0; index655 < (mbt_ffi_load32((iter_base) + 16)); index655 = index655 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index655 * 8) - () - } - DurationType => { - mbt_ffi_store8((iter_base) + 0, (29)) + let result653 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - QuantityType(payload358) => { - mbt_ffi_store8((iter_base) + 0, (30)) + array654.push(result653) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - let ptr359 = mbt_ffi_str2ptr((payload358).base_unit) - mbt_ffi_store32((iter_base) + 12, (payload358).base_unit.length()) - mbt_ffi_store32((iter_base) + 8, ptr359) + Option::Some(array654) + } + _ => panic() + } - let address361 = mbt_ffi_malloc(((payload358).allowed_suffixes).length() * 8); - for index362 = 0; index362 < ((payload358).allowed_suffixes).length(); index362 = index362 + 1 { - let iter_elem : String = ((payload358).allowed_suffixes)[(index362)] - let iter_base = address361 + (index362 * 8); + let lifted657 : UInt? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let ptr360 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr360) - cleanup_list.push(ptr360) + Option::Some((mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 20, ((payload358).allowed_suffixes).length()) - mbt_ffi_store32((iter_base) + 16, address361) + let lifted658 : UInt? = match mbt_ffi_load8_u((iter_base) + 28) { + 0 => Option::None + 1 => { - match ((payload358).min) { - None => { - mbt_ffi_store8((iter_base) + 24, (0)) + Option::Some((mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint()) + } + _ => panic() + } - () - } - Some(payload364) => { - mbt_ffi_store8((iter_base) + 24, (1)) - mbt_ffi_store64((iter_base) + 32, (payload364).mantissa) - mbt_ffi_store32((iter_base) + 40, (payload364).scale) + @types.SchemaTypeBody::BinaryType(@types.BinaryRestrictions::{mime_types : lifted656, min_bytes : lifted657, max_bytes : lifted658}) + } + 26 => { - let ptr365 = mbt_ffi_str2ptr((payload364).unit) - mbt_ffi_store32((iter_base) + 48, (payload364).unit.length()) - mbt_ffi_store32((iter_base) + 44, ptr365) - cleanup_list.push(ptr365) + let lifted662 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - () - } - } + let array660 : Array[String] = []; + for index661 = 0; index661 < (mbt_ffi_load32((iter_base) + 20)); index661 = index661 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index661 * 8) - match ((payload358).max) { - None => { - mbt_ffi_store8((iter_base) + 56, (0)) + let result659 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - Some(payload367) => { - mbt_ffi_store8((iter_base) + 56, (1)) - mbt_ffi_store64((iter_base) + 64, (payload367).mantissa) - mbt_ffi_store32((iter_base) + 72, (payload367).scale) + array660.push(result659) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - let ptr368 = mbt_ffi_str2ptr((payload367).unit) - mbt_ffi_store32((iter_base) + 80, (payload367).unit.length()) - mbt_ffi_store32((iter_base) + 76, ptr368) - cleanup_list.push(ptr368) + Option::Some(array660) + } + _ => panic() + } - () - } - } - cleanup_list.push(ptr359) - cleanup_list.push(address361) + let lifted666 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - () - } - UnionType(payload369) => { - mbt_ffi_store8((iter_base) + 0, (31)) + let array664 : Array[String] = []; + for index665 = 0; index665 < (mbt_ffi_load32((iter_base) + 32)); index665 = index665 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 28)) + (index665 * 8) + + let result663 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let address405 = mbt_ffi_malloc(((payload369).branches).length() * 92); - for index406 = 0; index406 < ((payload369).branches).length(); index406 = index406 + 1 { - let iter_elem : @types.UnionBranch = ((payload369).branches)[(index406)] - let iter_base = address405 + (index406 * 92); + array664.push(result663) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 28)) - let ptr370 = mbt_ffi_str2ptr((iter_elem).tag) - mbt_ffi_store32((iter_base) + 4, (iter_elem).tag.length()) - mbt_ffi_store32((iter_base) + 0, ptr370) - mbt_ffi_store32((iter_base) + 8, (iter_elem).body) + Option::Some(array664) + } + _ => panic() + } - match (iter_elem).discriminator { - Prefix(payload371) => { - mbt_ffi_store8((iter_base) + 12, (0)) + @types.SchemaTypeBody::PathType(@types.PathSpec::{direction : @types.PathDirection::from(mbt_ffi_load8_u((iter_base) + 8)), kind : @types.PathKind::from(mbt_ffi_load8_u((iter_base) + 9)), allowed_mime_types : lifted662, allowed_extensions : lifted666}) + } + 27 => { - let ptr372 = mbt_ffi_str2ptr(payload371) - mbt_ffi_store32((iter_base) + 20, payload371.length()) - mbt_ffi_store32((iter_base) + 16, ptr372) - cleanup_list.push(ptr372) + let lifted670 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - Suffix(payload373) => { - mbt_ffi_store8((iter_base) + 12, (1)) + let array668 : Array[String] = []; + for index669 = 0; index669 < (mbt_ffi_load32((iter_base) + 16)); index669 = index669 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 12)) + (index669 * 8) - let ptr374 = mbt_ffi_str2ptr(payload373) - mbt_ffi_store32((iter_base) + 20, payload373.length()) - mbt_ffi_store32((iter_base) + 16, ptr374) - cleanup_list.push(ptr374) + let result667 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - Contains(payload375) => { - mbt_ffi_store8((iter_base) + 12, (2)) + array668.push(result667) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) - let ptr376 = mbt_ffi_str2ptr(payload375) - mbt_ffi_store32((iter_base) + 20, payload375.length()) - mbt_ffi_store32((iter_base) + 16, ptr376) - cleanup_list.push(ptr376) + Option::Some(array668) + } + _ => panic() + } - () - } - Regex(payload377) => { - mbt_ffi_store8((iter_base) + 12, (3)) + let lifted674 : Array[String]? = match mbt_ffi_load8_u((iter_base) + 20) { + 0 => Option::None + 1 => { - let ptr378 = mbt_ffi_str2ptr(payload377) - mbt_ffi_store32((iter_base) + 20, payload377.length()) - mbt_ffi_store32((iter_base) + 16, ptr378) - cleanup_list.push(ptr378) + let array672 : Array[String] = []; + for index673 = 0; index673 < (mbt_ffi_load32((iter_base) + 28)); index673 = index673 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 24)) + (index673 * 8) - () - } - FieldEquals(payload379) => { - mbt_ffi_store8((iter_base) + 12, (4)) + let result671 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let ptr380 = mbt_ffi_str2ptr((payload379).field_name) - mbt_ffi_store32((iter_base) + 20, (payload379).field_name.length()) - mbt_ffi_store32((iter_base) + 16, ptr380) + array672.push(result671) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - match ((payload379).literal) { - None => { - mbt_ffi_store8((iter_base) + 24, (0)) + Option::Some(array672) + } + _ => panic() + } - () + @types.SchemaTypeBody::UrlType(@types.UrlRestrictions::{allowed_schemes : lifted670, allowed_hosts : lifted674}) } - Some(payload382) => { - mbt_ffi_store8((iter_base) + 24, (1)) + 28 => { - let ptr383 = mbt_ffi_str2ptr(payload382) - mbt_ffi_store32((iter_base) + 32, payload382.length()) - mbt_ffi_store32((iter_base) + 28, ptr383) - cleanup_list.push(ptr383) + @types.SchemaTypeBody::DatetimeType + } + 29 => { - () + @types.SchemaTypeBody::DurationType } - } - cleanup_list.push(ptr380) + 30 => { - () - } - FieldAbsent(payload384) => { - mbt_ffi_store8((iter_base) + 12, (5)) + let result675 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let ptr385 = mbt_ffi_str2ptr(payload384) - mbt_ffi_store32((iter_base) + 20, payload384.length()) - mbt_ffi_store32((iter_base) + 16, ptr385) - cleanup_list.push(ptr385) + let array677 : Array[String] = []; + for index678 = 0; index678 < (mbt_ffi_load32((iter_base) + 20)); index678 = index678 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index678 * 8) - () - } - } + let result676 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - match (((iter_elem).metadata).doc) { - None => { - mbt_ffi_store8((iter_base) + 36, (0)) + array677.push(result676) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - () - } - Some(payload387) => { - mbt_ffi_store8((iter_base) + 36, (1)) + let lifted680 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - let ptr388 = mbt_ffi_str2ptr(payload387) - mbt_ffi_store32((iter_base) + 44, payload387.length()) - mbt_ffi_store32((iter_base) + 40, ptr388) - cleanup_list.push(ptr388) + let result679 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 44), mbt_ffi_load32((iter_base) + 48)) - () - } - } + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 32), scale : mbt_ffi_load32((iter_base) + 40), unit : result679}) + } + _ => panic() + } - let address390 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); - for index391 = 0; index391 < (((iter_elem).metadata).aliases).length(); index391 = index391 + 1 { - let iter_elem : String = (((iter_elem).metadata).aliases)[(index391)] - let iter_base = address390 + (index391 * 8); + let lifted682 : @types.QuantityValue? = match mbt_ffi_load8_u((iter_base) + 56) { + 0 => Option::None + 1 => { - let ptr389 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr389) - cleanup_list.push(ptr389) + let result681 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 76), mbt_ffi_load32((iter_base) + 80)) - } - mbt_ffi_store32((iter_base) + 52, (((iter_elem).metadata).aliases).length()) - mbt_ffi_store32((iter_base) + 48, address390) + Option::Some(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 64), scale : mbt_ffi_load32((iter_base) + 72), unit : result681}) + } + _ => panic() + } - let address393 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); - for index394 = 0; index394 < (((iter_elem).metadata).examples).length(); index394 = index394 + 1 { - let iter_elem : String = (((iter_elem).metadata).examples)[(index394)] - let iter_base = address393 + (index394 * 8); + @types.SchemaTypeBody::QuantityType(@types.QuantitySpec::{base_unit : result675, allowed_suffixes : array677, min : lifted680, max : lifted682}) + } + 31 => { - let ptr392 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr392) - cleanup_list.push(ptr392) + let array706 : Array[@types.UnionBranch] = []; + for index707 = 0; index707 < (mbt_ffi_load32((iter_base) + 12)); index707 = index707 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index707 * 92) - } - mbt_ffi_store32((iter_base) + 60, (((iter_elem).metadata).examples).length()) - mbt_ffi_store32((iter_base) + 56, address393) + let result683 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - match (((iter_elem).metadata).deprecated) { - None => { - mbt_ffi_store8((iter_base) + 64, (0)) + let lifted692 = match (mbt_ffi_load8_u((iter_base) + 12)) { + 0 => { - () - } - Some(payload396) => { - mbt_ffi_store8((iter_base) + 64, (1)) + let result684 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let ptr397 = mbt_ffi_str2ptr(payload396) - mbt_ffi_store32((iter_base) + 72, payload396.length()) - mbt_ffi_store32((iter_base) + 68, ptr397) - cleanup_list.push(ptr397) + @types.DiscriminatorRule::Prefix(result684) + } + 1 => { - () - } - } + let result685 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - match (((iter_elem).metadata).role) { - None => { - mbt_ffi_store8((iter_base) + 76, (0)) + @types.DiscriminatorRule::Suffix(result685) + } + 2 => { - () - } - Some(payload399) => { - mbt_ffi_store8((iter_base) + 76, (1)) + let result686 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - match payload399 { - Multimodal => { - mbt_ffi_store8((iter_base) + 80, (0)) + @types.DiscriminatorRule::Contains(result686) + } + 3 => { - () - } - UnstructuredText => { - mbt_ffi_store8((iter_base) + 80, (1)) + let result687 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - () - } - UnstructuredBinary => { - mbt_ffi_store8((iter_base) + 80, (2)) + @types.DiscriminatorRule::Regex(result687) + } + 4 => { - () - } - Other(payload403) => { - mbt_ffi_store8((iter_base) + 80, (3)) + let result688 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - let ptr404 = mbt_ffi_str2ptr(payload403) - mbt_ffi_store32((iter_base) + 88, payload403.length()) - mbt_ffi_store32((iter_base) + 84, ptr404) - cleanup_list.push(ptr404) + let lifted690 : String? = match mbt_ffi_load8_u((iter_base) + 24) { + 0 => Option::None + 1 => { - () - } - } + let result689 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 28), mbt_ffi_load32((iter_base) + 32)) - () - } - } - cleanup_list.push(ptr370) - cleanup_list.push(address390) - cleanup_list.push(address393) + Option::Some(result689) + } + _ => panic() + } - } - mbt_ffi_store32((iter_base) + 12, ((payload369).branches).length()) - mbt_ffi_store32((iter_base) + 8, address405) - cleanup_list.push(address405) + @types.DiscriminatorRule::FieldEquals(@types.FieldDiscriminator::{field_name : result688, literal : lifted690}) + } + 5 => { - () - } - SecretType(payload407) => { - mbt_ffi_store8((iter_base) + 0, (32)) - mbt_ffi_store32((iter_base) + 8, (payload407).inner) + let result691 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - match ((payload407).category) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + @types.DiscriminatorRule::FieldAbsent(result691) + } + _ => panic() + } - () - } - Some(payload409) => { - mbt_ffi_store8((iter_base) + 12, (1)) + let lifted694 : String? = match mbt_ffi_load8_u((iter_base) + 36) { + 0 => Option::None + 1 => { - let ptr410 = mbt_ffi_str2ptr(payload409) - mbt_ffi_store32((iter_base) + 20, payload409.length()) - mbt_ffi_store32((iter_base) + 16, ptr410) - cleanup_list.push(ptr410) + let result693 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 40), mbt_ffi_load32((iter_base) + 44)) - () - } - } + Option::Some(result693) + } + _ => panic() + } + + let array696 : Array[String] = []; + for index697 = 0; index697 < (mbt_ffi_load32((iter_base) + 52)); index697 = index697 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 48)) + (index697 * 8) + + let result695 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array696.push(result695) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 48)) + + let array699 : Array[String] = []; + for index700 = 0; index700 < (mbt_ffi_load32((iter_base) + 60)); index700 = index700 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 56)) + (index700 * 8) + + let result698 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) + + array699.push(result698) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 56)) + + let lifted702 : String? = match mbt_ffi_load8_u((iter_base) + 64) { + 0 => Option::None + 1 => { - () - } - QuotaTokenType(payload411) => { - mbt_ffi_store8((iter_base) + 0, (33)) + let result701 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 68), mbt_ffi_load32((iter_base) + 72)) - match ((payload411).resource_name) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + Option::Some(result701) + } + _ => panic() + } - () - } - Some(payload413) => { - mbt_ffi_store8((iter_base) + 8, (1)) + let lifted705 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 76) { + 0 => Option::None + 1 => { - let ptr414 = mbt_ffi_str2ptr(payload413) - mbt_ffi_store32((iter_base) + 16, payload413.length()) - mbt_ffi_store32((iter_base) + 12, ptr414) - cleanup_list.push(ptr414) + let lifted704 = match (mbt_ffi_load8_u((iter_base) + 80)) { + 0 => { - () - } - } + @types.Role::Multimodal + } + 1 => { - () - } - PermissionCardType(payload415) => { - mbt_ffi_store8((iter_base) + 0, (34)) - mbt_ffi_store8((iter_base) + 8, (if (payload415).polymorphic { 1 } else { 0 })) + @types.Role::UnstructuredText + } + 2 => { - () - } - FutureType(payload416) => { - mbt_ffi_store8((iter_base) + 0, (35)) + @types.Role::UnstructuredBinary + } + 3 => { - match (payload416) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + let result703 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 84), mbt_ffi_load32((iter_base) + 88)) - () - } - Some(payload418) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload418) + @types.Role::Other(result703) + } + _ => panic() + } - () - } - } + Option::Some(lifted704) + } + _ => panic() + } - () - } - StreamType(payload419) => { - mbt_ffi_store8((iter_base) + 0, (36)) + array706.push(@types.UnionBranch::{tag : result683, body : mbt_ffi_load32((iter_base) + 8), discriminator : lifted692, metadata : @types.MetadataEnvelope::{doc : lifted694, aliases : array696, examples : array699, deprecated : lifted702, role : lifted705}}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - match (payload419) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + @types.SchemaTypeBody::UnionType(@types.UnionSpec::{branches : array706}) + } + 32 => { - () - } - Some(payload421) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload421) + let lifted709 : String? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - () - } - } + let result708 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20)) - () - } - } + Option::Some(result708) + } + _ => panic() + } - match (((iter_elem).metadata).doc) { - None => { - mbt_ffi_store8((iter_base) + 88, (0)) + @types.SchemaTypeBody::SecretType(@types.SecretSpec::{inner : mbt_ffi_load32((iter_base) + 8), category : lifted709}) + } + 33 => { - () - } - Some(payload423) => { - mbt_ffi_store8((iter_base) + 88, (1)) + let lifted711 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let ptr424 = mbt_ffi_str2ptr(payload423) - mbt_ffi_store32((iter_base) + 96, payload423.length()) - mbt_ffi_store32((iter_base) + 92, ptr424) - cleanup_list.push(ptr424) + let result710 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - () - } - } + Option::Some(result710) + } + _ => panic() + } - let address426 = mbt_ffi_malloc((((iter_elem).metadata).aliases).length() * 8); - for index427 = 0; index427 < (((iter_elem).metadata).aliases).length(); index427 = index427 + 1 { - let iter_elem : String = (((iter_elem).metadata).aliases)[(index427)] - let iter_base = address426 + (index427 * 8); + @types.SchemaTypeBody::QuotaTokenType(@types.QuotaTokenSpec::{resource_name : lifted711}) + } + 34 => { - let ptr425 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr425) - cleanup_list.push(ptr425) + @types.SchemaTypeBody::PermissionCardType(@types.PermissionCardSpec::{polymorphic : (mbt_ffi_load8_u((iter_base) + 8) != 0)}) + } + 35 => { - } - mbt_ffi_store32((iter_base) + 104, (((iter_elem).metadata).aliases).length()) - mbt_ffi_store32((iter_base) + 100, address426) + let lifted712 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - let address429 = mbt_ffi_malloc((((iter_elem).metadata).examples).length() * 8); - for index430 = 0; index430 < (((iter_elem).metadata).examples).length(); index430 = index430 + 1 { - let iter_elem : String = (((iter_elem).metadata).examples)[(index430)] - let iter_base = address429 + (index430 * 8); + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - let ptr428 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr428) - cleanup_list.push(ptr428) + @types.SchemaTypeBody::FutureType(lifted712) + } + 36 => { - } - mbt_ffi_store32((iter_base) + 112, (((iter_elem).metadata).examples).length()) - mbt_ffi_store32((iter_base) + 108, address429) + let lifted713 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - match (((iter_elem).metadata).deprecated) { - None => { - mbt_ffi_store8((iter_base) + 116, (0)) + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - () - } - Some(payload432) => { - mbt_ffi_store8((iter_base) + 116, (1)) + @types.SchemaTypeBody::StreamType(lifted713) + } + _ => panic() + } - let ptr433 = mbt_ffi_str2ptr(payload432) - mbt_ffi_store32((iter_base) + 124, payload432.length()) - mbt_ffi_store32((iter_base) + 120, ptr433) - cleanup_list.push(ptr433) + let lifted716 : String? = match mbt_ffi_load8_u((iter_base) + 88) { + 0 => Option::None + 1 => { - () - } - } + let result715 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 92), mbt_ffi_load32((iter_base) + 96)) - match (((iter_elem).metadata).role) { - None => { - mbt_ffi_store8((iter_base) + 128, (0)) + Option::Some(result715) + } + _ => panic() + } - () - } - Some(payload435) => { - mbt_ffi_store8((iter_base) + 128, (1)) + let array718 : Array[String] = []; + for index719 = 0; index719 < (mbt_ffi_load32((iter_base) + 104)); index719 = index719 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 100)) + (index719 * 8) - match payload435 { - Multimodal => { - mbt_ffi_store8((iter_base) + 132, (0)) + let result717 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - UnstructuredText => { - mbt_ffi_store8((iter_base) + 132, (1)) + array718.push(result717) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 100)) - () - } - UnstructuredBinary => { - mbt_ffi_store8((iter_base) + 132, (2)) + let array721 : Array[String] = []; + for index722 = 0; index722 < (mbt_ffi_load32((iter_base) + 112)); index722 = index722 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 108)) + (index722 * 8) - () - } - Other(payload439) => { - mbt_ffi_store8((iter_base) + 132, (3)) + let result720 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - let ptr440 = mbt_ffi_str2ptr(payload439) - mbt_ffi_store32((iter_base) + 140, payload439.length()) - mbt_ffi_store32((iter_base) + 136, ptr440) - cleanup_list.push(ptr440) + array721.push(result720) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 108)) - () - } - } + let lifted724 : String? = match mbt_ffi_load8_u((iter_base) + 116) { + 0 => Option::None + 1 => { - () - } - } - cleanup_list.push(address426) - cleanup_list.push(address429) + let result723 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 120), mbt_ffi_load32((iter_base) + 124)) - } - mbt_ffi_store32((iter_base) + 12, ((((iter_elem).value).graph).type_nodes).length()) - mbt_ffi_store32((iter_base) + 8, address441) + Option::Some(result723) + } + _ => panic() + } - let address447 = mbt_ffi_malloc(((((iter_elem).value).graph).defs).length() * 24); - for index448 = 0; index448 < ((((iter_elem).value).graph).defs).length(); index448 = index448 + 1 { - let iter_elem : @types.SchemaTypeDef = ((((iter_elem).value).graph).defs)[(index448)] - let iter_base = address447 + (index448 * 24); + let lifted727 : @types.Role? = match mbt_ffi_load8_u((iter_base) + 128) { + 0 => Option::None + 1 => { - let ptr443 = mbt_ffi_str2ptr((iter_elem).id) - mbt_ffi_store32((iter_base) + 4, (iter_elem).id.length()) - mbt_ffi_store32((iter_base) + 0, ptr443) + let lifted726 = match (mbt_ffi_load8_u((iter_base) + 132)) { + 0 => { - match ((iter_elem).name) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + @types.Role::Multimodal + } + 1 => { - () - } - Some(payload445) => { - mbt_ffi_store8((iter_base) + 8, (1)) + @types.Role::UnstructuredText + } + 2 => { - let ptr446 = mbt_ffi_str2ptr(payload445) - mbt_ffi_store32((iter_base) + 16, payload445.length()) - mbt_ffi_store32((iter_base) + 12, ptr446) - cleanup_list.push(ptr446) + @types.Role::UnstructuredBinary + } + 3 => { - () - } - } - mbt_ffi_store32((iter_base) + 20, (iter_elem).body) - cleanup_list.push(ptr443) + let result725 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 136), mbt_ffi_load32((iter_base) + 140)) - } - mbt_ffi_store32((iter_base) + 20, ((((iter_elem).value).graph).defs).length()) - mbt_ffi_store32((iter_base) + 16, address447) - mbt_ffi_store32((iter_base) + 24, (((iter_elem).value).graph).root) + @types.Role::Other(result725) + } + _ => panic() + } - let address523 = mbt_ffi_malloc(((((iter_elem).value).value).value_nodes).length() * 32); - for index524 = 0; index524 < ((((iter_elem).value).value).value_nodes).length(); index524 = index524 + 1 { - let iter_elem : @types.SchemaValueNode = ((((iter_elem).value).value).value_nodes)[(index524)] - let iter_base = address523 + (index524 * 32); + Option::Some(lifted726) + } + _ => panic() + } - match iter_elem { - BoolValue(payload449) => { - mbt_ffi_store8((iter_base) + 0, (0)) - mbt_ffi_store8((iter_base) + 8, (if payload449 { 1 } else { 0 })) + array728.push(@types.SchemaTypeNode::{body : lifted714, metadata : @types.MetadataEnvelope::{doc : lifted716, aliases : array718, examples : array721, deprecated : lifted724, role : lifted727}}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 12)) - () - } - S8Value(payload450) => { - mbt_ffi_store8((iter_base) + 0, (1)) - mbt_ffi_store8((iter_base) + 8, mbt_ffi_extend8(payload450)) + let array733 : Array[@types.SchemaTypeDef] = []; + for index734 = 0; index734 < (mbt_ffi_load32((return_area) + 24)); index734 = index734 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 20)) + (index734 * 24) - () - } - S16Value(payload451) => { - mbt_ffi_store8((iter_base) + 0, (2)) - mbt_ffi_store16((iter_base) + 8, mbt_ffi_extend16(payload451)) + let result730 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4)) - () - } - S32Value(payload452) => { - mbt_ffi_store8((iter_base) + 0, (3)) - mbt_ffi_store32((iter_base) + 8, payload452) + let lifted732 : String? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - S64Value(payload453) => { - mbt_ffi_store8((iter_base) + 0, (4)) - mbt_ffi_store64((iter_base) + 8, payload453) + let result731 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16)) - () - } - U8Value(payload454) => { - mbt_ffi_store8((iter_base) + 0, (5)) - mbt_ffi_store8((iter_base) + 8, (payload454).to_int()) + Option::Some(result731) + } + _ => panic() + } - () - } - U16Value(payload455) => { - mbt_ffi_store8((iter_base) + 0, (6)) - mbt_ffi_store16((iter_base) + 8, (payload455).reinterpret_as_int()) + array733.push(@types.SchemaTypeDef::{id : result730, name : lifted732, body : mbt_ffi_load32((iter_base) + 20)}) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 20)) - () - } - U32Value(payload456) => { - mbt_ffi_store8((iter_base) + 0, (7)) - mbt_ffi_store32((iter_base) + 8, (payload456).reinterpret_as_int()) + let array764 : Array[@types.SchemaValueNode] = []; + for index765 = 0; index765 < (mbt_ffi_load32((return_area) + 36)); index765 = index765 + 1 { + let iter_base = (mbt_ffi_load32((return_area) + 32)) + (index765 * 32) - () - } - U64Value(payload457) => { - mbt_ffi_store8((iter_base) + 0, (8)) - mbt_ffi_store64((iter_base) + 8, (payload457).reinterpret_as_int64()) + let lifted763 = match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => { - () - } - F32Value(payload458) => { - mbt_ffi_store8((iter_base) + 0, (9)) - mbt_ffi_storef32((iter_base) + 8, payload458) + @types.SchemaValueNode::BoolValue((mbt_ffi_load8_u((iter_base) + 8) != 0)) + } + 1 => { - () - } - F64Value(payload459) => { - mbt_ffi_store8((iter_base) + 0, (10)) - mbt_ffi_storef64((iter_base) + 8, payload459) + @types.SchemaValueNode::S8Value((mbt_ffi_load8((iter_base) + 8))) + } + 2 => { - () - } - CharValue(payload460) => { - mbt_ffi_store8((iter_base) + 0, (11)) - mbt_ffi_store32((iter_base) + 8, (payload460).to_int()) + @types.SchemaValueNode::S16Value((mbt_ffi_load16((iter_base) + 8))) + } + 3 => { - () - } - StringValue(payload461) => { - mbt_ffi_store8((iter_base) + 0, (12)) + @types.SchemaValueNode::S32Value(mbt_ffi_load32((iter_base) + 8)) + } + 4 => { - let ptr462 = mbt_ffi_str2ptr(payload461) - mbt_ffi_store32((iter_base) + 12, payload461.length()) - mbt_ffi_store32((iter_base) + 8, ptr462) - cleanup_list.push(ptr462) + @types.SchemaValueNode::S64Value(mbt_ffi_load64((iter_base) + 8)) + } + 5 => { - () - } - RecordValue(payload463) => { - mbt_ffi_store8((iter_base) + 0, (13)) + @types.SchemaValueNode::U8Value((mbt_ffi_load8_u((iter_base) + 8)).to_byte()) + } + 6 => { - let address464 = mbt_ffi_malloc((payload463).length() * 4); - for index465 = 0; index465 < (payload463).length(); index465 = index465 + 1 { - let iter_elem : Int = (payload463)[(index465)] - let iter_base = address464 + (index465 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + @types.SchemaValueNode::U16Value((mbt_ffi_load16_u((iter_base) + 8).land(0xFFFF).reinterpret_as_uint())) + } + 7 => { - } - mbt_ffi_store32((iter_base) + 12, (payload463).length()) - mbt_ffi_store32((iter_base) + 8, address464) - cleanup_list.push(address464) + @types.SchemaValueNode::U32Value((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 8 => { - () - } - VariantValue(payload466) => { - mbt_ffi_store8((iter_base) + 0, (14)) - mbt_ffi_store32((iter_base) + 8, ((payload466).case).reinterpret_as_int()) + @types.SchemaValueNode::U64Value((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64()) + } + 9 => { - match ((payload466).payload) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + @types.SchemaValueNode::F32Value(mbt_ffi_loadf32((iter_base) + 8)) + } + 10 => { - () - } - Some(payload468) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload468) + @types.SchemaValueNode::F64Value(mbt_ffi_loadf64((iter_base) + 8)) + } + 11 => { - () - } - } + @types.SchemaValueNode::CharValue(Int::unsafe_to_char(mbt_ffi_load32((iter_base) + 8))) + } + 12 => { - () - } - EnumValue(payload469) => { - mbt_ffi_store8((iter_base) + 0, (15)) - mbt_ffi_store32((iter_base) + 8, (payload469).reinterpret_as_int()) + let result735 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - () - } - FlagsValue(payload470) => { - mbt_ffi_store8((iter_base) + 0, (16)) + @types.SchemaValueNode::StringValue(result735) + } + 13 => { - let address471 = mbt_ffi_malloc((payload470).length() * 1); - for index472 = 0; index472 < (payload470).length(); index472 = index472 + 1 { - let iter_elem : Bool = (payload470)[(index472)] - let iter_base = address471 + (index472 * 1); - mbt_ffi_store8((iter_base) + 0, (if iter_elem { 1 } else { 0 })) + let array736 : Array[Int] = []; + for index737 = 0; index737 < (mbt_ffi_load32((iter_base) + 12)); index737 = index737 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index737 * 4) - } - mbt_ffi_store32((iter_base) + 12, (payload470).length()) - mbt_ffi_store32((iter_base) + 8, address471) - cleanup_list.push(address471) + array736.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - TupleValue(payload473) => { - mbt_ffi_store8((iter_base) + 0, (17)) + @types.SchemaValueNode::RecordValue(array736) + } + 14 => { - let address474 = mbt_ffi_malloc((payload473).length() * 4); - for index475 = 0; index475 < (payload473).length(); index475 = index475 + 1 { - let iter_elem : Int = (payload473)[(index475)] - let iter_base = address474 + (index475 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + let lifted738 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - } - mbt_ffi_store32((iter_base) + 12, (payload473).length()) - mbt_ffi_store32((iter_base) + 8, address474) - cleanup_list.push(address474) + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } - () - } - ListValue(payload476) => { - mbt_ffi_store8((iter_base) + 0, (18)) + @types.SchemaValueNode::VariantValue(@types.VariantValuePayload::{case : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), payload : lifted738}) + } + 15 => { - let address477 = mbt_ffi_malloc((payload476).length() * 4); - for index478 = 0; index478 < (payload476).length(); index478 = index478 + 1 { - let iter_elem : Int = (payload476)[(index478)] - let iter_base = address477 + (index478 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + @types.SchemaValueNode::EnumValue((mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint()) + } + 16 => { - } - mbt_ffi_store32((iter_base) + 12, (payload476).length()) - mbt_ffi_store32((iter_base) + 8, address477) - cleanup_list.push(address477) + let array739 : Array[Bool] = []; + for index740 = 0; index740 < (mbt_ffi_load32((iter_base) + 12)); index740 = index740 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index740 * 1) - () - } - FixedListValue(payload479) => { - mbt_ffi_store8((iter_base) + 0, (19)) + array739.push((mbt_ffi_load8_u((iter_base) + 0) != 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let address480 = mbt_ffi_malloc((payload479).length() * 4); - for index481 = 0; index481 < (payload479).length(); index481 = index481 + 1 { - let iter_elem : Int = (payload479)[(index481)] - let iter_base = address480 + (index481 * 4); - mbt_ffi_store32((iter_base) + 0, iter_elem) + @types.SchemaValueNode::FlagsValue(array739) + } + 17 => { - } - mbt_ffi_store32((iter_base) + 12, (payload479).length()) - mbt_ffi_store32((iter_base) + 8, address480) - cleanup_list.push(address480) + let array741 : Array[Int] = []; + for index742 = 0; index742 < (mbt_ffi_load32((iter_base) + 12)); index742 = index742 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index742 * 4) - () - } - MapValue(payload482) => { - mbt_ffi_store8((iter_base) + 0, (20)) + array741.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - let address483 = mbt_ffi_malloc((payload482).length() * 8); - for index484 = 0; index484 < (payload482).length(); index484 = index484 + 1 { - let iter_elem : @types.MapEntry = (payload482)[(index484)] - let iter_base = address483 + (index484 * 8); - mbt_ffi_store32((iter_base) + 0, (iter_elem).key) - mbt_ffi_store32((iter_base) + 4, (iter_elem).value) + @types.SchemaValueNode::TupleValue(array741) + } + 18 => { - } - mbt_ffi_store32((iter_base) + 12, (payload482).length()) - mbt_ffi_store32((iter_base) + 8, address483) - cleanup_list.push(address483) + let array743 : Array[Int] = []; + for index744 = 0; index744 < (mbt_ffi_load32((iter_base) + 12)); index744 = index744 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index744 * 4) - () - } - OptionValue(payload485) => { - mbt_ffi_store8((iter_base) + 0, (21)) + array743.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - match (payload485) { - None => { - mbt_ffi_store8((iter_base) + 8, (0)) + @types.SchemaValueNode::ListValue(array743) + } + 19 => { - () - } - Some(payload487) => { - mbt_ffi_store8((iter_base) + 8, (1)) - mbt_ffi_store32((iter_base) + 12, payload487) + let array745 : Array[Int] = []; + for index746 = 0; index746 < (mbt_ffi_load32((iter_base) + 12)); index746 = index746 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index746 * 4) - () - } - } + array745.push(mbt_ffi_load32((iter_base) + 0)) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - ResultValue(payload488) => { - mbt_ffi_store8((iter_base) + 0, (22)) + @types.SchemaValueNode::FixedListValue(array745) + } + 20 => { - match payload488 { - OkValue(payload489) => { - mbt_ffi_store8((iter_base) + 8, (0)) + let array747 : Array[@types.MapEntry] = []; + for index748 = 0; index748 < (mbt_ffi_load32((iter_base) + 12)); index748 = index748 + 1 { + let iter_base = (mbt_ffi_load32((iter_base) + 8)) + (index748 * 8) - match (payload489) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + array747.push(@types.MapEntry::{key : mbt_ffi_load32((iter_base) + 0), value : mbt_ffi_load32((iter_base) + 4)}) + } + mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - () - } - Some(payload491) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload491) + @types.SchemaValueNode::MapValue(array747) + } + 21 => { - () - } - } + let lifted749 : Int? = match mbt_ffi_load8_u((iter_base) + 8) { + 0 => Option::None + 1 => { - () - } - ErrValue(payload492) => { - mbt_ffi_store8((iter_base) + 8, (1)) + Option::Some(mbt_ffi_load32((iter_base) + 12)) + } + _ => panic() + } - match (payload492) { - None => { - mbt_ffi_store8((iter_base) + 12, (0)) + @types.SchemaValueNode::OptionValue(lifted749) + } + 22 => { - () - } - Some(payload494) => { - mbt_ffi_store8((iter_base) + 12, (1)) - mbt_ffi_store32((iter_base) + 16, payload494) + let lifted752 = match (mbt_ffi_load8_u((iter_base) + 8)) { + 0 => { - () - } - } + let lifted750 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - () - } - } + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } - () - } - TextValue(payload495) => { - mbt_ffi_store8((iter_base) + 0, (23)) + @types.ResultValuePayload::OkValue(lifted750) + } + 1 => { - let ptr496 = mbt_ffi_str2ptr((payload495).text) - mbt_ffi_store32((iter_base) + 12, (payload495).text.length()) - mbt_ffi_store32((iter_base) + 8, ptr496) + let lifted751 : Int? = match mbt_ffi_load8_u((iter_base) + 12) { + 0 => Option::None + 1 => { - match ((payload495).language) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + Option::Some(mbt_ffi_load32((iter_base) + 16)) + } + _ => panic() + } - () - } - Some(payload498) => { - mbt_ffi_store8((iter_base) + 16, (1)) + @types.ResultValuePayload::ErrValue(lifted751) + } + _ => panic() + } - let ptr499 = mbt_ffi_str2ptr(payload498) - mbt_ffi_store32((iter_base) + 24, payload498.length()) - mbt_ffi_store32((iter_base) + 20, ptr499) - cleanup_list.push(ptr499) + @types.SchemaValueNode::ResultValue(lifted752) + } + 23 => { - () - } - } - cleanup_list.push(ptr496) + let result753 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - () - } - BinaryValue(payload500) => { - mbt_ffi_store8((iter_base) + 0, (24)) + let lifted755 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - let ptr501 = mbt_ffi_bytes2ptr((payload500).bytes) + let result754 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - mbt_ffi_store32((iter_base) + 12, (payload500).bytes.length()) - mbt_ffi_store32((iter_base) + 8, ptr501) + Option::Some(result754) + } + _ => panic() + } - match ((payload500).mime_type) { - None => { - mbt_ffi_store8((iter_base) + 16, (0)) + @types.SchemaValueNode::TextValue(@types.TextValuePayload::{text : result753, language : lifted755}) + } + 24 => { - () - } - Some(payload503) => { - mbt_ffi_store8((iter_base) + 16, (1)) + let result756 = mbt_ffi_ptr2bytes(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let ptr504 = mbt_ffi_str2ptr(payload503) - mbt_ffi_store32((iter_base) + 24, payload503.length()) - mbt_ffi_store32((iter_base) + 20, ptr504) - cleanup_list.push(ptr504) + let lifted758 : String? = match mbt_ffi_load8_u((iter_base) + 16) { + 0 => Option::None + 1 => { - () - } - } - cleanup_list.push(ptr501) + let result757 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - () - } - PathValue(payload505) => { - mbt_ffi_store8((iter_base) + 0, (25)) + Option::Some(result757) + } + _ => panic() + } - let ptr506 = mbt_ffi_str2ptr(payload505) - mbt_ffi_store32((iter_base) + 12, payload505.length()) - mbt_ffi_store32((iter_base) + 8, ptr506) - cleanup_list.push(ptr506) + @types.SchemaValueNode::BinaryValue(@types.BinaryValuePayload::{bytes : result756, mime_type : lifted758}) + } + 25 => { - () - } - UrlValue(payload507) => { - mbt_ffi_store8((iter_base) + 0, (26)) + let result759 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let ptr508 = mbt_ffi_str2ptr(payload507) - mbt_ffi_store32((iter_base) + 12, payload507.length()) - mbt_ffi_store32((iter_base) + 8, ptr508) - cleanup_list.push(ptr508) + @types.SchemaValueNode::PathValue(result759) + } + 26 => { - () - } - DatetimeValue(payload509) => { - mbt_ffi_store8((iter_base) + 0, (27)) - mbt_ffi_store64((iter_base) + 8, (payload509).seconds) - mbt_ffi_store32((iter_base) + 16, ((payload509).nanoseconds).reinterpret_as_int()) + let result760 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - () - } - DurationValue(payload510) => { - mbt_ffi_store8((iter_base) + 0, (28)) - mbt_ffi_store64((iter_base) + 8, (payload510).nanoseconds) + @types.SchemaValueNode::UrlValue(result760) + } + 27 => { - () - } - QuantityValueNode(payload511) => { - mbt_ffi_store8((iter_base) + 0, (29)) - mbt_ffi_store64((iter_base) + 8, (payload511).mantissa) - mbt_ffi_store32((iter_base) + 16, (payload511).scale) + @types.SchemaValueNode::DatetimeValue(@types.Datetime::{seconds : mbt_ffi_load64((iter_base) + 8), nanoseconds : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}) + } + 28 => { - let ptr512 = mbt_ffi_str2ptr((payload511).unit) - mbt_ffi_store32((iter_base) + 24, (payload511).unit.length()) - mbt_ffi_store32((iter_base) + 20, ptr512) - cleanup_list.push(ptr512) + @types.SchemaValueNode::DurationValue(@types.DurationValuePayload::{nanoseconds : mbt_ffi_load64((iter_base) + 8)}) + } + 29 => { - () - } - UnionValue(payload513) => { - mbt_ffi_store8((iter_base) + 0, (30)) + let result761 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 20), mbt_ffi_load32((iter_base) + 24)) - let ptr514 = mbt_ffi_str2ptr((payload513).tag) - mbt_ffi_store32((iter_base) + 12, (payload513).tag.length()) - mbt_ffi_store32((iter_base) + 8, ptr514) - mbt_ffi_store32((iter_base) + 16, (payload513).body) - cleanup_list.push(ptr514) + @types.SchemaValueNode::QuantityValueNode(@types.QuantityValue::{mantissa : mbt_ffi_load64((iter_base) + 8), scale : mbt_ffi_load32((iter_base) + 16), unit : result761}) + } + 30 => { - () - } - SecretValue(payload515) => { - mbt_ffi_store8((iter_base) + 0, (31)) + let result762 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12)) - let @types.Secret(handle516) = payload515 - mbt_ffi_store32((iter_base) + 8, handle516) + @types.SchemaValueNode::UnionValue(@types.UnionValuePayload::{tag : result762, body : mbt_ffi_load32((iter_base) + 16)}) + } + 31 => { - () - } - QuotaTokenHandle(payload517) => { - mbt_ffi_store8((iter_base) + 0, (32)) + @types.SchemaValueNode::SecretValue(@types.Secret::Secret(mbt_ffi_load32((iter_base) + 8))) + } + 32 => { - let @types.QuotaToken(handle518) = payload517 - mbt_ffi_store32((iter_base) + 8, handle518) + @types.SchemaValueNode::QuotaTokenHandle(@types.QuotaToken::QuotaToken(mbt_ffi_load32((iter_base) + 8))) + } + 33 => { - () - } - PermissionCardHandle(payload519) => { - mbt_ffi_store8((iter_base) + 0, (33)) + @types.SchemaValueNode::PermissionCardHandle(@types.PermissionCard::PermissionCard(mbt_ffi_load32((iter_base) + 8))) + } + 34 => { - let @types.PermissionCard(handle520) = payload519 - mbt_ffi_store32((iter_base) + 8, handle520) + @types.SchemaValueNode::StreamValue(@types.SchemaValueStream::SchemaValueStream(mbt_ffi_load32((iter_base) + 8))) + } + _ => panic() + } - () - } - StreamValue(payload521) => { - mbt_ffi_store8((iter_base) + 0, (34)) + array764.push(lifted763) + } + mbt_ffi_free(mbt_ffi_load32((return_area) + 32)) - let @types.SchemaValueStream(handle522) = payload521 - mbt_ffi_store32((iter_base) + 8, handle522) + @common.AgentError::CustomError(@types.TypedSchemaValue::{graph : @types.SchemaGraph::{type_nodes : array728, defs : array733, root : mbt_ffi_load32((return_area) + 28)}, value : @types.SchemaValueTree::{value_nodes : array764, root : mbt_ffi_load32((return_area) + 40)}}) + } + _ => panic() + } - () + RpcError::RemoteAgentError(lifted766) } + _ => panic() } + Result::Err(lifted767) } - mbt_ffi_store32((iter_base) + 32, ((((iter_elem).value).value).value_nodes).length()) - mbt_ffi_store32((iter_base) + 28, address523) - mbt_ffi_store32((iter_base) + 36, (((iter_elem).value).value).root) - cleanup_list.push(address77) - cleanup_list.push(address441) - cleanup_list.push(address447) - cleanup_list.push(address523) - + _ => panic() } - let result : Int = wasmImportConstructorWasmRpc(ptr, agent_type_name.length(), address70, ((constructor_).value_nodes).length(), (constructor_).root, lowered, lowered74, lowered75, address525, (agent_config).length()); - let ret = WasmRpc::WasmRpc(result) + let ret = lifted768 mbt_ffi_free(ptr) mbt_ffi_free(address70) mbt_ffi_free(address525) + mbt_ffi_free(return_area) cleanup_list.each(mbt_ffi_free) return ret diff --git a/sdks/moonbit/golem_sdk/interface/golem/tool/host/top.mbt b/sdks/moonbit/golem_sdk/interface/golem/tool/host/top.mbt index 6162b8d538..40932db100 100644 --- a/sdks/moonbit/golem_sdk/interface/golem/tool/host/top.mbt +++ b/sdks/moonbit/golem_sdk/interface/golem/tool/host/top.mbt @@ -11967,7 +11967,12 @@ pub async fn ToolStdinClosed::wait(self : ToolStdinClosed) -> ByteStreamCloseCau } ///| /// Creates caller stdin endpoints. The writer and closure watcher remain -/// with the caller; the source is moved into one invocation. +/// with the caller; the source is moved into one invocation. Before passing +/// the source to `invoke-and-await`, either select a writer terminal or drive +/// the writer concurrently with the invocation. An open source is valid +/// while a concurrent producer can make progress; writing only after the +/// synchronous invocation returns can deadlock. SDK convenience adapters +/// must start their producer pump before awaiting the invocation terminal. pub fn create_stdin() -> (ToolStdinWriter, ToolStdin, ToolStdinClosed) { let return_area = mbt_ffi_malloc(12) @@ -12450,7 +12455,9 @@ pub fn ToolRpc::tool_rpc(tool_name : String) -> ToolRpc { } ///| /// Waits for the structured terminal. Callers that supplied stdout must -/// drive this wait and the already-created reader concurrently. +/// drive this wait and the already-created reader concurrently. Callers +/// that manually created an open stdin must likewise drive its writer +/// concurrently; see `create-stdin`. pub async fn ToolRpc::invoke_and_await(self : ToolRpc, command_path : Array[String], input : @types.TypedSchemaValue, stdin : ToolStdin?, stdout : ToolStdout?) -> Result[@common.InvocationResult, RpcError] { let lower_ptr : Int = mbt_ffi_malloc(60) diff --git a/sdks/moonbit/golem_sdk/wit/deps/golem-agent/host.wit b/sdks/moonbit/golem_sdk/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/sdks/moonbit/golem_sdk/wit/deps/golem-agent/host.wit +++ b/sdks/moonbit/golem_sdk/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/sdks/rust/golem-rust/wit/deps/golem-agent/host.wit b/sdks/rust/golem-rust/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/sdks/rust/golem-rust/wit/deps/golem-agent/host.wit +++ b/sdks/rust/golem-rust/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/sdks/scala/wit/deps/golem-agent/host.wit b/sdks/scala/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/sdks/scala/wit/deps/golem-agent/host.wit +++ b/sdks/scala/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/sdks/scala/wit/dts/golem_agent_2_0_0_host.d.ts b/sdks/scala/wit/dts/golem_agent_2_0_0_host.d.ts index 4272c4bad2..6a2d61b498 100644 --- a/sdks/scala/wit/dts/golem_agent_2_0_0_host.d.ts +++ b/sdks/scala/wit/dts/golem_agent_2_0_0_host.d.ts @@ -10,6 +10,10 @@ declare module 'golem:agent/host@2.0.0' { * Get a specific registered agent type by name */ export function getAgentType(agentTypeName: string): RegisteredAgentType | undefined; + /** + * Gets the registered agent type used by an existing agent, identified by its agent ID. + */ + export function getAgentTypeByAgentId(agentId: string): RegisteredAgentType | undefined; /** * Constructs a string agent-id from the agent type and its constructor parameters * and an optional phantom ID. @@ -36,11 +40,21 @@ declare module 'golem:agent/host@2.0.0' { export function getConfigValue(key: string[], expected: SchemaGraph): SchemaValueTree; export class WasmRpc { /** - * Constructs the RPC client connecting to the given target agent. + * Creates an RPC client connecting to the given target agent. * `constructor` is a value tree whose root encodes the target agent - * constructor's parameter list. + * constructor's parameter list. This fail-fast form traps if the client + * cannot be created and is intended for statically generated clients. */ constructor(agentTypeName: string, constructor: SchemaValueTree, phantomId: Uuid | undefined, agentConfig: TypedAgentConfigValue[]); + /** + * Creates an RPC client connecting to the given target agent. + * `constructor` is a value tree whose root encodes the target agent + * constructor's parameter list. This fallible form returns an RPC error + * if the client cannot be created and is intended for reflective and + * other dynamic clients. + * @throws RpcError + */ + static create(agentTypeName: string, constructor: SchemaValueTree, phantomId: Uuid | undefined, agentConfig: TypedAgentConfigValue[]): WasmRpc; /** * Invokes a remote method with the given parameters, and awaits the result. * `input` encodes the method's parameter list. The returned result is @@ -91,7 +105,6 @@ declare module 'golem:agent/host@2.0.0' { */ cancel(): void; } - export type ComponentId = golemCore200Types.ComponentId; export type Uuid = golemCore200Types.Uuid; export type PromiseId = golemCore200Types.PromiseId; export type SchemaGraph = golemCore200Types.SchemaGraph; diff --git a/sdks/ts/packages/golem-ts-sdk/package.json b/sdks/ts/packages/golem-ts-sdk/package.json index 4cde0c8f45..bc8844670b 100644 --- a/sdks/ts/packages/golem-ts-sdk/package.json +++ b/sdks/ts/packages/golem-ts-sdk/package.json @@ -16,6 +16,14 @@ "import": "./dist/index.mjs", "types": "./dist/index.d.mts" }, + "./schema": { + "import": "./dist/schema.mjs", + "types": "./dist/schema.d.mts" + }, + "./reflection": { + "import": "./dist/reflection.mjs", + "types": "./dist/reflection.d.mts" + }, "./middleware": { "import": "./dist/middleware.mjs", "types": "./dist/middleware.d.mts" diff --git a/sdks/ts/packages/golem-ts-sdk/rollup.config.js b/sdks/ts/packages/golem-ts-sdk/rollup.config.js index 371c462f66..3b50547b26 100644 --- a/sdks/ts/packages/golem-ts-sdk/rollup.config.js +++ b/sdks/ts/packages/golem-ts-sdk/rollup.config.js @@ -108,8 +108,12 @@ function declarations(input, output) { export default defineConfig([ javascript('src/index.ts', 'dist/index.mjs'), + javascript('src/schema/public.ts', 'dist/schema.mjs'), + javascript('src/reflection.ts', 'dist/reflection.mjs'), javascript('src/middleware.ts', 'dist/middleware.mjs', { hostNeutral: true }), javascript('src/middlewareRuntime.ts', 'dist/middleware-runtime.mjs', { hostNeutral: true }), declarations('src/index.ts', 'dist/index.d.mts'), + declarations('src/schema/public.ts', 'dist/schema.d.mts'), + declarations('src/reflection.ts', 'dist/reflection.d.mts'), declarations('src/middleware.ts', 'dist/middleware.d.mts'), ]); diff --git a/sdks/ts/packages/golem-ts-sdk/src/agentId.ts b/sdks/ts/packages/golem-ts-sdk/src/agentId.ts index 798ad1bfcf..88a5a9638c 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/agentId.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/agentId.ts @@ -16,11 +16,43 @@ import { makeAgentId, parseAgentId } from 'golem:agent/host@2.0.0'; import { Uuid } from './uuid'; import { Uuid as RawUuid } from 'golem:core/types@2.0.0'; import { SchemaValue, schemaValueFromWit, schemaValueToWit } from './internal/schema-model'; +import { DynamicAgentClient, type DynamicAgentClientSurface } from './dynamicClient'; + +/** @internal Protocol implemented by typed contracts and reflected agent types. */ +export const bindAgentClient = '__golemBindAgentClient' as const; + +/** @internal A value that can bind itself to an existing agent identity. */ +export interface AgentClientBinding { + [bindAgentClient](agentId: ParsedAgentId): Client; +} + +/** Explicit parts used to construct a {@link ParsedAgentId}. */ +export interface ParsedAgentIdCreateOptions { + readonly typeName: string; + readonly constructorValue: SchemaValue; + readonly phantomId?: Uuid; +} + +/** Semantic parts of a {@link ParsedAgentId}. */ +export interface ParsedAgentIdParts { + readonly typeName: string; + readonly constructorValue: SchemaValue; + readonly phantomId?: Uuid; +} + +function createAgentIdString( + agentTypeName: string, + parameters: SchemaValue, + phantomId?: RawUuid, +): string { + const normalized = phantomId ? Uuid.from(phantomId) : undefined; + return makeAgentId(agentTypeName, schemaValueToWit(parameters), normalized); +} /** - * Globally unique ID of an `agent`. + * Parsed environment-scoped agent identity string. * - * A ParsedAgentId wraps the string representation of an agent ID and can parse it + * A ParsedAgentId wraps the environment-scoped string representation of an agent ID and can parse it * into its constituent parts: agent type name, constructor parameters, and optional phantom ID. * * Constructor parameters are carried as the schema-native {@link SchemaValue} (the recursive @@ -37,16 +69,14 @@ export class ParsedAgentId { } /** - * Constructs a ParsedAgentId from the given agent type name, parameters and an optional phantom ID. - * @param agentTypeName Agent type name in kebab-case - * @param parameters Constructor parameter values encoded as a {@link SchemaValue} record - * @param phantomId Optional phantom ID + * Constructs a ParsedAgentId from an agent type name, constructor value, and optional phantom ID. + * Prefer a definition's `agentId(...)` when a typed definition is available. */ - static make(agentTypeName: string, parameters: SchemaValue, phantomId?: RawUuid): ParsedAgentId { - const normalized = phantomId ? Uuid.from(phantomId) : undefined; - const value = makeAgentId(agentTypeName, schemaValueToWit(parameters), normalized); + static create(options: ParsedAgentIdCreateOptions): ParsedAgentId { + const normalized = options.phantomId ? Uuid.from(options.phantomId) : undefined; + const value = createAgentIdString(options.typeName, options.constructorValue, normalized); const result = new ParsedAgentId(value); - result.parsedCache = [agentTypeName, parameters, normalized]; + result.parsedCache = [options.typeName, options.constructorValue, normalized]; return result; } @@ -65,4 +95,24 @@ export class ParsedAgentId { } return this.parsedCache; } + + /** Return the semantic parts of this environment-scoped identity. */ + parts(): ParsedAgentIdParts { + const [typeName, constructorValue, phantomId] = this.parsed(); + return { typeName, constructorValue, phantomId }; + } + + /** Bind caller-supplied codecs or a reflected agent type to this identity. */ + client(binding: AgentClientBinding): Client { + const bind = binding[bindAgentClient]; + if (typeof bind !== 'function') { + throw new TypeError('Expected an agent client contract or reflected agent type'); + } + return bind.call(binding, this); + } + + /** Invoke this identity with schema values and no discovery or typed contract. */ + dynamicClient(): DynamicAgentClientSurface { + return new DynamicAgentClient(this); + } } diff --git a/sdks/ts/packages/golem-ts-sdk/src/blobstore.ts b/sdks/ts/packages/golem-ts-sdk/src/blobstore.ts index 9dd041fe42..94cc099838 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/blobstore.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/blobstore.ts @@ -21,6 +21,7 @@ import * as ContainerNS from 'wasi:blobstore/container'; import * as Types from 'wasi:blobstore/types'; import { compileSchema } from './schema/adapter'; import type { StandardSchemaV1 } from './schema/standardSchema'; +import { decodeUtf8 } from './internal/utf8'; // --------------------------------------------------------------------------- // Errors @@ -68,7 +69,6 @@ const wrap = (operation: string, fn: () => A): A => { // --------------------------------------------------------------------------- const textEncoder = new TextEncoder(); -const textDecoder = new TextDecoder('utf-8', { fatal: true }); const validateSync = (schema: StandardSchemaV1, value: unknown): T => { const result = schema['~standard'].validate(value); @@ -90,7 +90,7 @@ const encodeValue = (schema: StandardSchemaV1, value: T): Uint8Array => const decodeValue = (schema: StandardSchemaV1, bytes: Uint8Array): T => wrap('schema.decode', () => { - const json = textDecoder.decode(bytes); + const json = decodeUtf8(bytes); const parsed: unknown = JSON.parse(json); return validateSync(schema, parsed); }); diff --git a/sdks/ts/packages/golem-ts-sdk/src/bridge/agent.ts b/sdks/ts/packages/golem-ts-sdk/src/bridge/agent.ts index 889a4a4c81..a9706db6c9 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/bridge/agent.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/bridge/agent.ts @@ -16,14 +16,55 @@ import { schemaValueFromWit, schemaValueToWit, schemaValueToWitAsync, + typedSchemaValueFromWit, typedSchemaValueToWit, type SchemaValue, type TypedSchemaValue, } from '../internal/schema-model'; import type { Uuid } from '../uuid'; +export type RemoteAgentError = + | { readonly tag: 'invalid-input'; readonly details: string } + | { readonly tag: 'invalid-method'; readonly details: string } + | { readonly tag: 'invalid-type'; readonly details: string } + | { readonly tag: 'invalid-agent-id'; readonly details: string } + | { readonly tag: 'custom-error'; readonly value: TypedSchemaValue }; + +export type RemoteCallErrorCause = + | { readonly tag: 'protocol-error'; readonly details: string } + | { readonly tag: 'denied'; readonly details: string } + | { readonly tag: 'not-found'; readonly details: string } + | { readonly tag: 'remote-internal-error'; readonly details: string } + | { readonly tag: 'remote-agent-error'; readonly error: RemoteAgentError }; + export class RemoteCallError extends Error { readonly _tag = 'RemoteCallError'; + override readonly cause: RemoteCallErrorCause; + + constructor(context: string, cause: RemoteCallErrorCause) { + super(`${context}: ${formatRemoteCallErrorCause(cause)}`, { cause }); + this.name = 'RemoteCallError'; + this.cause = cause; + } +} + +export function isRemoteCallError(error: unknown): error is RemoteCallError { + return ( + typeof error === 'object' && + error !== null && + (error as { _tag?: unknown })._tag === 'RemoteCallError' && + typeof (error as { message?: unknown }).message === 'string' && + isRemoteCallErrorCause((error as { cause?: unknown }).cause) + ); +} + +export class RemoteOutputError extends Error { + readonly _tag = 'RemoteOutputError'; + + constructor(message: string, options?: ErrorOptions) { + super(message, options); + this.name = 'RemoteOutputError'; + } } export interface RemoteInvocationResult { metadata: InvocationMetadata; @@ -34,6 +75,14 @@ export interface AgentConfigEntry { readonly value: TypedSchemaValue; } +type RemoteAgentCreation = ( + agentTypeName: string, + constructorTree: ReturnType, + phantomId: Uuid | undefined, + config: Array<{ path: string[]; value: ReturnType }>, + agentId: string, +) => WasmRpc; + function isRpcError(error: unknown): error is RpcError { if (error === null || typeof error !== 'object') return false; @@ -49,6 +98,84 @@ function isRpcError(error: unknown): error is RpcError { } } +function remoteCallError(context: string, error: RpcError): RemoteCallError { + return new RemoteCallError(context, mapRemoteCallErrorCause(error)); +} + +function mapRemoteCallErrorCause(error: RpcError): RemoteCallErrorCause { + switch (error.tag) { + case 'protocol-error': + case 'denied': + case 'not-found': + case 'remote-internal-error': + return { tag: error.tag, details: error.val }; + case 'remote-agent-error': + return { tag: error.tag, error: mapRemoteAgentError(error.val) }; + } +} + +function isRemoteCallErrorCause(cause: unknown): cause is RemoteCallErrorCause { + if (typeof cause !== 'object' || cause === null) return false; + const tagged = cause as { tag?: unknown; details?: unknown; error?: unknown }; + switch (tagged.tag) { + case 'protocol-error': + case 'denied': + case 'not-found': + case 'remote-internal-error': + return typeof tagged.details === 'string'; + case 'remote-agent-error': + return isRemoteAgentError(tagged.error); + default: + return false; + } +} + +function isRemoteAgentError(error: unknown): error is RemoteAgentError { + if (typeof error !== 'object' || error === null) return false; + const tagged = error as { tag?: unknown; details?: unknown; value?: unknown }; + switch (tagged.tag) { + case 'invalid-input': + case 'invalid-method': + case 'invalid-type': + case 'invalid-agent-id': + return typeof tagged.details === 'string'; + case 'custom-error': + return typeof tagged.value === 'object' && tagged.value !== null; + default: + return false; + } +} + +function mapRemoteAgentError( + error: Extract['val'], +): RemoteAgentError { + switch (error.tag) { + case 'invalid-input': + case 'invalid-method': + case 'invalid-type': + case 'invalid-agent-id': + return { tag: error.tag, details: error.val }; + case 'custom-error': + return { tag: error.tag, value: typedSchemaValueFromWit(error.val) }; + } +} + +function formatRemoteCallErrorCause(cause: RemoteCallErrorCause): string { + if (cause.tag !== 'remote-agent-error') return `${cause.tag}: ${cause.details}`; + return cause.error.tag === 'custom-error' + ? 'remote-agent-error: custom-error' + : `remote-agent-error: ${cause.error.tag}: ${cause.error.details}`; +} + +function mapRpcError(context: string, operation: () => T): T { + try { + return operation(); + } catch (error) { + if (!isRpcError(error)) throw error; + throw remoteCallError(context, error); + } +} + function disposeOwnedWitResources(tree: SchemaValueTree): void { for (const node of tree.valueNodes) { switch (node.tag) { @@ -102,11 +229,50 @@ export function resolveRemoteAgent( phantomId?: Uuid, configEntries: readonly AgentConfigEntry[] = [], mode: 'durable' | 'ephemeral' = 'durable', +): RemoteAgentHandle { + return resolveRemoteAgentWith( + agentTypeName, + constructorValue, + phantomId, + configEntries, + mode, + (typeName, constructorTree, phantom, config) => + new WasmRpc(typeName, constructorTree, phantom, config), + ); +} + +export function resolveRemoteAgentFallibly( + agentTypeName: string, + constructorValue: SchemaValue, + phantomId?: Uuid, + configEntries: readonly AgentConfigEntry[] = [], + mode: 'durable' | 'ephemeral' = 'durable', +): RemoteAgentHandle { + return resolveRemoteAgentWith( + agentTypeName, + constructorValue, + phantomId, + configEntries, + mode, + (typeName, constructorTree, phantom, config, agentId) => + mapRpcError(`Failed to create remote agent client for ${agentId}`, () => + WasmRpc.create(typeName, constructorTree, phantom, config), + ), + ); +} + +function resolveRemoteAgentWith( + agentTypeName: string, + constructorValue: SchemaValue, + phantomId: Uuid | undefined, + configEntries: readonly AgentConfigEntry[], + mode: 'durable' | 'ephemeral', + create: RemoteAgentCreation, ): RemoteAgentHandle { const constructorTree = schemaValueToWit(constructorValue); const agentId = mode === 'ephemeral' ? agentTypeName : makeAgentId(agentTypeName, constructorTree, phantomId); - const rpc = new WasmRpc( + const rpc = create( agentTypeName, constructorTree, phantomId, @@ -114,6 +280,7 @@ export function resolveRemoteAgent( path: [...entry.path], value: typedSchemaValueToWit(entry.value), })), + agentId, ); const awaitInvocation = async ( method: string, @@ -136,9 +303,7 @@ export function resolveRemoteAgent( result = await awaitAbortable(future.get(), signal, () => future.cancel()); } catch (error) { if (!isRpcError(error)) throw error; - throw new RemoteCallError( - `Remote agent ${agentId}.${method} errored: ${JSON.stringify(error, (_, value) => (typeof value === 'bigint' ? value.toString() : value))}`, - ); + throw remoteCallError(`Remote agent ${agentId}.${method} errored`, error); } try { return { @@ -146,8 +311,9 @@ export function resolveRemoteAgent( value: result === undefined ? undefined : schemaValueFromWit(result), }; } catch (error) { - throw new RemoteCallError( + throw new RemoteOutputError( `Remote agent ${agentId}.${method} returned an invalid schema value: ${error instanceof Error ? error.message : String(error)}`, + { cause: error }, ); } }; @@ -157,23 +323,34 @@ export function resolveRemoteAgent( (await awaitInvocation(method, params, signal)).value, invokeAndAwaitWithMetadata: awaitInvocation, invoke(method, params) { - rpc.invoke(method, schemaValueToWit(params), undefined); + mapRpcError(`Remote agent ${agentId}.${method} errored`, () => + rpc.invoke(method, schemaValueToWit(params), undefined), + ); }, invokeWithMetadata(method, params) { - return rpc.invoke(method, schemaValueToWit(params), undefined); + return mapRpcError(`Remote agent ${agentId}.${method} errored`, () => + rpc.invoke(method, schemaValueToWit(params), undefined), + ); }, schedule(at, method, params) { - rpc.scheduleInvocation(at, method, schemaValueToWit(params), undefined); + mapRpcError(`Scheduling remote agent ${agentId}.${method} failed`, () => + rpc.scheduleInvocation(at, method, schemaValueToWit(params), undefined), + ); }, scheduleWithMetadata(at, method, params) { - return rpc.scheduleInvocation(at, method, schemaValueToWit(params), undefined); + return mapRpcError(`Scheduling remote agent ${agentId}.${method} failed`, () => + rpc.scheduleInvocation(at, method, schemaValueToWit(params), undefined), + ); }, scheduleCancelable(at, method, params) { - return rpc.scheduleCancelableInvocation(at, method, schemaValueToWit(params), undefined) - .cancellationToken; + return mapRpcError(`Scheduling remote agent ${agentId}.${method} failed`, () => + rpc.scheduleCancelableInvocation(at, method, schemaValueToWit(params), undefined), + ).cancellationToken; }, scheduleCancelableWithMetadata(at, method, params) { - return rpc.scheduleCancelableInvocation(at, method, schemaValueToWit(params), undefined); + return mapRpcError(`Scheduling remote agent ${agentId}.${method} failed`, () => + rpc.scheduleCancelableInvocation(at, method, schemaValueToWit(params), undefined), + ); }, }; } diff --git a/sdks/ts/packages/golem-ts-sdk/src/client.ts b/sdks/ts/packages/golem-ts-sdk/src/client.ts index a3ad7c1d2c..f7e39b46eb 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/client.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/client.ts @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Wasm-RPC client. `clientFor(def)(id)` returns a typed proxy that calls a -// remote agent declared with the same `defineAgent` definition. The wire encoding +// Wasm-RPC clients attached to agent definitions. `def.client.get(id)` returns a +// typed proxy that calls a remote agent declared with the same definition. The wire encoding // is built from the LOCAL def's `SchemaCodec`s — the exact codecs the exported // component uses to decode (see runtime.ts `invoke`) — so the two sides are // symmetric by construction. Reuses the host `WasmRpc` resource (no decorator @@ -29,35 +29,39 @@ import { encodeChild, v, withIsolatedCapabilityAdoptionTransaction } from './int import type { SchemaGraph, SchemaType, SchemaValue } from './internal/schema-model'; import { compileConfig, ConfigDeclaration } from './config'; import { Uuid } from './uuid'; +import { ParsedAgentId, bindAgentClient } from './agentId'; import { compileSchema } from './schema/adapter'; import { SchemaCodec } from './schema/codec'; import { StandardSchemaV1 } from './schema/standardSchema'; -import type { MarkerKindOf } from './schema/markers'; -import { AgentDefinition, ConfigSpec, IdRecord, MethodsRecord } from './defineAgent'; +import type { + AgentClientContract, + AgentClientBindingDefinition, + AgentClientDefinition, + CallerInput, + ConfigSpec, + IdRecord, + MethodsRecord, +} from './defineAgent'; import { MethodSpec } from './method'; -import { resolveRemoteAgent, RemoteCallError, type AgentConfigEntry } from './bridge/agent'; +import { + resolveRemoteAgent, + resolveRemoteAgentFallibly, + RemoteOutputError, + type AgentConfigEntry, +} from './bridge/agent'; -export { RemoteCallError } from './bridge/agent'; +export { + isRemoteCallError, + RemoteCallError, + RemoteOutputError, + type RemoteAgentError, + type RemoteCallErrorCause, +} from './bridge/agent'; type InferRecord> = { [K in keyof R]: StandardSchemaV1.InferOutput; }; -/** Keys of `C` that are auto-injected `s.principal()` params (host-supplied). */ -type AutoInjectedKeys = { - [K in keyof C & string]: [MarkerKindOf] extends ['principal'] ? K : never; -}[keyof C & string]; - -/** - * Caller-facing input for a remote method: the declared params MINUS any - * auto-injected `s.principal()` param. The callee's host injects the caller's - * principal, so the RPC caller neither supplies nor encodes it. - */ -type CallerInput> = Omit< - Input, - AutoInjectedKeys ->; - /** The async remote signature for a durable method spec (no-arg when caller input is empty). */ type DurableRemoteMethodFor = M extends MethodSpec @@ -123,16 +127,21 @@ export type RemoteClient< /** A newly generated phantom client together with its reusable phantom id. */ export interface PhantomClientDetails { readonly client: RemoteClient; + readonly agentId: ParsedAgentId; readonly phantomId: Uuid; } /** Address existing agents or create a fresh phantom agent client. */ export interface RemoteClientFactory { - ( + /** Address the durable agent with this constructor identity. */ + get(id: InferRecord>, config?: Record): RemoteClient; + /** Address a known phantom instance. */ + getPhantom( id: InferRecord>, - phantomId?: Uuid, + phantomId: Uuid, config?: Record, ): RemoteClient; + /** Create a client with a newly generated phantom id. */ newPhantom( id: InferRecord>, config?: Record, @@ -141,12 +150,113 @@ export interface RemoteClientFactory { + /** Address a known ephemeral phantom instance. */ + getPhantom( + id: InferRecord>, + phantomId: Uuid, + config?: Record, + ): RemoteClient; + /** Create a logical client whose final identity is returned by each invocation. */ newPhantom( id: InferRecord>, config?: Record, ): RemoteClient; } +export type AgentClientFactory< + Id extends IdRecord, + Methods extends MethodsRecord, + Mode extends 'durable' | 'ephemeral', +> = Mode extends 'ephemeral' + ? EphemeralRemoteClientFactory + : RemoteClientFactory; + +export type AgentClientSpec< + Id extends IdRecord, + Methods extends MethodsRecord, + Config extends ConfigSpec = {}, + Mode extends 'durable' | 'ephemeral' = 'durable', +> = { + readonly name: string; + readonly id: Id; + readonly methods: Methods; + readonly config?: Config; +} & (Mode extends 'ephemeral' ? { readonly mode: 'ephemeral' } : { readonly mode?: 'durable' }); + +export interface AgentClientBindingSpec { + readonly name?: string; + readonly methods: Methods; + readonly id?: never; + readonly config?: never; + readonly mode?: never; +} + +/** + * Build a typed client definition without registering or implementing an agent. + * Its Standard Schema inputs may come from any schema library supported by the SDK. + */ +export function defineAgentClient< + Id extends IdRecord, + Methods extends MethodsRecord, + Config extends ConfigSpec = {}, +>( + spec: AgentClientSpec, +): AgentClientDefinition; +export function defineAgentClient< + Id extends IdRecord, + Methods extends MethodsRecord, + Config extends ConfigSpec = {}, +>( + spec: AgentClientSpec, +): AgentClientDefinition; +export function defineAgentClient( + spec: AgentClientBindingSpec, +): AgentClientBindingDefinition; +export function defineAgentClient(spec: { + readonly name?: string; + readonly id?: IdRecord; + readonly methods: MethodsRecord; + readonly config?: ConfigSpec; + readonly mode?: 'durable' | 'ephemeral'; +}): + | AgentClientDefinition + | AgentClientBindingDefinition { + return defineAgentClientImpl(spec); +} + +function defineAgentClientImpl(spec: { + readonly name?: string; + readonly id?: IdRecord; + readonly methods: MethodsRecord; + readonly config?: ConfigSpec; + readonly mode?: 'durable' | 'ephemeral'; +}): + | AgentClientDefinition + | AgentClientBindingDefinition { + if (spec.name !== undefined && spec.id !== undefined) { + const exact: AgentClientContract = + { + name: spec.name, + id: spec.id, + methods: spec.methods, + config: spec.config, + mode: spec.mode ?? 'durable', + }; + return Object.freeze({ ...exact, ...buildAgentClientSurface(exact, true) }); + } + if (spec.id !== undefined || spec.config !== undefined || spec.mode !== undefined) { + throw new TypeError( + 'Agent ID binding contracts may only define methods and an optional name; id, config, and mode require a complete exact name + id definition', + ); + } + const binding = buildAgentIdBinding(spec, true); + return Object.freeze({ + ...(spec.name === undefined ? {} : { name: spec.name }), + methods: spec.methods, + ...binding, + }); +} + interface NamedCodec { name: string; codec: SchemaCodec; @@ -225,113 +335,173 @@ function encodeConfigOverrides( return out; } -/** - * Build a typed RPC client factory for a remote agent definition. - * - * ```ts - * const counter = clientFor(CounterDef); - * const c1 = counter({ name: 'c1' }); - * const next = await c1.increment({ by: 5 }); - * c1.increment.trigger({ by: 1 }); // fire-and-forget - * ``` - */ -export function clientFor< +function compileRemoteMethods(methods: MethodsRecord): CompiledRemoteMethod[] { + return Object.entries(methods).map(([name, spec]) => { + const inputCodecs: NamedCodec[] = Object.keys(spec.input) + .map((key) => ({ name: key, codec: compileSchema(spec.input[key]) })) + .filter((entry) => entry.codec.autoInjected !== 'principal'); + const returnCodec = compileSchema(spec.returns); + return { + name, + inputCodecs, + output: returnCodec.isUnit + ? ({ tag: 'unit' } as const) + : ({ tag: 'single', codec: returnCodec } as const), + }; + }); +} + +function createRemoteClient( + methodCodecs: CompiledRemoteMethod[], + mode: Mode, + remote: ReturnType, +): RemoteClient { + const decodeOutput = (method: CompiledRemoteMethod, value: unknown): unknown => { + if (method.output.tag === 'unit') return undefined; + if (value === undefined) { + throw new RemoteOutputError( + `Remote agent ${remote.agentId}.${method.name} returned no value for a non-unit output`, + ); + } + try { + const decoded = value as SchemaValue; + assertValueMatchesType(decoded, method.output.codec.graph.root, method.output.codec.graph); + return method.output.codec.fromValue(decoded); + } catch (error) { + throw new RemoteOutputError( + `Remote agent ${remote.agentId}.${method.name} returned an invalid output: ${error instanceof Error ? error.message : String(error)}`, + { cause: error }, + ); + } + }; + + const client: Record = {}; + for (const method of methodCodecs) { + const invoke = async (input: Record = {}, signal?: AbortSignal) => { + const invocation = await remote.invokeAndAwaitWithMetadata( + method.name, + encodeRecord(method.inputCodecs, input), + signal, + ); + const value = decodeOutput(method, invocation.value); + return mode === 'ephemeral' ? { metadata: invocation.metadata, value } : value; + }; + const methodFn = + method.inputCodecs.length === 0 + ? (options?: RemoteCallOptions) => invoke({}, options?.signal) + : (input: Record, options?: RemoteCallOptions) => + invoke(input, options?.signal); + client[method.name] = Object.assign(methodFn, { + trigger: (input: Record = {}) => { + const metadata = remote.invokeWithMetadata( + method.name, + encodeRecord(method.inputCodecs, input), + ); + return mode === 'ephemeral' ? metadata : undefined; + }, + schedule: (at: Datetime, input: Record = {}) => { + const receipt = remote.scheduleCancelableWithMetadata( + at, + method.name, + encodeRecord(method.inputCodecs, input), + ); + return mode === 'ephemeral' ? receipt : receipt.cancellationToken; + }, + }); + } + return client as RemoteClient; +} + +function buildAgentIdBinding( + def: { readonly name?: string; readonly methods: Methods }, + fallible: boolean, +): { [bindAgentClient](agentId: ParsedAgentId): RemoteClient } { + const methodCodecs = compileRemoteMethods(def.methods); + return { + [bindAgentClient](agentId) { + return bindExistingAgent(def.name, methodCodecs, fallible, agentId, 'durable'); + }, + }; +} + +function bindExistingAgent( + exactName: string | undefined, + methodCodecs: CompiledRemoteMethod[], + fallible: boolean, + agentId: ParsedAgentId, + mode: Mode, +): RemoteClient { + const parts = agentId.parts(); + if (exactName !== undefined && exactName !== parts.typeName) { + throw new TypeError( + `Agent client contract '${exactName}' cannot bind agent type '${parts.typeName}'`, + ); + } + if (mode === 'ephemeral') { + throw new TypeError( + `Cannot bind existing ParsedAgentId '${agentId.value}' to ephemeral agent type '${parts.typeName}'; use its client.newPhantom(...) factory`, + ); + } + const remote = (fallible ? resolveRemoteAgentFallibly : resolveRemoteAgent)( + parts.typeName, + parts.constructorValue, + parts.phantomId, + [], + mode, + ); + return createRemoteClient(methodCodecs, mode, remote); +} + +/** @internal Build the identity and typed-client surface attached to a definition. */ +export function buildAgentClientSurface< Id extends IdRecord, Methods extends MethodsRecord, Config extends ConfigSpec, - StateSchema extends StandardSchemaV1, Mode extends 'durable' | 'ephemeral', >( - def: AgentDefinition, -): Mode extends 'ephemeral' - ? EphemeralRemoteClientFactory - : RemoteClientFactory { + def: AgentClientContract & { readonly name: string; readonly id: Id }, + fallible: boolean, +): { + client: Mode extends 'ephemeral' + ? EphemeralRemoteClientFactory + : RemoteClientFactory; + agentId: Mode extends 'ephemeral' + ? (id: InferRecord>, phantomId: Uuid) => ParsedAgentId + : (id: InferRecord>, phantomId?: Uuid) => ParsedAgentId; + [bindAgentClient](agentId: ParsedAgentId): RemoteClient; +} { // Compile the def's id + method codecs once (cached in this closure). const idCodecs: NamedCodec[] = Object.keys(def.id) - .map((k) => ({ name: k, codec: compileSchema(def.id[k]) })) + .map((k) => ({ name: k, codec: compileSchema((def.id as Id)[k]) })) .filter((nc) => nc.codec.autoInjected !== 'principal'); - const methodCodecs: CompiledRemoteMethod[] = Object.entries(def.methods).map(([name, spec]) => { - // Skip auto-injected `s.principal()` params: the callee's host injects the - // caller principal, so the RPC caller encodes no wire field for them (the - // remaining user-supplied codecs stay in declaration order, matching the - // callee's cursor decode in runtime.ts `invoke`). - const inputCodecs: NamedCodec[] = Object.keys((spec as MethodSpec).input) - .map((k) => ({ name: k, codec: compileSchema((spec as MethodSpec).input[k]) })) - .filter((nc) => nc.codec.autoInjected !== 'principal'); - const retCodec = compileSchema((spec as MethodSpec).returns); - const output = retCodec.isUnit - ? ({ tag: 'unit' } as const) - : ({ tag: 'single', codec: retCodec } as const); - return { name, inputCodecs, output }; - }); + const methodCodecs = compileRemoteMethods(def.methods); const configDecls: ConfigDeclaration[] = compileConfig(def.config); + const createAgentId = (id: InferRecord>, phantomId?: Uuid): ParsedAgentId => + ParsedAgentId.create({ + typeName: def.name, + constructorValue: encodeRecord(idCodecs, id as Record), + phantomId, + }); + const createClient = ( id: InferRecord>, phantomId?: Uuid, config?: Record, ): RemoteClient => { const agentConfig = config ? encodeConfigOverrides(configDecls, config) : []; - const remote = resolveRemoteAgent( + const remote = (fallible ? resolveRemoteAgentFallibly : resolveRemoteAgent)( def.name, encodeRecord(idCodecs, id as Record), phantomId, agentConfig, def.mode, ); - const agentId = remote.agentId; - - const decodeOutput = (mc: CompiledRemoteMethod, val: unknown): unknown => { - if (mc.output.tag === 'unit') return undefined; - if (val === undefined) { - throw new RemoteCallError( - `Remote agent ${agentId}.${mc.name} returned no value for a non-unit output`, - ); - } - try { - const decoded = val as SchemaValue; - assertValueMatchesType(decoded, mc.output.codec.graph.root, mc.output.codec.graph); - return mc.output.codec.fromValue(decoded); - } catch (error) { - throw new RemoteCallError( - `Remote agent ${agentId}.${mc.name} returned an invalid output: ${error instanceof Error ? error.message : String(error)}`, - ); - } - }; - - const client: Record = {}; - for (const mc of methodCodecs) { - const invoke = async (input: Record = {}, signal?: AbortSignal) => { - const inputTree = encodeRecord(mc.inputCodecs, input); - const invocation = await remote.invokeAndAwaitWithMetadata(mc.name, inputTree, signal); - const value = decodeOutput(mc, invocation.value); - return def.mode === 'ephemeral' ? { metadata: invocation.metadata, value } : value; - }; - const methodFn = - mc.inputCodecs.length === 0 - ? (options?: RemoteCallOptions) => invoke({}, options?.signal) - : (input: Record, options?: RemoteCallOptions) => - invoke(input, options?.signal); - client[mc.name] = Object.assign(methodFn, { - trigger: (input: Record = {}) => { - const metadata = remote.invokeWithMetadata(mc.name, encodeRecord(mc.inputCodecs, input)); - return def.mode === 'ephemeral' ? metadata : undefined; - }, - schedule: (at: Datetime, input: Record = {}) => { - const receipt = remote.scheduleCancelableWithMetadata( - at, - mc.name, - encodeRecord(mc.inputCodecs, input), - ); - return def.mode === 'ephemeral' ? receipt : receipt.cancellationToken; - }, - }); - } - return client as RemoteClient; + return createRemoteClient(methodCodecs, def.mode, remote); }; - createClient.newPhantom = ( + const newPhantom = ( id: InferRecord>, config?: Record, ): PhantomClientDetails | RemoteClient => { @@ -339,10 +509,38 @@ export function clientFor< return createClient(id, undefined, config) as RemoteClient; } const phantomId = Uuid.generate(); - return { client: createClient(id, phantomId, config) as RemoteClient, phantomId }; + return { + client: createClient(id, phantomId, config) as RemoteClient, + agentId: createAgentId(id, phantomId), + phantomId, + }; }; - return createClient as Mode extends 'ephemeral' - ? EphemeralRemoteClientFactory - : RemoteClientFactory; + let client; + if (def.mode === 'ephemeral') { + client = { + getPhantom: (id, phantomId, config) => + createClient(id, phantomId, config) as RemoteClient, + newPhantom, + } as EphemeralRemoteClientFactory; + } else { + client = { + get: (id, config) => createClient(id, undefined, config) as RemoteClient, + getPhantom: (id, phantomId, config) => + createClient(id, phantomId, config) as RemoteClient, + newPhantom, + } as RemoteClientFactory; + } + + return { + client: client as Mode extends 'ephemeral' + ? EphemeralRemoteClientFactory + : RemoteClientFactory, + agentId: createAgentId as Mode extends 'ephemeral' + ? (id: InferRecord>, phantomId: Uuid) => ParsedAgentId + : (id: InferRecord>, phantomId?: Uuid) => ParsedAgentId, + [bindAgentClient](agentId) { + return bindExistingAgent(def.name, methodCodecs, fallible, agentId, def.mode); + }, + }; } diff --git a/sdks/ts/packages/golem-ts-sdk/src/defineAgent.ts b/sdks/ts/packages/golem-ts-sdk/src/defineAgent.ts index 767d92b78b..9d0a9e4e96 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/defineAgent.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/defineAgent.ts @@ -21,7 +21,7 @@ import { StandardSchemaV1 } from './schema/standardSchema'; import { MethodSpec } from './method'; import type { InputRecord, MethodHasHttpOf } from './method'; -import { ParsedAgentId } from './agentId'; +import { bindAgentClient, ParsedAgentId, type AgentClientBinding } from './agentId'; import { Principal } from './principal'; import { Uuid } from './uuid'; import { registerAgentInitiator, registerAgentType, RegisteredAgent } from './runtime'; @@ -31,6 +31,8 @@ import type { MountSpecCovering, WebhookVarsValid } from './httpTypes'; import type { MarkerKindOf, SecretInnerOf } from './schema/markers'; import type { Secret } from './secret'; import { AgentTypeRegistry } from './internal/registry/agentTypeRegistry'; +import { buildAgentClientSurface } from './client'; +import type { AgentClientFactory } from './client'; export type { ConfigSpec } from './config'; @@ -109,6 +111,14 @@ type InferRecord> = { [K in keyof R]: StandardSchemaV1.InferOutput; }; +/** Keys whose values are supplied by the host rather than an RPC caller. */ +type AutoInjectedKeys> = { + [K in keyof R & string]: [MarkerKindOf] extends ['principal'] ? K : never; +}[keyof R & string]; + +/** The schema fields an RPC caller supplies after host-injected fields are removed. */ +export type CallerInput> = Omit>; + /** The handler signature inferred for a method spec (no-arg when input is empty). */ type HandlerFor = M extends MethodSpec @@ -182,20 +192,50 @@ export interface AgentImpl { readonly name: string; } -export interface AgentDefinition< +export interface AgentClientContract< Id extends IdRecord, Methods extends MethodsRecord, Config extends ConfigSpec = {}, - StateSchema extends StandardSchemaV1 = StandardSchemaV1, Mode extends 'durable' | 'ephemeral' = 'durable', - HasSnapshotState extends boolean = false, > { readonly name: string; readonly id: Id; readonly methods: Methods; readonly mode: Mode; - /** The agent's config schema (used by `clientFor` to encode config overrides). */ + /** The agent's config schema used to encode RPC config overrides. */ readonly config?: Config; +} + +export interface AgentClientBindingDefinition< + Methods extends MethodsRecord, +> extends AgentClientBinding> { + readonly name?: string; + readonly methods: Methods; +} + +export interface AgentClientDefinition< + Id extends IdRecord, + Methods extends MethodsRecord, + Config extends ConfigSpec = {}, + Mode extends 'durable' | 'ephemeral' = 'durable', +> extends AgentClientContract { + /** Construct the environment-scoped identity for an agent addressed by this definition. */ + readonly agentId: Mode extends 'ephemeral' + ? (id: InferRecord>, phantomId: Uuid) => ParsedAgentId + : (id: InferRecord>, phantomId?: Uuid) => ParsedAgentId; + /** A client factory compiled from this definition's local schemas. */ + readonly client: AgentClientFactory; + [bindAgentClient](agentId: ParsedAgentId): import('./client').RemoteClient; +} + +export interface AgentDefinition< + Id extends IdRecord, + Methods extends MethodsRecord, + Config extends ConfigSpec = {}, + StateSchema extends StandardSchemaV1 = StandardSchemaV1, + Mode extends 'durable' | 'ephemeral' = 'durable', + HasSnapshotState extends boolean = false, +> extends AgentClientDefinition { /** Supply the runtime behaviour. Registers the agent at module-load time. */ implement>( impl: AgentImplementation, @@ -367,15 +407,38 @@ export function defineAgent< `Definition failed: ${error instanceof Error ? error.message : String(error)}`, ); } - let implemented = false; - return { + const clientContract: AgentClientContract & { + readonly name: string; + readonly id: Id; + } = { name, id: spec.id, methods: spec.methods, mode: spec.mode ?? ('durable' as Mode), - // Expose the config schema on the def so `clientFor` can encode config + // Expose the config schema so the client can encode config // overrides for RPC (config-on-RPC); undefined when the agent has no config. config: spec.config, + }; + let implemented = false; + let surface: + | { + client: AgentClientFactory; + agentId: AgentClientDefinition['agentId']; + [bindAgentClient]: AgentClientDefinition[typeof bindAgentClient]; + } + | undefined; + const getSurface = () => (surface ??= buildAgentClientSurface(clientContract, false)); + return { + ...clientContract, + get agentId() { + return getSurface().agentId; + }, + get client() { + return getSurface().client; + }, + [bindAgentClient](agentId) { + return getSurface()[bindAgentClient](agentId); + }, implement(impl) { if (implemented) { AgentTypeRegistry.recordRegistrationError( diff --git a/sdks/ts/packages/golem-ts-sdk/src/dynamicClient.ts b/sdks/ts/packages/golem-ts-sdk/src/dynamicClient.ts new file mode 100644 index 0000000000..3d6d602b83 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/dynamicClient.ts @@ -0,0 +1,69 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 + +import { + parseAgentId, + type CancelableScheduledInvocationReceipt, + type Datetime, + type InvocationMetadata, +} from 'golem:agent/host@2.0.0'; +import { resolveRemoteAgentFallibly, type RemoteAgentHandle } from './bridge/agent'; +import { schemaValueFromWit, type SchemaValue } from './internal/schema-model'; +import type { ParsedAgentId } from './agentId'; +import { Uuid } from './uuid'; + +export interface DynamicInvocation { + readonly metadata: InvocationMetadata; + readonly value?: T; +} + +export interface DynamicAgentClientSurface { + readonly agentId: ParsedAgentId; + method(name: string): DynamicAgentMethodSurface; +} + +export interface DynamicAgentMethodSurface { + readonly name: string; + invokeValue(input: SchemaValue, signal?: AbortSignal): Promise>; + triggerValue(input: SchemaValue): InvocationMetadata; + scheduleValue(at: Datetime, input: SchemaValue): CancelableScheduledInvocationReceipt; +} + +export class DynamicAgentClient implements DynamicAgentClientSurface { + readonly agentId: ParsedAgentId; + private readonly remote: RemoteAgentHandle; + + constructor(agentId: ParsedAgentId) { + this.agentId = agentId; + const [typeName, constructorValue, phantomId] = parseAgentId(agentId.value); + this.remote = resolveRemoteAgentFallibly( + typeName, + schemaValueFromWit(constructorValue.value), + phantomId === undefined ? undefined : Uuid.from(phantomId), + ); + } + + method(name: string): DynamicAgentMethod { + return new DynamicAgentMethod(name, this.remote); + } +} + +export class DynamicAgentMethod implements DynamicAgentMethodSurface { + constructor( + public readonly name: string, + private readonly remote: RemoteAgentHandle, + ) {} + + invokeValue(input: SchemaValue, signal?: AbortSignal): Promise> { + return this.remote.invokeAndAwaitWithMetadata(this.name, input, signal); + } + + triggerValue(input: SchemaValue): InvocationMetadata { + return this.remote.invokeWithMetadata(this.name, input); + } + + scheduleValue(at: Datetime, input: SchemaValue): CancelableScheduledInvocationReceipt { + return this.remote.scheduleCancelableWithMetadata(at, this.name, input); + } +} diff --git a/sdks/ts/packages/golem-ts-sdk/src/host/hostapi.ts b/sdks/ts/packages/golem-ts-sdk/src/host/hostapi.ts index 0a3328a461..6d68f849e8 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/host/hostapi.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/host/hostapi.ts @@ -17,6 +17,8 @@ import { getPromise, generateIdempotencyKey as rawGenerateIdempotencyKey, resolveComponentId as rawResolveComponentId, + resolveAgentId as rawResolveAgentId, + resolveAgentIdStrict as rawResolveAgentIdStrict, fork as rawFork, ForkResult as RawForkResult, getSelfMetadata as rawGetSelfMetadata, @@ -55,8 +57,6 @@ export { updateAgent, forkAgent, revertAgent, - resolveAgentId, - resolveAgentIdStrict, } from 'golem:api/host@1.5.0'; // Re-export classes (GetAgents is wrapped below) @@ -146,6 +146,27 @@ export function resolveComponentId(componentReference: string): ComponentId | un return raw ? ComponentId.from(raw) : undefined; } +/** + * Resolve an agent reference without checking that the concrete agent exists. + * Returns `undefined` only when the component reference cannot be resolved. + */ +export function resolveAgentId(componentReference: string, agentName: string): AgentId | undefined { + const raw = rawResolveAgentId(componentReference, agentName); + return raw ? wrapAgentId(raw) : undefined; +} + +/** + * Resolve an agent reference and require the concrete agent to exist. + * Returns `undefined` when either the component or the agent cannot be found. + */ +export function resolveAgentIdStrict( + componentReference: string, + agentName: string, +): AgentId | undefined { + const raw = rawResolveAgentIdStrict(componentReference, agentName); + return raw ? wrapAgentId(raw) : undefined; +} + /** * Get the current agent's metadata. */ diff --git a/sdks/ts/packages/golem-ts-sdk/src/index.ts b/sdks/ts/packages/golem-ts-sdk/src/index.ts index 8da465ae22..edbc116ac2 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/index.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/index.ts @@ -52,6 +52,7 @@ import './schema/effect'; export { Uuid } from './uuid'; export { ComponentId, AccountId, EnvironmentId } from './ids'; export { ParsedAgentId } from './agentId'; +export type { ParsedAgentIdCreateOptions, ParsedAgentIdParts } from './agentId'; export * from './agentClassName'; export * from './newTypes/textInput'; export * from './newTypes/binaryInput'; @@ -75,6 +76,8 @@ export * from './host/durable'; export { defineAgent } from './defineAgent'; export type { AgentDefinition, + AgentClientBindingDefinition, + AgentClientDefinition, AgentImpl, AgentImplementation, AgentSpec, @@ -102,6 +105,8 @@ export type { } from './schema/markers'; export { registerSchemaWalker, registeredVendors, compileSchema } from './schema/adapter'; export type { SchemaCodec, SchemaWalker } from './schema/codec'; +export { SchemaRef, SchemaRenderError } from './schema/ref'; +export type { JsonValue, SchemaIssue, SchemaValidationResult } from './schema/ref'; export { c, command, @@ -167,12 +172,16 @@ export type { UniversalToolUnderlying, UniversalToolUnderlyingInvoke, } from './tool'; +export { defineAgentClient, isRemoteCallError, RemoteCallError, RemoteOutputError } from './client'; export type { ToolCallErrorCause, ToolClientOptions } from './toolClient'; -export { clientFor, RemoteCallError } from './client'; export type { + AgentClientFactory, + AgentClientSpec, EphemeralInvocationResult, EphemeralRemoteClientFactory, PhantomClientDetails, + RemoteAgentError, + RemoteCallErrorCause, RemoteCallOptions, RemoteClient, RemoteClientFactory, @@ -187,6 +196,20 @@ export * from './websocket'; export * from './rdbms'; export * as http from './http'; export * as bridge from './bridge'; +export * as reflection from './reflection'; +export { + AgentMethod as ReflectedAgentMethodDefinition, + AgentType as ReflectedAgentType, + DynamicAgentClient, + DynamicAgentMethod, + ReflectedAgentClient, + ReflectedAgentClientFactory, + ReflectedAgentMethod, + getAgentTypeByAgentId, + getAllAgentTypes, + getAgentType as getReflectedAgentType, +} from './reflection'; +export type { ReflectedInvocation, ReflectedPhantomClient } from './reflection'; export type { StartedToolInvocation } from './bridge/tool'; export { ToolStreamError } from './internal/tool/startedToolInvocation'; diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/freeze.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/freeze.ts new file mode 100644 index 0000000000..64fde834a2 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/freeze.ts @@ -0,0 +1,93 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import type { SchemaGraph } from './model'; + +/** Clone a caller-owned graph before the SDK turns it into immutable public state. */ +export function cloneSchemaGraph(graph: SchemaGraph): SchemaGraph { + const seen = new WeakMap(); + return cloneSchemaValue(graph, seen); +} + +function cloneSchemaValue(value: T, seen: WeakMap): T { + if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return value; + + const object = value as object; + const existing = seen.get(object); + if (existing !== undefined) return existing as T; + + if (value instanceof Map) { + const clone = new Map(); + seen.set(object, clone); + value.forEach((entryValue, key) => { + clone.set(cloneSchemaValue(key, seen), cloneSchemaValue(entryValue, seen)); + }); + return clone as T; + } + + if (Array.isArray(value)) { + const clone: unknown[] = []; + seen.set(object, clone); + value.forEach((entry) => clone.push(cloneSchemaValue(entry, seen))); + return clone as T; + } + + if (value instanceof Uint8Array) { + return value.slice() as T; + } + + const clone = Object.create(Object.getPrototypeOf(value)) as Record; + seen.set(object, clone); + Reflect.ownKeys(value).forEach((key) => { + const descriptor = Object.getOwnPropertyDescriptor(value, key); + if (!descriptor) return; + if ('value' in descriptor) descriptor.value = cloneSchemaValue(descriptor.value, seen); + Object.defineProperty(clone, key, descriptor); + }); + return clone as T; +} + +/** Recursively freezes a schema graph, including the mutable methods of its definition map. */ +export function freezeSchemaGraph(graph: SchemaGraph): SchemaGraph { + freezeSchemaValue(graph, new WeakSet()); + return graph; +} + +export function freezeSchemaValue(value: unknown, seen: WeakSet): void { + if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return; + if (seen.has(value)) return; + seen.add(value); + + if (value instanceof Map) { + value.forEach((entryValue, key) => { + freezeSchemaValue(key, seen); + freezeSchemaValue(entryValue, seen); + }); + Object.defineProperties(value, { + set: { value: immutableSchemaMutation }, + delete: { value: immutableSchemaMutation }, + clear: { value: immutableSchemaMutation }, + }); + } else { + Reflect.ownKeys(value).forEach((key) => { + const descriptor = Object.getOwnPropertyDescriptor(value, key); + if (descriptor && 'value' in descriptor) freezeSchemaValue(descriptor.value, seen); + }); + } + Object.freeze(value); +} + +function immutableSchemaMutation(): never { + throw new TypeError('Cannot mutate an immutable schema graph'); +} diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/index.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/index.ts index d63e729892..153ce3c389 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/index.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/index.ts @@ -26,4 +26,5 @@ export * from './model'; export * from './builder'; export * from './wit'; export * from './validation'; +export * from './freeze'; export * from './fingerprint'; diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/model.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/model.ts index cb5b57c347..9095c41af4 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/model.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/model.ts @@ -43,7 +43,10 @@ import type { } from 'golem:core/types@2.0.0'; import { GuestSecretHandle } from './secretHandle'; import { GuestQuotaTokenHandle } from './quotaTokenHandle'; -import { GuestSchemaValueStreamHandle } from './schemaValueStreamHandle'; +import { + GuestSchemaValueStreamHandle, + type GuestSchemaValueStream, +} from './schemaValueStreamHandle'; import { GuestPermissionCardHandle } from './permissionCardHandle'; export type { @@ -441,7 +444,7 @@ export type SchemaValue = // An opaque, affine owned `quota-token` handle. Carried by ownership; never // inspectable or forgeable from a guest. See `GuestQuotaTokenHandle`. | { tag: 'quota-token'; handle: GuestQuotaTokenHandle } - | { tag: 'stream'; handle: GuestSchemaValueStreamHandle } + | { tag: 'stream'; handle: SchemaValueStreamHandle } // An opaque, affine owned `permission-card` handle. | { tag: 'permission-card'; handle: GuestPermissionCardHandle }; @@ -450,6 +453,12 @@ export interface SchemaMapEntry { value: SchemaValue; } +interface SchemaValueStreamHandle { + peek(): GuestSchemaValueStream | undefined; + take(): GuestSchemaValueStream | undefined; + close(): Promise; +} + export type SchemaResult = { tag: 'ok'; value?: SchemaValue } | { tag: 'err'; value?: SchemaValue }; // ============================================================ @@ -578,7 +587,7 @@ export const v = { union: (unionTag: string, body: SchemaValue): SchemaValue => ({ tag: 'union', unionTag, body }), secret: (handle: GuestSecretHandle): SchemaValue => ({ tag: 'secret', handle }), quotaToken: (handle: GuestQuotaTokenHandle): SchemaValue => ({ tag: 'quota-token', handle }), - stream: (handle: GuestSchemaValueStreamHandle): SchemaValue => ({ tag: 'stream', handle }), + stream: (handle: SchemaValueStreamHandle): SchemaValue => ({ tag: 'stream', handle }), permissionCard: (handle: GuestPermissionCardHandle): SchemaValue => ({ tag: 'permission-card', handle, diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/wit.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/wit.ts index af54464aa7..3e9d53eb2c 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/wit.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/schema-model/wit.ts @@ -325,8 +325,17 @@ export function schemaGraphToWit(graph: SchemaGraph): WitSchemaGraph { return new GraphEncoder(graph.defs).encodeGraphRoot(graph.root); } -/** Decode a Component Model carrier into the recursive SDK model. */ -export function schemaGraphFromWit(wit: WitSchemaGraph): SchemaGraph { +/** Definitions and selected roots decoded from one Component Model graph. */ +export interface DecodedSchemaGraphRoots { + readonly defs: Map; + readonly roots: readonly SchemaType[]; +} + +/** Decode one WIT graph and any number of roots while sharing decoded nodes and definitions. */ +export function schemaGraphRootsFromWit( + wit: WitSchemaGraph, + roots: readonly TypeNodeIndex[], +): DecodedSchemaGraphRoots { const nodes = wit.typeNodes; const witDefs = wit.defs; // See `schemaValueFromWit`: a flat on-path `Uint8Array` (`1` = on the current @@ -335,6 +344,7 @@ export function schemaGraphFromWit(wit: WitSchemaGraph): SchemaGraph { // (which resolves to a def id without recursing here), so only a structural // back-edge in raw type-node indices is reported as a cycle. const onPath = new Uint8Array(nodes.length); + const decoded = new Array(nodes.length); function idByDefIndex(di: DefIndex): TypeId { if (di < 0 || di >= witDefs.length) { @@ -350,10 +360,13 @@ export function schemaGraphFromWit(wit: WitSchemaGraph): SchemaGraph { if (onPath[idx] === 1) { throw new SchemaDecodeError(`cyclic type node reference at index ${idx}`); } + const cached = decoded[idx]; + if (cached !== undefined) return cached; onPath[idx] = 1; const node = nodes[idx]; const result = { body: fromBody(node.body), metadata: node.metadata }; onPath[idx] = 0; + decoded[idx] = result; return result; } @@ -477,8 +490,13 @@ export function schemaGraphFromWit(wit: WitSchemaGraph): SchemaGraph { } defs.set(d.id, { name: d.name, body: fromType(d.body) }); } - const root = fromType(wit.root); - return { defs, root }; + return { defs, roots: roots.map(fromType) }; +} + +/** Decode a Component Model carrier into the recursive SDK model. */ +export function schemaGraphFromWit(wit: WitSchemaGraph): SchemaGraph { + const decoded = schemaGraphRootsFromWit(wit, [wit.root]); + return { defs: decoded.defs, root: decoded.roots[0] }; } // ============================================================ @@ -941,7 +959,10 @@ export async function schemaValueToWitAsync(value: SchemaValue): Promise = []; + const newlyWrapped: Array<{ + handle: Pick; + value: unknown; + }> = []; async function prepare(current: SchemaValue): Promise { switch (current.tag) { diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/utf8.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/utf8.ts new file mode 100644 index 0000000000..8f40c80fc5 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/utf8.ts @@ -0,0 +1,20 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const fatalUtf8Decoder = new TextDecoder('utf-8', { fatal: true }); + +/** Decode complete UTF-8 payloads without replacing malformed byte sequences. */ +export function decodeUtf8(bytes: Uint8Array): string { + return fatalUtf8Decoder.decode(bytes); +} diff --git a/sdks/ts/packages/golem-ts-sdk/src/keyvalue.ts b/sdks/ts/packages/golem-ts-sdk/src/keyvalue.ts index 3a6731cb24..5746a51493 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/keyvalue.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/keyvalue.ts @@ -25,6 +25,7 @@ import * as KvEventual from 'wasi:keyvalue/eventual@0.1.0'; import * as KvTypes from 'wasi:keyvalue/types@0.1.0'; import { compileSchema } from './schema/adapter'; import type { StandardSchemaV1 } from './schema/standardSchema'; +import { decodeUtf8 } from './internal/utf8'; // --------------------------------------------------------------------------- // Errors @@ -84,7 +85,6 @@ const wrap = (operation: string, fn: () => A): A => { // value to UTF-8 bytes. Validation/JSON failures throw {@link KeyValueError}. const textEncoder = new TextEncoder(); -const textDecoder = new TextDecoder('utf-8', { fatal: true }); const validateSync = (schema: StandardSchemaV1, value: unknown): T => { const result = schema['~standard'].validate(value); @@ -108,7 +108,7 @@ const encodeValue = (schema: StandardSchemaV1, value: T): Uint8Array => /** Decode UTF-8 JSON bytes and re-validate against the schema. */ const decodeValue = (schema: StandardSchemaV1, bytes: Uint8Array): T => wrap('schema.decode', () => { - const json = textDecoder.decode(bytes); + const json = decodeUtf8(bytes); const parsed: unknown = JSON.parse(json); return validateSync(schema, parsed); }); diff --git a/sdks/ts/packages/golem-ts-sdk/src/reflection.ts b/sdks/ts/packages/golem-ts-sdk/src/reflection.ts new file mode 100644 index 0000000000..3799a9e3bf --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/reflection.ts @@ -0,0 +1,343 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { + getAllAgentTypes as hostGetAllAgentTypes, + getAgentType as hostGetAgentType, + getAgentTypeByAgentId as hostGetAgentTypeByAgentId, + type CancelableScheduledInvocationReceipt, + type Datetime, + type InvocationMetadata, + type RegisteredAgentType, +} from 'golem:agent/host@2.0.0'; +import type { + AgentMethod as HostAgentMethod, + InputSchema as HostInputSchema, + OutputSchema as HostOutputSchema, +} from 'golem:agent/common@2.0.0'; +import type { SchemaGraph as WitSchemaGraph } from 'golem:core/types@2.0.0'; +import { + RemoteOutputError, + resolveRemoteAgentFallibly, + type RemoteAgentHandle, +} from './bridge/agent'; +import { + field, + freezeSchemaGraph, + schemaGraphRootsFromWit, + t, + type SchemaGraph, + type SchemaType, + type SchemaValue, +} from './internal/schema-model'; +import { SchemaRef, type JsonValue } from './schema/ref'; +import { Uuid } from './uuid'; +import { ComponentId } from './ids'; +export { ComponentId } from './ids'; +import { ParsedAgentId, bindAgentClient } from './agentId'; +export { + DynamicAgentClient, + DynamicAgentMethod, + type DynamicAgentClientSurface, + type DynamicAgentMethodSurface, + type DynamicInvocation, +} from './dynamicClient'; + +export { + isRemoteCallError, + RemoteCallError, + RemoteOutputError, + type RemoteAgentError, + type RemoteCallErrorCause, +} from './bridge/agent'; + +export interface ReflectedInvocation { + readonly metadata: InvocationMetadata; + readonly value?: T; +} + +export class AgentMethod { + readonly name: string; + readonly description: string; + readonly promptHint?: string; + readonly input: SchemaRef; + readonly output?: SchemaRef; + + constructor(raw: HostAgentMethod, graph: ReflectedGraph) { + this.name = raw.name; + this.description = raw.description; + this.promptHint = raw.promptHint; + this.input = inputSchemaRef(graph, raw.inputSchema); + this.output = outputSchemaRef(graph, raw.outputSchema); + Object.freeze(this); + } +} + +export class AgentType { + readonly name: string; + readonly description: string; + readonly sourceLanguage: string; + readonly mode: 'durable' | 'ephemeral'; + readonly implementedBy: ComponentId; + readonly constructorInput: SchemaRef; + readonly methods: readonly AgentMethod[]; + readonly client: ReflectedAgentClientFactory; + + constructor(registered: RegisteredAgentType) { + const raw = registered.agentType; + const graph = decodeReflectedGraph(raw.schema); + this.name = raw.typeName; + this.description = raw.description; + this.sourceLanguage = raw.sourceLanguage; + this.mode = raw.mode; + this.implementedBy = ComponentId.from(registered.implementedBy); + this.constructorInput = inputSchemaRef(graph, raw.constructor.inputSchema); + this.methods = Object.freeze(raw.methods.map((method) => new AgentMethod(method, graph))); + this.client = new ReflectedAgentClientFactory(this); + Object.freeze(this); + } + + method(name: string): AgentMethod | undefined { + return this.methods.find((method) => method.name === name); + } + + /** Construct an agent identity from canonical JSON constructor input. */ + agentId(input: JsonValue, phantomId?: Uuid): ParsedAgentId { + return this.agentIdValue(this.constructorInput.packJson(input), phantomId); + } + + /** Construct an agent identity from an already packed constructor value. */ + agentIdValue(input: SchemaValue, phantomId?: Uuid): ParsedAgentId { + return ParsedAgentId.create({ + typeName: this.name, + constructorValue: input, + phantomId, + }); + } + + [bindAgentClient](agentId: ParsedAgentId): ReflectedAgentClient { + const parts = agentId.parts(); + if (parts.typeName !== this.name) { + throw new TypeError(`Reflected agent type '${this.name}' cannot bind '${parts.typeName}'`); + } + if (this.mode === 'ephemeral') { + throw new TypeError( + `Cannot bind existing ParsedAgentId '${agentId.value}' to ephemeral agent type '${this.name}'; use agentType.client.newPhantom(...)`, + ); + } + return new ReflectedAgentClient( + this, + resolveRemoteAgentFallibly( + parts.typeName, + parts.constructorValue, + parts.phantomId, + [], + this.mode, + ), + ); + } +} + +export interface ReflectedPhantomClient { + readonly agentId: ParsedAgentId; + readonly phantomId: Uuid; + readonly client: ReflectedAgentClient; +} + +export class ReflectedAgentClientFactory { + constructor(private readonly agentType: AgentType) {} + + get(input: JsonValue): ReflectedAgentClient { + this.requireMode('durable', 'get'); + return this.create(this.agentType.constructorInput.packJson(input)); + } + + getValue(input: SchemaValue): ReflectedAgentClient { + this.requireMode('durable', 'getValue'); + return this.create(input); + } + + getPhantom(input: JsonValue, phantomId: Uuid): ReflectedAgentClient { + return this.create(this.agentType.constructorInput.packJson(input), phantomId); + } + + getPhantomValue(input: SchemaValue, phantomId: Uuid): ReflectedAgentClient { + return this.create(input, phantomId); + } + + newPhantom(input: JsonValue): ReflectedPhantomClient | ReflectedAgentClient { + return this.newPhantomValue(this.agentType.constructorInput.packJson(input)); + } + + newPhantomValue(input: SchemaValue): ReflectedPhantomClient | ReflectedAgentClient { + if (this.agentType.mode === 'ephemeral') return this.create(input); + const phantomId = Uuid.generate(); + const agentId = this.agentType.agentIdValue(input, phantomId); + return { + agentId, + phantomId, + client: this.create(input, phantomId), + }; + } + + private create(input: SchemaValue, phantomId?: Uuid): ReflectedAgentClient { + return new ReflectedAgentClient( + this.agentType, + resolveRemoteAgentFallibly(this.agentType.name, input, phantomId, [], this.agentType.mode), + ); + } + + private requireMode(expected: AgentType['mode'], operation: string): void { + if (this.agentType.mode !== expected) { + throw new TypeError(`${operation} is not available for ${this.agentType.mode} agent types`); + } + } +} + +export class ReflectedAgentClient { + constructor( + private readonly agentType: AgentType, + private readonly remote: RemoteAgentHandle, + ) {} + + method(name: string): ReflectedAgentMethod { + const method = this.agentType.method(name); + if (!method) throw new TypeError(`Agent type '${this.agentType.name}' has no method '${name}'`); + return new ReflectedAgentMethod(method, this.remote); + } +} + +export class ReflectedAgentMethod { + constructor( + public readonly definition: AgentMethod, + private readonly remote: RemoteAgentHandle, + ) {} + + invoke(input: JsonValue, signal?: AbortSignal): Promise> { + return this.invokeJson(input, signal); + } + + async invokeJson( + input: JsonValue, + signal?: AbortSignal, + ): Promise> { + const result = await this.invokeValue(this.definition.input.packJson(input), signal); + return { + metadata: result.metadata, + value: + result.value === undefined ? undefined : this.definition.output?.unpackJson(result.value), + }; + } + + async invokeValue( + input: SchemaValue, + signal?: AbortSignal, + ): Promise> { + const result = await this.remote.invokeAndAwaitWithMetadata( + this.definition.name, + input, + signal, + ); + if (this.definition.output !== undefined && result.value === undefined) { + throw new RemoteOutputError( + `Remote agent ${this.remote.agentId}.${this.definition.name} returned no value for a non-unit output`, + ); + } + if (this.definition.output !== undefined && result.value !== undefined) { + const validation = this.definition.output.validateValue(result.value); + if (!validation.success) { + throw new RemoteOutputError( + `Remote agent ${this.remote.agentId}.${this.definition.name} returned an invalid output: ${validation.issues.map((issue) => issue.message).join('; ')}`, + ); + } + } + return result; + } + + trigger(input: JsonValue): InvocationMetadata { + return this.triggerValue(this.definition.input.packJson(input)); + } + + triggerValue(input: SchemaValue): InvocationMetadata { + return this.remote.invokeWithMetadata(this.definition.name, input); + } + + schedule(at: Datetime, input: JsonValue): CancelableScheduledInvocationReceipt { + return this.scheduleValue(at, this.definition.input.packJson(input)); + } + + scheduleValue(at: Datetime, input: SchemaValue): CancelableScheduledInvocationReceipt { + return this.remote.scheduleCancelableWithMetadata(at, this.definition.name, input); + } +} + +export function getAllAgentTypes(): readonly AgentType[] { + return Object.freeze(hostGetAllAgentTypes().map((registered) => new AgentType(registered))); +} + +/** + * Look up a deployed agent type by name. + * + * This is an optional discovery operation: it returns `undefined` when the type is not visible in + * the current environment. Once returned, each schema operation is strict and throws for malformed + * JSON or schema values. + */ +export function getAgentType(name: string): AgentType | undefined { + const registered = hostGetAgentType(name); + return registered === undefined ? undefined : new AgentType(registered); +} + +/** + * Look up the current deployed schema for a full environment-scoped identity. + * + * Returns `undefined` when the agent does not exist, its ID is malformed, its type is missing, or + * the caller lacks `View` permission. Use {@link ParsedAgentId.parsed} when strict identity parsing is + * required independently of discovery. + */ +export function getAgentTypeByAgentId(agentId: ParsedAgentId): AgentType | undefined { + const registered = hostGetAgentTypeByAgentId(agentId.value); + return registered === undefined ? undefined : new AgentType(registered); +} + +interface ReflectedGraph { + readonly graph: SchemaGraph; + readonly types: readonly SchemaType[]; +} + +function decodeReflectedGraph(graph: WitSchemaGraph): ReflectedGraph { + const indices = graph.typeNodes.map((_, index) => index); + const decoded = schemaGraphRootsFromWit(graph, indices); + const shared = freezeSchemaGraph({ defs: decoded.defs, root: t.tuple([...decoded.roots]) }); + return { graph: shared, types: decoded.roots }; +} + +function inputSchemaRef(graph: ReflectedGraph, input: HostInputSchema): SchemaRef { + const fields = input.val + .filter((entry) => entry.source.tag === 'user-supplied') + .map((entry) => field(entry.name, reflectedTypeAt(graph, entry.schema), entry.metadata)); + return SchemaRef.fromImmutableGraph(graph.graph, t.record(fields)); +} + +function outputSchemaRef(graph: ReflectedGraph, output: HostOutputSchema): SchemaRef | undefined { + if (output.tag === 'unit') return undefined; + return SchemaRef.fromImmutableGraph(graph.graph, reflectedTypeAt(graph, output.val)); +} + +function reflectedTypeAt(graph: ReflectedGraph, index: number): SchemaType { + const type = graph.types[index]; + if (type === undefined) { + throw new TypeError(`reflected schema type node index out of range: ${index}`); + } + return type; +} diff --git a/sdks/ts/packages/golem-ts-sdk/src/schema/agentStream.ts b/sdks/ts/packages/golem-ts-sdk/src/schema/agentStream.ts index 071f60533c..3de1c3b98b 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/schema/agentStream.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/schema/agentStream.ts @@ -212,7 +212,7 @@ export function agentStreamToHandle( /** @internal Lift a recursive schema-value-stream handle into an AgentStream. */ export function agentStreamFromHandle( - handle: GuestSchemaValueStreamHandle, + handle: Pick, itemCodec: SchemaCodec, ): AgentStream { const endpoint = handle.take(); diff --git a/sdks/ts/packages/golem-ts-sdk/src/schema/codec.ts b/sdks/ts/packages/golem-ts-sdk/src/schema/codec.ts index 219c8ee128..dc239367b4 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/schema/codec.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/schema/codec.ts @@ -24,6 +24,7 @@ import { SchemaGraph, SchemaType, SchemaValue, + freezeSchemaValue, } from '../internal/schema-model'; import { createUntrackedGuestSecretHandle, @@ -136,7 +137,7 @@ function freezeCodec( if (seenCodecs.has(codec)) return; seenCodecs.add(codec); - freezeGraphValue(codec.graph, seenGraphValues); + freezeSchemaValue(codec.graph, seenGraphValues); if (codec.fields) { codec.fields.forEach((entry) => { freezeCodec(entry.codec, seenCodecs, seenGraphValues); @@ -152,36 +153,6 @@ function freezeCodec( Object.freeze(codec); } -function freezeGraphValue(value: unknown, seen: WeakSet): void { - if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return; - if (seen.has(value)) return; - seen.add(value); - - if (value instanceof Map) { - value.forEach((entryValue, key) => { - freezeGraphValue(key, seen); - freezeGraphValue(entryValue, seen); - }); - Object.defineProperties(value, { - set: { value: immutableMapMutation }, - delete: { value: immutableMapMutation }, - clear: { value: immutableMapMutation }, - }); - Object.freeze(value); - return; - } - - Reflect.ownKeys(value).forEach((key) => { - const descriptor = Object.getOwnPropertyDescriptor(value, key); - if (descriptor && 'value' in descriptor) freezeGraphValue(descriptor.value, seen); - }); - Object.freeze(value); -} - -function immutableMapMutation(): never { - throw new TypeError('Cannot mutate an immutable codec map'); -} - /** * A per-vendor schema walker. Given a schema (a Standard Schema value of a known * vendor) and a `recurse` callback for child schemas, it produces a `SchemaCodec`. diff --git a/sdks/ts/packages/golem-ts-sdk/src/schema/public.ts b/sdks/ts/packages/golem-ts-sdk/src/schema/public.ts new file mode 100644 index 0000000000..fe94833fb1 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/schema/public.ts @@ -0,0 +1,19 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export * from '../internal/schema-model'; +export * from './ref'; +export { registerSchemaWalker, registeredVendors, compileSchema } from './adapter'; +export type { SchemaCodec, SchemaWalker } from './codec'; +export type { StandardSchemaV1 } from './standardSchema'; diff --git a/sdks/ts/packages/golem-ts-sdk/src/schema/ref.ts b/sdks/ts/packages/golem-ts-sdk/src/schema/ref.ts new file mode 100644 index 0000000000..32695cdfa5 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/schema/ref.ts @@ -0,0 +1,110 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { + cloneSchemaGraph, + freezeSchemaGraph, + freezeSchemaValue, + type SchemaGraph, + type SchemaType, + type SchemaValue, +} from '../internal/schema-model'; +import { schemaValueConforms } from '../internal/tool/validation'; +import { fromCanonicalJson, toCanonicalJson, toCanonicalJsonSchema } from './render'; + +export type JsonValue = + | null + | boolean + | number + | string + | JsonValue[] + | { readonly [key: string]: JsonValue }; + +export interface SchemaIssue { + readonly message: string; + readonly path: readonly (string | number)[]; +} + +export type SchemaValidationResult = + | { readonly success: true; readonly value: T } + | { readonly success: false; readonly issues: readonly SchemaIssue[] }; + +export class SchemaRef { + readonly graph: SchemaGraph; + readonly root: SchemaType; + + constructor(graph: SchemaGraph, root: SchemaType = graph.root) { + this.graph = freezeSchemaGraph(cloneSchemaGraph({ defs: graph.defs, root })); + this.root = this.graph.root; + Object.freeze(this); + } + + /** @internal Build a view over definitions already owned and frozen by the SDK. */ + static fromImmutableGraph(graph: SchemaGraph, root: SchemaType): SchemaRef { + freezeSchemaValue(root, new WeakSet()); + const ref = Object.create(SchemaRef.prototype) as SchemaRef; + Object.defineProperties(ref, { + graph: { value: Object.freeze({ defs: graph.defs, root }), enumerable: true }, + root: { value: root, enumerable: true }, + }); + return Object.freeze(ref); + } + + validateJson(value: JsonValue): SchemaValidationResult { + try { + const packed = this.packJson(value); + return this.validateValue(packed); + } catch (error) { + return { success: false, issues: [schemaIssue(error)] }; + } + } + + validateValue(value: SchemaValue): SchemaValidationResult { + return schemaValueConforms(this.graph, this.root, value) + ? { success: true, value } + : { + success: false, + issues: [{ path: [], message: 'schema value does not conform to the expected schema' }], + }; + } + + packJson(value: JsonValue): SchemaValue { + return fromCanonicalJson(this.graph, this.root, value); + } + + unpackJson(value: SchemaValue): JsonValue { + return toCanonicalJson(this.graph, this.root, value); + } + + toJsonSchema(options: { includeDraftMarker?: boolean } = {}): JsonValue { + return toCanonicalJsonSchema(this.graph, this.root, options.includeDraftMarker ?? true); + } +} + +function schemaIssue(error: unknown): SchemaIssue { + if (error instanceof SchemaRenderError) { + return { path: error.path, message: error.message }; + } + return { path: [], message: error instanceof Error ? error.message : String(error) }; +} + +export class SchemaRenderError extends TypeError { + constructor( + message: string, + public readonly path: readonly (string | number)[] = [], + ) { + super(message); + this.name = 'SchemaRenderError'; + } +} diff --git a/sdks/ts/packages/golem-ts-sdk/src/schema/render.ts b/sdks/ts/packages/golem-ts-sdk/src/schema/render.ts new file mode 100644 index 0000000000..64f3b7b69e --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/src/schema/render.ts @@ -0,0 +1,960 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import type { + SchemaGraph, + SchemaType, + SchemaTypeBody, + SchemaValue, +} from '../internal/schema-model'; +import { datetimeFromISOString, datetimeToISOString } from '../bridge/schema'; +import { SchemaRenderError, type JsonValue } from './ref'; + +type Path = readonly (string | number)[]; + +function fail(path: Path, message: string): never { + throw new SchemaRenderError(message, path); +} + +function resolve(graph: SchemaGraph, type: SchemaType, seen = new Set()): SchemaType { + if (type.body.tag !== 'ref') return type; + if (seen.has(type.body.id)) + throw new SchemaRenderError(`reference cycle through '${type.body.id}'`); + const definition = graph.defs.get(type.body.id); + if (!definition) throw new SchemaRenderError(`dangling reference '${type.body.id}'`); + seen.add(type.body.id); + return resolve(graph, definition.body, seen); +} + +export function fromCanonicalJson( + graph: SchemaGraph, + type: SchemaType, + json: JsonValue, + path: Path = [], +): SchemaValue { + const body = resolve(graph, type).body; + switch (body.tag) { + case 'bool': + return { tag: 'bool', value: expectBoolean(json, path) }; + case 's8': + return { tag: 's8', value: expectInteger(json, path, -128, 127) }; + case 's16': + return { tag: 's16', value: expectInteger(json, path, -32768, 32767) }; + case 's32': + return { tag: 's32', value: expectInteger(json, path, -(2 ** 31), 2 ** 31 - 1) }; + case 'u8': + return { tag: 'u8', value: expectInteger(json, path, 0, 255) }; + case 'u16': + return { tag: 'u16', value: expectInteger(json, path, 0, 65535) }; + case 'u32': + return { tag: 'u32', value: expectInteger(json, path, 0, 2 ** 32 - 1) }; + case 's64': + return { tag: 's64', value: BigInt(expectSafeInteger(json, path)) }; + case 'u64': { + const value = expectSafeInteger(json, path); + if (value < 0) fail(path, 'expected an unsigned integer'); + return { tag: 'u64', value: BigInt(value) }; + } + case 'f32': + return { tag: 'f32', value: Math.fround(expectNumber(json, path)) }; + case 'f64': + return { tag: 'f64', value: expectNumber(json, path) }; + case 'char': { + const value = expectString(json, path); + if ([...value].length !== 1) fail(path, 'expected one Unicode scalar'); + return { tag: 'char', value }; + } + case 'string': + return { tag: 'string', value: expectString(json, path) }; + case 'text': + return decodeText(json, path); + case 'binary': + return decodeBinary(json, path); + case 'path': + return { tag: 'path', value: expectNonEmptyString(json, path) }; + case 'url': + return { tag: 'url', value: expectNonEmptyString(json, path) }; + case 'datetime': + return { tag: 'datetime', value: datetimeFromISOString(expectString(json, path)) }; + case 'duration': + return { tag: 'duration', nanoseconds: decodeDuration(json, path) }; + case 'quantity': + return decodeQuantity(json, path); + case 'record': { + const object = expectObject(json, path); + const expected = new Set(body.fields.map((field) => field.name)); + for (const key of Object.keys(object)) + if (!expected.has(key)) fail([...path, key], 'unknown field'); + return { + tag: 'record', + fields: body.fields.map((field) => { + if (!(field.name in object)) fail([...path, field.name], 'missing field'); + return fromCanonicalJson(graph, field.body, object[field.name], [...path, field.name]); + }), + }; + } + case 'variant': { + if (typeof json === 'string') { + const caseIndex = body.cases.findIndex((entry) => entry.name === json && !entry.payload); + if (caseIndex < 0) fail(path, `unknown payload-free variant case '${json}'`); + return { tag: 'variant', caseIndex }; + } + const object = expectObject(json, path); + const entries = Object.entries(object); + if (entries.length !== 1) fail(path, 'expected a single-key variant object'); + const [name, payload] = entries[0]; + const caseIndex = body.cases.findIndex((entry) => entry.name === name); + const variantCase = body.cases[caseIndex]; + if (!variantCase?.payload) fail(path, `unknown payload variant case '${name}'`); + return { + tag: 'variant', + caseIndex, + payload: fromCanonicalJson(graph, variantCase.payload, payload, [...path, name]), + }; + } + case 'enum': { + const name = expectString(json, path); + const caseIndex = body.cases.indexOf(name); + if (caseIndex < 0) fail(path, `unknown enum case '${name}'`); + return { tag: 'enum', caseIndex }; + } + case 'flags': { + const selected = expectArray(json, path).map((entry, index) => + expectString(entry, [...path, index]), + ); + const seen = new Set(); + selected.forEach((name, index) => { + if (!body.names.includes(name)) fail([...path, index], `unknown flag '${name}'`); + if (seen.has(name)) fail([...path, index], `duplicate flag '${name}'`); + seen.add(name); + }); + return { tag: 'flags', flags: body.names.map((name) => selected.includes(name)) }; + } + case 'tuple': { + const values = expectArray(json, path); + if (values.length !== body.elements.length) + fail(path, `expected ${body.elements.length} tuple elements`); + return { + tag: 'tuple', + elements: body.elements.map((entry, index) => + fromCanonicalJson(graph, entry, values[index], [...path, index]), + ), + }; + } + case 'list': + case 'fixed-list': { + const values = expectArray(json, path); + if (body.tag === 'fixed-list' && values.length !== body.length) + fail(path, `expected ${body.length} elements`); + const elements = values.map((entry, index) => + fromCanonicalJson(graph, body.element, entry, [...path, index]), + ); + return body.tag === 'list' ? { tag: 'list', elements } : { tag: 'fixed-list', elements }; + } + case 'map': { + const entries = expectArray(json, path).map((entry, index) => { + const pair = expectArray(entry, [...path, index]); + if (pair.length !== 2) fail([...path, index], 'expected a two-element map entry'); + return { + key: fromCanonicalJson(graph, body.key, pair[0], [...path, index, 0]), + value: fromCanonicalJson(graph, body.value, pair[1], [...path, index, 1]), + }; + }); + return { tag: 'map', entries }; + } + case 'option': + return json === null + ? { tag: 'option' } + : { tag: 'option', value: fromCanonicalJson(graph, body.element, json, path) }; + case 'result': { + const object = expectObject(json, path); + const keys = Object.keys(object); + if (keys.length !== 1 || (keys[0] !== 'ok' && keys[0] !== 'err')) + fail(path, "expected {'ok': ...} or {'err': ...}"); + const tag = keys[0] as 'ok' | 'err'; + const expected = tag === 'ok' ? body.ok : body.err; + const payload = object[tag]; + if (!expected) { + if (payload !== null) fail([...path, tag], 'expected null unit payload'); + return { tag: 'result', result: { tag } }; + } + return { + tag: 'result', + result: { tag, value: fromCanonicalJson(graph, expected, payload, [...path, tag]) }, + }; + } + case 'union': { + const matches = body.branches.filter((branch) => + discriminatorMatches(branch.discriminator, json), + ); + if (matches.length !== 1) + fail(path, `expected exactly one matching union branch, found ${matches.length}`); + return { + tag: 'union', + unionTag: matches[0].tag, + body: fromCanonicalJson(graph, matches[0].body, json, path), + }; + } + case 'secret': + case 'quota-token': + case 'permission-card': + fail(path, `${body.tag} values cannot be constructed from JSON`); + case 'future': + case 'stream': + fail(path, `${body.tag} values have no JSON representation`); + case 'ref': + throw new Error('unreachable'); + } +} + +export function toCanonicalJson( + graph: SchemaGraph, + type: SchemaType, + value: SchemaValue, + path: Path = [], +): JsonValue { + const body = resolve(graph, type).body; + if (body.tag === 'secret' || body.tag === 'quota-token' || body.tag === 'permission-card') + fail(path, `${body.tag} values cannot be exposed as JSON`); + if (body.tag === 'future' || body.tag === 'stream') + fail(path, `${body.tag} values have no JSON representation`); + if (body.tag !== value.tag && !(body.tag === 'ref')) + fail(path, `expected ${body.tag} schema value, found ${value.tag}`); + switch (value.tag) { + case 'bool': + case 's8': + case 's16': + case 's32': + case 'u8': + case 'u16': + case 'u32': + case 'f32': + case 'f64': + return value.value; + case 's64': + case 'u64': { + const number = Number(value.value); + if (!Number.isSafeInteger(number)) + fail(path, '64-bit integer cannot be represented losslessly as a JavaScript JSON number'); + return number; + } + case 'char': + case 'string': + case 'path': + case 'url': + return value.value; + case 'text': + return { + text: value.text, + ...(value.language === undefined ? {} : { language: value.language }), + }; + case 'binary': + return { + bytes: bytesToBase64(value.bytes), + ...(value.mimeType === undefined ? {} : { mimeType: value.mimeType }), + }; + case 'datetime': + return datetimeToISOString(value.value); + case 'duration': + return encodeDuration(value.nanoseconds); + case 'quantity': + return { + mantissa: bigintToSafeJsonNumber(value.value.mantissa, path, 'quantity mantissa'), + scale: value.value.scale, + unit: value.value.unit, + }; + case 'record': { + const fields = (body as Extract).fields; + if (value.fields.length !== fields.length) + fail(path, `expected ${fields.length} record fields, found ${value.fields.length}`); + return Object.fromEntries( + fields.map((field, index) => [ + field.name, + toCanonicalJson(graph, field.body, value.fields[index], [...path, field.name]), + ]), + ); + } + case 'variant': { + const entry = (body as Extract).cases[value.caseIndex]; + if (!entry) fail(path, `variant case index ${value.caseIndex} is out of range`); + return value.payload === undefined + ? entry.name + : { + [entry.name]: toCanonicalJson(graph, entry.payload!, value.payload, [ + ...path, + entry.name, + ]), + }; + } + case 'enum': + return ( + (body as Extract).cases[value.caseIndex] ?? + fail(path, 'enum case index is out of range') + ); + case 'flags': { + const names = (body as Extract).names; + if (value.flags.length !== names.length) + fail(path, `expected ${names.length} flag values, found ${value.flags.length}`); + return names.filter((_, index) => value.flags[index]); + } + case 'tuple': { + const elements = (body as Extract).elements; + if (value.elements.length !== elements.length) + fail(path, `expected ${elements.length} tuple elements, found ${value.elements.length}`); + return value.elements.map((entry, index) => + toCanonicalJson(graph, elements[index], entry, [...path, index]), + ); + } + case 'list': + case 'fixed-list': + if (body.tag === 'fixed-list' && value.elements.length !== body.length) + fail(path, `expected ${body.length} elements, found ${value.elements.length}`); + return value.elements.map((entry, index) => + toCanonicalJson( + graph, + (body as Extract).element, + entry, + [...path, index], + ), + ); + case 'map': + return value.entries.map((entry, index) => [ + toCanonicalJson(graph, (body as Extract).key, entry.key, [ + ...path, + index, + 0, + ]), + toCanonicalJson( + graph, + (body as Extract).value, + entry.value, + [...path, index, 1], + ), + ]); + case 'option': + return value.value === undefined + ? null + : toCanonicalJson( + graph, + (body as Extract).element, + value.value, + path, + ); + case 'result': { + const expected = + value.result.tag === 'ok' + ? (body as Extract).ok + : (body as Extract).err; + return { + [value.result.tag]: + value.result.value === undefined + ? null + : toCanonicalJson(graph, expected!, value.result.value, [...path, value.result.tag]), + }; + } + case 'union': + return toCanonicalJson( + graph, + (body as Extract).branches.find( + (entry) => entry.tag === value.unionTag, + )?.body ?? fail(path, `unknown union tag '${value.unionTag}'`), + value.body, + path, + ); + case 'secret': + case 'quota-token': + case 'permission-card': + fail(path, `${value.tag} values cannot be exposed as JSON`); + case 'stream': + fail(path, 'stream values have no JSON representation'); + } +} + +export function toCanonicalJsonSchema( + graph: SchemaGraph, + type: SchemaType, + includeDraftMarker: boolean, +): JsonValue { + const root = renderSchema(graph, type); + const defs = Object.fromEntries( + [...graph.defs].map(([id, definition]) => { + const rendered = renderSchema(graph, definition.body); + return [ + id, + definition.name === undefined || rendered.title !== undefined + ? rendered + : { ...rendered, title: definition.name }, + ]; + }), + ); + return { + ...(includeDraftMarker ? { $schema: 'https://json-schema.org/draft/2020-12/schema' } : {}), + ...root, + ...(Object.keys(defs).length ? { $defs: defs } : {}), + }; +} + +function renderSchema(graph: SchemaGraph, type: SchemaType): Record { + const body = type.body; + if (body.tag === 'ref') + return { $ref: `#/$defs/${body.id.replaceAll('~', '~0').replaceAll('/', '~1')}` }; + let rendered: Record; + switch (body.tag) { + case 'bool': + rendered = { type: 'boolean' }; + break; + case 's8': + rendered = integerSchema(-128, 127); + break; + case 's16': + rendered = integerSchema(-32768, 32767); + break; + case 's32': + rendered = integerSchema(-(2 ** 31), 2 ** 31 - 1); + break; + case 's64': + rendered = integerSchema(Number(-(2n ** 63n)), Number(2n ** 63n - 1n)); + break; + case 'u8': + rendered = integerSchema(0, 255); + break; + case 'u16': + rendered = integerSchema(0, 65535); + break; + case 'u32': + rendered = integerSchema(0, 2 ** 32 - 1); + break; + case 'u64': + rendered = integerSchema(0, Number(2n ** 64n - 1n)); + break; + case 'f32': + case 'f64': + rendered = { type: 'number' }; + break; + case 'char': + rendered = { type: 'string', minLength: 1, maxLength: 1 }; + break; + case 'string': + rendered = { type: 'string' }; + break; + case 'text': { + const text: Record = { type: 'string' }; + if (body.restrictions.minLength !== undefined) text.minLength = body.restrictions.minLength; + if (body.restrictions.maxLength !== undefined) text.maxLength = body.restrictions.maxLength; + if (body.restrictions.regex !== undefined) text.pattern = body.restrictions.regex; + rendered = { + type: 'object', + properties: { text, language: { type: 'string' } }, + required: ['text'], + additionalProperties: false, + ...(body.restrictions.languages === undefined + ? {} + : { description: `Allowed languages: ${body.restrictions.languages.join(', ')}` }), + }; + break; + } + case 'binary': + rendered = { + type: 'object', + required: ['bytes'], + properties: { + bytes: { + type: 'string', + contentEncoding: 'base64url', + ...(body.restrictions.minBytes === undefined + ? {} + : { minLength: base64UrlLength(body.restrictions.minBytes) }), + ...(body.restrictions.maxBytes === undefined + ? {} + : { maxLength: base64UrlLength(body.restrictions.maxBytes) }), + }, + mimeType: { type: 'string', pattern: MIME_TYPE_PATTERN.source }, + }, + additionalProperties: false, + ...(body.restrictions.mimeTypes === undefined + ? {} + : { description: `Allowed MIME types: ${body.restrictions.mimeTypes.join(', ')}` }), + }; + break; + case 'path': { + const direction = body.spec.direction === 'in-out' ? 'inout' : body.spec.direction; + const descriptions = [ + body.spec.allowedExtensions === undefined + ? undefined + : `Allowed extensions: ${body.spec.allowedExtensions.join(', ')}`, + body.spec.allowedMimeTypes === undefined + ? undefined + : `Allowed MIME types: ${body.spec.allowedMimeTypes.join(', ')}`, + ].filter((entry): entry is string => entry !== undefined); + rendered = { + type: 'string', + format: 'file-path', + title: `${direction} ${body.spec.kind} path`, + ...(descriptions.length ? { description: descriptions.join('; ') } : {}), + }; + break; + } + case 'url': { + const descriptions = [ + body.restrictions.allowedSchemes === undefined + ? undefined + : `Allowed schemes: ${body.restrictions.allowedSchemes.join(', ')}`, + body.restrictions.allowedHosts === undefined + ? undefined + : `Allowed hosts: ${body.restrictions.allowedHosts.join(', ')}`, + ].filter((entry): entry is string => entry !== undefined); + rendered = { + type: 'string', + format: 'uri', + title: 'URL', + ...(descriptions.length ? { description: descriptions.join('; ') } : {}), + }; + break; + } + case 'datetime': + rendered = { type: 'string', format: 'date-time' }; + break; + case 'duration': + rendered = { type: 'string', format: 'duration' }; + break; + case 'quantity': + rendered = { + type: 'object', + required: ['mantissa', 'scale', 'unit'], + properties: { + mantissa: { type: 'integer' }, + scale: { type: 'integer' }, + unit: { type: 'string' }, + }, + additionalProperties: false, + title: `Quantity (${body.spec.baseUnit})`, + }; + break; + case 'record': + rendered = { + type: 'object', + properties: Object.fromEntries( + body.fields.map((field) => [ + field.name, + attachMetadata(renderSchema(graph, field.body), field.metadata), + ]), + ), + required: body.fields + .filter((field) => resolve(graph, field.body).body.tag !== 'option') + .map((field) => field.name), + additionalProperties: false, + }; + break; + case 'variant': + rendered = { + oneOf: body.cases.map((entry) => { + if (!entry.payload) return { const: entry.name } as JsonValue; + return { + type: 'object', + required: [entry.name], + properties: { [entry.name]: renderSchema(graph, entry.payload) }, + additionalProperties: false, + } as JsonValue; + }), + }; + break; + case 'enum': + rendered = { type: 'string', enum: body.cases }; + break; + case 'flags': + rendered = { type: 'array', items: { type: 'string', enum: body.names }, uniqueItems: true }; + break; + case 'tuple': + rendered = + body.elements.length === 0 + ? { type: 'array', minItems: 0, maxItems: 0 } + : { + type: 'array', + prefixItems: body.elements.map((entry) => renderSchema(graph, entry)), + items: false, + minItems: body.elements.length, + }; + break; + case 'list': + rendered = { type: 'array', items: renderSchema(graph, body.element) }; + break; + case 'fixed-list': + rendered = { + type: 'array', + items: renderSchema(graph, body.element), + minItems: body.length, + maxItems: body.length, + }; + break; + case 'map': + rendered = { + type: 'array', + items: { + type: 'array', + prefixItems: [renderSchema(graph, body.key), renderSchema(graph, body.value)], + items: false, + minItems: 2, + maxItems: 2, + }, + }; + break; + case 'option': + rendered = { oneOf: [{ type: 'null' }, renderSchema(graph, body.element)] }; + break; + case 'result': + rendered = { + oneOf: [ + { + type: 'object', + required: ['ok'], + properties: { ok: body.ok ? renderSchema(graph, body.ok) : { type: 'null' } }, + additionalProperties: false, + }, + { + type: 'object', + required: ['err'], + properties: { err: body.err ? renderSchema(graph, body.err) : { type: 'null' } }, + additionalProperties: false, + }, + ], + }; + break; + case 'union': + rendered = { + oneOf: body.branches.map((entry) => + applyDiscriminator(renderSchema(graph, entry.body), entry.discriminator), + ), + }; + break; + case 'secret': + case 'quota-token': + case 'permission-card': + rendered = { writeOnly: true, 'x-golem-capability': body.tag }; + break; + case 'future': + case 'stream': + rendered = { type: 'null', description: 'WASI P3 placeholder' }; + break; + } + return attachMetadata(rendered, type.metadata); +} + +function integerSchema(minimum: number, maximum: number): Record { + return { type: 'integer', minimum, maximum }; +} + +function base64UrlLength(bytes: number): number { + return 4 * Math.floor(bytes / 3) + (bytes % 3 === 0 ? 0 : bytes % 3 === 1 ? 2 : 3); +} + +function attachMetadata( + schema: Record, + metadata: SchemaType['metadata'], +): Record { + return { + ...schema, + ...(metadata.doc === undefined || schema.description !== undefined + ? {} + : { description: metadata.doc }), + ...(metadata.examples.length === 0 || schema.examples !== undefined + ? {} + : { examples: metadata.examples }), + ...(metadata.deprecated === undefined + ? {} + : { + deprecated: true, + 'x-golem-deprecation-note': metadata.deprecated, + }), + }; +} + +function applyDiscriminator( + schema: Record, + rule: { tag: string; val?: unknown }, +): Record { + switch (rule.tag) { + case 'prefix': + return { ...schema, pattern: `^${escapeRegex(rule.val as string)}` }; + case 'suffix': + return { ...schema, pattern: `${escapeRegex(rule.val as string)}$` }; + case 'contains': + return { ...schema, pattern: escapeRegex(rule.val as string) }; + case 'regex': + return { ...schema, pattern: rule.val as string }; + case 'field-equals': { + const field = rule.val as { fieldName: string; literal?: string }; + const properties = (schema.properties ?? {}) as Record; + const fieldSchema = (properties[field.fieldName] ?? { type: 'string' }) as Record< + string, + JsonValue + >; + return { + ...schema, + required: [ + ...new Set([...((schema.required as string[] | undefined) ?? []), field.fieldName]), + ], + ...(field.literal === undefined + ? {} + : { + properties: { + ...properties, + [field.fieldName]: { ...fieldSchema, const: field.literal }, + }, + }), + }; + } + case 'field-absent': + return { ...schema, not: { required: [rule.val as string] } }; + default: + return schema; + } +} + +function escapeRegex(value: string): string { + return value.replace(/[\\^$.*+?()[\]{}|]/gu, '\\$&'); +} + +function expectBoolean(value: JsonValue, path: Path): boolean { + if (typeof value !== 'boolean') fail(path, 'expected a JSON boolean'); + return value; +} +function expectNumber(value: JsonValue, path: Path): number { + if (typeof value !== 'number' || !Number.isFinite(value)) + fail(path, 'expected a finite JSON number'); + return value; +} +function expectSafeInteger(value: JsonValue, path: Path): number { + const n = expectNumber(value, path); + if (!Number.isSafeInteger(n)) fail(path, 'expected a safe JSON integer'); + return n; +} +function expectInteger(value: JsonValue, path: Path, min: number, max: number): number { + const n = expectSafeInteger(value, path); + if (n < min || n > max) fail(path, `integer outside ${min}..${max}`); + return n; +} +function expectString(value: JsonValue, path: Path): string { + if (typeof value !== 'string') fail(path, 'expected a JSON string'); + return value; +} +function expectNonEmptyString(value: JsonValue, path: Path): string { + const string = expectString(value, path); + if (string.length === 0) fail(path, 'expected a non-empty JSON string'); + return string; +} +function expectArray(value: JsonValue, path: Path): JsonValue[] { + if (!Array.isArray(value)) fail(path, 'expected a JSON array'); + return value as JsonValue[]; +} +function expectObject(value: JsonValue, path: Path): Record { + if (value === null || Array.isArray(value) || typeof value !== 'object') + fail(path, 'expected a JSON object'); + return value as Record; +} +function decodeText(value: JsonValue, path: Path): SchemaValue { + const object = expectObject(value, path); + rejectUnknownFields(object, ['text', 'language'], path); + return { + tag: 'text', + text: expectString(object.text, [...path, 'text']), + ...(object.language === undefined + ? {} + : { language: expectString(object.language, [...path, 'language']) }), + }; +} +function decodeBinary(value: JsonValue, path: Path): SchemaValue { + const object = expectObject(value, path); + rejectUnknownFields(object, ['bytes', 'mimeType'], path); + const mimeType = + object.mimeType === undefined + ? undefined + : expectString(object.mimeType, [...path, 'mimeType']); + if (mimeType !== undefined && !MIME_TYPE_PATTERN.test(mimeType)) { + fail([...path, 'mimeType'], 'invalid MIME type'); + } + return { + tag: 'binary', + bytes: base64UrlToBytes(expectString(object.bytes, [...path, 'bytes']), [...path, 'bytes']), + ...(mimeType === undefined ? {} : { mimeType }), + }; +} +function decodeQuantity(value: JsonValue, path: Path): SchemaValue { + const object = expectObject(value, path); + rejectUnknownFields(object, ['mantissa', 'scale', 'unit'], path); + return { + tag: 'quantity', + value: { + mantissa: BigInt(expectSafeInteger(object.mantissa, [...path, 'mantissa'])), + scale: expectInteger(object.scale, [...path, 'scale'], -2147483648, 2147483647), + unit: expectString(object.unit, [...path, 'unit']), + }, + }; +} + +const I64_MIN = -(2n ** 63n); +const I64_MAX = 2n ** 63n - 1n; +const NS_PER_SECOND = 1_000_000_000n; +const NS_PER_MINUTE = 60n * NS_PER_SECOND; +const NS_PER_HOUR = 60n * NS_PER_MINUTE; +const NS_PER_DAY = 24n * NS_PER_HOUR; + +function encodeDuration(nanoseconds: bigint): string { + if (nanoseconds === 0n) return 'PT0S'; + const negative = nanoseconds < 0n; + let remaining = negative ? -nanoseconds : nanoseconds; + const days = remaining / NS_PER_DAY; + remaining %= NS_PER_DAY; + const hours = remaining / NS_PER_HOUR; + remaining %= NS_PER_HOUR; + const minutes = remaining / NS_PER_MINUTE; + remaining %= NS_PER_MINUTE; + const seconds = remaining / NS_PER_SECOND; + const nanos = remaining % NS_PER_SECOND; + + let result = negative ? '-P' : 'P'; + if (days !== 0n) result += `${days}D`; + if (hours !== 0n || minutes !== 0n || seconds !== 0n || nanos !== 0n) { + result += 'T'; + if (hours !== 0n) result += `${hours}H`; + if (minutes !== 0n) result += `${minutes}M`; + if (seconds !== 0n || nanos !== 0n) { + result += `${seconds}`; + if (nanos !== 0n) result += `.${nanos.toString().padStart(9, '0').replace(/0+$/u, '')}`; + result += 'S'; + } + } + return result; +} + +function decodeDuration(value: JsonValue, path: Path): bigint { + if (typeof value === 'object' && value !== null && !Array.isArray(value)) { + rejectUnknownFields(value, ['nanoseconds'], path); + return checkedI64(BigInt(expectSafeInteger(value.nanoseconds, [...path, 'nanoseconds'])), path); + } + const text = expectString(value, path); + const shorthand = text.match(/^(-?\d+)(ns|us|ms|s)$/u); + if (shorthand) { + const factor = + shorthand[2] === 'ns' + ? 1n + : shorthand[2] === 'us' + ? 1_000n + : shorthand[2] === 'ms' + ? 1_000_000n + : NS_PER_SECOND; + return checkedI64(BigInt(shorthand[1]) * factor, path); + } + + const iso = text.match( + /^(-)?P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d{1,9}))?S)?)?$/u, + ); + if ( + !iso || + (iso[2] === undefined && iso[3] === undefined && iso[4] === undefined && iso[5] === undefined) + ) { + fail(path, 'expected an ISO 8601 duration'); + } + let result = + BigInt(iso[2] ?? 0) * NS_PER_DAY + + BigInt(iso[3] ?? 0) * NS_PER_HOUR + + BigInt(iso[4] ?? 0) * NS_PER_MINUTE + + BigInt(iso[5] ?? 0) * NS_PER_SECOND + + BigInt((iso[6] ?? '').padEnd(9, '0') || 0); + if (iso[1]) result = -result; + return checkedI64(result, path); +} + +function checkedI64(value: bigint, path: Path): bigint { + if (value < I64_MIN || value > I64_MAX) fail(path, 'duration nanoseconds out of i64 range'); + return value; +} + +function discriminatorMatches(rule: { tag: string; val?: unknown }, value: JsonValue): boolean { + if (rule.tag === 'prefix') + return typeof value === 'string' && value.startsWith(rule.val as string); + if (rule.tag === 'suffix') return typeof value === 'string' && value.endsWith(rule.val as string); + if (rule.tag === 'contains') + return typeof value === 'string' && value.includes(rule.val as string); + if (rule.tag === 'regex') + return typeof value === 'string' && new RegExp(rule.val as string, 'u').test(value); + if (rule.tag === 'field-equals') { + const field = rule.val as { fieldName: string; literal?: string }; + return ( + value !== null && + !Array.isArray(value) && + typeof value === 'object' && + field.fieldName in value && + (field.literal === undefined || + (value as Record)[field.fieldName] === field.literal) + ); + } + if (rule.tag === 'field-absent') { + return ( + value !== null && + !Array.isArray(value) && + typeof value === 'object' && + !((rule.val as string) in value) + ); + } + return false; +} +const MIME_TYPE_PATTERN = /^[A-Za-z0-9!#$&^_.+\-]+\/[A-Za-z0-9!#$&^_.+\-]+$/u; + +function bytesToBase64(bytes: Uint8Array): string { + const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; + let result = ''; + for (let index = 0; index < bytes.length; index += 3) { + const first = bytes[index]; + const second = bytes[index + 1]; + const third = bytes[index + 2]; + result += alphabet[first >> 2]; + result += alphabet[((first & 3) << 4) | ((second ?? 0) >> 4)]; + if (second !== undefined) result += alphabet[((second & 15) << 2) | ((third ?? 0) >> 6)]; + if (third !== undefined) result += alphabet[third & 63]; + } + return result; +} +function base64UrlToBytes(value: string, path: Path): Uint8Array { + const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; + if (!/^[A-Za-z0-9_-]*$/u.test(value) || value.length % 4 === 1) { + fail(path, 'invalid base64url without padding'); + } + const bytes: number[] = []; + for (let index = 0; index < value.length; index += 4) { + const a = alphabet.indexOf(value[index]); + const b = alphabet.indexOf(value[index + 1]); + const c = value[index + 2] === undefined ? 0 : alphabet.indexOf(value[index + 2]); + const d = value[index + 3] === undefined ? 0 : alphabet.indexOf(value[index + 3]); + bytes.push((a << 2) | (b >> 4)); + if (value[index + 2] !== undefined) bytes.push(((b & 15) << 4) | (c >> 2)); + if (value[index + 3] !== undefined) bytes.push(((c & 3) << 6) | d); + } + return Uint8Array.from(bytes); +} + +function rejectUnknownFields( + object: Record, + allowed: readonly string[], + path: Path, +): void { + Object.keys(object).forEach((key) => { + if (!allowed.includes(key)) fail([...path, key], 'unknown field'); + }); +} + +function bigintToSafeJsonNumber(value: bigint, path: Path, label: string): number { + const number = Number(value); + if (!Number.isSafeInteger(number)) fail(path, `${label} cannot be represented losslessly`); + return number; +} diff --git a/sdks/ts/packages/golem-ts-sdk/tests/bridge.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/bridge.test.ts index effb68a96e..7bc4546c69 100644 --- a/sdks/ts/packages/golem-ts-sdk/tests/bridge.test.ts +++ b/sdks/ts/packages/golem-ts-sdk/tests/bridge.test.ts @@ -1,7 +1,7 @@ // Copyright 2024-2026 Golem Cloud // Licensed under the Golem Source License v1.1 -import { WasmRpc } from 'golem:agent/host@2.0.0'; +import { WasmRpc, type RpcError as AgentRpcError } from 'golem:agent/host@2.0.0'; import { SchemaValueStream, type SchemaValueTree } from 'golem:core/types@2.0.0'; import { createStdin, ToolRpc, type ByteStreamFailure, type RpcError } from 'golem:tool/host@0.1.0'; import { describe, expect, it, vi } from 'vitest'; @@ -694,11 +694,81 @@ describe('public bridge runtime', () => { }, }); await expect(remote.invokeAndAwait('broken', bridge.v.tuple([]))).rejects.toMatchObject({ - _tag: 'RemoteCallError', + _tag: 'RemoteOutputError', message: expect.stringContaining('.broken returned an invalid schema value'), }); }); + it.each<{ + raw: AgentRpcError; + mapped: bridge.RemoteCallErrorCause; + }>([ + { + raw: { tag: 'protocol-error', val: 'bad protocol' }, + mapped: { tag: 'protocol-error', details: 'bad protocol' }, + }, + { + raw: { tag: 'denied', val: 'not allowed' }, + mapped: { tag: 'denied', details: 'not allowed' }, + }, + { + raw: { tag: 'not-found', val: 'missing target' }, + mapped: { tag: 'not-found', details: 'missing target' }, + }, + { + raw: { tag: 'remote-internal-error', val: 'remote failure' }, + mapped: { tag: 'remote-internal-error', details: 'remote failure' }, + }, + { + raw: { tag: 'remote-agent-error', val: { tag: 'invalid-input', val: 'bad input' } }, + mapped: { + tag: 'remote-agent-error', + error: { tag: 'invalid-input', details: 'bad input' }, + }, + }, + { + raw: { tag: 'remote-agent-error', val: { tag: 'invalid-method', val: 'bad method' } }, + mapped: { + tag: 'remote-agent-error', + error: { tag: 'invalid-method', details: 'bad method' }, + }, + }, + { + raw: { tag: 'remote-agent-error', val: { tag: 'invalid-type', val: 'bad type' } }, + mapped: { + tag: 'remote-agent-error', + error: { tag: 'invalid-type', details: 'bad type' }, + }, + }, + { + raw: { + tag: 'remote-agent-error', + val: { tag: 'invalid-agent-id', val: 'bad agent id' }, + }, + mapped: { + tag: 'remote-agent-error', + error: { tag: 'invalid-agent-id', details: 'bad agent id' }, + }, + }, + ])('maps $raw.tag agent RPC failures to the public cause model', async ({ raw, mapped }) => { + const remote = bridge.resolveRemoteAgent('Example', bridge.v.tuple([])); + const rpc = vi.mocked(WasmRpc).mock.results.at(-1)!.value as { + asyncInvokeAndAwait: ReturnType; + }; + rpc.asyncInvokeAndAwait.mockReturnValue({ + metadata: { agentId: 'example', idempotencyKey: 'key' }, + future: { + get: vi.fn().mockRejectedValue(raw), + cancel: vi.fn(), + }, + }); + + await expect(remote.invokeAndAwait('broken', bridge.v.tuple([]))).rejects.toMatchObject({ + _tag: 'RemoteCallError', + cause: mapped, + }); + }); + it('returns scheduled invocation metadata when requested', () => { const remote = bridge.resolveRemoteAgent('Example', bridge.v.tuple([])); const rpc = vi.mocked(WasmRpc).mock.results.at(-1)!.value as { diff --git a/sdks/ts/packages/golem-ts-sdk/tests/entrypoints.test-d.ts b/sdks/ts/packages/golem-ts-sdk/tests/entrypoints.test-d.ts new file mode 100644 index 0000000000..53d9b1e5fe --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/tests/entrypoints.test-d.ts @@ -0,0 +1,81 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Type-only coverage for values crossing the package's public entrypoints. +// Checked by the package typecheck script; NOT executed by vitest. + +import { + ComponentId, + ParsedAgentId, + Uuid, + defineAgentClient, + method, + type AgentId, +} from '../dist/index.mjs'; +import { ComponentId as ReflectionComponentId, getAgentType } from '../dist/reflection.mjs'; +import { z } from 'zod'; +import { v } from '../dist/schema.mjs'; + +const componentId = new ComponentId(new Uuid(1n, 2n)); +const reflectionComponentId: ReflectionComponentId = componentId; +getAgentType('ExampleAgent')!.implementedBy satisfies ReflectionComponentId; +reflectionComponentId satisfies ComponentId; +const id = ParsedAgentId.create({ + typeName: 'ExampleAgent', + constructorValue: v.record([v.string('example')]), +}); +id.parts(); +const managementId: AgentId = { componentId, agentId: id.value }; +managementId.componentId satisfies ComponentId; +// @ts-expect-error management IDs do not provide reflection client helpers +managementId.client; +const contract = defineAgentClient({ + methods: { ping: method({ input: { message: z.string() }, returns: z.string() }) }, +}); +id.client(contract).ping({ message: 'hello' }); +id.dynamicClient().method('ping').invokeValue(v.record([])); + +const exactContract = defineAgentClient({ + name: 'ExampleAgent', + id: { name: z.string() }, + methods: { ping: method({ input: { message: z.string() }, returns: z.string() }) }, +}); +const schemaLibraryId = exactContract.agentId({ name: 'example' }); +const schemaValueId = ParsedAgentId.create({ + typeName: exactContract.name, + constructorValue: v.record([v.string('example')]), +}); +schemaLibraryId.client(exactContract).ping({ message: 'schema library' }); +schemaValueId.client(exactContract).ping({ message: 'schema value' }); +schemaValueId.value satisfies string; + +const ephemeralContract = defineAgentClient({ + name: 'EphemeralExampleAgent', + mode: 'ephemeral', + id: { name: z.string() }, + methods: { ping: method({ input: {}, returns: z.string() }) }, +}); +ephemeralContract.client + .newPhantom({ name: 'example' }) + .ping() + .then(({ metadata, value }) => { + metadata.agentId satisfies string; + metadata.idempotencyKey satisfies string; + value satisfies string; + }); + +// @ts-expect-error lifecycle mode requires a complete exact name + id definition +defineAgentClient({ mode: 'ephemeral', methods: contract.methods }); +// @ts-expect-error name-only binding contracts are lifecycle-free +defineAgentClient({ name: 'NamedContract', mode: 'durable', methods: contract.methods }); diff --git a/sdks/ts/packages/golem-ts-sdk/tests/reflection.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/reflection.test.ts new file mode 100644 index 0000000000..88a6d0b000 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/tests/reflection.test.ts @@ -0,0 +1,343 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { describe, expect, it, vi } from 'vitest'; +import { + WasmRpc, + getAgentType as hostGetAgentType, + getAgentTypeByAgentId as hostGetAgentTypeByAgentId, + parseAgentId, + type RegisteredAgentType, +} from 'golem:agent/host@2.0.0'; +import { SchemaRef } from '../src/schema/ref'; +import { + field, + schemaGraphToWit, + schemaValueToWit, + t, + v, + type SchemaGraph, +} from '../src/internal/schema-model'; +import { getAgentType, getAgentTypeByAgentId } from '../src/reflection'; +import { RemoteCallError, RemoteOutputError } from '../src/client'; +import { Uuid } from '../src/uuid'; +import { ParsedAgentId } from '../src/agentId'; + +const stringGraph: SchemaGraph = { defs: new Map(), root: t.string() }; + +function registeredType(mode: 'durable' | 'ephemeral' = 'durable'): RegisteredAgentType { + const schema = schemaGraphToWit(stringGraph); + const metadata = { aliases: [], examples: [] }; + return { + agentType: { + typeName: 'ReflectedEcho', + description: 'Echoes a string', + sourceLanguage: 'typescript', + schema, + constructor: { + description: 'Select an echo instance', + inputSchema: { + tag: 'parameters', + val: [{ name: 'id', source: { tag: 'user-supplied' }, schema: schema.root, metadata }], + }, + }, + methods: [ + { + name: 'echo', + description: 'Echo', + httpEndpoint: [], + inputSchema: { + tag: 'parameters', + val: [ + { + name: 'message', + source: { tag: 'user-supplied' }, + schema: schema.root, + metadata, + }, + ], + }, + outputSchema: { tag: 'single', val: schema.root }, + }, + ], + dependencies: [], + mode, + snapshotting: { tag: 'disabled' }, + config: [], + }, + implementedBy: { uuid: { highBits: 0n, lowBits: 1n } }, + }; +} + +describe('SchemaRef', () => { + const graph: SchemaGraph = { + defs: new Map(), + root: t.record([field('name', t.string()), field('count', t.u32())]), + }; + const schema = new SchemaRef(graph); + + it('packs, validates, unpacks, and renders canonical JSON schema', () => { + const packed = schema.packJson({ name: 'counter', count: 3 }); + expect(schema.validateValue(packed).success).toBe(true); + expect(schema.unpackJson(packed)).toEqual({ name: 'counter', count: 3 }); + expect(schema.toJsonSchema()).toMatchObject({ + $schema: 'https://json-schema.org/draft/2020-12/schema', + type: 'object', + required: ['name', 'count'], + }); + }); + + it('returns a structured path for invalid JSON', () => { + expect(schema.validateJson({ name: 'counter', count: -1 })).toEqual({ + success: false, + issues: [{ path: ['count'], message: expect.stringContaining('outside') }], + }); + }); + + it('does not expose mutable graph definitions', () => { + expect(() => + (schema.graph.defs as Map).set('new-type', { + body: t.string(), + }), + ).toThrow('immutable schema graph'); + }); + + it('deep-clones caller-owned schema nodes before freezing', () => { + const root = t.record([field('value', t.string())]); + const definition = { name: 'Shared', body: t.string() }; + const owned: SchemaGraph = { defs: new Map([['shared', definition]]), root }; + const reflected = new SchemaRef(owned); + + (root.body as Extract).fields[0].name = 'changed'; + definition.name = 'Changed'; + owned.defs.set('later', { name: 'Later', body: t.bool() }); + + expect( + (reflected.root.body as Extract).fields[0] + .name, + ).toBe('value'); + expect(reflected.graph.defs.get('shared')?.name).toBe('Shared'); + expect(reflected.graph.defs.has('later')).toBe(false); + }); +}); + +describe('agent reflection', () => { + it('returns undefined when an optional type lookup misses', () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(undefined); + expect(getAgentType('Missing')).toBeUndefined(); + }); + + it('rejects malformed reflected schema graphs', () => { + const malformed = registeredType(); + const output = malformed.agentType.methods[0].outputSchema; + if (output.tag !== 'single') throw new Error('test agent must declare a single output'); + output.val = malformed.agentType.schema.typeNodes.length; + vi.mocked(hostGetAgentType).mockReturnValueOnce(malformed); + expect(() => getAgentType('ReflectedEcho')).toThrow(/type node index out of range/); + }); + + it('rejects malformed constructor values and agent IDs', () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType()); + const reflected = getAgentType('ReflectedEcho')!; + expect(() => reflected.client.get({ id: 1 })).toThrow(/expected .*string/); + + vi.mocked(parseAgentId).mockImplementationOnce(() => { + throw new TypeError('malformed agent id'); + }); + const malformed = new ParsedAgentId('not-an-agent-id'); + expect(() => malformed.parts()).toThrow('malformed agent id'); + }); + + it('discovers a type and invokes through its reflected schemas', async () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType()); + const reflected = getAgentType('ReflectedEcho')!; + const client = reflected.client.get({ id: 'one' }); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; + rpc.asyncInvokeAndAwait.mockReturnValue({ + metadata: { agentId: 'ReflectedEcho(one)', idempotencyKey: 'key' }, + future: { + get: vi.fn().mockResolvedValue(schemaValueToWit(v.string('hello'))), + cancel: vi.fn(), + }, + }); + + await expect(client.method('echo').invokeJson({ message: 'hello' })).resolves.toEqual({ + metadata: { agentId: 'ReflectedEcho(one)', idempotencyKey: 'key' }, + value: 'hello', + }); + }); + + it('decodes a reflected graph once and shares immutable definitions and type nodes', () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType()); + const reflected = getAgentType('ReflectedEcho')!; + const method = reflected.method('echo')!; + const constructorField = ( + reflected.constructorInput.root.body as Extract< + typeof reflected.constructorInput.root.body, + { tag: 'record' } + > + ).fields[0]; + const methodField = ( + method.input.root.body as Extract + ).fields[0]; + + expect(reflected.constructorInput.graph.defs).toBe(method.input.graph.defs); + expect(method.input.graph.defs).toBe(method.output!.graph.defs); + expect(constructorField.body).toBe(methodField.body); + expect(methodField.body).toBe(method.output!.root); + expect(() => + (method.output!.graph.defs as Map).set('new', t.string()), + ).toThrow('immutable schema graph'); + }); + + it('rejects missing and malformed values for a declared output', async () => { + vi.mocked(hostGetAgentType).mockReturnValue(registeredType()); + const reflected = getAgentType('ReflectedEcho')!; + const client = reflected.client.get({ id: 'one' }); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; + + rpc.asyncInvokeAndAwait.mockReturnValueOnce({ + metadata: { agentId: 'ReflectedEcho(one)', idempotencyKey: 'missing' }, + future: { get: vi.fn().mockResolvedValue(undefined), cancel: vi.fn() }, + }); + await expect(client.method('echo').invokeValue(v.record([]))).rejects.toBeInstanceOf( + RemoteOutputError, + ); + + rpc.asyncInvokeAndAwait.mockReturnValueOnce({ + metadata: { agentId: 'ReflectedEcho(one)', idempotencyKey: 'malformed' }, + future: { get: vi.fn().mockResolvedValue(schemaValueToWit(v.u32(1))), cancel: vi.fn() }, + }); + await expect(client.method('echo').invokeValue(v.record([]))).rejects.toBeInstanceOf( + RemoteOutputError, + ); + }); + + it('looks up the current schema for a concrete agent instance', () => { + const rawId = new ParsedAgentId('ReflectedEcho(one)'); + vi.mocked(hostGetAgentTypeByAgentId).mockReturnValueOnce(registeredType()); + + expect(getAgentTypeByAgentId(rawId)?.name).toBe('ReflectedEcho'); + expect(hostGetAgentTypeByAgentId).toHaveBeenLastCalledWith(rawId.value); + }); + + it('creates a bare client without a discovery lookup', async () => { + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ReflectedEcho', + { + graph: schemaGraphToWit(stringGraph), + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + const before = vi.mocked(hostGetAgentType).mock.calls.length; + const agentId = new ParsedAgentId('ReflectedEcho(one)'); + const client = agentId.dynamicClient(); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; + rpc.asyncInvokeAndAwait.mockReturnValue({ + metadata: { agentId: 'ReflectedEcho(one)', idempotencyKey: 'key' }, + future: { + get: vi.fn().mockResolvedValue(schemaValueToWit(v.string('hello'))), + cancel: vi.fn(), + }, + }); + + await expect(client.method('anything').invokeValue(v.record([]))).resolves.toMatchObject({ + value: v.string('hello'), + }); + expect(hostGetAgentType).toHaveBeenCalledTimes(before); + }); + + it('binds a discovered reflected type fluently to an existing identity', () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType()); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ReflectedEcho', + { + graph: schemaGraphToWit(stringGraph), + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + const reflected = getAgentType('ReflectedEcho')!; + const agentId = new ParsedAgentId('ReflectedEcho(one)'); + + const client = agentId.client(reflected); + + expect(client).not.toHaveProperty('agentId'); + expect(client.method('echo').definition.name).toBe('echo'); + }); + + it('rejects binding a reflected ephemeral type to an existing identity', () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType('ephemeral')); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ReflectedEcho', + { + graph: schemaGraphToWit(stringGraph), + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + const reflected = getAgentType('ReflectedEcho')!; + const agentId = new ParsedAgentId('ReflectedEcho(one)'); + const creates = vi.mocked(WasmRpc.create).mock.calls.length; + + expect(() => agentId.client(reflected)).toThrow( + "Cannot bind existing ParsedAgentId 'ReflectedEcho(one)' to ephemeral agent type 'ReflectedEcho'; use agentType.client.newPhantom(...)", + ); + expect(WasmRpc.create).toHaveBeenCalledTimes(creates); + }); + + it('preserves the structured RPC error returned by client creation', () => { + const rpcError = { tag: 'not-found' as const, val: 'missing deployment' }; + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType()); + vi.mocked(WasmRpc.create).mockImplementationOnce(() => { + throw rpcError; + }); + + try { + getAgentType('ReflectedEcho')!.client.get({ id: 'one' }); + throw new Error('expected client creation to fail'); + } catch (error) { + expect(error).toBeInstanceOf(RemoteCallError); + expect(error).toMatchObject({ + cause: { tag: 'not-found', details: rpcError.val }, + }); + } + }); + + it('returns invocation metadata without synthetic identity for ephemeral reflected clients', async () => { + vi.mocked(hostGetAgentType).mockReturnValueOnce(registeredType('ephemeral')); + const reflected = getAgentType('ReflectedEcho')!; + const phantomId = new Uuid(1n, 2n); + const known = reflected.client.getPhantom({ id: 'one' }, phantomId); + const fresh = reflected.client.newPhantom({ id: 'two' }); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; + rpc.asyncInvokeAndAwait.mockReturnValue({ + metadata: { agentId: 'ReflectedEcho(two)[final]', idempotencyKey: 'key' }, + future: { + get: vi.fn().mockResolvedValue(schemaValueToWit(v.string('hello'))), + cancel: vi.fn(), + }, + }); + + expect(reflected.agentId({ id: 'one' }, phantomId).value).toBe('MockAgent()'); + expect(known).not.toHaveProperty('agentId'); + if ('client' in fresh) throw new Error('ephemeral newPhantom returned a durable wrapper'); + expect(fresh).not.toHaveProperty('agentId'); + await expect(fresh.method('echo').invoke({ message: 'hello' })).resolves.toEqual({ + metadata: { agentId: 'ReflectedEcho(two)[final]', idempotencyKey: 'key' }, + value: 'hello', + }); + }); +}); diff --git a/sdks/ts/packages/golem-ts-sdk/tests/schema-ref.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/schema-ref.test.ts new file mode 100644 index 0000000000..6d79027da0 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/tests/schema-ref.test.ts @@ -0,0 +1,184 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { describe, expect, it } from 'vitest'; +import { + emptyMetadata, + field, + schemaType, + t, + v, + type SchemaGraph, +} from '../src/internal/schema-model'; +import { SchemaRef } from '../src/schema/ref'; + +function schema(root: SchemaGraph['root']): SchemaRef { + return new SchemaRef({ defs: new Map(), root }); +} + +describe('SchemaRef canonical JSON', () => { + it('uses the canonical object representation for text', () => { + const ref = schema( + schemaType({ + tag: 'text', + restrictions: { minLength: 2, maxLength: 5, languages: ['en'] }, + }), + ); + + expect(ref.packJson({ text: 'hello', language: 'en' })).toEqual(v.text('hello', 'en')); + expect(ref.unpackJson(v.text('hello'))).toEqual({ text: 'hello' }); + expect(ref.validateJson({ text: 'x', language: 'en' }).success).toBe(false); + expect(ref.validateJson({ text: 'hello', language: 'de' }).success).toBe(false); + expect(ref.validateJson('hello').success).toBe(false); + expect(ref.validateJson({ text: 'hello', extra: true }).success).toBe(false); + }); + + it('round-trips binary values as unpadded base64url and validates MIME types', () => { + const ref = schema( + schemaType({ + tag: 'binary', + restrictions: { minBytes: 2, maxBytes: 3, mimeTypes: ['application/octet-stream'] }, + }), + ); + const json = { bytes: '-_8', mimeType: 'application/octet-stream' } as const; + + expect(ref.packJson(json)).toEqual( + v.binary(Uint8Array.from([251, 255]), 'application/octet-stream'), + ); + expect(ref.unpackJson(ref.packJson(json))).toEqual(json); + expect(ref.validateJson({ bytes: 'AQ==', mimeType: 'application/octet-stream' })).toEqual({ + success: false, + issues: [{ path: ['bytes'], message: 'invalid base64url without padding' }], + }); + expect(ref.validateJson({ bytes: 'AQI', mimeType: 'not a mime' }).success).toBe(false); + }); + + it('accepts ISO 8601 and shorthand durations and emits ISO 8601', () => { + const ref = schema(t.duration()); + + expect(ref.packJson('PT1M2.003S')).toEqual(v.duration(62_003_000_000n)); + expect(ref.packJson('250ms')).toEqual(v.duration(250_000_000n)); + expect(ref.unpackJson(v.duration(-90_000_000_000n))).toBe('-PT1M30S'); + }); + + it('uses JSON integers for quantity mantissas', () => { + const ref = schema(t.quantity({ baseUnit: 'm', allowedUnits: [] })); + const json = { mantissa: 123, scale: -2, unit: 'm' } as const; + + expect(ref.packJson(json)).toEqual(v.quantity({ mantissa: 123n, scale: -2, unit: 'm' })); + expect(ref.unpackJson(ref.packJson(json))).toEqual(json); + expect(ref.validateJson({ ...json, mantissa: '123' }).success).toBe(false); + }); + + it('uses lossless JSON numbers for s64 and u64 values', () => { + const signed = schema(t.s64()); + const unsigned = schema(t.u64()); + + expect(signed.packJson(Number.MIN_SAFE_INTEGER)).toEqual( + v.s64(BigInt(Number.MIN_SAFE_INTEGER)), + ); + expect(unsigned.packJson(Number.MAX_SAFE_INTEGER)).toEqual( + v.u64(BigInt(Number.MAX_SAFE_INTEGER)), + ); + expect(signed.unpackJson(v.s64(BigInt(Number.MAX_SAFE_INTEGER)))).toBe(Number.MAX_SAFE_INTEGER); + expect(unsigned.validateJson(-1).success).toBe(false); + expect(signed.validateJson(Number.MAX_SAFE_INTEGER + 1).success).toBe(false); + expect(() => unsigned.unpackJson(v.u64(2n ** 63n))).toThrow(/cannot be represented losslessly/); + }); + + it('rejects out-of-range and malformed primitive values', () => { + expect(schema(t.s8()).validateJson(-129).success).toBe(false); + expect(schema(t.u8()).validateJson(256).success).toBe(false); + expect(schema(t.u32()).validateJson(1.5).success).toBe(false); + expect(schema(t.string()).validateValue(v.bool(true)).success).toBe(false); + }); + + it('rejects unknown and duplicate flags', () => { + const ref = schema(t.flags(['read', 'write'])); + + expect(ref.validateJson(['read', 'read']).success).toBe(false); + expect(ref.validateJson(['admin']).success).toBe(false); + }); + + it('keeps structural packing separate from full restriction validation', () => { + const ref = schema(t.u32({ min: { tag: 'unsigned', val: 5n } })); + + expect(ref.packJson(3)).toEqual(v.u32(3)); + expect(ref.validateJson(3)).toEqual({ + success: false, + issues: [{ path: [], message: 'schema value does not conform to the expected schema' }], + }); + }); +}); + +describe('SchemaRef JSON Schema', () => { + it('renders canonical records, optional fields, metadata, and exact tuples', () => { + const named = t.record([ + field('name', t.string(), { + ...emptyMetadata(), + doc: 'Display name', + examples: ['Ada'], + }), + field('nickname', t.option(t.string())), + ]); + const graph: SchemaGraph = { + defs: new Map([['person', { name: 'Person', body: named }]]), + root: t.tuple([t.ref('person'), t.u8()]), + }; + + expect(new SchemaRef(graph).toJsonSchema()).toEqual({ + $schema: 'https://json-schema.org/draft/2020-12/schema', + type: 'array', + prefixItems: [{ $ref: '#/$defs/person' }, { type: 'integer', minimum: 0, maximum: 255 }], + items: false, + minItems: 2, + $defs: { + person: { + title: 'Person', + type: 'object', + properties: { + name: { type: 'string', description: 'Display name', examples: ['Ada'] }, + nickname: { oneOf: [{ type: 'null' }, { type: 'string' }] }, + }, + required: ['name'], + additionalProperties: false, + }, + }, + }); + }); + + it('renders the same canonical shapes used by rich JSON values', () => { + const root = t.record([ + field('text', schemaType({ tag: 'text', restrictions: {} })), + field('duration', t.duration()), + field('quantity', t.quantity({ baseUnit: 'm', allowedUnits: [] })), + ]); + + expect(schema(root).toJsonSchema()).toMatchObject({ + properties: { + text: { + type: 'object', + properties: { text: { type: 'string' }, language: { type: 'string' } }, + required: ['text'], + additionalProperties: false, + }, + duration: { type: 'string', format: 'duration' }, + quantity: { + type: 'object', + properties: { mantissa: { type: 'integer' } }, + }, + }, + }); + }); +}); diff --git a/sdks/ts/packages/golem-ts-sdk/tests/sdk.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/sdk.test.ts index 5937a96869..550755adff 100644 --- a/sdks/ts/packages/golem-ts-sdk/tests/sdk.test.ts +++ b/sdks/ts/packages/golem-ts-sdk/tests/sdk.test.ts @@ -14,16 +14,22 @@ import { describe, it, expect, vi } from 'vitest'; import { z } from 'zod'; -import { makeAgentId, WasmRpc } from 'golem:agent/host@2.0.0'; +import { makeAgentId, parseAgentId, WasmRpc } from 'golem:agent/host@2.0.0'; import type { CancellationToken, Datetime } from 'golem:agent/host@2.0.0'; import { defineAgent } from '../src/defineAgent'; import type { AgentSpec } from '../src/defineAgent'; import { method } from '../src/method'; -import { clientFor, RemoteCallError } from '../src/client'; +import { + defineAgentClient, + isRemoteCallError, + RemoteCallError, + RemoteOutputError, +} from '../src/client'; import { compileSchema } from '../src/schema/adapter'; import type { StandardSchemaV1 } from '../src/schema/standardSchema'; import { s } from '../src/schema/markers'; import { Uuid } from '../src/uuid'; +import { ParsedAgentId } from '../src/agentId'; import { AgentClassName } from '../src/agentClassName'; import { AgentTypeRegistry } from '../src/internal/registry/agentTypeRegistry'; import { AgentInitiatorRegistry } from '../src/internal/registry/agentInitiatorRegistry'; @@ -43,11 +49,14 @@ function remoteClientTypeChecks(): void { add: method({ input: { by: z.number() }, returns: z.number() }), }, }); - const factory = clientFor(def); - const client = factory({ name: 'counter' }); + const factory = def.client; + const client = factory.get({ name: 'counter' }); + const definitionClient = def.client.get({ name: 'counter' }); + const agentId = def.agentId({ name: 'counter' }); const controller = new AbortController(); void client.ping({ signal: controller.signal }); void client.add({ by: 1 }, { signal: controller.signal }); + void definitionClient.ping(); // @ts-expect-error cancellation is an option on the normal call, not a separate operation void client.ping.abortable(controller.signal); const at: Datetime = { seconds: 1n, nanoseconds: 0 }; @@ -65,21 +74,55 @@ function remoteClientTypeChecks(): void { id: { name: z.string() }, methods: { ping: method({ input: {}, returns: z.string() }) }, }); - const ephemeralFactory = clientFor(ephemeralDef); + const ephemeralFactory = ephemeralDef.client; const ephemeral = ephemeralFactory.newPhantom({ name: 'counter' }); void ephemeral.ping().then(({ metadata, value }) => ({ metadata, value })); const ephemeralMetadata = ephemeral.ping.trigger(); const ephemeralReceipt = ephemeral.ping.schedule(at); + const knownEphemeral = ephemeralDef.client.getPhantom({ name: 'counter' }, new Uuid(1n, 2n)); + const ephemeralAgentId = ephemeralDef.agentId({ name: 'counter' }, new Uuid(1n, 2n)); + void knownEphemeral.ping(); // @ts-expect-error ephemeral factories cannot address a stable agent directly - ephemeralFactory({ name: 'counter' }); + ephemeralFactory.get({ name: 'counter' }); // @ts-expect-error ephemeral clients have no reusable pre-invocation phantom id void ephemeral.phantomId; void pingToken; void addToken; void phantomId; + void agentId; + void ephemeralAgentId; void ephemeralMetadata; void ephemeralReceipt; + const exactEphemeralContract = defineAgentClient({ + name: 'ExactEphemeralClientTypeChecks', + mode: 'ephemeral', + id: { name: z.string() }, + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + const exactEphemeralClient = exactEphemeralContract.client.newPhantom({ name: 'counter' }); + void exactEphemeralClient.ping().then(({ metadata, value }) => ({ + agentId: metadata.agentId, + idempotencyKey: metadata.idempotencyKey, + value, + })); + + const sharedContract = defineAgentClient({ + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + void agentId.client(sharedContract).ping(); + void agentId.dynamicClient().method('ping'); + // @ts-expect-error lifecycle mode belongs to exact constructor definitions, not ID bindings + defineAgentClient({ mode: 'durable', methods: sharedContract.methods }); + // @ts-expect-error name-only ID bindings do not carry lifecycle mode either + defineAgentClient({ name: 'Named', mode: 'ephemeral', methods: sharedContract.methods }); + // @ts-expect-error binding definitions expose no synthetic lifecycle mode + void sharedContract.mode; + // @ts-expect-error method-only contracts do not construct exact-target identities + sharedContract.agentId({}); + // @ts-expect-error method-only contracts do not expose constructor-based factories + sharedContract.client.get({}); + const ephemeralId = { name: z.string() }; const ephemeralMethods = { ping: method({ input: {}, returns: z.string() }) }; // @ts-expect-error an ephemeral AgentSpec must explicitly select ephemeral runtime behavior @@ -523,12 +566,227 @@ describe('RPC client', () => { scheduleCancelableInvocation: ReturnType; }; + it('exposes a cached client factory on authored agent definitions', () => { + expect(clientDef.client).toBe(clientDef.client); + const client = clientDef.client.get({ name: 'counter' }, { greeting: 'hello' }); + + expect(client.ping).toBeTypeOf('function'); + expect(vi.mocked(WasmRpc).mock.calls.at(-1)![3]).toHaveLength(1); + }); + + it('builds a client-only definition from Standard Schema libraries without registration', () => { + const name = 'RuntimeBuiltClientOnlyAgent'; + const before = AgentTypeRegistry.getRegisteredAgents().length; + const definition = defineAgentClient({ + name, + id: { name: z.string() }, + methods: { ping: method({ input: { message: z.string() }, returns: z.string() }) }, + }); + const client = definition.client.get({ name: 'counter' }); + + expect(client.ping).toBeTypeOf('function'); + expect(AgentTypeRegistry.getRegisteredAgents()).toHaveLength(before); + expect(AgentTypeRegistry.exists(new AgentClassName(name))).toBe(false); + }); + + it('binds one method-only contract to differently shaped existing agent identities', async () => { + const contract = defineAgentClient({ + methods: { ping: method({ input: { message: z.string() }, returns: z.string() }) }, + }); + const first = new ParsedAgentId('FirstAgent(one)'); + const second = new ParsedAgentId('SecondAgent(team,two)'); + vi.mocked(parseAgentId) + .mockReturnValueOnce([ + 'FirstAgent', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]) + .mockReturnValueOnce([ + 'SecondAgent', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('team'), v.string('two')])), + }, + undefined, + ]); + + expect(first.client(contract).ping).toBeTypeOf('function'); + expect(second.client(contract).ping).toBeTypeOf('function'); + expect( + vi + .mocked(WasmRpc.create) + .mock.calls.slice(-2) + .map((call) => call[0]), + ).toEqual(['FirstAgent', 'SecondAgent']); + expect(contract).not.toHaveProperty('mode'); + }); + + it('binds a method-only contract to a durable phantom identity without discovery', () => { + const contract = defineAgentClient({ + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + const phantomId = new Uuid(1n, 2n); + const target = new ParsedAgentId('DurablePhantom(one)[00000000-0000-0001-0000-000000000002]'); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'DurablePhantom', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('one')])), + }, + phantomId, + ]); + + expect(target.client(contract).ping).toBeTypeOf('function'); + expect(vi.mocked(WasmRpc.create).mock.calls.at(-1)![2]).toBe(phantomId); + }); + + it('rejects lifecycle fields on partial JavaScript binding contracts', () => { + expect(() => + defineAgentClient({ + mode: 'durable', + methods: { ping: method({ input: {}, returns: z.string() }) }, + } as any), + ).toThrow( + 'Agent ID binding contracts may only define methods and an optional name; id, config, and mode require a complete exact name + id definition', + ); + }); + + it('binds an exact durable definition to its matching existing identity', () => { + const definition = defineAgentClient({ + name: 'ExactDurableAgent', + id: { name: z.string() }, + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + const target = new ParsedAgentId('ExactDurableAgent(one)'); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ExactDurableAgent', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + + expect(target.client(definition).ping).toBeTypeOf('function'); + }); + + it('rejects binding an exact ephemeral definition to an existing identity', () => { + const definition = defineAgentClient({ + name: 'ExactEphemeralAgent', + mode: 'ephemeral', + id: { name: z.string() }, + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + const target = new ParsedAgentId('ExactEphemeralAgent(one)'); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ExactEphemeralAgent', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + const creates = vi.mocked(WasmRpc.create).mock.calls.length; + + expect(() => target.client(definition)).toThrow( + "Cannot bind existing ParsedAgentId 'ExactEphemeralAgent(one)' to ephemeral agent type 'ExactEphemeralAgent'; use its client.newPhantom(...) factory", + ); + expect(WasmRpc.create).toHaveBeenCalledTimes(creates); + }); + + it('checks an optional exact name locally before creating the remote client', () => { + const contract = defineAgentClient({ + name: 'ExpectedAgent', + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + const target = new ParsedAgentId('OtherAgent(one)'); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'OtherAgent', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('one')])), + }, + undefined, + ]); + const creates = vi.mocked(WasmRpc.create).mock.calls.length; + + expect(() => target.client(contract)).toThrow( + "Agent client contract 'ExpectedAgent' cannot bind agent type 'OtherAgent'", + ); + expect(WasmRpc.create).toHaveBeenCalledTimes(creates); + }); + + it('surfaces an incompatible target method as a structured remote error', async () => { + const contract = defineAgentClient({ + methods: { analyze: method({ input: { topic: z.string() }, returns: z.string() }) }, + }); + const target = new ParsedAgentId('ReportArchive(reports)'); + vi.mocked(parseAgentId).mockReturnValueOnce([ + 'ReportArchive', + { + graph: { typeNodes: [], defs: [], root: 0 }, + value: schemaValueToWit(v.record([v.string('reports')])), + }, + undefined, + ]); + const client = target.client(contract); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; + rpc.asyncInvokeAndAwait.mockReturnValue({ + metadata: { agentId: target.value, idempotencyKey: 'key' }, + future: { + get: vi.fn().mockRejectedValue({ + tag: 'remote-agent-error', + val: { tag: 'invalid-method', val: 'analyze is not defined' }, + }), + cancel: vi.fn(), + }, + }); + + await expect(client.analyze({ topic: 'demand' })).rejects.toMatchObject({ + cause: { + tag: 'remote-agent-error', + error: { tag: 'invalid-method', details: 'analyze is not defined' }, + }, + }); + }); + + it('surfaces client creation failures for runtime-built reflection definitions', () => { + const rpcError = { tag: 'not-found' as const, val: 'missing deployment' }; + const definition = defineAgentClient({ + name: 'FallibleClientDefinitionAgent', + id: {}, + methods: { ping: method({ input: {}, returns: z.string() }) }, + }); + vi.mocked(WasmRpc.create).mockImplementationOnce(() => { + throw rpcError; + }); + + expect(() => definition.client.get({})).toThrow(RemoteCallError); + }); + + it('constructs identity on the definition even when a method name would collide', () => { + const phantomId = new Uuid(1n, 2n); + const def = defineAgentClient({ + name: 'ClientIdentityAgent', + id: {}, + methods: { agentId: method({ input: {}, returns: z.string() }) }, + }); + const client = def.client.getPhantom({}, phantomId); + + expect(client.agentId).toBeTypeOf('function'); + expect(def.agentId({}, phantomId).value).toBe('MockAgent()'); + }); + it('creates a fresh phantom client and exposes the generated id', () => { const phantomId = new Uuid(1n, 2n); const generate = vi.spyOn(Uuid, 'generate').mockReturnValue(phantomId); - const phantom = clientFor(clientDef).newPhantom({ name: 'counter' }, { greeting: 'hello' }); + const phantom = clientDef.client.newPhantom({ name: 'counter' }, { greeting: 'hello' }); expect(phantom.phantomId).toBe(phantomId); + expect(phantom.agentId).toEqual(clientDef.agentId({ name: 'counter' }, phantomId)); expect(phantom.client.ping).toBeTypeOf('function'); const constructorArgs = vi.mocked(WasmRpc).mock.calls.at(-1)!; expect(constructorArgs[2]).toBe(phantomId); @@ -544,14 +802,14 @@ describe('RPC client', () => { phantomId: method({ input: {}, returns: z.string() }), }, }); - const phantom = clientFor(def).newPhantom({}); + const phantom = def.client.newPhantom({}); expect(typeof phantom.client.phantomId).toBe('function'); expect(phantom.phantomId).toBeInstanceOf(Uuid); }); it('returns cancellation tokens from schedule and removes the old operations', () => { - const client = clientFor(clientDef)({ name: 'counter' }); + const client = clientDef.client.get({ name: 'counter' }); const rpc = latestRpc(); const token = { cancel: vi.fn() }; rpc.scheduleCancelableInvocation.mockReturnValue({ @@ -581,7 +839,7 @@ describe('RPC client', () => { }); const raw = { id: 'client-capability' } as never; const capability = compileSchema(s.secret(z.string())); - const client = clientFor(def)({}); + const client = def.client.get({}); expect(() => client.send.trigger({ @@ -595,15 +853,15 @@ describe('RPC client', () => { }); it('uses one logical client for ephemeral invocations and returns final identity metadata', async () => { - const ephemeralDef = defineAgent({ + const ephemeralDef = defineAgentClient({ name: 'EphemeralClientTestAgent', mode: 'ephemeral', id: { name: z.string() }, methods: { ping: method({ input: {}, returns: z.void() }) }, }); const makeAgentIdCalls = vi.mocked(makeAgentId).mock.calls.length; - const client = clientFor(ephemeralDef).newPhantom({ name: 'counter' }); - const rpc = latestRpc(); + const client = ephemeralDef.client.newPhantom({ name: 'counter' }); + const rpc = vi.mocked(WasmRpc.create).mock.results.at(-1)!.value; const metadata = { agentId: 'final-agent-id', idempotencyKey: 'key' }; const future = { subscribe: vi.fn().mockReturnValue({ promise: vi.fn().mockResolvedValue(undefined) }), @@ -618,7 +876,7 @@ describe('RPC client', () => { await expect(client.ping()).resolves.toEqual({ metadata, value: undefined }); expect(client.ping.trigger()).toBe(metadata); expect(client.ping.schedule({ seconds: 1n, nanoseconds: 0 })).toBe(receipt); - expect(vi.mocked(WasmRpc).mock.calls.at(-1)![2]).toBeUndefined(); + expect(vi.mocked(WasmRpc.create).mock.calls.at(-1)![2]).toBeUndefined(); expect(vi.mocked(makeAgentId).mock.calls).toHaveLength(makeAgentIdCalls); }); @@ -631,7 +889,7 @@ describe('RPC client', () => { const phantomId = new Uuid(1n, 2n); const agentId = 'MissingSingleOutputAgent(1)[00000000-0000-0001-0000-000000000002]'; vi.mocked(makeAgentId).mockReturnValueOnce(agentId); - const client = clientFor(def)({ id: 1n }, phantomId); + const client = def.client.getPhantom({ id: 1n }, phantomId); const rpc = latestRpc(); rpc.asyncInvokeAndAwait.mockReturnValue({ metadata: { agentId: 'agent-id', idempotencyKey: 'key' }, @@ -659,7 +917,7 @@ describe('RPC client', () => { methods: { ping: method({ input: {}, returns: z.string() }) }, }); vi.mocked(makeAgentId).mockReturnValueOnce('MismatchedSingleOutputAgent()'); - const client = clientFor(def)({}); + const client = def.client.get({}); const rpc = latestRpc(); rpc.asyncInvokeAndAwait.mockReturnValue({ metadata: { agentId: 'agent-id', idempotencyKey: 'key' }, @@ -670,7 +928,7 @@ describe('RPC client', () => { }, }); - await expect(client.ping()).rejects.toBeInstanceOf(RemoteCallError); + await expect(client.ping()).rejects.toBeInstanceOf(RemoteOutputError); }); it('preserves RemoteCallError when a remote custom error contains bigint values', async () => { @@ -680,7 +938,7 @@ describe('RPC client', () => { methods: { ping: method({ input: {}, returns: z.string() }) }, }); vi.mocked(makeAgentId).mockReturnValueOnce('BigintRemoteErrorAgent()'); - const client = clientFor(def)({}); + const client = def.client.get({}); const rpc = latestRpc(); const errorCodec = compileSchema(s.u64()); rpc.asyncInvokeAndAwait.mockReturnValue({ @@ -701,7 +959,31 @@ describe('RPC client', () => { }, }); - await expect(client.ping()).rejects.toBeInstanceOf(RemoteCallError); + try { + await client.ping(); + throw new Error('expected the remote call to fail'); + } catch (error) { + expect(isRemoteCallError(error)).toBe(true); + if (!isRemoteCallError(error)) throw error; + expect(error.cause).toMatchObject({ + tag: 'remote-agent-error', + error: { + tag: 'custom-error', + value: { value: { tag: 'u64', value: 1n } }, + }, + }); + } + }); + + it('narrows RemoteCallError structurally across package entry identities', () => { + expect( + isRemoteCallError({ + _tag: 'RemoteCallError', + message: 'Remote call failed', + cause: { tag: 'denied', details: 'not allowed' }, + }), + ).toBe(true); + expect(isRemoteCallError(new Error('not remote'))).toBe(false); }); it('omits auto-injected principal fields from RPC constructor input', () => { @@ -710,16 +992,21 @@ describe('RPC client', () => { id: { tenant: z.string(), caller: s.principal() }, methods: { ping: method({ input: {}, returns: z.void() }) }, }); - const factory = clientFor(def); + const factory = def.client; - expect(() => - (factory as unknown as (id: { tenant: string }) => unknown)({ tenant: 'acme' }), - ).not.toThrow(); + expect(() => factory.get({ tenant: 'acme' })).not.toThrow(); const constructorTree = vi.mocked(WasmRpc).mock.calls.at(-1)![1]; expect(schemaValueFromWit(constructorTree)).toEqual({ tag: 'record', fields: [{ tag: 'string', value: 'acme' }], }); + + expect(() => def.agentId({ tenant: 'acme' })).not.toThrow(); + const identityTree = vi.mocked(makeAgentId).mock.calls.at(-1)![1]; + expect(schemaValueFromWit(identityTree)).toEqual({ + tag: 'record', + fields: [{ tag: 'string', value: 'acme' }], + }); }); it('treats an empty config object as containing no RPC overrides', () => { @@ -730,7 +1017,7 @@ describe('RPC client', () => { methods: { ping: method({ input: {}, returns: z.void() }) }, }); - clientFor(def)({}, undefined, {}); + def.client.get({}, {}); expect(vi.mocked(WasmRpc).mock.calls.at(-1)![3]).toEqual([]); }); @@ -743,11 +1030,11 @@ describe('RPC client', () => { methods: { ping: method({ input: {}, returns: z.void() }) }, }); - expect(() => clientFor(def)({}, undefined, { nested: 'not-an-object' })).toThrow(); + expect(() => def.client.get({}, { nested: 'not-an-object' })).toThrow(); }); it('accepts cancellation options on input and zero-input calls', async () => { - const client = clientFor(clientDef)({ name: 'counter' }); + const client = clientDef.client.get({ name: 'counter' }); const rpc = latestRpc(); const controller = new AbortController(); controller.abort('cancelled'); diff --git a/sdks/ts/packages/golem-ts-sdk/tests/testSetup.ts b/sdks/ts/packages/golem-ts-sdk/tests/testSetup.ts index e08cf6598f..a0db6d1f8d 100644 --- a/sdks/ts/packages/golem-ts-sdk/tests/testSetup.ts +++ b/sdks/ts/packages/golem-ts-sdk/tests/testSetup.ts @@ -18,9 +18,21 @@ import { AgentClassName } from '../src/agentClassName'; // The production runtime boundary now targets `golem:agent/host@2.0.0`. Mock its // registry and RPC surfaces; tests that inspect an agent ID configure the exact // canonical host result they expect. +const makeWasmRpc = () => ({ + invokeAndAwait: vi.fn(), + invoke: vi.fn(), + asyncInvokeAndAwait: vi.fn(), + scheduleInvocation: vi.fn(), + scheduleCancelableInvocation: vi.fn(), +}); + +const MockWasmRpc = Object.assign(vi.fn(makeWasmRpc), { + create: vi.fn(makeWasmRpc), +}); + vi.mock('golem:agent/host@2.0.0', () => ({ - getAllAgentTypes: () => [], - getAgentType: (agentTypeName: string) => { + getAllAgentTypes: vi.fn(() => []), + getAgentType: vi.fn((agentTypeName: string) => { if (agentTypeName === 'FooAgent') { const agentType = AgentTypeRegistry.get(new AgentClassName('FooAgent')); if (!agentType) { @@ -32,9 +44,10 @@ vi.mock('golem:agent/host@2.0.0', () => ({ }; } return undefined; - }, + }), + getAgentTypeByAgentId: vi.fn(() => undefined), makeAgentId: vi.fn(() => 'MockAgent()'), - parseAgentId: (agentId: string) => { + parseAgentId: vi.fn((agentId: string) => { const match = agentId.match(/^(.*)\((.*)\)(\[(\d+)-(\d+)])?$/); if (!match) { throw new Error(`Invalid agent ID: ${agentId}`); @@ -51,18 +64,12 @@ vi.mock('golem:agent/host@2.0.0', () => ({ phantomId = { highBits: BigInt(hiBits), lowBits: BigInt(loBits) }; } return [typeName, typed, phantomId]; - }, + }), getConfigValue: () => { throw new Error('getConfigValue is not mocked in this test setup'); }, createWebhook: () => 'https://example.com/webhook', - WasmRpc: vi.fn().mockImplementation(() => ({ - invokeAndAwait: vi.fn(), - invoke: vi.fn(), - asyncInvokeAndAwait: vi.fn(), - scheduleInvocation: vi.fn(), - scheduleCancelableInvocation: vi.fn(), - })), + WasmRpc: MockWasmRpc, })); vi.mock('golem:tool/host@0.1.0', () => ({ @@ -100,6 +107,22 @@ vi.mock('golem:core/types@2.0.0', () => ({ }, })); +vi.mock('golem:api/host@1.5.0', () => ({ + getSelfMetadata: vi.fn(() => ({ + agentId: { + componentId: { uuid: { highBits: 0n, lowBits: 1n } }, + agentId: 'TestAgent()', + }, + args: [], + env: [], + config: [], + status: 'idle', + componentRevision: 0n, + retryCount: 0n, + environmentId: { uuid: { highBits: 0n, lowBits: 2n } }, + })), +})); + vi.mock('golem:api/oplog@1.5.0', () => ({ GetOplog: vi.fn(), SearchOplog: vi.fn(), diff --git a/sdks/ts/packages/golem-ts-sdk/tests/utf8.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/utf8.test.ts new file mode 100644 index 0000000000..b27548a729 --- /dev/null +++ b/sdks/ts/packages/golem-ts-sdk/tests/utf8.test.ts @@ -0,0 +1,31 @@ +// Copyright 2024-2026 Golem Cloud +// +// Licensed under the Golem Source License v1.1 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://license.golem.cloud/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { describe, expect, it } from 'vitest'; +import { decodeUtf8 } from '../src/internal/utf8'; + +const encoder = new TextEncoder(); + +describe('strict UTF-8 decoding', () => { + it('reuses the decoder across repeated complete payloads', () => { + expect(decodeUtf8(encoder.encode('first'))).toBe('first'); + expect(decodeUtf8(encoder.encode('árvíztűrő tükörfúrógép'))).toBe('árvíztűrő tükörfúrógép'); + expect(decodeUtf8(encoder.encode('third'))).toBe('third'); + }); + + it('rejects malformed UTF-8 and remains usable afterward', () => { + expect(() => decodeUtf8(Uint8Array.from([0xc3, 0x28]))).toThrow(); + expect(decodeUtf8(encoder.encode('valid afterward'))).toBe('valid afterward'); + }); +}); diff --git a/sdks/ts/packages/golem-ts-sdk/tsconfig.type-tests.json b/sdks/ts/packages/golem-ts-sdk/tsconfig.type-tests.json index 714f0c1c7f..d27db2f8d9 100644 --- a/sdks/ts/packages/golem-ts-sdk/tsconfig.type-tests.json +++ b/sdks/ts/packages/golem-ts-sdk/tsconfig.type-tests.json @@ -4,5 +4,5 @@ "declaration": false, "noEmit": true }, - "include": ["tests/tool.test-d.ts", "types/**/*.d.ts"] + "include": ["tests/entrypoints.test-d.ts", "tests/tool.test-d.ts", "types/**/*.d.ts"] } diff --git a/sdks/ts/packages/golem-ts-sdk/types/golem_agent_2_0_0_host.d.ts b/sdks/ts/packages/golem-ts-sdk/types/golem_agent_2_0_0_host.d.ts index 4272c4bad2..6a2d61b498 100644 --- a/sdks/ts/packages/golem-ts-sdk/types/golem_agent_2_0_0_host.d.ts +++ b/sdks/ts/packages/golem-ts-sdk/types/golem_agent_2_0_0_host.d.ts @@ -10,6 +10,10 @@ declare module 'golem:agent/host@2.0.0' { * Get a specific registered agent type by name */ export function getAgentType(agentTypeName: string): RegisteredAgentType | undefined; + /** + * Gets the registered agent type used by an existing agent, identified by its agent ID. + */ + export function getAgentTypeByAgentId(agentId: string): RegisteredAgentType | undefined; /** * Constructs a string agent-id from the agent type and its constructor parameters * and an optional phantom ID. @@ -36,11 +40,21 @@ declare module 'golem:agent/host@2.0.0' { export function getConfigValue(key: string[], expected: SchemaGraph): SchemaValueTree; export class WasmRpc { /** - * Constructs the RPC client connecting to the given target agent. + * Creates an RPC client connecting to the given target agent. * `constructor` is a value tree whose root encodes the target agent - * constructor's parameter list. + * constructor's parameter list. This fail-fast form traps if the client + * cannot be created and is intended for statically generated clients. */ constructor(agentTypeName: string, constructor: SchemaValueTree, phantomId: Uuid | undefined, agentConfig: TypedAgentConfigValue[]); + /** + * Creates an RPC client connecting to the given target agent. + * `constructor` is a value tree whose root encodes the target agent + * constructor's parameter list. This fallible form returns an RPC error + * if the client cannot be created and is intended for reflective and + * other dynamic clients. + * @throws RpcError + */ + static create(agentTypeName: string, constructor: SchemaValueTree, phantomId: Uuid | undefined, agentConfig: TypedAgentConfigValue[]): WasmRpc; /** * Invokes a remote method with the given parameters, and awaits the result. * `input` encodes the method's parameter list. The returned result is @@ -91,7 +105,6 @@ declare module 'golem:agent/host@2.0.0' { */ cancel(): void; } - export type ComponentId = golemCore200Types.ComponentId; export type Uuid = golemCore200Types.Uuid; export type PromiseId = golemCore200Types.PromiseId; export type SchemaGraph = golemCore200Types.SchemaGraph; diff --git a/sdks/ts/wit/deps/golem-agent/host.wit b/sdks/ts/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/sdks/ts/wit/deps/golem-agent/host.wit +++ b/sdks/ts/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is diff --git a/test-components/agent-constructor-parameter-echo/AGENTS.md b/test-components/agent-constructor-parameter-echo/AGENTS.md index 869c100209..02fe49ad4c 100644 --- a/test-components/agent-constructor-parameter-echo/AGENTS.md +++ b/test-components/agent-constructor-parameter-echo/AGENTS.md @@ -27,7 +27,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -254,15 +254,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/agent-promise/AGENTS.md b/test-components/agent-promise/AGENTS.md index 61de8f8686..02fe49ad4c 100644 --- a/test-components/agent-promise/AGENTS.md +++ b/test-components/agent-promise/AGENTS.md @@ -27,7 +27,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -36,7 +36,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-wait-for-external-input-ts` | Waiting for external input using Golem promises (human-in-the-loop) | | `golem-add-webhook-ts` | Creating and awaiting webhooks for webhook-driven external APIs | | `golem-multi-instance-agent-ts` | Creating multiple agent instances with phantom agents | -| `golem-atomic-block-ts` | Atomic blocks, persistence control, and idempotency | +| `golem-atomic-block-ts` | Atomic blocks and idempotency | | `golem-add-transactions-ts` | Saga-pattern transactions with compensation | | `golem-add-http-endpoint-ts` | Exposing an agent over HTTP with mount paths and endpoints | | `golem-http-params-ts` | Mapping path, query, header, and body parameters for HTTP endpoints | @@ -254,15 +254,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/agent-rpc/AGENTS.md b/test-components/agent-rpc/AGENTS.md index 1e4638b062..b8abdca8a4 100644 --- a/test-components/agent-rpc/AGENTS.md +++ b/test-components/agent-rpc/AGENTS.md @@ -500,7 +500,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -727,15 +727,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/agent-rpc/golem-it-agent-rpc-rust/src/lib.rs b/test-components/agent-rpc/golem-it-agent-rpc-rust/src/lib.rs index 57b19d4ffb..1abfc627fd 100644 --- a/test-components/agent-rpc/golem-it-agent-rpc-rust/src/lib.rs +++ b/test-components/agent-rpc/golem-it-agent-rpc-rust/src/lib.rs @@ -35,6 +35,7 @@ pub trait RustParent { async fn spawn_child(&self, data: String) -> Uuid; async fn call_ts_agent(&self, name: String) -> f64; + fn inspect_missing_rpc_type(&self) -> String; } struct RustParentImpl { @@ -63,6 +64,15 @@ impl RustParent for RustParentImpl { let client = SimpleChildAgentClient::get(name); client.value().await } + + fn inspect_missing_rpc_type(&self) -> String { + let constructor = encode_schema_value(&SchemaValue::Record { fields: Vec::new() }) + .expect("failed to encode empty RPC constructor"); + match WasmRpc::create("MissingReflectedType", constructor, None, Vec::new()) { + Ok(_) => "unexpected success".to_string(), + Err(error) => format!("{error:?}"), + } + } } #[agent_definition] diff --git a/test-components/agent-rpc/golem-it-agent-rpc/src/main.ts b/test-components/agent-rpc/golem-it-agent-rpc/src/main.ts index c496eeae93..5ba4ea52d2 100644 --- a/test-components/agent-rpc/golem-it-agent-rpc/src/main.ts +++ b/test-components/agent-rpc/golem-it-agent-rpc/src/main.ts @@ -1,14 +1,19 @@ import { z } from "zod"; import { + ParsedAgentId, AgentStream, + awaitPromise, + createPromise, defineAgent, + defineAgentClient, + getAgentTypeByAgentId, + getAllAgentTypes, + getReflectedAgentType, + isRemoteCallError, method, s, - clientFor, - createPromise, - awaitPromise, } from "@golemcloud/golem-ts-sdk"; -import type { PromiseId } from "golem:api/host@1.5.0"; +import { type PromiseId } from "golem:api/host@1.5.0"; import * as process from "node:process"; const EnvVar = z.object({ key: z.string(), value: z.string() }); @@ -38,8 +43,6 @@ export const ChildAgent = defineAgent({ }, }); -const childClient = clientFor(ChildAgent); - export const ChildAgentImpl = ChildAgent.implement({ init: ({ id }) => ({ id: id.id }), methods: { @@ -62,6 +65,56 @@ export const ChildAgentImpl = ChildAgent.implement({ }, }); +const EphemeralReuseReport = z.object({ + value: z.string(), + agentId: z.string(), + idempotencyKey: z.string(), + category: z.string(), + errorTag: z.string(), + details: z.string(), +}); + +const ReflectionDiscoveryReport = z.object({ + listed: z.boolean(), + typeName: z.string(), + methodName: z.string(), + firstValue: z.string(), + secondValue: z.string(), + missingName: z.boolean(), + missingAgentId: z.boolean(), +}); + +const ReflectedEphemeralReport = z.object({ + value: z.string(), + agentId: z.string(), + idempotencyKey: z.string(), + proxyHasAgentId: z.boolean(), +}); + +export const EphemeralSingleUseAgent = defineAgent({ + name: "EphemeralSingleUseAgent", + mode: "ephemeral", + id: { value: z.string() }, + methods: { + capture: method({ input: {}, returns: z.string() }), + }, +}); + +export const EphemeralSingleUseAgentImpl = EphemeralSingleUseAgent.implement({ + init: ({ id }) => ({ value: id.value }), + methods: { + capture() { + return this.value; + }, + }, +}); + +const EphemeralReuseContract = defineAgentClient({ + methods: { + capture: method({ input: {}, returns: z.string() }), + }, +}); + export const TestAgent = defineAgent({ name: "TestAgent", id: { id: z.string() }, @@ -75,6 +128,15 @@ export const TestAgent = defineAgent({ input: { durationInMillis: z.number() }, returns: z.void(), }), + ephemeralReuseTest: method({ input: {}, returns: EphemeralReuseReport }), + reflectionDiscoveryTest: method({ + input: {}, + returns: ReflectionDiscoveryReport, + }), + reflectedEphemeralTest: method({ + input: {}, + returns: ReflectedEphemeralReport, + }), }, }); @@ -89,14 +151,14 @@ export const TestAgentImpl = TestAgent.implement({ for (const chunk of chunks) { console.log(`Processing chunk ${chunk}`); const promises = chunk.map( - async (id) => await childClient({ id }).process(), + async (id) => await ChildAgent.client.get({ id }).process(), ); result.push(...(await Promise.all(promises))); } return result; }, async envVarTest() { - const child = await childClient({ id: 0 }).envVars(); + const child = await ChildAgent.client.get({ id: 0 }).envVars(); const parent = Object.entries(process.env).map(([key, value]) => ({ key, value: value ?? "", @@ -107,7 +169,118 @@ export const TestAgentImpl = TestAgent.implement({ }; }, async longRpcCall({ durationInMillis }) { - await childClient({ id: 1000 }).longRpcCall({ durationInMillis }); + await ChildAgent.client.get({ id: 1000 }).longRpcCall({ + durationInMillis, + }); + }, + async ephemeralReuseTest() { + const first = await EphemeralSingleUseAgent.client + .newPhantom({ value: "captured" }) + .capture(); + const finalAgentId = new ParsedAgentId(first.metadata.agentId); + + try { + await finalAgentId.client(EphemeralReuseContract).capture(); + throw new Error("ephemeral agent identity was unexpectedly reusable"); + } catch (error) { + if (!isRemoteCallError(error)) throw error; + if (error.cause.tag !== "remote-agent-error") { + throw new Error( + `expected remote-agent-error, got ${error.cause.tag}`, + ); + } + if (error.cause.error.tag === "custom-error") { + throw new Error("expected a structured invalid-input error"); + } + return { + value: first.value, + agentId: first.metadata.agentId, + idempotencyKey: first.metadata.idempotencyKey, + category: error.cause.tag, + errorTag: error.cause.error.tag, + details: error.cause.error.details, + }; + } + }, + async reflectionDiscoveryTest() { + const targetName = `reflection-${this.id}`; + const allTypes = getAllAgentTypes(); + const reflected = getReflectedAgentType("Counter"); + if (!reflected) throw new Error("Counter was not discovered"); + + const method = reflected.method("get_value"); + if (!method) throw new Error("Counter.get_value was not discovered"); + + const missingAgentId = reflected.agentId({ + id: `${targetName}-missing`, + }); + const missingAgentIdResult = + getAgentTypeByAgentId(missingAgentId) === undefined; + + const first = await reflected.client + .get({ id: targetName }) + .method("get_value") + .invoke({}); + if (typeof first.value !== "string") { + throw new Error( + "expected reflected Counter.get_value to return a string", + ); + } + + const concreteAgentId = reflected.agentId({ id: targetName }); + const byAgentId = getAgentTypeByAgentId(concreteAgentId); + if (!byAgentId) { + throw new Error("existing Counter type was not resolved"); + } + + const second = await concreteAgentId + .client(byAgentId) + .method("get_value") + .invoke({}); + if (typeof second.value !== "string") { + throw new Error( + "expected rebound Counter.get_value to return a string", + ); + } + + return { + listed: allTypes.some((agentType) => agentType.name === reflected.name), + typeName: reflected.name, + methodName: method.name, + firstValue: first.value, + secondValue: second.value, + missingName: + getReflectedAgentType("MissingReflectionAgent") === undefined, + missingAgentId: missingAgentIdResult, + }; + }, + async reflectedEphemeralTest() { + const reflected = getReflectedAgentType("EphemeralSingleUseAgent"); + if (!reflected || reflected.mode !== "ephemeral") { + throw new Error( + "EphemeralSingleUseAgent was not discovered as ephemeral", + ); + } + + const fresh = reflected.client.newPhantom({ value: "reflected" }); + const proxyHasAgentId = "agentId" in fresh; + if ("client" in fresh) { + throw new Error("ephemeral reflection returned a durable wrapper"); + } + + const invocation = await fresh.method("capture").invoke({}); + if (typeof invocation.value !== "string") { + throw new Error( + "expected reflected ephemeral capture to return a string", + ); + } + + return { + value: invocation.value, + agentId: invocation.metadata.agentId, + idempotencyKey: invocation.metadata.idempotencyKey, + proxyHasAgentId, + }; }, }, }); @@ -138,8 +311,6 @@ export const SelfRpcAgent = defineAgent({ }, }); -const selfRpcClient = clientFor(SelfRpcAgent); - export const SelfRpcAgentImpl = SelfRpcAgent.implement({ init: ({ id }) => ({ name: id.name }), methods: { @@ -147,7 +318,7 @@ export const SelfRpcAgentImpl = SelfRpcAgent.implement({ return; }, async selfRpc() { - return selfRpcClient({ name: this.name }).doWork(); + return SelfRpcAgent.client.get({ name: this.name }).doWork(); }, }, }); @@ -216,9 +387,6 @@ export const TsBlockingAgentImpl = TsBlockingAgent.implement({ }, }); -const tsCounterClient = clientFor(TsCounter); -const tsBlockingClient = clientFor(TsBlockingAgent); - export const TsCancelTester = defineAgent({ name: "TsCancelTester", id: { name: z.string() }, @@ -242,7 +410,7 @@ export const TsCancelTesterImpl = TsCancelTester.implement({ * short delay, and returns "aborted" if the AbortError is caught. */ async testAbortBeforeAwait({ counterName }) { - const counter = tsCounterClient({ name: counterName }); + const counter = TsCounter.client.get({ name: counterName }); const controller = new AbortController(); // Abort after 100ms — slowIncBy takes 5000ms so it is still pending. @@ -267,7 +435,7 @@ export const TsCancelTesterImpl = TsCancelTester.implement({ * Returns the counter value. */ async testAbortAfterComplete({ counterName }) { - const counter = tsCounterClient({ name: counterName }); + const counter = TsCounter.client.get({ name: counterName }); const controller = new AbortController(); // Completes quickly. @@ -297,7 +465,7 @@ export const TsCancelCallerAgentImpl = TsCancelCallerAgent.implement({ init: ({ id }) => ({ name: id.name, lastOutcome: "none" }), methods: { async callAndAbort({ targetName, delayMs }) { - const blocker = tsBlockingClient({ name: targetName }); + const blocker = TsBlockingAgent.client.get({ name: targetName }); const controller = new AbortController(); const timer = setTimeout( @@ -472,8 +640,6 @@ export const TsStreamingRpcTargetImpl = TsStreamingRpcTarget.implement({ }, }); -const tsStreamingTargetClient = clientFor(TsStreamingRpcTarget); - export const TsStreamingRpcCaller = defineAgent({ name: "TsStreamingRpcCaller", id: { name: z.string() }, @@ -488,7 +654,7 @@ export const TsStreamingRpcCallerImpl = TsStreamingRpcCaller.implement({ init: ({ id }) => ({ name: id.name }), methods: { async run() { - const target = tsStreamingTargetClient({ name: this.name }); + const target = TsStreamingRpcTarget.client.get({ name: this.name }); const inputOnly = await target.consume({ input: AgentStream.from([1, 2, 3]), @@ -553,15 +719,15 @@ export const TsStreamingRpcCallerImpl = TsStreamingRpcCaller.implement({ }, async callProducerError() { return collect( - await tsStreamingTargetClient({ - name: this.name, - }).produceError(), + await TsStreamingRpcTarget.client + .get({ name: this.name }) + .produceError(), ); }, async callStreamFree() { - return tsStreamingTargetClient({ - name: this.name, - }).incrementScalar(); + return TsStreamingRpcTarget.client + .get({ name: this.name }) + .incrementScalar(); }, }, }); diff --git a/test-components/agent-sdk-ts/AGENTS.md b/test-components/agent-sdk-ts/AGENTS.md index 61de8f8686..02fe49ad4c 100644 --- a/test-components/agent-sdk-ts/AGENTS.md +++ b/test-components/agent-sdk-ts/AGENTS.md @@ -27,7 +27,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -36,7 +36,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-wait-for-external-input-ts` | Waiting for external input using Golem promises (human-in-the-loop) | | `golem-add-webhook-ts` | Creating and awaiting webhooks for webhook-driven external APIs | | `golem-multi-instance-agent-ts` | Creating multiple agent instances with phantom agents | -| `golem-atomic-block-ts` | Atomic blocks, persistence control, and idempotency | +| `golem-atomic-block-ts` | Atomic blocks and idempotency | | `golem-add-transactions-ts` | Saga-pattern transactions with compensation | | `golem-add-http-endpoint-ts` | Exposing an agent over HTTP with mount paths and endpoints | | `golem-http-params-ts` | Mapping path, query, header, and body parameters for HTTP endpoints | @@ -254,15 +254,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/agent-sdk-ts/src/config.ts b/test-components/agent-sdk-ts/src/config.ts index 7fa11be788..7e93977ee7 100644 --- a/test-components/agent-sdk-ts/src/config.ts +++ b/test-components/agent-sdk-ts/src/config.ts @@ -3,7 +3,6 @@ import { defineAgent, method, s, - clientFor, awaitPromise, createPromise, } from '@golemcloud/golem-ts-sdk'; @@ -258,11 +257,9 @@ export const NestedRequiredGroupConfigAgentImpl = NestedRequiredGroupConfigAgent }); // `RpcLocalConfigAgent` invokes `LocalConfigAgent` with per-call config -// overrides via the config-on-RPC form `clientFor(def)(id, phantomId?, config)`: +// overrides via `definition.client.get(id, config)`: // the non-secret override leaves present in `config` are encoded into the target // `WasmRpc`'s `agentConfig` list (see `agent_config/rpc.rs`). -const localConfigClient = clientFor(LocalConfigAgent); - export const RpcLocalConfigAgent = defineAgent({ name: 'RpcLocalConfigAgent', id: { name: z.string() }, @@ -287,7 +284,7 @@ export const RpcLocalConfigAgentImpl = RpcLocalConfigAgent.implement({ if (config.nested_a !== undefined) { overrides.nested = { a: config.nested_a }; } - const client = localConfigClient({ _name: this.name }, undefined, overrides); + const client = LocalConfigAgent.client.get({ _name: this.name }, overrides); return await client.echoLocalConfig(); }, }, diff --git a/test-components/agent-sdk-ts/src/quota_rpc.ts b/test-components/agent-sdk-ts/src/quota_rpc.ts index 10a7439cca..b34822297a 100644 --- a/test-components/agent-sdk-ts/src/quota_rpc.ts +++ b/test-components/agent-sdk-ts/src/quota_rpc.ts @@ -20,7 +20,7 @@ // handles `s.quotaToken()` carries — to keep the RPC-passing behavior faithful. import { z } from 'zod'; -import { defineAgent, method, s, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, s } from '@golemcloud/golem-ts-sdk'; import { newToken, reserve, @@ -64,8 +64,6 @@ export const QuotaRpcReceiverImpl = QuotaRpcReceiver.implement({ }, }); -const receiverClient = clientFor(QuotaRpcReceiver); - export const QuotaRpcSender = defineAgent({ name: 'QuotaRpcSender', id: { name: z.string() }, @@ -92,7 +90,7 @@ export const QuotaRpcSenderImpl = QuotaRpcSender.implement({ const childToken = split(token, BigInt(childExpectedUse)); const receiverName = `${this.name}-receiver`; - receiverClient({ _name: receiverName }).reserveAndCallInLoop.trigger({ + QuotaRpcReceiver.client.get({ _name: receiverName }).reserveAndCallInLoop.trigger({ childToken, host, port, diff --git a/test-components/agent-self-rpc/AGENTS.md b/test-components/agent-self-rpc/AGENTS.md index 61de8f8686..02fe49ad4c 100644 --- a/test-components/agent-self-rpc/AGENTS.md +++ b/test-components/agent-self-rpc/AGENTS.md @@ -27,7 +27,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -36,7 +36,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-wait-for-external-input-ts` | Waiting for external input using Golem promises (human-in-the-loop) | | `golem-add-webhook-ts` | Creating and awaiting webhooks for webhook-driven external APIs | | `golem-multi-instance-agent-ts` | Creating multiple agent instances with phantom agents | -| `golem-atomic-block-ts` | Atomic blocks, persistence control, and idempotency | +| `golem-atomic-block-ts` | Atomic blocks and idempotency | | `golem-add-transactions-ts` | Saga-pattern transactions with compensation | | `golem-add-http-endpoint-ts` | Exposing an agent over HTTP with mount paths and endpoints | | `golem-http-params-ts` | Mapping path, query, header, and body parameters for HTTP endpoints | @@ -254,15 +254,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/agent-self-rpc/src/main.ts b/test-components/agent-self-rpc/src/main.ts index bf525129bc..69257401eb 100644 --- a/test-components/agent-self-rpc/src/main.ts +++ b/test-components/agent-self-rpc/src/main.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { defineAgent, method, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method } from '@golemcloud/golem-ts-sdk'; export const SelfRpcAgent = defineAgent({ name: 'SelfRpcAgent', @@ -10,8 +10,6 @@ export const SelfRpcAgent = defineAgent({ }, }); -const selfClient = clientFor(SelfRpcAgent); - export const SelfRpcAgentImpl = SelfRpcAgent.implement({ init: ({ id }) => ({ name: id.name }), methods: { @@ -19,7 +17,7 @@ export const SelfRpcAgentImpl = SelfRpcAgent.implement({ return; }, async selfRpc() { - return selfClient({ name: this.name }).doWork(); + return SelfRpcAgent.client.get({ name: this.name }).doWork(); }, }, }); diff --git a/test-components/benchmarks/AGENTS.md b/test-components/benchmarks/AGENTS.md index 7d9eac1228..ee1d7756b9 100644 --- a/test-components/benchmarks/AGENTS.md +++ b/test-components/benchmarks/AGENTS.md @@ -500,7 +500,7 @@ This project includes coding-agent skills in `.agents/skills/`. Load a skill whe | `golem-mark-read-only-ts` | Marking methods `readOnly` for a side-effect-free guarantee and result caching | | `golem-add-config-ts` | Adding typed configuration to a TypeScript agent | | `golem-add-secret-ts` | Adding secrets (`s.secret`, `Secret`) to TypeScript agents | -| `golem-call-another-agent-ts` | Calling another agent and awaiting the result (RPC) with `clientFor` | +| `golem-call-another-agent-ts` | Calling another agent and awaiting the result over RPC through a definition client | | `golem-call-from-external-ts` | Calling agents from external Node.js apps using generated bridge SDKs | | `golem-fire-and-forget-ts` | Triggering an agent invocation without waiting for the result (`.trigger`) | | `golem-parallel-workers-ts` | Fan out work to multiple parallel agents and collect results | @@ -727,15 +727,13 @@ Config values are provisioned via `golem.yaml` (`env`/`envDefaults`/`secretDefau ## Calling Other Agents (RPC) -`clientFor(Def)` returns a factory; call it with an id record to get a typed proxy, or use `factory.newPhantom(id)` to create a phantom and return `{ client, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. +Every agent definition exposes a `.client` factory. Use `.get(id)` for a durable agent, `.getPhantom(id, phantomId)` for a known phantom, or `.newPhantom(id)` to create a phantom and return `{ client, agentId, phantomId }`. `await client.m(input, { signal })` invokes with optional cancellation; `client.m.trigger(input)` is fire-and-forget; `client.m.schedule(at, input)` enqueues for later and returns a `CancellationToken`. ```typescript -import { clientFor } from '@golemcloud/golem-ts-sdk'; import { Counter } from './counter-agent.js'; -const counter = clientFor(Counter); -const next = await counter({ name: 'c1' }).add({ by: 5 }); -counter({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget +const next = await Counter.client.get({ name: 'c1' }).add({ by: 5 }); +Counter.client.get({ name: 'c1' }).add.trigger({ by: 1 }); // fire-and-forget ``` ## Snapshotting diff --git a/test-components/benchmarks/benchmark-agent-ts/src/main.ts b/test-components/benchmarks/benchmark-agent-ts/src/main.ts index 4259154a2a..9db80a43d2 100644 --- a/test-components/benchmarks/benchmark-agent-ts/src/main.ts +++ b/test-components/benchmarks/benchmark-agent-ts/src/main.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { defineAgent, method, http, s, clientFor } from '@golemcloud/golem-ts-sdk'; +import { defineAgent, method, http, s } from '@golemcloud/golem-ts-sdk'; import * as common from 'common/lib'; @@ -48,8 +48,6 @@ export const BenchmarkAgentImpl = BenchmarkAgent.implement({ }, }); -const benchmarkClient = clientFor(BenchmarkAgent); - export const RpcBenchmarkAgent = defineAgent({ name: 'RpcBenchmarkAgent', id: { name: z.string() }, @@ -65,16 +63,16 @@ export const RpcBenchmarkAgentImpl = RpcBenchmarkAgent.implement({ init: ({ id }) => ({ name: id.name }), methods: { async echo({ message }) { - return await benchmarkClient({ name: this.name }).echo({ message }); + return await BenchmarkAgent.client.get({ name: this.name }).echo({ message }); }, async largeInput({ input }) { - return await benchmarkClient({ name: this.name }).largeInput({ input }); + return await BenchmarkAgent.client.get({ name: this.name }).largeInput({ input }); }, async cpuIntensive({ length }) { - return await benchmarkClient({ name: this.name }).cpuIntensive({ length }); + return await BenchmarkAgent.client.get({ name: this.name }).cpuIntensive({ length }); }, async oplogHeavy({ length }) { - return await benchmarkClient({ name: this.name }).oplogHeavy({ length }); + return await BenchmarkAgent.client.get({ name: this.name }).oplogHeavy({ length }); }, }, }); diff --git a/wit/deps/golem-agent/host.wit b/wit/deps/golem-agent/host.wit index 14d5d2df88..0d1b651dc8 100644 --- a/wit/deps/golem-agent/host.wit +++ b/wit/deps/golem-agent/host.wit @@ -1,7 +1,7 @@ package golem:agent@2.0.0; interface host { - use golem:core/types@2.0.0.{component-id, uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; + use golem:core/types@2.0.0.{uuid, promise-id, schema-graph, schema-value-tree, typed-schema-value, permission-card}; use wasi:clocks/system-clock@0.3.0.{instant as datetime}; use common.{agent-error, agent-type, registered-agent-type, typed-agent-config-value}; @@ -11,6 +11,9 @@ interface host { /// Get a specific registered agent type by name get-agent-type: func(agent-type-name: string) -> option; + /// Gets the registered agent type used by an existing agent, identified by its agent ID. + get-agent-type-by-agent-id: func(agent-id: string) -> option; + /// Constructs a string agent-id from the agent type and its constructor parameters /// and an optional phantom ID. /// @@ -85,12 +88,21 @@ interface host { /// An RPC client for invoking remote agents resource wasm-rpc { - /// Constructs the RPC client connecting to the given target agent. + /// Creates an RPC client connecting to the given target agent. /// /// `constructor` is a value tree whose root encodes the target agent - /// constructor's parameter list. + /// constructor's parameter list. This fail-fast form traps if the client + /// cannot be created and is intended for statically generated clients. constructor(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list); + /// Creates an RPC client connecting to the given target agent. + /// + /// `constructor` is a value tree whose root encodes the target agent + /// constructor's parameter list. This fallible form returns an RPC error + /// if the client cannot be created and is intended for reflective and + /// other dynamic clients. + create: static func(agent-type-name: string, %constructor: schema-value-tree, phantom-id: option, agent-config: list) -> result; + /// Invokes a remote method with the given parameters, and awaits the result. /// /// `input` encodes the method's parameter list. The returned result is