@finalai/agents 0.8.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/agents might be problematic. Click here for more details.
- package/README.md +30 -0
- package/dist/modules/agent-client/acp-frames.d.mts +19 -0
- package/dist/modules/agent-client/acp-frames.mjs +49 -0
- package/dist/modules/agent-client/acp-frames.mjs.map +7 -0
- package/dist/modules/agent-client/acp.d.mts +43 -0
- package/dist/modules/agent-client/acp.mjs +76 -0
- package/dist/modules/agent-client/acp.mjs.map +7 -0
- package/dist/modules/agent-client/async-queue.d.mts +10 -0
- package/dist/modules/agent-client/async-queue.mjs +66 -0
- package/dist/modules/agent-client/async-queue.mjs.map +7 -0
- package/dist/modules/agent-client/build.d.mts +107 -0
- package/dist/modules/agent-client/build.mjs +222 -0
- package/dist/modules/agent-client/build.mjs.map +7 -0
- package/dist/modules/agent-client/client.d.mts +111 -0
- package/dist/modules/agent-client/client.mjs +198 -0
- package/dist/modules/agent-client/client.mjs.map +7 -0
- package/dist/modules/agent-client/collection-events.d.mts +35 -0
- package/dist/modules/agent-client/collection-events.mjs +142 -0
- package/dist/modules/agent-client/collection-events.mjs.map +7 -0
- package/dist/modules/agent-client/config-options.d.mts +24 -0
- package/dist/modules/agent-client/config-options.mjs +49 -0
- package/dist/modules/agent-client/config-options.mjs.map +7 -0
- package/dist/modules/agent-client/context.d.mts +31 -0
- package/dist/modules/agent-client/context.mjs +11 -0
- package/dist/modules/agent-client/context.mjs.map +7 -0
- package/dist/modules/agent-client/conversations.d.mts +385 -0
- package/dist/modules/agent-client/conversations.mjs +1156 -0
- package/dist/modules/agent-client/conversations.mjs.map +7 -0
- package/dist/modules/agent-client/errors.d.mts +85 -0
- package/dist/modules/agent-client/errors.mjs +94 -0
- package/dist/modules/agent-client/errors.mjs.map +7 -0
- package/dist/modules/agent-client/event-stream.d.mts +14 -0
- package/dist/modules/agent-client/event-stream.mjs +89 -0
- package/dist/modules/agent-client/event-stream.mjs.map +7 -0
- package/dist/modules/agent-client/frame-stream.d.mts +51 -0
- package/dist/modules/agent-client/frame-stream.mjs +333 -0
- package/dist/modules/agent-client/frame-stream.mjs.map +7 -0
- package/dist/modules/agent-client/http.d.mts +68 -0
- package/dist/modules/agent-client/http.mjs +168 -0
- package/dist/modules/agent-client/http.mjs.map +7 -0
- package/dist/modules/agent-client/index.d.mts +17 -0
- package/dist/modules/agent-client/index.mjs +86 -0
- package/dist/modules/agent-client/index.mjs.map +7 -0
- package/dist/modules/agent-client/live-stream.d.mts +18 -0
- package/dist/modules/agent-client/live-stream.mjs +94 -0
- package/dist/modules/agent-client/live-stream.mjs.map +7 -0
- package/dist/modules/agent-client/realtime.d.mts +72 -0
- package/dist/modules/agent-client/realtime.mjs +186 -0
- package/dist/modules/agent-client/realtime.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-uri.d.mts +19 -0
- package/dist/modules/agent-client/sandbox-uri.mjs +43 -0
- package/dist/modules/agent-client/sandbox-uri.mjs.map +7 -0
- package/dist/modules/agent-client/sessions.d.mts +124 -0
- package/dist/modules/agent-client/sessions.mjs +350 -0
- package/dist/modules/agent-client/sessions.mjs.map +7 -0
- package/dist/modules/agent-client/test-fakes.d.mts +40 -0
- package/dist/modules/agent-client/test-fakes.mjs +94 -0
- package/dist/modules/agent-client/test-fakes.mjs.map +7 -0
- package/dist/modules/authoring/approval.d.mts +1 -0
- package/dist/modules/authoring/approval.mjs +2 -0
- package/dist/modules/authoring/approval.mjs.map +7 -0
- package/dist/modules/authoring/channels.d.mts +1 -0
- package/dist/modules/authoring/channels.mjs +2 -0
- package/dist/modules/authoring/channels.mjs.map +7 -0
- package/dist/modules/authoring/final-channel.d.mts +1 -0
- package/dist/modules/authoring/final-channel.mjs +2 -0
- package/dist/modules/authoring/final-channel.mjs.map +7 -0
- package/dist/modules/authoring/hooks.d.mts +1 -0
- package/dist/modules/authoring/hooks.mjs +2 -0
- package/dist/modules/authoring/hooks.mjs.map +7 -0
- package/dist/modules/authoring/index.d.mts +1 -0
- package/dist/modules/authoring/index.mjs +2 -0
- package/dist/modules/authoring/index.mjs.map +7 -0
- package/dist/modules/authoring/instructions.d.mts +1 -0
- package/dist/modules/authoring/instructions.mjs +2 -0
- package/dist/modules/authoring/instructions.mjs.map +7 -0
- package/dist/modules/authoring/providers.d.mts +2 -0
- package/dist/modules/authoring/providers.mjs +1 -0
- package/dist/modules/authoring/providers.mjs.map +7 -0
- package/dist/modules/authoring/tools.d.mts +1 -0
- package/dist/modules/authoring/tools.mjs +2 -0
- package/dist/modules/authoring/tools.mjs.map +7 -0
- package/dist/modules/cli/build.d.mts +22 -0
- package/dist/modules/cli/build.mjs +77 -0
- package/dist/modules/cli/build.mjs.map +7 -0
- package/dist/modules/cli/channel-socket.d.mts +9 -0
- package/dist/modules/cli/channel-socket.mjs +114 -0
- package/dist/modules/cli/channel-socket.mjs.map +7 -0
- package/dist/modules/cli/cli.d.mts +16 -0
- package/dist/modules/cli/cli.mjs +151 -0
- package/dist/modules/cli/cli.mjs.map +7 -0
- package/dist/modules/cli/conformance.d.mts +36 -0
- package/dist/modules/cli/conformance.mjs +220 -0
- package/dist/modules/cli/conformance.mjs.map +7 -0
- package/dist/modules/cli/dev.d.mts +24 -0
- package/dist/modules/cli/dev.mjs +263 -0
- package/dist/modules/cli/dev.mjs.map +7 -0
- package/dist/modules/cli/files.d.mts +18 -0
- package/dist/modules/cli/files.mjs +66 -0
- package/dist/modules/cli/files.mjs.map +7 -0
- package/dist/modules/cli/harness-descriptions.d.mts +20 -0
- package/dist/modules/cli/harness-descriptions.mjs +70 -0
- package/dist/modules/cli/harness-descriptions.mjs.map +7 -0
- package/dist/modules/cli/main.d.mts +2 -0
- package/dist/modules/cli/main.mjs +20 -0
- package/dist/modules/cli/main.mjs.map +7 -0
- package/dist/modules/cli/output.d.mts +14 -0
- package/dist/modules/cli/output.mjs +94 -0
- package/dist/modules/cli/output.mjs.map +7 -0
- package/dist/modules/cli/publish.d.mts +14 -0
- package/dist/modules/cli/publish.mjs +89 -0
- package/dist/modules/cli/publish.mjs.map +7 -0
- package/dist/modules/compile.d.mts +3 -0
- package/dist/modules/compile.mjs +62 -0
- package/dist/modules/compile.mjs.map +7 -0
- package/dist/modules/harnesses.d.mts +1 -0
- package/dist/modules/harnesses.mjs +2 -0
- package/dist/modules/harnesses.mjs.map +7 -0
- package/dist/modules/index.browser.d.mts +4 -0
- package/dist/modules/index.browser.mjs +8 -0
- package/dist/modules/index.browser.mjs.map +7 -0
- package/dist/modules/index.d.mts +3 -0
- package/dist/modules/index.mjs +6 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/models.d.mts +1 -0
- package/dist/modules/models.mjs +2 -0
- package/dist/modules/models.mjs.map +7 -0
- package/dist/modules/public.d.mts +6 -0
- package/dist/modules/public.mjs +68 -0
- package/dist/modules/public.mjs.map +7 -0
- package/dist/modules/sandboxes.d.mts +1 -0
- package/dist/modules/sandboxes.mjs +2 -0
- package/dist/modules/sandboxes.mjs.map +7 -0
- package/examples/custom-harness/README.md +16 -0
- package/examples/custom-harness/agent.ts +154 -0
- package/examples/custom-sandbox/README.md +12 -0
- package/examples/custom-sandbox/agent.ts +14 -0
- package/examples/custom-sandbox/sandbox.ts +22 -0
- package/examples/release-scout/README.md +11 -0
- package/examples/release-scout/agent/agent.ts +22 -0
- package/examples/release-scout/agent/channels/github-signature.ts +27 -0
- package/examples/release-scout/agent/channels/github.ts +38 -0
- package/examples/release-scout/agent/connections/linear.ts +9 -0
- package/examples/release-scout/agent/hooks/audit.ts +24 -0
- package/examples/release-scout/agent/instructions/org-context.ts +26 -0
- package/examples/release-scout/agent/instructions.md +2 -0
- package/examples/release-scout/agent/sandbox.ts +20 -0
- package/examples/release-scout/agent/schedules/daily-digest.md +7 -0
- package/examples/release-scout/agent/skills/triage/SKILL.md +8 -0
- package/examples/release-scout/agent/skills/triage/checklist.md +3 -0
- package/examples/release-scout/agent/tools/lookup_release_notes.ts +24 -0
- package/examples/release-scout/client.ts +123 -0
- package/package.json +126 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
const headerRecordSchema = z.record(z.string(), z.string());
|
|
3
|
+
const createFakeFetch = (routes) => {
|
|
4
|
+
const requests = [];
|
|
5
|
+
const fetch = async (input, init) => {
|
|
6
|
+
const url = new URL(input);
|
|
7
|
+
const bodyText = z.string().safeParse(init.body);
|
|
8
|
+
const request = {
|
|
9
|
+
method: init.method ?? "GET",
|
|
10
|
+
path: url.pathname,
|
|
11
|
+
query: url.searchParams,
|
|
12
|
+
headers: headerRecordSchema.safeParse(init.headers).data ?? {},
|
|
13
|
+
credentials: init.credentials,
|
|
14
|
+
body: bodyText.success ? z.json().parse(JSON.parse(bodyText.data)) : null
|
|
15
|
+
};
|
|
16
|
+
requests.push(request);
|
|
17
|
+
const route = routes[`${request.method} ${request.path}`];
|
|
18
|
+
if (route == null) {
|
|
19
|
+
return new Response(JSON.stringify({ error: { code: "not_found", message: "no route" } }), {
|
|
20
|
+
status: 404
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const response = route(request);
|
|
24
|
+
const status = response.status ?? 200;
|
|
25
|
+
const body = status === 204 ? null : response.text ?? JSON.stringify(response.json ?? {});
|
|
26
|
+
return new Response(body, { status });
|
|
27
|
+
};
|
|
28
|
+
return { fetch, requests };
|
|
29
|
+
};
|
|
30
|
+
const createFakeTransport = () => {
|
|
31
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
32
|
+
const subscriptions = [];
|
|
33
|
+
const transport = {
|
|
34
|
+
subscribe: (topic, onFrame) => {
|
|
35
|
+
subscriptions.push(topic);
|
|
36
|
+
const set = listeners.get(topic) ?? /* @__PURE__ */ new Set();
|
|
37
|
+
set.add(onFrame);
|
|
38
|
+
listeners.set(topic, set);
|
|
39
|
+
return () => set.delete(onFrame);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const emit = (topic, frame) => {
|
|
43
|
+
for (const listener of [...listeners.get(topic) ?? []]) listener(frame);
|
|
44
|
+
};
|
|
45
|
+
const listenerCount = (topic) => listeners.get(topic)?.size ?? 0;
|
|
46
|
+
return { transport, emit, subscriptions, listenerCount };
|
|
47
|
+
};
|
|
48
|
+
let cursor = 0;
|
|
49
|
+
const eventFrame = (args) => {
|
|
50
|
+
cursor += 1;
|
|
51
|
+
return {
|
|
52
|
+
type: "event",
|
|
53
|
+
topic: args.topic,
|
|
54
|
+
cursor: `${cursor}-0`,
|
|
55
|
+
eventKey: `${args.kind}:${cursor}`,
|
|
56
|
+
kind: args.kind,
|
|
57
|
+
payload: args.payload,
|
|
58
|
+
createdAt: "2026-10-09T14:02:12.004Z"
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const sessionUpdateFrame = (args) => ({
|
|
62
|
+
seq: args.seq,
|
|
63
|
+
direction: args.direction ?? "agent_to_client",
|
|
64
|
+
at: "2026-10-09T14:02:12.004Z",
|
|
65
|
+
frame: {
|
|
66
|
+
jsonrpc: "2.0",
|
|
67
|
+
method: "session/update",
|
|
68
|
+
params: { sessionId: "ases_1", update: args.update }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const promptFrame = (seq) => ({
|
|
72
|
+
seq,
|
|
73
|
+
direction: "client_to_agent",
|
|
74
|
+
at: "2026-10-09T14:02:11.000Z",
|
|
75
|
+
frame: {
|
|
76
|
+
jsonrpc: "2.0",
|
|
77
|
+
id: 1,
|
|
78
|
+
method: "session/prompt",
|
|
79
|
+
params: { sessionId: "ases_1", prompt: [] }
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const flush = async () => {
|
|
83
|
+
for (let index = 0; index < 10; index += 1)
|
|
84
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
85
|
+
};
|
|
86
|
+
export {
|
|
87
|
+
createFakeFetch,
|
|
88
|
+
createFakeTransport,
|
|
89
|
+
eventFrame,
|
|
90
|
+
flush,
|
|
91
|
+
promptFrame,
|
|
92
|
+
sessionUpdateFrame
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=test-fakes.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/test-fakes.ts"],
|
|
4
|
+
"sourcesContent": ["import type { JsonValue } from '@finalai/agent-protocol';\nimport * as z from 'zod';\nimport type { FetchIface } from \"./http.mjs\";\nimport type { RealtimeTransportFrameIface, RealtimeTransportIface } from \"./realtime.mjs\";\n\n// Dependency seams for SDK tests: a routed fake fetch and an in-memory\n// realtime transport. No module mocking.\n\nexport interface RecordedRequestIface {\n method: string;\n path: string;\n query: URLSearchParams;\n headers: Record<string, string>;\n credentials: RequestCredentials | undefined;\n body: JsonValue | null;\n}\n\nexport interface FakeResponseIface {\n status?: number;\n json?: JsonValue;\n text?: string;\n}\n\nexport type FakeRoute = (request: RecordedRequestIface) => FakeResponseIface;\n\nconst headerRecordSchema = z.record(z.string(), z.string());\n\nexport const createFakeFetch = (routes: Record<string, FakeRoute>) => {\n const requests: RecordedRequestIface[] = [];\n const fetch: FetchIface = async (input, init) => {\n const url = new URL(input);\n const bodyText = z.string().safeParse(init.body);\n const request: RecordedRequestIface = {\n method: init.method ?? 'GET',\n path: url.pathname,\n query: url.searchParams,\n headers: headerRecordSchema.safeParse(init.headers).data ?? {},\n credentials: init.credentials,\n body: bodyText.success ? z.json().parse(JSON.parse(bodyText.data)) : null,\n };\n requests.push(request);\n const route = routes[`${request.method} ${request.path}`];\n if (route == null) {\n return new Response(JSON.stringify({ error: { code: 'not_found', message: 'no route' } }), {\n status: 404,\n });\n }\n const response = route(request);\n const status = response.status ?? 200;\n const body = status === 204 ? null : (response.text ?? JSON.stringify(response.json ?? {}));\n return new Response(body, { status });\n };\n return { fetch, requests };\n};\n\nexport const createFakeTransport = () => {\n const listeners = new Map<string, Set<(frame: RealtimeTransportFrameIface) => void>>();\n const subscriptions: string[] = [];\n const transport: RealtimeTransportIface = {\n subscribe: (topic, onFrame) => {\n subscriptions.push(topic);\n const set = listeners.get(topic) ?? new Set();\n set.add(onFrame);\n listeners.set(topic, set);\n return () => set.delete(onFrame);\n },\n };\n const emit = (topic: string, frame: RealtimeTransportFrameIface): void => {\n for (const listener of [...(listeners.get(topic) ?? [])]) listener(frame);\n };\n const listenerCount = (topic: string): number => listeners.get(topic)?.size ?? 0;\n return { transport, emit, subscriptions, listenerCount };\n};\n\nlet cursor = 0;\n\nexport const eventFrame = (args: {\n topic: string;\n kind: string;\n payload: JsonValue;\n}): RealtimeTransportFrameIface => {\n cursor += 1;\n return {\n type: 'event',\n topic: args.topic,\n cursor: `${cursor}-0`,\n eventKey: `${args.kind}:${cursor}`,\n kind: args.kind,\n payload: args.payload,\n createdAt: '2026-10-09T14:02:12.004Z',\n };\n};\n\nexport const sessionUpdateFrame = (args: {\n seq: number;\n update: JsonValue;\n direction?: string;\n}): JsonValue => ({\n seq: args.seq,\n direction: args.direction ?? 'agent_to_client',\n at: '2026-10-09T14:02:12.004Z',\n frame: {\n jsonrpc: '2.0',\n method: 'session/update',\n params: { sessionId: 'ases_1', update: args.update },\n },\n});\n\nexport const promptFrame = (seq: number): JsonValue => ({\n seq,\n direction: 'client_to_agent',\n at: '2026-10-09T14:02:11.000Z',\n frame: {\n jsonrpc: '2.0',\n id: 1,\n method: 'session/prompt',\n params: { sessionId: 'ases_1', prompt: [] },\n },\n});\n\n/** Lets pending promise callbacks (replay fetches) run. */\nexport const flush = async (): Promise<void> => {\n for (let index = 0; index < 10; index += 1)\n await new Promise((resolve) => setTimeout(resolve, 0));\n};\n"],
|
|
5
|
+
"mappings": "AACA,YAAY,OAAO;AAwBnB,MAAM,qBAAqB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAEnD,MAAM,kBAAkB,CAAC,WAAsC;AACpE,QAAM,WAAmC,CAAC;AAC1C,QAAM,QAAoB,OAAO,OAAO,SAAS;AAC/C,UAAM,MAAM,IAAI,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@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@finalai/final-agent-provider/channels/final';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@finalai/agent-definition/hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@finalai/agent-definition/authoring';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@finalai/agent-definition/instructions';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { ClaudeModelId, CodexCliModelId, CodexResponsesLiteModelId, FinalHarnessModelId, HarnessBindingOutputIface, LocalStdioConfigInputIface, PiModelId, RemoteAcpConfigInputIface, RemoteClaudeCodeConfigInputIface, RemoteClientTlsInputIface, RemoteCodexConfigInputIface, RemotePiConfigInputIface, SecretRefIface, ServerlessFinalConfigInputIface, ServerlessNanocodeClaudeConfigInputIface, ServerlessNanocodeCodexConfigInputIface, ServerlessPiConfigInputIface, } from '@finalai/final-agent-provider/harnesses';
|
|
2
|
+
export type { ComputerInlineGuideInputIface, ComputerInputIface, ComputerParametersInputIface, ComputerRepositoryInputIface, ComputerSetupGuideInputIface, DeviceInputIface, InstalledSandboxEnvironmentIface, InstalledSandboxOpenRequestIface, SandboxOpenInputIface, } from '@finalai/final-agent-provider/sandboxes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=providers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@finalai/agent-definition/tools';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CompileResultIface } from '@finalai/agent-definition/compiler';
|
|
2
|
+
import type { AgentClientIface } from "../agent-client/client.mjs";
|
|
3
|
+
import { type OutputIface } from "./output.mjs";
|
|
4
|
+
export declare const COMPILE_OUTPUT_DIR: string;
|
|
5
|
+
export interface CompileDirectoryArgsIface {
|
|
6
|
+
source: {
|
|
7
|
+
dir: string;
|
|
8
|
+
} | {
|
|
9
|
+
files: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
client: AgentClientIface | null;
|
|
12
|
+
output: OutputIface;
|
|
13
|
+
}
|
|
14
|
+
export declare const compileAndPrint: (args: CompileDirectoryArgsIface) => Promise<{
|
|
15
|
+
result: CompileResultIface;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const runBuild: (args: {
|
|
19
|
+
dir: string;
|
|
20
|
+
client: AgentClientIface | null;
|
|
21
|
+
output: OutputIface;
|
|
22
|
+
}) => Promise<number>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DiagnosticSeverity,
|
|
3
|
+
hasErrors
|
|
4
|
+
} from "@finalai/agent-definition/compiler";
|
|
5
|
+
import { ProviderRefKind } from "@finalai/agent-provider";
|
|
6
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { compile } from "../compile.mjs";
|
|
9
|
+
import { createHarnessDescriptions } from "./harness-descriptions.mjs";
|
|
10
|
+
import {
|
|
11
|
+
diagnosticLine,
|
|
12
|
+
hookLines,
|
|
13
|
+
manifestSummaryLines,
|
|
14
|
+
reportLines
|
|
15
|
+
} from "./output.mjs";
|
|
16
|
+
const COMPILE_OUTPUT_DIR = join(".final", "compile");
|
|
17
|
+
const compileAndPrint = async (args) => {
|
|
18
|
+
const options = {
|
|
19
|
+
...args.source,
|
|
20
|
+
// Installed harnesses are described by the platform (needs a client); a
|
|
21
|
+
// bundle harness by its own describe, run locally.
|
|
22
|
+
harnessDescriptions: createHarnessDescriptions({ client: args.client, output: args.output })
|
|
23
|
+
};
|
|
24
|
+
const result = await compile(options);
|
|
25
|
+
const { stdout, stderr } = args.output;
|
|
26
|
+
if (result.manifest != null) {
|
|
27
|
+
for (const line of manifestSummaryLines(result.manifest)) stdout(line);
|
|
28
|
+
for (const line of hookLines(result.manifest)) stdout(line);
|
|
29
|
+
}
|
|
30
|
+
if (result.report != null) for (const line of reportLines(result.report)) stdout(line);
|
|
31
|
+
else if (args.client == null && result.manifest != null && result.manifest.harness.harness.kind !== ProviderRefKind.Bundle)
|
|
32
|
+
stdout("compatibility: not checked (set FINAL_API_KEY to check the installed harness)");
|
|
33
|
+
for (const item of result.diagnostics) {
|
|
34
|
+
(item.severity === DiagnosticSeverity.Error ? stderr : stdout)(diagnosticLine(item));
|
|
35
|
+
}
|
|
36
|
+
const ok = !hasErrors(result.diagnostics) && result.manifest != null && result.report?.ok !== false;
|
|
37
|
+
return { result, ok };
|
|
38
|
+
};
|
|
39
|
+
const prettyJson = (value) => `${JSON.stringify(value, null, 2)}
|
|
40
|
+
`;
|
|
41
|
+
const writeOutputs = async (dir, result) => {
|
|
42
|
+
const out = join(dir, COMPILE_OUTPUT_DIR);
|
|
43
|
+
await rm(out, { recursive: true, force: true });
|
|
44
|
+
await mkdir(out, { recursive: true });
|
|
45
|
+
await writeFile(join(out, "diagnostics.json"), prettyJson(result.diagnostics));
|
|
46
|
+
if (result.manifest != null)
|
|
47
|
+
await writeFile(join(out, "manifest.json"), prettyJson(result.manifest));
|
|
48
|
+
if (result.report != null) await writeFile(join(out, "report.json"), prettyJson(result.report));
|
|
49
|
+
if (result.bundle != null) {
|
|
50
|
+
await writeFile(join(out, "bundle.mjs"), result.bundle.code);
|
|
51
|
+
await writeFile(
|
|
52
|
+
join(out, "modules.json"),
|
|
53
|
+
prettyJson({
|
|
54
|
+
hash: result.bundle.hash,
|
|
55
|
+
modules: result.bundle.modules,
|
|
56
|
+
sandboxOpeners: result.bundle.sandboxOpeners
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
};
|
|
62
|
+
const runBuild = async (args) => {
|
|
63
|
+
const { result, ok } = await compileAndPrint({
|
|
64
|
+
source: { dir: args.dir },
|
|
65
|
+
client: args.client,
|
|
66
|
+
output: args.output
|
|
67
|
+
});
|
|
68
|
+
const out = await writeOutputs(args.dir, result);
|
|
69
|
+
args.output.stdout(`wrote ${out}`);
|
|
70
|
+
return ok ? 0 : 1;
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
COMPILE_OUTPUT_DIR,
|
|
74
|
+
compileAndPrint,
|
|
75
|
+
runBuild
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/cli/build.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n DiagnosticSeverity,\n hasErrors,\n type CompileOptionsIface,\n type CompileResultIface,\n} from '@finalai/agent-definition/compiler';\nimport { ProviderRefKind } from '@finalai/agent-provider';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { AgentClientIface } from \"../agent-client/client.mjs\";\nimport { compile } from \"../compile.mjs\";\nimport { createHarnessDescriptions } from \"./harness-descriptions.mjs\";\nimport {\n diagnosticLine,\n hookLines,\n manifestSummaryLines,\n reportLines,\n type OutputIface,\n} from \"./output.mjs\";\n\n// `final agents build`: compiles the agent directory, prints the\n// manifest summary, the compatibility report for the chosen harness, the\n// diagnostics and the hooks, and writes the outputs under `.final/compile/`.\n\nexport const COMPILE_OUTPUT_DIR = join('.final', 'compile');\n\nexport interface CompileDirectoryArgsIface {\n // The directory on disk, or the files that will be committed.\n source: { dir: string } | { files: Record<string, string> };\n // Null compiles without a compatibility report (no API key).\n client: AgentClientIface | null;\n output: OutputIface;\n}\n\nexport const compileAndPrint = async (\n args: CompileDirectoryArgsIface,\n): Promise<{ result: CompileResultIface; ok: boolean }> => {\n const options: CompileOptionsIface = {\n ...args.source,\n // Installed harnesses are described by the platform (needs a client); a\n // bundle harness by its own describe, run locally.\n harnessDescriptions: createHarnessDescriptions({ client: args.client, output: args.output }),\n };\n const result = await compile(options);\n const { stdout, stderr } = args.output;\n if (result.manifest != null) {\n for (const line of manifestSummaryLines(result.manifest)) stdout(line);\n for (const line of hookLines(result.manifest)) stdout(line);\n }\n if (result.report != null) for (const line of reportLines(result.report)) stdout(line);\n else if (\n args.client == null &&\n result.manifest != null &&\n result.manifest.harness.harness.kind !== ProviderRefKind.Bundle\n )\n stdout('compatibility: not checked (set FINAL_API_KEY to check the installed harness)');\n for (const item of result.diagnostics) {\n (item.severity === DiagnosticSeverity.Error ? stderr : stdout)(diagnosticLine(item));\n }\n const ok =\n !hasErrors(result.diagnostics) && result.manifest != null && result.report?.ok !== false;\n return { result, ok };\n};\n\nconst prettyJson = (value: CompileOutputJson): string => `${JSON.stringify(value, null, 2)}\\n`;\n\ntype CompileOutputJson =\n | CompileResultIface['diagnostics']\n | NonNullable<CompileResultIface['manifest']>\n | NonNullable<CompileResultIface['report']>\n | { hash: string; modules: Record<string, string>; sandboxOpeners: Record<string, string> };\n\nconst writeOutputs = async (dir: string, result: CompileResultIface): Promise<string> => {\n const out = join(dir, COMPILE_OUTPUT_DIR);\n await rm(out, { recursive: true, force: true });\n await mkdir(out, { recursive: true });\n await writeFile(join(out, 'diagnostics.json'), prettyJson(result.diagnostics));\n if (result.manifest != null)\n await writeFile(join(out, 'manifest.json'), prettyJson(result.manifest));\n if (result.report != null) await writeFile(join(out, 'report.json'), prettyJson(result.report));\n if (result.bundle != null) {\n await writeFile(join(out, 'bundle.mjs'), result.bundle.code);\n await writeFile(\n join(out, 'modules.json'),\n prettyJson({\n hash: result.bundle.hash,\n modules: result.bundle.modules,\n sandboxOpeners: result.bundle.sandboxOpeners,\n }),\n );\n }\n return out;\n};\n\nexport const runBuild = async (args: {\n dir: string;\n client: AgentClientIface | null;\n output: OutputIface;\n}): Promise<number> => {\n const { result, ok } = await compileAndPrint({\n source: { dir: args.dir },\n client: args.client,\n output: args.output,\n });\n const out = await writeOutputs(args.dir, result);\n args.output.stdout(`wrote ${out}`);\n return ok ? 0 : 1;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,uBAAuB;AAChC,SAAS,OAAO,IAAI,iBAAiB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,QAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC,QAAM,UAAU,KAAK,KAAK,kBAAkB,GAAG,WAAW,OAAO,WAAW,CAAC;AAC7E,MAAI,OAAO,YAAY;AACrB,UAAM,UAAU,KAAK,KAAK,eAAe,GAAG,WAAW,OAAO,QAAQ,CAAC;AACzE,MAAI,OAAO,UAAU,KAAM,OAAM,UAAU,KAAK,KAAK,aAAa,GAAG,WAAW,OAAO,MAAM,CAAC;AAC9F,MAAI,OAAO,UAAU,MAAM;AACzB,UAAM,UAAU,KAAK,KAAK,YAAY,GAAG,OAAO,OAAO,IAAI;AAC3D,UAAM;AAAA,MACJ,KAAK,KAAK,cAAc;AAAA,MACxB,WAAW;AAAA,QACT,MAAM,OAAO,OAAO;AAAA,QACpB,SAAS,OAAO,OAAO;AAAA,QACvB,gBAAgB,OAAO,OAAO;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,WAAW,OAAO,SAIR;AACrB,QAAM,EAAE,QAAQ,GAAG,IAAI,MAAM,gBAAgB;AAAA,IAC3C,QAAQ,EAAE,KAAK,KAAK,IAAI;AAAA,IACxB,QAAQ,KAAK;AAAA,IACb,QAAQ,KAAK;AAAA,EACf,CAAC;AACD,QAAM,MAAM,MAAM,aAAa,KAAK,KAAK,MAAM;AAC/C,OAAK,OAAO,OAAO,SAAS,GAAG,EAAE;AACjC,SAAO,KAAK,IAAI;AAClB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IncomingMessage, Server } from 'node:http';
|
|
2
|
+
export declare const attachDevChannelSockets: (args: {
|
|
3
|
+
server: Server;
|
|
4
|
+
open: (incoming: IncomingMessage, signal: AbortSignal) => Promise<ChannelSocketOpenResult>;
|
|
5
|
+
log: (message: string) => void;
|
|
6
|
+
}) => {
|
|
7
|
+
close: () => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
import type { ChannelSocketOpenResult } from '@finalai/agent-provider/local-channel-socket';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHANNEL_SOCKET_MAX_MESSAGE_BYTES,
|
|
3
|
+
ChannelSocketActionKind,
|
|
4
|
+
channelSocketData
|
|
5
|
+
} from "@finalai/agent-provider/channel-socket";
|
|
6
|
+
import { WebSocketServer } from "ws";
|
|
7
|
+
const attachDevChannelSockets = (args) => {
|
|
8
|
+
const protocols = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const sockets = new WebSocketServer({
|
|
10
|
+
noServer: true,
|
|
11
|
+
perMessageDeflate: false,
|
|
12
|
+
maxPayload: CHANNEL_SOCKET_MAX_MESSAGE_BYTES,
|
|
13
|
+
handleProtocols: (_offered, request) => protocols.get(request) ?? false
|
|
14
|
+
});
|
|
15
|
+
const controllers = /* @__PURE__ */ new Set();
|
|
16
|
+
let stopped = false;
|
|
17
|
+
const reject = async (socket, response) => {
|
|
18
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
19
|
+
const headers = new Headers(response.headers);
|
|
20
|
+
headers.set("connection", "close");
|
|
21
|
+
headers.set("content-length", String(body.byteLength));
|
|
22
|
+
socket.write(
|
|
23
|
+
`HTTP/1.1 ${response.status} ${response.statusText}\r
|
|
24
|
+
${[...headers].map(([name, value]) => `${name}: ${value}`).join("\r\n")}\r
|
|
25
|
+
\r
|
|
26
|
+
`
|
|
27
|
+
);
|
|
28
|
+
socket.end(body);
|
|
29
|
+
};
|
|
30
|
+
args.server.on("upgrade", (incoming, socket, head) => {
|
|
31
|
+
const controller = new AbortController();
|
|
32
|
+
controllers.add(controller);
|
|
33
|
+
socket.once("close", () => controller.abort());
|
|
34
|
+
socket.once("error", () => controller.abort());
|
|
35
|
+
let upgraded = false;
|
|
36
|
+
void (async () => {
|
|
37
|
+
if (stopped) {
|
|
38
|
+
await reject(socket, new Response("Dev server stopping", { status: 503 }));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const opened = await args.open(incoming, controller.signal);
|
|
42
|
+
if (!opened.ok) {
|
|
43
|
+
await reject(socket, opened.response);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (controller.signal.aborted) {
|
|
47
|
+
opened.connection.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
protocols.set(incoming, opened.protocol);
|
|
51
|
+
sockets.handleUpgrade(incoming, socket, head, (peer) => {
|
|
52
|
+
upgraded = true;
|
|
53
|
+
const cleanup = () => {
|
|
54
|
+
opened.connection.close();
|
|
55
|
+
controller.abort();
|
|
56
|
+
controllers.delete(controller);
|
|
57
|
+
};
|
|
58
|
+
peer.once("close", cleanup);
|
|
59
|
+
peer.once("error", cleanup);
|
|
60
|
+
peer.on("message", (raw, binary) => {
|
|
61
|
+
try {
|
|
62
|
+
const bytes = Array.isArray(raw) ? Buffer.concat(raw) : Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
63
|
+
opened.connection.send(binary ? bytes : bytes.toString("utf8"));
|
|
64
|
+
} catch {
|
|
65
|
+
peer.close(1013, "Channel input unavailable");
|
|
66
|
+
cleanup();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
void (async () => {
|
|
70
|
+
for await (const action of opened.connection.actions) {
|
|
71
|
+
if (peer.readyState !== peer.OPEN) break;
|
|
72
|
+
if (action.kind === ChannelSocketActionKind.Message) {
|
|
73
|
+
if (peer.bufferedAmount > 8 * 1024 * 1024) {
|
|
74
|
+
peer.close(1013, "Channel output fell behind");
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
peer.send(channelSocketData(action));
|
|
78
|
+
} else if (action.kind === ChannelSocketActionKind.Close) {
|
|
79
|
+
peer.close(action.code ?? 1e3, action.reason ?? "");
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (peer.readyState === peer.OPEN) peer.close(1e3);
|
|
84
|
+
})().catch((cause) => {
|
|
85
|
+
args.log(
|
|
86
|
+
`socket route failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
87
|
+
);
|
|
88
|
+
if (peer.readyState === peer.OPEN) peer.close(1011, "Channel route failed");
|
|
89
|
+
}).finally(cleanup);
|
|
90
|
+
});
|
|
91
|
+
})().catch(async (cause) => {
|
|
92
|
+
args.log(`socket route failed: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
93
|
+
if (!socket.destroyed)
|
|
94
|
+
await reject(socket, new Response("Channel route failed", { status: 500 }));
|
|
95
|
+
}).finally(() => {
|
|
96
|
+
if (!upgraded) {
|
|
97
|
+
controller.abort();
|
|
98
|
+
controllers.delete(controller);
|
|
99
|
+
}
|
|
100
|
+
}).catch(() => socket.destroy());
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
close: async () => {
|
|
104
|
+
stopped = true;
|
|
105
|
+
for (const controller of controllers) controller.abort();
|
|
106
|
+
for (const peer of sockets.clients) peer.terminate();
|
|
107
|
+
await new Promise((resolve) => sockets.close(() => resolve()));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
attachDevChannelSockets
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=channel-socket.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/cli/channel-socket.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n CHANNEL_SOCKET_MAX_MESSAGE_BYTES,\n ChannelSocketActionKind,\n channelSocketData,\n} from '@finalai/agent-provider/channel-socket';\nimport type { IncomingMessage, Server } from 'node:http';\nimport type { Duplex } from 'node:stream';\nimport { WebSocketServer } from 'ws';\n\n// Keeps an accepted local route on its original compiled bundle until disconnect.\nexport const attachDevChannelSockets = (args: {\n server: Server;\n open: (incoming: IncomingMessage, signal: AbortSignal) => Promise<ChannelSocketOpenResult>;\n log: (message: string) => void;\n}) => {\n const protocols = new WeakMap<IncomingMessage, string | null>();\n const sockets = new WebSocketServer({\n noServer: true,\n perMessageDeflate: false,\n maxPayload: CHANNEL_SOCKET_MAX_MESSAGE_BYTES,\n handleProtocols: (_offered, request) => protocols.get(request) ?? false,\n });\n const controllers = new Set<AbortController>();\n let stopped = false;\n const reject = async (socket: Duplex, response: Response): Promise<void> => {\n const body = Buffer.from(await response.arrayBuffer());\n const headers = new Headers(response.headers);\n headers.set('connection', 'close');\n headers.set('content-length', String(body.byteLength));\n socket.write(\n `HTTP/1.1 ${response.status} ${response.statusText}\\r\\n${[...headers].map(([name, value]) => `${name}: ${value}`).join('\\r\\n')}\\r\\n\\r\\n`,\n );\n socket.end(body);\n };\n args.server.on('upgrade', (incoming, socket, head) => {\n const controller = new AbortController();\n controllers.add(controller);\n socket.once('close', () => controller.abort());\n socket.once('error', () => controller.abort());\n let upgraded = false;\n void (async () => {\n if (stopped) {\n await reject(socket, new Response('Dev server stopping', { status: 503 }));\n return;\n }\n const opened = await args.open(incoming, controller.signal);\n if (!opened.ok) {\n await reject(socket, opened.response);\n return;\n }\n if (controller.signal.aborted) {\n opened.connection.close();\n return;\n }\n protocols.set(incoming, opened.protocol);\n sockets.handleUpgrade(incoming, socket, head, (peer) => {\n upgraded = true;\n const cleanup = (): void => {\n opened.connection.close();\n controller.abort();\n controllers.delete(controller);\n };\n peer.once('close', cleanup);\n peer.once('error', cleanup);\n peer.on('message', (raw, binary) => {\n try {\n const bytes = Array.isArray(raw)\n ? Buffer.concat(raw)\n : Buffer.isBuffer(raw)\n ? raw\n : Buffer.from(raw);\n opened.connection.send(binary ? bytes : bytes.toString('utf8'));\n } catch {\n peer.close(1013, 'Channel input unavailable');\n cleanup();\n }\n });\n void (async () => {\n for await (const action of opened.connection.actions) {\n if (peer.readyState !== peer.OPEN) break;\n if (action.kind === ChannelSocketActionKind.Message) {\n if (peer.bufferedAmount > 8 * 1024 * 1024) {\n peer.close(1013, 'Channel output fell behind');\n break;\n }\n peer.send(channelSocketData(action));\n } else if (action.kind === ChannelSocketActionKind.Close) {\n peer.close(action.code ?? 1000, action.reason ?? '');\n break;\n }\n }\n if (peer.readyState === peer.OPEN) peer.close(1000);\n })()\n .catch((cause: unknown) => {\n args.log(\n `socket route failed: ${cause instanceof Error ? cause.message : String(cause)}`,\n );\n if (peer.readyState === peer.OPEN) peer.close(1011, 'Channel route failed');\n })\n .finally(cleanup);\n });\n })()\n .catch(async (cause: unknown) => {\n args.log(`socket route failed: ${cause instanceof Error ? cause.message : String(cause)}`);\n if (!socket.destroyed)\n await reject(socket, new Response('Channel route failed', { status: 500 }));\n })\n .finally(() => {\n if (!upgraded) {\n controller.abort();\n controllers.delete(controller);\n }\n })\n .catch(() => socket.destroy());\n });\n return {\n close: async (): Promise<void> => {\n stopped = true;\n for (const controller of controllers) controller.abort();\n for (const peer of sockets.clients) peer.terminate();\n await new Promise<void>((resolve) => sockets.close(() => resolve()));\n },\n };\n};\n\nimport type { ChannelSocketOpenResult } from '@finalai/agent-provider/local-channel-socket';\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,uBAAuB;AAGzB,MAAM,0BAA0B,CAAC,SAIlC;AACJ,QAAM,YAAY,oBAAI,QAAwC;AAC9D,QAAM,UAAU,IAAI,gBAAgB;AAAA,IAClC,UAAU;AAAA,IACV,mBAAmB;AAAA,IACnB,YAAY;AAAA,IACZ,iBAAiB,CAAC,UAAU,YAAY,UAAU,IAAI,OAAO,KAAK;AAAA,EACpE,CAAC;AACD,QAAM,cAAc,oBAAI,IAAqB;AAC7C,MAAI,UAAU;AACd,QAAM,SAAS,OAAO,QAAgB,aAAsC;AAC1E,UAAM,OAAO,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC;AACrD,UAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;AAC5C,YAAQ,IAAI,cAAc,OAAO;AACjC,YAAQ,IAAI,kBAAkB,OAAO,KAAK,UAAU,CAAC;AACrD,WAAO;AA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AAO,QAAQ,CAAC;AAAA,EACjC,CAAC;AACD,SAAO;AAAA,IACL,OAAO,YAA2B;AAChC,gBAAU;AACV,iBAAW,cAAc,YAAa,YAAW,MAAM;AACvD,iBAAW,QAAQ,QAAQ,QAAS,MAAK,UAAU;AACnD,YAAM,IAAI,QAAc,CAAC,YAAY,QAAQ,MAAM,MAAM,QAAQ,CAAC,CAAC;AAAA,IACrE;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FetchIface } from "../agent-client/http.mjs";
|
|
2
|
+
import { type ImportModule } from "./conformance.mjs";
|
|
3
|
+
import { type ListFiles } from "./files.mjs";
|
|
4
|
+
import type { OutputIface } from "./output.mjs";
|
|
5
|
+
export declare const DEFAULT_AGENTS_HOST = "https://agent-session.final.ai/api";
|
|
6
|
+
export interface AgentsCliDepsIface {
|
|
7
|
+
argv: string[];
|
|
8
|
+
env: Record<string, string | undefined>;
|
|
9
|
+
cwd: string;
|
|
10
|
+
output: OutputIface;
|
|
11
|
+
fetch?: FetchIface;
|
|
12
|
+
listFiles?: ListFiles;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
importModule?: ImportModule;
|
|
15
|
+
}
|
|
16
|
+
export declare const runAgentsCommand: (deps: AgentsCliDepsIface) => Promise<number>;
|