@finalai/agents 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOSTING.md +334 -245
- package/README.md +214 -29
- package/dist/modules/agent-client/agent-input.d.mts +24 -0
- package/dist/modules/agent-client/agent-input.mjs +46 -0
- package/dist/modules/agent-client/agent-input.mjs.map +7 -0
- package/dist/modules/agent-client/channels.d.mts +52 -3
- package/dist/modules/agent-client/channels.mjs +71 -10
- package/dist/modules/agent-client/channels.mjs.map +2 -2
- package/dist/modules/agent-client/client.d.mts +85 -20
- package/dist/modules/agent-client/client.mjs +74 -21
- package/dist/modules/agent-client/client.mjs.map +2 -2
- package/dist/modules/agent-client/config-options.mjs +1 -2
- package/dist/modules/agent-client/config-options.mjs.map +2 -2
- package/dist/modules/agent-client/conversation-resources.d.mts +85 -0
- package/dist/modules/agent-client/conversation-resources.mjs +150 -0
- package/dist/modules/agent-client/conversation-resources.mjs.map +7 -0
- package/dist/modules/agent-client/conversations.d.mts +116 -38
- package/dist/modules/agent-client/conversations.mjs +379 -71
- package/dist/modules/agent-client/conversations.mjs.map +2 -2
- package/dist/modules/agent-client/defaults.d.mts +8 -0
- package/dist/modules/agent-client/defaults.mjs +77 -0
- package/dist/modules/agent-client/defaults.mjs.map +7 -0
- package/dist/modules/agent-client/errors.d.mts +22 -2
- package/dist/modules/agent-client/errors.mjs +19 -0
- package/dist/modules/agent-client/errors.mjs.map +2 -2
- package/dist/modules/agent-client/events.d.mts +62 -0
- package/dist/modules/agent-client/events.mjs +107 -0
- package/dist/modules/agent-client/events.mjs.map +7 -0
- package/dist/modules/agent-client/harnesses.d.mts +66 -0
- package/dist/modules/agent-client/harnesses.mjs +156 -0
- package/dist/modules/agent-client/harnesses.mjs.map +7 -0
- package/dist/modules/agent-client/http.d.mts +2 -1
- package/dist/modules/agent-client/http.mjs +21 -2
- package/dist/modules/agent-client/http.mjs.map +2 -2
- package/dist/modules/agent-client/index.d.mts +21 -6
- package/dist/modules/agent-client/index.mjs +26 -0
- package/dist/modules/agent-client/index.mjs.map +2 -2
- package/dist/modules/agent-client/integrations.d.mts +40 -0
- package/dist/modules/agent-client/integrations.mjs +92 -0
- package/dist/modules/agent-client/integrations.mjs.map +7 -0
- package/dist/modules/agent-client/local-host-protocol.d.mts +156 -0
- package/dist/modules/agent-client/local-host-protocol.mjs +258 -0
- package/dist/modules/agent-client/local-host-protocol.mjs.map +7 -0
- package/dist/modules/agent-client/local-host.d.mts +56 -0
- package/dist/modules/agent-client/local-host.mjs +200 -0
- package/dist/modules/agent-client/local-host.mjs.map +7 -0
- package/dist/modules/agent-client/oauth-clients.d.mts +36 -0
- package/dist/modules/agent-client/oauth-clients.mjs +67 -0
- package/dist/modules/agent-client/oauth-clients.mjs.map +7 -0
- package/dist/modules/agent-client/project-agents.d.mts +54 -0
- package/dist/modules/agent-client/project-agents.mjs +111 -0
- package/dist/modules/agent-client/project-agents.mjs.map +7 -0
- package/dist/modules/agent-client/project.d.mts +43 -0
- package/dist/modules/agent-client/project.mjs +66 -0
- package/dist/modules/agent-client/project.mjs.map +7 -0
- package/dist/modules/agent-client/projects.d.mts +61 -0
- package/dist/modules/agent-client/projects.mjs +145 -0
- package/dist/modules/agent-client/projects.mjs.map +7 -0
- package/dist/modules/agent-client/provide.d.mts +41 -0
- package/dist/modules/agent-client/provide.mjs +90 -0
- package/dist/modules/agent-client/provide.mjs.map +7 -0
- package/dist/modules/agent-client/publishers.d.mts +57 -0
- package/dist/modules/agent-client/publishers.mjs +109 -0
- package/dist/modules/agent-client/publishers.mjs.map +7 -0
- package/dist/modules/agent-client/requirements.d.mts +60 -0
- package/dist/modules/agent-client/requirements.mjs +83 -0
- package/dist/modules/agent-client/requirements.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-providers.d.mts +34 -0
- package/dist/modules/agent-client/sandbox-providers.mjs +75 -0
- package/dist/modules/agent-client/sandbox-providers.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-uri.d.mts +1 -1
- package/dist/modules/agent-client/sandbox-uri.mjs +4 -4
- package/dist/modules/agent-client/sandbox-uri.mjs.map +1 -1
- package/dist/modules/agent-client/sandboxes.d.mts +65 -0
- package/dist/modules/agent-client/sandboxes.mjs +130 -0
- package/dist/modules/agent-client/sandboxes.mjs.map +7 -0
- package/dist/modules/agent-client/schedules.d.mts +24 -0
- package/dist/modules/agent-client/schedules.mjs +56 -0
- package/dist/modules/agent-client/schedules.mjs.map +7 -0
- package/dist/modules/agent-client/sessions.d.mts +46 -8
- package/dist/modules/agent-client/sessions.mjs +91 -29
- package/dist/modules/agent-client/sessions.mjs.map +2 -2
- package/dist/modules/agent-client/start.d.mts +101 -0
- package/dist/modules/agent-client/start.mjs +260 -0
- package/dist/modules/agent-client/start.mjs.map +7 -0
- package/dist/modules/agent-client/test-fakes.d.mts +1 -0
- package/dist/modules/agent-client/test-fakes.mjs +3 -1
- package/dist/modules/agent-client/test-fakes.mjs.map +2 -2
- package/dist/modules/cli/agent-module.d.mts +39 -0
- package/dist/modules/cli/agent-module.mjs +89 -0
- package/dist/modules/cli/agent-module.mjs.map +7 -0
- package/dist/modules/cli/cli.d.mts +6 -6
- package/dist/modules/cli/cli.mjs +94 -120
- package/dist/modules/cli/cli.mjs.map +2 -2
- package/dist/modules/cli/conformance.d.mts +2 -6
- package/dist/modules/cli/conformance.mjs +5 -8
- package/dist/modules/cli/conformance.mjs.map +2 -2
- package/dist/modules/cli/main.mjs.map +1 -1
- package/dist/modules/cli/output.d.mts +0 -9
- package/dist/modules/cli/output.mjs +7 -85
- package/dist/modules/cli/output.mjs.map +2 -2
- package/dist/modules/harnesses.mjs.map +2 -2
- package/dist/modules/index.d.mts +0 -2
- package/dist/modules/index.mjs +0 -4
- package/dist/modules/index.mjs.map +2 -2
- package/dist/modules/integrations.d.mts +24 -0
- package/dist/modules/integrations.mjs +30 -0
- package/dist/modules/integrations.mjs.map +7 -0
- package/dist/modules/public.d.mts +10 -10
- package/dist/modules/public.mjs +29 -78
- package/dist/modules/public.mjs.map +2 -2
- package/dist/modules/sandboxes.d.mts +2 -0
- package/dist/modules/sandboxes.mjs +4 -0
- package/dist/modules/sandboxes.mjs.map +2 -2
- package/dist/modules/verify.d.mts +1 -0
- package/dist/modules/verify.mjs +2 -0
- package/dist/modules/verify.mjs.map +7 -0
- package/dist/modules/webhooks.d.mts +37 -0
- package/dist/modules/webhooks.mjs +100 -0
- package/dist/modules/webhooks.mjs.map +7 -0
- package/examples/release-scout/README.md +18 -10
- package/examples/release-scout/agent.ts +41 -0
- package/examples/release-scout/by-name.ts +43 -0
- package/examples/release-scout/db.ts +6 -0
- package/examples/release-scout/instructions.md +5 -0
- package/examples/release-scout/run-on-a-computer.ts +49 -0
- package/examples/release-scout/run.ts +38 -0
- package/package.json +42 -28
- package/dist/modules/agent-client/build.d.mts +0 -110
- package/dist/modules/agent-client/build.mjs +0 -213
- package/dist/modules/agent-client/build.mjs.map +0 -7
- package/dist/modules/authoring/index.d.mts +0 -1
- package/dist/modules/authoring/index.mjs +0 -2
- package/dist/modules/authoring/index.mjs.map +0 -7
- package/dist/modules/authoring/instructions.d.mts +0 -1
- package/dist/modules/authoring/instructions.mjs +0 -2
- package/dist/modules/authoring/instructions.mjs.map +0 -7
- package/dist/modules/authoring/providers.d.mts +0 -2
- package/dist/modules/authoring/providers.mjs +0 -1
- package/dist/modules/authoring/providers.mjs.map +0 -7
- package/dist/modules/cli/build.d.mts +0 -22
- package/dist/modules/cli/build.mjs +0 -77
- package/dist/modules/cli/build.mjs.map +0 -7
- package/dist/modules/cli/channel-install.d.mts +0 -12
- package/dist/modules/cli/channel-install.mjs +0 -25
- package/dist/modules/cli/channel-install.mjs.map +0 -7
- package/dist/modules/cli/channel-socket.d.mts +0 -9
- package/dist/modules/cli/channel-socket.mjs +0 -114
- package/dist/modules/cli/channel-socket.mjs.map +0 -7
- package/dist/modules/cli/dev.d.mts +0 -26
- package/dist/modules/cli/dev.mjs +0 -311
- package/dist/modules/cli/dev.mjs.map +0 -7
- package/dist/modules/cli/files.d.mts +0 -18
- package/dist/modules/cli/files.mjs +0 -66
- package/dist/modules/cli/files.mjs.map +0 -7
- package/dist/modules/cli/harness-descriptions.d.mts +0 -20
- package/dist/modules/cli/harness-descriptions.mjs +0 -70
- package/dist/modules/cli/harness-descriptions.mjs.map +0 -7
- package/dist/modules/cli/publish.d.mts +0 -15
- package/dist/modules/cli/publish.mjs +0 -92
- package/dist/modules/cli/publish.mjs.map +0 -7
- package/dist/modules/compile.d.mts +0 -3
- package/dist/modules/compile.mjs +0 -58
- package/dist/modules/compile.mjs.map +0 -7
- package/dist/modules/index.browser.d.mts +0 -4
- package/dist/modules/index.browser.mjs +0 -8
- package/dist/modules/index.browser.mjs.map +0 -7
- package/examples/custom-harness/README.md +0 -16
- package/examples/custom-harness/agent.ts +0 -154
- package/examples/custom-sandbox/README.md +0 -12
- package/examples/custom-sandbox/agent.ts +0 -14
- package/examples/custom-sandbox/sandbox.ts +0 -24
- package/examples/release-scout/agent/agent.ts +0 -22
- package/examples/release-scout/agent/channels/github-signature.ts +0 -27
- package/examples/release-scout/agent/channels/github.ts +0 -32
- package/examples/release-scout/agent/connections/linear.ts +0 -9
- package/examples/release-scout/agent/hooks/audit.ts +0 -24
- package/examples/release-scout/agent/instructions/org-context.ts +0 -26
- package/examples/release-scout/agent/instructions.md +0 -2
- package/examples/release-scout/agent/sandbox.ts +0 -20
- package/examples/release-scout/agent/schedules/daily-digest.md +0 -7
- package/examples/release-scout/agent/skills/triage/SKILL.md +0 -8
- package/examples/release-scout/agent/skills/triage/checklist.md +0 -3
- package/examples/release-scout/agent/tools/lookup_release_notes.ts +0 -24
- package/examples/release-scout/client.ts +0 -122
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { connectSandboxClient } from "@finalai/agent-provider/sandbox/client";
|
|
2
|
+
import { frameChannelFromWebSocket } from "@finalai/agent-provider/sandbox/wire";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import { noChannelSource } from "./channels.mjs";
|
|
5
|
+
import { clientError, ClientErrorCode } from "./errors.mjs";
|
|
6
|
+
import { LOCAL_HOST_SUBPROTOCOL } from "./local-host-protocol.mjs";
|
|
7
|
+
const agentValueSchema = z.custom(
|
|
8
|
+
(value) => typeof value === "object" && value != null && "require" in value && "name" in value,
|
|
9
|
+
"Not an agent: define it with defineAgent, or fetch it with project.agents.get"
|
|
10
|
+
);
|
|
11
|
+
const agentValueOf = (agent) => {
|
|
12
|
+
const value = agentValueSchema.safeParse(agent);
|
|
13
|
+
if (value.success) return value.data;
|
|
14
|
+
throw clientError({
|
|
15
|
+
message: value.error.issues[0]?.message ?? "Not an agent",
|
|
16
|
+
status: 0,
|
|
17
|
+
code: ClientErrorCode.InvalidRequest
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const defaultAgentCodec = {
|
|
21
|
+
documentOf: async (agent) => (await import("@finalai/agent-definition")).documentOf(agentValueOf(agent)),
|
|
22
|
+
inProcessCodeOf: async (agent) => (await import("@finalai/agent-definition")).inProcessCodeOf(agentValueOf(agent))
|
|
23
|
+
};
|
|
24
|
+
const defaultChannelSourceOf = noChannelSource;
|
|
25
|
+
const defaultLocalCompute = () => ({
|
|
26
|
+
sandbox: async () => {
|
|
27
|
+
const { createLocalSandbox } = await import("@finalai/final-agent-provider/sandboxes/local");
|
|
28
|
+
return createLocalSandbox({ root: globalThis.process.cwd() });
|
|
29
|
+
},
|
|
30
|
+
openSandbox: (endpoint) => connectSandboxClient({
|
|
31
|
+
url: endpoint.url,
|
|
32
|
+
token: endpoint.token,
|
|
33
|
+
expiresAt: endpoint.expiresAt
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
const defaultLocalHostDial = (http) => async (path, signal) => {
|
|
37
|
+
const url = http.url(path);
|
|
38
|
+
url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
|
|
39
|
+
const headers = await http.headers();
|
|
40
|
+
const { WebSocket } = await import("ws");
|
|
41
|
+
signal?.throwIfAborted();
|
|
42
|
+
const socket = new WebSocket(url, [LOCAL_HOST_SUBPROTOCOL], { headers });
|
|
43
|
+
let tcp = null;
|
|
44
|
+
let referenced = true;
|
|
45
|
+
socket.on("upgrade", (response) => {
|
|
46
|
+
tcp = response.socket;
|
|
47
|
+
if (!referenced) tcp.unref();
|
|
48
|
+
});
|
|
49
|
+
const { channel, opened } = frameChannelFromWebSocket(socket);
|
|
50
|
+
const onAbort = () => socket.terminate();
|
|
51
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
52
|
+
try {
|
|
53
|
+
await opened;
|
|
54
|
+
} finally {
|
|
55
|
+
signal?.removeEventListener("abort", onAbort);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
...channel,
|
|
59
|
+
keepAlive: {
|
|
60
|
+
ref: () => {
|
|
61
|
+
referenced = true;
|
|
62
|
+
tcp?.ref();
|
|
63
|
+
},
|
|
64
|
+
unref: () => {
|
|
65
|
+
referenced = false;
|
|
66
|
+
tcp?.unref();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
defaultAgentCodec,
|
|
73
|
+
defaultChannelSourceOf,
|
|
74
|
+
defaultLocalCompute,
|
|
75
|
+
defaultLocalHostDial
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=defaults.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/defaults.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AgentIface } from '@finalai/agent-definition';\nimport { connectSandboxClient } from '@finalai/agent-provider/sandbox/client';\nimport { frameChannelFromWebSocket } from '@finalai/agent-provider/sandbox/wire';\nimport * as z from 'zod';\nimport type { AgentValueCodecIface } from \"./agent-input.mjs\";\nimport { noChannelSource, type ChannelSourceOf } from \"./channels.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport type { HttpIface } from \"./http.mjs\";\nimport { LOCAL_HOST_SUBPROTOCOL } from \"./local-host-protocol.mjs\";\nimport type { LocalComputeIface, LocalHostSocketIface } from \"./local-host.mjs\";\n\n// What `createClient` uses unless a seam replaces it.\n\nconst agentValueSchema = z.custom<AgentIface>(\n (value) => typeof value === 'object' && value != null && 'require' in value && 'name' in value,\n 'Not an agent: define it with defineAgent, or fetch it with project.agents.get',\n);\n\nconst agentValueOf = (agent: object): AgentIface => {\n const value = agentValueSchema.safeParse(agent);\n if (value.success) return value.data;\n throw clientError({\n message: value.error.issues[0]?.message ?? 'Not an agent',\n status: 0,\n code: ClientErrorCode.InvalidRequest,\n });\n};\n\n// Loaded on first use, so browser bundles of the client leave the authoring\n// code (and its source parser) out until an agent value is started.\nexport const defaultAgentCodec: AgentValueCodecIface = {\n documentOf: async (agent) =>\n (await import('@finalai/agent-definition')).documentOf(agentValueOf(agent)),\n inProcessCodeOf: async (agent) =>\n (await import('@finalai/agent-definition')).inProcessCodeOf(agentValueOf(agent)),\n};\n\nexport const defaultChannelSourceOf: ChannelSourceOf = noChannelSource;\n\n// The model's files and shell are this process's working directory, as for a\n// coding agent run on this machine. Loaded on use: it needs Node.\nexport const defaultLocalCompute = (): LocalComputeIface => ({\n sandbox: async () => {\n const { createLocalSandbox } = await import('@finalai/final-agent-provider/sandboxes/local');\n return createLocalSandbox({ root: globalThis.process.cwd() });\n },\n openSandbox: (endpoint) =>\n connectSandboxClient({\n url: endpoint.url,\n token: endpoint.token,\n expiresAt: endpoint.expiresAt,\n }),\n});\n\n// The local host socket is dialed from Node with the client's own headers. It\n// keeps the process alive only while the host starts or is in use (see\n// LocalHostKeepAliveIface), so a script that is done exits and the platform\n// reports its tools and compute as unavailable.\nexport const defaultLocalHostDial =\n (http: HttpIface) =>\n async (path: string, signal?: AbortSignal): Promise<LocalHostSocketIface> => {\n const url = http.url(path);\n url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:';\n const headers = await http.headers();\n const { WebSocket } = await import('ws');\n signal?.throwIfAborted();\n const socket = new WebSocket(url, [LOCAL_HOST_SUBPROTOCOL], { headers });\n let tcp: { ref: () => unknown; unref: () => unknown } | null = null;\n let referenced = true;\n socket.on('upgrade', (response) => {\n tcp = response.socket;\n if (!referenced) tcp.unref();\n });\n const { channel, opened } = frameChannelFromWebSocket(socket);\n // Aborting while the socket opens tears it down, which rejects `opened`.\n const onAbort = () => socket.terminate();\n signal?.addEventListener('abort', onAbort, { once: true });\n try {\n await opened;\n } finally {\n signal?.removeEventListener('abort', onAbort);\n }\n return {\n ...channel,\n keepAlive: {\n ref: () => {\n referenced = true;\n tcp?.ref();\n },\n unref: () => {\n referenced = false;\n tcp?.unref();\n },\n },\n };\n };\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAC1C,YAAY,OAAO;AAEnB,SAAS,uBAA6C;AACtD,SAAS,aAAa,uBAAuB;AAE7C,SAAS,8BAA8B;AAKvC,MAAM,mBAAmB,EAAE;AAAA,EACzB,CAAC,UAAU,OAAO,UAAU,YAAY,SAAS,QAAQ,aAAa,SAAS,UAAU;AAAA,EACzF;AACF;AAEA,MAAM,eAAe,CAAC,UAA8B;AAClD,QAAM,QAAQ,iBAAiB,UAAU,KAAK;AAC9C,MAAI,MAAM,QAAS,QAAO,MAAM;AAChC,QAAM,YAAY;AAAA,IAChB,SAAS,MAAM,MAAM,OAAO,CAAC,GAAG,WAAW;AAAA,IAC3C,QAAQ;AAAA,IACR,MAAM,gBAAgB;AAAA,EACxB,CAAC;AACH;AAIO,MAAM,oBAA0C;AAAA,EACrD,YAAY,OAAO,WAChB,MAAM,OAAO,2BAA2B,GAAG,WAAW,aAAa,KAAK,CAAC;AAAA,EAC5E,iBAAiB,OAAO,WACrB,MAAM,OAAO,2BAA2B,GAAG,gBAAgB,aAAa,KAAK,CAAC;AACnF;AAEO,MAAM,yBAA0C;AAIhD,MAAM,sBAAsB,OAA0B;AAAA,EAC3D,SAAS,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ue } from '@finalai/agent-protocol';
|
|
2
|
+
import type { UnmetRequirementIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
3
|
export declare enum AgentClientErrorName {
|
|
3
4
|
Client = "ClientError",
|
|
4
5
|
Decision = "DecisionError",
|
|
5
6
|
TurnRejected = "TurnRejectedError",
|
|
6
|
-
RealtimeSubscription = "RealtimeSubscriptionError"
|
|
7
|
+
RealtimeSubscription = "RealtimeSubscriptionError",
|
|
8
|
+
RequirementsUnmet = "RequirementsUnmetError"
|
|
7
9
|
}
|
|
8
10
|
export declare enum DecisionErrorReason {
|
|
9
11
|
NotFound = "not_found",
|
|
@@ -49,7 +51,19 @@ export interface RealtimeSubscriptionErrorIface extends Error, ErrorFieldsIface
|
|
|
49
51
|
name: AgentClientErrorName.RealtimeSubscription;
|
|
50
52
|
topic: string;
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Something an agent requires was not provided or does not suit it, so nothing
|
|
56
|
+
* was created. `code` is `requirements_unmet`, or `harness_unsuitable` when only
|
|
57
|
+
* the harness settings were refused. `status` is 0 when the SDK found it before
|
|
58
|
+
* sending.
|
|
59
|
+
*/
|
|
60
|
+
export interface RequirementsUnmetErrorIface extends Error, ErrorFieldsIface {
|
|
61
|
+
name: AgentClientErrorName.RequirementsUnmet;
|
|
62
|
+
/** The agent's hash or id, when known. */
|
|
63
|
+
agent: string | null;
|
|
64
|
+
requirements: UnmetRequirementIface[];
|
|
65
|
+
}
|
|
66
|
+
export type AgentClientError = ClientErrorIface | DecisionErrorIface | TurnRejectedErrorIface | RealtimeSubscriptionErrorIface | RequirementsUnmetErrorIface;
|
|
53
67
|
export interface ClientErrorArgsIface {
|
|
54
68
|
message: string;
|
|
55
69
|
status: number;
|
|
@@ -66,6 +80,11 @@ export declare const turnRejectedError: (args: ClientErrorArgsIface & {
|
|
|
66
80
|
sessionId: string | null;
|
|
67
81
|
state: string | null;
|
|
68
82
|
}) => TurnRejectedErrorIface;
|
|
83
|
+
export declare const requirementsUnmetError: (args: Omit<ClientErrorArgsIface, "message"> & {
|
|
84
|
+
message?: string;
|
|
85
|
+
agent: string | null;
|
|
86
|
+
requirements: UnmetRequirementIface[];
|
|
87
|
+
}) => RequirementsUnmetErrorIface;
|
|
69
88
|
export declare const realtimeSubscriptionError: (args: {
|
|
70
89
|
topic: string;
|
|
71
90
|
code: string;
|
|
@@ -80,6 +99,7 @@ export declare const isTerminalRealtimeError: (frame: {
|
|
|
80
99
|
export declare const isClientError: (cause: unknown) => cause is AgentClientError;
|
|
81
100
|
export declare const isDecisionError: (cause: unknown) => cause is DecisionErrorIface;
|
|
82
101
|
export declare const isTurnRejectedError: (cause: unknown) => cause is TurnRejectedErrorIface;
|
|
102
|
+
export declare const isRequirementsUnmetError: (cause: unknown) => cause is RequirementsUnmetErrorIface;
|
|
83
103
|
export declare const isRealtimeSubscriptionError: (cause: unknown) => cause is RealtimeSubscriptionErrorIface;
|
|
84
104
|
export declare const isRetryableClientError: (cause: unknown) => boolean;
|
|
85
105
|
export {};
|
|
@@ -4,6 +4,7 @@ var AgentClientErrorName = /* @__PURE__ */ ((AgentClientErrorName2) => {
|
|
|
4
4
|
AgentClientErrorName2["Decision"] = "DecisionError";
|
|
5
5
|
AgentClientErrorName2["TurnRejected"] = "TurnRejectedError";
|
|
6
6
|
AgentClientErrorName2["RealtimeSubscription"] = "RealtimeSubscriptionError";
|
|
7
|
+
AgentClientErrorName2["RequirementsUnmet"] = "RequirementsUnmetError";
|
|
7
8
|
return AgentClientErrorName2;
|
|
8
9
|
})(AgentClientErrorName || {});
|
|
9
10
|
var DecisionErrorReason = /* @__PURE__ */ ((DecisionErrorReason2) => {
|
|
@@ -47,6 +48,21 @@ const turnRejectedError = (args) => Object.assign(baseError(args), {
|
|
|
47
48
|
sessionId: args.sessionId,
|
|
48
49
|
state: args.state
|
|
49
50
|
});
|
|
51
|
+
const requirementLine = (requirement) => `${requirement.kind} ${requirement.name} (${requirement.problem}${requirement.detail == null ? "" : `: ${requirement.detail}`})`;
|
|
52
|
+
const requirementsUnmetError = (args) => Object.assign(
|
|
53
|
+
baseError({
|
|
54
|
+
...args,
|
|
55
|
+
message: args.message ?? `The agent's requirements are not met: ${args.requirements.map(requirementLine).join("; ")}`
|
|
56
|
+
}),
|
|
57
|
+
{
|
|
58
|
+
name: "RequirementsUnmetError" /* RequirementsUnmet */,
|
|
59
|
+
status: args.status,
|
|
60
|
+
code: args.code,
|
|
61
|
+
body: args.body ?? null,
|
|
62
|
+
agent: args.agent,
|
|
63
|
+
requirements: args.requirements
|
|
64
|
+
}
|
|
65
|
+
);
|
|
50
66
|
const realtimeStatusByCode = /* @__PURE__ */ new Map([
|
|
51
67
|
["unauthorized", 401],
|
|
52
68
|
["forbidden", 403],
|
|
@@ -74,6 +90,7 @@ const errorNameOf = (cause) => {
|
|
|
74
90
|
const isClientError = (cause) => errorNameOf(cause) != null;
|
|
75
91
|
const isDecisionError = (cause) => errorNameOf(cause) === "DecisionError" /* Decision */;
|
|
76
92
|
const isTurnRejectedError = (cause) => errorNameOf(cause) === "TurnRejectedError" /* TurnRejected */;
|
|
93
|
+
const isRequirementsUnmetError = (cause) => errorNameOf(cause) === "RequirementsUnmetError" /* RequirementsUnmet */;
|
|
77
94
|
const isRealtimeSubscriptionError = (cause) => errorNameOf(cause) === "RealtimeSubscriptionError" /* RealtimeSubscription */;
|
|
78
95
|
const isRetryableClientError = (cause) => isClientError(cause) && (cause.code === "network_error" /* Network */ || cause.status === 429 || cause.status >= 500);
|
|
79
96
|
export {
|
|
@@ -85,10 +102,12 @@ export {
|
|
|
85
102
|
isClientError,
|
|
86
103
|
isDecisionError,
|
|
87
104
|
isRealtimeSubscriptionError,
|
|
105
|
+
isRequirementsUnmetError,
|
|
88
106
|
isRetryableClientError,
|
|
89
107
|
isTerminalRealtimeError,
|
|
90
108
|
isTurnRejectedError,
|
|
91
109
|
realtimeSubscriptionError,
|
|
110
|
+
requirementsUnmetError,
|
|
92
111
|
turnRejectedError
|
|
93
112
|
};
|
|
94
113
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/errors.ts"],
|
|
4
|
-
"sourcesContent": ["import type { JsonValue } from '@finalai/agent-protocol';\nimport * as z from 'zod';\n\n// Errors are plain `Error` objects with a discriminating `name` (no classes):\n// narrow with the `is*Error` guards, never `instanceof`.\n\nexport enum AgentClientErrorName {\n Client = 'ClientError',\n Decision = 'DecisionError',\n TurnRejected = 'TurnRejectedError',\n RealtimeSubscription = 'RealtimeSubscriptionError',\n}\n\nexport enum DecisionErrorReason {\n NotFound = 'not_found',\n NotInAudience = 'not_in_audience',\n AlreadyResolved = 'already_resolved',\n Expired = 'expired',\n}\n\n/** Codes the SDK itself assigns when no HTTP error body applies. */\nexport enum ClientErrorCode {\n Network = 'network_error',\n InvalidRequest = 'invalid_request',\n InvalidResponse = 'invalid_response',\n UploadFailed = 'upload_failed',\n NotFound = 'not_found',\n Closed = 'client_closed',\n /** The runtime's fetch cannot stream a response body (Streamable HTTP). */\n StreamUnsupported = 'stream_unsupported',\n Unknown = 'unknown',\n}\n\ninterface ErrorFieldsIface {\n /** HTTP status; 0 when no response arrived or the SDK rejected the call locally. */\n status: number;\n code: string;\n body: JsonValue | null;\n}\n\nexport interface ClientErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.Client;\n}\n\n/** Answering a decision outside your audience, already resolved, expired, or unknown. */\nexport interface DecisionErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.Decision;\n decisionId: string | null;\n reason: DecisionErrorReason;\n}\n\n/** The session is not accepting prompts; `state` is its ACP/session state. */\nexport interface TurnRejectedErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.TurnRejected;\n sessionId: string | null;\n state: string | null;\n}\n\n/** The realtime gateway refused a topic for good (no access, unknown topic, subscription limit). */\nexport interface RealtimeSubscriptionErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.RealtimeSubscription;\n topic: string;\n}\n\nexport type AgentClientError =\n | ClientErrorIface\n | DecisionErrorIface\n | TurnRejectedErrorIface\n | RealtimeSubscriptionErrorIface;\n\ntype ErrorBaseKey = 'message' | 'stack' | 'cause';\n\nexport interface ClientErrorArgsIface {\n message: string;\n status: number;\n code: string;\n body?: JsonValue | null;\n cause?: unknown;\n}\n\nconst baseError = (args: ClientErrorArgsIface): Error =>\n args.cause === undefined\n ? new Error(args.message)\n : new Error(args.message, { cause: args.cause });\n\nexport const clientError = (args: ClientErrorArgsIface): ClientErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.Client,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n } satisfies Omit<ClientErrorIface, ErrorBaseKey>);\n\nexport const decisionError = (\n args: ClientErrorArgsIface & { decisionId: string | null; reason: DecisionErrorReason },\n): DecisionErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.Decision,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n decisionId: args.decisionId,\n reason: args.reason,\n } satisfies Omit<DecisionErrorIface, ErrorBaseKey>);\n\nexport const turnRejectedError = (\n args: ClientErrorArgsIface & { sessionId: string | null; state: string | null },\n): TurnRejectedErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.TurnRejected,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n sessionId: args.sessionId,\n state: args.state,\n } satisfies Omit<TurnRejectedErrorIface, ErrorBaseKey>);\n\n// Gateway codes map onto the HTTP statuses callers already branch on.\nconst realtimeStatusByCode = new Map<string, number>([\n ['unauthorized', 401],\n ['forbidden', 403],\n ['not_found', 404],\n ['too_many_subscriptions', 429],\n]);\n\nexport const realtimeSubscriptionError = (args: {\n topic: string;\n code: string;\n message: string;\n}): RealtimeSubscriptionErrorIface =>\n Object.assign(new Error(args.message), {\n name: AgentClientErrorName.RealtimeSubscription,\n status: realtimeStatusByCode.get(args.code) ?? 0,\n code: args.code,\n body: null,\n topic: args.topic,\n } satisfies Omit<RealtimeSubscriptionErrorIface, ErrorBaseKey>);\n\n/** Whether a realtime error frame ends the subscription: explicit, or by a known terminal code. */\nexport const isTerminalRealtimeError = (frame: {\n code: string | null;\n retryable: boolean | null;\n}): boolean =>\n frame.retryable === false ||\n (frame.retryable == null && realtimeStatusByCode.has(frame.code ?? ''));\n\nconst errorIdentitySchema = z.object({\n name: z.nativeEnum(AgentClientErrorName),\n status: z.number(),\n code: z.string(),\n message: z.string(),\n});\n\nconst errorNameOf = (cause: unknown): AgentClientErrorName | null => {\n const parsed = errorIdentitySchema.safeParse(cause);\n return parsed.success ? parsed.data.name : null;\n};\n\n/** True for every SDK error (ClientError, DecisionError, TurnRejectedError). */\nexport const isClientError = (cause: unknown): cause is AgentClientError =>\n errorNameOf(cause) != null;\n\nexport const isDecisionError = (cause: unknown): cause is DecisionErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.Decision;\n\nexport const isTurnRejectedError = (cause: unknown): cause is TurnRejectedErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.TurnRejected;\n\nexport const isRealtimeSubscriptionError = (\n cause: unknown,\n): cause is RealtimeSubscriptionErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.RealtimeSubscription;\n\nexport const isRetryableClientError = (cause: unknown): boolean =>\n isClientError(cause) &&\n (cause.code === ClientErrorCode.Network || cause.status === 429 || cause.status >= 500);\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { JsonValue } from '@finalai/agent-protocol';\nimport type { UnmetRequirementIface } from '@finalai/agent-protocol/agent-platform';\nimport * as z from 'zod';\n\n// Errors are plain `Error` objects with a discriminating `name` (no classes):\n// narrow with the `is*Error` guards, never `instanceof`.\n\nexport enum AgentClientErrorName {\n Client = 'ClientError',\n Decision = 'DecisionError',\n TurnRejected = 'TurnRejectedError',\n RealtimeSubscription = 'RealtimeSubscriptionError',\n RequirementsUnmet = 'RequirementsUnmetError',\n}\n\nexport enum DecisionErrorReason {\n NotFound = 'not_found',\n NotInAudience = 'not_in_audience',\n AlreadyResolved = 'already_resolved',\n Expired = 'expired',\n}\n\n/** Codes the SDK itself assigns when no HTTP error body applies. */\nexport enum ClientErrorCode {\n Network = 'network_error',\n InvalidRequest = 'invalid_request',\n InvalidResponse = 'invalid_response',\n UploadFailed = 'upload_failed',\n NotFound = 'not_found',\n Closed = 'client_closed',\n /** The runtime's fetch cannot stream a response body (Streamable HTTP). */\n StreamUnsupported = 'stream_unsupported',\n Unknown = 'unknown',\n}\n\ninterface ErrorFieldsIface {\n /** HTTP status; 0 when no response arrived or the SDK rejected the call locally. */\n status: number;\n code: string;\n body: JsonValue | null;\n}\n\nexport interface ClientErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.Client;\n}\n\n/** Answering a decision outside your audience, already resolved, expired, or unknown. */\nexport interface DecisionErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.Decision;\n decisionId: string | null;\n reason: DecisionErrorReason;\n}\n\n/** The session is not accepting prompts; `state` is its ACP/session state. */\nexport interface TurnRejectedErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.TurnRejected;\n sessionId: string | null;\n state: string | null;\n}\n\n/** The realtime gateway refused a topic for good (no access, unknown topic, subscription limit). */\nexport interface RealtimeSubscriptionErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.RealtimeSubscription;\n topic: string;\n}\n\n/**\n * Something an agent requires was not provided or does not suit it, so nothing\n * was created. `code` is `requirements_unmet`, or `harness_unsuitable` when only\n * the harness settings were refused. `status` is 0 when the SDK found it before\n * sending.\n */\nexport interface RequirementsUnmetErrorIface extends Error, ErrorFieldsIface {\n name: AgentClientErrorName.RequirementsUnmet;\n /** The agent's hash or id, when known. */\n agent: string | null;\n requirements: UnmetRequirementIface[];\n}\n\nexport type AgentClientError =\n | ClientErrorIface\n | DecisionErrorIface\n | TurnRejectedErrorIface\n | RealtimeSubscriptionErrorIface\n | RequirementsUnmetErrorIface;\n\ntype ErrorBaseKey = 'message' | 'stack' | 'cause';\n\nexport interface ClientErrorArgsIface {\n message: string;\n status: number;\n code: string;\n body?: JsonValue | null;\n cause?: unknown;\n}\n\nconst baseError = (args: ClientErrorArgsIface): Error =>\n args.cause === undefined\n ? new Error(args.message)\n : new Error(args.message, { cause: args.cause });\n\nexport const clientError = (args: ClientErrorArgsIface): ClientErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.Client,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n } satisfies Omit<ClientErrorIface, ErrorBaseKey>);\n\nexport const decisionError = (\n args: ClientErrorArgsIface & { decisionId: string | null; reason: DecisionErrorReason },\n): DecisionErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.Decision,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n decisionId: args.decisionId,\n reason: args.reason,\n } satisfies Omit<DecisionErrorIface, ErrorBaseKey>);\n\nexport const turnRejectedError = (\n args: ClientErrorArgsIface & { sessionId: string | null; state: string | null },\n): TurnRejectedErrorIface =>\n Object.assign(baseError(args), {\n name: AgentClientErrorName.TurnRejected,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n sessionId: args.sessionId,\n state: args.state,\n } satisfies Omit<TurnRejectedErrorIface, ErrorBaseKey>);\n\nconst requirementLine = (requirement: UnmetRequirementIface): string =>\n `${requirement.kind} ${requirement.name} (${requirement.problem}${\n requirement.detail == null ? '' : `: ${requirement.detail}`\n })`;\n\nexport const requirementsUnmetError = (\n args: Omit<ClientErrorArgsIface, 'message'> & {\n message?: string;\n agent: string | null;\n requirements: UnmetRequirementIface[];\n },\n): RequirementsUnmetErrorIface =>\n Object.assign(\n baseError({\n ...args,\n message:\n args.message ??\n `The agent's requirements are not met: ${args.requirements.map(requirementLine).join('; ')}`,\n }),\n {\n name: AgentClientErrorName.RequirementsUnmet,\n status: args.status,\n code: args.code,\n body: args.body ?? null,\n agent: args.agent,\n requirements: args.requirements,\n } satisfies Omit<RequirementsUnmetErrorIface, ErrorBaseKey>,\n );\n\n// Gateway codes map onto the HTTP statuses callers already branch on.\nconst realtimeStatusByCode = new Map<string, number>([\n ['unauthorized', 401],\n ['forbidden', 403],\n ['not_found', 404],\n ['too_many_subscriptions', 429],\n]);\n\nexport const realtimeSubscriptionError = (args: {\n topic: string;\n code: string;\n message: string;\n}): RealtimeSubscriptionErrorIface =>\n Object.assign(new Error(args.message), {\n name: AgentClientErrorName.RealtimeSubscription,\n status: realtimeStatusByCode.get(args.code) ?? 0,\n code: args.code,\n body: null,\n topic: args.topic,\n } satisfies Omit<RealtimeSubscriptionErrorIface, ErrorBaseKey>);\n\n/** Whether a realtime error frame ends the subscription: explicit, or by a known terminal code. */\nexport const isTerminalRealtimeError = (frame: {\n code: string | null;\n retryable: boolean | null;\n}): boolean =>\n frame.retryable === false ||\n (frame.retryable == null && realtimeStatusByCode.has(frame.code ?? ''));\n\nconst errorIdentitySchema = z.object({\n name: z.nativeEnum(AgentClientErrorName),\n status: z.number(),\n code: z.string(),\n message: z.string(),\n});\n\nconst errorNameOf = (cause: unknown): AgentClientErrorName | null => {\n const parsed = errorIdentitySchema.safeParse(cause);\n return parsed.success ? parsed.data.name : null;\n};\n\n/** True for every SDK error (ClientError, DecisionError, TurnRejectedError). */\nexport const isClientError = (cause: unknown): cause is AgentClientError =>\n errorNameOf(cause) != null;\n\nexport const isDecisionError = (cause: unknown): cause is DecisionErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.Decision;\n\nexport const isTurnRejectedError = (cause: unknown): cause is TurnRejectedErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.TurnRejected;\n\nexport const isRequirementsUnmetError = (cause: unknown): cause is RequirementsUnmetErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.RequirementsUnmet;\n\nexport const isRealtimeSubscriptionError = (\n cause: unknown,\n): cause is RealtimeSubscriptionErrorIface =>\n errorNameOf(cause) === AgentClientErrorName.RealtimeSubscription;\n\nexport const isRetryableClientError = (cause: unknown): boolean =>\n isClientError(cause) &&\n (cause.code === ClientErrorCode.Network || cause.status === 429 || cause.status >= 500);\n"],
|
|
5
|
+
"mappings": "AAEA,YAAY,OAAO;AAKZ,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,YAAS;AACT,EAAAA,sBAAA,cAAW;AACX,EAAAA,sBAAA,kBAAe;AACf,EAAAA,sBAAA,0BAAuB;AACvB,EAAAA,sBAAA,uBAAoB;AALV,SAAAA;AAAA,GAAA;AAQL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,mBAAgB;AAChB,EAAAA,qBAAA,qBAAkB;AAClB,EAAAA,qBAAA,aAAU;AAJA,SAAAA;AAAA,GAAA;AAQL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,qBAAkB;AAClB,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,cAAW;AACX,EAAAA,iBAAA,YAAS;AAET,EAAAA,iBAAA,uBAAoB;AACpB,EAAAA,iBAAA,aAAU;AATA,SAAAA;AAAA,GAAA;AAyEZ,MAAM,YAAY,CAAC,SACjB,KAAK,UAAU,SACX,IAAI,MAAM,KAAK,OAAO,IACtB,IAAI,MAAM,KAAK,SAAS,EAAE,OAAO,KAAK,MAAM,CAAC;AAE5C,MAAM,cAAc,CAAC,SAC1B,OAAO,OAAO,UAAU,IAAI,GAAG;AAAA,EAC7B,MAAM;AAAA,EACN,QAAQ,KAAK;AAAA,EACb,MAAM,KAAK;AAAA,EACX,MAAM,KAAK,QAAQ;AACrB,CAAgD;AAE3C,MAAM,gBAAgB,CAC3B,SAEA,OAAO,OAAO,UAAU,IAAI,GAAG;AAAA,EAC7B,MAAM;AAAA,EACN,QAAQ,KAAK;AAAA,EACb,MAAM,KAAK;AAAA,EACX,MAAM,KAAK,QAAQ;AAAA,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AAqB,IAAI,MAAM,QAAQ,EAAE;AAEvE,MAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,MAAM,EAAE,WAAW,oBAAoB;AAAA,EACvC,QAAQ,EAAE,OAAO;AAAA,EACjB,MAAM,EAAE,OAAO;AAAA,EACf,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,cAAc,CAAC,UAAgD;AACnE,QAAM,SAAS,oBAAoB,UAAU,KAAK;AAClD,SAAO,OAAO,UAAU,OAAO,KAAK,OAAO;AAC7C;AAGO,MAAM,gBAAgB,CAAC,UAC5B,YAAY,KAAK,KAAK;AAEjB,MAAM,kBAAkB,CAAC,UAC9B,YAAY,KAAK,MAAM;AAElB,MAAM,sBAAsB,CAAC,UAClC,YAAY,KAAK,MAAM;AAElB,MAAM,2BAA2B,CAAC,UACvC,YAAY,KAAK,MAAM;AAElB,MAAM,8BAA8B,CACzC,UAEA,YAAY,KAAK,MAAM;AAElB,MAAM,yBAAyB,CAAC,UACrC,cAAc,KAAK,MAClB,MAAM,SAAS,iCAA2B,MAAM,WAAW,OAAO,MAAM,UAAU;",
|
|
6
6
|
"names": ["AgentClientErrorName", "DecisionErrorReason", "ClientErrorCode"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type CreateEventSubscriptionRequestIface, type CreateEventSubscriptionResponseIface, type EventsPageIface, type EventSubscriptionIface, type PlatformEventKind, type PlatformEventType, type UpdateEventSubscriptionRequestIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
|
+
import { type ClientContextIface, type EnumInput, type SignalOptionsIface } from "./context.mjs";
|
|
3
|
+
/** How long `stream()` waits before reading again once it has caught up. */
|
|
4
|
+
export declare const EVENTS_POLL_INTERVAL_MS = 5000;
|
|
5
|
+
export interface ListEventsOptionsIface extends SignalOptionsIface {
|
|
6
|
+
/** A previous page's or delivery's `cursor`; omitted, the feed's head. */
|
|
7
|
+
after?: string;
|
|
8
|
+
kinds?: readonly EnumInput<PlatformEventKind>[];
|
|
9
|
+
limit?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface StreamEventsOptionsIface extends Omit<ListEventsOptionsIface, 'limit'> {
|
|
12
|
+
/** Defaults to `EVENTS_POLL_INTERVAL_MS`. */
|
|
13
|
+
pollIntervalMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface EventsApiIface {
|
|
16
|
+
/**
|
|
17
|
+
* One page of events after `after`, oldest first. An expired cursor (older
|
|
18
|
+
* than the feed keeps) fails with `cursor_expired` (410).
|
|
19
|
+
*/
|
|
20
|
+
list: (options?: ListEventsOptionsIface) => Promise<EventsPageIface>;
|
|
21
|
+
/**
|
|
22
|
+
* Every event after `after`, polling the feed once caught up, until
|
|
23
|
+
* `signal` aborts or the client closes. A delivery may repeat an event:
|
|
24
|
+
* deduplicate by `id`.
|
|
25
|
+
*/
|
|
26
|
+
stream: (options?: StreamEventsOptionsIface) => AsyncIterableIterator<PlatformEventType>;
|
|
27
|
+
}
|
|
28
|
+
export interface EventSubscriptionsApiIface {
|
|
29
|
+
/**
|
|
30
|
+
* Pushes events to `url`, signed with the returned `signingSecret` (shown
|
|
31
|
+
* only here; verify deliveries with `verifyWebhook` from
|
|
32
|
+
* `@finalai/agents/webhooks`). Delivery starts at the feed's head unless
|
|
33
|
+
* `after` names a cursor.
|
|
34
|
+
*/
|
|
35
|
+
create: (args: CreateEventSubscriptionRequestIface & SignalOptionsIface) => Promise<CreateEventSubscriptionResponseIface>;
|
|
36
|
+
list: (options?: SignalOptionsIface) => Promise<EventSubscriptionIface[]>;
|
|
37
|
+
get: (args: {
|
|
38
|
+
id: string;
|
|
39
|
+
} & SignalOptionsIface) => Promise<EventSubscriptionIface>;
|
|
40
|
+
/** `state: 'active'` re-enables a disabled subscription and resets its retries. */
|
|
41
|
+
update: (args: {
|
|
42
|
+
id: string;
|
|
43
|
+
} & UpdateEventSubscriptionRequestIface & SignalOptionsIface) => Promise<EventSubscriptionIface>;
|
|
44
|
+
delete: (args: {
|
|
45
|
+
id: string;
|
|
46
|
+
} & SignalOptionsIface) => Promise<void>;
|
|
47
|
+
/** Delivers again from `after`, within the feed's retention. */
|
|
48
|
+
replay: (args: {
|
|
49
|
+
id: string;
|
|
50
|
+
after: string;
|
|
51
|
+
} & SignalOptionsIface) => Promise<EventSubscriptionIface>;
|
|
52
|
+
}
|
|
53
|
+
export declare const createEventsApi: (args: {
|
|
54
|
+
context: ClientContextIface;
|
|
55
|
+
/** Narrows to this project and those below it; null for everything the caller can see. */
|
|
56
|
+
projectId: string | null;
|
|
57
|
+
}) => EventsApiIface;
|
|
58
|
+
export declare const createEventSubscriptionsApi: (args: {
|
|
59
|
+
context: ClientContextIface;
|
|
60
|
+
/** `/v1/projects/:projectId/event-subscriptions`, or `/v1/apps/me/event-subscriptions`. */
|
|
61
|
+
basePath: string;
|
|
62
|
+
}) => EventSubscriptionsApiIface;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEventSubscriptionRequestSchema,
|
|
3
|
+
createEventSubscriptionResponseSchema,
|
|
4
|
+
eventsPageSchema,
|
|
5
|
+
eventSubscriptionListSchema,
|
|
6
|
+
eventSubscriptionResponseSchema,
|
|
7
|
+
okResponseSchema,
|
|
8
|
+
replayEventSubscriptionRequestSchema,
|
|
9
|
+
updateEventSubscriptionRequestSchema
|
|
10
|
+
} from "@finalai/agent-protocol/agent-platform";
|
|
11
|
+
import {
|
|
12
|
+
encodePath
|
|
13
|
+
} from "./context.mjs";
|
|
14
|
+
import { HttpMethod } from "./http.mjs";
|
|
15
|
+
const EVENTS_POLL_INTERVAL_MS = 5e3;
|
|
16
|
+
const sleepUnlessAborted = (sleep, signal) => new Promise((resolve, reject) => {
|
|
17
|
+
if (signal.aborted) {
|
|
18
|
+
reject(signal.reason);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const onAbort = () => reject(signal.reason);
|
|
22
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
23
|
+
sleep.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
24
|
+
});
|
|
25
|
+
const createEventsApi = (args) => {
|
|
26
|
+
const { context } = args;
|
|
27
|
+
const list = (options) => context.http.request({
|
|
28
|
+
method: HttpMethod.Get,
|
|
29
|
+
path: "/v1/events",
|
|
30
|
+
query: {
|
|
31
|
+
after: options?.after,
|
|
32
|
+
limit: options?.limit,
|
|
33
|
+
kinds: options?.kinds == null ? void 0 : options.kinds.join(","),
|
|
34
|
+
projectId: args.projectId ?? void 0
|
|
35
|
+
},
|
|
36
|
+
response: eventsPageSchema,
|
|
37
|
+
signal: options?.signal
|
|
38
|
+
});
|
|
39
|
+
const stream = async function* (options) {
|
|
40
|
+
const signal = options?.signal == null ? context.closeSignal : AbortSignal.any([context.closeSignal, options.signal]);
|
|
41
|
+
let after = options?.after;
|
|
42
|
+
for (; ; ) {
|
|
43
|
+
const page = await list({ after, kinds: options?.kinds, signal });
|
|
44
|
+
yield* page.events;
|
|
45
|
+
after = page.cursor ?? after;
|
|
46
|
+
if (page.hasMore && page.events.length > 0) continue;
|
|
47
|
+
await sleepUnlessAborted(
|
|
48
|
+
context.timing.sleep(options?.pollIntervalMs ?? EVENTS_POLL_INTERVAL_MS),
|
|
49
|
+
signal
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return { list, stream };
|
|
54
|
+
};
|
|
55
|
+
const createEventSubscriptionsApi = (args) => {
|
|
56
|
+
const { http } = args.context;
|
|
57
|
+
const path = (id, suffix = "") => id == null ? args.basePath : `${args.basePath}/${encodePath(id)}${suffix}`;
|
|
58
|
+
return {
|
|
59
|
+
create: ({ signal, ...value }) => http.request({
|
|
60
|
+
method: HttpMethod.Post,
|
|
61
|
+
path: path(),
|
|
62
|
+
body: { schema: createEventSubscriptionRequestSchema, value },
|
|
63
|
+
response: createEventSubscriptionResponseSchema,
|
|
64
|
+
signal
|
|
65
|
+
}),
|
|
66
|
+
list: async (options) => (await http.request({
|
|
67
|
+
method: HttpMethod.Get,
|
|
68
|
+
path: path(),
|
|
69
|
+
response: eventSubscriptionListSchema,
|
|
70
|
+
signal: options?.signal
|
|
71
|
+
})).subscriptions,
|
|
72
|
+
get: async ({ id, signal }) => (await http.request({
|
|
73
|
+
method: HttpMethod.Get,
|
|
74
|
+
path: path(id),
|
|
75
|
+
response: eventSubscriptionResponseSchema,
|
|
76
|
+
signal
|
|
77
|
+
})).subscription,
|
|
78
|
+
update: async ({ id, signal, ...value }) => (await http.request({
|
|
79
|
+
method: HttpMethod.Patch,
|
|
80
|
+
path: path(id),
|
|
81
|
+
body: { schema: updateEventSubscriptionRequestSchema, value },
|
|
82
|
+
response: eventSubscriptionResponseSchema,
|
|
83
|
+
signal
|
|
84
|
+
})).subscription,
|
|
85
|
+
delete: async ({ id, signal }) => {
|
|
86
|
+
await http.request({
|
|
87
|
+
method: HttpMethod.Delete,
|
|
88
|
+
path: path(id),
|
|
89
|
+
response: okResponseSchema,
|
|
90
|
+
signal
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
replay: async ({ id, after, signal }) => (await http.request({
|
|
94
|
+
method: HttpMethod.Post,
|
|
95
|
+
path: path(id, "/replay"),
|
|
96
|
+
body: { schema: replayEventSubscriptionRequestSchema, value: { after } },
|
|
97
|
+
response: eventSubscriptionResponseSchema,
|
|
98
|
+
signal
|
|
99
|
+
})).subscription
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export {
|
|
103
|
+
EVENTS_POLL_INTERVAL_MS,
|
|
104
|
+
createEventSubscriptionsApi,
|
|
105
|
+
createEventsApi
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=events.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/events.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n createEventSubscriptionRequestSchema,\n createEventSubscriptionResponseSchema,\n eventsPageSchema,\n eventSubscriptionListSchema,\n eventSubscriptionResponseSchema,\n okResponseSchema,\n replayEventSubscriptionRequestSchema,\n updateEventSubscriptionRequestSchema,\n type CreateEventSubscriptionRequestIface,\n type CreateEventSubscriptionResponseIface,\n type EventsPageIface,\n type EventSubscriptionIface,\n type PlatformEventKind,\n type PlatformEventType,\n type UpdateEventSubscriptionRequestIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport {\n encodePath,\n type ClientContextIface,\n type EnumInput,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { HttpMethod } from \"./http.mjs\";\n\n// The event feed (`GET /v1/events`): what changed in the projects the caller\n// can see, in commit order, and event subscriptions that push it to a URL.\n\n/** How long `stream()` waits before reading again once it has caught up. */\nexport const EVENTS_POLL_INTERVAL_MS = 5_000;\n\nexport interface ListEventsOptionsIface extends SignalOptionsIface {\n /** A previous page's or delivery's `cursor`; omitted, the feed's head. */\n after?: string;\n kinds?: readonly EnumInput<PlatformEventKind>[];\n limit?: number;\n}\n\nexport interface StreamEventsOptionsIface extends Omit<ListEventsOptionsIface, 'limit'> {\n /** Defaults to `EVENTS_POLL_INTERVAL_MS`. */\n pollIntervalMs?: number;\n}\n\nexport interface EventsApiIface {\n /**\n * One page of events after `after`, oldest first. An expired cursor (older\n * than the feed keeps) fails with `cursor_expired` (410).\n */\n list: (options?: ListEventsOptionsIface) => Promise<EventsPageIface>;\n /**\n * Every event after `after`, polling the feed once caught up, until\n * `signal` aborts or the client closes. A delivery may repeat an event:\n * deduplicate by `id`.\n */\n stream: (options?: StreamEventsOptionsIface) => AsyncIterableIterator<PlatformEventType>;\n}\n\nexport interface EventSubscriptionsApiIface {\n /**\n * Pushes events to `url`, signed with the returned `signingSecret` (shown\n * only here; verify deliveries with `verifyWebhook` from\n * `@finalai/agents/webhooks`). Delivery starts at the feed's head unless\n * `after` names a cursor.\n */\n create: (\n args: CreateEventSubscriptionRequestIface & SignalOptionsIface,\n ) => Promise<CreateEventSubscriptionResponseIface>;\n list: (options?: SignalOptionsIface) => Promise<EventSubscriptionIface[]>;\n get: (args: { id: string } & SignalOptionsIface) => Promise<EventSubscriptionIface>;\n /** `state: 'active'` re-enables a disabled subscription and resets its retries. */\n update: (\n args: { id: string } & UpdateEventSubscriptionRequestIface & SignalOptionsIface,\n ) => Promise<EventSubscriptionIface>;\n delete: (args: { id: string } & SignalOptionsIface) => Promise<void>;\n /** Delivers again from `after`, within the feed's retention. */\n replay: (\n args: { id: string; after: string } & SignalOptionsIface,\n ) => Promise<EventSubscriptionIface>;\n}\n\n// Rejects with the signal's reason as soon as it aborts.\nconst sleepUnlessAborted = (sleep: Promise<void>, signal: AbortSignal): Promise<void> =>\n new Promise((resolve, reject) => {\n if (signal.aborted) {\n reject(signal.reason);\n return;\n }\n const onAbort = (): void => reject(signal.reason);\n signal.addEventListener('abort', onAbort, { once: true });\n sleep.then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));\n });\n\nexport const createEventsApi = (args: {\n context: ClientContextIface;\n /** Narrows to this project and those below it; null for everything the caller can see. */\n projectId: string | null;\n}): EventsApiIface => {\n const { context } = args;\n const list: EventsApiIface['list'] = (options) =>\n context.http.request({\n method: HttpMethod.Get,\n path: '/v1/events',\n query: {\n after: options?.after,\n limit: options?.limit,\n kinds: options?.kinds == null ? undefined : options.kinds.join(','),\n projectId: args.projectId ?? undefined,\n },\n response: eventsPageSchema,\n signal: options?.signal,\n });\n const stream = async function* (\n options?: StreamEventsOptionsIface,\n ): AsyncGenerator<PlatformEventType> {\n const signal =\n options?.signal == null\n ? context.closeSignal\n : AbortSignal.any([context.closeSignal, options.signal]);\n let after = options?.after;\n for (;;) {\n const page = await list({ after, kinds: options?.kinds, signal });\n yield* page.events;\n after = page.cursor ?? after;\n if (page.hasMore && page.events.length > 0) continue;\n await sleepUnlessAborted(\n context.timing.sleep(options?.pollIntervalMs ?? EVENTS_POLL_INTERVAL_MS),\n signal,\n );\n }\n };\n return { list, stream };\n};\n\nexport const createEventSubscriptionsApi = (args: {\n context: ClientContextIface;\n /** `/v1/projects/:projectId/event-subscriptions`, or `/v1/apps/me/event-subscriptions`. */\n basePath: string;\n}): EventSubscriptionsApiIface => {\n const { http } = args.context;\n const path = (id?: string, suffix = ''): string =>\n id == null ? args.basePath : `${args.basePath}/${encodePath(id)}${suffix}`;\n return {\n create: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: path(),\n body: { schema: createEventSubscriptionRequestSchema, value },\n response: createEventSubscriptionResponseSchema,\n signal,\n }),\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: path(),\n response: eventSubscriptionListSchema,\n signal: options?.signal,\n })\n ).subscriptions,\n get: async ({ id, signal }) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: path(id),\n response: eventSubscriptionResponseSchema,\n signal,\n })\n ).subscription,\n update: async ({ id, signal, ...value }) =>\n (\n await http.request({\n method: HttpMethod.Patch,\n path: path(id),\n body: { schema: updateEventSubscriptionRequestSchema, value },\n response: eventSubscriptionResponseSchema,\n signal,\n })\n ).subscription,\n delete: async ({ id, signal }) => {\n await http.request({\n method: HttpMethod.Delete,\n path: path(id),\n response: okResponseSchema,\n signal,\n });\n },\n replay: async ({ id, after, signal }) =>\n (\n await http.request({\n method: HttpMethod.Post,\n path: path(id, '/replay'),\n body: { schema: replayEventSubscriptionRequestSchema, value: { after } },\n response: eventSubscriptionResponseSchema,\n signal,\n })\n ).subscription,\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,OAIK;AACP,SAAS,kBAAkB;AAMpB,MAAM,0BAA0B;AAoDvC,MAAM,qBAAqB,CAAC,OAAsB,WAChD,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC/B,MAAI,OAAO,SAAS;AAClB,WAAO,OAAO,MAAM;AACpB;AAAA,EACF;AACA,QAAM,UAAU,MAAY,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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Capability } from '@finalai/agent-protocol';
|
|
2
|
+
import { type AcpAdapterDefinitionInfoIface, type AcpAdapterDefinitionSummaryIface, type DefinitionPublicationIface, type DefinitionVisibility, type HarnessCheckResponseIface, type HarnessDefinitionInfoIface, type HarnessDefinitionSummaryIface, type HarnessSettingsIface, type SubscriptionAllowanceIface } from '@finalai/agent-protocol/agent-platform';
|
|
3
|
+
import { type AcpAdapterDefinitionInputIface, type HarnessDefinitionInputIface } from '@finalai/agent-provider/harness-definition';
|
|
4
|
+
import type { AgentInput } from "./agent-input.mjs";
|
|
5
|
+
import { type ClientContextIface, type EnumInput, type SignalOptionsIface } from "./context.mjs";
|
|
6
|
+
export type DefinitionSelectorIface = {
|
|
7
|
+
name: string;
|
|
8
|
+
} | {
|
|
9
|
+
hash: string;
|
|
10
|
+
};
|
|
11
|
+
export interface SubscriptionAllowancesApiIface {
|
|
12
|
+
/** The harnesses subscriptions may reach in this project, the catalog's included. */
|
|
13
|
+
list: (options?: SignalOptionsIface) => Promise<SubscriptionAllowanceIface[]>;
|
|
14
|
+
/** Lets personal and shared subscriptions reach `harness`. */
|
|
15
|
+
allow: (args: {
|
|
16
|
+
harness: string;
|
|
17
|
+
} & SignalOptionsIface) => Promise<SubscriptionAllowanceIface>;
|
|
18
|
+
revoke: (args: {
|
|
19
|
+
harness: string;
|
|
20
|
+
} & SignalOptionsIface) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface HarnessesApiIface {
|
|
23
|
+
/**
|
|
24
|
+
* Whether harness settings suit an agent, where the harness would run, and
|
|
25
|
+
* which of its compute that environment covers. `agent` is the agent or its
|
|
26
|
+
* content hash; `compute` places a harness that names no environment.
|
|
27
|
+
*/
|
|
28
|
+
check: (args: {
|
|
29
|
+
agent: string | AgentInput;
|
|
30
|
+
harness: HarnessSettingsIface;
|
|
31
|
+
compute?: Partial<Record<Capability, string>>;
|
|
32
|
+
} & SignalOptionsIface) => Promise<HarnessCheckResponseIface>;
|
|
33
|
+
/**
|
|
34
|
+
* Stores a harness definition and points `name` at it. `visibility: 'public'`
|
|
35
|
+
* also makes the name public under the project's publisher handle.
|
|
36
|
+
*/
|
|
37
|
+
publish: (args: {
|
|
38
|
+
harness: HarnessDefinitionInputIface;
|
|
39
|
+
name: string;
|
|
40
|
+
visibility?: EnumInput<DefinitionVisibility>;
|
|
41
|
+
} & SignalOptionsIface) => Promise<DefinitionPublicationIface>;
|
|
42
|
+
get: (selector: DefinitionSelectorIface & SignalOptionsIface) => Promise<HarnessDefinitionInfoIface>;
|
|
43
|
+
/** The harnesses this project can name by bare name: its own and its ancestors'. */
|
|
44
|
+
list: (options?: SignalOptionsIface) => Promise<HarnessDefinitionSummaryIface[]>;
|
|
45
|
+
allowances: SubscriptionAllowancesApiIface;
|
|
46
|
+
}
|
|
47
|
+
export interface AcpAdaptersApiIface {
|
|
48
|
+
/** Stores an ACP adapter definition and points `name` at it; see `harnesses.publish` for `visibility`. */
|
|
49
|
+
publish: (args: {
|
|
50
|
+
adapter: AcpAdapterDefinitionInputIface;
|
|
51
|
+
name: string;
|
|
52
|
+
visibility?: EnumInput<DefinitionVisibility>;
|
|
53
|
+
} & SignalOptionsIface) => Promise<DefinitionPublicationIface>;
|
|
54
|
+
get: (selector: DefinitionSelectorIface & SignalOptionsIface) => Promise<AcpAdapterDefinitionInfoIface>;
|
|
55
|
+
list: (options?: SignalOptionsIface) => Promise<AcpAdapterDefinitionSummaryIface[]>;
|
|
56
|
+
}
|
|
57
|
+
export declare const createHarnessesApi: (args: {
|
|
58
|
+
context: ClientContextIface;
|
|
59
|
+
projectId: string;
|
|
60
|
+
/** Stores an agent's document so the platform can check against it; returns its hash. */
|
|
61
|
+
store: (agent: AgentInput, signal?: AbortSignal) => Promise<string>;
|
|
62
|
+
}) => HarnessesApiIface;
|
|
63
|
+
export declare const createAcpAdaptersApi: (args: {
|
|
64
|
+
context: ClientContextIface;
|
|
65
|
+
projectId: string;
|
|
66
|
+
}) => AcpAdaptersApiIface;
|