@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,197 @@
|
|
|
1
|
+
import { type McpServer, type Stream } from '@agentclientprotocol/sdk/experimental/v2';
|
|
2
|
+
import { type InitializeMetaHolderIface } from '@finalai/acp-session';
|
|
3
|
+
import { RuntimeKind, type Capability } from '@finalai/agent-protocol';
|
|
4
|
+
import type { ResolvedHarnessSettingsIface } from '@finalai/agent-protocol/agent-platform';
|
|
5
|
+
import * as z from 'zod';
|
|
6
|
+
import type { AgentDocumentIface } from "./document.mjs";
|
|
7
|
+
import type { JsonValue } from "./json.mjs";
|
|
8
|
+
import { AcpTransport, type CredentialGrantIface, type SandboxStartIface, type HarnessHealthIface, type HarnessObserverIface, type HarnessSessionContextIface, type HarnessSessionRefIface, type SandboxEndpointIface, type SecretReaderIface, type TraceContextIface } from "./harness.mjs";
|
|
9
|
+
import { FinalExtension, type AcpAdapterDefinitionIface, type ComposedEnvironmentIface, type HarnessDefinitionIface } from "./harness-definition.mjs";
|
|
10
|
+
import { type SandboxProcessIface, type SandboxProcessOptionsIface, type SandboxWorkerOptionsIface, type SandboxWorkerStartType } from "./sandbox/types.mjs";
|
|
11
|
+
export declare const HARNESS_PROVIDER_EXPORTS: readonly ["open", "resume", "park", "close", "health"];
|
|
12
|
+
export type HarnessProviderExport = (typeof HARNESS_PROVIDER_EXPORTS)[number];
|
|
13
|
+
export interface PublishedDefinitionIface<Definition> {
|
|
14
|
+
name: string;
|
|
15
|
+
hash: string;
|
|
16
|
+
definition: Definition;
|
|
17
|
+
}
|
|
18
|
+
export interface HarnessProviderOpenArgsIface {
|
|
19
|
+
session: HarnessSessionContextIface;
|
|
20
|
+
harnessSessionId: string;
|
|
21
|
+
harness: PublishedDefinitionIface<HarnessDefinitionIface>;
|
|
22
|
+
adapter: PublishedDefinitionIface<AcpAdapterDefinitionIface> | null;
|
|
23
|
+
environment: ComposedEnvironmentIface;
|
|
24
|
+
runtime: RuntimeKind | null;
|
|
25
|
+
settings: ResolvedHarnessSettingsIface;
|
|
26
|
+
document: AgentDocumentIface;
|
|
27
|
+
mcpServers: McpServer[];
|
|
28
|
+
compute: Partial<Record<Capability, SandboxEndpointIface>>;
|
|
29
|
+
credentials: CredentialGrantIface;
|
|
30
|
+
trace: TraceContextIface;
|
|
31
|
+
forkSource?: {
|
|
32
|
+
ref: HarnessSessionRefIface;
|
|
33
|
+
acpSessionId: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface HarnessProviderResumeArgsIface extends HarnessProviderOpenArgsIface {
|
|
37
|
+
ref: HarnessSessionRefIface;
|
|
38
|
+
lastSeq: number;
|
|
39
|
+
}
|
|
40
|
+
export interface HarnessProviderRefArgsIface {
|
|
41
|
+
ref: HarnessSessionRefIface;
|
|
42
|
+
environment: ComposedEnvironmentIface;
|
|
43
|
+
}
|
|
44
|
+
export interface HarnessProviderCloseArgsIface extends HarnessProviderRefArgsIface {
|
|
45
|
+
force: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface HarnessProviderContextIface {
|
|
48
|
+
secrets: SecretReaderIface;
|
|
49
|
+
observer: HarnessObserverIface;
|
|
50
|
+
}
|
|
51
|
+
export declare const harnessProviderEndpointSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
52
|
+
ref: z.ZodObject<{
|
|
53
|
+
harness: z.ZodString;
|
|
54
|
+
harnessSessionRef: z.ZodString;
|
|
55
|
+
generation: z.ZodNumber;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
transport: z.ZodLiteral<AcpTransport.Ws>;
|
|
58
|
+
url: z.ZodString;
|
|
59
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
60
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
61
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
62
|
+
ref: z.ZodObject<{
|
|
63
|
+
harness: z.ZodString;
|
|
64
|
+
harnessSessionRef: z.ZodString;
|
|
65
|
+
generation: z.ZodNumber;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
transport: z.ZodLiteral<AcpTransport.Http>;
|
|
68
|
+
url: z.ZodString;
|
|
69
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
70
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
71
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
72
|
+
ref: z.ZodObject<{
|
|
73
|
+
harness: z.ZodString;
|
|
74
|
+
harnessSessionRef: z.ZodString;
|
|
75
|
+
generation: z.ZodNumber;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
transport: z.ZodLiteral<AcpTransport.Sandbox>;
|
|
78
|
+
sandboxId: z.ZodString;
|
|
79
|
+
start: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
80
|
+
runtime: z.ZodLiteral<RuntimeKind.Process>;
|
|
81
|
+
command: z.ZodString;
|
|
82
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
83
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
84
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
runtime: z.ZodLiteral<RuntimeKind.Worker>;
|
|
87
|
+
program: z.ZodString;
|
|
88
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
89
|
+
input: z.ZodDefault<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
|
|
90
|
+
}, z.core.$strict>], "runtime">;
|
|
91
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
92
|
+
}, z.core.$strict>], "transport">;
|
|
93
|
+
export declare const harnessProviderRefusalSchema: z.ZodObject<{
|
|
94
|
+
unsuitable: z.ZodArray<z.ZodString>;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
export type HarnessProviderRefusalIface = z.output<typeof harnessProviderRefusalSchema>;
|
|
97
|
+
export declare const harnessProviderOpenResultSchema: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
98
|
+
ref: z.ZodObject<{
|
|
99
|
+
harness: z.ZodString;
|
|
100
|
+
harnessSessionRef: z.ZodString;
|
|
101
|
+
generation: z.ZodNumber;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
transport: z.ZodLiteral<AcpTransport.Ws>;
|
|
104
|
+
url: z.ZodString;
|
|
105
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
106
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
107
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
+
ref: z.ZodObject<{
|
|
109
|
+
harness: z.ZodString;
|
|
110
|
+
harnessSessionRef: z.ZodString;
|
|
111
|
+
generation: z.ZodNumber;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
transport: z.ZodLiteral<AcpTransport.Http>;
|
|
114
|
+
url: z.ZodString;
|
|
115
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
116
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
ref: z.ZodObject<{
|
|
119
|
+
harness: z.ZodString;
|
|
120
|
+
harnessSessionRef: z.ZodString;
|
|
121
|
+
generation: z.ZodNumber;
|
|
122
|
+
}, z.core.$strip>;
|
|
123
|
+
transport: z.ZodLiteral<AcpTransport.Sandbox>;
|
|
124
|
+
sandboxId: z.ZodString;
|
|
125
|
+
start: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
126
|
+
runtime: z.ZodLiteral<RuntimeKind.Process>;
|
|
127
|
+
command: z.ZodString;
|
|
128
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
129
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
130
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
131
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
132
|
+
runtime: z.ZodLiteral<RuntimeKind.Worker>;
|
|
133
|
+
program: z.ZodString;
|
|
134
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
135
|
+
input: z.ZodDefault<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
|
|
136
|
+
}, z.core.$strict>], "runtime">;
|
|
137
|
+
extensions: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof FinalExtension>>>;
|
|
138
|
+
}, z.core.$strict>], "transport">, z.ZodObject<{
|
|
139
|
+
unsuitable: z.ZodArray<z.ZodString>;
|
|
140
|
+
}, z.core.$strict>]>;
|
|
141
|
+
export declare const missingFinalExtensions: (initialize: InitializeMetaHolderIface, required: readonly FinalExtension[]) => FinalExtension[];
|
|
142
|
+
export type HarnessProviderEndpointIface = z.output<typeof harnessProviderEndpointSchema>;
|
|
143
|
+
export type HarnessProviderEndpointInputIface = z.input<typeof harnessProviderEndpointSchema>;
|
|
144
|
+
type EnumLiteral<E extends string> = E | `${E}`;
|
|
145
|
+
interface ExtensionsResultIface {
|
|
146
|
+
extensions?: EnumLiteral<FinalExtension>[];
|
|
147
|
+
}
|
|
148
|
+
export type HarnessProviderEndpointResultIface = (ExtensionsResultIface & {
|
|
149
|
+
ref: HarnessSessionRefIface;
|
|
150
|
+
transport: EnumLiteral<AcpTransport.Ws> | EnumLiteral<AcpTransport.Http>;
|
|
151
|
+
url: string;
|
|
152
|
+
headers?: Record<string, string>;
|
|
153
|
+
}) | (ExtensionsResultIface & {
|
|
154
|
+
ref: HarnessSessionRefIface;
|
|
155
|
+
transport: EnumLiteral<AcpTransport.Sandbox>;
|
|
156
|
+
sandboxId: string;
|
|
157
|
+
start: {
|
|
158
|
+
runtime: EnumLiteral<RuntimeKind.Process>;
|
|
159
|
+
command: string;
|
|
160
|
+
args?: string[];
|
|
161
|
+
env?: Record<string, string>;
|
|
162
|
+
cwd?: string;
|
|
163
|
+
} | {
|
|
164
|
+
runtime: EnumLiteral<RuntimeKind.Worker>;
|
|
165
|
+
program: string;
|
|
166
|
+
env?: Record<string, string>;
|
|
167
|
+
input?: JsonValue;
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
export type HarnessProviderOpenResultIface = HarnessProviderEndpointResultIface | HarnessProviderRefusalIface;
|
|
171
|
+
export interface SandboxEndpointHostIface {
|
|
172
|
+
spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;
|
|
173
|
+
startWorker?(options: SandboxWorkerOptionsIface): Promise<SandboxWorkerStartType>;
|
|
174
|
+
}
|
|
175
|
+
export declare const startSandboxEndpoint: (args: {
|
|
176
|
+
sandbox: SandboxEndpointHostIface;
|
|
177
|
+
start: SandboxStartIface;
|
|
178
|
+
abortSignal?: AbortSignal;
|
|
179
|
+
}) => Promise<{
|
|
180
|
+
process: SandboxProcessIface;
|
|
181
|
+
stream: Stream;
|
|
182
|
+
}>;
|
|
183
|
+
export declare const harnessProviderHealthSchema: z.ZodObject<{
|
|
184
|
+
ok: z.ZodBoolean;
|
|
185
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
186
|
+
checkedAt: z.ZodOptional<z.ZodString>;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
export interface HarnessProviderIface {
|
|
189
|
+
open(args: HarnessProviderOpenArgsIface, ctx: HarnessProviderContextIface): Promise<HarnessProviderOpenResultIface>;
|
|
190
|
+
resume(args: HarnessProviderResumeArgsIface, ctx: HarnessProviderContextIface): Promise<HarnessProviderOpenResultIface>;
|
|
191
|
+
park(args: HarnessProviderRefArgsIface, ctx: HarnessProviderContextIface): Promise<void>;
|
|
192
|
+
close(args: HarnessProviderCloseArgsIface, ctx: HarnessProviderContextIface): Promise<void>;
|
|
193
|
+
health(args: HarnessProviderRefArgsIface, ctx: HarnessProviderContextIface): Promise<Omit<HarnessHealthIface, 'checkedAt'> & {
|
|
194
|
+
checkedAt?: string;
|
|
195
|
+
}>;
|
|
196
|
+
}
|
|
197
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ndJsonStream
|
|
3
|
+
} from "@agentclientprotocol/sdk/experimental/v2";
|
|
4
|
+
import { advertisedFinalExtensions } from "@finalai/acp-session";
|
|
5
|
+
import { RuntimeKind } from "@finalai/agent-protocol";
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
import {
|
|
8
|
+
AcpTransport,
|
|
9
|
+
harnessSessionRefSchema,
|
|
10
|
+
sandboxStartSchema
|
|
11
|
+
} from "./harness.mjs";
|
|
12
|
+
import {
|
|
13
|
+
FinalExtension
|
|
14
|
+
} from "./harness-definition.mjs";
|
|
15
|
+
import {
|
|
16
|
+
isSandboxWorkerEndpoint
|
|
17
|
+
} from "./sandbox/types.mjs";
|
|
18
|
+
const HARNESS_PROVIDER_EXPORTS = ["open", "resume", "park", "close", "health"];
|
|
19
|
+
const extensionsSchema = z.array(z.nativeEnum(FinalExtension)).default([]);
|
|
20
|
+
const harnessProviderEndpointSchema = z.discriminatedUnion("transport", [
|
|
21
|
+
z.strictObject({
|
|
22
|
+
ref: harnessSessionRefSchema,
|
|
23
|
+
transport: z.literal(AcpTransport.Ws),
|
|
24
|
+
url: z.string().url(),
|
|
25
|
+
headers: z.record(z.string(), z.string()).default({}),
|
|
26
|
+
extensions: extensionsSchema
|
|
27
|
+
}),
|
|
28
|
+
z.strictObject({
|
|
29
|
+
ref: harnessSessionRefSchema,
|
|
30
|
+
transport: z.literal(AcpTransport.Http),
|
|
31
|
+
url: z.string().url(),
|
|
32
|
+
headers: z.record(z.string(), z.string()).default({}),
|
|
33
|
+
extensions: extensionsSchema
|
|
34
|
+
}),
|
|
35
|
+
z.strictObject({
|
|
36
|
+
ref: harnessSessionRefSchema,
|
|
37
|
+
transport: z.literal(AcpTransport.Sandbox),
|
|
38
|
+
sandboxId: z.string().min(1),
|
|
39
|
+
start: sandboxStartSchema,
|
|
40
|
+
extensions: extensionsSchema
|
|
41
|
+
})
|
|
42
|
+
]);
|
|
43
|
+
const harnessProviderRefusalSchema = z.strictObject({
|
|
44
|
+
unsuitable: z.array(z.string().min(1)).min(1)
|
|
45
|
+
});
|
|
46
|
+
const harnessProviderOpenResultSchema = z.union([
|
|
47
|
+
harnessProviderEndpointSchema,
|
|
48
|
+
harnessProviderRefusalSchema
|
|
49
|
+
]);
|
|
50
|
+
const missingFinalExtensions = (initialize, required) => {
|
|
51
|
+
const advertised = advertisedFinalExtensions(initialize);
|
|
52
|
+
const has = {
|
|
53
|
+
[FinalExtension.Observe]: advertised.observe,
|
|
54
|
+
[FinalExtension.AuthorMeta]: advertised.authorMeta,
|
|
55
|
+
[FinalExtension.ResumeReplay]: advertised.resumeReplay === true,
|
|
56
|
+
[FinalExtension.Fork]: advertised.fork === true,
|
|
57
|
+
[FinalExtension.AfterSeqReplay]: advertised.afterSeqReplay
|
|
58
|
+
};
|
|
59
|
+
return required.filter((extension) => !has[extension]);
|
|
60
|
+
};
|
|
61
|
+
const startSandboxEndpoint = async (args) => {
|
|
62
|
+
const { start, sandbox } = args;
|
|
63
|
+
let process;
|
|
64
|
+
if (start.runtime === RuntimeKind.Process)
|
|
65
|
+
process = await sandbox.spawn({
|
|
66
|
+
command: start.command,
|
|
67
|
+
args: start.args,
|
|
68
|
+
env: start.env,
|
|
69
|
+
...start.cwd == null ? {} : { cwd: start.cwd },
|
|
70
|
+
...args.abortSignal == null ? {} : { abortSignal: args.abortSignal }
|
|
71
|
+
});
|
|
72
|
+
else {
|
|
73
|
+
if (sandbox.startWorker == null)
|
|
74
|
+
throw new Error(`The sandbox runs no worker programs (${start.program})`);
|
|
75
|
+
const started = await sandbox.startWorker({
|
|
76
|
+
program: start.program,
|
|
77
|
+
env: start.env,
|
|
78
|
+
input: start.input,
|
|
79
|
+
...args.abortSignal == null ? {} : { abortSignal: args.abortSignal }
|
|
80
|
+
});
|
|
81
|
+
if (isSandboxWorkerEndpoint(started))
|
|
82
|
+
throw new Error(
|
|
83
|
+
`The worker program ${start.program} serves its own endpoint; dial it instead of its streams`
|
|
84
|
+
);
|
|
85
|
+
process = started;
|
|
86
|
+
}
|
|
87
|
+
const input = new WritableStream({
|
|
88
|
+
write: (chunk) => process.write(chunk),
|
|
89
|
+
close: () => process.write(new Uint8Array(), { end: true })
|
|
90
|
+
});
|
|
91
|
+
return { process, stream: ndJsonStream(input, process.stdout) };
|
|
92
|
+
};
|
|
93
|
+
const harnessProviderHealthSchema = z.object({
|
|
94
|
+
ok: z.boolean(),
|
|
95
|
+
detail: z.string().optional(),
|
|
96
|
+
// Defaults to when the check returned.
|
|
97
|
+
checkedAt: z.string().optional()
|
|
98
|
+
});
|
|
99
|
+
export {
|
|
100
|
+
HARNESS_PROVIDER_EXPORTS,
|
|
101
|
+
harnessProviderEndpointSchema,
|
|
102
|
+
harnessProviderHealthSchema,
|
|
103
|
+
harnessProviderOpenResultSchema,
|
|
104
|
+
harnessProviderRefusalSchema,
|
|
105
|
+
missingFinalExtensions,
|
|
106
|
+
startSandboxEndpoint
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=harness-provider.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/harness-provider.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n ndJsonStream,\n type McpServer,\n type Stream,\n} from '@agentclientprotocol/sdk/experimental/v2';\nimport { advertisedFinalExtensions, type InitializeMetaHolderIface } from '@finalai/acp-session';\nimport { RuntimeKind, type Capability } from '@finalai/agent-protocol';\nimport type { ResolvedHarnessSettingsIface } from '@finalai/agent-protocol/agent-platform';\nimport * as z from 'zod';\nimport type { AgentDocumentIface } from \"./document.mjs\";\nimport type { JsonValue } from \"./json.mjs\";\nimport {\n AcpTransport,\n harnessSessionRefSchema,\n sandboxStartSchema,\n type CredentialGrantIface,\n type SandboxStartIface,\n type HarnessHealthIface,\n type HarnessObserverIface,\n type HarnessSessionContextIface,\n type HarnessSessionRefIface,\n type SandboxEndpointIface,\n type SecretReaderIface,\n type TraceContextIface,\n} from \"./harness.mjs\";\nimport {\n FinalExtension,\n type AcpAdapterDefinitionIface,\n type ComposedEnvironmentIface,\n type HarnessDefinitionIface,\n} from \"./harness-definition.mjs\";\nimport {\n isSandboxWorkerEndpoint,\n type SandboxProcessIface,\n type SandboxProcessOptionsIface,\n type SandboxWorkerOptionsIface,\n type SandboxWorkerStartType,\n} from \"./sandbox/types.mjs\";\n\n// A harness provider is the code that reaches a harness: one self-contained ES\n// module, run on the serverless runtime, exporting the functions of\n// HarnessProviderIface by name. The platform's general provider starts\n// adapter(harness) in its environment from the definitions' run entries and\n// is built on this same contract; a harness definition that carries its own\n// `provider` is reached by that code instead (a hosted fleet, a vendor API).\n//\n// Everything crossing the boundary is JSON: arguments in, endpoints out.\n\nexport const HARNESS_PROVIDER_EXPORTS = ['open', 'resume', 'park', 'close', 'health'] as const;\n\nexport type HarnessProviderExport = (typeof HARNESS_PROVIDER_EXPORTS)[number];\n\nexport interface PublishedDefinitionIface<Definition> {\n name: string;\n hash: string;\n definition: Definition;\n}\n\nexport interface HarnessProviderOpenArgsIface {\n session: HarnessSessionContextIface;\n // The session service's id for this harness session; key runtime state by it.\n harnessSessionId: string;\n harness: PublishedDefinitionIface<HarnessDefinitionIface>;\n // The adapter it runs behind; null when it speaks ACP v2 itself or runs at a URL.\n adapter: PublishedDefinitionIface<AcpAdapterDefinitionIface> | null;\n // Where it runs (composeHarness).\n environment: ComposedEnvironmentIface;\n // What the environment runs it as; null at a URL or without a run entry.\n runtime: RuntimeKind | null;\n // The caller's settings, defaults applied.\n settings: ResolvedHarnessSettingsIface;\n document: AgentDocumentIface;\n // ACP MCP server entries for `session/new`: the agent's tools, the provided\n // integrations, sandbox MCP projections where applicable.\n mcpServers: McpServer[];\n // The sandbox provided for each capability the harness drives on one.\n compute: Partial<Record<Capability, SandboxEndpointIface>>;\n credentials: CredentialGrantIface;\n trace: TraceContextIface;\n forkSource?: { ref: HarnessSessionRefIface; acpSessionId: string };\n}\n\nexport interface HarnessProviderResumeArgsIface extends HarnessProviderOpenArgsIface {\n ref: HarnessSessionRefIface;\n // Last log seq the session service holds; the harness replays anything newer.\n lastSeq: number;\n}\n\nexport interface HarnessProviderRefArgsIface {\n ref: HarnessSessionRefIface;\n environment: ComposedEnvironmentIface;\n}\n\nexport interface HarnessProviderCloseArgsIface extends HarnessProviderRefArgsIface {\n // Skip the graceful wait: the program did not settle ACP `session/close` in time.\n force: boolean;\n}\n\n// What every call gets besides its arguments.\nexport interface HarnessProviderContextIface {\n // The project's secrets the provider may read, by name.\n secrets: SecretReaderIface;\n // Lifecycle signals, recorded and never relied on.\n observer: HarnessObserverIface;\n}\n\n// The endpoint a provider returns: an ACP v2 endpoint the session service\n// dials, or a program it starts in the environment sandbox (ACP on stdio or\n// the worker's stream; nothing listens on a port). `extensions` are the Final\n// ACP extensions its `initialize` must advertise: the session service refuses\n// an endpoint missing any (missingFinalExtensions) as unsuitable, naming them.\nconst extensionsSchema = z.array(z.nativeEnum(FinalExtension)).default([]);\n\nexport const harnessProviderEndpointSchema = z.discriminatedUnion('transport', [\n z.strictObject({\n ref: harnessSessionRefSchema,\n transport: z.literal(AcpTransport.Ws),\n url: z.string().url(),\n headers: z.record(z.string(), z.string()).default({}),\n extensions: extensionsSchema,\n }),\n z.strictObject({\n ref: harnessSessionRefSchema,\n transport: z.literal(AcpTransport.Http),\n url: z.string().url(),\n headers: z.record(z.string(), z.string()).default({}),\n extensions: extensionsSchema,\n }),\n z.strictObject({\n ref: harnessSessionRefSchema,\n transport: z.literal(AcpTransport.Sandbox),\n sandboxId: z.string().min(1),\n start: sandboxStartSchema,\n extensions: extensionsSchema,\n }),\n]);\n\n// A provider that cannot reach the harness under these settings says why; the\n// session service reports it as an unsuitable harness requirement.\nexport const harnessProviderRefusalSchema = z.strictObject({\n unsuitable: z.array(z.string().min(1)).min(1),\n});\n\nexport type HarnessProviderRefusalIface = z.output<typeof harnessProviderRefusalSchema>;\n\n// What open and resume answer.\nexport const harnessProviderOpenResultSchema = z.union([\n harnessProviderEndpointSchema,\n harnessProviderRefusalSchema,\n]);\n\n// The extensions of `required` an `initialize` response does not advertise.\nexport const missingFinalExtensions = (\n initialize: InitializeMetaHolderIface,\n required: readonly FinalExtension[],\n): FinalExtension[] => {\n const advertised = advertisedFinalExtensions(initialize);\n const has: Record<FinalExtension, boolean> = {\n [FinalExtension.Observe]: advertised.observe,\n [FinalExtension.AuthorMeta]: advertised.authorMeta,\n [FinalExtension.ResumeReplay]: advertised.resumeReplay === true,\n [FinalExtension.Fork]: advertised.fork === true,\n [FinalExtension.AfterSeqReplay]: advertised.afterSeqReplay,\n };\n return required.filter((extension) => !has[extension]);\n};\n\nexport type HarnessProviderEndpointIface = z.output<typeof harnessProviderEndpointSchema>;\nexport type HarnessProviderEndpointInputIface = z.input<typeof harnessProviderEndpointSchema>;\n\n// What provider code returns. Its source cannot import the contract's enums,\n// so their values may be written as the strings they are.\ntype EnumLiteral<E extends string> = E | `${E}`;\n\ninterface ExtensionsResultIface {\n extensions?: EnumLiteral<FinalExtension>[];\n}\n\nexport type HarnessProviderEndpointResultIface =\n | (ExtensionsResultIface & {\n ref: HarnessSessionRefIface;\n transport: EnumLiteral<AcpTransport.Ws> | EnumLiteral<AcpTransport.Http>;\n url: string;\n headers?: Record<string, string>;\n })\n | (ExtensionsResultIface & {\n ref: HarnessSessionRefIface;\n transport: EnumLiteral<AcpTransport.Sandbox>;\n sandboxId: string;\n start:\n | {\n runtime: EnumLiteral<RuntimeKind.Process>;\n command: string;\n args?: string[];\n env?: Record<string, string>;\n cwd?: string;\n }\n | {\n runtime: EnumLiteral<RuntimeKind.Worker>;\n program: string;\n env?: Record<string, string>;\n input?: JsonValue;\n };\n });\n\nexport type HarnessProviderOpenResultIface =\n | HarnessProviderEndpointResultIface\n | HarnessProviderRefusalIface;\n\n// What starting a `sandbox` endpoint needs of its sandbox: a process\n// environment spawns, a worker runtime starts worker programs.\nexport interface SandboxEndpointHostIface {\n spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;\n startWorker?(options: SandboxWorkerOptionsIface): Promise<SandboxWorkerStartType>;\n}\n\n// Starts what a `sandbox` endpoint names in its environment sandbox and\n// returns the ACP stream on its stdio (a process) or its stream (a worker\n// program), over the sandbox's own process streams: nothing listens on a port.\nexport const startSandboxEndpoint = async (args: {\n sandbox: SandboxEndpointHostIface;\n start: SandboxStartIface;\n abortSignal?: AbortSignal;\n}): Promise<{ process: SandboxProcessIface; stream: Stream }> => {\n const { start, sandbox } = args;\n let process: SandboxProcessIface;\n if (start.runtime === RuntimeKind.Process)\n process = await sandbox.spawn({\n command: start.command,\n args: start.args,\n env: start.env,\n ...(start.cwd == null ? {} : { cwd: start.cwd }),\n ...(args.abortSignal == null ? {} : { abortSignal: args.abortSignal }),\n });\n else {\n if (sandbox.startWorker == null)\n throw new Error(`The sandbox runs no worker programs (${start.program})`);\n const started = await sandbox.startWorker({\n program: start.program,\n env: start.env,\n input: start.input,\n ...(args.abortSignal == null ? {} : { abortSignal: args.abortSignal }),\n });\n // A program serving an endpoint of its own is dialed there, not over its streams.\n if (isSandboxWorkerEndpoint(started))\n throw new Error(\n `The worker program ${start.program} serves its own endpoint; dial it instead of its streams`,\n );\n process = started;\n }\n const input = new WritableStream<Uint8Array>({\n write: (chunk) => process.write(chunk),\n close: () => process.write(new Uint8Array(), { end: true }),\n });\n return { process, stream: ndJsonStream(input, process.stdout) };\n};\n\nexport const harnessProviderHealthSchema = z.object({\n ok: z.boolean(),\n detail: z.string().optional(),\n // Defaults to when the check returned.\n checkedAt: z.string().optional(),\n});\n\nexport interface HarnessProviderIface {\n open(\n args: HarnessProviderOpenArgsIface,\n ctx: HarnessProviderContextIface,\n ): Promise<HarnessProviderOpenResultIface>;\n resume(\n args: HarnessProviderResumeArgsIface,\n ctx: HarnessProviderContextIface,\n ): Promise<HarnessProviderOpenResultIface>;\n park(args: HarnessProviderRefArgsIface, ctx: HarnessProviderContextIface): Promise<void>;\n // Graceful unless `force`: the harness's state is durable before it stops.\n close(args: HarnessProviderCloseArgsIface, ctx: HarnessProviderContextIface): Promise<void>;\n health(\n args: HarnessProviderRefArgsIface,\n ctx: HarnessProviderContextIface,\n ): Promise<Omit<HarnessHealthIface, 'checkedAt'> & { checkedAt?: string }>;\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,iCAAiE;AAC1E,SAAS,mBAAoC;AAE7C,YAAY,OAAO;AAGnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAUK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAKK;AAWA,MAAM,2BAA2B,CAAC,QAAQ,UAAU,QAAQ,SAAS,QAAQ;AA+DpF,MAAM,mBAAmB,EAAE,MAAM,EAAE,WAAW,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC;AAElE,MAAM,gCAAgC,EAAE,mBAAmB,aAAa;AAAA,EAC7E,EAAE,aAAa;AAAA,IACb,KAAK;AAAA,IACL,W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@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PermissionLevel } from '@finalai/agent-protocol/agent-platform';
|
|
2
|
+
import { HarnessFeature, type AgentDocumentIface } from "./document.mjs";
|
|
3
|
+
export { PermissionLevel, narrowerPermission, permissionWithin, } from '@finalai/agent-protocol/agent-platform';
|
|
4
|
+
export declare const harnessFeaturesUsed: (document: AgentDocumentIface) => HarnessFeature[];
|
|
5
|
+
export declare const requiredHarnessFeatures: (document: AgentDocumentIface) => HarnessFeature[];
|
|
6
|
+
export interface HarnessSuitabilityArgsIface {
|
|
7
|
+
document: AgentDocumentIface;
|
|
8
|
+
supports: readonly HarnessFeature[];
|
|
9
|
+
lowestPermission: PermissionLevel;
|
|
10
|
+
permissionMode?: PermissionLevel;
|
|
11
|
+
}
|
|
12
|
+
export interface HarnessUnsuitabilityIface {
|
|
13
|
+
missingFeatures: HarnessFeature[];
|
|
14
|
+
permission: {
|
|
15
|
+
ceiling: PermissionLevel;
|
|
16
|
+
offered: PermissionLevel;
|
|
17
|
+
} | null;
|
|
18
|
+
}
|
|
19
|
+
export declare const harnessUnsuitability: (args: HarnessSuitabilityArgsIface) => HarnessUnsuitabilityIface | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PermissionLevel, permissionWithin } from "@finalai/agent-protocol/agent-platform";
|
|
2
|
+
import { HarnessFeature } from "./document.mjs";
|
|
3
|
+
import {
|
|
4
|
+
PermissionLevel as PermissionLevel2,
|
|
5
|
+
narrowerPermission,
|
|
6
|
+
permissionWithin as permissionWithin2
|
|
7
|
+
} from "@finalai/agent-protocol/agent-platform";
|
|
8
|
+
const harnessFeaturesUsed = (document) => {
|
|
9
|
+
const used = /* @__PURE__ */ new Set();
|
|
10
|
+
if (document.skills.length > 0) used.add(HarnessFeature.Skills);
|
|
11
|
+
if (Object.keys(document.tools).length > 0 || Object.keys(document.require.integrations).length > 0)
|
|
12
|
+
used.add(HarnessFeature.McpTools);
|
|
13
|
+
if (Object.keys(document.toolPolicy).length > 0) used.add(HarnessFeature.NativeToolPolicy);
|
|
14
|
+
if (document.instructions.trim().length > 0) used.add(HarnessFeature.SystemInstructions);
|
|
15
|
+
return [...used];
|
|
16
|
+
};
|
|
17
|
+
const requiredHarnessFeatures = (document) => {
|
|
18
|
+
const optional = new Set(document.require.harness.optionalFeatures);
|
|
19
|
+
return harnessFeaturesUsed(document).filter((feature) => !optional.has(feature));
|
|
20
|
+
};
|
|
21
|
+
const harnessUnsuitability = (args) => {
|
|
22
|
+
const supported = new Set(args.supports);
|
|
23
|
+
const missingFeatures = requiredHarnessFeatures(args.document).filter(
|
|
24
|
+
(feature) => !supported.has(feature)
|
|
25
|
+
);
|
|
26
|
+
const ceiling = args.document.require.harness.permissionMode;
|
|
27
|
+
const offered = args.permissionMode ?? args.lowestPermission;
|
|
28
|
+
const permission = permissionWithin(args.lowestPermission, ceiling) && permissionWithin(offered, ceiling) ? null : { ceiling, offered };
|
|
29
|
+
if (missingFeatures.length === 0 && permission == null) return null;
|
|
30
|
+
return { missingFeatures, permission };
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
PermissionLevel2 as PermissionLevel,
|
|
34
|
+
harnessFeaturesUsed,
|
|
35
|
+
harnessUnsuitability,
|
|
36
|
+
narrowerPermission,
|
|
37
|
+
permissionWithin2 as permissionWithin,
|
|
38
|
+
requiredHarnessFeatures
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=harness-requirements.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/harness-requirements.ts"],
|
|
4
|
+
"sourcesContent": ["import { PermissionLevel, permissionWithin } from '@finalai/agent-protocol/agent-platform';\nimport { HarnessFeature, type AgentDocumentIface } from \"./document.mjs\";\n\nexport {\n PermissionLevel,\n narrowerPermission,\n permissionWithin,\n} from '@finalai/agent-protocol/agent-platform';\n\n// Harness features an agent's parts need. Computed, never stored in the\n// document: recording derived data would change the hash whenever the\n// derivation changes.\nexport const harnessFeaturesUsed = (document: AgentDocumentIface): HarnessFeature[] => {\n const used = new Set<HarnessFeature>();\n if (document.skills.length > 0) used.add(HarnessFeature.Skills);\n if (\n Object.keys(document.tools).length > 0 ||\n Object.keys(document.require.integrations).length > 0\n )\n used.add(HarnessFeature.McpTools);\n if (Object.keys(document.toolPolicy).length > 0) used.add(HarnessFeature.NativeToolPolicy);\n if (document.instructions.trim().length > 0) used.add(HarnessFeature.SystemInstructions);\n return [...used];\n};\n\n// The features a harness must support for this agent: what it uses, less what\n// its author marked optional.\nexport const requiredHarnessFeatures = (document: AgentDocumentIface): HarnessFeature[] => {\n const optional = new Set(document.require.harness.optionalFeatures);\n return harnessFeaturesUsed(document).filter((feature) => !optional.has(feature));\n};\n\nexport interface HarnessSuitabilityArgsIface {\n document: AgentDocumentIface;\n // Features the harness supports, from its description.\n supports: readonly HarnessFeature[];\n // The most the harness can be limited to; a harness that cannot ask is `auto`.\n lowestPermission: PermissionLevel;\n // The mode the caller picked, if any.\n permissionMode?: PermissionLevel;\n}\n\nexport interface HarnessUnsuitabilityIface {\n missingFeatures: HarnessFeature[];\n // Set when the harness cannot be held at or below the agent's ceiling.\n permission: { ceiling: PermissionLevel; offered: PermissionLevel } | null;\n}\n\n// Null when the harness suits the agent.\nexport const harnessUnsuitability = (\n args: HarnessSuitabilityArgsIface,\n): HarnessUnsuitabilityIface | null => {\n const supported = new Set(args.supports);\n const missingFeatures = requiredHarnessFeatures(args.document).filter(\n (feature) => !supported.has(feature),\n );\n const ceiling = args.document.require.harness.permissionMode;\n const offered = args.permissionMode ?? args.lowestPermission;\n const permission =\n permissionWithin(args.lowestPermission, ceiling) && permissionWithin(offered, ceiling)\n ? null\n : { ceiling, offered };\n if (missingFeatures.length === 0 && permission == null) return null;\n return { missingFeatures, permission };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB,wBAAwB;AAClD,SAAS,sBAA+C;AAExD;AAAA,EACE,mBAAAA;A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ntimeKind } from '@finalai/agent-protocol/runtime-kind';
|
|
2
|
+
import type { SandboxStartIface } from "./harness.mjs";
|
|
3
|
+
import type { AcpAdapterDefinitionIface, HarnessDefinitionIface, RunEntriesIface } from "./harness-definition.mjs";
|
|
4
|
+
export declare const ACP_V2_INTERFACE = "acp-v2";
|
|
5
|
+
export declare enum FinalExtension {
|
|
6
|
+
Observe = "observe",
|
|
7
|
+
AuthorMeta = "authorMeta",
|
|
8
|
+
ResumeReplay = "resumeReplay",
|
|
9
|
+
Fork = "fork",
|
|
10
|
+
AfterSeqReplay = "afterSeqReplay"
|
|
11
|
+
}
|
|
12
|
+
export declare enum HarnessEnvironmentKind {
|
|
13
|
+
Sandbox = "sandbox",
|
|
14
|
+
Url = "url"
|
|
15
|
+
}
|
|
16
|
+
export declare const PLACEHOLDER: RegExp;
|
|
17
|
+
export declare const HARNESS_COMMAND_PATH = "harness.command";
|
|
18
|
+
export declare const runtimesOf: (run: RunEntriesIface) => RuntimeKind[];
|
|
19
|
+
type ConfigurationIface = Readonly<Record<string, unknown>>;
|
|
20
|
+
export type HarnessStartResult = {
|
|
21
|
+
ok: true;
|
|
22
|
+
start: SandboxStartIface;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
problems: string[];
|
|
26
|
+
};
|
|
27
|
+
export declare const harnessStartFor: (args: {
|
|
28
|
+
harness: HarnessDefinitionIface;
|
|
29
|
+
adapter: AcpAdapterDefinitionIface | null;
|
|
30
|
+
runtime: RuntimeKind;
|
|
31
|
+
configuration: ConfigurationIface;
|
|
32
|
+
}) => HarnessStartResult;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { RUNTIME_KINDS, RuntimeKind } from "@finalai/agent-protocol/runtime-kind";
|
|
2
|
+
const ACP_V2_INTERFACE = "acp-v2";
|
|
3
|
+
var FinalExtension = /* @__PURE__ */ ((FinalExtension2) => {
|
|
4
|
+
FinalExtension2["Observe"] = "observe";
|
|
5
|
+
FinalExtension2["AuthorMeta"] = "authorMeta";
|
|
6
|
+
FinalExtension2["ResumeReplay"] = "resumeReplay";
|
|
7
|
+
FinalExtension2["Fork"] = "fork";
|
|
8
|
+
FinalExtension2["AfterSeqReplay"] = "afterSeqReplay";
|
|
9
|
+
return FinalExtension2;
|
|
10
|
+
})(FinalExtension || {});
|
|
11
|
+
var HarnessEnvironmentKind = /* @__PURE__ */ ((HarnessEnvironmentKind2) => {
|
|
12
|
+
HarnessEnvironmentKind2["Sandbox"] = "sandbox";
|
|
13
|
+
HarnessEnvironmentKind2["Url"] = "url";
|
|
14
|
+
return HarnessEnvironmentKind2;
|
|
15
|
+
})(HarnessEnvironmentKind || {});
|
|
16
|
+
const PLACEHOLDER = /\{\{\s*([A-Za-z0-9_.-]+)\s*\}\}/gu;
|
|
17
|
+
const HARNESS_COMMAND_PATH = "harness.command";
|
|
18
|
+
const runtimesOf = (run) => RUNTIME_KINDS.filter((kind) => run[kind] != null);
|
|
19
|
+
const isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
const isJsonValue = (value) => {
|
|
21
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
22
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
23
|
+
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
24
|
+
return isRecord(value) && Object.values(value).every(isJsonValue);
|
|
25
|
+
};
|
|
26
|
+
const isJsonObject = (value) => isRecord(value) && isJsonValue(value);
|
|
27
|
+
const valueAt = (context, path) => {
|
|
28
|
+
if (path === HARNESS_COMMAND_PATH) return context.harness?.command;
|
|
29
|
+
let value = context.configuration;
|
|
30
|
+
for (const key of path.split(".").slice(1)) {
|
|
31
|
+
if (!isRecord(value)) return void 0;
|
|
32
|
+
value = value[key];
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const isSet = (value) => value !== void 0 && value !== null && value !== false;
|
|
37
|
+
const textOf = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
38
|
+
const render = (template, context, problems) => template.replace(PLACEHOLDER, (_match, path) => {
|
|
39
|
+
const value = valueAt(context, path);
|
|
40
|
+
if (value === void 0 || value === null) {
|
|
41
|
+
problems.push(`{{${path}}} has no value`);
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
return textOf(value);
|
|
45
|
+
});
|
|
46
|
+
const renderProcess = (run, context, problems) => {
|
|
47
|
+
const args = [];
|
|
48
|
+
for (const arg of run.args) {
|
|
49
|
+
if (typeof arg === "string") args.push(render(arg, context, problems));
|
|
50
|
+
else if ("spread" in arg) args.push(...context.harness?.args ?? []);
|
|
51
|
+
else if (isSet(valueAt(context, arg.when)))
|
|
52
|
+
for (const template of arg.args) args.push(render(template, context, problems));
|
|
53
|
+
}
|
|
54
|
+
const env = {};
|
|
55
|
+
for (const [key, value] of Object.entries(run.env)) {
|
|
56
|
+
if (typeof value === "string") env[key] = render(value, context, problems);
|
|
57
|
+
else if (isSet(valueAt(context, value.when))) env[key] = render(value.value, context, problems);
|
|
58
|
+
}
|
|
59
|
+
return { command: render(run.command, context, problems), args, env };
|
|
60
|
+
};
|
|
61
|
+
const harnessStartFor = (args) => {
|
|
62
|
+
const problems = [];
|
|
63
|
+
const { harness, adapter, configuration } = args;
|
|
64
|
+
if (!isJsonObject(configuration))
|
|
65
|
+
return { ok: false, problems: ["The configuration is not a JSON object"] };
|
|
66
|
+
if (args.runtime === RuntimeKind.Process) {
|
|
67
|
+
const own2 = harness.run.process;
|
|
68
|
+
const wrapper2 = adapter == null ? null : adapter.run.process;
|
|
69
|
+
if (own2 == null || adapter != null && wrapper2 == null)
|
|
70
|
+
return { ok: false, problems: ["No process entry to start"] };
|
|
71
|
+
const started = renderProcess(own2, { configuration, harness: null }, problems);
|
|
72
|
+
const outer = wrapper2 == null ? started : renderProcess(
|
|
73
|
+
wrapper2,
|
|
74
|
+
{ configuration, harness: { command: started.command, args: started.args } },
|
|
75
|
+
problems
|
|
76
|
+
);
|
|
77
|
+
const env = wrapper2 == null ? started.env : { ...started.env, ...outer.env };
|
|
78
|
+
if (problems.length > 0) return { ok: false, problems };
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
start: { runtime: RuntimeKind.Process, command: outer.command, args: outer.args, env }
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const own = harness.run.worker;
|
|
85
|
+
const wrapper = adapter == null ? null : adapter.run.worker;
|
|
86
|
+
if (own == null || adapter != null && wrapper == null)
|
|
87
|
+
return { ok: false, problems: ["No worker entry to start"] };
|
|
88
|
+
return {
|
|
89
|
+
ok: true,
|
|
90
|
+
start: {
|
|
91
|
+
runtime: RuntimeKind.Worker,
|
|
92
|
+
program: wrapper?.program ?? own.program,
|
|
93
|
+
env: {},
|
|
94
|
+
input: wrapper == null ? { configuration } : { harness: { program: own.program }, configuration }
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
ACP_V2_INTERFACE,
|
|
100
|
+
FinalExtension,
|
|
101
|
+
HARNESS_COMMAND_PATH,
|
|
102
|
+
HarnessEnvironmentKind,
|
|
103
|
+
PLACEHOLDER,
|
|
104
|
+
harnessStartFor,
|
|
105
|
+
runtimesOf
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=harness-start.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/harness-start.ts"],
|
|
4
|
+
"sourcesContent": ["import { RUNTIME_KINDS, RuntimeKind } from '@finalai/agent-protocol/runtime-kind';\nimport type { SandboxStartIface } from \"./harness.mjs\";\nimport type { JsonObject, JsonValue } from \"./json.mjs\";\nimport type {\n AcpAdapterDefinitionIface,\n HarnessDefinitionIface,\n ProcessRunIface,\n RunEntriesIface,\n} from \"./harness-definition.mjs\";\n\n// The parts of harness composition that run inside a harness provider: what to\n// start for adapter(harness), and the names it is decided by. Free of runtime\n// dependencies, so a provider bundles it into its self-contained module.\n\n// The interface a harness that speaks ACP v2 itself declares.\nexport const ACP_V2_INTERFACE = 'acp-v2';\n\n// Final's ACP extensions an agent advertises in its `initialize` response\n// (`_meta[\"final.ai\"].supports`), by flag name.\nexport enum FinalExtension {\n Observe = 'observe',\n AuthorMeta = 'authorMeta',\n ResumeReplay = 'resumeReplay',\n Fork = 'fork',\n AfterSeqReplay = 'afterSeqReplay',\n}\n\nexport enum HarnessEnvironmentKind {\n Sandbox = 'sandbox',\n Url = 'url',\n}\n\n// `{{configuration.model}}`, `{{harness.command}}`: a value from the harness\n// settings' configuration, or (in an adapter's entry) the harness command it wraps.\nexport const PLACEHOLDER = /\\{\\{\\s*([A-Za-z0-9_.-]+)\\s*\\}\\}/gu;\nexport const HARNESS_COMMAND_PATH = 'harness.command';\n\nexport const runtimesOf = (run: RunEntriesIface): RuntimeKind[] =>\n RUNTIME_KINDS.filter((kind) => run[kind] != null);\n\n// What to start: the run entries rendered against the settings'\n// configuration.\n\n// The settings' configuration: JSON, as the settings schema parsed it.\ntype ConfigurationIface = Readonly<Record<string, unknown>>;\n\ninterface RunContextIface {\n configuration: ConfigurationIface;\n harness: { command: string; args: string[] } | null;\n}\n\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n value != null && typeof value === 'object' && !Array.isArray(value);\n\nconst isJsonValue = (value: unknown): value is JsonValue => {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (Array.isArray(value)) return value.every(isJsonValue);\n return isRecord(value) && Object.values(value).every(isJsonValue);\n};\n\nconst isJsonObject = (value: unknown): value is JsonObject => isRecord(value) && isJsonValue(value);\n\nconst valueAt = (context: RunContextIface, path: string): unknown => {\n if (path === HARNESS_COMMAND_PATH) return context.harness?.command;\n let value: unknown = context.configuration;\n for (const key of path.split('.').slice(1)) {\n if (!isRecord(value)) return undefined;\n value = value[key];\n }\n return value;\n};\n\nconst isSet = (value: unknown): boolean => value !== undefined && value !== null && value !== false;\n\nconst textOf = (value: unknown): string =>\n typeof value === 'string' ? value : JSON.stringify(value);\n\nconst render = (template: string, context: RunContextIface, problems: string[]): string =>\n template.replace(PLACEHOLDER, (_match, path: string) => {\n const value = valueAt(context, path);\n if (value === undefined || value === null) {\n problems.push(`{{${path}}} has no value`);\n return '';\n }\n return textOf(value);\n });\n\nconst renderProcess = (\n run: ProcessRunIface,\n context: RunContextIface,\n problems: string[],\n): { command: string; args: string[]; env: Record<string, string> } => {\n const args: string[] = [];\n for (const arg of run.args) {\n if (typeof arg === 'string') args.push(render(arg, context, problems));\n else if ('spread' in arg) args.push(...(context.harness?.args ?? []));\n else if (isSet(valueAt(context, arg.when)))\n for (const template of arg.args) args.push(render(template, context, problems));\n }\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(run.env)) {\n if (typeof value === 'string') env[key] = render(value, context, problems);\n else if (isSet(valueAt(context, value.when))) env[key] = render(value.value, context, problems);\n }\n return { command: render(run.command, context, problems), args, env };\n};\n\nexport type HarnessStartResult =\n | { ok: true; start: SandboxStartIface }\n | { ok: false; problems: string[] };\n\n// What a provider starts for adapter(harness) as `runtime`: an adapter's\n// process entry wraps the harness's rendered command; an adapter's worker\n// program gets the harness's program in its input.\nexport const harnessStartFor = (args: {\n harness: HarnessDefinitionIface;\n adapter: AcpAdapterDefinitionIface | null;\n runtime: RuntimeKind;\n configuration: ConfigurationIface;\n}): HarnessStartResult => {\n const problems: string[] = [];\n const { harness, adapter, configuration } = args;\n if (!isJsonObject(configuration))\n return { ok: false, problems: ['The configuration is not a JSON object'] };\n if (args.runtime === RuntimeKind.Process) {\n const own = harness.run.process;\n const wrapper = adapter == null ? null : adapter.run.process;\n if (own == null || (adapter != null && wrapper == null))\n return { ok: false, problems: ['No process entry to start'] };\n const started = renderProcess(own, { configuration, harness: null }, problems);\n const outer =\n wrapper == null\n ? started\n : renderProcess(\n wrapper,\n { configuration, harness: { command: started.command, args: started.args } },\n problems,\n );\n const env = wrapper == null ? started.env : { ...started.env, ...outer.env };\n if (problems.length > 0) return { ok: false, problems };\n return {\n ok: true,\n start: { runtime: RuntimeKind.Process, command: outer.command, args: outer.args, env },\n };\n }\n const own = harness.run.worker;\n const wrapper = adapter == null ? null : adapter.run.worker;\n if (own == null || (adapter != null && wrapper == null))\n return { ok: false, problems: ['No worker entry to start'] };\n return {\n ok: true,\n start: {\n runtime: RuntimeKind.Worker,\n program: wrapper?.program ?? own.program,\n env: {},\n input:\n wrapper == null ? { configuration } : { harness: { program: own.program }, configuration },\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,eAAe,mBAAmB;AAepC,MAAM,mBAAmB;AAIzB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,aAAU;AACV,EAAAA,gBAAA,gBAAa;AACb,EAAAA,gBAAA,kBAAe;AACf,EAAAA,gBAAA,UAAO;AACP,EAAAA,gBAAA,oBAAiB;AALP,SAAAA;AAAA,GAAA;AAQL,IAAK,yBAAL,kBAAKC,4BAAL;AACL,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,SAAM;AAFI,SAAAA;AAAA,GAAA;AAOL,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAE7B,MAAM,aAAa,CAAC,QACzB,cAAc,OAAO,CAAC,SAAS,IAAI,IAAI,KAAK,IAAI;AAalD,MAAM,WAAW,CAAC,UAChB,SAAS,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAEpE,MAAM,cAAc,CAAC,UAAuC;AAC1D,MAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,QAAO;AACtF,MAAI,OAAO,UAAU,SAAU,QAAO,OAAO,SAAS,KAAK;AAC3D,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,MAAM,WAAW;AACxD,SAAO,SAAS,KAAK,KAAK,OAAO,OAAO,KAAK,EAAE,MAAM,WAAW;AAClE;AAEA,MAAM,e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