@finalai/agent-provider 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOSTING.md +334 -245
- package/README.md +93 -14
- package/dist/modules/canonical-json.d.mts +4 -0
- package/dist/modules/canonical-json.mjs +33 -0
- package/dist/modules/canonical-json.mjs.map +7 -0
- package/dist/modules/channel.d.mts +9 -3
- package/dist/modules/channel.mjs.map +2 -2
- package/dist/modules/code-host/host.d.mts +10 -0
- package/dist/modules/code-host/host.mjs +88 -0
- package/dist/modules/code-host/host.mjs.map +7 -0
- package/dist/modules/code-host/in-process.d.mts +24 -0
- package/dist/modules/code-host/in-process.mjs +89 -0
- package/dist/modules/code-host/in-process.mjs.map +7 -0
- package/dist/modules/code-host/index.d.mts +4 -0
- package/dist/modules/code-host/index.mjs +5 -0
- package/dist/modules/code-host/index.mjs.map +7 -0
- package/dist/modules/code-host/serverless.d.mts +63 -0
- package/dist/modules/code-host/serverless.mjs +27 -0
- package/dist/modules/code-host/serverless.mjs.map +7 -0
- package/dist/modules/code-host/types.d.mts +152 -0
- package/dist/modules/code-host/types.mjs +85 -0
- package/dist/modules/code-host/types.mjs.map +7 -0
- package/dist/modules/conformance/agent.mjs +72 -6
- package/dist/modules/conformance/agent.mjs.map +2 -2
- package/dist/modules/conformance/harness-kit.d.mts +9 -2
- package/dist/modules/conformance/harness-kit.mjs +224 -63
- package/dist/modules/conformance/harness-kit.mjs.map +3 -3
- package/dist/modules/conformance/local-harness.d.mts +1 -4
- package/dist/modules/conformance/local-harness.mjs +21 -22
- package/dist/modules/conformance/local-harness.mjs.map +2 -2
- package/dist/modules/conformance/protocol.d.mts +1 -0
- package/dist/modules/conformance/protocol.mjs +2 -0
- package/dist/modules/conformance/protocol.mjs.map +2 -2
- package/dist/modules/conformance/sandbox-kit.d.mts +12 -4
- package/dist/modules/conformance/sandbox-kit.mjs +189 -103
- package/dist/modules/conformance/sandbox-kit.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/chat-completions.mjs +1 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/directives.d.mts +3 -0
- package/dist/modules/conformance/scripted-model/directives.mjs +26 -10
- package/dist/modules/conformance/scripted-model/directives.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/messages.mjs +1 -0
- package/dist/modules/conformance/scripted-model/messages.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/responses.mjs +2 -0
- package/dist/modules/conformance/scripted-model/responses.mjs.map +2 -2
- package/dist/modules/conformance/stdio.d.mts +21 -0
- package/dist/modules/conformance/stdio.mjs +158 -0
- package/dist/modules/conformance/stdio.mjs.map +7 -0
- package/dist/modules/credential-routes.d.mts +2 -0
- package/dist/modules/credential-routes.mjs +2 -0
- package/dist/modules/credential-routes.mjs.map +2 -2
- package/dist/modules/document.d.mts +376 -0
- package/dist/modules/document.mjs +208 -0
- package/dist/modules/document.mjs.map +7 -0
- package/dist/modules/harness-configuration.d.mts +16 -0
- package/dist/modules/harness-configuration.mjs +83 -0
- package/dist/modules/harness-configuration.mjs.map +7 -0
- package/dist/modules/harness-definition.d.mts +280 -0
- package/dist/modules/harness-definition.mjs +430 -0
- package/dist/modules/harness-definition.mjs.map +7 -0
- package/dist/modules/harness-provider.d.mts +197 -0
- package/dist/modules/harness-provider.mjs +108 -0
- package/dist/modules/harness-provider.mjs.map +7 -0
- package/dist/modules/harness-requirements.d.mts +19 -0
- package/dist/modules/harness-requirements.mjs +40 -0
- package/dist/modules/harness-requirements.mjs.map +7 -0
- package/dist/modules/harness-start.d.mts +33 -0
- package/dist/modules/harness-start.mjs +107 -0
- package/dist/modules/harness-start.mjs.map +7 -0
- package/dist/modules/harness.d.mts +84 -109
- package/dist/modules/harness.mjs +56 -111
- package/dist/modules/harness.mjs.map +3 -3
- package/dist/modules/identity.d.mts +1 -0
- package/dist/modules/identity.mjs +2 -0
- package/dist/modules/identity.mjs.map +7 -0
- package/dist/modules/index.d.mts +12 -6
- package/dist/modules/index.mjs +12 -6
- package/dist/modules/index.mjs.map +2 -2
- package/dist/modules/inference.d.mts +35 -0
- package/dist/modules/inference.mjs +74 -0
- package/dist/modules/inference.mjs.map +7 -0
- package/dist/modules/local-channel-context.mjs +3 -1
- package/dist/modules/local-channel-context.mjs.map +2 -2
- package/dist/modules/requirements-check.d.mts +30 -0
- package/dist/modules/requirements-check.mjs +164 -0
- package/dist/modules/requirements-check.mjs.map +7 -0
- package/dist/modules/room-surface.d.mts +0 -5
- package/dist/modules/room-surface.mjs.map +2 -2
- package/dist/modules/sandbox/client.d.mts +3 -0
- package/dist/modules/sandbox/client.mjs +101 -18
- package/dist/modules/sandbox/client.mjs.map +2 -2
- package/dist/modules/sandbox/grant.d.mts +78 -0
- package/dist/modules/sandbox/grant.mjs +134 -0
- package/dist/modules/sandbox/grant.mjs.map +7 -0
- package/dist/modules/sandbox/index.d.mts +3 -3
- package/dist/modules/sandbox/index.mjs +4 -5
- package/dist/modules/sandbox/index.mjs.map +2 -2
- package/dist/modules/sandbox/mcp-hosted.d.mts +1 -1
- package/dist/modules/sandbox/mcp-hosted.mjs +4 -7
- package/dist/modules/sandbox/mcp-hosted.mjs.map +2 -2
- package/dist/modules/sandbox/mcp.d.mts +4 -2
- package/dist/modules/sandbox/mcp.mjs +14 -7
- package/dist/modules/sandbox/mcp.mjs.map +2 -2
- package/dist/modules/sandbox/memory-sandbox.d.mts +2 -1
- package/dist/modules/sandbox/memory-sandbox.mjs +71 -41
- package/dist/modules/sandbox/memory-sandbox.mjs.map +2 -2
- package/dist/modules/sandbox/networking.d.mts +7 -7
- package/dist/modules/sandbox/networking.mjs +16 -9
- package/dist/modules/sandbox/networking.mjs.map +2 -2
- package/dist/modules/sandbox/remote/adapter.d.mts +30 -0
- package/dist/modules/sandbox/remote/adapter.mjs +381 -0
- package/dist/modules/sandbox/remote/adapter.mjs.map +7 -0
- package/dist/modules/sandbox/remote/errors.d.mts +10 -0
- package/dist/modules/sandbox/remote/errors.mjs +62 -0
- package/dist/modules/sandbox/remote/errors.mjs.map +7 -0
- package/dist/modules/sandbox/remote/index.d.mts +5 -0
- package/dist/modules/sandbox/remote/index.mjs +6 -0
- package/dist/modules/sandbox/remote/index.mjs.map +7 -0
- package/dist/modules/sandbox/remote/ndjson.d.mts +6 -0
- package/dist/modules/sandbox/remote/ndjson.mjs +80 -0
- package/dist/modules/sandbox/remote/ndjson.mjs.map +7 -0
- package/dist/modules/sandbox/remote/platform-api.d.mts +8 -0
- package/dist/modules/sandbox/remote/platform-api.mjs +15 -0
- package/dist/modules/sandbox/remote/platform-api.mjs.map +7 -0
- package/dist/modules/sandbox/remote/preamble.d.mts +7 -0
- package/dist/modules/sandbox/remote/preamble.mjs +51 -0
- package/dist/modules/sandbox/remote/preamble.mjs.map +7 -0
- package/dist/modules/sandbox/remote/serve.d.mts +34 -0
- package/dist/modules/sandbox/remote/serve.mjs +519 -0
- package/dist/modules/sandbox/remote/serve.mjs.map +7 -0
- package/dist/modules/sandbox/remote/testing.d.mts +34 -0
- package/dist/modules/sandbox/remote/testing.mjs +275 -0
- package/dist/modules/sandbox/remote/testing.mjs.map +7 -0
- package/dist/modules/sandbox/seeds.d.mts +2 -2
- package/dist/modules/sandbox/seeds.mjs +2 -2
- package/dist/modules/sandbox/seeds.mjs.map +2 -2
- package/dist/modules/sandbox/server.d.mts +4 -6
- package/dist/modules/sandbox/server.mjs +93 -49
- package/dist/modules/sandbox/server.mjs.map +2 -2
- package/dist/modules/sandbox/setup/apply.d.mts +41 -0
- package/dist/modules/sandbox/setup/apply.mjs +204 -0
- package/dist/modules/sandbox/setup/apply.mjs.map +7 -0
- package/dist/modules/sandbox/setup/describe.d.mts +10 -0
- package/dist/modules/sandbox/setup/describe.mjs +62 -0
- package/dist/modules/sandbox/setup/describe.mjs.map +7 -0
- package/dist/modules/sandbox/setup/index.d.mts +6 -0
- package/dist/modules/sandbox/setup/index.mjs +17 -0
- package/dist/modules/sandbox/setup/index.mjs.map +7 -0
- package/dist/modules/sandbox/setup/paths.d.mts +8 -0
- package/dist/modules/sandbox/setup/paths.mjs +18 -0
- package/dist/modules/sandbox/setup/paths.mjs.map +7 -0
- package/dist/modules/sandbox/setup/schema.d.mts +42 -0
- package/dist/modules/sandbox/setup/schema.mjs +58 -0
- package/dist/modules/sandbox/setup/schema.mjs.map +7 -0
- package/dist/modules/sandbox/tool-policy.d.mts +1 -1
- package/dist/modules/sandbox/tool-policy.mjs +1 -1
- package/dist/modules/sandbox/tool-policy.mjs.map +2 -2
- package/dist/modules/sandbox/types.d.mts +117 -130
- package/dist/modules/sandbox/types.mjs +46 -50
- package/dist/modules/sandbox/types.mjs.map +3 -3
- package/dist/modules/sandbox/wire.d.mts +93 -6
- package/dist/modules/sandbox/wire.mjs +61 -38
- package/dist/modules/sandbox/wire.mjs.map +2 -2
- package/dist/modules/schemas.d.mts +5 -76
- package/dist/modules/schemas.mjs +18 -85
- package/dist/modules/schemas.mjs.map +2 -2
- package/dist/modules/tool-annotations.d.mts +15 -6
- package/dist/modules/tool-annotations.mjs +9 -3
- package/dist/modules/tool-annotations.mjs.map +2 -2
- package/dist/modules/tool-descriptor.d.mts +16 -0
- package/dist/modules/tool-descriptor.mjs +19 -0
- package/dist/modules/tool-descriptor.mjs.map +7 -0
- package/dist/modules/tool-patterns.d.mts +7 -7
- package/dist/modules/tool-patterns.mjs +10 -9
- package/dist/modules/tool-patterns.mjs.map +2 -2
- package/package.json +86 -36
- package/dist/modules/credentials.d.mts +0 -206
- package/dist/modules/credentials.mjs +0 -207
- package/dist/modules/credentials.mjs.map +0 -7
- package/dist/modules/dynamic.d.mts +0 -40
- package/dist/modules/dynamic.mjs +0 -79
- package/dist/modules/dynamic.mjs.map +0 -7
- package/dist/modules/hosted-bindings.d.mts +0 -15
- package/dist/modules/hosted-bindings.mjs +0 -21
- package/dist/modules/hosted-bindings.mjs.map +0 -7
- package/dist/modules/manifest.d.mts +0 -787
- package/dist/modules/manifest.mjs +0 -320
- package/dist/modules/manifest.mjs.map +0 -7
- package/dist/modules/provider-ref.d.mts +0 -29
- package/dist/modules/provider-ref.mjs +0 -55
- package/dist/modules/provider-ref.mjs.map +0 -7
- package/dist/modules/sandbox/open-scope-node.d.mts +0 -4
- package/dist/modules/sandbox/open-scope-node.mjs +0 -19
- package/dist/modules/sandbox/open-scope-node.mjs.map +0 -7
- package/dist/modules/sandbox/open-scope.d.mts +0 -16
- package/dist/modules/sandbox/open-scope.mjs +0 -66
- package/dist/modules/sandbox/open-scope.mjs.map +0 -7
- package/dist/modules/sandbox/workspace-identity.d.mts +0 -5
- package/dist/modules/sandbox/workspace-identity.mjs +0 -14
- package/dist/modules/sandbox/workspace-identity.mjs.map +0 -7
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { type CodeInvocationIface, type CodeLineIface } from "./types.mjs";
|
|
3
|
+
export declare const serverlessInvocationSchema: z.ZodObject<{
|
|
4
|
+
agent: z.ZodString;
|
|
5
|
+
source: z.ZodString;
|
|
6
|
+
export: z.ZodString;
|
|
7
|
+
invocation: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<import("./types.mjs").CodeKind.Tool>;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
input: z.ZodType<import("../index.mjs").JsonValue, unknown, z.core.$ZodTypeInternals<import("../index.mjs").JsonValue, unknown>>;
|
|
11
|
+
context: z.ZodObject<{
|
|
12
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
13
|
+
callId: z.ZodString;
|
|
14
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof import("@finalai/agent-protocol").Capability> & z.core.$partial, z.ZodObject<{
|
|
16
|
+
url: z.ZodString;
|
|
17
|
+
token: z.ZodString;
|
|
18
|
+
expiresAt: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
|
+
kind: z.ZodLiteral<import("./types.mjs").CodeKind.Hook>;
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
event: z.ZodString;
|
|
25
|
+
payload: z.ZodType<import("../index.mjs").JsonValue, unknown, z.core.$ZodTypeInternals<import("../index.mjs").JsonValue, unknown>>;
|
|
26
|
+
context: z.ZodObject<{
|
|
27
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
28
|
+
callId: z.ZodString;
|
|
29
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof import("@finalai/agent-protocol").Capability> & z.core.$partial, z.ZodObject<{
|
|
31
|
+
url: z.ZodString;
|
|
32
|
+
token: z.ZodString;
|
|
33
|
+
expiresAt: z.ZodString;
|
|
34
|
+
}, z.core.$strip>>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
37
|
+
kind: z.ZodLiteral<import("./types.mjs").CodeKind.Approval>;
|
|
38
|
+
name: z.ZodString;
|
|
39
|
+
input: z.ZodType<import("../index.mjs").JsonValue, unknown, z.core.$ZodTypeInternals<import("../index.mjs").JsonValue, unknown>>;
|
|
40
|
+
context: z.ZodObject<{
|
|
41
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
42
|
+
callId: z.ZodString;
|
|
43
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof import("@finalai/agent-protocol").Capability> & z.core.$partial, z.ZodObject<{
|
|
45
|
+
url: z.ZodString;
|
|
46
|
+
token: z.ZodString;
|
|
47
|
+
expiresAt: z.ZodString;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
}, z.core.$strip>], "kind">;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
export type ServerlessInvocationIface = z.input<typeof serverlessInvocationSchema>;
|
|
53
|
+
export interface ServerlessRuntimeIface {
|
|
54
|
+
run(request: ServerlessInvocationIface, options: {
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}): AsyncIterable<CodeLineIface>;
|
|
57
|
+
}
|
|
58
|
+
export type { CodeInvocationIface };
|
|
59
|
+
export declare const SERVERLESS_TOOL_RESULT = "finalai.serverless-tool-result";
|
|
60
|
+
export declare const serverlessToolResultOf: (returned: unknown) => {
|
|
61
|
+
output: unknown;
|
|
62
|
+
modelOutput?: unknown;
|
|
63
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { codeInvocationSchema } from "./types.mjs";
|
|
3
|
+
const serverlessInvocationSchema = z.object({
|
|
4
|
+
// The agent's content hash; the runtime may keep loaded sources by it.
|
|
5
|
+
agent: z.string().min(1),
|
|
6
|
+
source: z.string().min(1),
|
|
7
|
+
// The module export implementing the tool, hook or predicate.
|
|
8
|
+
export: z.string().min(1),
|
|
9
|
+
invocation: codeInvocationSchema
|
|
10
|
+
});
|
|
11
|
+
const SERVERLESS_TOOL_RESULT = "finalai.serverless-tool-result";
|
|
12
|
+
const toolResultEnvelopeSchema = z.object({
|
|
13
|
+
output: z.unknown(),
|
|
14
|
+
modelOutput: z.unknown().optional()
|
|
15
|
+
});
|
|
16
|
+
const serverlessToolResultOf = (returned) => {
|
|
17
|
+
if (typeof returned !== "object" || returned == null || Reflect.get(returned, Symbol.for(SERVERLESS_TOOL_RESULT)) !== true)
|
|
18
|
+
return { output: returned };
|
|
19
|
+
const { output, modelOutput } = toolResultEnvelopeSchema.parse(returned);
|
|
20
|
+
return modelOutput === void 0 ? { output } : { output, modelOutput };
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
SERVERLESS_TOOL_RESULT,
|
|
24
|
+
serverlessInvocationSchema,
|
|
25
|
+
serverlessToolResultOf
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=serverless.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/code-host/serverless.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport { codeInvocationSchema, type CodeInvocationIface, type CodeLineIface } from \"./types.mjs\";\n\n// The contract of Final's serverless runtime: it runs a serverless tool's or\n// hook's self-contained source from the agent's document. The source travels\n// with every request and is cached by the agent's hash, so nothing is deployed\n// first. The runtime answers with code lines (types.ts), one JSON object per\n// line.\n\nexport const serverlessInvocationSchema = z.object({\n // The agent's content hash; the runtime may keep loaded sources by it.\n agent: z.string().min(1),\n source: z.string().min(1),\n // The module export implementing the tool, hook or predicate.\n export: z.string().min(1),\n invocation: codeInvocationSchema,\n});\n\nexport type ServerlessInvocationIface = z.input<typeof serverlessInvocationSchema>;\n\nexport interface ServerlessRuntimeIface {\n run(\n request: ServerlessInvocationIface,\n options: { signal?: AbortSignal },\n ): AsyncIterable<CodeLineIface>;\n}\n\nexport type { CodeInvocationIface };\n\n// A serverless tool whose model-facing result differs from its structured\n// output returns an envelope marked with the registered symbol of this key:\n// `{ [Symbol.for(SERVERLESS_TOOL_RESULT)]: true, output, modelOutput }`. The\n// code imports nothing, so it names the symbol itself. The runtime reads the\n// return with `serverlessToolResultOf` and sends both on the result line.\nexport const SERVERLESS_TOOL_RESULT = 'finalai.serverless-tool-result';\n\nconst toolResultEnvelopeSchema = z.object({\n output: z.unknown(),\n modelOutput: z.unknown().optional(),\n});\n\n// What a serverless tool's export returned, as the result line's parts: a\n// marked envelope carries `modelOutput` beside `output`; anything else,\n// whatever its fields, is the output.\nexport const serverlessToolResultOf = (\n returned: unknown,\n): { output: unknown; modelOutput?: unknown } => {\n if (\n typeof returned !== 'object' ||\n returned == null ||\n Reflect.get(returned, Symbol.for(SERVERLESS_TOOL_RESULT)) !== true\n )\n return { output: returned };\n const { output, modelOutput } = toolResultEnvelopeSchema.parse(returned);\n // An explicit null is a projection too: the model sees null.\n return modelOutput === undefined ? { output } : { output, modelOutput };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,4BAA0E;AAQ5E,MAAM,6BAA6B,EAAE,OAAO;AAAA;AAAA,EAEjD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACvB,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAExB,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACxB,YAAY;AACd,CAAC;AAkBM,MAAM,yBAAyB;AAEtC,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,QAAQ,EAAE,QAAQ;AAAA,EAClB,aAAa,EAAE,QAAQ,EAAE,SAAS;AACpC,CAAC;AAKM,MAAM,yBAAyB,CACpC,aAC+C;AAC/C,MACE,OAAO,aAAa,YACpB,YAAY,QACZ,QAAQ,IAAI,UAAU,OAAO,IAAI,sBAAsB,CAAC,MAAM;AAE9D,WAAO,EAAE,QAAQ,SAAS;AAC5B,QAAM,EAAE,QAAQ,YAAY,IAAI,yBAAyB,MAAM,QAAQ;AAEvE,SAAO,gBAAgB,SAAY,EAAE,OAAO,IAAI,EAAE,QAAQ,YAAY;AACxE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { Capability } from '@finalai/agent-protocol';
|
|
3
|
+
import { type JsonValue } from "../json.mjs";
|
|
4
|
+
import type { SandboxClientIface } from "../sandbox/client.mjs";
|
|
5
|
+
export declare enum CodeKind {
|
|
6
|
+
Tool = "tool",
|
|
7
|
+
Hook = "hook",
|
|
8
|
+
Approval = "approval"
|
|
9
|
+
}
|
|
10
|
+
export declare const codeSandboxEndpointSchema: z.ZodObject<{
|
|
11
|
+
url: z.ZodString;
|
|
12
|
+
token: z.ZodString;
|
|
13
|
+
expiresAt: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type CodeSandboxEndpointIface = z.infer<typeof codeSandboxEndpointSchema>;
|
|
16
|
+
export declare const codeCallContextSchema: z.ZodObject<{
|
|
17
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
18
|
+
callId: z.ZodString;
|
|
19
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof Capability> & z.core.$partial, z.ZodObject<{
|
|
21
|
+
url: z.ZodString;
|
|
22
|
+
token: z.ZodString;
|
|
23
|
+
expiresAt: z.ZodString;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export type CodeCallContextIface = z.input<typeof codeCallContextSchema>;
|
|
27
|
+
export declare const codeInvocationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
28
|
+
kind: z.ZodLiteral<CodeKind.Tool>;
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
31
|
+
context: z.ZodObject<{
|
|
32
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
33
|
+
callId: z.ZodString;
|
|
34
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof Capability> & z.core.$partial, z.ZodObject<{
|
|
36
|
+
url: z.ZodString;
|
|
37
|
+
token: z.ZodString;
|
|
38
|
+
expiresAt: z.ZodString;
|
|
39
|
+
}, z.core.$strip>>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<CodeKind.Hook>;
|
|
43
|
+
name: z.ZodString;
|
|
44
|
+
event: z.ZodString;
|
|
45
|
+
payload: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
46
|
+
context: z.ZodObject<{
|
|
47
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
48
|
+
callId: z.ZodString;
|
|
49
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof Capability> & z.core.$partial, z.ZodObject<{
|
|
51
|
+
url: z.ZodString;
|
|
52
|
+
token: z.ZodString;
|
|
53
|
+
expiresAt: z.ZodString;
|
|
54
|
+
}, z.core.$strip>>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<CodeKind.Approval>;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
input: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
60
|
+
context: z.ZodObject<{
|
|
61
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
62
|
+
callId: z.ZodString;
|
|
63
|
+
actingUserId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
compute: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof Capability> & z.core.$partial, z.ZodObject<{
|
|
65
|
+
url: z.ZodString;
|
|
66
|
+
token: z.ZodString;
|
|
67
|
+
expiresAt: z.ZodString;
|
|
68
|
+
}, z.core.$strip>>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
}, z.core.$strip>], "kind">;
|
|
71
|
+
export type CodeInvocationIface = z.input<typeof codeInvocationSchema>;
|
|
72
|
+
export declare enum CodeLineType {
|
|
73
|
+
Progress = "progress",
|
|
74
|
+
Result = "result",
|
|
75
|
+
Error = "error"
|
|
76
|
+
}
|
|
77
|
+
export declare const codeLineSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
78
|
+
type: z.ZodLiteral<CodeLineType.Progress>;
|
|
79
|
+
data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
80
|
+
label: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
82
|
+
type: z.ZodLiteral<CodeLineType.Result>;
|
|
83
|
+
output: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
84
|
+
modelOutput: z.ZodOptional<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
|
|
85
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
86
|
+
type: z.ZodLiteral<CodeLineType.Error>;
|
|
87
|
+
message: z.ZodString;
|
|
88
|
+
}, z.core.$strip>], "type">;
|
|
89
|
+
export type CodeLineIface = z.infer<typeof codeLineSchema>;
|
|
90
|
+
export type CodeRunIface = (invocation: CodeInvocationIface, options: CodeRunOptionsIface) => AsyncIterable<CodeLineIface>;
|
|
91
|
+
export interface CodeSecretsIface {
|
|
92
|
+
get(name: string): Promise<string | null>;
|
|
93
|
+
}
|
|
94
|
+
export interface CodeRunOptionsIface {
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
secrets?: CodeSecretsIface;
|
|
97
|
+
}
|
|
98
|
+
export declare enum CodeErrorCode {
|
|
99
|
+
NotFound = "not_found",
|
|
100
|
+
Unavailable = "unavailable",
|
|
101
|
+
Failed = "failed",
|
|
102
|
+
Invalid = "invalid"
|
|
103
|
+
}
|
|
104
|
+
export type CodeResultIface = {
|
|
105
|
+
ok: true;
|
|
106
|
+
output: JsonValue;
|
|
107
|
+
modelOutput?: JsonValue;
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
code: CodeErrorCode;
|
|
111
|
+
message: string;
|
|
112
|
+
};
|
|
113
|
+
export type ApprovalResultIface = {
|
|
114
|
+
ok: true;
|
|
115
|
+
ask: boolean;
|
|
116
|
+
} | {
|
|
117
|
+
ok: false;
|
|
118
|
+
code: CodeErrorCode;
|
|
119
|
+
message: string;
|
|
120
|
+
};
|
|
121
|
+
export interface CodeCallIface {
|
|
122
|
+
context: CodeCallContextIface;
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
onProgress?: (progress: {
|
|
125
|
+
data: JsonValue;
|
|
126
|
+
label?: string;
|
|
127
|
+
}) => void;
|
|
128
|
+
}
|
|
129
|
+
export interface CodeHostIface {
|
|
130
|
+
invokeTool(args: CodeCallIface & {
|
|
131
|
+
name: string;
|
|
132
|
+
input: JsonValue;
|
|
133
|
+
}): Promise<CodeResultIface>;
|
|
134
|
+
dispatchHook(args: CodeCallIface & {
|
|
135
|
+
name: string;
|
|
136
|
+
event: string;
|
|
137
|
+
payload: JsonValue;
|
|
138
|
+
}): Promise<CodeResultIface>;
|
|
139
|
+
evaluateApproval(args: Omit<CodeCallIface, 'onProgress'> & {
|
|
140
|
+
name: string;
|
|
141
|
+
input: JsonValue;
|
|
142
|
+
}): Promise<ApprovalResultIface>;
|
|
143
|
+
}
|
|
144
|
+
export interface CodeContextIface {
|
|
145
|
+
sessionId: string | null;
|
|
146
|
+
callId: string;
|
|
147
|
+
actingUserId: string | null;
|
|
148
|
+
signal: AbortSignal;
|
|
149
|
+
progress(data: JsonValue, label?: string): void;
|
|
150
|
+
sandbox(capability: Capability | `${Capability}`): Promise<SandboxClientIface>;
|
|
151
|
+
secrets?: CodeSecretsIface;
|
|
152
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { Capability } from "@finalai/agent-protocol";
|
|
3
|
+
import { jsonValueSchema } from "../json.mjs";
|
|
4
|
+
var CodeKind = /* @__PURE__ */ ((CodeKind2) => {
|
|
5
|
+
CodeKind2["Tool"] = "tool";
|
|
6
|
+
CodeKind2["Hook"] = "hook";
|
|
7
|
+
CodeKind2["Approval"] = "approval";
|
|
8
|
+
return CodeKind2;
|
|
9
|
+
})(CodeKind || {});
|
|
10
|
+
const codeSandboxEndpointSchema = z.object({
|
|
11
|
+
url: z.string().min(1),
|
|
12
|
+
token: z.string(),
|
|
13
|
+
expiresAt: z.string()
|
|
14
|
+
});
|
|
15
|
+
const codeCallContextSchema = z.object({
|
|
16
|
+
sessionId: z.string().nullable(),
|
|
17
|
+
// The tool call or hook delivery this answers; the same on a retry.
|
|
18
|
+
callId: z.string().min(1),
|
|
19
|
+
// The person the turn acts for; null for work nobody prompted.
|
|
20
|
+
actingUserId: z.string().nullable().default(null),
|
|
21
|
+
// The session's compute, by capability: what `ctx.sandbox(capability)` opens.
|
|
22
|
+
compute: z.partialRecord(z.nativeEnum(Capability), codeSandboxEndpointSchema).default({})
|
|
23
|
+
});
|
|
24
|
+
const codeInvocationSchema = z.discriminatedUnion("kind", [
|
|
25
|
+
z.object({
|
|
26
|
+
kind: z.literal("tool" /* Tool */),
|
|
27
|
+
// The tool's name in the document.
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
input: jsonValueSchema,
|
|
30
|
+
context: codeCallContextSchema
|
|
31
|
+
}),
|
|
32
|
+
z.object({
|
|
33
|
+
kind: z.literal("hook" /* Hook */),
|
|
34
|
+
// The hook's name in the document.
|
|
35
|
+
name: z.string().min(1),
|
|
36
|
+
event: z.string().min(1),
|
|
37
|
+
payload: jsonValueSchema,
|
|
38
|
+
context: codeCallContextSchema
|
|
39
|
+
}),
|
|
40
|
+
z.object({
|
|
41
|
+
kind: z.literal("approval" /* Approval */),
|
|
42
|
+
// The tool whose predicate runs.
|
|
43
|
+
name: z.string().min(1),
|
|
44
|
+
input: jsonValueSchema,
|
|
45
|
+
context: codeCallContextSchema
|
|
46
|
+
})
|
|
47
|
+
]);
|
|
48
|
+
var CodeLineType = /* @__PURE__ */ ((CodeLineType2) => {
|
|
49
|
+
CodeLineType2["Progress"] = "progress";
|
|
50
|
+
CodeLineType2["Result"] = "result";
|
|
51
|
+
CodeLineType2["Error"] = "error";
|
|
52
|
+
return CodeLineType2;
|
|
53
|
+
})(CodeLineType || {});
|
|
54
|
+
const codeLineSchema = z.discriminatedUnion("type", [
|
|
55
|
+
z.object({
|
|
56
|
+
type: z.literal("progress" /* Progress */),
|
|
57
|
+
data: jsonValueSchema,
|
|
58
|
+
label: z.string().optional()
|
|
59
|
+
}),
|
|
60
|
+
z.object({
|
|
61
|
+
type: z.literal("result" /* Result */),
|
|
62
|
+
output: jsonValueSchema,
|
|
63
|
+
// What the model sees in place of `output`, which stays the structured
|
|
64
|
+
// result. Absent when the tool has no projection.
|
|
65
|
+
modelOutput: jsonValueSchema.optional()
|
|
66
|
+
}),
|
|
67
|
+
z.object({ type: z.literal("error" /* Error */), message: z.string() })
|
|
68
|
+
]);
|
|
69
|
+
var CodeErrorCode = /* @__PURE__ */ ((CodeErrorCode2) => {
|
|
70
|
+
CodeErrorCode2["NotFound"] = "not_found";
|
|
71
|
+
CodeErrorCode2["Unavailable"] = "unavailable";
|
|
72
|
+
CodeErrorCode2["Failed"] = "failed";
|
|
73
|
+
CodeErrorCode2["Invalid"] = "invalid";
|
|
74
|
+
return CodeErrorCode2;
|
|
75
|
+
})(CodeErrorCode || {});
|
|
76
|
+
export {
|
|
77
|
+
CodeErrorCode,
|
|
78
|
+
CodeKind,
|
|
79
|
+
CodeLineType,
|
|
80
|
+
codeCallContextSchema,
|
|
81
|
+
codeInvocationSchema,
|
|
82
|
+
codeLineSchema,
|
|
83
|
+
codeSandboxEndpointSchema
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/code-host/types.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport { Capability } from '@finalai/agent-protocol';\nimport { jsonValueSchema, type JsonValue } from \"../json.mjs\";\nimport type { SandboxClientIface } from \"../sandbox/client.mjs\";\n\n// The one way the platform calls an agent's own code: a tool, a hook, or a\n// tool's approval predicate. Each says where it runs by its placement in the\n// agent's document; both placements take the same invocation and answer with\n// the same lines, whatever carries them (NDJSON over HTTP to the serverless\n// runtime, frames over the creating client's connection).\n\nexport enum CodeKind {\n Tool = 'tool',\n Hook = 'hook',\n // A tool's `approval: { whenInput }` predicate: answers whether to ask first.\n Approval = 'approval',\n}\n\n// A sandbox handle RPC endpoint, for `ctx.sandbox(capability)`.\nexport const codeSandboxEndpointSchema = z.object({\n url: z.string().min(1),\n token: z.string(),\n expiresAt: z.string(),\n});\n\nexport type CodeSandboxEndpointIface = z.infer<typeof codeSandboxEndpointSchema>;\n\nexport const codeCallContextSchema = z.object({\n sessionId: z.string().nullable(),\n // The tool call or hook delivery this answers; the same on a retry.\n callId: z.string().min(1),\n // The person the turn acts for; null for work nobody prompted.\n actingUserId: z.string().nullable().default(null),\n // The session's compute, by capability: what `ctx.sandbox(capability)` opens.\n compute: z.partialRecord(z.nativeEnum(Capability), codeSandboxEndpointSchema).default({}),\n});\n\nexport type CodeCallContextIface = z.input<typeof codeCallContextSchema>;\n\nexport const codeInvocationSchema = z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal(CodeKind.Tool),\n // The tool's name in the document.\n name: z.string().min(1),\n input: jsonValueSchema,\n context: codeCallContextSchema,\n }),\n z.object({\n kind: z.literal(CodeKind.Hook),\n // The hook's name in the document.\n name: z.string().min(1),\n event: z.string().min(1),\n payload: jsonValueSchema,\n context: codeCallContextSchema,\n }),\n z.object({\n kind: z.literal(CodeKind.Approval),\n // The tool whose predicate runs.\n name: z.string().min(1),\n input: jsonValueSchema,\n context: codeCallContextSchema,\n }),\n]);\n\nexport type CodeInvocationIface = z.input<typeof codeInvocationSchema>;\n\nexport enum CodeLineType {\n Progress = 'progress',\n Result = 'result',\n Error = 'error',\n}\n\nexport const codeLineSchema = z.discriminatedUnion('type', [\n z.object({\n type: z.literal(CodeLineType.Progress),\n data: jsonValueSchema,\n label: z.string().optional(),\n }),\n z.object({\n type: z.literal(CodeLineType.Result),\n output: jsonValueSchema,\n // What the model sees in place of `output`, which stays the structured\n // result. Absent when the tool has no projection.\n modelOutput: jsonValueSchema.optional(),\n }),\n z.object({ type: z.literal(CodeLineType.Error), message: z.string() }),\n]);\n\nexport type CodeLineIface = z.infer<typeof codeLineSchema>;\n\n// Carries one invocation to where the code runs and streams its lines back,\n// ending with exactly one result or error line.\nexport type CodeRunIface = (\n invocation: CodeInvocationIface,\n options: CodeRunOptionsIface,\n) => AsyncIterable<CodeLineIface>;\n\n// Reads the project secrets the agent lists in `secrets`; null when one is not set.\nexport interface CodeSecretsIface {\n get(name: string): Promise<string | null>;\n}\n\nexport interface CodeRunOptionsIface {\n signal?: AbortSignal;\n // Where code run in this process reads secrets for this invocation.\n secrets?: CodeSecretsIface;\n}\n\nexport enum CodeErrorCode {\n // The document has no such tool or hook.\n NotFound = 'not_found',\n // In-process code with no connected client holding it.\n Unavailable = 'unavailable',\n // The code threw or answered with an error line.\n Failed = 'failed',\n // The code answered with something its kind does not allow.\n Invalid = 'invalid',\n}\n\nexport type CodeResultIface =\n | { ok: true; output: JsonValue; modelOutput?: JsonValue }\n | { ok: false; code: CodeErrorCode; message: string };\n\nexport type ApprovalResultIface =\n | { ok: true; ask: boolean }\n | { ok: false; code: CodeErrorCode; message: string };\n\nexport interface CodeCallIface {\n context: CodeCallContextIface;\n signal?: AbortSignal;\n onProgress?: (progress: { data: JsonValue; label?: string }) => void;\n}\n\n// What the platform calls. One implementation routes by placement.\nexport interface CodeHostIface {\n invokeTool(args: CodeCallIface & { name: string; input: JsonValue }): Promise<CodeResultIface>;\n dispatchHook(\n args: CodeCallIface & { name: string; event: string; payload: JsonValue },\n ): Promise<CodeResultIface>;\n // A tool's approval: its fixed mode, or its predicate run where it runs.\n evaluateApproval(\n args: Omit<CodeCallIface, 'onProgress'> & { name: string; input: JsonValue },\n ): Promise<ApprovalResultIface>;\n}\n\n// What code is given as `ctx`, in either placement.\nexport interface CodeContextIface {\n sessionId: string | null;\n callId: string;\n actingUserId: string | null;\n signal: AbortSignal;\n progress(data: JsonValue, label?: string): void;\n // The sandbox the session was provided for a capability. Throws when the\n // session has none for it.\n sandbox(capability: Capability | `${Capability}`): Promise<SandboxClientIface>;\n // The agent's project secrets, when whoever runs the code can read them.\n secrets?: CodeSecretsIface;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuC;AASzC,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,UAAO;AAEP,EAAAA,UAAA,cAAW;AAJD,SAAAA;AAAA,GAAA;AAQL,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACrB,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AACtB,CAAC;AAIM,MAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE/B,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAExB,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA;AAAA,EAEhD,SAAS,EAAE,cAAc,EAAE,WAAW,UAAU,GAAG,yBAAyB,EAAE,QAAQ,CAAC,CAAC;AAC1F,CAAC;AAIM,MAAM,uBAAuB,EAAE,mBAAmB,QAAQ;AAAA,EAC/D,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,iBAAa;AAAA;AAAA,IAE7B,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,IACtB,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,iBAAa;AAAA;AAAA,IAE7B,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,IACtB,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,IACvB,SAAS;AAAA,IACT,SAAS;AAAA,EACX,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,yBAAiB;AAAA;AAAA,IAEjC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,IACtB,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AACH,CAAC;AAIM,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,cAAW;AACX,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AAML,MAAM,iBAAiB,EAAE,mBAAmB,QAAQ;AAAA,EACzD,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,yBAAqB;AAAA,IACrC,MAAM;AAAA,IACN,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,qBAAmB;AAAA,IACnC,QAAQ;AAAA;AAAA;AAAA,IAGR,aAAa,gBAAgB,SAAS;AAAA,EACxC,CAAC;AAAA,EACD,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,mBAAkB,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC;AACvE,CAAC;AAsBM,IAAK,gBAAL,kBAAKC,mBAAL;AAEL,EAAAA,eAAA,cAAW;AAEX,EAAAA,eAAA,iBAAc;AAEd,EAAAA,eAAA,YAAS;AAET,EAAAA,eAAA,aAAU;AARA,SAAAA;AAAA,GAAA;",
|
|
6
|
+
"names": ["CodeKind", "CodeLineType", "CodeErrorCode"]
|
|
7
|
+
}
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
RequestError
|
|
6
6
|
} from "@agentclientprotocol/sdk/experimental/v2";
|
|
7
7
|
import {
|
|
8
|
+
authorOf,
|
|
9
|
+
FINAL_LIVE_TEXT_METHOD,
|
|
8
10
|
FinalContentRole,
|
|
9
11
|
RESOURCE_LINK_DESCRIPTION_BYTES,
|
|
10
12
|
roleOf,
|
|
@@ -146,13 +148,49 @@ const createConformanceAgent = (options = {}) => {
|
|
|
146
148
|
const middle = Math.ceil(text.length / 2);
|
|
147
149
|
const parts = text.length > 1 ? [text.slice(0, middle), text.slice(middle)] : [text];
|
|
148
150
|
for (const part of parts) {
|
|
151
|
+
if (!extensions) {
|
|
152
|
+
await emit(session, {
|
|
153
|
+
sessionUpdate: "agent_message_chunk",
|
|
154
|
+
messageId,
|
|
155
|
+
content: { type: "text", text: part }
|
|
156
|
+
});
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const emittedAtMs = Date.now();
|
|
160
|
+
const offset = session.liveOffsets.get(messageId) ?? 0;
|
|
161
|
+
session.liveOffsets.set(messageId, offset + part.length);
|
|
162
|
+
const live = session.client.notify(FINAL_LIVE_TEXT_METHOD, {
|
|
163
|
+
sessionId: session.id,
|
|
164
|
+
messageId,
|
|
165
|
+
offset,
|
|
166
|
+
text: part,
|
|
167
|
+
emittedAtMs
|
|
168
|
+
});
|
|
169
|
+
if (survives) await live.catch(() => void 0);
|
|
170
|
+
else await live;
|
|
149
171
|
await emit(session, {
|
|
150
172
|
sessionUpdate: "agent_message_chunk",
|
|
151
173
|
messageId,
|
|
152
|
-
content: { type: "text", text: part }
|
|
174
|
+
content: { type: "text", text: part },
|
|
175
|
+
_meta: { [FINAL_META_KEY]: { emittedAtMs } }
|
|
153
176
|
});
|
|
154
177
|
}
|
|
155
178
|
};
|
|
179
|
+
const transcriptOf = (prompt) => {
|
|
180
|
+
if (!extensions) return textOf(prompt);
|
|
181
|
+
let text = "";
|
|
182
|
+
let current = null;
|
|
183
|
+
for (const block of prompt) {
|
|
184
|
+
const author = authorOf(block);
|
|
185
|
+
if (author != null && author.displayName !== current) {
|
|
186
|
+
text += `${text === "" || text.endsWith("\n") ? "" : "\n"}[${author.displayName}]
|
|
187
|
+
`;
|
|
188
|
+
current = author.displayName;
|
|
189
|
+
}
|
|
190
|
+
text += textOf([block]);
|
|
191
|
+
}
|
|
192
|
+
return text;
|
|
193
|
+
};
|
|
156
194
|
const ask = async (session, method, params, viaSdk) => {
|
|
157
195
|
const current = session.link;
|
|
158
196
|
if (!survives || current == null) {
|
|
@@ -391,8 +429,7 @@ const createConformanceAgent = (options = {}) => {
|
|
|
391
429
|
content: [...prompt]
|
|
392
430
|
});
|
|
393
431
|
const injectIntoTurn = (session, turn, prompt, userMessageId) => {
|
|
394
|
-
|
|
395
|
-
session.transcript.push(text);
|
|
432
|
+
session.transcript.push(transcriptOf(prompt));
|
|
396
433
|
const work = (async () => {
|
|
397
434
|
await echo(session, prompt, userMessageId);
|
|
398
435
|
await runTurn(session, directiveTextOf(prompt), turn.signal);
|
|
@@ -400,7 +437,7 @@ const createConformanceAgent = (options = {}) => {
|
|
|
400
437
|
session.injected.push(work);
|
|
401
438
|
};
|
|
402
439
|
const startTurn = (session, prompt, userMessageId) => {
|
|
403
|
-
const text =
|
|
440
|
+
const text = transcriptOf(prompt);
|
|
404
441
|
const cancels = session.cancels;
|
|
405
442
|
session.queue = session.queue.then(async () => {
|
|
406
443
|
if (session.cancels !== cancels) return;
|
|
@@ -442,7 +479,13 @@ const createConformanceAgent = (options = {}) => {
|
|
|
442
479
|
session: { mcp: { acp: {}, http: {} } },
|
|
443
480
|
_meta: {
|
|
444
481
|
[FINAL_META_KEY]: {
|
|
445
|
-
supports: {
|
|
482
|
+
supports: {
|
|
483
|
+
observe: true,
|
|
484
|
+
authorMeta: true,
|
|
485
|
+
resumeReplay: true,
|
|
486
|
+
afterSeqReplay: true,
|
|
487
|
+
fork: true
|
|
488
|
+
},
|
|
446
489
|
privateMethods: options.privateMethods ?? []
|
|
447
490
|
}
|
|
448
491
|
}
|
|
@@ -462,7 +505,8 @@ const createConformanceAgent = (options = {}) => {
|
|
|
462
505
|
queue: Promise.resolve(),
|
|
463
506
|
injected: [],
|
|
464
507
|
cancels: 0,
|
|
465
|
-
open: /* @__PURE__ */ new Map()
|
|
508
|
+
open: /* @__PURE__ */ new Map(),
|
|
509
|
+
liveOffsets: /* @__PURE__ */ new Map()
|
|
466
510
|
});
|
|
467
511
|
return { sessionId: id };
|
|
468
512
|
}).onRequest(methods.agent.session.resume, async ({ params, client, requestId }) => {
|
|
@@ -495,6 +539,28 @@ const createConformanceAgent = (options = {}) => {
|
|
|
495
539
|
else startTurn(session, params.prompt, messageId);
|
|
496
540
|
}, 0);
|
|
497
541
|
return { messageId };
|
|
542
|
+
}).onRequest(methods.agent.session.fork, ({ params, client, requestId }) => {
|
|
543
|
+
if (!extensions) throw RequestError.methodNotFound(methods.agent.session.fork);
|
|
544
|
+
const source = getSession(params.sessionId);
|
|
545
|
+
const id = randomId();
|
|
546
|
+
sessions.set(id, {
|
|
547
|
+
...source,
|
|
548
|
+
id,
|
|
549
|
+
nativeId: randomId(),
|
|
550
|
+
cwd: params.cwd,
|
|
551
|
+
mcpServers: params.mcpServers ?? source.mcpServers,
|
|
552
|
+
history: [...source.history],
|
|
553
|
+
transcript: [...source.transcript],
|
|
554
|
+
client,
|
|
555
|
+
link: linkOf(requestId),
|
|
556
|
+
turn: null,
|
|
557
|
+
queue: Promise.resolve(),
|
|
558
|
+
injected: [],
|
|
559
|
+
cancels: 0,
|
|
560
|
+
open: /* @__PURE__ */ new Map(),
|
|
561
|
+
liveOffsets: /* @__PURE__ */ new Map()
|
|
562
|
+
});
|
|
563
|
+
return { sessionId: id };
|
|
498
564
|
}).onRequest(methods.agent.session.close, async ({ params }) => {
|
|
499
565
|
const session = sessions.get(params.sessionId);
|
|
500
566
|
if (session != null) {
|