@finalai/agent-definition 0.1.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.
Potentially problematic release.
This version of @finalai/agent-definition might be problematic. Click here for more details.
- package/README.md +16 -0
- package/THIRD_PARTY_NOTICES.md +303 -0
- package/dist/compiler-assets/chunk-2CZRHOLL.ts +10 -0
- package/dist/compiler-assets/chunk-32O3ODZE.ts +39 -0
- package/dist/compiler-assets/chunk-5BK6FVRE.ts +75 -0
- package/dist/compiler-assets/chunk-6WR3PGNF.ts +0 -0
- package/dist/compiler-assets/chunk-7QP2CKPI.ts +30 -0
- package/dist/compiler-assets/chunk-7VSSVZM4.ts +55 -0
- package/dist/compiler-assets/chunk-7WGYG73V.ts +42 -0
- package/dist/compiler-assets/chunk-BLB6JGLO.ts +481 -0
- package/dist/compiler-assets/chunk-CWWRTRWW.ts +76 -0
- package/dist/compiler-assets/chunk-EVQIK62B.ts +188 -0
- package/dist/compiler-assets/chunk-GNR7XBPN.ts +3364 -0
- package/dist/compiler-assets/chunk-GTUZOATD.ts +10 -0
- package/dist/compiler-assets/chunk-HFS4KLEL.ts +10 -0
- package/dist/compiler-assets/chunk-HGW4YHAY.ts +6865 -0
- package/dist/compiler-assets/chunk-HNPUTP35.ts +172 -0
- package/dist/compiler-assets/chunk-JIPNTA56.ts +59 -0
- package/dist/compiler-assets/chunk-JNJE72EH.ts +10 -0
- package/dist/compiler-assets/chunk-JPY4L2UJ.ts +349 -0
- package/dist/compiler-assets/chunk-JTGTLYDT.ts +0 -0
- package/dist/compiler-assets/chunk-LUSAAV4L.ts +33 -0
- package/dist/compiler-assets/chunk-MZMSKIKU.ts +472 -0
- package/dist/compiler-assets/chunk-NMYHO2QN.ts +25 -0
- package/dist/compiler-assets/chunk-NYTOYKKF.ts +28 -0
- package/dist/compiler-assets/chunk-OWC6SFFF.ts +295 -0
- package/dist/compiler-assets/chunk-QMKWAFVZ.ts +59 -0
- package/dist/compiler-assets/chunk-QMWTDPNT.ts +79 -0
- package/dist/compiler-assets/chunk-RWUIMTBI.ts +13 -0
- package/dist/compiler-assets/chunk-SKTNMUO7.ts +64 -0
- package/dist/compiler-assets/chunk-T6WG4L4M.ts +19 -0
- package/dist/compiler-assets/chunk-TATN3PYK.ts +81 -0
- package/dist/compiler-assets/chunk-VHXHUU7L.ts +16 -0
- package/dist/compiler-assets/chunk-WMXMVFHM.ts +121 -0
- package/dist/compiler-assets/chunk-XHKPWT3G.ts +55 -0
- package/dist/compiler-assets/chunk-ZDLVA6XF.ts +476 -0
- package/dist/compiler-assets/src/authoring/agent.ts +10 -0
- package/dist/compiler-assets/src/authoring/approval.ts +19 -0
- package/dist/compiler-assets/src/authoring/brand.ts +23 -0
- package/dist/compiler-assets/src/authoring/channels.ts +26 -0
- package/dist/compiler-assets/src/authoring/connections.ts +10 -0
- package/dist/compiler-assets/src/authoring/context.ts +7 -0
- package/dist/compiler-assets/src/authoring/credentials.ts +21 -0
- package/dist/compiler-assets/src/authoring/dynamic.ts +10 -0
- package/dist/compiler-assets/src/authoring/harness.ts +17 -0
- package/dist/compiler-assets/src/authoring/hooks.ts +28 -0
- package/dist/compiler-assets/src/authoring/index.ts +110 -0
- package/dist/compiler-assets/src/authoring/instructions.ts +14 -0
- package/dist/compiler-assets/src/authoring/sandbox.ts +25 -0
- package/dist/compiler-assets/src/authoring/schedules.ts +10 -0
- package/dist/compiler-assets/src/authoring/skills.ts +10 -0
- package/dist/compiler-assets/src/authoring/tools.ts +23 -0
- package/dist/compiler-assets/src/compatibility.ts +14810 -0
- package/dist/compiler-assets/src/compiler/evaluate-child.mjs +77 -0
- package/dist/compiler-assets/src/index.ts +195 -0
- package/dist/compiler-assets/src/manifest.ts +72 -0
- package/dist/compiler-assets/src/resolve.ts +19 -0
- package/dist/compiler-assets/src/runtime/bundle.ts +72 -0
- package/dist/compiler-assets/src/runtime/describe.ts +31 -0
- package/dist/compiler-assets/src/runtime/described.ts +142 -0
- package/dist/compiler-assets/src/runtime/isolate.ts +28 -0
- package/dist/compiler-assets/src/runtime/layout.ts +15 -0
- package/dist/compiler-assets/src/runtime/lower.ts +52 -0
- package/dist/compiler-assets/src/runtime/schema-validation.ts +21 -0
- package/dist/compiler-assets/src/runtime/values.ts +38 -0
- package/dist/modules/authoring/agent.d.mts +22 -0
- package/dist/modules/authoring/agent.mjs +6 -0
- package/dist/modules/authoring/agent.mjs.map +7 -0
- package/dist/modules/authoring/approval.d.mts +17 -0
- package/dist/modules/authoring/approval.mjs +42 -0
- package/dist/modules/authoring/approval.mjs.map +7 -0
- package/dist/modules/authoring/brand.d.mts +27 -0
- package/dist/modules/authoring/brand.mjs +51 -0
- package/dist/modules/authoring/brand.mjs.map +7 -0
- package/dist/modules/authoring/channels.d.mts +41 -0
- package/dist/modules/authoring/channels.mjs +65 -0
- package/dist/modules/authoring/channels.mjs.map +7 -0
- package/dist/modules/authoring/connections.d.mts +23 -0
- package/dist/modules/authoring/connections.mjs +6 -0
- package/dist/modules/authoring/connections.mjs.map +7 -0
- package/dist/modules/authoring/context.d.mts +83 -0
- package/dist/modules/authoring/context.mjs +12 -0
- package/dist/modules/authoring/context.mjs.map +7 -0
- package/dist/modules/authoring/credentials.d.mts +10 -0
- package/dist/modules/authoring/credentials.mjs +31 -0
- package/dist/modules/authoring/credentials.mjs.map +7 -0
- package/dist/modules/authoring/dynamic.d.mts +30 -0
- package/dist/modules/authoring/dynamic.mjs +15 -0
- package/dist/modules/authoring/dynamic.mjs.map +7 -0
- package/dist/modules/authoring/harness.d.mts +85 -0
- package/dist/modules/authoring/harness.mjs +55 -0
- package/dist/modules/authoring/harness.mjs.map +7 -0
- package/dist/modules/authoring/hooks.d.mts +120 -0
- package/dist/modules/authoring/hooks.mjs +72 -0
- package/dist/modules/authoring/hooks.mjs.map +7 -0
- package/dist/modules/authoring/index.d.mts +27 -0
- package/dist/modules/authoring/index.mjs +63 -0
- package/dist/modules/authoring/index.mjs.map +7 -0
- package/dist/modules/authoring/instructions.d.mts +13 -0
- package/dist/modules/authoring/instructions.mjs +15 -0
- package/dist/modules/authoring/instructions.mjs.map +7 -0
- package/dist/modules/authoring/sandbox.d.mts +21 -0
- package/dist/modules/authoring/sandbox.mjs +13 -0
- package/dist/modules/authoring/sandbox.mjs.map +7 -0
- package/dist/modules/authoring/schedules.d.mts +8 -0
- package/dist/modules/authoring/schedules.mjs +6 -0
- package/dist/modules/authoring/schedules.mjs.map +7 -0
- package/dist/modules/authoring/skills.d.mts +8 -0
- package/dist/modules/authoring/skills.mjs +6 -0
- package/dist/modules/authoring/skills.mjs.map +7 -0
- package/dist/modules/authoring/tools.d.mts +80 -0
- package/dist/modules/authoring/tools.mjs +70 -0
- package/dist/modules/authoring/tools.mjs.map +7 -0
- package/dist/modules/compatibility.d.mts +36 -0
- package/dist/modules/compatibility.mjs +536 -0
- package/dist/modules/compatibility.mjs.map +7 -0
- package/dist/modules/compiler/assemble.d.mts +30 -0
- package/dist/modules/compiler/assemble.mjs +923 -0
- package/dist/modules/compiler/assemble.mjs.map +7 -0
- package/dist/modules/compiler/bundle.d.mts +22 -0
- package/dist/modules/compiler/bundle.mjs +385 -0
- package/dist/modules/compiler/bundle.mjs.map +7 -0
- package/dist/modules/compiler/diagnostics.d.mts +40 -0
- package/dist/modules/compiler/diagnostics.mjs +38 -0
- package/dist/modules/compiler/diagnostics.mjs.map +7 -0
- package/dist/modules/compiler/discovery.d.mts +36 -0
- package/dist/modules/compiler/discovery.mjs +158 -0
- package/dist/modules/compiler/discovery.mjs.map +7 -0
- package/dist/modules/compiler/evaluate.d.mts +13 -0
- package/dist/modules/compiler/evaluate.mjs +194 -0
- package/dist/modules/compiler/evaluate.mjs.map +7 -0
- package/dist/modules/compiler/files.d.mts +19 -0
- package/dist/modules/compiler/files.mjs +90 -0
- package/dist/modules/compiler/files.mjs.map +7 -0
- package/dist/modules/compiler/frontmatter.d.mts +9 -0
- package/dist/modules/compiler/frontmatter.mjs +34 -0
- package/dist/modules/compiler/frontmatter.mjs.map +7 -0
- package/dist/modules/compiler/index.d.mts +49 -0
- package/dist/modules/compiler/index.mjs +244 -0
- package/dist/modules/compiler/index.mjs.map +7 -0
- package/dist/modules/compiler/load.d.mts +8 -0
- package/dist/modules/compiler/load.mjs +45 -0
- package/dist/modules/compiler/load.mjs.map +7 -0
- package/dist/modules/compiler/local-isolate.d.mts +20 -0
- package/dist/modules/compiler/local-isolate.mjs +93 -0
- package/dist/modules/compiler/local-isolate.mjs.map +7 -0
- package/dist/modules/compiler/packages.d.mts +66 -0
- package/dist/modules/compiler/packages.mjs +307 -0
- package/dist/modules/compiler/packages.mjs.map +7 -0
- package/dist/modules/index.d.mts +7 -0
- package/dist/modules/index.mjs +25 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/manifest.d.mts +2 -0
- package/dist/modules/manifest.mjs +67 -0
- package/dist/modules/manifest.mjs.map +7 -0
- package/dist/modules/resolve.d.mts +24 -0
- package/dist/modules/resolve.mjs +176 -0
- package/dist/modules/resolve.mjs.map +7 -0
- package/dist/modules/runtime/bundle.d.mts +12 -0
- package/dist/modules/runtime/bundle.mjs +48 -0
- package/dist/modules/runtime/bundle.mjs.map +7 -0
- package/dist/modules/runtime/describe.d.mts +19 -0
- package/dist/modules/runtime/describe.mjs +471 -0
- package/dist/modules/runtime/describe.mjs.map +7 -0
- package/dist/modules/runtime/described.d.mts +376 -0
- package/dist/modules/runtime/described.mjs +116 -0
- package/dist/modules/runtime/described.mjs.map +7 -0
- package/dist/modules/runtime/isolate.d.mts +70 -0
- package/dist/modules/runtime/isolate.mjs +454 -0
- package/dist/modules/runtime/isolate.mjs.map +7 -0
- package/dist/modules/runtime/layout.d.mts +21 -0
- package/dist/modules/runtime/layout.mjs +24 -0
- package/dist/modules/runtime/layout.mjs.map +7 -0
- package/dist/modules/runtime/lower.d.mts +73 -0
- package/dist/modules/runtime/lower.mjs +463 -0
- package/dist/modules/runtime/lower.mjs.map +7 -0
- package/dist/modules/runtime/schema-validation.d.mts +21 -0
- package/dist/modules/runtime/schema-validation.mjs +238 -0
- package/dist/modules/runtime/schema-validation.mjs.map +7 -0
- package/dist/modules/runtime/values.d.mts +20 -0
- package/dist/modules/runtime/values.mjs +48 -0
- package/dist/modules/runtime/values.mjs.map +7 -0
- package/fixtures/acme-fleet/agent/agent.ts +74 -0
- package/fixtures/acme-fleet/agent/instructions.md +1 -0
- package/fixtures/assistant/agent/agent.ts +16 -0
- package/fixtures/assistant/agent/instructions.md +1 -0
- package/fixtures/assistant/agent/tools/current_time.ts +9 -0
- package/fixtures/assistant-with-tools/agent/agent.ts +16 -0
- package/fixtures/assistant-with-tools/agent/instructions.md +1 -0
- package/fixtures/assistant-with-tools/agent/tools/current_time.ts +9 -0
- package/fixtures/final-connection/agent/agent.ts +15 -0
- package/fixtures/final-connection/agent/connections/final.ts +9 -0
- package/fixtures/release-scout/agent/agent.ts +22 -0
- package/fixtures/release-scout/agent/channels/github-signature.ts +27 -0
- package/fixtures/release-scout/agent/channels/github.ts +38 -0
- package/fixtures/release-scout/agent/connections/linear.ts +9 -0
- package/fixtures/release-scout/agent/hooks/audit.ts +24 -0
- package/fixtures/release-scout/agent/instructions/org-context.ts +26 -0
- package/fixtures/release-scout/agent/instructions.md +2 -0
- package/fixtures/release-scout/agent/sandbox.ts +20 -0
- package/fixtures/release-scout/agent/schedules/daily-digest.md +7 -0
- package/fixtures/release-scout/agent/skills/triage/SKILL.md +8 -0
- package/fixtures/release-scout/agent/skills/triage/checklist.md +3 -0
- package/fixtures/release-scout/agent/tools/lookup_release_notes.ts +24 -0
- package/fixtures/tsconfig.json +5 -0
- package/package.json +94 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConversationKind,
|
|
3
|
+
DynamicEvent,
|
|
4
|
+
InputApprovalKind,
|
|
5
|
+
jsonObjectSchema,
|
|
6
|
+
jsonValueSchema,
|
|
7
|
+
McpServerBindingKind,
|
|
8
|
+
mcpServerBindingSchema,
|
|
9
|
+
ParticipantKind,
|
|
10
|
+
providerRefSchema,
|
|
11
|
+
ToolApproval,
|
|
12
|
+
unopenedRequestOf
|
|
13
|
+
} from "@finalai/agent-provider";
|
|
14
|
+
import * as z from "zod";
|
|
15
|
+
import { lowerApproval } from "../authoring/approval.mjs";
|
|
16
|
+
import { AuthoredKind, authoredKindOf, stamp } from "../authoring/brand.mjs";
|
|
17
|
+
import {
|
|
18
|
+
TranscriptRole
|
|
19
|
+
} from "../authoring/context.mjs";
|
|
20
|
+
import {
|
|
21
|
+
hookHandlersFor
|
|
22
|
+
} from "../authoring/hooks.mjs";
|
|
23
|
+
import { registerToolName, toolLabelSchema } from "../authoring/tools.mjs";
|
|
24
|
+
import { AUTHORED_SERVER_KEY } from "./layout.mjs";
|
|
25
|
+
import {
|
|
26
|
+
isDynamicSentinel,
|
|
27
|
+
isEnvironmentLike,
|
|
28
|
+
isOpenRequestLike,
|
|
29
|
+
lowerConnection,
|
|
30
|
+
lowerEnvironment,
|
|
31
|
+
lowerInstructions,
|
|
32
|
+
lowerSkill,
|
|
33
|
+
lowerTool,
|
|
34
|
+
toJson
|
|
35
|
+
} from "./lower.mjs";
|
|
36
|
+
import { validateSchemaValue } from "./schema-validation.mjs";
|
|
37
|
+
import {
|
|
38
|
+
authoredRecordSchema,
|
|
39
|
+
callableSchema,
|
|
40
|
+
entriesOf,
|
|
41
|
+
fieldOf,
|
|
42
|
+
isAsyncIterable,
|
|
43
|
+
isCallable,
|
|
44
|
+
isObjectLike,
|
|
45
|
+
isPlainObject,
|
|
46
|
+
messageOf,
|
|
47
|
+
optionalValueSchema
|
|
48
|
+
} from "./values.mjs";
|
|
49
|
+
const jsonOf = (value, path) => {
|
|
50
|
+
const issues = [];
|
|
51
|
+
const json = toJson(value, { path, issues });
|
|
52
|
+
const failure = issues.find((issue) => issue.severity === "error");
|
|
53
|
+
if (failure != null) throw new Error(failure.message);
|
|
54
|
+
return json;
|
|
55
|
+
};
|
|
56
|
+
const lastSegment = (exportName) => {
|
|
57
|
+
const base = exportName.split("#")[0] ?? exportName;
|
|
58
|
+
return base.split("/").at(-1) ?? base;
|
|
59
|
+
};
|
|
60
|
+
const lowerResolvedValue = (value, key) => {
|
|
61
|
+
if (value == null) return null;
|
|
62
|
+
const kind = authoredKindOf(value);
|
|
63
|
+
if (kind === AuthoredKind.Instructions)
|
|
64
|
+
return jsonOf(lowerInstructions(value, null), "instructions");
|
|
65
|
+
if (kind === AuthoredKind.Skill) {
|
|
66
|
+
const lowered = lowerSkill({ key, value });
|
|
67
|
+
const failure = lowered.issues.find((issue) => issue.severity === "error");
|
|
68
|
+
if (failure != null) throw new Error(failure.message);
|
|
69
|
+
return jsonOf(lowered.skill, "skill");
|
|
70
|
+
}
|
|
71
|
+
if (isEnvironmentLike(value) || isOpenRequestLike(value)) {
|
|
72
|
+
const issues = [];
|
|
73
|
+
const environment = lowerEnvironment(value, "environment", issues);
|
|
74
|
+
return jsonOf(environment, "environment");
|
|
75
|
+
}
|
|
76
|
+
if (isPlainObject(value)) {
|
|
77
|
+
const entries = entriesOf(value);
|
|
78
|
+
if (entries.length > 0 && entries.every(([, item]) => authoredKindOf(item) === AuthoredKind.Skill)) {
|
|
79
|
+
return entries.map(
|
|
80
|
+
([entryKey, item]) => jsonOf(lowerSkill({ key: entryKey, value: item }).skill, "skill")
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return jsonOf(value, "resolved value");
|
|
85
|
+
};
|
|
86
|
+
const throwOnErrors = (issues) => {
|
|
87
|
+
const failure = issues.find((issue) => issue.severity === "error");
|
|
88
|
+
if (failure != null) throw new Error(failure.message);
|
|
89
|
+
};
|
|
90
|
+
const combineMcpServers = (entries) => {
|
|
91
|
+
const handler = (event) => async (payload, ctx) => {
|
|
92
|
+
const previous = z.array(mcpServerBindingSchema).safeParse(ctx.previousValue).data ?? [];
|
|
93
|
+
const tools = [];
|
|
94
|
+
const approvals = {};
|
|
95
|
+
const connections = [];
|
|
96
|
+
const addTool = (name, exportName, value, resolver) => {
|
|
97
|
+
const lowered = lowerTool({ name, exportName, value });
|
|
98
|
+
throwOnErrors(lowered.issues);
|
|
99
|
+
registerToolName(value, name);
|
|
100
|
+
if (resolver != null) {
|
|
101
|
+
const snapshot = jsonObjectSchema.parse(
|
|
102
|
+
jsonOf(
|
|
103
|
+
{
|
|
104
|
+
resolver,
|
|
105
|
+
name,
|
|
106
|
+
event,
|
|
107
|
+
payload,
|
|
108
|
+
session: ctx.session,
|
|
109
|
+
messages: ctx.messages,
|
|
110
|
+
channel: ctx.channel
|
|
111
|
+
},
|
|
112
|
+
"dynamic tool boundary"
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
lowered.descriptor.dynamic = snapshot;
|
|
116
|
+
if (lowered.descriptor.inputApproval != null)
|
|
117
|
+
lowered.descriptor.inputApproval = {
|
|
118
|
+
...lowered.descriptor.inputApproval,
|
|
119
|
+
dynamic: snapshot
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
tools.push(lowered.descriptor);
|
|
123
|
+
approvals[name] = lowered.approval;
|
|
124
|
+
};
|
|
125
|
+
const addConnection = (key, exportName, value, resolver) => {
|
|
126
|
+
const lowered = lowerConnection({ key, exportName, value });
|
|
127
|
+
throwOnErrors(lowered.issues);
|
|
128
|
+
if (resolver != null && lowered.binding.inputApprovals != null) {
|
|
129
|
+
const snapshot = jsonObjectSchema.parse(
|
|
130
|
+
jsonOf(
|
|
131
|
+
{
|
|
132
|
+
resolver,
|
|
133
|
+
name: key,
|
|
134
|
+
event,
|
|
135
|
+
payload,
|
|
136
|
+
session: ctx.session,
|
|
137
|
+
messages: ctx.messages,
|
|
138
|
+
channel: ctx.channel
|
|
139
|
+
},
|
|
140
|
+
"dynamic connection boundary"
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
lowered.binding.inputApprovals = Object.fromEntries(
|
|
144
|
+
Object.entries(lowered.binding.inputApprovals).map(([name, reference]) => [
|
|
145
|
+
name,
|
|
146
|
+
{ ...reference, dynamic: snapshot }
|
|
147
|
+
])
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
connections.push(
|
|
151
|
+
resolver == null ? lowered.binding : { ...lowered.binding, dynamicResolver: resolver }
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
const add = entry.kind === "tool" ? addTool : (name, exportName, value) => addConnection(name, exportName, value);
|
|
156
|
+
if (!isDynamicSentinel(entry.value)) {
|
|
157
|
+
add(entry.key, entry.exportName, entry.value);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const resolve = fieldOf(fieldOf(entry.value, "events"), event);
|
|
161
|
+
if (!isCallable(resolve)) {
|
|
162
|
+
for (const server of previous) {
|
|
163
|
+
if (entry.kind === "connection" && server.kind === McpServerBindingKind.Http && server.dynamicResolver === entry.exportName) {
|
|
164
|
+
connections.push(server);
|
|
165
|
+
} else if (entry.kind === "tool" && server.kind === McpServerBindingKind.Worker) {
|
|
166
|
+
for (const tool of server.tools) {
|
|
167
|
+
if (tool.dynamic?.["resolver"] !== entry.exportName) continue;
|
|
168
|
+
tools.push(tool);
|
|
169
|
+
approvals[tool.name] = Object.hasOwn(server.approvals ?? {}, tool.name) ? server.approvals?.[tool.name] ?? ToolApproval.Allow : ToolApproval.Allow;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const result = await resolve(payload, ctx);
|
|
176
|
+
if (result == null) continue;
|
|
177
|
+
const kind = authoredKindOf(result);
|
|
178
|
+
if (kind === AuthoredKind.Tool || kind === AuthoredKind.Connection) {
|
|
179
|
+
if (entry.kind === "tool") addTool(entry.key, entry.exportName, result, entry.exportName);
|
|
180
|
+
else addConnection(entry.key, entry.exportName, result, entry.exportName);
|
|
181
|
+
} else if (isPlainObject(result)) {
|
|
182
|
+
for (const [name, item] of entriesOf(result)) {
|
|
183
|
+
if (entry.kind === "tool")
|
|
184
|
+
addTool(name, `${entry.exportName}#${name}`, item, entry.exportName);
|
|
185
|
+
else addConnection(name, `${entry.exportName}#${name}`, item, entry.exportName);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const servers = [];
|
|
190
|
+
if (tools.length > 0) {
|
|
191
|
+
servers.push({
|
|
192
|
+
key: AUTHORED_SERVER_KEY,
|
|
193
|
+
kind: McpServerBindingKind.Worker,
|
|
194
|
+
tools,
|
|
195
|
+
approvals
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return jsonOf([...servers, ...connections], "mcpServers");
|
|
199
|
+
};
|
|
200
|
+
return stamp(
|
|
201
|
+
{
|
|
202
|
+
kind: "final:dynamic",
|
|
203
|
+
events: {
|
|
204
|
+
[DynamicEvent.SessionStarted]: handler(DynamicEvent.SessionStarted),
|
|
205
|
+
[DynamicEvent.TurnStarted]: handler(DynamicEvent.TurnStarted)
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
AuthoredKind.Dynamic
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
const matchRoute = (pattern, path) => {
|
|
212
|
+
const patternParts = pattern.split("/").filter((part) => part.length > 0);
|
|
213
|
+
const pathParts = path.split("/").filter((part) => part.length > 0);
|
|
214
|
+
if (patternParts.length !== pathParts.length) return false;
|
|
215
|
+
return patternParts.every((part, index) => part.startsWith(":") || part === pathParts[index]);
|
|
216
|
+
};
|
|
217
|
+
const toolModuleSchema = z.looseObject({
|
|
218
|
+
execute: callableSchema,
|
|
219
|
+
inputSchema: optionalValueSchema,
|
|
220
|
+
outputSchema: optionalValueSchema,
|
|
221
|
+
toModelOutput: callableSchema.optional(),
|
|
222
|
+
label: toolLabelSchema.nullish()
|
|
223
|
+
});
|
|
224
|
+
const sentinelSchema = z.looseObject({ events: authoredRecordSchema });
|
|
225
|
+
const channelModuleSchema = z.looseObject({
|
|
226
|
+
configure: callableSchema.optional(),
|
|
227
|
+
routes: z.array(z.looseObject({ method: z.string(), path: z.string(), handler: callableSchema }))
|
|
228
|
+
});
|
|
229
|
+
const dynamicToolBoundarySchema = z.object({
|
|
230
|
+
resolver: z.string(),
|
|
231
|
+
name: z.string(),
|
|
232
|
+
event: z.nativeEnum(DynamicEvent),
|
|
233
|
+
payload: z.object({
|
|
234
|
+
type: z.nativeEnum(DynamicEvent),
|
|
235
|
+
prompt: z.array(jsonValueSchema).nullable()
|
|
236
|
+
}),
|
|
237
|
+
session: z.object({
|
|
238
|
+
id: z.string(),
|
|
239
|
+
organizationId: z.string(),
|
|
240
|
+
definitionId: z.string(),
|
|
241
|
+
revisionId: z.string(),
|
|
242
|
+
conversation: z.object({
|
|
243
|
+
id: z.string(),
|
|
244
|
+
kind: z.nativeEnum(ConversationKind),
|
|
245
|
+
title: z.string().nullable(),
|
|
246
|
+
metadata: jsonObjectSchema,
|
|
247
|
+
participants: z.array(
|
|
248
|
+
z.object({
|
|
249
|
+
id: z.string(),
|
|
250
|
+
kind: z.nativeEnum(ParticipantKind),
|
|
251
|
+
displayName: z.string(),
|
|
252
|
+
userId: z.string().nullable()
|
|
253
|
+
})
|
|
254
|
+
)
|
|
255
|
+
}).nullable(),
|
|
256
|
+
author: z.object({
|
|
257
|
+
participantId: z.string().nullable(),
|
|
258
|
+
userId: z.string().nullable(),
|
|
259
|
+
displayName: z.string()
|
|
260
|
+
}).nullable(),
|
|
261
|
+
turn: z.object({ id: z.string() }).nullable(),
|
|
262
|
+
harness: providerRefSchema
|
|
263
|
+
}),
|
|
264
|
+
messages: z.array(
|
|
265
|
+
z.object({
|
|
266
|
+
role: z.nativeEnum(TranscriptRole),
|
|
267
|
+
content: z.array(jsonValueSchema),
|
|
268
|
+
toolCallId: z.string().nullable(),
|
|
269
|
+
seq: z.number()
|
|
270
|
+
})
|
|
271
|
+
),
|
|
272
|
+
channel: z.object({ kind: z.string().nullable() })
|
|
273
|
+
});
|
|
274
|
+
const createIsolateRuntime = (modules) => {
|
|
275
|
+
const lookup = (name) => {
|
|
276
|
+
if (!(name in modules)) throw new Error(`bundle has no export ${name}`);
|
|
277
|
+
return modules[name];
|
|
278
|
+
};
|
|
279
|
+
const resolveAuthored = async (args) => {
|
|
280
|
+
if (args.dynamic == null) return lookup(args.exportName);
|
|
281
|
+
const boundary = dynamicToolBoundarySchema.parse(args.dynamic);
|
|
282
|
+
if (args.exportName !== boundary.resolver && args.exportName !== `${boundary.resolver}#${boundary.name}`)
|
|
283
|
+
throw new Error("dynamic export does not match its boundary");
|
|
284
|
+
const sentinel = lookup(boundary.resolver);
|
|
285
|
+
if (!isDynamicSentinel(sentinel)) throw new Error("dynamic resolver is not a defineDynamic");
|
|
286
|
+
const resolve = fieldOf(fieldOf(sentinel, "events"), boundary.event);
|
|
287
|
+
if (!isCallable(resolve)) throw new Error("dynamic resolver has no boundary handler");
|
|
288
|
+
const result = await resolve(boundary.payload, {
|
|
289
|
+
session: boundary.session,
|
|
290
|
+
messages: boundary.messages,
|
|
291
|
+
channel: boundary.channel,
|
|
292
|
+
secrets: args.secrets
|
|
293
|
+
});
|
|
294
|
+
const expected = args.kind === InputApprovalKind.Tool ? AuthoredKind.Tool : AuthoredKind.Connection;
|
|
295
|
+
return authoredKindOf(result) === expected ? result : fieldOf(result, boundary.name);
|
|
296
|
+
};
|
|
297
|
+
return {
|
|
298
|
+
evaluateApproval: async ({ reference, input, secrets }) => {
|
|
299
|
+
const value = await resolveAuthored({
|
|
300
|
+
exportName: reference.export,
|
|
301
|
+
dynamic: reference.dynamic,
|
|
302
|
+
kind: reference.kind,
|
|
303
|
+
secrets
|
|
304
|
+
});
|
|
305
|
+
let policy;
|
|
306
|
+
let validated = input;
|
|
307
|
+
if (reference.kind === InputApprovalKind.Tool) {
|
|
308
|
+
const tool = toolModuleSchema.parse(value);
|
|
309
|
+
validated = await validateSchemaValue({
|
|
310
|
+
schema: tool.inputSchema,
|
|
311
|
+
value: input,
|
|
312
|
+
what: "approval input"
|
|
313
|
+
});
|
|
314
|
+
policy = fieldOf(value, "approval");
|
|
315
|
+
} else {
|
|
316
|
+
if (authoredKindOf(value) !== AuthoredKind.Connection)
|
|
317
|
+
throw new Error("approval export is not a connection");
|
|
318
|
+
policy = reference.policyKey == null ? fieldOf(value, "approval") : fieldOf(fieldOf(fieldOf(value, "tools"), "approval"), reference.policyKey);
|
|
319
|
+
}
|
|
320
|
+
const lowered = lowerApproval(policy);
|
|
321
|
+
const predicate = fieldOf(policy, "predicate");
|
|
322
|
+
if (lowered.error != null || !lowered.inputDependent || !isCallable(predicate))
|
|
323
|
+
throw new Error("approval reference has no valid input predicate");
|
|
324
|
+
return z.boolean().parse(await predicate(validated)) ? ToolApproval.Ask : ToolApproval.Allow;
|
|
325
|
+
},
|
|
326
|
+
runTool: async (args) => {
|
|
327
|
+
const value = await resolveAuthored({
|
|
328
|
+
exportName: args.export,
|
|
329
|
+
dynamic: args.dynamic,
|
|
330
|
+
kind: InputApprovalKind.Tool,
|
|
331
|
+
secrets: args.ctx.secrets
|
|
332
|
+
});
|
|
333
|
+
if (args.dynamic != null)
|
|
334
|
+
registerToolName(value, dynamicToolBoundarySchema.parse(args.dynamic).name);
|
|
335
|
+
const parsed = toolModuleSchema.safeParse(value);
|
|
336
|
+
if (!parsed.success) throw new Error(`${args.export} is not a tool`);
|
|
337
|
+
const tool = parsed.data;
|
|
338
|
+
const input = await validateSchemaValue({
|
|
339
|
+
schema: tool.inputSchema,
|
|
340
|
+
value: args.input,
|
|
341
|
+
what: "tool input"
|
|
342
|
+
});
|
|
343
|
+
const label = isObjectLike(tool.label) ? tool.label : null;
|
|
344
|
+
const statusLabel = async (callback, values) => {
|
|
345
|
+
if (callback == null) return void 0;
|
|
346
|
+
try {
|
|
347
|
+
const text = z.string().safeParse(await callback(...values));
|
|
348
|
+
return text.success ? text.data : void 0;
|
|
349
|
+
} catch {
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const started = await statusLabel(label?.start, [input]);
|
|
354
|
+
if (started != null) args.onProgress?.(null, started);
|
|
355
|
+
const result = await tool.execute(input, args.ctx);
|
|
356
|
+
let output = result;
|
|
357
|
+
if (isAsyncIterable(result)) {
|
|
358
|
+
for await (const item of result) {
|
|
359
|
+
output = item;
|
|
360
|
+
args.onProgress?.(
|
|
361
|
+
jsonOf(item, "tool progress"),
|
|
362
|
+
await statusLabel(label?.delta, [input, item])
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const validated = await validateSchemaValue({
|
|
367
|
+
schema: tool.outputSchema,
|
|
368
|
+
value: output,
|
|
369
|
+
what: "tool output"
|
|
370
|
+
});
|
|
371
|
+
const modelOutput = tool.toModelOutput == null ? null : await tool.toModelOutput(validated);
|
|
372
|
+
const completed = await statusLabel(label?.complete, [input, validated]);
|
|
373
|
+
if (completed != null) args.onProgress?.(null, completed);
|
|
374
|
+
return {
|
|
375
|
+
output: jsonOf(validated ?? null, "tool output"),
|
|
376
|
+
modelOutput: modelOutput == null ? null : jsonOf(modelOutput, "tool model output")
|
|
377
|
+
};
|
|
378
|
+
},
|
|
379
|
+
resolveDynamic: async (args) => {
|
|
380
|
+
const sentinel = lookup(args.export);
|
|
381
|
+
const parsed = sentinelSchema.safeParse(sentinel);
|
|
382
|
+
if (!isDynamicSentinel(sentinel) || !parsed.success) {
|
|
383
|
+
throw new Error(`${args.export} is not a defineDynamic resolver`);
|
|
384
|
+
}
|
|
385
|
+
const resolve = parsed.data.events[args.event];
|
|
386
|
+
if (!isCallable(resolve)) return null;
|
|
387
|
+
let result;
|
|
388
|
+
try {
|
|
389
|
+
result = await resolve(args.payload, args.ctx);
|
|
390
|
+
} catch (cause) {
|
|
391
|
+
const request = unopenedRequestOf(cause);
|
|
392
|
+
if (request == null) throw cause;
|
|
393
|
+
result = request;
|
|
394
|
+
}
|
|
395
|
+
return lowerResolvedValue(result, args.key ?? lastSegment(args.export));
|
|
396
|
+
},
|
|
397
|
+
dispatchHook: async (args) => {
|
|
398
|
+
const handlers = hookHandlersFor(lookup(args.export), args.event);
|
|
399
|
+
const failures = [];
|
|
400
|
+
for (const invoke of handlers) {
|
|
401
|
+
try {
|
|
402
|
+
await invoke(args.event, args.ctx);
|
|
403
|
+
} catch (cause) {
|
|
404
|
+
failures.push({ message: messageOf(cause) });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return { handled: handlers.length, failures };
|
|
408
|
+
},
|
|
409
|
+
handleChannelSocket: async (args) => {
|
|
410
|
+
const original = channelModuleSchema.safeParse(lookup(args.export));
|
|
411
|
+
if (!original.success) return null;
|
|
412
|
+
const parsed = original.data.configure == null ? original : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));
|
|
413
|
+
if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);
|
|
414
|
+
const route = parsed.data.routes.find(
|
|
415
|
+
(candidate) => candidate.method === "WS" && matchRoute(candidate.path, args.path)
|
|
416
|
+
);
|
|
417
|
+
if (route == null) return null;
|
|
418
|
+
const response = await route.handler({
|
|
419
|
+
request: args.request,
|
|
420
|
+
secrets: args.secrets,
|
|
421
|
+
receive: args.receive,
|
|
422
|
+
socket: args.socket
|
|
423
|
+
});
|
|
424
|
+
if (response != null && !(response instanceof Response))
|
|
425
|
+
throw new Error(`${args.export} socket route returned an invalid response`);
|
|
426
|
+
return response;
|
|
427
|
+
},
|
|
428
|
+
handleChannelRoute: async (args) => {
|
|
429
|
+
const original = channelModuleSchema.safeParse(lookup(args.export));
|
|
430
|
+
if (!original.success) return null;
|
|
431
|
+
const parsed = original.data.configure == null ? original : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));
|
|
432
|
+
if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);
|
|
433
|
+
const route = parsed.data.routes.find(
|
|
434
|
+
(candidate) => candidate.method === args.request.method && matchRoute(candidate.path, args.path)
|
|
435
|
+
);
|
|
436
|
+
if (route == null) return null;
|
|
437
|
+
const response = await route.handler({
|
|
438
|
+
request: args.request,
|
|
439
|
+
secrets: args.secrets,
|
|
440
|
+
receive: args.receive
|
|
441
|
+
});
|
|
442
|
+
if (!(response instanceof Response)) {
|
|
443
|
+
throw new Error(`${args.export} route ${args.path} did not return a Response`);
|
|
444
|
+
}
|
|
445
|
+
return response;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
export {
|
|
450
|
+
combineMcpServers,
|
|
451
|
+
createIsolateRuntime,
|
|
452
|
+
lowerResolvedValue
|
|
453
|
+
};
|
|
454
|
+
//# sourceMappingURL=isolate.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/runtime/isolate.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n ConversationKind,\n DynamicEvent,\n InputApprovalKind,\n jsonObjectSchema,\n jsonValueSchema,\n McpServerBindingKind,\n mcpServerBindingSchema,\n ParticipantKind,\n providerRefSchema,\n ToolApproval,\n unopenedRequestOf,\n type ChannelReceiveResult,\n type ChannelSocketIface,\n type InputApprovalIface,\n type JsonObject,\n type JsonValue,\n type McpServerBinding,\n type ToolDescriptorIface,\n} from '@finalai/agent-provider';\nimport * as z from 'zod';\nimport { lowerApproval } from \"../authoring/approval.mjs\";\nimport { AuthoredKind, authoredKindOf, stamp } from \"../authoring/brand.mjs\";\nimport {\n TranscriptRole,\n type DynamicResolveContextIface,\n type ToolContextIface,\n} from \"../authoring/context.mjs\";\nimport type { DynamicBoundaryEventIface } from \"../authoring/dynamic.mjs\";\nimport {\n hookHandlersFor,\n type HookContextIface,\n type HookDispatchEventIface,\n} from \"../authoring/hooks.mjs\";\nimport { registerToolName, toolLabelSchema } from \"../authoring/tools.mjs\";\nimport { AUTHORED_SERVER_KEY } from \"./layout.mjs\";\nimport {\n isDynamicSentinel,\n isEnvironmentLike,\n isOpenRequestLike,\n lowerConnection,\n lowerEnvironment,\n lowerInstructions,\n lowerSkill,\n lowerTool,\n toJson,\n type IssueIface,\n} from \"./lower.mjs\";\nimport { validateSchemaValue } from \"./schema-validation.mjs\";\nimport {\n authoredRecordSchema,\n callableSchema,\n entriesOf,\n fieldOf,\n isAsyncIterable,\n isCallable,\n isObjectLike,\n isPlainObject,\n messageOf,\n optionalValueSchema,\n type AuthoredCallable,\n type AuthoredRecord,\n type AuthoredValue,\n} from \"./values.mjs\";\n\n// What an agent bundle exposes to the Worker isolate that runs it (B4/B7):\n// the authored module map plus helpers that run its exports. The bundle is\n// the only place authored code executes.\n\nexport interface RunToolArgsIface {\n export: string;\n input: AuthoredValue;\n dynamic?: JsonValue;\n ctx: ToolContextIface;\n // Each yield of an async-generator execute, for MCP progress notifications.\n onProgress?: (value: JsonValue, label?: string) => void;\n}\n\nexport interface RunToolResultIface {\n output: JsonValue;\n // toModelOutput's projection, when the tool has one.\n modelOutput: JsonValue | null;\n}\n\nexport interface ResolveDynamicArgsIface {\n export: string;\n event: DynamicEvent;\n payload: DynamicBoundaryEventIface;\n ctx: DynamicResolveContextIface;\n // Names a single returned skill (defaults to the export's last path segment).\n key?: string;\n}\n\nexport interface DispatchHookArgsIface {\n export: string;\n event: HookDispatchEventIface;\n ctx: HookContextIface;\n}\n\nexport interface HookFailureIface {\n message: string;\n}\n\nexport interface ChannelRouteArgsIface {\n export: string;\n request: Request;\n configuration?: JsonObject;\n // The route path relative to the channel's mount point ('/webhook').\n path: string;\n secrets: { get(name: string): Promise<string | null> };\n receive: (input: JsonValue) => Promise<ChannelReceiveResult>;\n}\n\nexport interface ChannelSocketArgsIface extends ChannelRouteArgsIface {\n socket: ChannelSocketIface;\n}\n\nexport interface IsolateRuntimeIface {\n evaluateApproval(args: {\n reference: InputApprovalIface;\n input: AuthoredValue;\n secrets: { get(name: string): Promise<string | null> };\n }): Promise<ToolApproval>;\n runTool(args: RunToolArgsIface): Promise<RunToolResultIface>;\n resolveDynamic(args: ResolveDynamicArgsIface): Promise<JsonValue | null>;\n dispatchHook(\n args: DispatchHookArgsIface,\n ): Promise<{ handled: number; failures: HookFailureIface[] }>;\n // Null when no route of the channel matches the method and path.\n handleChannelRoute(args: ChannelRouteArgsIface): Promise<Response | null>;\n handleChannelSocket(args: ChannelSocketArgsIface): Promise<Response | void | null>;\n}\n\nconst jsonOf = (value: AuthoredValue, path: string): JsonValue => {\n const issues: IssueIface[] = [];\n const json = toJson(value, { path, issues });\n const failure = issues.find((issue) => issue.severity === 'error');\n if (failure != null) throw new Error(failure.message);\n return json;\n};\n\nconst lastSegment = (exportName: string): string => {\n const base = exportName.split('#')[0] ?? exportName;\n return base.split('/').at(-1) ?? base;\n};\n\n// Lowers a resolver's return value to manifest JSON by what it is.\nexport const lowerResolvedValue = (value: AuthoredValue, key: string): JsonValue | null => {\n if (value == null) return null;\n const kind = authoredKindOf(value);\n if (kind === AuthoredKind.Instructions)\n return jsonOf(lowerInstructions(value, null), 'instructions');\n if (kind === AuthoredKind.Skill) {\n const lowered = lowerSkill({ key, value });\n const failure = lowered.issues.find((issue) => issue.severity === 'error');\n if (failure != null) throw new Error(failure.message);\n return jsonOf(lowered.skill, 'skill');\n }\n if (isEnvironmentLike(value) || isOpenRequestLike(value)) {\n const issues: IssueIface[] = [];\n const environment = lowerEnvironment(value, 'environment', issues);\n return jsonOf(environment, 'environment');\n }\n if (isPlainObject(value)) {\n const entries = entriesOf(value);\n if (\n entries.length > 0 &&\n entries.every(([, item]) => authoredKindOf(item) === AuthoredKind.Skill)\n ) {\n return entries.map(([entryKey, item]) =>\n jsonOf(lowerSkill({ key: entryKey, value: item }).skill, 'skill'),\n );\n }\n }\n return jsonOf(value, 'resolved value');\n};\n\nexport interface CombinedEntryIface {\n kind: 'tool' | 'connection';\n key: string;\n exportName: string;\n value: AuthoredValue;\n}\n\nconst throwOnErrors = (issues: IssueIface[]): void => {\n const failure = issues.find((issue) => issue.severity === 'error');\n if (failure != null) throw new Error(failure.message);\n};\n\n// A resolver for the whole `mcpServers` field, used when any tool or\n// connection is dynamic: the manifest stores one slot and the session gets\n// the static and resolved entries together.\nexport const combineMcpServers = (entries: CombinedEntryIface[]): AuthoredValue => {\n const handler =\n (event: DynamicEvent) =>\n async (payload: DynamicBoundaryEventIface, ctx: DynamicResolveContextIface) => {\n const previous = z.array(mcpServerBindingSchema).safeParse(ctx.previousValue).data ?? [];\n const tools: ToolDescriptorIface[] = [];\n const approvals: Record<string, ToolApproval> = {};\n const connections: McpServerBinding[] = [];\n const addTool = (\n name: string,\n exportName: string,\n value: AuthoredValue,\n resolver?: string,\n ): void => {\n const lowered = lowerTool({ name, exportName, value });\n throwOnErrors(lowered.issues);\n registerToolName(value, name);\n if (resolver != null) {\n const snapshot = jsonObjectSchema.parse(\n jsonOf(\n {\n resolver,\n name,\n event,\n payload,\n session: ctx.session,\n messages: ctx.messages,\n channel: ctx.channel,\n },\n 'dynamic tool boundary',\n ),\n );\n lowered.descriptor.dynamic = snapshot;\n if (lowered.descriptor.inputApproval != null)\n lowered.descriptor.inputApproval = {\n ...lowered.descriptor.inputApproval,\n dynamic: snapshot,\n };\n }\n tools.push(lowered.descriptor);\n approvals[name] = lowered.approval;\n };\n const addConnection = (\n key: string,\n exportName: string,\n value: AuthoredValue,\n resolver?: string,\n ): void => {\n const lowered = lowerConnection({ key, exportName, value });\n throwOnErrors(lowered.issues);\n if (resolver != null && lowered.binding.inputApprovals != null) {\n const snapshot = jsonObjectSchema.parse(\n jsonOf(\n {\n resolver,\n name: key,\n event,\n payload,\n session: ctx.session,\n messages: ctx.messages,\n channel: ctx.channel,\n },\n 'dynamic connection boundary',\n ),\n );\n lowered.binding.inputApprovals = Object.fromEntries(\n Object.entries(lowered.binding.inputApprovals).map(([name, reference]) => [\n name,\n { ...reference, dynamic: snapshot },\n ]),\n );\n }\n connections.push(\n resolver == null ? lowered.binding : { ...lowered.binding, dynamicResolver: resolver },\n );\n };\n for (const entry of entries) {\n const add =\n entry.kind === 'tool'\n ? addTool\n : (name: string, exportName: string, value: AuthoredValue) =>\n addConnection(name, exportName, value);\n if (!isDynamicSentinel(entry.value)) {\n add(entry.key, entry.exportName, entry.value);\n continue;\n }\n const resolve = fieldOf(fieldOf(entry.value, 'events'), event);\n if (!isCallable(resolve)) {\n for (const server of previous) {\n if (\n entry.kind === 'connection' &&\n server.kind === McpServerBindingKind.Http &&\n server.dynamicResolver === entry.exportName\n ) {\n connections.push(server);\n } else if (entry.kind === 'tool' && server.kind === McpServerBindingKind.Worker) {\n for (const tool of server.tools) {\n if (tool.dynamic?.['resolver'] !== entry.exportName) continue;\n tools.push(tool);\n approvals[tool.name] = Object.hasOwn(server.approvals ?? {}, tool.name)\n ? (server.approvals?.[tool.name] ?? ToolApproval.Allow)\n : ToolApproval.Allow;\n }\n }\n }\n continue;\n }\n const result = await resolve(payload, ctx);\n if (result == null) continue;\n const kind = authoredKindOf(result);\n if (kind === AuthoredKind.Tool || kind === AuthoredKind.Connection) {\n if (entry.kind === 'tool') addTool(entry.key, entry.exportName, result, entry.exportName);\n else addConnection(entry.key, entry.exportName, result, entry.exportName);\n } else if (isPlainObject(result)) {\n for (const [name, item] of entriesOf(result)) {\n if (entry.kind === 'tool')\n addTool(name, `${entry.exportName}#${name}`, item, entry.exportName);\n else addConnection(name, `${entry.exportName}#${name}`, item, entry.exportName);\n }\n }\n }\n const servers: McpServerBinding[] = [];\n if (tools.length > 0) {\n servers.push({\n key: AUTHORED_SERVER_KEY,\n kind: McpServerBindingKind.Worker,\n tools,\n approvals,\n });\n }\n return jsonOf([...servers, ...connections], 'mcpServers');\n };\n return stamp(\n {\n kind: 'final:dynamic' as const,\n events: {\n [DynamicEvent.SessionStarted]: handler(DynamicEvent.SessionStarted),\n [DynamicEvent.TurnStarted]: handler(DynamicEvent.TurnStarted),\n },\n },\n AuthoredKind.Dynamic,\n );\n};\n\nconst matchRoute = (pattern: string, path: string): boolean => {\n const patternParts = pattern.split('/').filter((part) => part.length > 0);\n const pathParts = path.split('/').filter((part) => part.length > 0);\n if (patternParts.length !== pathParts.length) return false;\n return patternParts.every((part, index) => part.startsWith(':') || part === pathParts[index]);\n};\n\nconst toolModuleSchema = z.looseObject({\n execute: callableSchema,\n inputSchema: optionalValueSchema,\n outputSchema: optionalValueSchema,\n toModelOutput: callableSchema.optional(),\n label: toolLabelSchema.nullish(),\n});\n\nconst sentinelSchema = z.looseObject({ events: authoredRecordSchema });\n\nconst channelModuleSchema = z.looseObject({\n configure: callableSchema.optional(),\n routes: z.array(z.looseObject({ method: z.string(), path: z.string(), handler: callableSchema })),\n});\n\nconst dynamicToolBoundarySchema = z.object({\n resolver: z.string(),\n name: z.string(),\n event: z.nativeEnum(DynamicEvent),\n payload: z.object({\n type: z.nativeEnum(DynamicEvent),\n prompt: z.array(jsonValueSchema).nullable(),\n }),\n session: z.object({\n id: z.string(),\n organizationId: z.string(),\n definitionId: z.string(),\n revisionId: z.string(),\n conversation: z\n .object({\n id: z.string(),\n kind: z.nativeEnum(ConversationKind),\n title: z.string().nullable(),\n metadata: jsonObjectSchema,\n participants: z.array(\n z.object({\n id: z.string(),\n kind: z.nativeEnum(ParticipantKind),\n displayName: z.string(),\n userId: z.string().nullable(),\n }),\n ),\n })\n .nullable(),\n author: z\n .object({\n participantId: z.string().nullable(),\n userId: z.string().nullable(),\n displayName: z.string(),\n })\n .nullable(),\n turn: z.object({ id: z.string() }).nullable(),\n harness: providerRefSchema,\n }),\n messages: z.array(\n z.object({\n role: z.nativeEnum(TranscriptRole),\n content: z.array(jsonValueSchema),\n toolCallId: z.string().nullable(),\n seq: z.number(),\n }),\n ),\n channel: z.object({ kind: z.string().nullable() }),\n});\n\nexport const createIsolateRuntime = (modules: AuthoredRecord): IsolateRuntimeIface => {\n const lookup = (name: string): AuthoredValue => {\n if (!(name in modules)) throw new Error(`bundle has no export ${name}`);\n return modules[name];\n };\n const resolveAuthored = async (args: {\n exportName: string;\n dynamic?: JsonValue;\n kind: InputApprovalKind;\n secrets: { get(name: string): Promise<string | null> };\n }): Promise<AuthoredValue> => {\n if (args.dynamic == null) return lookup(args.exportName);\n const boundary = dynamicToolBoundarySchema.parse(args.dynamic);\n if (\n args.exportName !== boundary.resolver &&\n args.exportName !== `${boundary.resolver}#${boundary.name}`\n )\n throw new Error('dynamic export does not match its boundary');\n const sentinel = lookup(boundary.resolver);\n if (!isDynamicSentinel(sentinel)) throw new Error('dynamic resolver is not a defineDynamic');\n const resolve = fieldOf(fieldOf(sentinel, 'events'), boundary.event);\n if (!isCallable(resolve)) throw new Error('dynamic resolver has no boundary handler');\n const result = await resolve(boundary.payload, {\n session: boundary.session,\n messages: boundary.messages,\n channel: boundary.channel,\n secrets: args.secrets,\n });\n const expected =\n args.kind === InputApprovalKind.Tool ? AuthoredKind.Tool : AuthoredKind.Connection;\n return authoredKindOf(result) === expected ? result : fieldOf(result, boundary.name);\n };\n return {\n evaluateApproval: async ({ reference, input, secrets }) => {\n const value = await resolveAuthored({\n exportName: reference.export,\n dynamic: reference.dynamic,\n kind: reference.kind,\n secrets,\n });\n let policy: AuthoredValue;\n let validated: AuthoredValue = input;\n if (reference.kind === InputApprovalKind.Tool) {\n const tool = toolModuleSchema.parse(value);\n validated = await validateSchemaValue({\n schema: tool.inputSchema,\n value: input,\n what: 'approval input',\n });\n policy = fieldOf(value, 'approval');\n } else {\n if (authoredKindOf(value) !== AuthoredKind.Connection)\n throw new Error('approval export is not a connection');\n policy =\n reference.policyKey == null\n ? fieldOf(value, 'approval')\n : fieldOf(fieldOf(fieldOf(value, 'tools'), 'approval'), reference.policyKey);\n }\n const lowered = lowerApproval(policy);\n const predicate = fieldOf(policy, 'predicate');\n if (lowered.error != null || !lowered.inputDependent || !isCallable(predicate))\n throw new Error('approval reference has no valid input predicate');\n return z.boolean().parse(await predicate(validated)) ? ToolApproval.Ask : ToolApproval.Allow;\n },\n runTool: async (args) => {\n const value = await resolveAuthored({\n exportName: args.export,\n dynamic: args.dynamic,\n kind: InputApprovalKind.Tool,\n secrets: args.ctx.secrets,\n });\n if (args.dynamic != null)\n registerToolName(value, dynamicToolBoundarySchema.parse(args.dynamic).name);\n const parsed = toolModuleSchema.safeParse(value);\n if (!parsed.success) throw new Error(`${args.export} is not a tool`);\n const tool = parsed.data;\n const input = await validateSchemaValue({\n schema: tool.inputSchema,\n value: args.input,\n what: 'tool input',\n });\n const label = isObjectLike(tool.label) ? tool.label : null;\n const statusLabel = async (\n callback: AuthoredCallable | undefined,\n values: AuthoredValue[],\n ): Promise<string | undefined> => {\n if (callback == null) return undefined;\n try {\n const text = z.string().safeParse(await callback(...values));\n return text.success ? text.data : undefined;\n } catch {\n // Display labels must not turn a completed side effect into a tool failure.\n return undefined;\n }\n };\n const started = await statusLabel(label?.start, [input]);\n if (started != null) args.onProgress?.(null, started);\n const result = await tool.execute(input, args.ctx);\n let output: AuthoredValue = result;\n if (isAsyncIterable(result)) {\n for await (const item of result) {\n output = item;\n args.onProgress?.(\n jsonOf(item, 'tool progress'),\n await statusLabel(label?.delta, [input, item]),\n );\n }\n }\n const validated = await validateSchemaValue({\n schema: tool.outputSchema,\n value: output,\n what: 'tool output',\n });\n const modelOutput = tool.toModelOutput == null ? null : await tool.toModelOutput(validated);\n const completed = await statusLabel(label?.complete, [input, validated]);\n if (completed != null) args.onProgress?.(null, completed);\n return {\n output: jsonOf(validated ?? null, 'tool output'),\n modelOutput: modelOutput == null ? null : jsonOf(modelOutput, 'tool model output'),\n };\n },\n resolveDynamic: async (args) => {\n const sentinel = lookup(args.export);\n const parsed = sentinelSchema.safeParse(sentinel);\n if (!isDynamicSentinel(sentinel) || !parsed.success) {\n throw new Error(`${args.export} is not a defineDynamic resolver`);\n }\n const resolve = parsed.data.events[args.event];\n if (!isCallable(resolve)) return null;\n let result: AuthoredValue;\n try {\n result = await resolve(args.payload, args.ctx);\n } catch (cause) {\n // Dynamic handlers describe configurations; live setup belongs in defineSandbox.\n // `async () => environment.open(...)` is lowered as a request.\n const request = unopenedRequestOf(cause);\n if (request == null) throw cause;\n result = request;\n }\n return lowerResolvedValue(result, args.key ?? lastSegment(args.export));\n },\n dispatchHook: async (args) => {\n const handlers = hookHandlersFor(lookup(args.export), args.event);\n const failures: HookFailureIface[] = [];\n for (const invoke of handlers) {\n try {\n await invoke(args.event, args.ctx);\n } catch (cause) {\n failures.push({ message: messageOf(cause) });\n }\n }\n return { handled: handlers.length, failures };\n },\n handleChannelSocket: async (args) => {\n const original = channelModuleSchema.safeParse(lookup(args.export));\n if (!original.success) return null;\n const parsed =\n original.data.configure == null\n ? original\n : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));\n if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);\n const route = parsed.data.routes.find(\n (candidate) => candidate.method === 'WS' && matchRoute(candidate.path, args.path),\n );\n if (route == null) return null;\n const response = await route.handler({\n request: args.request,\n secrets: args.secrets,\n receive: args.receive,\n socket: args.socket,\n });\n if (response != null && !(response instanceof Response))\n throw new Error(`${args.export} socket route returned an invalid response`);\n return response;\n },\n handleChannelRoute: async (args) => {\n const original = channelModuleSchema.safeParse(lookup(args.export));\n if (!original.success) return null;\n const parsed =\n original.data.configure == null\n ? original\n : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));\n if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);\n const route = parsed.data.routes.find(\n (candidate) =>\n candidate.method === args.request.method && matchRoute(candidate.path, args.path),\n );\n if (route == null) return null;\n const response = await route.handler({\n request: args.request,\n secrets: args.secrets,\n receive: args.receive,\n });\n if (!(response instanceof Response)) {\n throw new Error(`${args.export} route ${args.path} did not return a Response`);\n }\n return response;\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP,YAAY,OAAO;AACnB,SAAS,qBAAqB;AAC9B,SAAS,cAAc,gBAAgB,aAAa;AACpD;AAAA,EACE;AAAA,OAGK;AAEP;AAAA,EACE;AAAA,OAGK;AACP,SAAS,kBAAkB,uBAAuB;AAClD,SAAS,2BAA2B;AACpC;A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AC1B,YAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,QACnC,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,QACd,QAAQ,KAAK;AAAA,MACf,CAAC;AACD,UAAI,YAAY,QAAQ,EAAE,oBAAoB;AAC5C,cAAM,IAAI,MAAM,GAAG,KAAK,MAAM,4CAA4C;AAC5E,aAAO;AAAA,IACT;AAAA,IACA,oBAAoB,OAAO,SAAS;AAClC,YAAM,WAAW,oBAAoB,UAAU,OAAO,KAAK,MAAM,CAAC;AAClE,UAAI,CAAC,SAAS,QAAS,QAAO;AAC9B,YAAM,SACJ,SAAS,KAAK,aAAa,OACvB,WACA,oBAAoB,UAAU,MAAM,SAAS,KAAK,UAAU,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAC3F,UAAI,CAAC,OAAO,QAAS,OAAM,IAAI,MAAM,GAAG,KAAK,MAAM,gCAAgC;AACnF,YAAM,QAAQ,OAAO,KAAK,OAAO;AAAA,QAC/B,CAAC,cACC,UAAU,WAAW,KAAK,QAAQ,UAAU,WAAW,UAAU,MAAM,KAAK,IAAI;AAAA,MACpF;AACA,UAAI,SAAS,KAAM,QAAO;AAC1B,YAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,QACnC,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,MAChB,CAAC;AACD,UAAI,EAAE,oBAAoB,WAAW;AACnC,cAAM,IAAI,MAAM,GAAG,KAAK,MAAM,UAAU,KAAK,IAAI,4BAA4B;AAAA,MAC/E;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum SlotKind {
|
|
2
|
+
Agent = "agent",
|
|
3
|
+
Instructions = "instructions",
|
|
4
|
+
Skill = "skill",
|
|
5
|
+
Tool = "tool",
|
|
6
|
+
Connection = "connection",
|
|
7
|
+
Schedule = "schedule",
|
|
8
|
+
Hook = "hook",
|
|
9
|
+
Channel = "channel",
|
|
10
|
+
Sandbox = "sandbox"
|
|
11
|
+
}
|
|
12
|
+
export interface LayoutModuleIface {
|
|
13
|
+
base: string;
|
|
14
|
+
path: string;
|
|
15
|
+
slot: SlotKind;
|
|
16
|
+
key: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const AGENT_DYNAMIC_PREFIX = "agent:";
|
|
19
|
+
export declare const COMBINED_MCP_SERVERS_EXPORT = "final:mcpServers";
|
|
20
|
+
export declare const AUTHORED_SERVER_KEY = "authored";
|
|
21
|
+
export declare const namedExportName: (base: string, name: string) => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var SlotKind = /* @__PURE__ */ ((SlotKind2) => {
|
|
2
|
+
SlotKind2["Agent"] = "agent";
|
|
3
|
+
SlotKind2["Instructions"] = "instructions";
|
|
4
|
+
SlotKind2["Skill"] = "skill";
|
|
5
|
+
SlotKind2["Tool"] = "tool";
|
|
6
|
+
SlotKind2["Connection"] = "connection";
|
|
7
|
+
SlotKind2["Schedule"] = "schedule";
|
|
8
|
+
SlotKind2["Hook"] = "hook";
|
|
9
|
+
SlotKind2["Channel"] = "channel";
|
|
10
|
+
SlotKind2["Sandbox"] = "sandbox";
|
|
11
|
+
return SlotKind2;
|
|
12
|
+
})(SlotKind || {});
|
|
13
|
+
const AGENT_DYNAMIC_PREFIX = "agent:";
|
|
14
|
+
const COMBINED_MCP_SERVERS_EXPORT = "final:mcpServers";
|
|
15
|
+
const AUTHORED_SERVER_KEY = "authored";
|
|
16
|
+
const namedExportName = (base, name) => name === "default" ? base : `${base}#${name}`;
|
|
17
|
+
export {
|
|
18
|
+
AGENT_DYNAMIC_PREFIX,
|
|
19
|
+
AUTHORED_SERVER_KEY,
|
|
20
|
+
COMBINED_MCP_SERVERS_EXPORT,
|
|
21
|
+
SlotKind,
|
|
22
|
+
namedExportName
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=layout.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/runtime/layout.ts"],
|
|
4
|
+
"sourcesContent": ["// The module layout the compiler hands to the bundle entry: every authored\n// module it discovered, in bundle order, with its slot and key.\n\nexport enum SlotKind {\n Agent = 'agent',\n Instructions = 'instructions',\n Skill = 'skill',\n Tool = 'tool',\n Connection = 'connection',\n Schedule = 'schedule',\n Hook = 'hook',\n Channel = 'channel',\n Sandbox = 'sandbox',\n}\n\nexport interface LayoutModuleIface {\n // Bundle export base: the path without extension ('tools/lookup_release_notes').\n base: string;\n path: string;\n slot: SlotKind;\n // Name in its slot: tool name, connection key, skill key, hook slug, ...\n key: string;\n}\n\nexport const AGENT_DYNAMIC_PREFIX = 'agent:';\nexport const COMBINED_MCP_SERVERS_EXPORT = 'final:mcpServers';\nexport const AUTHORED_SERVER_KEY = 'authored';\n\nexport const namedExportName = (base: string, name: string): string =>\n name === 'default' ? base : `${base}#${name}`;\n"],
|
|
5
|
+
"mappings": "AAGO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,kBAAe;AACf,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,gBAAa;AACb,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,aAAU;AACV,EAAAA,UAAA,aAAU;AATA,SAAAA;AAAA,GAAA;AAqBL,MAAM,uBAAuB;AAC7B,MAAM,8BAA8B;AACpC,MAAM,sBAAsB;AAE5B,MAAM,kBAAkB,CAAC,MAAc,SAC5C,SAAS,YAAY,OAAO,GAAG,IAAI,IAAI,IAAI;",
|
|
6
|
+
"names": ["SlotKind"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ToolApproval, type HttpMcpServerBindingIface, type InstructionFragmentIface, type JsonObject, type JsonValue, type SkillBundleIface, type ToolDescriptorIface } from '@finalai/agent-provider';
|
|
2
|
+
import { SchemaIo } from "./schema-validation.mjs";
|
|
3
|
+
import { type AuthoredValue } from "./values.mjs";
|
|
4
|
+
export declare enum IssueSeverity {
|
|
5
|
+
Error = "error",
|
|
6
|
+
Warning = "warning",
|
|
7
|
+
Note = "note"
|
|
8
|
+
}
|
|
9
|
+
export interface IssueIface {
|
|
10
|
+
severity: IssueSeverity;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const error: (message: string) => IssueIface;
|
|
14
|
+
export declare const warning: (message: string) => IssueIface;
|
|
15
|
+
export declare const note: (message: string) => IssueIface;
|
|
16
|
+
export declare const childPath: (parent: string, key: string | number) => string;
|
|
17
|
+
export interface ToJsonOptionsIface {
|
|
18
|
+
path: string;
|
|
19
|
+
issues: IssueIface[];
|
|
20
|
+
visit?: (value: AuthoredValue, path: string) => JsonValue | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare const toJson: (value: AuthoredValue, options: ToJsonOptionsIface) => JsonValue;
|
|
23
|
+
export declare const toJsonSchema: (args: {
|
|
24
|
+
schema: AuthoredValue;
|
|
25
|
+
path: string;
|
|
26
|
+
issues: IssueIface[];
|
|
27
|
+
io?: SchemaIo;
|
|
28
|
+
}) => JsonObject | null;
|
|
29
|
+
export interface LoweredToolIface {
|
|
30
|
+
descriptor: ToolDescriptorIface;
|
|
31
|
+
approval: ToolApproval;
|
|
32
|
+
issues: IssueIface[];
|
|
33
|
+
}
|
|
34
|
+
export declare const lowerTool: (args: {
|
|
35
|
+
name: string;
|
|
36
|
+
exportName: string;
|
|
37
|
+
value: AuthoredValue;
|
|
38
|
+
}) => LoweredToolIface;
|
|
39
|
+
export interface LoweredConnectionIface {
|
|
40
|
+
binding: HttpMcpServerBindingIface;
|
|
41
|
+
issues: IssueIface[];
|
|
42
|
+
}
|
|
43
|
+
export declare const lowerConnection: (args: {
|
|
44
|
+
key: string;
|
|
45
|
+
exportName: string;
|
|
46
|
+
value: AuthoredValue;
|
|
47
|
+
}) => LoweredConnectionIface;
|
|
48
|
+
export declare const skillMarkdown: (args: {
|
|
49
|
+
key: string;
|
|
50
|
+
description: string;
|
|
51
|
+
markdown: string;
|
|
52
|
+
}) => string;
|
|
53
|
+
export interface LoweredSkillIface {
|
|
54
|
+
skill: SkillBundleIface;
|
|
55
|
+
issues: IssueIface[];
|
|
56
|
+
}
|
|
57
|
+
export declare const lowerSkill: (args: {
|
|
58
|
+
key: string;
|
|
59
|
+
value: AuthoredValue;
|
|
60
|
+
}) => LoweredSkillIface;
|
|
61
|
+
export declare const lowerInstructions: (value: AuthoredValue, source: string | null) => InstructionFragmentIface | null;
|
|
62
|
+
export interface LoweredEnvironmentIface {
|
|
63
|
+
providerName: string;
|
|
64
|
+
providerRef: JsonValue | null;
|
|
65
|
+
options: JsonValue;
|
|
66
|
+
openOptions: JsonValue | null;
|
|
67
|
+
}
|
|
68
|
+
export declare const isEnvironmentLike: (value: AuthoredValue) => boolean;
|
|
69
|
+
export declare const isOpenRequestLike: (value: AuthoredValue) => boolean;
|
|
70
|
+
export declare const sandboxProviderNameOf: (value: AuthoredValue) => string | null;
|
|
71
|
+
export declare const lowerEnvironment: (value: AuthoredValue, path: string, issues: IssueIface[]) => LoweredEnvironmentIface | null;
|
|
72
|
+
export declare const isDynamicSentinel: (value: AuthoredValue) => boolean;
|
|
73
|
+
export declare const dynamicEventsOf: (value: AuthoredValue) => string[];
|