@finalai/agents 0.4.4 → 0.6.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 +3 -3
- package/dist/modules/agent-client/build.d.mts +11 -1
- package/dist/modules/agent-client/build.mjs +1 -1
- package/dist/modules/agent-client/build.mjs.map +2 -2
- package/dist/modules/agent-client/client.d.mts +10 -22
- package/dist/modules/agent-client/client.mjs +10 -40
- package/dist/modules/agent-client/client.mjs.map +2 -2
- package/dist/modules/agent-client/collection-events.d.mts +1 -1
- package/dist/modules/agent-client/collection-events.mjs.map +1 -1
- package/dist/modules/agent-client/context.d.mts +1 -2
- package/dist/modules/agent-client/context.mjs +0 -1
- package/dist/modules/agent-client/context.mjs.map +2 -2
- package/dist/modules/agent-client/conversations.d.mts +35 -10
- package/dist/modules/agent-client/conversations.mjs +46 -42
- package/dist/modules/agent-client/conversations.mjs.map +2 -2
- package/dist/modules/agent-client/errors.d.mts +14 -14
- package/dist/modules/agent-client/errors.mjs +15 -15
- package/dist/modules/agent-client/errors.mjs.map +3 -3
- package/dist/modules/agent-client/frame-stream.d.mts +8 -8
- package/dist/modules/agent-client/frame-stream.mjs +36 -36
- package/dist/modules/agent-client/frame-stream.mjs.map +2 -2
- package/dist/modules/agent-client/http.d.mts +2 -2
- package/dist/modules/agent-client/http.mjs +10 -10
- package/dist/modules/agent-client/http.mjs.map +2 -2
- package/dist/modules/agent-client/index.d.mts +2 -2
- package/dist/modules/agent-client/index.mjs +6 -6
- package/dist/modules/agent-client/index.mjs.map +2 -2
- package/dist/modules/agent-client/sessions.d.mts +9 -8
- package/dist/modules/agent-client/sessions.mjs +13 -13
- package/dist/modules/agent-client/sessions.mjs.map +2 -2
- package/dist/modules/cli/cli.mjs +2 -2
- package/dist/modules/cli/cli.mjs.map +2 -2
- package/examples/release-scout/README.md +1 -1
- package/examples/release-scout/client.ts +2 -2
- package/package.json +5 -5
package/HOSTING.md
CHANGED
|
@@ -7,13 +7,13 @@ resolve against dev and production configuration without source edits.
|
|
|
7
7
|
## Selecting a deployment
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
export FINAL_API_HOST=https
|
|
11
|
-
export FINAL_API_KEY=<dev-
|
|
10
|
+
export FINAL_API_HOST=https://<dev-agents-api-host>/api
|
|
11
|
+
export FINAL_API_KEY=<dev-api-key>
|
|
12
12
|
pnpm exec final-agents build ./agent
|
|
13
13
|
pnpm exec final-agents publish ./agent --agent my-agent
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Choose production by changing the host and
|
|
16
|
+
Choose production by changing the host and API key. `--host` overrides
|
|
17
17
|
`FINAL_API_HOST`; without either, the existing production default remains. Build
|
|
18
18
|
compiles locally and optionally checks installed-harness compatibility. Publish
|
|
19
19
|
compiles again and sends source/release requests to the selected deployment.
|
|
@@ -10,13 +10,23 @@ export interface DefinitionsApiIface {
|
|
|
10
10
|
ref: string;
|
|
11
11
|
}) => Promise<RevisionIface>;
|
|
12
12
|
previewCredentialPolicy: (args: DefinitionRefIface & PreviewCredentialPolicyRequestIface) => Promise<CredentialPolicyPreviewIface>;
|
|
13
|
+
/**
|
|
14
|
+
* With `projectId`, its definitions and those inherited from its ancestors. Without it,
|
|
15
|
+
* everything the caller can access (an API key: its parent project and every project it is
|
|
16
|
+
* granted; a person: every project they can read).
|
|
17
|
+
*/
|
|
13
18
|
list: (options?: SignalOptionsIface & {
|
|
14
19
|
cursor?: string;
|
|
15
20
|
limit?: number;
|
|
21
|
+
projectId?: string;
|
|
16
22
|
}) => Promise<{
|
|
17
23
|
definitions: DefinitionIface[];
|
|
18
24
|
nextCursor: string | null;
|
|
19
25
|
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates the definition in `projectId` (editors of that project); omitted, the API key's parent
|
|
28
|
+
* project (a signed-in person's: My Work).
|
|
29
|
+
*/
|
|
20
30
|
create: (args: CreateDefinitionRequestIface & SignalOptionsIface) => Promise<DefinitionIface>;
|
|
21
31
|
get: (args: DefinitionRefIface) => Promise<DefinitionIface>;
|
|
22
32
|
/** Compiles the directory at `ref` server-side without publishing. */
|
|
@@ -69,7 +79,7 @@ export interface DefinitionsApiIface {
|
|
|
69
79
|
archive: (args: DefinitionRefIface) => Promise<DefinitionIface>;
|
|
70
80
|
/**
|
|
71
81
|
* A short-lived, read-only git remote for a Final-hosted repository, for
|
|
72
|
-
* `git clone` (
|
|
82
|
+
* `git clone` (editors of the definition's project).
|
|
73
83
|
*/
|
|
74
84
|
cloneUrl: (args: DefinitionRefIface) => Promise<DefinitionCloneUrlIface>;
|
|
75
85
|
}
|
|
@@ -51,7 +51,7 @@ const createDefinitionsApi = ({ http }) => ({
|
|
|
51
51
|
list: (options) => http.request({
|
|
52
52
|
method: HttpMethod.Get,
|
|
53
53
|
path: "/v1/definitions",
|
|
54
|
-
query: { cursor: options?.cursor, limit: options?.limit },
|
|
54
|
+
query: { cursor: options?.cursor, limit: options?.limit, projectId: options?.projectId },
|
|
55
55
|
response: definitionListSchema,
|
|
56
56
|
signal: options?.signal
|
|
57
57
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/build.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n attachChannelBindingRequestSchema,\n attachChannelBindingResponseSchema,\n commitDefinitionRequestSchema,\n commitResultSchema,\n compatibilityReportSchema,\n compileDefinitionRequestSchema,\n compileResultSchema,\n computerSetupGuideDetailSchema,\n computerSetupGuideListSchema,\n createDefinitionRequestSchema,\n credentialPolicyPreviewSchema,\n definitionChannelsResponseSchema,\n definitionCloneUrlSchema,\n definitionFilesSchema,\n definitionListSchema,\n definitionSchema,\n previewCredentialPolicyRequestSchema,\n providerListSchema,\n publishComputerSetupGuideRequestSchema,\n publishComputerSetupGuideResultSchema,\n publishDefinitionRequestSchema,\n publishResultSchema,\n revisionDiffSchema,\n revisionListSchema,\n revisionSchema,\n scheduleListSchema,\n scheduleRunResultSchema,\n scheduleSchema,\n updateScheduleRequestSchema,\n type AttachChannelBindingResponseIface,\n type CommitDefinitionRequestIface,\n type CommitResultIface,\n type CompatibilityReportIface,\n type CompileResultIface,\n type ComputerSetupGuideDetailIface,\n type ComputerSetupGuideIface,\n type ComputerSetupGuideVersionIface,\n type CreateDefinitionRequestIface,\n type CredentialPolicyPreviewIface,\n type DefinitionChannelIface,\n type DefinitionCloneUrlIface,\n type DefinitionFilesIface,\n type DefinitionIface,\n type PreviewCredentialPolicyRequestIface,\n type ProviderEntryIface,\n type PublishComputerSetupGuideRequestIface,\n type PublishResultIface,\n type RevisionDiffIface,\n type RevisionIface,\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\";\n\n// Definitions, providers, setup guides, schedules, credentials and budgets:\n// what Build, settings and CI use.\n\nexport interface DefinitionRefIface extends SignalOptionsIface {\n /** Definition id or slug. */\n definition: string;\n}\n\nexport interface DefinitionsApiIface {\n /** Compiles a draft into an immutable test snapshot without publishing or activating schedules/channels. */\n testRevision: (args: DefinitionRefIface & { ref: string }) => Promise<RevisionIface>;\n previewCredentialPolicy: (\n args: DefinitionRefIface & PreviewCredentialPolicyRequestIface,\n ) => Promise<CredentialPolicyPreviewIface>;\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number },\n ) => Promise<{ definitions: DefinitionIface[]; nextCursor: string | null }>;\n create: (args: CreateDefinitionRequestIface & SignalOptionsIface) => Promise<DefinitionIface>;\n get: (args: DefinitionRefIface) => Promise<DefinitionIface>;\n /** Compiles the directory at `ref` server-side without publishing. */\n compile: (\n args: DefinitionRefIface & { ref: string; harness?: string },\n ) => Promise<CompileResultIface>;\n commit: (args: DefinitionRefIface & CommitDefinitionRequestIface) => Promise<CommitResultIface>;\n /** Compiles `ref`, stores a revision and makes it current. */\n publish: (\n args: DefinitionRefIface & { ref: string; note?: string },\n ) => Promise<PublishResultIface>;\n /** The agent directory's files at `ref` (default branch when omitted). */\n files: (args: DefinitionRefIface & { ref?: string }) => Promise<DefinitionFilesIface>;\n revisions: (\n args: DefinitionRefIface & { cursor?: string },\n ) => Promise<{ revisions: RevisionIface[]; nextCursor: string | null }>;\n /**\n * What changed in the compiled manifest between two revisions (revision ids\n * or numbers); `to` defaults to the current revision.\n */\n revisionDiff: (\n args: DefinitionRefIface & { from: string | number; to?: string | number },\n ) => Promise<RevisionDiffIface>;\n compatibility: (\n args: DefinitionRefIface & { harness: string; ref?: string },\n ) => Promise<CompatibilityReportIface>;\n /** The agent's live channel bindings, with the conversation each is attached to. */\n channels: (args: DefinitionRefIface) => Promise<DefinitionChannelIface[]>;\n /**\n * Attaches a channel binding to a conversation the agent and the caller take\n * part in (its events and bound-conversation schedules post there); null detaches.\n */\n attachChannel: (\n args: DefinitionRefIface & { bindingId: string; conversationId: string | null },\n ) => Promise<AttachChannelBindingResponseIface>;\n /**\n * Archives the definition: it leaves listings, its schedules and channel\n * bindings stop, and new sessions are refused. Its repository is kept.\n */\n archive: (args: DefinitionRefIface) => Promise<DefinitionIface>;\n /**\n * A short-lived, read-only git remote for a Final-hosted repository, for\n * `git clone` (owners of personal agents, organization admins otherwise).\n */\n cloneUrl: (args: DefinitionRefIface) => Promise<DefinitionCloneUrlIface>;\n}\n\nexport interface ProvidersApiIface {\n list: (options?: SignalOptionsIface) => Promise<ProviderEntryIface[]>;\n}\n\nexport interface ComputerSetupGuidesApiIface {\n list: (options?: SignalOptionsIface) => Promise<ComputerSetupGuideIface[]>;\n /** Guide by slug or id, with its versions. */\n get: (ref: string, options?: SignalOptionsIface) => Promise<ComputerSetupGuideDetailIface>;\n /** Publishes a new version (creating the guide on first publish). */\n publish: (\n args: PublishComputerSetupGuideRequestIface & SignalOptionsIface,\n ) => Promise<{ guide: ComputerSetupGuideIface; version: ComputerSetupGuideVersionIface }>;\n}\n\nexport type ScheduleRef = { scheduleId: string } | { agent: string; key: string };\n\nexport interface SchedulesApiIface {\n list: (options?: SignalOptionsIface & { agent?: string }) => Promise<ScheduleIface[]>;\n runNow: (args: ScheduleRef & SignalOptionsIface) => Promise<ScheduleRunResultIface>;\n update: (\n args: { scheduleId: string } & UpdateScheduleRequestIface & SignalOptionsIface,\n ) => Promise<ScheduleIface>;\n}\n\nconst definitionPath = (definition: string, suffix = ''): string =>\n `/v1/definitions/${encodePath(definition)}${suffix}`;\n\nexport const createDefinitionsApi = ({ http }: ClientContextIface): DefinitionsApiIface => ({\n testRevision: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/test-revision'),\n body: { schema: compileDefinitionRequestSchema, value },\n response: revisionSchema,\n signal,\n }),\n previewCredentialPolicy: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/credential-policy/preview'),\n body: { schema: previewCredentialPolicyRequestSchema, value },\n response: credentialPolicyPreviewSchema,\n signal,\n }),\n list: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/definitions',\n query: { cursor: options?.cursor, limit: options?.limit },\n response: definitionListSchema,\n signal: options?.signal,\n }),\n create: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/definitions',\n body: { schema: createDefinitionRequestSchema, value },\n response: definitionSchema,\n signal,\n }),\n get: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition),\n response: definitionSchema,\n signal,\n }),\n compile: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/compile'),\n body: { schema: compileDefinitionRequestSchema, value },\n response: compileResultSchema,\n signal,\n }),\n commit: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/commit'),\n body: { schema: commitDefinitionRequestSchema, value },\n response: commitResultSchema,\n signal,\n }),\n publish: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/publish'),\n body: { schema: publishDefinitionRequestSchema, value },\n response: publishResultSchema,\n signal,\n }),\n files: ({ definition, ref, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/files'),\n query: { ref },\n response: definitionFilesSchema,\n signal,\n }),\n revisions: ({ definition, cursor, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/revisions'),\n query: { cursor },\n response: revisionListSchema,\n signal,\n }),\n revisionDiff: ({ definition, from, to, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/revisions/diff'),\n query: { from, to },\n response: revisionDiffSchema,\n signal,\n }),\n compatibility: ({ definition, harness, ref, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/compatibility'),\n query: { harness, ref },\n response: compatibilityReportSchema,\n signal,\n }),\n channels: async ({ definition, signal }) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/channels'),\n response: definitionChannelsResponseSchema,\n signal,\n })\n ).channels,\n attachChannel: ({ definition, bindingId, conversationId, signal }) =>\n http.request({\n method: HttpMethod.Put,\n path: definitionPath(definition, `/channels/${encodePath(bindingId)}/conversation`),\n body: { schema: attachChannelBindingRequestSchema, value: { conversationId } },\n response: attachChannelBindingResponseSchema,\n signal,\n }),\n archive: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/archive'),\n response: definitionSchema,\n signal,\n }),\n cloneUrl: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/clone-url'),\n response: definitionCloneUrlSchema,\n signal,\n }),\n});\n\nexport const createProvidersApi = ({ http }: ClientContextIface): ProvidersApiIface => ({\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: '/v1/providers',\n response: providerListSchema,\n signal: options?.signal,\n })\n ).providers,\n});\n\nexport const createComputerSetupGuidesApi = ({\n http,\n}: ClientContextIface): ComputerSetupGuidesApiIface => ({\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: '/v1/computer-setup-guides',\n response: computerSetupGuideListSchema,\n signal: options?.signal,\n })\n ).guides,\n get: (ref, options) =>\n http.request({\n method: HttpMethod.Get,\n path: `/v1/computer-setup-guides/${encodePath(ref)}`,\n response: computerSetupGuideDetailSchema,\n signal: options?.signal,\n }),\n publish: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/computer-setup-guides',\n body: { schema: publishComputerSetupGuideRequestSchema, value },\n response: publishComputerSetupGuideResultSchema,\n signal,\n }),\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, ...value }) =>\n http.request({\n method: HttpMethod.Patch,\n path: `/v1/schedules/${encodePath(scheduleId)}`,\n body: { schema: updateScheduleRequestSchema, value },\n response: scheduleSchema,\n signal,\n }),\n };\n};\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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,OAwBK;AACP,SAAS,kBAAoE;AAC7E,SAAS,aAAa,uBAAuB;AAC7C,SAAS,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import {\n attachChannelBindingRequestSchema,\n attachChannelBindingResponseSchema,\n commitDefinitionRequestSchema,\n commitResultSchema,\n compatibilityReportSchema,\n compileDefinitionRequestSchema,\n compileResultSchema,\n computerSetupGuideDetailSchema,\n computerSetupGuideListSchema,\n createDefinitionRequestSchema,\n credentialPolicyPreviewSchema,\n definitionChannelsResponseSchema,\n definitionCloneUrlSchema,\n definitionFilesSchema,\n definitionListSchema,\n definitionSchema,\n previewCredentialPolicyRequestSchema,\n providerListSchema,\n publishComputerSetupGuideRequestSchema,\n publishComputerSetupGuideResultSchema,\n publishDefinitionRequestSchema,\n publishResultSchema,\n revisionDiffSchema,\n revisionListSchema,\n revisionSchema,\n scheduleListSchema,\n scheduleRunResultSchema,\n scheduleSchema,\n updateScheduleRequestSchema,\n type AttachChannelBindingResponseIface,\n type CommitDefinitionRequestIface,\n type CommitResultIface,\n type CompatibilityReportIface,\n type CompileResultIface,\n type ComputerSetupGuideDetailIface,\n type ComputerSetupGuideIface,\n type ComputerSetupGuideVersionIface,\n type CreateDefinitionRequestIface,\n type CredentialPolicyPreviewIface,\n type DefinitionChannelIface,\n type DefinitionCloneUrlIface,\n type DefinitionFilesIface,\n type DefinitionIface,\n type PreviewCredentialPolicyRequestIface,\n type ProviderEntryIface,\n type PublishComputerSetupGuideRequestIface,\n type PublishResultIface,\n type RevisionDiffIface,\n type RevisionIface,\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\";\n\n// Definitions, providers, setup guides, schedules, credentials and budgets:\n// what Build, settings and CI use.\n\nexport interface DefinitionRefIface extends SignalOptionsIface {\n /** Definition id or slug. */\n definition: string;\n}\n\nexport interface DefinitionsApiIface {\n /** Compiles a draft into an immutable test snapshot without publishing or activating schedules/channels. */\n testRevision: (args: DefinitionRefIface & { ref: string }) => Promise<RevisionIface>;\n previewCredentialPolicy: (\n args: DefinitionRefIface & PreviewCredentialPolicyRequestIface,\n ) => Promise<CredentialPolicyPreviewIface>;\n /**\n * With `projectId`, its definitions and those inherited from its ancestors. Without it,\n * everything the caller can access (an API key: its parent project and every project it is\n * granted; a person: every project they can read).\n */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number; projectId?: string },\n ) => Promise<{ definitions: DefinitionIface[]; nextCursor: string | null }>;\n /**\n * Creates the definition in `projectId` (editors of that project); omitted, the API key's parent\n * project (a signed-in person's: My Work).\n */\n create: (args: CreateDefinitionRequestIface & SignalOptionsIface) => Promise<DefinitionIface>;\n get: (args: DefinitionRefIface) => Promise<DefinitionIface>;\n /** Compiles the directory at `ref` server-side without publishing. */\n compile: (\n args: DefinitionRefIface & { ref: string; harness?: string },\n ) => Promise<CompileResultIface>;\n commit: (args: DefinitionRefIface & CommitDefinitionRequestIface) => Promise<CommitResultIface>;\n /** Compiles `ref`, stores a revision and makes it current. */\n publish: (\n args: DefinitionRefIface & { ref: string; note?: string },\n ) => Promise<PublishResultIface>;\n /** The agent directory's files at `ref` (default branch when omitted). */\n files: (args: DefinitionRefIface & { ref?: string }) => Promise<DefinitionFilesIface>;\n revisions: (\n args: DefinitionRefIface & { cursor?: string },\n ) => Promise<{ revisions: RevisionIface[]; nextCursor: string | null }>;\n /**\n * What changed in the compiled manifest between two revisions (revision ids\n * or numbers); `to` defaults to the current revision.\n */\n revisionDiff: (\n args: DefinitionRefIface & { from: string | number; to?: string | number },\n ) => Promise<RevisionDiffIface>;\n compatibility: (\n args: DefinitionRefIface & { harness: string; ref?: string },\n ) => Promise<CompatibilityReportIface>;\n /** The agent's live channel bindings, with the conversation each is attached to. */\n channels: (args: DefinitionRefIface) => Promise<DefinitionChannelIface[]>;\n /**\n * Attaches a channel binding to a conversation the agent and the caller take\n * part in (its events and bound-conversation schedules post there); null detaches.\n */\n attachChannel: (\n args: DefinitionRefIface & { bindingId: string; conversationId: string | null },\n ) => Promise<AttachChannelBindingResponseIface>;\n /**\n * Archives the definition: it leaves listings, its schedules and channel\n * bindings stop, and new sessions are refused. Its repository is kept.\n */\n archive: (args: DefinitionRefIface) => Promise<DefinitionIface>;\n /**\n * A short-lived, read-only git remote for a Final-hosted repository, for\n * `git clone` (editors of the definition's project).\n */\n cloneUrl: (args: DefinitionRefIface) => Promise<DefinitionCloneUrlIface>;\n}\n\nexport interface ProvidersApiIface {\n list: (options?: SignalOptionsIface) => Promise<ProviderEntryIface[]>;\n}\n\nexport interface ComputerSetupGuidesApiIface {\n list: (options?: SignalOptionsIface) => Promise<ComputerSetupGuideIface[]>;\n /** Guide by slug or id, with its versions. */\n get: (ref: string, options?: SignalOptionsIface) => Promise<ComputerSetupGuideDetailIface>;\n /** Publishes a new version (creating the guide on first publish). */\n publish: (\n args: PublishComputerSetupGuideRequestIface & SignalOptionsIface,\n ) => Promise<{ guide: ComputerSetupGuideIface; version: ComputerSetupGuideVersionIface }>;\n}\n\nexport type ScheduleRef = { scheduleId: string } | { agent: string; key: string };\n\nexport interface SchedulesApiIface {\n list: (options?: SignalOptionsIface & { agent?: string }) => Promise<ScheduleIface[]>;\n runNow: (args: ScheduleRef & SignalOptionsIface) => Promise<ScheduleRunResultIface>;\n update: (\n args: { scheduleId: string } & UpdateScheduleRequestIface & SignalOptionsIface,\n ) => Promise<ScheduleIface>;\n}\n\nconst definitionPath = (definition: string, suffix = ''): string =>\n `/v1/definitions/${encodePath(definition)}${suffix}`;\n\nexport const createDefinitionsApi = ({ http }: ClientContextIface): DefinitionsApiIface => ({\n testRevision: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/test-revision'),\n body: { schema: compileDefinitionRequestSchema, value },\n response: revisionSchema,\n signal,\n }),\n previewCredentialPolicy: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/credential-policy/preview'),\n body: { schema: previewCredentialPolicyRequestSchema, value },\n response: credentialPolicyPreviewSchema,\n signal,\n }),\n list: (options) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/definitions',\n query: { cursor: options?.cursor, limit: options?.limit, projectId: options?.projectId },\n response: definitionListSchema,\n signal: options?.signal,\n }),\n create: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/definitions',\n body: { schema: createDefinitionRequestSchema, value },\n response: definitionSchema,\n signal,\n }),\n get: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition),\n response: definitionSchema,\n signal,\n }),\n compile: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/compile'),\n body: { schema: compileDefinitionRequestSchema, value },\n response: compileResultSchema,\n signal,\n }),\n commit: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/commit'),\n body: { schema: commitDefinitionRequestSchema, value },\n response: commitResultSchema,\n signal,\n }),\n publish: ({ definition, signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/publish'),\n body: { schema: publishDefinitionRequestSchema, value },\n response: publishResultSchema,\n signal,\n }),\n files: ({ definition, ref, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/files'),\n query: { ref },\n response: definitionFilesSchema,\n signal,\n }),\n revisions: ({ definition, cursor, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/revisions'),\n query: { cursor },\n response: revisionListSchema,\n signal,\n }),\n revisionDiff: ({ definition, from, to, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/revisions/diff'),\n query: { from, to },\n response: revisionDiffSchema,\n signal,\n }),\n compatibility: ({ definition, harness, ref, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/compatibility'),\n query: { harness, ref },\n response: compatibilityReportSchema,\n signal,\n }),\n channels: async ({ definition, signal }) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: definitionPath(definition, '/channels'),\n response: definitionChannelsResponseSchema,\n signal,\n })\n ).channels,\n attachChannel: ({ definition, bindingId, conversationId, signal }) =>\n http.request({\n method: HttpMethod.Put,\n path: definitionPath(definition, `/channels/${encodePath(bindingId)}/conversation`),\n body: { schema: attachChannelBindingRequestSchema, value: { conversationId } },\n response: attachChannelBindingResponseSchema,\n signal,\n }),\n archive: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/archive'),\n response: definitionSchema,\n signal,\n }),\n cloneUrl: ({ definition, signal }) =>\n http.request({\n method: HttpMethod.Post,\n path: definitionPath(definition, '/clone-url'),\n response: definitionCloneUrlSchema,\n signal,\n }),\n});\n\nexport const createProvidersApi = ({ http }: ClientContextIface): ProvidersApiIface => ({\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: '/v1/providers',\n response: providerListSchema,\n signal: options?.signal,\n })\n ).providers,\n});\n\nexport const createComputerSetupGuidesApi = ({\n http,\n}: ClientContextIface): ComputerSetupGuidesApiIface => ({\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: '/v1/computer-setup-guides',\n response: computerSetupGuideListSchema,\n signal: options?.signal,\n })\n ).guides,\n get: (ref, options) =>\n http.request({\n method: HttpMethod.Get,\n path: `/v1/computer-setup-guides/${encodePath(ref)}`,\n response: computerSetupGuideDetailSchema,\n signal: options?.signal,\n }),\n publish: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/computer-setup-guides',\n body: { schema: publishComputerSetupGuideRequestSchema, value },\n response: publishComputerSetupGuideResultSchema,\n signal,\n }),\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, ...value }) =>\n http.request({\n method: HttpMethod.Patch,\n path: `/v1/schedules/${encodePath(scheduleId)}`,\n body: { schema: updateScheduleRequestSchema, value },\n response: scheduleSchema,\n signal,\n }),\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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,OA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ACvD,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,GAAG,MAAM,MACtC,KAAK,QAAQ;AAAA,MACX,QAAQ,WAAW;AAAA,MACnB,MAAM,iBAAiB,WAAW,UAAU,CAAC;AAAA,MAC7C,MAAM,EAAE,QAAQ,6BAA6B,MAAM;AAAA,MACnD,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACL;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AgentInfoIface, type AgentListIface, type HealthResponseIface, type
|
|
1
|
+
import { type AgentInfoIface, type AgentListIface, type HealthResponseIface, type PersonIface, type PersonListIface, type RealtimeSessionResponseIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
2
|
import { type AcpApiIface } from "./acp.mjs";
|
|
3
3
|
import { type ComputerSetupGuidesApiIface, type DefinitionsApiIface, type ProvidersApiIface, type SchedulesApiIface } from "./build.mjs";
|
|
4
|
-
import { type CollectionEvent, type CollectionEventsOptionsIface } from "./collection-events.mjs";
|
|
5
4
|
import { type SignalOptionsIface } from "./context.mjs";
|
|
6
5
|
import { type ConversationsApiIface } from "./conversations.mjs";
|
|
7
6
|
import { type StreamTimingIface } from "./frame-stream.mjs";
|
|
@@ -10,9 +9,8 @@ import { type GatewayConnect, type RealtimeTransportIface } from "./realtime.mjs
|
|
|
10
9
|
import { type SessionsApiIface } from "./sessions.mjs";
|
|
11
10
|
export interface CreateClientOptionsIface {
|
|
12
11
|
/**
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
* under (console-server's `https://<console>/api/agent-platform` proxy).
|
|
12
|
+
* The agents API origin (`https://agent-session.final.ai`; its API is under
|
|
13
|
+
* `/api` and ACP at `/acp/ws`), or a base URL the API routes are mounted under.
|
|
16
14
|
*/
|
|
17
15
|
host: string;
|
|
18
16
|
auth: AgentClientAuth;
|
|
@@ -43,28 +41,19 @@ export interface AgentHandleIface {
|
|
|
43
41
|
info: (options?: SignalOptionsIface) => Promise<AgentInfoIface>;
|
|
44
42
|
}
|
|
45
43
|
export interface AgentsApiIface {
|
|
44
|
+
/**
|
|
45
|
+
* The agents the caller can use; with `projectId`, those usable there (its own and those
|
|
46
|
+
* inherited from its ancestors). Without it, everything the caller can access (an API key: its
|
|
47
|
+
* parent project and every project it is granted; a person: every project they can read).
|
|
48
|
+
*/
|
|
46
49
|
list: (options?: SignalOptionsIface & {
|
|
47
50
|
cursor?: string;
|
|
48
51
|
limit?: number;
|
|
52
|
+
projectId?: string;
|
|
49
53
|
}) => Promise<AgentListIface>;
|
|
50
54
|
/** I/O-free handle by slug or id. */
|
|
51
55
|
get: (slugOrId: string) => AgentHandleIface;
|
|
52
56
|
}
|
|
53
|
-
export interface PendingApiIface {
|
|
54
|
-
/**
|
|
55
|
-
* The caller's pending topic (`user.collection:<userId>:pending`): `acp.pending`
|
|
56
|
-
* events for requests addressed to them, and a `collection.resync` whenever
|
|
57
|
-
* `mine()` must be re-read (on every subscription, resync and while realtime is down).
|
|
58
|
-
*/
|
|
59
|
-
events: (options?: CollectionEventsOptionsIface) => AsyncIterableIterator<CollectionEvent>;
|
|
60
|
-
/** Every open permission and elicitation request whose audience includes the caller, newest first (all pages). */
|
|
61
|
-
mine: (options?: SignalOptionsIface) => Promise<PendingRequestIface[]>;
|
|
62
|
-
/** One page, newest first; pass `nextCursor` as `cursor` for the next. */
|
|
63
|
-
page: (options?: SignalOptionsIface & {
|
|
64
|
-
cursor?: string;
|
|
65
|
-
limit?: number;
|
|
66
|
-
}) => Promise<PendingRequestListIface>;
|
|
67
|
-
}
|
|
68
57
|
export interface PeopleApiIface {
|
|
69
58
|
/** One page of the caller's organization members, by name; pass `nextCursor` as `cursor` for the next. */
|
|
70
59
|
list: (options?: SignalOptionsIface & {
|
|
@@ -93,10 +82,9 @@ export interface AgentClientIface {
|
|
|
93
82
|
providers: ProvidersApiIface;
|
|
94
83
|
computerSetupGuides: ComputerSetupGuidesApiIface;
|
|
95
84
|
schedules: SchedulesApiIface;
|
|
96
|
-
pending: PendingApiIface;
|
|
97
85
|
/**
|
|
98
86
|
* ACP-native access (`/acp/ws`): an ACP v2 ClientApp connection on which the
|
|
99
|
-
*
|
|
87
|
+
* agents API is the agent. The ACP SDK loads on the first `connect`.
|
|
100
88
|
*/
|
|
101
89
|
acp: AcpApiIface;
|
|
102
90
|
/**
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
agentListSchema,
|
|
4
4
|
agentRealtimeTopics,
|
|
5
5
|
healthResponseSchema,
|
|
6
|
-
pendingRequestListSchema,
|
|
7
6
|
personListSchema,
|
|
8
7
|
realtimeSessionResponseSchema
|
|
9
8
|
} from "@finalai/agent-protocol/agent-platform";
|
|
@@ -14,13 +13,7 @@ import {
|
|
|
14
13
|
createProvidersApi,
|
|
15
14
|
createSchedulesApi
|
|
16
15
|
} from "./build.mjs";
|
|
17
|
-
import {
|
|
18
|
-
streamCollectionEvents
|
|
19
|
-
} from "./collection-events.mjs";
|
|
20
|
-
import {
|
|
21
|
-
ClientCollection,
|
|
22
|
-
encodePath
|
|
23
|
-
} from "./context.mjs";
|
|
16
|
+
import { encodePath } from "./context.mjs";
|
|
24
17
|
import { createConversationsApi } from "./conversations.mjs";
|
|
25
18
|
import { clientError, ClientErrorCode } from "./errors.mjs";
|
|
26
19
|
import { defaultStreamTiming } from "./frame-stream.mjs";
|
|
@@ -76,11 +69,12 @@ const createClient = (options) => {
|
|
|
76
69
|
http,
|
|
77
70
|
closeSignal: closing.signal,
|
|
78
71
|
realtimeUserId,
|
|
79
|
-
|
|
72
|
+
// Conversations is the only collection.
|
|
73
|
+
realtimeCollectionTopic: async () => {
|
|
80
74
|
const owner = await realtimeOwnerSession();
|
|
81
75
|
if (owner.userId == null)
|
|
82
76
|
throw new Error("Collection streams belong to users; API-key owners use session streams");
|
|
83
|
-
return
|
|
77
|
+
return agentRealtimeTopics.userConversations(owner.userId);
|
|
84
78
|
},
|
|
85
79
|
storageFetch: options.storageFetch ?? ((input, init) => globalThis.fetch(input, init)),
|
|
86
80
|
realtime: () => {
|
|
@@ -117,7 +111,11 @@ const createClient = (options) => {
|
|
|
117
111
|
list: (listOptions) => http.request({
|
|
118
112
|
method: HttpMethod.Get,
|
|
119
113
|
path: "/v1/agents",
|
|
120
|
-
query: {
|
|
114
|
+
query: {
|
|
115
|
+
cursor: listOptions?.cursor,
|
|
116
|
+
limit: listOptions?.limit,
|
|
117
|
+
projectId: listOptions?.projectId
|
|
118
|
+
},
|
|
121
119
|
response: agentListSchema,
|
|
122
120
|
signal: listOptions?.signal
|
|
123
121
|
}),
|
|
@@ -160,35 +158,7 @@ const createClient = (options) => {
|
|
|
160
158
|
providers: createProvidersApi(context),
|
|
161
159
|
computerSetupGuides: createComputerSetupGuidesApi(context),
|
|
162
160
|
schedules: createSchedulesApi(context),
|
|
163
|
-
acp: createAcpApi({ http })
|
|
164
|
-
pending: /* @__PURE__ */ (() => {
|
|
165
|
-
const page = (pageOptions) => http.request({
|
|
166
|
-
method: HttpMethod.Get,
|
|
167
|
-
path: "/v1/pending",
|
|
168
|
-
query: { cursor: pageOptions?.cursor, limit: pageOptions?.limit },
|
|
169
|
-
response: pendingRequestListSchema,
|
|
170
|
-
signal: pageOptions?.signal
|
|
171
|
-
});
|
|
172
|
-
return {
|
|
173
|
-
page,
|
|
174
|
-
events: (eventsOptions) => streamCollectionEvents({
|
|
175
|
-
context,
|
|
176
|
-
topicFor: agentRealtimeTopics.userPending,
|
|
177
|
-
collection: ClientCollection.Pending,
|
|
178
|
-
options: eventsOptions
|
|
179
|
-
}),
|
|
180
|
-
mine: async (mineOptions) => {
|
|
181
|
-
const all = [];
|
|
182
|
-
let cursor;
|
|
183
|
-
for (; ; ) {
|
|
184
|
-
const next = await page({ cursor, signal: mineOptions?.signal });
|
|
185
|
-
all.push(...next.pending);
|
|
186
|
-
if (next.nextCursor == null) return all;
|
|
187
|
-
cursor = next.nextCursor;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
})()
|
|
161
|
+
acp: createAcpApi({ http })
|
|
192
162
|
};
|
|
193
163
|
};
|
|
194
164
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/client.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n agentInfoSchema,\n agentListSchema,\n agentRealtimeTopics,\n healthResponseSchema,\n pendingRequestListSchema,\n personListSchema,\n realtimeSessionResponseSchema,\n type AgentInfoIface,\n type AgentListIface,\n type HealthResponseIface,\n type PendingRequestIface,\n type PendingRequestListIface,\n type PersonIface,\n type PersonListIface,\n type RealtimeSessionResponseIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAcpApi, type AcpApiIface } from \"./acp.mjs\";\nimport {\n createComputerSetupGuidesApi,\n createDefinitionsApi,\n createProvidersApi,\n createSchedulesApi,\n type ComputerSetupGuidesApiIface,\n type DefinitionsApiIface,\n type ProvidersApiIface,\n type SchedulesApiIface,\n} from \"./build.mjs\";\nimport {\n streamCollectionEvents,\n type CollectionEvent,\n type CollectionEventsOptionsIface,\n} from \"./collection-events.mjs\";\nimport {\n ClientCollection,\n encodePath,\n type ClientContextIface,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { createConversationsApi, type ConversationsApiIface } from \"./conversations.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport { defaultStreamTiming, type StreamTimingIface } from \"./frame-stream.mjs\";\nimport {\n createHttp,\n HttpMethod,\n type AgentClientAuth,\n type FetchIface,\n type HeadersOption,\n} from \"./http.mjs\";\nimport {\n createGatewayRealtimeTransport,\n type GatewayConnect,\n type GatewayRealtimeTransportIface,\n type RealtimeTransportIface,\n} from \"./realtime.mjs\";\nimport { createSessionsApi, type SessionsApiIface } from \"./sessions.mjs\";\n\nexport interface CreateClientOptionsIface {\n /**\n * The session service's origin (`https://agent-session.final.ai`; its API is\n * under `/api` and ACP at `/acp/ws`), or a base URL the API routes are mounted\n * under (console-server's `https://<console>/api/agent-platform` proxy).\n */\n host: string;\n auth: AgentClientAuth;\n /** Extra headers per request; console clients send their client identity header here. */\n headers?: HeadersOption;\n /** API requests (the host's routes); carries auth and caller headers. */\n fetch?: FetchIface;\n /**\n * Presigned storage requests (attachment uploads). Gets only the headers the\n * presign requires, never auth, client identity or cookies, so a storage\n * bucket's CORS and third-party hosts see nothing of the caller. Defaults to\n * `globalThis.fetch`; keep it free of header-injecting wrappers.\n */\n storageFetch?: FetchIface;\n /** console-web and console-mobile pass their realtime clients; defaults to a gateway connection. */\n realtime?: RealtimeTransportIface;\n /** Seam for the default transport's gateway connection. */\n gatewayConnect?: GatewayConnect;\n /** Seam for stream retry timing (tests). */\n timing?: Partial<StreamTimingIface>;\n /** Seam for idempotency keys and client message ids; defaults to `crypto.randomUUID`. */\n newKey?: () => string;\n /** Seam for the client clock (conversation recovery windows). */\n now?: () => number;\n}\n\nexport interface AgentHandleIface {\n slug: string;\n info: (options?: SignalOptionsIface) => Promise<AgentInfoIface>;\n}\n\nexport interface AgentsApiIface {\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number },\n ) => Promise<AgentListIface>;\n /** I/O-free handle by slug or id. */\n get: (slugOrId: string) => AgentHandleIface;\n}\n\nexport interface PendingApiIface {\n /**\n * The caller's pending topic (`user.collection:<userId>:pending`): `acp.pending`\n * events for requests addressed to them, and a `collection.resync` whenever\n * `mine()` must be re-read (on every subscription, resync and while realtime is down).\n */\n events: (options?: CollectionEventsOptionsIface) => AsyncIterableIterator<CollectionEvent>;\n /** Every open permission and elicitation request whose audience includes the caller, newest first (all pages). */\n mine: (options?: SignalOptionsIface) => Promise<PendingRequestIface[]>;\n /** One page, newest first; pass `nextCursor` as `cursor` for the next. */\n page: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number },\n ) => Promise<PendingRequestListIface>;\n}\n\nexport interface PeopleApiIface {\n /** One page of the caller's organization members, by name; pass `nextCursor` as `cursor` for the next. */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number },\n ) => Promise<PersonListIface>;\n /** Every member of the caller's organization (all pages). */\n all: (options?: SignalOptionsIface) => Promise<PersonIface[]>;\n}\n\nexport interface RealtimeApiIface {\n /**\n * Mints a gateway session (`POST /v1/realtime/session`) for the signed-in user:\n * the gateway URL, a short-lived token, and the user id realtime topics are keyed by.\n * Pass it as `createSession` to `createGatewayRealtimeTransport` when supplying a transport.\n */\n createSession: (options?: SignalOptionsIface) => Promise<RealtimeSessionResponseIface>;\n}\n\nexport interface AgentClientIface {\n health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;\n agents: AgentsApiIface;\n people: PeopleApiIface;\n realtime: RealtimeApiIface;\n sessions: SessionsApiIface;\n conversations: ConversationsApiIface;\n definitions: DefinitionsApiIface;\n providers: ProvidersApiIface;\n computerSetupGuides: ComputerSetupGuidesApiIface;\n schedules: SchedulesApiIface;\n pending: PendingApiIface;\n /**\n * ACP-native access (`/acp/ws`): an ACP v2 ClientApp connection on which the\n * session service is the agent. The ACP SDK loads on the first `connect`.\n */\n acp: AcpApiIface;\n /**\n * Ends every stream (they reject with a `client_closed` ClientError) and, when\n * the client created its own realtime transport, closes the gateway connection\n * and cancels its retries. A transport passed in `realtime` belongs to the\n * caller and is left open. Idempotent.\n */\n close: () => void;\n [Symbol.asyncDispose]: () => Promise<void>;\n}\n\nexport const createClient = (options: CreateClientOptionsIface): AgentClientIface => {\n const http = createHttp({\n host: options.host,\n auth: options.auth,\n headers: options.headers,\n fetch: options.fetch,\n });\n let realtime = options.realtime ?? null;\n let ownTransport: GatewayRealtimeTransportIface | null = null;\n const closing = new AbortController();\n const createRealtimeSession: RealtimeApiIface['createSession'] = (sessionOptions) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/realtime/session',\n response: realtimeSessionResponseSchema,\n signal: sessionOptions?.signal,\n });\n let realtimeOwner: Promise<RealtimeSessionResponseIface> | null = null;\n const realtimeOwnerSession = () => {\n if (realtimeOwner != null) return realtimeOwner;\n const pending = createRealtimeSession({ signal: closing.signal });\n realtimeOwner = pending;\n void pending.catch(() => {\n if (realtimeOwner === pending) realtimeOwner = null;\n });\n return pending;\n };\n let realtimeUser: Promise<string> | null = null;\n // Shared by every stream, so it is cancelled only with the client, never by one caller.\n const realtimeUserId: ClientContextIface['realtimeUserId'] = () => {\n if (realtimeUser != null) return realtimeUser;\n const pending = realtimeOwnerSession().then((session) => {\n if (session.userId == null)\n throw new Error('This client authenticates as an API-key owner, not a user');\n return session.userId;\n });\n realtimeUser = pending;\n // A failed (or aborted) read is not cached.\n pending.catch(() => {\n if (realtimeUser === pending) realtimeUser = null;\n });\n return pending;\n };\n const context: ClientContextIface = {\n http,\n closeSignal: closing.signal,\n realtimeUserId,\n realtimeCollectionTopic: async (collection) => {\n const owner = await realtimeOwnerSession();\n // Organization and team keys are no conversation members: they reach agents through channels.\n if (owner.userId == null)\n throw new Error('Collection streams belong to users; API-key owners use session streams');\n return collection === ClientCollection.Pending\n ? agentRealtimeTopics.userPending(owner.userId)\n : agentRealtimeTopics.userConversations(owner.userId);\n },\n storageFetch: options.storageFetch ?? ((input, init) => globalThis.fetch(input, init)),\n realtime: () => {\n if (realtime != null) return realtime;\n ownTransport = createGatewayRealtimeTransport({\n createSession: () => createRealtimeSession(),\n connect: options.gatewayConnect,\n });\n if (closing.signal.aborted) ownTransport.close();\n realtime = ownTransport;\n return realtime;\n },\n timing: { ...defaultStreamTiming, ...options.timing },\n newKey: options.newKey ?? (() => globalThis.crypto.randomUUID()),\n now: options.now ?? Date.now,\n };\n\n const close = (): void => {\n if (closing.signal.aborted) return;\n closing.abort(\n clientError({ message: 'Agent client closed', status: 0, code: ClientErrorCode.Closed }),\n );\n ownTransport?.close();\n };\n\n return {\n close,\n [Symbol.asyncDispose]: async () => close(),\n health: (healthOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/health',\n response: healthResponseSchema,\n signal: healthOptions?.signal,\n }),\n agents: {\n list: (listOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/agents',\n query: { cursor: listOptions?.cursor, limit: listOptions?.limit },\n response: agentListSchema,\n signal: listOptions?.signal,\n }),\n get: (slugOrId) => ({\n slug: slugOrId,\n info: (infoOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: `/v1/agents/${encodePath(slugOrId)}`,\n response: agentInfoSchema,\n signal: infoOptions?.signal,\n }),\n }),\n },\n people: (() => {\n const list: PeopleApiIface['list'] = (listOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/people',\n query: { cursor: listOptions?.cursor, limit: listOptions?.limit },\n response: personListSchema,\n signal: listOptions?.signal,\n });\n return {\n list,\n all: async (allOptions) => {\n const all: PersonIface[] = [];\n let cursor: string | undefined;\n for (;;) {\n const next = await list({ cursor, signal: allOptions?.signal });\n all.push(...next.people);\n if (next.nextCursor == null) return all;\n cursor = next.nextCursor;\n }\n },\n };\n })(),\n realtime: { createSession: createRealtimeSession },\n sessions: createSessionsApi(context),\n conversations: createConversationsApi(context),\n definitions: createDefinitionsApi(context),\n providers: createProvidersApi(context),\n computerSetupGuides: createComputerSetupGuidesApi(context),\n schedules: createSchedulesApi(context),\n acp: createAcpApi({ http }),\n pending: (() => {\n const page: PendingApiIface['page'] = (pageOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/pending',\n query: { cursor: pageOptions?.cursor, limit: pageOptions?.limit },\n response: pendingRequestListSchema,\n signal: pageOptions?.signal,\n });\n return {\n page,\n events: (eventsOptions) =>\n streamCollectionEvents({\n context,\n topicFor: agentRealtimeTopics.userPending,\n collection: ClientCollection.Pending,\n options: eventsOptions,\n }),\n mine: async (mineOptions) => {\n const all: PendingRequestIface[] = [];\n let cursor: string | undefined;\n for (;;) {\n const next = await page({ cursor, signal: mineOptions?.signal });\n all.push(...next.pending);\n if (next.nextCursor == null) return all;\n cursor = next.nextCursor;\n }\n },\n };\n })(),\n };\n};\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n agentInfoSchema,\n agentListSchema,\n agentRealtimeTopics,\n healthResponseSchema,\n personListSchema,\n realtimeSessionResponseSchema,\n type AgentInfoIface,\n type AgentListIface,\n type HealthResponseIface,\n type PersonIface,\n type PersonListIface,\n type RealtimeSessionResponseIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAcpApi, type AcpApiIface } from \"./acp.mjs\";\nimport {\n createComputerSetupGuidesApi,\n createDefinitionsApi,\n createProvidersApi,\n createSchedulesApi,\n type ComputerSetupGuidesApiIface,\n type DefinitionsApiIface,\n type ProvidersApiIface,\n type SchedulesApiIface,\n} from \"./build.mjs\";\nimport { encodePath, type ClientContextIface, type SignalOptionsIface } from \"./context.mjs\";\nimport { createConversationsApi, type ConversationsApiIface } from \"./conversations.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport { defaultStreamTiming, type StreamTimingIface } from \"./frame-stream.mjs\";\nimport {\n createHttp,\n HttpMethod,\n type AgentClientAuth,\n type FetchIface,\n type HeadersOption,\n} from \"./http.mjs\";\nimport {\n createGatewayRealtimeTransport,\n type GatewayConnect,\n type GatewayRealtimeTransportIface,\n type RealtimeTransportIface,\n} from \"./realtime.mjs\";\nimport { createSessionsApi, type SessionsApiIface } from \"./sessions.mjs\";\n\nexport interface CreateClientOptionsIface {\n /**\n * The agents API origin (`https://agent-session.final.ai`; its API is under\n * `/api` and ACP at `/acp/ws`), or a base URL the API routes are mounted under.\n */\n host: string;\n auth: AgentClientAuth;\n /** Extra headers per request; console clients send their client identity header here. */\n headers?: HeadersOption;\n /** API requests (the host's routes); carries auth and caller headers. */\n fetch?: FetchIface;\n /**\n * Presigned storage requests (attachment uploads). Gets only the headers the\n * presign requires, never auth, client identity or cookies, so a storage\n * bucket's CORS and third-party hosts see nothing of the caller. Defaults to\n * `globalThis.fetch`; keep it free of header-injecting wrappers.\n */\n storageFetch?: FetchIface;\n /** console-web and console-mobile pass their realtime clients; defaults to a gateway connection. */\n realtime?: RealtimeTransportIface;\n /** Seam for the default transport's gateway connection. */\n gatewayConnect?: GatewayConnect;\n /** Seam for stream retry timing (tests). */\n timing?: Partial<StreamTimingIface>;\n /** Seam for idempotency keys and client message ids; defaults to `crypto.randomUUID`. */\n newKey?: () => string;\n /** Seam for the client clock (conversation recovery windows). */\n now?: () => number;\n}\n\nexport interface AgentHandleIface {\n slug: string;\n info: (options?: SignalOptionsIface) => Promise<AgentInfoIface>;\n}\n\nexport interface AgentsApiIface {\n /**\n * The agents the caller can use; with `projectId`, those usable there (its own and those\n * inherited from its ancestors). Without it, everything the caller can access (an API key: its\n * parent project and every project it is granted; a person: every project they can read).\n */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number; projectId?: string },\n ) => Promise<AgentListIface>;\n /** I/O-free handle by slug or id. */\n get: (slugOrId: string) => AgentHandleIface;\n}\n\nexport interface PeopleApiIface {\n /** One page of the caller's organization members, by name; pass `nextCursor` as `cursor` for the next. */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number },\n ) => Promise<PersonListIface>;\n /** Every member of the caller's organization (all pages). */\n all: (options?: SignalOptionsIface) => Promise<PersonIface[]>;\n}\n\nexport interface RealtimeApiIface {\n /**\n * Mints a gateway session (`POST /v1/realtime/session`) for the signed-in user:\n * the gateway URL, a short-lived token, and the user id realtime topics are keyed by.\n * Pass it as `createSession` to `createGatewayRealtimeTransport` when supplying a transport.\n */\n createSession: (options?: SignalOptionsIface) => Promise<RealtimeSessionResponseIface>;\n}\n\nexport interface AgentClientIface {\n health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;\n agents: AgentsApiIface;\n people: PeopleApiIface;\n realtime: RealtimeApiIface;\n sessions: SessionsApiIface;\n conversations: ConversationsApiIface;\n definitions: DefinitionsApiIface;\n providers: ProvidersApiIface;\n computerSetupGuides: ComputerSetupGuidesApiIface;\n schedules: SchedulesApiIface;\n /**\n * ACP-native access (`/acp/ws`): an ACP v2 ClientApp connection on which the\n * agents API is the agent. The ACP SDK loads on the first `connect`.\n */\n acp: AcpApiIface;\n /**\n * Ends every stream (they reject with a `client_closed` ClientError) and, when\n * the client created its own realtime transport, closes the gateway connection\n * and cancels its retries. A transport passed in `realtime` belongs to the\n * caller and is left open. Idempotent.\n */\n close: () => void;\n [Symbol.asyncDispose]: () => Promise<void>;\n}\n\nexport const createClient = (options: CreateClientOptionsIface): AgentClientIface => {\n const http = createHttp({\n host: options.host,\n auth: options.auth,\n headers: options.headers,\n fetch: options.fetch,\n });\n let realtime = options.realtime ?? null;\n let ownTransport: GatewayRealtimeTransportIface | null = null;\n const closing = new AbortController();\n const createRealtimeSession: RealtimeApiIface['createSession'] = (sessionOptions) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/realtime/session',\n response: realtimeSessionResponseSchema,\n signal: sessionOptions?.signal,\n });\n let realtimeOwner: Promise<RealtimeSessionResponseIface> | null = null;\n const realtimeOwnerSession = () => {\n if (realtimeOwner != null) return realtimeOwner;\n const pending = createRealtimeSession({ signal: closing.signal });\n realtimeOwner = pending;\n void pending.catch(() => {\n if (realtimeOwner === pending) realtimeOwner = null;\n });\n return pending;\n };\n let realtimeUser: Promise<string> | null = null;\n // Shared by every stream, so it is cancelled only with the client, never by one caller.\n const realtimeUserId: ClientContextIface['realtimeUserId'] = () => {\n if (realtimeUser != null) return realtimeUser;\n const pending = realtimeOwnerSession().then((session) => {\n if (session.userId == null)\n throw new Error('This client authenticates as an API-key owner, not a user');\n return session.userId;\n });\n realtimeUser = pending;\n // A failed (or aborted) read is not cached.\n pending.catch(() => {\n if (realtimeUser === pending) realtimeUser = null;\n });\n return pending;\n };\n const context: ClientContextIface = {\n http,\n closeSignal: closing.signal,\n realtimeUserId,\n // Conversations is the only collection.\n realtimeCollectionTopic: async () => {\n const owner = await realtimeOwnerSession();\n // API keys act in their project, not as members: they reach agents through channels.\n if (owner.userId == null)\n throw new Error('Collection streams belong to users; API-key owners use session streams');\n return agentRealtimeTopics.userConversations(owner.userId);\n },\n storageFetch: options.storageFetch ?? ((input, init) => globalThis.fetch(input, init)),\n realtime: () => {\n if (realtime != null) return realtime;\n ownTransport = createGatewayRealtimeTransport({\n createSession: () => createRealtimeSession(),\n connect: options.gatewayConnect,\n });\n if (closing.signal.aborted) ownTransport.close();\n realtime = ownTransport;\n return realtime;\n },\n timing: { ...defaultStreamTiming, ...options.timing },\n newKey: options.newKey ?? (() => globalThis.crypto.randomUUID()),\n now: options.now ?? Date.now,\n };\n\n const close = (): void => {\n if (closing.signal.aborted) return;\n closing.abort(\n clientError({ message: 'Agent client closed', status: 0, code: ClientErrorCode.Closed }),\n );\n ownTransport?.close();\n };\n\n return {\n close,\n [Symbol.asyncDispose]: async () => close(),\n health: (healthOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/health',\n response: healthResponseSchema,\n signal: healthOptions?.signal,\n }),\n agents: {\n list: (listOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/agents',\n query: {\n cursor: listOptions?.cursor,\n limit: listOptions?.limit,\n projectId: listOptions?.projectId,\n },\n response: agentListSchema,\n signal: listOptions?.signal,\n }),\n get: (slugOrId) => ({\n slug: slugOrId,\n info: (infoOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: `/v1/agents/${encodePath(slugOrId)}`,\n response: agentInfoSchema,\n signal: infoOptions?.signal,\n }),\n }),\n },\n people: (() => {\n const list: PeopleApiIface['list'] = (listOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/people',\n query: { cursor: listOptions?.cursor, limit: listOptions?.limit },\n response: personListSchema,\n signal: listOptions?.signal,\n });\n return {\n list,\n all: async (allOptions) => {\n const all: PersonIface[] = [];\n let cursor: string | undefined;\n for (;;) {\n const next = await list({ cursor, signal: allOptions?.signal });\n all.push(...next.people);\n if (next.nextCursor == null) return all;\n cursor = next.nextCursor;\n }\n },\n };\n })(),\n realtime: { createSession: createRealtimeSession },\n sessions: createSessionsApi(context),\n conversations: createConversationsApi(context),\n definitions: createDefinitionsApi(context),\n providers: createProvidersApi(context),\n computerSetupGuides: createComputerSetupGuidesApi(context),\n schedules: createSchedulesApi(context),\n acp: createAcpApi({ http }),\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP,SAAS,oBAAsC;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,kBAAoE;AAC7E,SAAS,8BAA0D;AACnE,SAAS,aAAa,uBAAuB;AAC7C,SAAS,2BAAmD;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAIK;AACP,SAAS,yBAAgD;AA8FlD,MAAM,eAAe,CAAC,YAAwD;AACnF,QAAM,OAAO,WAAW;AAAA,IACtB,MAAM,QAAQ;AAAA,IACd,MAAM,QAAQ;AAAA,IACd,SAAS,QAAQ;AAAA,IACjB,OAAO,QAAQ;AAAA,EACjB,CAAC;AACD,MAAI,WAAW,QAAQ,YAAY;AACnC,MAAI,eAAqD;AACzD,QAAM,UAAU,IAAI,gBAAgB;AACpC,QAAM,wBAA2D,CAAC,mBAChE,KAAK,QAAQ;AAAA,IACX,QAAQ,WAAW;AAAA,IACnB,MAAM;AAAA,IACN,UAAU;AAAA,IACV,QAAQ,gBAA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ACvB,CAAC;AACH,aAAO;AAAA,QACL;AAAA,QACA,KAAK,OAAO,eAAe;AACzB,gBAAM,MAAqB,CAAC;AAC5B,cAAI;AACJ,qBAAS;AACP,kBAAM,OAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAC9D,gBAAI,KAAK,GAAG,KAAK,MAAM;AACvB,gBAAI,KAAK,cAAc,KAAM,QAAO;AACpC,qBAAS,KAAK;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,IACF,GAAG;AAAA,IACH,UAAU,EAAE,eAAe,sBAAsB;AAAA,IACjD,UAAU,kBAAkB,OAAO;AAAA,IACnC,eAAe,uBAAuB,OAAO;AAAA,IAC7C,aAAa,qBAAqB,OAAO;AAAA,IACzC,WAAW,mBAAmB,OAAO;AAAA,IACrC,qBAAqB,6BAA6B,OAAO;AAAA,IACzD,WAAW,mBAAmB,OAAO;AAAA,IACrC,KAAK,aAAa,EAAE,KAAK,CAAC;AAAA,EAC5B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientCollection, ClientContextIface, SignalOptionsIface } from "./context.mjs";
|
|
2
2
|
import type { ConversationEvent } from "./conversations.mjs";
|
|
3
3
|
export declare enum CollectionEventKind {
|
|
4
|
-
/** Re-read the collection (`conversations.list()
|
|
4
|
+
/** Re-read the collection (`conversations.list()`); events may have been missed. */
|
|
5
5
|
Resync = "collection.resync"
|
|
6
6
|
}
|
|
7
7
|
export declare enum CollectionResyncReason {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/collection-events.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n agentRealtimeFrameSchema,\n AgentRealtimeFrameType,\n parseAgentRealtimeEvent,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAsyncQueue, failOnAbort } from \"./async-queue.mjs\";\nimport type { ClientCollection, ClientContextIface, SignalOptionsIface } from \"./context.mjs\";\nimport type { ConversationEvent } from \"./conversations.mjs\";\nimport {\n isRetryableClientError,\n isTerminalRealtimeError,\n realtimeSubscriptionError,\n} from \"./errors.mjs\";\nimport type { RealtimeTransportFrameIface } from \"./realtime.mjs\";\n\n// The caller's collection
|
|
4
|
+
"sourcesContent": ["import {\n agentRealtimeFrameSchema,\n AgentRealtimeFrameType,\n parseAgentRealtimeEvent,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAsyncQueue, failOnAbort } from \"./async-queue.mjs\";\nimport type { ClientCollection, ClientContextIface, SignalOptionsIface } from \"./context.mjs\";\nimport type { ConversationEvent } from \"./conversations.mjs\";\nimport {\n isRetryableClientError,\n isTerminalRealtimeError,\n realtimeSubscriptionError,\n} from \"./errors.mjs\";\nimport type { RealtimeTransportFrameIface } from \"./realtime.mjs\";\n\n// The caller's collection topic (`user.collection:<userId>:conversations`).\n// It carries no replay, so a stream says when the\n// caller must re-read the collection over HTTP: on every (re)subscription and\n// resync, and while the realtime transport reports errors.\n\nexport enum CollectionEventKind {\n /** Re-read the collection (`conversations.list()`); events may have been missed. */\n Resync = 'collection.resync',\n}\n\nexport enum CollectionResyncReason {\n Subscribed = 'subscribed',\n ResyncRequired = 'resync_required',\n /** The realtime transport is down; repeated every `timing.conversationPollIntervalMs`. */\n Degraded = 'degraded',\n}\n\nexport interface CollectionResyncEventIface {\n kind: CollectionEventKind.Resync;\n /** Null while the signed-in user, and so the topic, could not be read yet. */\n topic: string | null;\n reason: CollectionResyncReason;\n}\n\n/** A realtime event of the collection topic, or a cue to re-read the collection. */\nexport type CollectionEvent = ConversationEvent | CollectionResyncEventIface;\n\nexport interface CollectionEventsOptionsIface extends SignalOptionsIface {\n /** Keep streaming; false ends after the first resync. Defaults to true. */\n follow?: boolean;\n /**\n * The signed-in user the topics are keyed by. Defaults to the user of a\n * minted realtime session (`realtime.createSession()`).\n */\n userId?: string;\n}\n\nconst MAX_LOOKUP_RETRY_MS = 30_000;\n\nexport const streamCollectionEvents = (args: {\n context: ClientContextIface;\n topicFor: (userId: string) => string;\n collection?: ClientCollection;\n options: CollectionEventsOptionsIface | undefined;\n}): AsyncIterableIterator<CollectionEvent> => {\n const follow = args.options?.follow ?? true;\n const controller = new AbortController();\n const signal = AbortSignal.any([\n controller.signal,\n args.context.closeSignal,\n ...(args.options?.signal == null ? [] : [args.options.signal]),\n ]);\n let unsubscribe: (() => void) | null = null;\n let pollTimer: ReturnType<typeof setTimeout> | null = null;\n let lookupTimer: ReturnType<typeof setTimeout> | null = null;\n const clearPoll = (): void => {\n if (pollTimer != null) clearTimeout(pollTimer);\n pollTimer = null;\n };\n let detachAbort: () => void = () => {};\n let detachClose: () => void = () => {};\n const queue = createAsyncQueue<CollectionEvent>(() => {\n controller.abort();\n clearPoll();\n if (lookupTimer != null) clearTimeout(lookupTimer);\n unsubscribe?.();\n detachAbort();\n detachClose();\n });\n\n const resync = (topic: string | null, reason: CollectionResyncReason): void => {\n queue.push({ kind: CollectionEventKind.Resync, topic, reason });\n if (!follow) queue.end();\n };\n\n const degrade = (topic: string): void => {\n if (pollTimer != null || queue.closed()) return;\n resync(topic, CollectionResyncReason.Degraded);\n if (!follow || queue.closed()) return;\n pollTimer = setTimeout(() => {\n pollTimer = null;\n degrade(topic);\n }, args.context.timing.conversationPollIntervalMs);\n };\n\n const onFrame =\n (topic: string) =>\n (raw: RealtimeTransportFrameIface): void => {\n const frame = agentRealtimeFrameSchema.safeParse(raw);\n if (!frame.success || queue.closed()) return;\n switch (frame.data.type) {\n case AgentRealtimeFrameType.Event: {\n const envelope = frame.data;\n queue.push({\n ...parseAgentRealtimeEvent(envelope),\n topic: envelope.topic,\n cursor: envelope.cursor,\n createdAt: envelope.createdAt,\n replayed: false,\n });\n return;\n }\n case AgentRealtimeFrameType.Subscribed:\n clearPoll();\n resync(topic, CollectionResyncReason.Subscribed);\n return;\n case AgentRealtimeFrameType.ResyncRequired:\n resync(topic, CollectionResyncReason.ResyncRequired);\n return;\n case AgentRealtimeFrameType.Error:\n if (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 // The transport resubscribes; until then the caller re-reads periodically.\n degrade(topic);\n return;\n default:\n return;\n }\n };\n\n detachAbort = failOnAbort(queue, signal);\n detachClose = failOnAbort(queue, args.context.closeSignal);\n const userId = args.options?.userId;\n let lookupFailures = 0;\n const start = (): void => {\n lookupTimer = null;\n if (queue.closed()) return;\n const topic =\n userId != null\n ? Promise.resolve(args.topicFor(userId))\n : args.collection != null && args.context.realtimeCollectionTopic != null\n ? args.context.realtimeCollectionTopic(args.collection)\n : args.context.realtimeUserId().then(args.topicFor);\n void topic.then(\n (topic) => {\n if (queue.closed()) return;\n const stop = args.context.realtime().subscribe(topic, onFrame(topic));\n if (queue.closed()) stop();\n else unsubscribe = stop;\n },\n (cause: unknown) => {\n if (queue.closed()) return;\n if (!isRetryableClientError(cause)) {\n queue.fail(cause);\n return;\n }\n // The user lookup is unreachable: the caller re-reads meanwhile, and it is retried.\n resync(null, CollectionResyncReason.Degraded);\n if (queue.closed()) return;\n const delay = Math.min(\n MAX_LOOKUP_RETRY_MS,\n args.context.timing.conversationPollIntervalMs * 2 ** lookupFailures,\n );\n lookupFailures += 1;\n lookupTimer = setTimeout(start, delay);\n },\n );\n };\n start();\n return queue.iterator;\n};\n"],
|
|
5
5
|
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,mBAAmB;AAG9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQA,IAAK,sBAAL,kBAAKA,yBAAL;AAEL,EAAAA,qBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;AAKL,IAAK,yBAAL,kBAAKC,4BAAL;AACL,EAAAA,wBAAA,gBAAa;AAC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AACpB,cAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,UAAUA,QAAO,QAAQA,MAAK,CAAC;AACpE,YAAI,MAAM,OAAO,EAAG,MAAK;AAAA,YACpB,eAAc;AAAA,MACrB;AAAA,MACA,CAAC,UAAmB;AAClB,YAAI,MAAM,OAAO,EAAG;AACpB,YAAI,CAAC,uBAAuB,KAAK,GAAG;AAClC,gBAAM,KAAK,KAAK;AAChB;AAAA,QACF;AAEA,eAAO,MAAM,yBAA+B;AAC5C,YAAI,MAAM,OAAO,EAAG;AACpB,cAAM,QAAQ,KAAK;AAAA,UACjB;AAAA,UACA,KAAK,QAAQ,OAAO,6BAA6B,KAAK;AAAA,QACxD;AACA,0BAAkB;AAClB,sBAAc,WAAW,OAAO,KAAK;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACA,QAAM;AACN,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": ["CollectionEventKind", "CollectionResyncReason", "topic"]
|
|
7
7
|
}
|
|
@@ -2,8 +2,7 @@ import type { StreamTimingIface } from "./frame-stream.mjs";
|
|
|
2
2
|
import type { FetchIface, HttpIface } from "./http.mjs";
|
|
3
3
|
import type { RealtimeTransportIface } from "./realtime.mjs";
|
|
4
4
|
export declare enum ClientCollection {
|
|
5
|
-
Conversations = "conversations"
|
|
6
|
-
Pending = "pending"
|
|
5
|
+
Conversations = "conversations"
|
|
7
6
|
}
|
|
8
7
|
/** What every API group gets from `createClient`. */
|
|
9
8
|
export interface ClientContextIface {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
var ClientCollection = /* @__PURE__ */ ((ClientCollection2) => {
|
|
2
2
|
ClientCollection2["Conversations"] = "conversations";
|
|
3
|
-
ClientCollection2["Pending"] = "pending";
|
|
4
3
|
return ClientCollection2;
|
|
5
4
|
})(ClientCollection || {});
|
|
6
5
|
const encodePath = (segment) => encodeURIComponent(segment);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/context.ts"],
|
|
4
|
-
"sourcesContent": ["import type { StreamTimingIface } from \"./frame-stream.mjs\";\nimport type { FetchIface, HttpIface } from \"./http.mjs\";\nimport type { RealtimeTransportIface } from \"./realtime.mjs\";\n\nexport enum ClientCollection {\n Conversations = 'conversations',\n
|
|
5
|
-
"mappings": "AAIO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,mBAAgB;
|
|
4
|
+
"sourcesContent": ["import type { StreamTimingIface } from \"./frame-stream.mjs\";\nimport type { FetchIface, HttpIface } from \"./http.mjs\";\nimport type { RealtimeTransportIface } from \"./realtime.mjs\";\n\nexport enum ClientCollection {\n Conversations = 'conversations',\n}\n\n/** What every API group gets from `createClient`. */\nexport interface ClientContextIface {\n http: HttpIface;\n /** Aborts when `client.close()` is called; every stream ends with it. */\n closeSignal: AbortSignal;\n /** Presigned storage requests: no API credentials, client identity or cookies. */\n storageFetch: FetchIface;\n /** Resolved on first use, so clients that never stream never mint a gateway token. */\n realtime: () => RealtimeTransportIface;\n /** The signed-in user realtime topics are keyed by (a minted realtime session's); cached. */\n realtimeUserId: () => Promise<string>;\n realtimeCollectionTopic?: (collection: ClientCollection) => Promise<string>;\n timing: StreamTimingIface;\n /** Idempotency keys and client message ids. */\n newKey: () => string;\n /** Client clock in epoch ms. */\n now: () => number;\n}\n\nexport interface SignalOptionsIface {\n signal?: AbortSignal;\n}\n\n/** Author calls may use the wire spelling or the exported enum constant. */\nexport type EnumInput<E extends string> = E | `${E}`;\n\nexport const encodePath = (segment: string): string => encodeURIComponent(segment);\n"],
|
|
5
|
+
"mappings": "AAIO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,mBAAgB;AADN,SAAAA;AAAA,GAAA;AA8BL,MAAM,aAAa,CAAC,YAA4B,mBAAmB,OAAO;",
|
|
6
6
|
"names": ["ClientCollection"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ProcessInspectionRequestIface, type ProcessInspectionResultIface } from '@finalai/agent-protocol';
|
|
2
|
-
import { AgentSessionState, type PostConversationEventResponseIface, type AgentRealtimeEvent, type AgentTurnPolicy, type AttachmentDownloadIface, type AttachmentUploadIface, type ContentInput, type ConversationIface, type ConversationKind, type ConversationLinkIface, type ConversationListIface, type ConversationMessageIface, type ConversationMessagesPageIface, type ConversationSandboxIface, type ConversationScheduleIface, type CreateConversationScheduleRequestIface, type DecisionsPageIface, type MessageDeliveryIface, type ParticipantIface, type ParticipantInput, type PostConversationEventRequestIface, type ReactionIface, type ReadStateIface, type
|
|
2
|
+
import { AgentSessionState, type PostConversationEventResponseIface, type AgentRealtimeEvent, type AgentTurnPolicy, type AttachmentDownloadIface, type AttachmentUploadIface, type ContentInput, type ConversationIface, type ConversationKind, type ConversationLinkIface, type ConversationListIface, type ConversationMessageIface, type ConversationMessagesPageIface, type ConversationSandboxIface, type ConversationScheduleIface, type CreateConversationScheduleRequestIface, type DecisionsPageIface, type MessageDeliveryIface, type ParticipantIface, type ParticipantInput, type PostConversationEventRequestIface, type ReactionIface, type ReadStateIface, type RespondDecisionResponseIface, type SandboxDirectoryIface, type SandboxEditorSessionIface, type SandboxFileIface, type SandboxPathIface, type SandboxPreviewType, type SandboxSearchIface, type SearchMessagesPageIface, type UpdateConversationRequestIface, type UpdateConversationScheduleRequestIface, type UpdateParticipantRequestIface, type WireFallback } from '@finalai/agent-protocol/agent-platform';
|
|
3
3
|
import { type CollectionEvent, type CollectionEventsOptionsIface } from "./collection-events.mjs";
|
|
4
4
|
import { type ClientContextIface, type EnumInput, type SignalOptionsIface } from "./context.mjs";
|
|
5
5
|
import { type RespondArgs } from "./sessions.mjs";
|
|
@@ -24,7 +24,7 @@ export interface ConversationEventMetaIface {
|
|
|
24
24
|
/** True for messages the SDK fetched over HTTP to fill a realtime gap. */
|
|
25
25
|
replayed: boolean;
|
|
26
26
|
}
|
|
27
|
-
/** A realtime event of the conversation topic, flattened (`event.message`, `event.
|
|
27
|
+
/** A realtime event of the conversation topic, flattened (`event.message`, `event.decision`). */
|
|
28
28
|
export type ConversationEvent = AgentRealtimeEvent & ConversationEventMetaIface;
|
|
29
29
|
export interface ConversationEventsOptionsIface extends SignalOptionsIface {
|
|
30
30
|
/** Keep streaming; false ends once the subscription is current. Defaults to true. */
|
|
@@ -49,9 +49,10 @@ export interface ConversationEventsOptionsIface extends SignalOptionsIface {
|
|
|
49
49
|
/**
|
|
50
50
|
* Also recover what only realtime carries (default true). On every
|
|
51
51
|
* (re)subscribe, resync and fallback poll the stream re-reads the open
|
|
52
|
-
* permission and elicitation
|
|
53
|
-
* and emits replayed `
|
|
54
|
-
* has not emitted, `resolved` for one it emitted open that no
|
|
52
|
+
* permission and elicitation decisions of the conversation's agent sessions
|
|
53
|
+
* and emits replayed `decision.changed` events: `created` for an open
|
|
54
|
+
* decision it has not emitted, `resolved` for one it emitted open that no
|
|
55
|
+
* longer is. And
|
|
55
56
|
* for every turn it saw start whose session is no longer running, it emits a
|
|
56
57
|
* replayed `conversation.turn.ended` (stop reason null). Turns that started
|
|
57
58
|
* and ended while it was away arrive only as messages.
|
|
@@ -155,7 +156,7 @@ export interface ConversationHandleIface {
|
|
|
155
156
|
* source is accepted once; the receipt says whether the agent was prompted.
|
|
156
157
|
*/
|
|
157
158
|
postEvent: (event: PostConversationEventRequestIface, options?: SignalOptionsIface) => Promise<PostConversationEventResponseIface>;
|
|
158
|
-
respond: (args: RespondArgs, options?: SignalOptionsIface) => Promise<
|
|
159
|
+
respond: (args: RespondArgs, options?: SignalOptionsIface) => Promise<RespondDecisionResponseIface>;
|
|
159
160
|
/** Stops the agents' running turns in this conversation. */
|
|
160
161
|
cancel: (options?: SignalOptionsIface & {
|
|
161
162
|
reason?: string;
|
|
@@ -303,7 +304,7 @@ export interface ConversationAgentTurnIface {
|
|
|
303
304
|
participantId: string;
|
|
304
305
|
sessionId: string;
|
|
305
306
|
state: AgentSessionState | WireFallback;
|
|
306
|
-
/** A turn is running or waiting on a
|
|
307
|
+
/** A turn is running or waiting on a decision. */
|
|
307
308
|
running: boolean;
|
|
308
309
|
}
|
|
309
310
|
/** Session states in which a turn is open. */
|
|
@@ -312,23 +313,41 @@ export interface OpenedConversationIface extends ConversationHandleIface {
|
|
|
312
313
|
conversation: ConversationIface;
|
|
313
314
|
}
|
|
314
315
|
export interface CreateConversationArgsIface extends SignalOptionsIface {
|
|
316
|
+
/**
|
|
317
|
+
* The project (`prj_...`) a group chat is created in (editors only); omitted,
|
|
318
|
+
* the API key's parent project (a signed-in person's: My Work).
|
|
319
|
+
* A direct chat is the caller's own and lives in their personal project.
|
|
320
|
+
*/
|
|
321
|
+
projectId?: string;
|
|
315
322
|
kind: EnumInput<ConversationKind>;
|
|
316
323
|
title?: string;
|
|
317
324
|
participants: ParticipantCreateInput[];
|
|
318
325
|
turnPolicy?: EnumInput<AgentTurnPolicy>;
|
|
319
326
|
}
|
|
320
327
|
export interface ConversationsApiIface {
|
|
328
|
+
/**
|
|
329
|
+
* The conversations the caller can read.
|
|
330
|
+
* Without `projectId`: everything the caller can access (an API key: its parent project and
|
|
331
|
+
* every project it is granted; a person: every project they can read). `projectId` narrows to
|
|
332
|
+
* that project and the projects below it.
|
|
333
|
+
*/
|
|
321
334
|
list: (options?: SignalOptionsIface & {
|
|
322
335
|
cursor?: string;
|
|
323
336
|
limit?: number;
|
|
324
337
|
includeArchived?: boolean;
|
|
338
|
+
projectId?: string;
|
|
325
339
|
}) => Promise<ConversationListIface>;
|
|
326
340
|
/** Finds or creates the caller's direct conversation with an agent. */
|
|
327
341
|
direct: (args: {
|
|
328
342
|
agent: string;
|
|
329
343
|
} & SignalOptionsIface) => Promise<OpenedConversationIface>;
|
|
330
|
-
/**
|
|
331
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Finds or creates the caller's own Project Agent thread in `projectId`, which
|
|
346
|
+
* omitted, is the API key's parent project (a signed-in person's: My Work).
|
|
347
|
+
*/
|
|
348
|
+
home: (options?: SignalOptionsIface & {
|
|
349
|
+
projectId?: string;
|
|
350
|
+
}) => Promise<OpenedConversationIface>;
|
|
332
351
|
create: (args: CreateConversationArgsIface) => Promise<OpenedConversationIface>;
|
|
333
352
|
/** I/O-free handle. */
|
|
334
353
|
get: (conversationId: string) => ConversationHandleIface;
|
|
@@ -346,10 +365,16 @@ export interface ConversationsApiIface {
|
|
|
346
365
|
* subscription, resync and while realtime is down).
|
|
347
366
|
*/
|
|
348
367
|
listEvents: (options?: CollectionEventsOptionsIface) => AsyncIterableIterator<CollectionEvent>;
|
|
349
|
-
/**
|
|
368
|
+
/**
|
|
369
|
+
* What awaits the caller's answer across conversations.
|
|
370
|
+
* Without `projectId`: everything the caller can access (an API key: its parent project and
|
|
371
|
+
* every project it is granted; a person: every project they can read). `projectId` narrows to
|
|
372
|
+
* that project and the projects below it.
|
|
373
|
+
*/
|
|
350
374
|
decisions: (options?: SignalOptionsIface & {
|
|
351
375
|
cursor?: string;
|
|
352
376
|
limit?: number;
|
|
377
|
+
projectId?: string;
|
|
353
378
|
}) => Promise<DecisionsPageIface>;
|
|
354
379
|
}
|
|
355
380
|
/**
|