@finalai/agents 0.10.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,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
scheduleListSchema,
|
|
3
|
+
scheduleRunResultSchema,
|
|
4
|
+
scheduleSchema,
|
|
5
|
+
updateScheduleRequestSchema
|
|
6
|
+
} from "@finalai/agent-protocol/agent-platform";
|
|
7
|
+
import { encodePath } from "./context.mjs";
|
|
8
|
+
import { clientError, ClientErrorCode } from "./errors.mjs";
|
|
9
|
+
import { HttpMethod } from "./http.mjs";
|
|
10
|
+
import { provideDocumentOf } from "./provide.mjs";
|
|
11
|
+
const createSchedulesApi = ({ http }) => {
|
|
12
|
+
const list = async (options) => (await http.request({
|
|
13
|
+
method: HttpMethod.Get,
|
|
14
|
+
path: "/v1/schedules",
|
|
15
|
+
query: { agent: options?.agent },
|
|
16
|
+
response: scheduleListSchema,
|
|
17
|
+
signal: options?.signal
|
|
18
|
+
})).schedules;
|
|
19
|
+
const scheduleIdOf = async (args) => {
|
|
20
|
+
if ("scheduleId" in args) return args.scheduleId;
|
|
21
|
+
const found = (await list({ agent: args.agent, signal: args.signal })).find(
|
|
22
|
+
(schedule) => schedule.key === args.key
|
|
23
|
+
);
|
|
24
|
+
if (found == null) {
|
|
25
|
+
throw clientError({
|
|
26
|
+
message: `No schedule ${args.key} on agent ${args.agent}`,
|
|
27
|
+
status: 0,
|
|
28
|
+
code: ClientErrorCode.NotFound
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return found.id;
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
list,
|
|
35
|
+
runNow: async (args) => http.request({
|
|
36
|
+
method: HttpMethod.Post,
|
|
37
|
+
path: `/v1/schedules/${encodePath(await scheduleIdOf(args))}/run-now`,
|
|
38
|
+
response: scheduleRunResultSchema,
|
|
39
|
+
signal: args.signal
|
|
40
|
+
}),
|
|
41
|
+
update: ({ scheduleId, signal, provide, ...value }) => http.request({
|
|
42
|
+
method: HttpMethod.Patch,
|
|
43
|
+
path: `/v1/schedules/${encodePath(scheduleId)}`,
|
|
44
|
+
body: {
|
|
45
|
+
schema: updateScheduleRequestSchema,
|
|
46
|
+
value: { ...value, ...provide == null ? {} : { provide: provideDocumentOf(provide) } }
|
|
47
|
+
},
|
|
48
|
+
response: scheduleSchema,
|
|
49
|
+
signal
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
createSchedulesApi
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=schedules.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/schedules.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n scheduleListSchema,\n scheduleRunResultSchema,\n scheduleSchema,\n updateScheduleRequestSchema,\n type ScheduleIface,\n type ScheduleRunResultIface,\n type UpdateScheduleRequestIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { encodePath, type ClientContextIface, type SignalOptionsIface } from \"./context.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport { HttpMethod } from \"./http.mjs\";\nimport { provideDocumentOf, type ProvideIface } from \"./provide.mjs\";\n\n// An agent's own schedules. Nobody is calling when one fires, so each carries\n// what its runs are provided.\n\nexport type ScheduleRef = { scheduleId: string } | { agent: string; key: string };\n\nexport interface ScheduleUpdateIface extends Omit<UpdateScheduleRequestIface, 'provide'> {\n /** What its runs start with; fails with `requirements_unmet` unless it meets the agent's requirements. */\n provide?: ProvideIface;\n}\n\nexport interface SchedulesApiIface {\n /** `agent` narrows to one agent's schedules, by its id. */\n list: (options?: SignalOptionsIface & { agent?: string }) => Promise<ScheduleIface[]>;\n runNow: (args: ScheduleRef & SignalOptionsIface) => Promise<ScheduleRunResultIface>;\n update: (\n args: { scheduleId: string } & ScheduleUpdateIface & SignalOptionsIface,\n ) => Promise<ScheduleIface>;\n}\n\nexport const createSchedulesApi = ({ http }: ClientContextIface): SchedulesApiIface => {\n const list: SchedulesApiIface['list'] = async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: '/v1/schedules',\n query: { agent: options?.agent },\n response: scheduleListSchema,\n signal: options?.signal,\n })\n ).schedules;\n\n const scheduleIdOf = async (args: ScheduleRef & SignalOptionsIface): Promise<string> => {\n if ('scheduleId' in args) return args.scheduleId;\n const found = (await list({ agent: args.agent, signal: args.signal })).find(\n (schedule) => schedule.key === args.key,\n );\n if (found == null) {\n throw clientError({\n message: `No schedule ${args.key} on agent ${args.agent}`,\n status: 0,\n code: ClientErrorCode.NotFound,\n });\n }\n return found.id;\n };\n\n return {\n list,\n runNow: async (args) =>\n http.request({\n method: HttpMethod.Post,\n path: `/v1/schedules/${encodePath(await scheduleIdOf(args))}/run-now`,\n response: scheduleRunResultSchema,\n signal: args.signal,\n }),\n update: ({ scheduleId, signal, provide, ...value }) =>\n http.request({\n method: HttpMethod.Patch,\n path: `/v1/schedules/${encodePath(scheduleId)}`,\n body: {\n schema: updateScheduleRequestSchema,\n value: { ...value, ...(provide == null ? {} : { provide: provideDocumentOf(provide) }) },\n },\n response: scheduleSchema,\n signal,\n }),\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,kBAAoE;AAC7E,SAAS,aAAa,uBAAuB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,yBAA4C;AAqB9C,MAAM,qBAAqB,CAAC,EAAE,KAAK,MAA6C;AACrF,QAAM,OAAkC,OAAO,aAE3C,MAAM,KAAK,QAAQ;AAAA,IACjB,QAAQ,WAAW;AAAA,IACnB,MAAM;AAAA,IACN,OAAO,EAAE,OAAO,SAAS,MAAM;AAAA,IAC/B,UAAU;AAAA,IACV,QAAQ,SAAS;AAAA,EACnB,CAAC,GACD;AAEJ,QAAM,eAAe,OAAO,SAA4D;AACtF,QAAI,gBAAgB,KAAM,QAAO,KAAK;AACtC,UAAM,SAAS,MAAM,KAAK,EAAE,OAAO,KAAK,OAAO,QAAQ,KAAK,OAAO,CAAC,GAAG;AAAA,MACrE,CAAC,aAAa,SAAS,QAAQ,KAAK;AAAA,IACtC;AACA,QAAI,SAAS,MAAM;AACjB,YAAM,YAAY;AAAA,QAChB,SAAS,eAAe,KAAK,GAAG,aAAa,KAAK,KAAK;AAAA,QACvD,QAAQ;AAAA,QACR,MAAM,gBAAgB;AAAA,MACxB,CAAC;AAAA,IACH;AACA,WAAO,MAAM;AAAA,EACf;AAEA,SAAO;AAAA,IACL;AAAA,IACA,QAAQ,OAAO,SACb,KAAK,QAAQ;AAAA,MACX,QAAQ,WAAW;AAAA,MACnB,MAAM,iBAAiB,WAAW,MAAM,aAAa,IAAI,CAAC,CAAC;AAAA,MAC3D,UAAU;AAAA,MACV,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,IACH,QAAQ,CAAC,EAAE,YAAY,QAAQ,SAAS,GAAG,MAAM,MAC/C,KAAK,QAAQ;AAAA,MACX,QAAQ,WAAW;AAAA,MACnB,MAAM,iBAAiB,WAAW,UAAU,CAAC;AAAA,MAC7C,MAAM;AAAA,QACJ,QAAQ;AAAA,QACR,OAAO,EAAE,GAAG,OAAO,GAAI,WAAW,OAAO,CAAC,IAAI,EAAE,SAAS,kBAAkB,OAAO,EAAE,EAAG;AAAA,MACzF;AAAA,MACA,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACL;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { JsonObjectIface, JsonValue } from '@finalai/agent-protocol';
|
|
2
|
-
import { type AcpFrameEventIface, type AcpPreviewEventIface, type AgentSessionIface, type AgentTurnIface, type AgentTurnPolicy, type AttachmentDownloadIface, type ContentInput, type DecisionOutcomeInput, type DecisionRecordIface, type PromptAcceptedIface, type RespondDecisionResponseIface, type SessionFramesPageIface, type SessionManifestIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
|
+
import { type AcpFrameEventIface, type AcpPreviewEventIface, type ActorIface, type AgentSessionIface, type AgentTurnIface, type AgentTurnPolicy, type AttachmentDownloadIface, type ContentInput, type DecisionOutcomeInput, type DecisionRecordIface, type PromptAcceptedIface, type ProvideDocumentViewIface, type RequirementStatusIface, type RespondDecisionResponseIface, type SessionFramesPageIface, type SessionManifestIface, type SessionPlanIface } from '@finalai/agent-protocol/agent-platform';
|
|
3
|
+
import type { AgentInput } from "./agent-input.mjs";
|
|
3
4
|
import { type ClientContextIface, type EnumInput, type SignalOptionsIface } from "./context.mjs";
|
|
4
5
|
import { type SessionLiveEvent } from "./live-stream.mjs";
|
|
6
|
+
import type { ProvideIface } from "./provide.mjs";
|
|
7
|
+
import { type AgentStartDepsIface } from "./start.mjs";
|
|
5
8
|
/** Answer a decision by option id (permission) or with a full ACP outcome. */
|
|
6
9
|
export type RespondArgs = {
|
|
7
10
|
decisionId: string;
|
|
@@ -32,6 +35,8 @@ export interface TurnHandleIface<MessageId extends string | null = string> exten
|
|
|
32
35
|
get: (options?: SignalOptionsIface) => Promise<AgentTurnIface>;
|
|
33
36
|
stream: (options?: SignalOptionsIface) => AsyncIterableIterator<AcpFrameEventIface>;
|
|
34
37
|
result: (options?: SignalOptionsIface) => Promise<TurnResultIface<MessageId>>;
|
|
38
|
+
/** The turn's visible agent text, once it ends. */
|
|
39
|
+
text: (options?: SignalOptionsIface) => Promise<string>;
|
|
35
40
|
}
|
|
36
41
|
export interface SendOptionsIface extends SignalOptionsIface {
|
|
37
42
|
turnPolicy?: EnumInput<AgentTurnPolicy>;
|
|
@@ -48,7 +53,7 @@ export interface ForkSessionOptionsIface extends SignalOptionsIface {
|
|
|
48
53
|
/** An I/O-free handle on one session; every method is one HTTP call or one stream. */
|
|
49
54
|
export interface SessionHandleIface {
|
|
50
55
|
id: string;
|
|
51
|
-
/** Native fork of an idle source on its pinned
|
|
56
|
+
/** Native fork of an idle source on its pinned agent hash; the standalone child has fresh scopes. */
|
|
52
57
|
fork: (options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;
|
|
53
58
|
get: (options?: SignalOptionsIface) => Promise<AgentSessionIface>;
|
|
54
59
|
/** Resolves a `final-attachment:` resource link from this session's frames. */
|
|
@@ -92,14 +97,36 @@ export interface SessionHandleIface {
|
|
|
92
97
|
value: JsonValue;
|
|
93
98
|
}, options?: SignalOptionsIface) => Promise<void>;
|
|
94
99
|
close: (options?: SignalOptionsIface) => Promise<void>;
|
|
95
|
-
/**
|
|
100
|
+
/** The agent document the session pins and the provide document it was resolved with. */
|
|
96
101
|
manifest: (options?: SignalOptionsIface) => Promise<SessionManifestIface>;
|
|
102
|
+
/** Each of the agent's requirements and what provides it now. */
|
|
103
|
+
requirements: (options?: SignalOptionsIface) => Promise<RequirementStatusIface[]>;
|
|
104
|
+
/** What the session was provided; null before its first open. */
|
|
105
|
+
provide: (options?: SignalOptionsIface) => Promise<ProvideDocumentViewIface | null>;
|
|
106
|
+
/**
|
|
107
|
+
* The latest plan the agent reported, with its history (`GET …/plan`); null
|
|
108
|
+
* until it reports one. Each update raises `revision` and emits a
|
|
109
|
+
* `session.plan_updated` event.
|
|
110
|
+
*/
|
|
111
|
+
plan: (options?: SignalOptionsIface) => Promise<SessionPlanIface | null>;
|
|
97
112
|
}
|
|
98
113
|
export interface CreateSessionArgsIface extends SignalOptionsIface {
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
/**
|
|
115
|
+
* A session id you chose, so whatever you create for it first (a sandbox it
|
|
116
|
+
* owns) can name it. Creating with an id that exists returns that session.
|
|
117
|
+
*/
|
|
118
|
+
id?: string;
|
|
119
|
+
/** The agent you defined, or one fetched with `project.agents.get`; never a string. */
|
|
120
|
+
agent: AgentInput;
|
|
121
|
+
/**
|
|
122
|
+
* What the agent requires. Files and shell left out run in this process
|
|
123
|
+
* unless the client was created with `localCompute: false`.
|
|
124
|
+
*/
|
|
125
|
+
provide: ProvideIface;
|
|
126
|
+
/** Your app's end user the first turn acts for. */
|
|
127
|
+
actor?: Omit<ActorIface, 'displayName'> & {
|
|
128
|
+
displayName?: string;
|
|
129
|
+
};
|
|
103
130
|
message?: ContentInput;
|
|
104
131
|
turnPolicy?: EnumInput<AgentTurnPolicy>;
|
|
105
132
|
idempotencyKey?: string;
|
|
@@ -115,7 +142,6 @@ export interface CreatedSessionIface {
|
|
|
115
142
|
response: TurnHandleIface | null;
|
|
116
143
|
}
|
|
117
144
|
export interface SessionsApiIface {
|
|
118
|
-
create: (args: CreateSessionArgsIface) => Promise<CreatedSessionIface>;
|
|
119
145
|
fork: (sessionId: string, options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;
|
|
120
146
|
get: (sessionId: string, options?: SignalOptionsIface) => Promise<AgentSessionIface>;
|
|
121
147
|
attach: (sessionId: string) => SessionHandleIface;
|
|
@@ -123,3 +149,15 @@ export interface SessionsApiIface {
|
|
|
123
149
|
export declare const outcomeOf: (args: RespondArgs) => DecisionOutcomeInput;
|
|
124
150
|
export declare const createSessionHandle: (context: ClientContextIface, sessionId: string) => SessionHandleIface;
|
|
125
151
|
export declare const createSessionsApi: (context: ClientContextIface) => SessionsApiIface;
|
|
152
|
+
export interface ProjectSessionsApiIface extends SessionsApiIface {
|
|
153
|
+
/**
|
|
154
|
+
* Starts a session. Fails with `requirements_unmet`, creating nothing, unless
|
|
155
|
+
* every requirement the agent does not mark optional is provided.
|
|
156
|
+
*/
|
|
157
|
+
create: (args: CreateSessionArgsIface) => Promise<CreatedSessionIface>;
|
|
158
|
+
}
|
|
159
|
+
export declare const createProjectSessionsApi: (args: {
|
|
160
|
+
context: ClientContextIface;
|
|
161
|
+
projectId: string;
|
|
162
|
+
start: AgentStartDepsIface;
|
|
163
|
+
}) => ProjectSessionsApiIface;
|
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
respondDecisionSchema,
|
|
21
21
|
sessionFramesPageSchema,
|
|
22
22
|
sessionManifestSchema,
|
|
23
|
+
sessionPlanResponseSchema,
|
|
24
|
+
sessionRequirementsSchema,
|
|
23
25
|
sessionSchema,
|
|
24
26
|
setConfigOptionRequestSchema,
|
|
25
27
|
turnSchema
|
|
@@ -34,6 +36,8 @@ import { streamServerSentEvents } from "./event-stream.mjs";
|
|
|
34
36
|
import { streamSessionFrames } from "./frame-stream.mjs";
|
|
35
37
|
import { HttpMethod } from "./http.mjs";
|
|
36
38
|
import { streamSessionLiveEvents } from "./live-stream.mjs";
|
|
39
|
+
import { LocalHostOwnerKind } from "./local-host-protocol.mjs";
|
|
40
|
+
import { serveCodeFor, startAgent } from "./start.mjs";
|
|
37
41
|
const outcomeOf = (args) => "optionId" in args ? { outcome: "selected", optionId: args.optionId } : args.outcome;
|
|
38
42
|
const sessionPath = (sessionId, suffix = "") => `/v1/sessions/${encodePath(sessionId)}${suffix}`;
|
|
39
43
|
const turnHandle = (args) => {
|
|
@@ -94,7 +98,14 @@ const turnHandle = (args) => {
|
|
|
94
98
|
toSeq: receipt.toSeq ?? last?.seq ?? accepted.fromSeq ?? 0
|
|
95
99
|
};
|
|
96
100
|
};
|
|
97
|
-
return {
|
|
101
|
+
return {
|
|
102
|
+
...accepted,
|
|
103
|
+
sessionId,
|
|
104
|
+
get,
|
|
105
|
+
stream,
|
|
106
|
+
result,
|
|
107
|
+
text: async (options) => (await result(options)).text
|
|
108
|
+
};
|
|
98
109
|
};
|
|
99
110
|
const getTurn = (args) => args.context.http.request({
|
|
100
111
|
method: HttpMethod.Get,
|
|
@@ -227,6 +238,18 @@ const createSessionHandle = (context, sessionId) => {
|
|
|
227
238
|
response: sessionManifestSchema,
|
|
228
239
|
signal: options?.signal
|
|
229
240
|
}),
|
|
241
|
+
requirements: async (options) => (await http.request({
|
|
242
|
+
method: HttpMethod.Get,
|
|
243
|
+
path: sessionPath(sessionId, "/requirements"),
|
|
244
|
+
response: sessionRequirementsSchema,
|
|
245
|
+
signal: options?.signal
|
|
246
|
+
})).requirements,
|
|
247
|
+
provide: async (options) => (await http.request({
|
|
248
|
+
method: HttpMethod.Get,
|
|
249
|
+
path: sessionPath(sessionId, "/manifest"),
|
|
250
|
+
response: sessionManifestSchema,
|
|
251
|
+
signal: options?.signal
|
|
252
|
+
})).provide,
|
|
230
253
|
send: async (content, options) => {
|
|
231
254
|
const accepted = await http.request({
|
|
232
255
|
method: HttpMethod.Post,
|
|
@@ -307,42 +330,81 @@ const createSessionHandle = (context, sessionId) => {
|
|
|
307
330
|
body: { schema: setConfigOptionRequestSchema, value: args },
|
|
308
331
|
signal: options?.signal
|
|
309
332
|
}),
|
|
310
|
-
close: (options) => post({ suffix: "/close", signal: options?.signal })
|
|
333
|
+
close: (options) => post({ suffix: "/close", signal: options?.signal }),
|
|
334
|
+
plan: async (options) => (await http.request({
|
|
335
|
+
method: HttpMethod.Get,
|
|
336
|
+
path: sessionPath(sessionId, "/plan"),
|
|
337
|
+
response: sessionPlanResponseSchema,
|
|
338
|
+
signal: options?.signal
|
|
339
|
+
})).plan
|
|
311
340
|
};
|
|
312
341
|
};
|
|
313
342
|
const createSessionsApi = (context) => ({
|
|
314
|
-
create: async (args) => {
|
|
315
|
-
const created = await context.http.request({
|
|
316
|
-
method: HttpMethod.Post,
|
|
317
|
-
path: "/v1/sessions",
|
|
318
|
-
body: {
|
|
319
|
-
schema: createSessionRequestSchema,
|
|
320
|
-
value: {
|
|
321
|
-
agent: args.agent,
|
|
322
|
-
revisionId: args.revisionId,
|
|
323
|
-
message: args.message,
|
|
324
|
-
turnPolicy: args.turnPolicy,
|
|
325
|
-
idempotencyKey: args.idempotencyKey ?? (args.message == null ? void 0 : context.newKey()),
|
|
326
|
-
title: args.title,
|
|
327
|
-
meta: args.meta,
|
|
328
|
-
clientSubmittedAtMs: args.message == null ? void 0 : args.clientSubmittedAtMs ?? context.now()
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
response: createSessionResponseSchema,
|
|
332
|
-
signal: args.signal
|
|
333
|
-
});
|
|
334
|
-
const handle = createSessionHandle(context, created.session.id);
|
|
335
|
-
return {
|
|
336
|
-
session: created.session,
|
|
337
|
-
handle,
|
|
338
|
-
response: created.turn == null ? null : turnHandle({ context, sessionId: created.session.id, accepted: created.turn })
|
|
339
|
-
};
|
|
340
|
-
},
|
|
341
343
|
fork: (sessionId, options) => createSessionHandle(context, sessionId).fork(options),
|
|
342
344
|
get: (sessionId, options) => createSessionHandle(context, sessionId).get(options),
|
|
343
345
|
attach: (sessionId) => createSessionHandle(context, sessionId)
|
|
344
346
|
});
|
|
347
|
+
const createProjectSessionsApi = (args) => {
|
|
348
|
+
const { context } = args;
|
|
349
|
+
return {
|
|
350
|
+
...createSessionsApi(context),
|
|
351
|
+
create: async (create) => {
|
|
352
|
+
const started = await startAgent(args.start, {
|
|
353
|
+
projectId: args.projectId,
|
|
354
|
+
agent: create.agent,
|
|
355
|
+
provide: create.provide,
|
|
356
|
+
owner: { kind: LocalHostOwnerKind.Session, id: create.id },
|
|
357
|
+
signal: create.signal
|
|
358
|
+
});
|
|
359
|
+
try {
|
|
360
|
+
const created = await context.http.request({
|
|
361
|
+
method: HttpMethod.Post,
|
|
362
|
+
path: "/v1/sessions",
|
|
363
|
+
body: {
|
|
364
|
+
schema: createSessionRequestSchema,
|
|
365
|
+
value: {
|
|
366
|
+
id: started.ownerId ?? create.id,
|
|
367
|
+
projectId: args.projectId,
|
|
368
|
+
agent: started.ref,
|
|
369
|
+
provide: started.provide,
|
|
370
|
+
actor: create.actor,
|
|
371
|
+
message: create.message,
|
|
372
|
+
turnPolicy: create.turnPolicy,
|
|
373
|
+
idempotencyKey: create.idempotencyKey ?? (create.message == null ? void 0 : context.newKey()),
|
|
374
|
+
title: create.title,
|
|
375
|
+
meta: create.meta,
|
|
376
|
+
clientSubmittedAtMs: create.message == null ? void 0 : create.clientSubmittedAtMs ?? context.now()
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
response: createSessionResponseSchema,
|
|
380
|
+
signal: create.signal
|
|
381
|
+
});
|
|
382
|
+
const reserved = started.ownerId ?? create.id;
|
|
383
|
+
if (reserved != null && created.session.id !== reserved) {
|
|
384
|
+
started.abandon();
|
|
385
|
+
if (started.host != null)
|
|
386
|
+
await serveCodeFor(args.start, {
|
|
387
|
+
projectId: args.projectId,
|
|
388
|
+
agent: create.agent,
|
|
389
|
+
owner: { kind: LocalHostOwnerKind.Session, id: created.session.id },
|
|
390
|
+
signal: create.signal
|
|
391
|
+
});
|
|
392
|
+
} else started.established();
|
|
393
|
+
const handle = createSessionHandle(context, created.session.id);
|
|
394
|
+
return {
|
|
395
|
+
session: created.session,
|
|
396
|
+
handle,
|
|
397
|
+
response: created.turn == null ? null : turnHandle({ context, sessionId: created.session.id, accepted: created.turn })
|
|
398
|
+
};
|
|
399
|
+
} catch (cause) {
|
|
400
|
+
started.abandon();
|
|
401
|
+
throw cause;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
};
|
|
345
406
|
export {
|
|
407
|
+
createProjectSessionsApi,
|
|
346
408
|
createSessionHandle,
|
|
347
409
|
createSessionsApi,
|
|
348
410
|
outcomeOf
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/sessions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { JsonObjectIface, JsonValue } from '@finalai/agent-protocol';\nimport {\n acpFrameEventSchema,\n acpPreviewEventSchema,\n agentRealtimeFrameSchema,\n AgentRealtimeFrameType,\n AgentRealtimeKind,\n agentRealtimeTopics,\n attachmentDownloadSchema,\n cancelRequestSchema,\n createSessionRequestSchema,\n createSessionResponseSchema,\n FIRST_ACP_FRAME_SEQ,\n forkSessionRequestSchema,\n observeSessionRequestSchema,\n decisionRecordListSchema,\n okResponseSchema,\n promptAcceptedSchema,\n promptSessionRequestSchema,\n respondDecisionResponseSchema,\n respondDecisionSchema,\n sessionFramesPageSchema,\n sessionManifestSchema,\n sessionSchema,\n setConfigOptionRequestSchema,\n turnSchema,\n type AcpFrameEventIface,\n type AcpPreviewEventIface,\n type AgentSessionIface,\n type AgentTurnIface,\n type AgentTurnPolicy,\n type AttachmentDownloadIface,\n type ContentInput,\n type DecisionOutcomeInput,\n type DecisionRecordIface,\n type PromptAcceptedIface,\n type RespondDecisionResponseIface,\n type SessionFramesPageIface,\n type SessionManifestIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createTextCollector, isUserMessageFor, turnEndOf } from \"./acp-frames.mjs\";\nimport { createAsyncQueue, failOnAbort } from \"./async-queue.mjs\";\nimport {\n encodePath,\n type ClientContextIface,\n type EnumInput,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { isTerminalRealtimeError, realtimeSubscriptionError } from \"./errors.mjs\";\nimport { streamServerSentEvents } from \"./event-stream.mjs\";\nimport { streamSessionFrames } from \"./frame-stream.mjs\";\nimport { HttpMethod, type HttpBodyIface } from \"./http.mjs\";\nimport { streamSessionLiveEvents, type SessionLiveEvent } from \"./live-stream.mjs\";\nimport type { RealtimeTransportFrameIface } from \"./realtime.mjs\";\n\n/** Answer a decision by option id (permission) or with a full ACP outcome. */\nexport type RespondArgs =\n | { decisionId: string; optionId: string }\n | { decisionId: string; outcome: DecisionOutcomeInput };\n\nexport interface StreamOptionsIface extends SignalOptionsIface {\n /** Inclusive; defaults to `FIRST_ACP_FRAME_SEQ` (the whole log). Earlier values are clamped. */\n fromSeq?: number;\n /** Keep streaming live frames after replay catches up; defaults to true. */\n follow?: boolean;\n}\n\nexport interface TurnResultIface<MessageId extends string | null = string> {\n messageId: MessageId;\n turnId: string;\n stopReason: string | null;\n /** Visible agent text of the turn. */\n text: string;\n /** Seq of the frame that ended the turn. */\n toSeq: number;\n}\n\n/** An accepted prompt. `stream()` yields this turn's frames; `result()` waits for its end. */\nexport interface TurnHandleIface<MessageId extends string | null = string> extends Omit<\n PromptAcceptedIface,\n 'messageId'\n> {\n messageId: MessageId;\n sessionId: string;\n get: (options?: SignalOptionsIface) => Promise<AgentTurnIface>;\n stream: (options?: SignalOptionsIface) => AsyncIterableIterator<AcpFrameEventIface>;\n result: (options?: SignalOptionsIface) => Promise<TurnResultIface<MessageId>>;\n}\n\nexport interface SendOptionsIface extends SignalOptionsIface {\n turnPolicy?: EnumInput<AgentTurnPolicy>;\n idempotencyKey?: string;\n meta?: JsonObjectIface;\n /** When the person submitted, for the prompt-to-inference trace; defaults to now. */\n clientSubmittedAtMs?: number;\n}\n\nexport interface ForkSessionOptionsIface extends SignalOptionsIface {\n /** Retain this key when retrying an interrupted fork. Defaults to a new key. */\n idempotencyKey?: string;\n title?: string;\n}\n\n/** An I/O-free handle on one session; every method is one HTTP call or one stream. */\nexport interface SessionHandleIface {\n id: string;\n /** Native fork of an idle source on its pinned revision; the standalone child has fresh scopes. */\n fork: (options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;\n get: (options?: SignalOptionsIface) => Promise<AgentSessionIface>;\n /** Resolves a `final-attachment:` resource link from this session's frames. */\n attachment: (\n attachmentId: string,\n options?: SignalOptionsIface,\n ) => Promise<AttachmentDownloadIface>;\n send: (content: ContentInput, options?: SendOptionsIface) => Promise<TurnHandleIface>;\n /** Adds content to history without a model call (`_final/session/observe`). */\n observe: (\n content: ContentInput,\n options?: SignalOptionsIface & { idempotencyKey?: string; meta?: JsonObjectIface },\n ) => Promise<void>;\n stream: (options?: StreamOptionsIface) => AsyncIterableIterator<AcpFrameEventIface>;\n /** Full provisional frames and reset notices; never a durable replay cursor or receipt. */\n liveEvents: (options?: SignalOptionsIface) => AsyncIterableIterator<SessionLiveEvent>;\n /**\n * `acp.preview` events: the text of message and thought chunks as the session\n * publishes them, live only (never replayed), for surfaces that render text\n * ahead of the durable frames and the conversation's projected messages.\n */\n previews: (options?: SignalOptionsIface) => AsyncIterableIterator<AcpPreviewEventIface>;\n /** One replay page (`GET /sessions/:id/frames`). */\n frames: (\n options: SignalOptionsIface & { fromSeq: number; limit?: number },\n ) => Promise<SessionFramesPageIface>;\n /** The session's open decisions (`GET /sessions/:id/decisions`). */\n decisions: (options?: SignalOptionsIface) => Promise<DecisionRecordIface[]>;\n turn: (turnId: string, options?: SignalOptionsIface) => Promise<AgentTurnIface>;\n /** Reconstruct an accepted response from its durable turn id, without resending its prompt. */\n response: (\n turnId: string,\n options?: SignalOptionsIface,\n ) => Promise<TurnHandleIface<string | null>>;\n respond: (\n args: RespondArgs,\n options?: SignalOptionsIface,\n ) => Promise<RespondDecisionResponseIface>;\n cancel: (options?: SignalOptionsIface & { reason?: string }) => Promise<void>;\n /**\n * ACP `session/set_config_option` (model, reasoning, mode, ...): `configId` and a value\n * from the options the harness advertises (`get().configOptions`, `configSelectsOf`).\n * Changing them takes the session's owner, or a conversation owner or admin.\n */\n setConfigOption: (\n args: { configId: string; value: JsonValue },\n options?: SignalOptionsIface,\n ) => Promise<void>;\n close: (options?: SignalOptionsIface) => Promise<void>;\n /** Resolved manifest and resolver report; secret-bearing output requires agents:read and admin secret-binding access. */\n manifest: (options?: SignalOptionsIface) => Promise<SessionManifestIface>;\n}\n\nexport interface CreateSessionArgsIface extends SignalOptionsIface {\n /** Agent slug or id. */\n agent: string;\n /** Pin an author test session to a revision returned by definitions.testRevision. */\n revisionId?: string;\n message?: ContentInput;\n turnPolicy?: EnumInput<AgentTurnPolicy>;\n idempotencyKey?: string;\n title?: string;\n meta?: JsonObjectIface;\n /** When the person submitted `message`; defaults to now. */\n clientSubmittedAtMs?: number;\n}\n\nexport interface CreatedSessionIface {\n session: AgentSessionIface;\n handle: SessionHandleIface;\n /** The first turn when `message` was given. */\n response: TurnHandleIface | null;\n}\n\nexport interface SessionsApiIface {\n create: (args: CreateSessionArgsIface) => Promise<CreatedSessionIface>;\n fork: (sessionId: string, options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;\n get: (sessionId: string, options?: SignalOptionsIface) => Promise<AgentSessionIface>;\n attach: (sessionId: string) => SessionHandleIface;\n}\n\nexport const outcomeOf = (args: RespondArgs): DecisionOutcomeInput =>\n 'optionId' in args ? { outcome: 'selected', optionId: args.optionId } : args.outcome;\n\nconst sessionPath = (sessionId: string, suffix = ''): string =>\n `/v1/sessions/${encodePath(sessionId)}${suffix}`;\n\ninterface TurnHandleArgsIface<MessageId extends string | null> {\n context: ClientContextIface;\n sessionId: string;\n accepted: Omit<PromptAcceptedIface, 'messageId'> & { messageId: MessageId };\n}\n\nconst turnHandle = <MessageId extends string | null>(\n args: TurnHandleArgsIface<MessageId>,\n): TurnHandleIface<MessageId> => {\n const { context, sessionId, accepted } = args;\n const get = (options?: SignalOptionsIface) =>\n getTurn({ context, sessionId, turnId: accepted.turnId, signal: options?.signal });\n const stream = (options?: SignalOptionsIface): AsyncIterableIterator<AcpFrameEventIface> => {\n // Without the prompt's seq, scan from the start for ACP's user message with this id.\n // `until` runs as frames are queued and `next` as they are consumed, so each tracks its own start.\n let queuedStart = accepted.messageId == null && accepted.fromSeq != null;\n let started = queuedStart;\n const frames = streamSessionFrames({\n sessionId,\n fromSeq: accepted.fromSeq ?? FIRST_ACP_FRAME_SEQ,\n follow: true,\n ...frameSources({ context, sessionId }),\n transport: context.realtime(),\n timing: context.timing,\n signal: options?.signal,\n closeSignal: context.closeSignal,\n terminal: async (signal) => {\n const receipt = await get({ signal });\n return receipt.endedAt == null ? null : { throughSeq: receipt.toSeq ?? 0 };\n },\n until: (event) => {\n if (\n !queuedStart &&\n accepted.messageId != null &&\n isUserMessageFor(event, accepted.messageId)\n )\n queuedStart = true;\n return queuedStart && turnEndOf(event) != null;\n },\n });\n const iterator: AsyncIterableIterator<AcpFrameEventIface> = {\n next: async () => {\n for (;;) {\n const next = await frames.next();\n if (next.done === true || started) return next;\n if (accepted.messageId != null && isUserMessageFor(next.value, accepted.messageId)) {\n started = true;\n return next;\n }\n }\n },\n return: () => frames.return?.() ?? Promise.resolve({ done: true, value: undefined }),\n [Symbol.asyncIterator]: () => iterator,\n };\n return iterator;\n };\n\n const result = async (options?: SignalOptionsIface): Promise<TurnResultIface<MessageId>> => {\n const text = createTextCollector();\n let last: AcpFrameEventIface | null = null;\n for await (const event of stream(options)) {\n text.add(event);\n last = event;\n }\n const end = last == null ? null : turnEndOf(last);\n const receipt = await get(options);\n return {\n messageId: accepted.messageId,\n turnId: accepted.turnId,\n stopReason: receipt.stopReason ?? end?.stopReason ?? null,\n text: text.text(),\n toSeq: receipt.toSeq ?? last?.seq ?? accepted.fromSeq ?? 0,\n };\n };\n\n return { ...accepted, sessionId, get, stream, result };\n};\n\nconst getTurn = (args: {\n context: ClientContextIface;\n sessionId: string;\n turnId: string;\n signal?: AbortSignal;\n}): Promise<AgentTurnIface> =>\n args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, `/turns/${encodePath(args.turnId)}`),\n response: turnSchema,\n signal: args.signal,\n });\n\ninterface ReplayArgsIface extends SignalOptionsIface {\n context: ClientContextIface;\n sessionId: string;\n fromSeq: number;\n limit?: number;\n}\n\nconst replay = (args: ReplayArgsIface): Promise<SessionFramesPageIface> =>\n args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, '/frames'),\n query: { fromSeq: args.fromSeq, limit: args.limit },\n response: sessionFramesPageSchema,\n signal: args.signal,\n });\n\nconst openDecisions = async (args: {\n context: ClientContextIface;\n sessionId: string;\n signal?: AbortSignal;\n}): Promise<DecisionRecordIface[]> =>\n (\n await args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, '/decisions'),\n response: decisionRecordListSchema,\n signal: args.signal,\n })\n ).decisions;\n\n/** The session's frames over Streamable HTTP (`GET /sessions/:id/frames/stream`), from `fromSeq`. */\nasync function* streamFramesOverHttp(args: {\n context: ClientContextIface;\n sessionId: string;\n fromSeq: number;\n signal: AbortSignal;\n}): AsyncGenerator<AcpFrameEventIface> {\n for await (const message of streamServerSentEvents({\n http: args.context.http,\n path: sessionPath(args.sessionId, '/frames/stream'),\n query: { fromSeq: args.fromSeq },\n signal: AbortSignal.any([args.signal, args.context.closeSignal]),\n })) {\n if (message.event !== AgentRealtimeKind.AcpFrame) continue;\n try {\n const event = acpFrameEventSchema.safeParse(JSON.parse(message.data));\n if (event.success) yield event.data;\n } catch {\n // A malformed event is skipped; replay fills any gap it leaves.\n }\n }\n}\n\n/** Live `acp.preview` events of the session topic. */\nconst streamPreviews = (args: {\n context: ClientContextIface;\n sessionId: string;\n signal?: AbortSignal;\n}): AsyncIterableIterator<AcpPreviewEventIface> => {\n const topic = agentRealtimeTopics.session(args.sessionId);\n let unsubscribe: (() => void) | null = null;\n let detachAbort: () => void = () => {};\n let detachClose: () => void = () => {};\n const queue = createAsyncQueue<AcpPreviewEventIface>(() => {\n unsubscribe?.();\n detachAbort();\n detachClose();\n });\n const onFrame = (raw: RealtimeTransportFrameIface): void => {\n const frame = agentRealtimeFrameSchema.safeParse(raw);\n if (!frame.success) return;\n if (frame.data.type === AgentRealtimeFrameType.Error && isTerminalRealtimeError(frame.data)) {\n queue.fail(\n realtimeSubscriptionError({\n topic: frame.data.topic ?? topic,\n code: frame.data.code ?? 'unknown',\n message: frame.data.message ?? 'Realtime subscription was refused',\n }),\n );\n return;\n }\n if (frame.data.type !== AgentRealtimeFrameType.Event) return;\n if (frame.data.kind !== AgentRealtimeKind.AcpPreview) return;\n const preview = acpPreviewEventSchema.safeParse(frame.data.payload);\n if (preview.success) queue.push(preview.data);\n };\n detachAbort = failOnAbort(queue, args.signal);\n detachClose = failOnAbort(queue, args.context.closeSignal);\n if (!queue.closed()) {\n const stop = args.context.realtime().subscribe(topic, onFrame);\n if (queue.closed()) stop();\n else unsubscribe = stop;\n }\n return queue.iterator;\n};\n\n/** Replay, open decisions and the Streamable HTTP fallback of one session's frame stream. */\nconst frameSources = (args: { context: ClientContextIface; sessionId: string }) => ({\n replay: (page: { fromSeq: number; limit: number; signal?: AbortSignal }) =>\n replay({ context: args.context, sessionId: args.sessionId, ...page }),\n decisions: (signal?: AbortSignal) => openDecisions({ ...args, signal }),\n httpStream: (stream: { fromSeq: number; signal: AbortSignal }) =>\n streamFramesOverHttp({ ...args, ...stream }),\n});\n\nexport const createSessionHandle = (\n context: ClientContextIface,\n sessionId: string,\n): SessionHandleIface => {\n const { http } = context;\n const post = async (args: {\n suffix: string;\n body?: HttpBodyIface;\n signal?: AbortSignal;\n }): Promise<void> => {\n await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, args.suffix),\n body: args.body,\n response: okResponseSchema,\n signal: args.signal,\n context: { sessionId },\n });\n };\n\n return {\n id: sessionId,\n fork: async (options) => {\n const created = await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/fork'),\n body: {\n schema: forkSessionRequestSchema,\n value: {\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n title: options?.title,\n },\n },\n response: createSessionResponseSchema,\n signal: options?.signal,\n context: { sessionId },\n });\n return {\n session: created.session,\n handle: createSessionHandle(context, created.session.id),\n response: null,\n };\n },\n attachment: (attachmentId, options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, `/attachments/${encodePath(attachmentId)}`),\n response: attachmentDownloadSchema,\n signal: options?.signal,\n }),\n get: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId),\n response: sessionSchema,\n signal: options?.signal,\n }),\n manifest: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, '/manifest'),\n response: sessionManifestSchema,\n signal: options?.signal,\n }),\n send: async (content, options) => {\n const accepted = await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/prompt'),\n body: {\n schema: promptSessionRequestSchema,\n value: {\n content,\n turnPolicy: options?.turnPolicy,\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n meta: options?.meta,\n clientSubmittedAtMs: options?.clientSubmittedAtMs ?? context.now(),\n },\n },\n response: promptAcceptedSchema,\n signal: options?.signal,\n context: { sessionId },\n });\n return turnHandle({ context, sessionId, accepted });\n },\n observe: (content, options) =>\n post({\n suffix: '/observe',\n body: {\n schema: observeSessionRequestSchema,\n value: {\n content,\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n meta: options?.meta,\n },\n },\n signal: options?.signal,\n }),\n stream: (options) =>\n streamSessionFrames({\n sessionId,\n fromSeq: options?.fromSeq ?? FIRST_ACP_FRAME_SEQ,\n follow: options?.follow ?? true,\n ...frameSources({ context, sessionId }),\n transport: context.realtime(),\n timing: context.timing,\n signal: options?.signal,\n closeSignal: context.closeSignal,\n }),\n liveEvents: (options) =>\n streamSessionLiveEvents({ context, sessionId, signal: options?.signal }),\n previews: (options) => streamPreviews({ context, sessionId, signal: options?.signal }),\n frames: (options) => replay({ context, sessionId, ...options }),\n decisions: (options) => openDecisions({ context, sessionId, signal: options?.signal }),\n turn: (turnId, options) => getTurn({ context, sessionId, turnId, signal: options?.signal }),\n response: async (turnId, options) => {\n const receipt = await getTurn({ context, sessionId, turnId, signal: options?.signal });\n return turnHandle({\n context,\n sessionId,\n accepted: {\n turnId: receipt.id,\n messageId: receipt.promptMessageId,\n fromSeq: receipt.fromSeq,\n },\n });\n },\n respond: (args, options) =>\n http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/respond'),\n body: {\n schema: respondDecisionSchema,\n value: { decisionId: args.decisionId, outcome: outcomeOf(args) },\n },\n response: respondDecisionResponseSchema,\n signal: options?.signal,\n context: { sessionId, decisionId: args.decisionId },\n }),\n cancel: (options) =>\n post({\n suffix: '/cancel',\n body: { schema: cancelRequestSchema, value: { reason: options?.reason } },\n signal: options?.signal,\n }),\n setConfigOption: (args, options) =>\n post({\n suffix: '/config-option',\n body: { schema: setConfigOptionRequestSchema, value: args },\n signal: options?.signal,\n }),\n close: (options) => post({ suffix: '/close', signal: options?.signal }),\n };\n};\n\nexport const createSessionsApi = (context: ClientContextIface): SessionsApiIface => ({\n create: async (args) => {\n const created = await context.http.request({\n method: HttpMethod.Post,\n path: '/v1/sessions',\n body: {\n schema: createSessionRequestSchema,\n value: {\n agent: args.agent,\n revisionId: args.revisionId,\n message: args.message,\n turnPolicy: args.turnPolicy,\n idempotencyKey:\n args.idempotencyKey ?? (args.message == null ? undefined : context.newKey()),\n title: args.title,\n meta: args.meta,\n clientSubmittedAtMs:\n args.message == null ? undefined : (args.clientSubmittedAtMs ?? context.now()),\n },\n },\n response: createSessionResponseSchema,\n signal: args.signal,\n });\n const handle = createSessionHandle(context, created.session.id);\n return {\n session: created.session,\n handle,\n response:\n created.turn == null\n ? null\n : turnHandle({ context, sessionId: created.session.id, accepted: created.turn }),\n };\n },\n fork: (sessionId, options) => createSessionHandle(context, sessionId).fork(options),\n get: (sessionId, options) => createSessionHandle(context, sessionId).get(options),\n attach: (sessionId) => createSessionHandle(context, sessionId),\n});\n"],
|
|
5
|
-
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import type { JsonObjectIface, JsonValue } from '@finalai/agent-protocol';\nimport {\n acpFrameEventSchema,\n acpPreviewEventSchema,\n agentRealtimeFrameSchema,\n AgentRealtimeFrameType,\n AgentRealtimeKind,\n agentRealtimeTopics,\n attachmentDownloadSchema,\n cancelRequestSchema,\n createSessionRequestSchema,\n createSessionResponseSchema,\n FIRST_ACP_FRAME_SEQ,\n forkSessionRequestSchema,\n observeSessionRequestSchema,\n decisionRecordListSchema,\n okResponseSchema,\n promptAcceptedSchema,\n promptSessionRequestSchema,\n respondDecisionResponseSchema,\n respondDecisionSchema,\n sessionFramesPageSchema,\n sessionManifestSchema,\n sessionPlanResponseSchema,\n sessionRequirementsSchema,\n sessionSchema,\n setConfigOptionRequestSchema,\n turnSchema,\n type AcpFrameEventIface,\n type AcpPreviewEventIface,\n type ActorIface,\n type AgentSessionIface,\n type AgentTurnIface,\n type AgentTurnPolicy,\n type AttachmentDownloadIface,\n type ContentInput,\n type DecisionOutcomeInput,\n type DecisionRecordIface,\n type PromptAcceptedIface,\n type ProvideDocumentViewIface,\n type RequirementStatusIface,\n type RespondDecisionResponseIface,\n type SessionFramesPageIface,\n type SessionManifestIface,\n type SessionPlanIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createTextCollector, isUserMessageFor, turnEndOf } from \"./acp-frames.mjs\";\nimport type { AgentInput } from \"./agent-input.mjs\";\nimport { createAsyncQueue, failOnAbort } from \"./async-queue.mjs\";\nimport {\n encodePath,\n type ClientContextIface,\n type EnumInput,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { isTerminalRealtimeError, realtimeSubscriptionError } from \"./errors.mjs\";\nimport { streamServerSentEvents } from \"./event-stream.mjs\";\nimport { streamSessionFrames } from \"./frame-stream.mjs\";\nimport { HttpMethod, type HttpBodyIface } from \"./http.mjs\";\nimport { streamSessionLiveEvents, type SessionLiveEvent } from \"./live-stream.mjs\";\nimport { LocalHostOwnerKind } from \"./local-host-protocol.mjs\";\nimport type { ProvideIface } from \"./provide.mjs\";\nimport type { RealtimeTransportFrameIface } from \"./realtime.mjs\";\nimport { serveCodeFor, startAgent, type AgentStartDepsIface } from \"./start.mjs\";\n\n/** Answer a decision by option id (permission) or with a full ACP outcome. */\nexport type RespondArgs =\n | { decisionId: string; optionId: string }\n | { decisionId: string; outcome: DecisionOutcomeInput };\n\nexport interface StreamOptionsIface extends SignalOptionsIface {\n /** Inclusive; defaults to `FIRST_ACP_FRAME_SEQ` (the whole log). Earlier values are clamped. */\n fromSeq?: number;\n /** Keep streaming live frames after replay catches up; defaults to true. */\n follow?: boolean;\n}\n\nexport interface TurnResultIface<MessageId extends string | null = string> {\n messageId: MessageId;\n turnId: string;\n stopReason: string | null;\n /** Visible agent text of the turn. */\n text: string;\n /** Seq of the frame that ended the turn. */\n toSeq: number;\n}\n\n/** An accepted prompt. `stream()` yields this turn's frames; `result()` waits for its end. */\nexport interface TurnHandleIface<MessageId extends string | null = string> extends Omit<\n PromptAcceptedIface,\n 'messageId'\n> {\n messageId: MessageId;\n sessionId: string;\n get: (options?: SignalOptionsIface) => Promise<AgentTurnIface>;\n stream: (options?: SignalOptionsIface) => AsyncIterableIterator<AcpFrameEventIface>;\n result: (options?: SignalOptionsIface) => Promise<TurnResultIface<MessageId>>;\n /** The turn's visible agent text, once it ends. */\n text: (options?: SignalOptionsIface) => Promise<string>;\n}\n\nexport interface SendOptionsIface extends SignalOptionsIface {\n turnPolicy?: EnumInput<AgentTurnPolicy>;\n idempotencyKey?: string;\n meta?: JsonObjectIface;\n /** When the person submitted, for the prompt-to-inference trace; defaults to now. */\n clientSubmittedAtMs?: number;\n}\n\nexport interface ForkSessionOptionsIface extends SignalOptionsIface {\n /** Retain this key when retrying an interrupted fork. Defaults to a new key. */\n idempotencyKey?: string;\n title?: string;\n}\n\n/** An I/O-free handle on one session; every method is one HTTP call or one stream. */\nexport interface SessionHandleIface {\n id: string;\n /** Native fork of an idle source on its pinned agent hash; the standalone child has fresh scopes. */\n fork: (options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;\n get: (options?: SignalOptionsIface) => Promise<AgentSessionIface>;\n /** Resolves a `final-attachment:` resource link from this session's frames. */\n attachment: (\n attachmentId: string,\n options?: SignalOptionsIface,\n ) => Promise<AttachmentDownloadIface>;\n send: (content: ContentInput, options?: SendOptionsIface) => Promise<TurnHandleIface>;\n /** Adds content to history without a model call (`_final/session/observe`). */\n observe: (\n content: ContentInput,\n options?: SignalOptionsIface & { idempotencyKey?: string; meta?: JsonObjectIface },\n ) => Promise<void>;\n stream: (options?: StreamOptionsIface) => AsyncIterableIterator<AcpFrameEventIface>;\n /** Full provisional frames and reset notices; never a durable replay cursor or receipt. */\n liveEvents: (options?: SignalOptionsIface) => AsyncIterableIterator<SessionLiveEvent>;\n /**\n * `acp.preview` events: the text of message and thought chunks as the session\n * publishes them, live only (never replayed), for surfaces that render text\n * ahead of the durable frames and the conversation's projected messages.\n */\n previews: (options?: SignalOptionsIface) => AsyncIterableIterator<AcpPreviewEventIface>;\n /** One replay page (`GET /sessions/:id/frames`). */\n frames: (\n options: SignalOptionsIface & { fromSeq: number; limit?: number },\n ) => Promise<SessionFramesPageIface>;\n /** The session's open decisions (`GET /sessions/:id/decisions`). */\n decisions: (options?: SignalOptionsIface) => Promise<DecisionRecordIface[]>;\n turn: (turnId: string, options?: SignalOptionsIface) => Promise<AgentTurnIface>;\n /** Reconstruct an accepted response from its durable turn id, without resending its prompt. */\n response: (\n turnId: string,\n options?: SignalOptionsIface,\n ) => Promise<TurnHandleIface<string | null>>;\n respond: (\n args: RespondArgs,\n options?: SignalOptionsIface,\n ) => Promise<RespondDecisionResponseIface>;\n cancel: (options?: SignalOptionsIface & { reason?: string }) => Promise<void>;\n /**\n * ACP `session/set_config_option` (model, reasoning, mode, ...): `configId` and a value\n * from the options the harness advertises (`get().configOptions`, `configSelectsOf`).\n * Changing them takes the session's owner, or a conversation owner or admin.\n */\n setConfigOption: (\n args: { configId: string; value: JsonValue },\n options?: SignalOptionsIface,\n ) => Promise<void>;\n close: (options?: SignalOptionsIface) => Promise<void>;\n /** The agent document the session pins and the provide document it was resolved with. */\n manifest: (options?: SignalOptionsIface) => Promise<SessionManifestIface>;\n /** Each of the agent's requirements and what provides it now. */\n requirements: (options?: SignalOptionsIface) => Promise<RequirementStatusIface[]>;\n /** What the session was provided; null before its first open. */\n provide: (options?: SignalOptionsIface) => Promise<ProvideDocumentViewIface | null>;\n /**\n * The latest plan the agent reported, with its history (`GET \u2026/plan`); null\n * until it reports one. Each update raises `revision` and emits a\n * `session.plan_updated` event.\n */\n plan: (options?: SignalOptionsIface) => Promise<SessionPlanIface | null>;\n}\n\nexport interface CreateSessionArgsIface extends SignalOptionsIface {\n /**\n * A session id you chose, so whatever you create for it first (a sandbox it\n * owns) can name it. Creating with an id that exists returns that session.\n */\n id?: string;\n /** The agent you defined, or one fetched with `project.agents.get`; never a string. */\n agent: AgentInput;\n /**\n * What the agent requires. Files and shell left out run in this process\n * unless the client was created with `localCompute: false`.\n */\n provide: ProvideIface;\n /** Your app's end user the first turn acts for. */\n actor?: Omit<ActorIface, 'displayName'> & { displayName?: string };\n message?: ContentInput;\n turnPolicy?: EnumInput<AgentTurnPolicy>;\n idempotencyKey?: string;\n title?: string;\n meta?: JsonObjectIface;\n /** When the person submitted `message`; defaults to now. */\n clientSubmittedAtMs?: number;\n}\n\nexport interface CreatedSessionIface {\n session: AgentSessionIface;\n handle: SessionHandleIface;\n /** The first turn when `message` was given. */\n response: TurnHandleIface | null;\n}\n\nexport interface SessionsApiIface {\n fork: (sessionId: string, options?: ForkSessionOptionsIface) => Promise<CreatedSessionIface>;\n get: (sessionId: string, options?: SignalOptionsIface) => Promise<AgentSessionIface>;\n attach: (sessionId: string) => SessionHandleIface;\n}\n\nexport const outcomeOf = (args: RespondArgs): DecisionOutcomeInput =>\n 'optionId' in args ? { outcome: 'selected', optionId: args.optionId } : args.outcome;\n\nconst sessionPath = (sessionId: string, suffix = ''): string =>\n `/v1/sessions/${encodePath(sessionId)}${suffix}`;\n\ninterface TurnHandleArgsIface<MessageId extends string | null> {\n context: ClientContextIface;\n sessionId: string;\n accepted: Omit<PromptAcceptedIface, 'messageId'> & { messageId: MessageId };\n}\n\nconst turnHandle = <MessageId extends string | null>(\n args: TurnHandleArgsIface<MessageId>,\n): TurnHandleIface<MessageId> => {\n const { context, sessionId, accepted } = args;\n const get = (options?: SignalOptionsIface) =>\n getTurn({ context, sessionId, turnId: accepted.turnId, signal: options?.signal });\n const stream = (options?: SignalOptionsIface): AsyncIterableIterator<AcpFrameEventIface> => {\n // Without the prompt's seq, scan from the start for ACP's user message with this id.\n // `until` runs as frames are queued and `next` as they are consumed, so each tracks its own start.\n let queuedStart = accepted.messageId == null && accepted.fromSeq != null;\n let started = queuedStart;\n const frames = streamSessionFrames({\n sessionId,\n fromSeq: accepted.fromSeq ?? FIRST_ACP_FRAME_SEQ,\n follow: true,\n ...frameSources({ context, sessionId }),\n transport: context.realtime(),\n timing: context.timing,\n signal: options?.signal,\n closeSignal: context.closeSignal,\n terminal: async (signal) => {\n const receipt = await get({ signal });\n return receipt.endedAt == null ? null : { throughSeq: receipt.toSeq ?? 0 };\n },\n until: (event) => {\n if (\n !queuedStart &&\n accepted.messageId != null &&\n isUserMessageFor(event, accepted.messageId)\n )\n queuedStart = true;\n return queuedStart && turnEndOf(event) != null;\n },\n });\n const iterator: AsyncIterableIterator<AcpFrameEventIface> = {\n next: async () => {\n for (;;) {\n const next = await frames.next();\n if (next.done === true || started) return next;\n if (accepted.messageId != null && isUserMessageFor(next.value, accepted.messageId)) {\n started = true;\n return next;\n }\n }\n },\n return: () => frames.return?.() ?? Promise.resolve({ done: true, value: undefined }),\n [Symbol.asyncIterator]: () => iterator,\n };\n return iterator;\n };\n\n const result = async (options?: SignalOptionsIface): Promise<TurnResultIface<MessageId>> => {\n const text = createTextCollector();\n let last: AcpFrameEventIface | null = null;\n for await (const event of stream(options)) {\n text.add(event);\n last = event;\n }\n const end = last == null ? null : turnEndOf(last);\n const receipt = await get(options);\n return {\n messageId: accepted.messageId,\n turnId: accepted.turnId,\n stopReason: receipt.stopReason ?? end?.stopReason ?? null,\n text: text.text(),\n toSeq: receipt.toSeq ?? last?.seq ?? accepted.fromSeq ?? 0,\n };\n };\n\n return {\n ...accepted,\n sessionId,\n get,\n stream,\n result,\n text: async (options) => (await result(options)).text,\n };\n};\n\nconst getTurn = (args: {\n context: ClientContextIface;\n sessionId: string;\n turnId: string;\n signal?: AbortSignal;\n}): Promise<AgentTurnIface> =>\n args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, `/turns/${encodePath(args.turnId)}`),\n response: turnSchema,\n signal: args.signal,\n });\n\ninterface ReplayArgsIface extends SignalOptionsIface {\n context: ClientContextIface;\n sessionId: string;\n fromSeq: number;\n limit?: number;\n}\n\nconst replay = (args: ReplayArgsIface): Promise<SessionFramesPageIface> =>\n args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, '/frames'),\n query: { fromSeq: args.fromSeq, limit: args.limit },\n response: sessionFramesPageSchema,\n signal: args.signal,\n });\n\nconst openDecisions = async (args: {\n context: ClientContextIface;\n sessionId: string;\n signal?: AbortSignal;\n}): Promise<DecisionRecordIface[]> =>\n (\n await args.context.http.request({\n method: HttpMethod.Get,\n path: sessionPath(args.sessionId, '/decisions'),\n response: decisionRecordListSchema,\n signal: args.signal,\n })\n ).decisions;\n\n/** The session's frames over Streamable HTTP (`GET /sessions/:id/frames/stream`), from `fromSeq`. */\nasync function* streamFramesOverHttp(args: {\n context: ClientContextIface;\n sessionId: string;\n fromSeq: number;\n signal: AbortSignal;\n}): AsyncGenerator<AcpFrameEventIface> {\n for await (const message of streamServerSentEvents({\n http: args.context.http,\n path: sessionPath(args.sessionId, '/frames/stream'),\n query: { fromSeq: args.fromSeq },\n signal: AbortSignal.any([args.signal, args.context.closeSignal]),\n })) {\n if (message.event !== AgentRealtimeKind.AcpFrame) continue;\n try {\n const event = acpFrameEventSchema.safeParse(JSON.parse(message.data));\n if (event.success) yield event.data;\n } catch {\n // A malformed event is skipped; replay fills any gap it leaves.\n }\n }\n}\n\n/** Live `acp.preview` events of the session topic. */\nconst streamPreviews = (args: {\n context: ClientContextIface;\n sessionId: string;\n signal?: AbortSignal;\n}): AsyncIterableIterator<AcpPreviewEventIface> => {\n const topic = agentRealtimeTopics.session(args.sessionId);\n let unsubscribe: (() => void) | null = null;\n let detachAbort: () => void = () => {};\n let detachClose: () => void = () => {};\n const queue = createAsyncQueue<AcpPreviewEventIface>(() => {\n unsubscribe?.();\n detachAbort();\n detachClose();\n });\n const onFrame = (raw: RealtimeTransportFrameIface): void => {\n const frame = agentRealtimeFrameSchema.safeParse(raw);\n if (!frame.success) return;\n if (frame.data.type === AgentRealtimeFrameType.Error && isTerminalRealtimeError(frame.data)) {\n queue.fail(\n realtimeSubscriptionError({\n topic: frame.data.topic ?? topic,\n code: frame.data.code ?? 'unknown',\n message: frame.data.message ?? 'Realtime subscription was refused',\n }),\n );\n return;\n }\n if (frame.data.type !== AgentRealtimeFrameType.Event) return;\n if (frame.data.kind !== AgentRealtimeKind.AcpPreview) return;\n const preview = acpPreviewEventSchema.safeParse(frame.data.payload);\n if (preview.success) queue.push(preview.data);\n };\n detachAbort = failOnAbort(queue, args.signal);\n detachClose = failOnAbort(queue, args.context.closeSignal);\n if (!queue.closed()) {\n const stop = args.context.realtime().subscribe(topic, onFrame);\n if (queue.closed()) stop();\n else unsubscribe = stop;\n }\n return queue.iterator;\n};\n\n/** Replay, open decisions and the Streamable HTTP fallback of one session's frame stream. */\nconst frameSources = (args: { context: ClientContextIface; sessionId: string }) => ({\n replay: (page: { fromSeq: number; limit: number; signal?: AbortSignal }) =>\n replay({ context: args.context, sessionId: args.sessionId, ...page }),\n decisions: (signal?: AbortSignal) => openDecisions({ ...args, signal }),\n httpStream: (stream: { fromSeq: number; signal: AbortSignal }) =>\n streamFramesOverHttp({ ...args, ...stream }),\n});\n\nexport const createSessionHandle = (\n context: ClientContextIface,\n sessionId: string,\n): SessionHandleIface => {\n const { http } = context;\n const post = async (args: {\n suffix: string;\n body?: HttpBodyIface;\n signal?: AbortSignal;\n }): Promise<void> => {\n await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, args.suffix),\n body: args.body,\n response: okResponseSchema,\n signal: args.signal,\n context: { sessionId },\n });\n };\n\n return {\n id: sessionId,\n fork: async (options) => {\n const created = await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/fork'),\n body: {\n schema: forkSessionRequestSchema,\n value: {\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n title: options?.title,\n },\n },\n response: createSessionResponseSchema,\n signal: options?.signal,\n context: { sessionId },\n });\n return {\n session: created.session,\n handle: createSessionHandle(context, created.session.id),\n response: null,\n };\n },\n attachment: (attachmentId, options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, `/attachments/${encodePath(attachmentId)}`),\n response: attachmentDownloadSchema,\n signal: options?.signal,\n }),\n get: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId),\n response: sessionSchema,\n signal: options?.signal,\n }),\n manifest: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, '/manifest'),\n response: sessionManifestSchema,\n signal: options?.signal,\n }),\n requirements: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, '/requirements'),\n response: sessionRequirementsSchema,\n signal: options?.signal,\n })\n ).requirements,\n provide: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, '/manifest'),\n response: sessionManifestSchema,\n signal: options?.signal,\n })\n ).provide,\n send: async (content, options) => {\n const accepted = await http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/prompt'),\n body: {\n schema: promptSessionRequestSchema,\n value: {\n content,\n turnPolicy: options?.turnPolicy,\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n meta: options?.meta,\n clientSubmittedAtMs: options?.clientSubmittedAtMs ?? context.now(),\n },\n },\n response: promptAcceptedSchema,\n signal: options?.signal,\n context: { sessionId },\n });\n return turnHandle({ context, sessionId, accepted });\n },\n observe: (content, options) =>\n post({\n suffix: '/observe',\n body: {\n schema: observeSessionRequestSchema,\n value: {\n content,\n idempotencyKey: options?.idempotencyKey ?? context.newKey(),\n meta: options?.meta,\n },\n },\n signal: options?.signal,\n }),\n stream: (options) =>\n streamSessionFrames({\n sessionId,\n fromSeq: options?.fromSeq ?? FIRST_ACP_FRAME_SEQ,\n follow: options?.follow ?? true,\n ...frameSources({ context, sessionId }),\n transport: context.realtime(),\n timing: context.timing,\n signal: options?.signal,\n closeSignal: context.closeSignal,\n }),\n liveEvents: (options) =>\n streamSessionLiveEvents({ context, sessionId, signal: options?.signal }),\n previews: (options) => streamPreviews({ context, sessionId, signal: options?.signal }),\n frames: (options) => replay({ context, sessionId, ...options }),\n decisions: (options) => openDecisions({ context, sessionId, signal: options?.signal }),\n turn: (turnId, options) => getTurn({ context, sessionId, turnId, signal: options?.signal }),\n response: async (turnId, options) => {\n const receipt = await getTurn({ context, sessionId, turnId, signal: options?.signal });\n return turnHandle({\n context,\n sessionId,\n accepted: {\n turnId: receipt.id,\n messageId: receipt.promptMessageId,\n fromSeq: receipt.fromSeq,\n },\n });\n },\n respond: (args, options) =>\n http.request({\n method: HttpMethod.Post,\n path: sessionPath(sessionId, '/respond'),\n body: {\n schema: respondDecisionSchema,\n value: { decisionId: args.decisionId, outcome: outcomeOf(args) },\n },\n response: respondDecisionResponseSchema,\n signal: options?.signal,\n context: { sessionId, decisionId: args.decisionId },\n }),\n cancel: (options) =>\n post({\n suffix: '/cancel',\n body: { schema: cancelRequestSchema, value: { reason: options?.reason } },\n signal: options?.signal,\n }),\n setConfigOption: (args, options) =>\n post({\n suffix: '/config-option',\n body: { schema: setConfigOptionRequestSchema, value: args },\n signal: options?.signal,\n }),\n close: (options) => post({ suffix: '/close', signal: options?.signal }),\n plan: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: sessionPath(sessionId, '/plan'),\n response: sessionPlanResponseSchema,\n signal: options?.signal,\n })\n ).plan,\n };\n};\n\nexport const createSessionsApi = (context: ClientContextIface): SessionsApiIface => ({\n fork: (sessionId, options) => createSessionHandle(context, sessionId).fork(options),\n get: (sessionId, options) => createSessionHandle(context, sessionId).get(options),\n attach: (sessionId) => createSessionHandle(context, sessionId),\n});\n\nexport interface ProjectSessionsApiIface extends SessionsApiIface {\n /**\n * Starts a session. Fails with `requirements_unmet`, creating nothing, unless\n * every requirement the agent does not mark optional is provided.\n */\n create: (args: CreateSessionArgsIface) => Promise<CreatedSessionIface>;\n}\n\nexport const createProjectSessionsApi = (args: {\n context: ClientContextIface;\n projectId: string;\n start: AgentStartDepsIface;\n}): ProjectSessionsApiIface => {\n const { context } = args;\n return {\n ...createSessionsApi(context),\n create: async (create) => {\n const started = await startAgent(args.start, {\n projectId: args.projectId,\n agent: create.agent,\n provide: create.provide,\n owner: { kind: LocalHostOwnerKind.Session, id: create.id },\n signal: create.signal,\n });\n try {\n const created = await context.http.request({\n method: HttpMethod.Post,\n path: '/v1/sessions',\n body: {\n schema: createSessionRequestSchema,\n value: {\n id: started.ownerId ?? create.id,\n projectId: args.projectId,\n agent: started.ref,\n provide: started.provide,\n actor: create.actor,\n message: create.message,\n turnPolicy: create.turnPolicy,\n idempotencyKey:\n create.idempotencyKey ?? (create.message == null ? undefined : context.newKey()),\n title: create.title,\n meta: create.meta,\n clientSubmittedAtMs:\n create.message == null ? undefined : (create.clientSubmittedAtMs ?? context.now()),\n },\n },\n response: createSessionResponseSchema,\n signal: create.signal,\n });\n const reserved = started.ownerId ?? create.id;\n if (reserved != null && created.session.id !== reserved) {\n // The idempotency key replayed an earlier creation: the session is that one, not\n // the id this call reserved, and what was started for that id serves nothing. Its\n // in-process code is served for it from here; its compute stays what that\n // creation named, which nothing can change now.\n started.abandon();\n if (started.host != null)\n await serveCodeFor(args.start, {\n projectId: args.projectId,\n agent: create.agent,\n owner: { kind: LocalHostOwnerKind.Session, id: created.session.id },\n signal: create.signal,\n });\n } else started.established();\n const handle = createSessionHandle(context, created.session.id);\n return {\n session: created.session,\n handle,\n response:\n created.turn == null\n ? null\n : turnHandle({ context, sessionId: created.session.id, accepted: created.turn }),\n };\n } catch (cause) {\n started.abandon();\n throw cause;\n }\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAkBK;AACP,SAAS,qBAAqB,kBAAkB,iBAAiB;AAEjE,SAAS,kBAAkB,mBAAmB;AAC9C;AAAA,EACE;AAAA,OAIK;AACP,SAAS,yBAAyB,iCAAiC;AACnE,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,kBAAsC;AAC/C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,cACf,SAAS,QAAQ;AAAA,cACjB,OAAO,OAAO;AAAA,cACd,SAAS,OAAO;AAAA,cAChB,YAAY,OAAO;AAAA,cACnB,gBACE,OAAO,mBAAmB,OAAO,WAAW,OAAO,SAAY,QAAQ,OAAO;AAAA,cAChF,OAAO,OAAO;AAAA,cACd,MAAM,OAAO;AAAA,cACb,qBACE,OAAO,WAAW,OAAO,SAAa,OAAO,uBAAuB,QAAQ,IAAI;AAAA,YACpF;AAAA,UACF;AAAA,UACA,UAAU;AAAA,UACV,QAAQ,OAAO;AAAA,QACjB,CAAC;AACD,cAAM,WAAW,QAAQ,WAAW,OAAO;AAC3C,YAAI,YAAY,QAAQ,QAAQ,QAAQ,OAAO,UAAU;AAKvD,kBAAQ,QAAQ;AAChB,cAAI,QAAQ,QAAQ;AAClB,kBAAM,aAAa,KAAK,OAAO;AAAA,cAC7B,WAAW,KAAK;AAAA,cAChB,OAAO,OAAO;AAAA,cACd,OAAO,EAAE,MAAM,mBAAmB,SAAS,IAAI,QAAQ,QAAQ,GAAG;AAAA,cAClE,QAAQ,OAAO;AAAA,YACjB,CAAC;AAAA,QACL,MAAO,SAAQ,YAAY;AAC3B,cAAM,SAAS,oBAAoB,SAAS,QAAQ,QAAQ,EAAE;AAC9D,eAAO;AAAA,UACL,SAAS,QAAQ;AAAA,UACjB;AAAA,UACA,UACE,QAAQ,QAAQ,OACZ,OACA,WAAW,EAAE,SAAS,WAAW,QAAQ,QAAQ,IAAI,UAAU,QAAQ,KAAK,CAAC;AAAA,QACrF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,QAAQ;AAChB,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type AgentRefInputIface, type HarnessCheckResponseIface, type ProvideDocumentIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
|
+
import { type AgentValueCodecIface } from "./agent-input.mjs";
|
|
3
|
+
import { type ClientContextIface } from "./context.mjs";
|
|
4
|
+
import { type LocalComputeIface, type LocalHostIface, type LocalHostSocketIface } from "./local-host.mjs";
|
|
5
|
+
import { LocalHostOwnerKind, type LocalHostOwnerIface } from "./local-host-protocol.mjs";
|
|
6
|
+
import { type ProvideIface } from "./provide.mjs";
|
|
7
|
+
/** What the project client needs to start agents; built once per client. */
|
|
8
|
+
export interface AgentStartDepsIface {
|
|
9
|
+
context: ClientContextIface;
|
|
10
|
+
codec: AgentValueCodecIface;
|
|
11
|
+
/** False: never serve compute from this process (`createClient({ localCompute: false })`). */
|
|
12
|
+
localCompute: boolean;
|
|
13
|
+
compute: LocalComputeIface;
|
|
14
|
+
dial: (path: string, signal?: AbortSignal) => Promise<LocalHostSocketIface>;
|
|
15
|
+
/** Every open local host, so `client.close()` ends them. */
|
|
16
|
+
hosts: Set<LocalHostIface>;
|
|
17
|
+
}
|
|
18
|
+
export interface StartAgentArgsIface {
|
|
19
|
+
projectId: string | null;
|
|
20
|
+
agent: unknown;
|
|
21
|
+
provide: ProvideIface;
|
|
22
|
+
/** Provided alongside by a conversation; the participant's own wins each top-level key whole. */
|
|
23
|
+
shared?: ProvideDocumentIface | null;
|
|
24
|
+
owner: LocalHostOwnerIface;
|
|
25
|
+
/** The owner id was reserved for this call (by a local host), not chosen by the caller. */
|
|
26
|
+
ownerIdReserved?: boolean;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
export interface StartedAgentIface {
|
|
30
|
+
ref: AgentRefInputIface;
|
|
31
|
+
/** The participant's or session's own provide, with this process's compute filled in. */
|
|
32
|
+
provide: ProvideDocumentIface;
|
|
33
|
+
/** The owner id, when a local host reserved or confirmed one, or the SDK chose one for a Workers sandbox. */
|
|
34
|
+
ownerId: string | undefined;
|
|
35
|
+
host: LocalHostIface | null;
|
|
36
|
+
/**
|
|
37
|
+
* Ends the local host when the call that would have used it failed, and
|
|
38
|
+
* deletes a Workers sandbox created for an owner id the SDK chose once the
|
|
39
|
+
* owner is confirmed not to exist.
|
|
40
|
+
*/
|
|
41
|
+
abandon: () => void;
|
|
42
|
+
/** The call that uses it succeeded: the local host stops keeping the process alive while idle. */
|
|
43
|
+
established: () => void;
|
|
44
|
+
}
|
|
45
|
+
export interface WorkersEnvironmentIface {
|
|
46
|
+
/** The harness settings with the Workers sandbox as their environment; unchanged when none was needed. */
|
|
47
|
+
harness: NonNullable<ProvideDocumentIface['harness']>;
|
|
48
|
+
/** The owner id the sandbox was created for: the caller's, else one the SDK chose. */
|
|
49
|
+
ownerId: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* When the SDK chose the owner id: deletes the sandbox unless its owner was
|
|
52
|
+
* created after all (a lost response does not prove the creation failed).
|
|
53
|
+
*/
|
|
54
|
+
created: {
|
|
55
|
+
discard: () => Promise<void>;
|
|
56
|
+
} | null;
|
|
57
|
+
/**
|
|
58
|
+
* Capabilities the harness uses natively from where it runs, when its
|
|
59
|
+
* settings name no environment; such a harness runs where `shell` is.
|
|
60
|
+
*/
|
|
61
|
+
native: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gives harness settings that name no environment, for a harness that runs
|
|
65
|
+
* only as a worker program, a Workers sandbox owned by the session or
|
|
66
|
+
* conversation: the same one on a retry with the same owner id. A caller that
|
|
67
|
+
* chose no owner id gets one chosen here, which the session or conversation
|
|
68
|
+
* must then be created with.
|
|
69
|
+
*/
|
|
70
|
+
export declare const withWorkersEnvironment: (args: {
|
|
71
|
+
context: ClientContextIface;
|
|
72
|
+
projectId: string;
|
|
73
|
+
harness: NonNullable<ProvideDocumentIface["harness"]>;
|
|
74
|
+
owner: LocalHostOwnerIface;
|
|
75
|
+
/** The owner id was reserved for this call, not chosen by the caller. */
|
|
76
|
+
ownerIdReserved?: boolean;
|
|
77
|
+
signal: AbortSignal | undefined;
|
|
78
|
+
}) => Promise<WorkersEnvironmentIface>;
|
|
79
|
+
export declare const checkHarness: (args: {
|
|
80
|
+
context: ClientContextIface;
|
|
81
|
+
projectId: string;
|
|
82
|
+
hash: string;
|
|
83
|
+
harness: NonNullable<ProvideDocumentIface["harness"]>;
|
|
84
|
+
compute?: ProvideDocumentIface["compute"];
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}) => Promise<HarnessCheckResponseIface>;
|
|
87
|
+
export declare const startAgent: (deps: AgentStartDepsIface, args: StartAgentArgsIface) => Promise<StartedAgentIface>;
|
|
88
|
+
/**
|
|
89
|
+
* Serves the agent's in-process code to an existing session or conversation
|
|
90
|
+
* from this process, without compute: its provide is already what an earlier
|
|
91
|
+
* call stored. Null when the agent has no in-process code.
|
|
92
|
+
*/
|
|
93
|
+
export declare const serveCodeFor: (deps: AgentStartDepsIface, args: {
|
|
94
|
+
projectId: string;
|
|
95
|
+
agent: unknown;
|
|
96
|
+
owner: {
|
|
97
|
+
kind: LocalHostOwnerKind;
|
|
98
|
+
id: string;
|
|
99
|
+
};
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}) => Promise<LocalHostIface | null>;
|