@finalai/agents 0.13.0 → 0.14.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/README.md +1 -1
- package/dist/modules/agent-client/channels.mjs +9 -1
- package/dist/modules/agent-client/channels.mjs.map +2 -2
- package/dist/modules/agent-client/client.d.mts +11 -1
- package/dist/modules/agent-client/client.mjs +9 -0
- package/dist/modules/agent-client/client.mjs.map +2 -2
- package/dist/modules/agent-client/conversations.d.mts +17 -25
- package/dist/modules/agent-client/conversations.mjs +10 -62
- package/dist/modules/agent-client/conversations.mjs.map +2 -2
- package/dist/modules/agent-client/index.d.mts +2 -0
- package/dist/modules/agent-client/index.mjs.map +2 -2
- package/dist/modules/agent-client/integrations.d.mts +5 -1
- package/dist/modules/agent-client/integrations.mjs +9 -1
- package/dist/modules/agent-client/integrations.mjs.map +2 -2
- package/dist/modules/agent-client/organization.d.mts +83 -0
- package/dist/modules/agent-client/organization.mjs +209 -0
- package/dist/modules/agent-client/organization.mjs.map +7 -0
- package/dist/modules/agent-client/participant-configuration.d.mts +21 -0
- package/dist/modules/agent-client/participant-configuration.mjs +38 -0
- package/dist/modules/agent-client/participant-configuration.mjs.map +7 -0
- package/dist/modules/agent-client/project.d.mts +3 -0
- package/dist/modules/agent-client/project.mjs +3 -1
- package/dist/modules/agent-client/project.mjs.map +2 -2
- package/dist/modules/agent-client/provide.d.mts +0 -1
- package/dist/modules/agent-client/provide.mjs +0 -1
- package/dist/modules/agent-client/provide.mjs.map +2 -2
- package/dist/modules/agent-client/sessions.d.mts +8 -1
- package/dist/modules/agent-client/sessions.mjs +24 -5
- package/dist/modules/agent-client/sessions.mjs.map +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ requirements check the platform runs; anything missing throws a
|
|
|
98
98
|
`sessions.create` and `conversations.create` take an `id` you choose, so a
|
|
99
99
|
sandbox created first can be owned by the session or conversation it is for
|
|
100
100
|
(`project.sandboxes.create(environment, { setup, ownedBy, idempotencyKey })`).
|
|
101
|
-
`conversations.
|
|
101
|
+
`conversations.findDirect({ agent })` looks up without creating.
|
|
102
102
|
|
|
103
103
|
## Where things run
|
|
104
104
|
|
|
@@ -71,7 +71,12 @@ const createProjectChannelsApi = (args) => {
|
|
|
71
71
|
path: installsPath,
|
|
72
72
|
body: {
|
|
73
73
|
schema: installChannelRequestSchema,
|
|
74
|
-
value: {
|
|
74
|
+
value: {
|
|
75
|
+
...install,
|
|
76
|
+
channel: referenceOf(install.channel),
|
|
77
|
+
agent: referenceOf(install.agent),
|
|
78
|
+
agents: { provide: provideDocumentOf(agents.provide) }
|
|
79
|
+
}
|
|
75
80
|
},
|
|
76
81
|
response: installedChannelResponseSchema,
|
|
77
82
|
signal
|
|
@@ -85,6 +90,7 @@ const createProjectChannelsApi = (args) => {
|
|
|
85
90
|
})).bindings
|
|
86
91
|
};
|
|
87
92
|
};
|
|
93
|
+
const referenceOf = (reference) => "hash" in reference ? { hash: reference.hash } : { name: reference.name };
|
|
88
94
|
const createChannelBindingsApi = (ctx) => ({
|
|
89
95
|
get: async ({ bindingId, signal }) => (await ctx.http.request({
|
|
90
96
|
method: HttpMethod.Get,
|
|
@@ -99,6 +105,8 @@ const createChannelBindingsApi = (ctx) => ({
|
|
|
99
105
|
schema: updateChannelBindingRequestSchema,
|
|
100
106
|
value: {
|
|
101
107
|
...change,
|
|
108
|
+
...change.channel == null ? {} : { channel: referenceOf(change.channel) },
|
|
109
|
+
...change.agent == null ? {} : { agent: referenceOf(change.agent) },
|
|
102
110
|
...agents == null ? {} : { agents: { provide: provideDocumentOf(agents.provide) } }
|
|
103
111
|
}
|
|
104
112
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/channels.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n channelAppListSchema,\n channelAppResponseSchema,\n channelBindingListSchema,\n channelBindingResponseSchema,\n channelIdentityLinkListSchema,\n channelIdentityLinkProgressSchema,\n channelPlaceConnectionResponseSchema,\n channelPlacesResponseSchema,\n channelSchema,\n channelTenantTicketSchema,\n channelTicketSchema,\n completeChannelIdentityLinkRequestSchema,\n completeChannelPlaceConnectionRequestSchema,\n createChannelAppRequestSchema,\n installChannelRequestSchema,\n installedChannelResponseSchema,\n okResponseSchema,\n publishChannelRequestSchema,\n publishChannelResponseSchema,\n uninstallChannelBindingResponseSchema,\n updateChannelAppRequestSchema,\n updateChannelBindingRequestSchema,\n updateChannelIdentityLinkRequestSchema,\n type ActorInputIface,\n type ChannelAppIface,\n type ChannelBindingIface,\n type ChannelIdentityLinkIface,\n type ChannelIdentityLinkProgressIface,\n type ChannelIface,\n type ChannelSeenPlaceIface,\n type ChannelTenantTicketIface,\n type ChannelTicketIface,\n type CompleteChannelIdentityLinkRequestIface,\n type CompleteChannelPlaceConnectionRequestIface,\n type CreateChannelAppRequestIface,\n type DefinitionVisibility,\n type InstallChannelRequestIface,\n type InstalledChannelIface,\n type PublishChannelResponseIface,\n type UpdateChannelAppRequestIface,\n type UpdateChannelBindingRequestIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport {\n encodePath,\n type ClientContextIface,\n type EnumInput,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport { HttpMethod } from \"./http.mjs\";\nimport { provideDocumentOf, type ProvideIface } from \"./provide.mjs\";\n\n// Channels connect a provider (Slack, email, a webhook) to a project's chats.\n// A channel is one self-contained module, published by name and stored by\n// content hash; its handlers always run on Final's serverless runtime. An\n// install (a channel binding) runs a channel in a project, a channel app holds\n// the provider application's credentials, and tickets let the installer's own\n// pages link people and connect places.\n\n/** A channel value's source, as `channels.publish({ channel })` sends it. */\nexport interface ChannelSourceIface {\n source: string;\n export?: string;\n}\n\n/** How the SDK turns a channel value into its source; a seam over `@finalai/agent-definition`. */\nexport type ChannelSourceOf = (channel: object) => ChannelSourceIface;\n\nexport type PublishChannelArgsIface = {\n name: string;\n /** `public` also makes the name public under the project's publisher handle. */\n visibility?: EnumInput<DefinitionVisibility>;\n /** A channel app of this project that installs of the publication use unless they bring their own. */\n app?: string;\n} & SignalOptionsIface &\n ({ channel: object } | { source: string; export?: string });\n\nexport type InstallChannelArgsIface = Omit<InstallChannelRequestIface, 'agents'> & {\n /** What the agent gets in every chat this install creates. */\n agents: { provide: ProvideIface };\n} & SignalOptionsIface;\n\nexport type UpdateChannelBindingArgsIface = Omit<UpdateChannelBindingRequestIface, 'agents'> & {\n bindingId: string;\n agents?: { provide: ProvideIface };\n} & SignalOptionsIface;\n\nexport interface ProjectChannelsApiIface {\n publish: (args: PublishChannelArgsIface) => Promise<PublishChannelResponseIface>;\n get: (\n selector: ({ name: string } | { hash: string }) & SignalOptionsIface,\n ) => Promise<ChannelIface>;\n /**\n * Installs a channel in the project. Fails with `requirements_unmet`, and\n * installs nothing, unless `agents.provide` meets the agent's requirements\n * and the channel's app requirement is met.\n */\n install: (args: InstallChannelArgsIface) => Promise<InstalledChannelIface>;\n /** The project's installs, newest first. */\n installs: (\n options?: SignalOptionsIface & { includeArchived?: boolean },\n ) => Promise<ChannelBindingIface[]>;\n}\n\nexport interface ChannelBindingsApiIface {\n /** One install, with whether its agent's requirements are met now. */\n get: (args: { bindingId: string } & SignalOptionsIface) => Promise<ChannelBindingIface>;\n /** Fails with `revision_conflict` unless `revision` is the one last read, and with `requirements_unmet` when the change would leave them unmet. */\n update: (args: UpdateChannelBindingArgsIface) => Promise<InstalledChannelIface>;\n /** Ends the install: its connected places, tenants, listeners and the links made through it. */\n uninstall: (\n args: { bindingId: string } & SignalOptionsIface,\n ) => Promise<{ archivedAt: string | null }>;\n /** A single-use link that installs the provider app for one tenant (a workspace, a server). */\n tenantTicket: (\n args: { bindingId: string } & SignalOptionsIface,\n ) => Promise<ChannelTenantTicketIface>;\n /** The provider places the install has seen. */\n places: (args: { bindingId: string } & SignalOptionsIface) => Promise<ChannelSeenPlaceIface[]>;\n}\n\nexport interface ChannelAppsApiIface {\n /** Registers the provider application's credentials; secret values stay project secrets. */\n create: (args: CreateChannelAppRequestIface & SignalOptionsIface) => Promise<ChannelAppIface>;\n /** The apps of the project and its ancestors. */\n list: (options?: SignalOptionsIface) => Promise<ChannelAppIface[]>;\n update: (\n args: UpdateChannelAppRequestIface & { id: string } & SignalOptionsIface,\n ) => Promise<ChannelAppIface>;\n /** Refused while a live install or publication uses the app. */\n delete: (args: { id: string } & SignalOptionsIface) => Promise<void>;\n}\n\n/** The actor an API key or app acts for, by its external id. */\nexport interface ActorOptionIface {\n actor?: string;\n}\n\nexport interface ChannelTicketsApiIface {\n /** What a ticket from an installer's link or connect page is for. */\n get: (\n args: { ticket: string } & ActorOptionIface & SignalOptionsIface,\n ) => Promise<ChannelTicketIface>;\n /** Links the ticket's channel account to the caller's person, or to `actor`. */\n link: (\n args: { ticket: string } & CompleteChannelIdentityLinkRequestIface & SignalOptionsIface,\n ) => Promise<ChannelIdentityLinkProgressIface>;\n /** Connects the ticket's place to a conversation the caller manages. */\n connect: (\n args: { ticket: string } & CompleteChannelPlaceConnectionRequestIface & SignalOptionsIface,\n ) => Promise<{ routeId: string }>;\n}\n\nexport interface IdentityLinksApiIface {\n /** The channel accounts linked to the caller's person, or to `actor`. */\n list: (options?: ActorOptionIface & SignalOptionsIface) => Promise<ChannelIdentityLinkIface[]>;\n /** Chooses where the person's direct messages to the channel land. */\n update: (\n args: {\n id: string;\n directConversationId: string | null;\n actor?: ActorInputIface;\n } & SignalOptionsIface,\n ) => Promise<void>;\n /** Unlinks the account. */\n delete: (args: { id: string } & ActorOptionIface & SignalOptionsIface) => Promise<void>;\n}\n\nconst channelsPath = (projectId: string, suffix: string): string =>\n `/v1/projects/${encodePath(projectId)}/channels${suffix}`;\n\nconst bindingPath = (bindingId: string, suffix = ''): string =>\n `/v1/channel-bindings/${encodePath(bindingId)}${suffix}`;\n\nexport const createProjectChannelsApi = (args: {\n context: ClientContextIface;\n projectId: string;\n sourceOf: ChannelSourceOf;\n}): ProjectChannelsApiIface => {\n const { http } = args.context;\n const installsPath = `/v1/projects/${encodePath(args.projectId)}/channel-bindings`;\n return {\n publish: (publish) => {\n const source: ChannelSourceIface =\n 'channel' in publish\n ? args.sourceOf(publish.channel)\n : {\n source: publish.source,\n ...(publish.export == null ? {} : { export: publish.export }),\n };\n return http.request({\n method: HttpMethod.Post,\n path: channelsPath(args.projectId, '/publish'),\n body: {\n schema: publishChannelRequestSchema,\n value: {\n name: publish.name,\n ...source,\n visibility: publish.visibility,\n app: publish.app,\n },\n },\n response: publishChannelResponseSchema,\n signal: publish.signal,\n });\n },\n get: ({ signal, ...selector }) =>\n http.request({\n method: HttpMethod.Get,\n path: channelsPath(args.projectId, '/lookup'),\n query: {\n name: 'name' in selector ? selector.name : undefined,\n hash: 'hash' in selector ? selector.hash : undefined,\n },\n response: channelSchema,\n signal,\n }),\n install: ({ signal, agents, ...install }) =>\n http.request({\n method: HttpMethod.Post,\n path: installsPath,\n body: {\n schema: installChannelRequestSchema,\n value: { ...install, agents: { provide: provideDocumentOf(agents.provide) } },\n },\n response: installedChannelResponseSchema,\n signal,\n }),\n installs: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: installsPath,\n query: { includeArchived: options?.includeArchived === true ? 'true' : undefined },\n response: channelBindingListSchema,\n signal: options?.signal,\n })\n ).bindings,\n };\n};\n\nexport const createChannelBindingsApi = (ctx: ClientContextIface): ChannelBindingsApiIface => ({\n get: async ({ bindingId, signal }) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: bindingPath(bindingId),\n response: channelBindingResponseSchema,\n signal,\n })\n ).binding,\n update: ({ bindingId, signal, agents, ...change }) =>\n ctx.http.request({\n method: HttpMethod.Patch,\n path: bindingPath(bindingId),\n body: {\n schema: updateChannelBindingRequestSchema,\n value: {\n ...change,\n ...(agents == null ? {} : { agents: { provide: provideDocumentOf(agents.provide) } }),\n },\n },\n response: installedChannelResponseSchema,\n signal,\n }),\n uninstall: ({ bindingId, signal }) =>\n ctx.http.request({\n method: HttpMethod.Delete,\n path: bindingPath(bindingId),\n response: uninstallChannelBindingResponseSchema,\n signal,\n }),\n tenantTicket: ({ bindingId, signal }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: bindingPath(bindingId, '/tenant-tickets'),\n response: channelTenantTicketSchema,\n signal,\n }),\n places: async ({ bindingId, signal }) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: bindingPath(bindingId, '/places'),\n response: channelPlacesResponseSchema,\n signal,\n })\n ).places,\n});\n\nexport const createChannelAppsApi = (args: {\n context: ClientContextIface;\n projectId: string;\n}): ChannelAppsApiIface => {\n const { http } = args.context;\n const appPath = (id: string): string => `/v1/channel-apps/${encodePath(id)}`;\n return {\n create: async ({ signal, ...value }) =>\n (\n await http.request({\n method: HttpMethod.Post,\n path: `/v1/projects/${encodePath(args.projectId)}/channel-apps`,\n body: { schema: createChannelAppRequestSchema, value },\n response: channelAppResponseSchema,\n signal,\n })\n ).app,\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: `/v1/projects/${encodePath(args.projectId)}/channel-apps`,\n response: channelAppListSchema,\n signal: options?.signal,\n })\n ).apps,\n update: async ({ id, signal, ...value }) =>\n (\n await http.request({\n method: HttpMethod.Patch,\n path: appPath(id),\n body: { schema: updateChannelAppRequestSchema, value },\n response: channelAppResponseSchema,\n signal,\n })\n ).app,\n delete: async ({ id, signal }) => {\n await http.request({\n method: HttpMethod.Delete,\n path: appPath(id),\n response: okResponseSchema,\n signal,\n });\n },\n };\n};\n\nexport const createChannelTicketsApi = (ctx: ClientContextIface): ChannelTicketsApiIface => {\n const ticketPath = (ticket: string, suffix = ''): string =>\n `/v1/channel-tickets/${encodePath(ticket)}${suffix}`;\n return {\n get: ({ ticket, actor, signal }) =>\n ctx.http.request({\n method: HttpMethod.Get,\n path: ticketPath(ticket),\n query: { actor },\n response: channelTicketSchema,\n signal,\n }),\n link: ({ ticket, signal, ...value }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: ticketPath(ticket, '/identity-link'),\n body: { schema: completeChannelIdentityLinkRequestSchema, value },\n response: channelIdentityLinkProgressSchema,\n signal,\n }),\n connect: ({ ticket, signal, ...value }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: ticketPath(ticket, '/place-connection'),\n body: { schema: completeChannelPlaceConnectionRequestSchema, value },\n response: channelPlaceConnectionResponseSchema,\n signal,\n }),\n };\n};\n\nexport const createIdentityLinksApi = (ctx: ClientContextIface): IdentityLinksApiIface => {\n const linksPath = (suffix = ''): string => `/v1/people/me/identity-links${suffix}`;\n return {\n list: async (options) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: linksPath(),\n query: { actor: options?.actor },\n response: channelIdentityLinkListSchema,\n signal: options?.signal,\n })\n ).links,\n update: async ({ id, signal, ...value }) => {\n await ctx.http.request({\n method: HttpMethod.Patch,\n path: linksPath(`/${encodePath(id)}`),\n body: { schema: updateChannelIdentityLinkRequestSchema, value },\n response: okResponseSchema,\n signal,\n });\n },\n delete: async ({ id, actor, signal }) => {\n await ctx.http.request({\n method: HttpMethod.Delete,\n path: linksPath(`/${encodePath(id)}`),\n query: { actor },\n response: okResponseSchema,\n signal,\n });\n },\n };\n};\n\n/** The default `ChannelSourceOf` when no codec is available. */\nexport const noChannelSource: ChannelSourceOf = () => {\n throw clientError({\n message: 'Publish a channel as `source`: this build cannot capture a channel value',\n status: 0,\n code: ClientErrorCode.InvalidRequest,\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,OA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A,IACH,SAAS,CAAC,EAAE,QAAQ,QAAQ,GAAG,QAAQ,MACrC,KAAK,QAAQ;AAAA,MACX,QAAQ,WAAW;AAAA,MACnB,MAAM;AAAA,MACN,MAAM;AAAA,QACJ,QAAQ;AAAA,QACR,OAAO,
|
|
4
|
+
"sourcesContent": ["import {\n channelAppListSchema,\n channelAppResponseSchema,\n channelBindingListSchema,\n channelBindingResponseSchema,\n channelIdentityLinkListSchema,\n channelIdentityLinkProgressSchema,\n channelPlaceConnectionResponseSchema,\n channelPlacesResponseSchema,\n channelSchema,\n channelTenantTicketSchema,\n channelTicketSchema,\n completeChannelIdentityLinkRequestSchema,\n completeChannelPlaceConnectionRequestSchema,\n createChannelAppRequestSchema,\n installChannelRequestSchema,\n installedChannelResponseSchema,\n okResponseSchema,\n publishChannelRequestSchema,\n publishChannelResponseSchema,\n uninstallChannelBindingResponseSchema,\n updateChannelAppRequestSchema,\n updateChannelBindingRequestSchema,\n updateChannelIdentityLinkRequestSchema,\n type ActorInputIface,\n type ChannelAppIface,\n type ChannelBindingIface,\n type ChannelIdentityLinkIface,\n type ChannelIdentityLinkProgressIface,\n type ChannelIface,\n type ChannelSeenPlaceIface,\n type ChannelTenantTicketIface,\n type ChannelTicketIface,\n type CompleteChannelIdentityLinkRequestIface,\n type CompleteChannelPlaceConnectionRequestIface,\n type CreateChannelAppRequestIface,\n type DefinitionVisibility,\n type InstallChannelRequestIface,\n type InstalledChannelIface,\n type PublishChannelResponseIface,\n type UpdateChannelAppRequestIface,\n type UpdateChannelBindingRequestIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport {\n encodePath,\n type ClientContextIface,\n type EnumInput,\n type SignalOptionsIface,\n} from \"./context.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport { HttpMethod } from \"./http.mjs\";\nimport { provideDocumentOf, type ProvideIface } from \"./provide.mjs\";\n\n// Channels connect a provider (Slack, email, a webhook) to a project's chats.\n// A channel is one self-contained module, published by name and stored by\n// content hash; its handlers always run on Final's serverless runtime. An\n// install (a channel binding) runs a channel in a project, a channel app holds\n// the provider application's credentials, and tickets let the installer's own\n// pages link people and connect places.\n\n/** A channel value's source, as `channels.publish({ channel })` sends it. */\nexport interface ChannelSourceIface {\n source: string;\n export?: string;\n}\n\n/** How the SDK turns a channel value into its source; a seam over `@finalai/agent-definition`. */\nexport type ChannelSourceOf = (channel: object) => ChannelSourceIface;\n\nexport type PublishChannelArgsIface = {\n name: string;\n /** `public` also makes the name public under the project's publisher handle. */\n visibility?: EnumInput<DefinitionVisibility>;\n /** A channel app of this project that installs of the publication use unless they bring their own. */\n app?: string;\n} & SignalOptionsIface &\n ({ channel: object } | { source: string; export?: string });\n\nexport type InstallChannelArgsIface = Omit<InstallChannelRequestIface, 'agents'> & {\n /** What the agent gets in every chat this install creates. */\n agents: { provide: ProvideIface };\n} & SignalOptionsIface;\n\nexport type UpdateChannelBindingArgsIface = Omit<UpdateChannelBindingRequestIface, 'agents'> & {\n bindingId: string;\n agents?: { provide: ProvideIface };\n} & SignalOptionsIface;\n\nexport interface ProjectChannelsApiIface {\n publish: (args: PublishChannelArgsIface) => Promise<PublishChannelResponseIface>;\n get: (\n selector: ({ name: string } | { hash: string }) & SignalOptionsIface,\n ) => Promise<ChannelIface>;\n /**\n * Installs a channel in the project. Fails with `requirements_unmet`, and\n * installs nothing, unless `agents.provide` meets the agent's requirements\n * and the channel's app requirement is met.\n */\n install: (args: InstallChannelArgsIface) => Promise<InstalledChannelIface>;\n /** The project's installs, newest first. */\n installs: (\n options?: SignalOptionsIface & { includeArchived?: boolean },\n ) => Promise<ChannelBindingIface[]>;\n}\n\nexport interface ChannelBindingsApiIface {\n /** One install, with whether its agent's requirements are met now. */\n get: (args: { bindingId: string } & SignalOptionsIface) => Promise<ChannelBindingIface>;\n /** Fails with `revision_conflict` unless `revision` is the one last read, and with `requirements_unmet` when the change would leave them unmet. */\n update: (args: UpdateChannelBindingArgsIface) => Promise<InstalledChannelIface>;\n /** Ends the install: its connected places, tenants, listeners and the links made through it. */\n uninstall: (\n args: { bindingId: string } & SignalOptionsIface,\n ) => Promise<{ archivedAt: string | null }>;\n /** A single-use link that installs the provider app for one tenant (a workspace, a server). */\n tenantTicket: (\n args: { bindingId: string } & SignalOptionsIface,\n ) => Promise<ChannelTenantTicketIface>;\n /** The provider places the install has seen. */\n places: (args: { bindingId: string } & SignalOptionsIface) => Promise<ChannelSeenPlaceIface[]>;\n}\n\nexport interface ChannelAppsApiIface {\n /** Registers the provider application's credentials; secret values stay project secrets. */\n create: (args: CreateChannelAppRequestIface & SignalOptionsIface) => Promise<ChannelAppIface>;\n /** The apps of the project and its ancestors. */\n list: (options?: SignalOptionsIface) => Promise<ChannelAppIface[]>;\n update: (\n args: UpdateChannelAppRequestIface & { id: string } & SignalOptionsIface,\n ) => Promise<ChannelAppIface>;\n /** Refused while a live install or publication uses the app. */\n delete: (args: { id: string } & SignalOptionsIface) => Promise<void>;\n}\n\n/** The actor an API key or app acts for, by its external id. */\nexport interface ActorOptionIface {\n actor?: string;\n}\n\nexport interface ChannelTicketsApiIface {\n /** What a ticket from an installer's link or connect page is for. */\n get: (\n args: { ticket: string } & ActorOptionIface & SignalOptionsIface,\n ) => Promise<ChannelTicketIface>;\n /** Links the ticket's channel account to the caller's person, or to `actor`. */\n link: (\n args: { ticket: string } & CompleteChannelIdentityLinkRequestIface & SignalOptionsIface,\n ) => Promise<ChannelIdentityLinkProgressIface>;\n /** Connects the ticket's place to a conversation the caller manages. */\n connect: (\n args: { ticket: string } & CompleteChannelPlaceConnectionRequestIface & SignalOptionsIface,\n ) => Promise<{ routeId: string }>;\n}\n\nexport interface IdentityLinksApiIface {\n /** The channel accounts linked to the caller's person, or to `actor`. */\n list: (options?: ActorOptionIface & SignalOptionsIface) => Promise<ChannelIdentityLinkIface[]>;\n /** Chooses where the person's direct messages to the channel land. */\n update: (\n args: {\n id: string;\n directConversationId: string | null;\n actor?: ActorInputIface;\n } & SignalOptionsIface,\n ) => Promise<void>;\n /** Unlinks the account. */\n delete: (args: { id: string } & ActorOptionIface & SignalOptionsIface) => Promise<void>;\n}\n\nconst channelsPath = (projectId: string, suffix: string): string =>\n `/v1/projects/${encodePath(projectId)}/channels${suffix}`;\n\nconst bindingPath = (bindingId: string, suffix = ''): string =>\n `/v1/channel-bindings/${encodePath(bindingId)}${suffix}`;\n\nexport const createProjectChannelsApi = (args: {\n context: ClientContextIface;\n projectId: string;\n sourceOf: ChannelSourceOf;\n}): ProjectChannelsApiIface => {\n const { http } = args.context;\n const installsPath = `/v1/projects/${encodePath(args.projectId)}/channel-bindings`;\n return {\n publish: (publish) => {\n const source: ChannelSourceIface =\n 'channel' in publish\n ? args.sourceOf(publish.channel)\n : {\n source: publish.source,\n ...(publish.export == null ? {} : { export: publish.export }),\n };\n return http.request({\n method: HttpMethod.Post,\n path: channelsPath(args.projectId, '/publish'),\n body: {\n schema: publishChannelRequestSchema,\n value: {\n name: publish.name,\n ...source,\n visibility: publish.visibility,\n app: publish.app,\n },\n },\n response: publishChannelResponseSchema,\n signal: publish.signal,\n });\n },\n get: ({ signal, ...selector }) =>\n http.request({\n method: HttpMethod.Get,\n path: channelsPath(args.projectId, '/lookup'),\n query: {\n name: 'name' in selector ? selector.name : undefined,\n hash: 'hash' in selector ? selector.hash : undefined,\n },\n response: channelSchema,\n signal,\n }),\n install: ({ signal, agents, ...install }) =>\n http.request({\n method: HttpMethod.Post,\n path: installsPath,\n body: {\n schema: installChannelRequestSchema,\n value: {\n ...install,\n channel: referenceOf(install.channel),\n agent: referenceOf(install.agent),\n agents: { provide: provideDocumentOf(agents.provide) },\n },\n },\n response: installedChannelResponseSchema,\n signal,\n }),\n installs: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: installsPath,\n query: { includeArchived: options?.includeArchived === true ? 'true' : undefined },\n response: channelBindingListSchema,\n signal: options?.signal,\n })\n ).bindings,\n };\n};\n\n// A channel or agent reference as the wire takes it: a published value (with its id, name and\n// more) narrows to its hash, which pins what was read.\nconst referenceOf = (reference: { hash: string } | { name: string }) =>\n 'hash' in reference ? { hash: reference.hash } : { name: reference.name };\n\nexport const createChannelBindingsApi = (ctx: ClientContextIface): ChannelBindingsApiIface => ({\n get: async ({ bindingId, signal }) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: bindingPath(bindingId),\n response: channelBindingResponseSchema,\n signal,\n })\n ).binding,\n update: ({ bindingId, signal, agents, ...change }) =>\n ctx.http.request({\n method: HttpMethod.Patch,\n path: bindingPath(bindingId),\n body: {\n schema: updateChannelBindingRequestSchema,\n value: {\n ...change,\n ...(change.channel == null ? {} : { channel: referenceOf(change.channel) }),\n ...(change.agent == null ? {} : { agent: referenceOf(change.agent) }),\n ...(agents == null ? {} : { agents: { provide: provideDocumentOf(agents.provide) } }),\n },\n },\n response: installedChannelResponseSchema,\n signal,\n }),\n uninstall: ({ bindingId, signal }) =>\n ctx.http.request({\n method: HttpMethod.Delete,\n path: bindingPath(bindingId),\n response: uninstallChannelBindingResponseSchema,\n signal,\n }),\n tenantTicket: ({ bindingId, signal }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: bindingPath(bindingId, '/tenant-tickets'),\n response: channelTenantTicketSchema,\n signal,\n }),\n places: async ({ bindingId, signal }) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: bindingPath(bindingId, '/places'),\n response: channelPlacesResponseSchema,\n signal,\n })\n ).places,\n});\n\nexport const createChannelAppsApi = (args: {\n context: ClientContextIface;\n projectId: string;\n}): ChannelAppsApiIface => {\n const { http } = args.context;\n const appPath = (id: string): string => `/v1/channel-apps/${encodePath(id)}`;\n return {\n create: async ({ signal, ...value }) =>\n (\n await http.request({\n method: HttpMethod.Post,\n path: `/v1/projects/${encodePath(args.projectId)}/channel-apps`,\n body: { schema: createChannelAppRequestSchema, value },\n response: channelAppResponseSchema,\n signal,\n })\n ).app,\n list: async (options) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: `/v1/projects/${encodePath(args.projectId)}/channel-apps`,\n response: channelAppListSchema,\n signal: options?.signal,\n })\n ).apps,\n update: async ({ id, signal, ...value }) =>\n (\n await http.request({\n method: HttpMethod.Patch,\n path: appPath(id),\n body: { schema: updateChannelAppRequestSchema, value },\n response: channelAppResponseSchema,\n signal,\n })\n ).app,\n delete: async ({ id, signal }) => {\n await http.request({\n method: HttpMethod.Delete,\n path: appPath(id),\n response: okResponseSchema,\n signal,\n });\n },\n };\n};\n\nexport const createChannelTicketsApi = (ctx: ClientContextIface): ChannelTicketsApiIface => {\n const ticketPath = (ticket: string, suffix = ''): string =>\n `/v1/channel-tickets/${encodePath(ticket)}${suffix}`;\n return {\n get: ({ ticket, actor, signal }) =>\n ctx.http.request({\n method: HttpMethod.Get,\n path: ticketPath(ticket),\n query: { actor },\n response: channelTicketSchema,\n signal,\n }),\n link: ({ ticket, signal, ...value }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: ticketPath(ticket, '/identity-link'),\n body: { schema: completeChannelIdentityLinkRequestSchema, value },\n response: channelIdentityLinkProgressSchema,\n signal,\n }),\n connect: ({ ticket, signal, ...value }) =>\n ctx.http.request({\n method: HttpMethod.Post,\n path: ticketPath(ticket, '/place-connection'),\n body: { schema: completeChannelPlaceConnectionRequestSchema, value },\n response: channelPlaceConnectionResponseSchema,\n signal,\n }),\n };\n};\n\nexport const createIdentityLinksApi = (ctx: ClientContextIface): IdentityLinksApiIface => {\n const linksPath = (suffix = ''): string => `/v1/people/me/identity-links${suffix}`;\n return {\n list: async (options) =>\n (\n await ctx.http.request({\n method: HttpMethod.Get,\n path: linksPath(),\n query: { actor: options?.actor },\n response: channelIdentityLinkListSchema,\n signal: options?.signal,\n })\n ).links,\n update: async ({ id, signal, ...value }) => {\n await ctx.http.request({\n method: HttpMethod.Patch,\n path: linksPath(`/${encodePath(id)}`),\n body: { schema: updateChannelIdentityLinkRequestSchema, value },\n response: okResponseSchema,\n signal,\n });\n },\n delete: async ({ id, actor, signal }) => {\n await ctx.http.request({\n method: HttpMethod.Delete,\n path: linksPath(`/${encodePath(id)}`),\n query: { actor },\n response: okResponseSchema,\n signal,\n });\n },\n };\n};\n\n/** The default `ChannelSourceOf` when no codec is available. */\nexport const noChannelSource: ChannelSourceOf = () => {\n throw clientError({\n message: 'Publish a channel as `source`: this build cannot capture a channel value',\n status: 0,\n code: ClientErrorCode.InvalidRequest,\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,OAmBK;AACP;AAAA,EACE;AAAA,OAIK;AACP,SAAS,aAAa,uBAAuB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,yBAA4C;AAsHrD,MAAM,eAAe,CAAC,WAAmB,WACvC,gBAAgB,WAAW,SAAS,CAAC,YAAY,MAAM;AAEzD,MAAM,cAAc,CAAC,WAAmB,SAAS,OAC/C,wBAAwB,WAAW,SAAS,CAAC,GAAG,MAAM;AAEjD,MAAM,2BAA2B,CAAC,SAIV;AAC7B,QAAM,EAAE,KAAK,IAAI,KAAK;AACtB,QAAM,eAAe,gBAAgB,WAAW,KAAK,SAAS,CAAC;AAC/D,SAAO;AAAA,IACL,SAAS,CAAC,YAAY;AACpB,YAAM,SACJ,aAAa,UACT,KAAK,SAAS,QAAQ,OAAO,IAC7B;AAAA,QACE,QAAQ,QAAQ;AAAA,QAChB,GAAI,QAAQ,UAAU,OAAO,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;AAAA,MAC7D;AACN,aAAO,KAAK,QAAQ;AAAA,QAClB,QAAQ,WAAW;AAAA,QACnB,MAAM,aAAa,KAAK,WAAW,UAAU;AAAA,QAC7C,MAAM;AAAA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AA,MACF,CAAC;AAAA,IACH;AAAA,IACA,QAAQ,OAAO,EAAE,IAAI,OAAO,OAAO,MAAM;AACvC,YAAM,IAAI,KAAK,QAAQ;AAAA,QACrB,QAAQ,WAAW;AAAA,QACnB,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC,EAAE;AAAA,QACpC,OAAO,EAAE,MAAM;AAAA,QACf,UAAU;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAGO,MAAM,kBAAmC,MAAM;AACpD,QAAM,YAAY;AAAA,IAChB,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,MAAM,gBAAgB;AAAA,EACxB,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentListIface, type DecisionIface, type HealthResponseIface, type InferenceOfferingIface, type PersonIface, type PersonListIface, type PlatformIdentityExchangeRequestIface, type PlatformIdentityExchangeResponseIface, type RealtimeSessionResponseIface } from '@finalai/agent-protocol/agent-platform';
|
|
1
|
+
import { type AgentListIface, type AgentSummaryIface, type DecisionIface, type HealthResponseIface, type InferenceOfferingIface, type PersonIface, type PersonListIface, type PlatformIdentityExchangeRequestIface, type PlatformIdentityExchangeResponseIface, type RealtimeSessionResponseIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
2
|
import { type AcpApiIface } from "./acp.mjs";
|
|
3
3
|
import type { AgentValueCodecIface } from "./agent-input.mjs";
|
|
4
4
|
import { type ChannelBindingsApiIface, type ChannelSourceOf, type ChannelTicketsApiIface, type IdentityLinksApiIface } from "./channels.mjs";
|
|
@@ -11,6 +11,7 @@ import { type GatewayConnect, type RealtimeTransportIface } from "./realtime.mjs
|
|
|
11
11
|
import type { LocalComputeIface, LocalHostSocketIface } from "./local-host.mjs";
|
|
12
12
|
import { type ProjectClientIface } from "./project.mjs";
|
|
13
13
|
import { type ProjectsApiIface } from "./projects.mjs";
|
|
14
|
+
import { type OrganizationApiIface } from "./organization.mjs";
|
|
14
15
|
import { type PublishersApiIface } from "./publishers.mjs";
|
|
15
16
|
import { type SessionsApiIface } from "./sessions.mjs";
|
|
16
17
|
/** Final's agents API. */
|
|
@@ -74,6 +75,13 @@ export interface AgentsApiIface {
|
|
|
74
75
|
limit?: number;
|
|
75
76
|
projectId?: string;
|
|
76
77
|
}) => Promise<AgentListIface>;
|
|
78
|
+
/**
|
|
79
|
+
* One agent the caller can use, by id, in whichever project owns it; also one that was never
|
|
80
|
+
* published (`hash` and `revisionId` are null). Archived agents are not found.
|
|
81
|
+
*/
|
|
82
|
+
get: (args: {
|
|
83
|
+
id: string;
|
|
84
|
+
} & SignalOptionsIface) => Promise<AgentSummaryIface>;
|
|
77
85
|
}
|
|
78
86
|
export interface PeopleApiIface {
|
|
79
87
|
/** One page of the caller's organization members, by name; pass `nextCursor` as `cursor` for the next. */
|
|
@@ -141,6 +149,8 @@ export interface AgentClientIface {
|
|
|
141
149
|
platformIdentity: PlatformIdentityApiIface;
|
|
142
150
|
decisions: DecisionsApiIface;
|
|
143
151
|
health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;
|
|
152
|
+
/** The caller's organization: model credentials, budgets and policies. */
|
|
153
|
+
organization: OrganizationApiIface;
|
|
144
154
|
agents: AgentsApiIface;
|
|
145
155
|
people: PeopleApiIface;
|
|
146
156
|
realtime: RealtimeApiIface;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
agentListSchema,
|
|
3
3
|
agentRealtimeTopics,
|
|
4
|
+
agentSummarySchema,
|
|
4
5
|
decisionResponseSchema,
|
|
5
6
|
healthResponseSchema,
|
|
6
7
|
inferenceOfferingSchema,
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
} from "./realtime.mjs";
|
|
39
40
|
import { createProjectClient } from "./project.mjs";
|
|
40
41
|
import { createProjectsApi } from "./projects.mjs";
|
|
42
|
+
import { createOrganizationApi } from "./organization.mjs";
|
|
41
43
|
import { createPublishersApi } from "./publishers.mjs";
|
|
42
44
|
import { createSessionsApi } from "./sessions.mjs";
|
|
43
45
|
const DEFAULT_AGENTS_HOST = "https://agent-session.final.ai";
|
|
@@ -148,6 +150,12 @@ const createClient = (options) => {
|
|
|
148
150
|
},
|
|
149
151
|
response: agentListSchema,
|
|
150
152
|
signal: listOptions?.signal
|
|
153
|
+
}),
|
|
154
|
+
get: ({ id, signal }) => http.request({
|
|
155
|
+
method: HttpMethod.Get,
|
|
156
|
+
path: `/v1/agents/${encodePath(id)}`,
|
|
157
|
+
response: agentSummarySchema,
|
|
158
|
+
signal
|
|
151
159
|
})
|
|
152
160
|
},
|
|
153
161
|
people: (() => {
|
|
@@ -177,6 +185,7 @@ const createClient = (options) => {
|
|
|
177
185
|
project: ({ id }) => createProjectClient({ context, start, channelSourceOf, projectId: id }),
|
|
178
186
|
projects: createProjectsApi(context),
|
|
179
187
|
events: createEventsApi({ context, projectId: null }),
|
|
188
|
+
organization: createOrganizationApi(context),
|
|
180
189
|
app: {
|
|
181
190
|
eventSubscriptions: createEventSubscriptionsApi({
|
|
182
191
|
context,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/agent-client/client.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n agentListSchema,\n agentRealtimeTopics,\n decisionResponseSchema,\n healthResponseSchema,\n inferenceOfferingSchema,\n personListSchema,\n platformIdentityExchangeRequestSchema,\n platformIdentityExchangeResponseSchema,\n realtimeSessionResponseSchema,\n type AgentListIface,\n type DecisionIface,\n type HealthResponseIface,\n type InferenceOfferingIface,\n type PersonIface,\n type PersonListIface,\n type PlatformIdentityExchangeRequestIface,\n type PlatformIdentityExchangeResponseIface,\n type RealtimeSessionResponseIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAcpApi, type AcpApiIface } from \"./acp.mjs\";\nimport type { AgentValueCodecIface } from \"./agent-input.mjs\";\nimport {\n createChannelBindingsApi,\n createChannelTicketsApi,\n createIdentityLinksApi,\n type ChannelBindingsApiIface,\n type ChannelSourceOf,\n type ChannelTicketsApiIface,\n type IdentityLinksApiIface,\n} from \"./channels.mjs\";\nimport { encodePath, type ClientContextIface, type SignalOptionsIface } from \"./context.mjs\";\nimport { createConversationsApi, type ConversationsApiIface } from \"./conversations.mjs\";\nimport {\n defaultAgentCodec,\n defaultChannelSourceOf,\n defaultLocalCompute,\n defaultLocalHostDial,\n} from \"./defaults.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport {\n createEventsApi,\n createEventSubscriptionsApi,\n type EventsApiIface,\n type EventSubscriptionsApiIface,\n} from \"./events.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 type { LocalComputeIface, LocalHostIface, LocalHostSocketIface } from \"./local-host.mjs\";\nimport { createProjectClient, type ProjectClientIface } from \"./project.mjs\";\nimport { createProjectsApi, type ProjectsApiIface } from \"./projects.mjs\";\nimport { createPublishersApi, type PublishersApiIface } from \"./publishers.mjs\";\nimport { createSessionsApi, type SessionsApiIface } from \"./sessions.mjs\";\nimport type { AgentStartDepsIface } from \"./start.mjs\";\n\n/** Final's agents API. */\nexport const DEFAULT_AGENTS_HOST = 'https://agent-session.final.ai';\n\nexport interface CreateClientOptionsIface {\n auth: AgentClientAuth;\n /**\n * Whether this process provides the files and shell an agent requires when\n * the caller leaves them out (default true), so the model's file edits and\n * commands run here, on this machine. A server should provide every\n * capability explicitly and pass false, so an omission fails with\n * `requirements_unmet` instead of giving the model a shell in the server.\n */\n localCompute?: boolean;\n /**\n * The agents API origin (default `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 under.\n */\n host?: string;\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 /** Seam: how agent values become documents and in-process code. */\n agentCodec?: AgentValueCodecIface;\n /** Seam: how a channel value becomes its source. */\n channelSourceOf?: ChannelSourceOf;\n /** Seams for local hosts: the socket, and the sandbox this process serves. */\n localHosts?: {\n /** Opens the local host socket; abandons it when `signal` aborts. */\n dial?: (path: string, signal?: AbortSignal) => Promise<LocalHostSocketIface>;\n compute?: Partial<LocalComputeIface>;\n };\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 * Fetch one as data with `client.project({ id }).agents.get`.\n */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number; projectId?: string },\n ) => Promise<AgentListIface>;\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 /** The caller's own person (or, for an API key or app, the actor it names). */\n me: { identityLinks: IdentityLinksApiIface };\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 InferenceApiIface {\n /**\n * The vendors and models the platform's own metered inference serves, with\n * prices (`GET /v1/inference/offering`, public). A harness using the\n * platform's inference can run only models listed here.\n */\n offering: (options?: SignalOptionsIface) => Promise<InferenceOfferingIface>;\n}\n\nexport interface PlatformIdentityApiIface {\n /**\n * Exchanges a sandbox-provider (or downstream) assertion the platform issued\n * for a fresh one: for the provider's own URL (a refresh) or a backend its\n * registration was granted. The subject token is the credential.\n */\n exchange: (\n args: PlatformIdentityExchangeRequestIface & SignalOptionsIface,\n ) => Promise<PlatformIdentityExchangeResponseIface>;\n}\n\nexport interface DecisionsApiIface {\n /** One decision awaiting the caller's answer, as `conversations.decisions` lists it. */\n get: (args: { id: string } & SignalOptionsIface) => Promise<DecisionIface>;\n}\n\nexport interface AppApiIface {\n /**\n * The calling app's event subscriptions, across every organization that\n * installed it. Needs an app-level token.\n */\n eventSubscriptions: EventSubscriptionsApiIface;\n}\n\nexport interface AgentClientIface {\n /** One project: where sessions, conversations, sandboxes and integrations are created. */\n project: (args: { id: string }) => ProjectClientIface;\n /** The project tree: list projects and create them. */\n projects: ProjectsApiIface;\n /** The event feed across everything the caller can see; `project({ id }).events` narrows it. */\n events: EventsApiIface;\n app: AppApiIface;\n /** Publishers' public agents, channels, harnesses and ACP adapters. */\n publishers: PublishersApiIface;\n inference: InferenceApiIface;\n platformIdentity: PlatformIdentityApiIface;\n decisions: DecisionsApiIface;\n health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;\n agents: AgentsApiIface;\n people: PeopleApiIface;\n realtime: RealtimeApiIface;\n /** Existing sessions by id; create them through `project({ id }).sessions`. */\n sessions: SessionsApiIface;\n /** The caller's conversations; create them through `project({ id }).conversations`. */\n conversations: ConversationsApiIface;\n /** Channel installs by id; install them through `project({ id }).channels`. */\n channelBindings: ChannelBindingsApiIface;\n /** Tickets from an installer's link and connect pages. */\n channelTickets: ChannelTicketsApiIface;\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 every\n * local host connection (the platform then reports this process's tools and\n * compute as unavailable; sessions carry on) and, when the client created its\n * own realtime transport, closes the gateway connection and cancels its\n * retries. A transport passed in `realtime` belongs to the caller and is left\n * 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 ?? DEFAULT_AGENTS_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 hosts = new Set<LocalHostIface>();\n const localCompute = defaultLocalCompute();\n const start: AgentStartDepsIface = {\n context,\n codec: options.agentCodec ?? defaultAgentCodec,\n localCompute: options.localCompute ?? true,\n compute: { ...localCompute, ...options.localHosts?.compute },\n dial: options.localHosts?.dial ?? defaultLocalHostDial(http),\n hosts,\n };\n const channelSourceOf = options.channelSourceOf ?? defaultChannelSourceOf;\n const clientLevel = { deps: start, projectId: null };\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 for (const host of hosts) host.close();\n hosts.clear();\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 },\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 me: { identityLinks: createIdentityLinksApi(context) },\n };\n })(),\n realtime: { createSession: createRealtimeSession },\n project: ({ id }) => createProjectClient({ context, start, channelSourceOf, projectId: id }),\n projects: createProjectsApi(context),\n events: createEventsApi({ context, projectId: null }),\n app: {\n eventSubscriptions: createEventSubscriptionsApi({\n context,\n basePath: '/v1/apps/me/event-subscriptions',\n }),\n },\n publishers: createPublishersApi(context),\n inference: {\n offering: (offeringOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/inference/offering',\n response: inferenceOfferingSchema,\n signal: offeringOptions?.signal,\n }),\n },\n platformIdentity: {\n exchange: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/platform-identity/exchange',\n body: { schema: platformIdentityExchangeRequestSchema, value },\n response: platformIdentityExchangeResponseSchema,\n signal,\n }),\n },\n decisions: {\n get: async ({ id, signal }) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: `/v1/decisions/${encodePath(id)}`,\n response: decisionResponseSchema,\n signal,\n context: { decisionId: id },\n })\n ).decision,\n },\n sessions: createSessionsApi(context),\n conversations: createConversationsApi(context, clientLevel),\n channelBindings: createChannelBindingsApi(context),\n channelTickets: createChannelTicketsApi(context),\n acp: createAcpApi({ http }),\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,
|
|
4
|
+
"sourcesContent": ["import {\n agentListSchema,\n agentRealtimeTopics,\n agentSummarySchema,\n decisionResponseSchema,\n healthResponseSchema,\n inferenceOfferingSchema,\n personListSchema,\n platformIdentityExchangeRequestSchema,\n platformIdentityExchangeResponseSchema,\n realtimeSessionResponseSchema,\n type AgentListIface,\n type AgentSummaryIface,\n type DecisionIface,\n type HealthResponseIface,\n type InferenceOfferingIface,\n type PersonIface,\n type PersonListIface,\n type PlatformIdentityExchangeRequestIface,\n type PlatformIdentityExchangeResponseIface,\n type RealtimeSessionResponseIface,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAcpApi, type AcpApiIface } from \"./acp.mjs\";\nimport type { AgentValueCodecIface } from \"./agent-input.mjs\";\nimport {\n createChannelBindingsApi,\n createChannelTicketsApi,\n createIdentityLinksApi,\n type ChannelBindingsApiIface,\n type ChannelSourceOf,\n type ChannelTicketsApiIface,\n type IdentityLinksApiIface,\n} from \"./channels.mjs\";\nimport { encodePath, type ClientContextIface, type SignalOptionsIface } from \"./context.mjs\";\nimport { createConversationsApi, type ConversationsApiIface } from \"./conversations.mjs\";\nimport {\n defaultAgentCodec,\n defaultChannelSourceOf,\n defaultLocalCompute,\n defaultLocalHostDial,\n} from \"./defaults.mjs\";\nimport { clientError, ClientErrorCode } from \"./errors.mjs\";\nimport {\n createEventsApi,\n createEventSubscriptionsApi,\n type EventsApiIface,\n type EventSubscriptionsApiIface,\n} from \"./events.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 type { LocalComputeIface, LocalHostIface, LocalHostSocketIface } from \"./local-host.mjs\";\nimport { createProjectClient, type ProjectClientIface } from \"./project.mjs\";\nimport { createProjectsApi, type ProjectsApiIface } from \"./projects.mjs\";\nimport { createOrganizationApi, type OrganizationApiIface } from \"./organization.mjs\";\nimport { createPublishersApi, type PublishersApiIface } from \"./publishers.mjs\";\nimport { createSessionsApi, type SessionsApiIface } from \"./sessions.mjs\";\nimport type { AgentStartDepsIface } from \"./start.mjs\";\n\n/** Final's agents API. */\nexport const DEFAULT_AGENTS_HOST = 'https://agent-session.final.ai';\n\nexport interface CreateClientOptionsIface {\n auth: AgentClientAuth;\n /**\n * Whether this process provides the files and shell an agent requires when\n * the caller leaves them out (default true), so the model's file edits and\n * commands run here, on this machine. A server should provide every\n * capability explicitly and pass false, so an omission fails with\n * `requirements_unmet` instead of giving the model a shell in the server.\n */\n localCompute?: boolean;\n /**\n * The agents API origin (default `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 under.\n */\n host?: string;\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 /** Seam: how agent values become documents and in-process code. */\n agentCodec?: AgentValueCodecIface;\n /** Seam: how a channel value becomes its source. */\n channelSourceOf?: ChannelSourceOf;\n /** Seams for local hosts: the socket, and the sandbox this process serves. */\n localHosts?: {\n /** Opens the local host socket; abandons it when `signal` aborts. */\n dial?: (path: string, signal?: AbortSignal) => Promise<LocalHostSocketIface>;\n compute?: Partial<LocalComputeIface>;\n };\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 * Fetch one as data with `client.project({ id }).agents.get`.\n */\n list: (\n options?: SignalOptionsIface & { cursor?: string; limit?: number; projectId?: string },\n ) => Promise<AgentListIface>;\n /**\n * One agent the caller can use, by id, in whichever project owns it; also one that was never\n * published (`hash` and `revisionId` are null). Archived agents are not found.\n */\n get: (args: { id: string } & SignalOptionsIface) => Promise<AgentSummaryIface>;\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 /** The caller's own person (or, for an API key or app, the actor it names). */\n me: { identityLinks: IdentityLinksApiIface };\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 InferenceApiIface {\n /**\n * The vendors and models the platform's own metered inference serves, with\n * prices (`GET /v1/inference/offering`, public). A harness using the\n * platform's inference can run only models listed here.\n */\n offering: (options?: SignalOptionsIface) => Promise<InferenceOfferingIface>;\n}\n\nexport interface PlatformIdentityApiIface {\n /**\n * Exchanges a sandbox-provider (or downstream) assertion the platform issued\n * for a fresh one: for the provider's own URL (a refresh) or a backend its\n * registration was granted. The subject token is the credential.\n */\n exchange: (\n args: PlatformIdentityExchangeRequestIface & SignalOptionsIface,\n ) => Promise<PlatformIdentityExchangeResponseIface>;\n}\n\nexport interface DecisionsApiIface {\n /** One decision awaiting the caller's answer, as `conversations.decisions` lists it. */\n get: (args: { id: string } & SignalOptionsIface) => Promise<DecisionIface>;\n}\n\nexport interface AppApiIface {\n /**\n * The calling app's event subscriptions, across every organization that\n * installed it. Needs an app-level token.\n */\n eventSubscriptions: EventSubscriptionsApiIface;\n}\n\nexport interface AgentClientIface {\n /** One project: where sessions, conversations, sandboxes and integrations are created. */\n project: (args: { id: string }) => ProjectClientIface;\n /** The project tree: list projects and create them. */\n projects: ProjectsApiIface;\n /** The event feed across everything the caller can see; `project({ id }).events` narrows it. */\n events: EventsApiIface;\n app: AppApiIface;\n /** Publishers' public agents, channels, harnesses and ACP adapters. */\n publishers: PublishersApiIface;\n inference: InferenceApiIface;\n platformIdentity: PlatformIdentityApiIface;\n decisions: DecisionsApiIface;\n health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;\n /** The caller's organization: model credentials, budgets and policies. */\n organization: OrganizationApiIface;\n agents: AgentsApiIface;\n people: PeopleApiIface;\n realtime: RealtimeApiIface;\n /** Existing sessions by id; create them through `project({ id }).sessions`. */\n sessions: SessionsApiIface;\n /** The caller's conversations; create them through `project({ id }).conversations`. */\n conversations: ConversationsApiIface;\n /** Channel installs by id; install them through `project({ id }).channels`. */\n channelBindings: ChannelBindingsApiIface;\n /** Tickets from an installer's link and connect pages. */\n channelTickets: ChannelTicketsApiIface;\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 every\n * local host connection (the platform then reports this process's tools and\n * compute as unavailable; sessions carry on) and, when the client created its\n * own realtime transport, closes the gateway connection and cancels its\n * retries. A transport passed in `realtime` belongs to the caller and is left\n * 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 ?? DEFAULT_AGENTS_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 hosts = new Set<LocalHostIface>();\n const localCompute = defaultLocalCompute();\n const start: AgentStartDepsIface = {\n context,\n codec: options.agentCodec ?? defaultAgentCodec,\n localCompute: options.localCompute ?? true,\n compute: { ...localCompute, ...options.localHosts?.compute },\n dial: options.localHosts?.dial ?? defaultLocalHostDial(http),\n hosts,\n };\n const channelSourceOf = options.channelSourceOf ?? defaultChannelSourceOf;\n const clientLevel = { deps: start, projectId: null };\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 for (const host of hosts) host.close();\n hosts.clear();\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: ({ id, signal }) =>\n http.request({\n method: HttpMethod.Get,\n path: `/v1/agents/${encodePath(id)}`,\n response: agentSummarySchema,\n signal,\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 me: { identityLinks: createIdentityLinksApi(context) },\n };\n })(),\n realtime: { createSession: createRealtimeSession },\n project: ({ id }) => createProjectClient({ context, start, channelSourceOf, projectId: id }),\n projects: createProjectsApi(context),\n events: createEventsApi({ context, projectId: null }),\n organization: createOrganizationApi(context),\n app: {\n eventSubscriptions: createEventSubscriptionsApi({\n context,\n basePath: '/v1/apps/me/event-subscriptions',\n }),\n },\n publishers: createPublishersApi(context),\n inference: {\n offering: (offeringOptions) =>\n http.request({\n method: HttpMethod.Get,\n path: '/v1/inference/offering',\n response: inferenceOfferingSchema,\n signal: offeringOptions?.signal,\n }),\n },\n platformIdentity: {\n exchange: ({ signal, ...value }) =>\n http.request({\n method: HttpMethod.Post,\n path: '/v1/platform-identity/exchange',\n body: { schema: platformIdentityExchangeRequestSchema, value },\n response: platformIdentityExchangeResponseSchema,\n signal,\n }),\n },\n decisions: {\n get: async ({ id, signal }) =>\n (\n await http.request({\n method: HttpMethod.Get,\n path: `/v1/decisions/${encodePath(id)}`,\n response: decisionResponseSchema,\n signal,\n context: { decisionId: id },\n })\n ).decision,\n },\n sessions: createSessionsApi(context),\n conversations: createConversationsApi(context, clientLevel),\n channelBindings: createChannelBindingsApi(context),\n channelTickets: createChannelTicketsApi(context),\n acp: createAcpApi({ http }),\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,OAWK;AACP,SAAS,oBAAsC;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,kBAAoE;AAC7E,SAAS,8BAA0D;AACnE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,uBAAuB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,2BAAmD;AAC5D;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AAAA,IAC1D,iBAAiB,yBAAyB,OAAO;AAAA,IACjD,gBAAgB,wBAAwB,OAAO;AAAA,IAC/C,KAAK,aAAa,EAAE,KAAK,CAAC;AAAA,EAC5B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type ParticipantConfigurationApiIface } from "./participant-configuration.mjs";
|
|
1
2
|
import { type ProcessInspectionRequestIface, type ProcessInspectionResultIface } from '@finalai/agent-protocol';
|
|
2
|
-
import { AgentSessionState, type
|
|
3
|
+
import { AgentSessionState, 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 ActorInputIface, type ParticipantInput, type ParticipantProvideResponseIface, 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 ScheduleRunResultIface, type UpdateParticipantRequestIface, type WireFallback } from '@finalai/agent-protocol/agent-platform';
|
|
3
4
|
import type { AgentInput } from "./agent-input.mjs";
|
|
4
5
|
import { type ConversationResourcesIface } from "./conversation-resources.mjs";
|
|
5
6
|
import { type CollectionEvent, type CollectionEventsOptionsIface } from "./collection-events.mjs";
|
|
@@ -104,6 +105,8 @@ export interface ParticipantsApiIface {
|
|
|
104
105
|
* `harness_unsuitable` for harness settings it cannot run on.
|
|
105
106
|
*/
|
|
106
107
|
provide: (participantId: string, patch: ProvidePatchIface, options?: SignalOptionsIface) => Promise<ParticipantProvideResponseIface>;
|
|
108
|
+
/** Changes to an agent participant's settings through proposals a manager decides. */
|
|
109
|
+
configuration: ParticipantConfigurationApiIface;
|
|
107
110
|
}
|
|
108
111
|
export interface SentMessageIface {
|
|
109
112
|
message: ConversationMessageIface;
|
|
@@ -138,9 +141,16 @@ export interface ConversationHandleIface extends ConversationResourcesIface {
|
|
|
138
141
|
send: (content: ContentInput, options?: SendMessageOptionsIface) => Promise<SentMessageIface>;
|
|
139
142
|
events: (options?: ConversationEventsOptionsIface) => AsyncIterableIterator<ConversationEvent>;
|
|
140
143
|
messages: (options?: ListMessagesOptionsIface) => Promise<ConversationMessagesPageIface>;
|
|
141
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* One message: by id (`GET /v1/conversations/:id/messages/:messageId`), e.g. a thread root,
|
|
146
|
+
* or the reply a turn's streamed text became, by the session seq its text started at (a
|
|
147
|
+
* preview's `fromSeq`).
|
|
148
|
+
*/
|
|
142
149
|
message: (args: {
|
|
143
150
|
messageId: string;
|
|
151
|
+
} | {
|
|
152
|
+
turnId: string;
|
|
153
|
+
fromSeq: number;
|
|
144
154
|
}, options?: SignalOptionsIface) => Promise<ConversationMessageIface>;
|
|
145
155
|
react: (args: {
|
|
146
156
|
messageId: string;
|
|
@@ -150,11 +160,6 @@ export interface ConversationHandleIface extends ConversationResourcesIface {
|
|
|
150
160
|
messageId: string;
|
|
151
161
|
emoji: string;
|
|
152
162
|
}, options?: SignalOptionsIface) => Promise<ReactionIface[]>;
|
|
153
|
-
recordPushOpen: (args: {
|
|
154
|
-
deliveryId: string;
|
|
155
|
-
}, options?: SignalOptionsIface) => Promise<{
|
|
156
|
-
recorded: boolean;
|
|
157
|
-
}>;
|
|
158
163
|
markRead: (args: {
|
|
159
164
|
throughSeq: number;
|
|
160
165
|
}, options?: SignalOptionsIface) => Promise<ReadStateIface>;
|
|
@@ -175,13 +180,6 @@ export interface ConversationHandleIface extends ConversationResourcesIface {
|
|
|
175
180
|
typing: (args: {
|
|
176
181
|
typing: boolean;
|
|
177
182
|
}, options?: SignalOptionsIface) => Promise<void>;
|
|
178
|
-
/**
|
|
179
|
-
* Hands something that happened outside the conversation (`POST …/events`)
|
|
180
|
-
* to its Default agent as input from you, not as a message: the agent's
|
|
181
|
-
* reply carries the source as its caption. The same `eventId` from the same
|
|
182
|
-
* source is accepted once; the receipt says whether the agent was prompted.
|
|
183
|
-
*/
|
|
184
|
-
postEvent: (event: PostConversationEventRequestIface, options?: SignalOptionsIface) => Promise<PostConversationEventResponseIface>;
|
|
185
183
|
respond: (args: RespondArgs, options?: SignalOptionsIface) => Promise<RespondDecisionResponseIface>;
|
|
186
184
|
/** Stops the agents' running turns in this conversation. */
|
|
187
185
|
cancel: (options?: SignalOptionsIface & {
|
|
@@ -371,16 +369,6 @@ export interface ProjectConversationsApiIface extends ConversationsApiIface {
|
|
|
371
369
|
* creating nothing, unless each agent's requirements are met.
|
|
372
370
|
*/
|
|
373
371
|
create: (args: CreateConversationArgsIface) => Promise<OpenedConversationIface>;
|
|
374
|
-
/**
|
|
375
|
-
* The caller's own Home thread with the project's agent, found or created.
|
|
376
|
-
* `provide` is stored only when the agent has no settings there yet.
|
|
377
|
-
*/
|
|
378
|
-
home: (args: {
|
|
379
|
-
id?: string;
|
|
380
|
-
provide: ProvideIface;
|
|
381
|
-
} & SignalOptionsIface) => Promise<OpenedConversationIface>;
|
|
382
|
-
/** The caller's Home thread, if there is one. Creates nothing. */
|
|
383
|
-
findHome: (options?: SignalOptionsIface) => Promise<ConversationIface | null>;
|
|
384
372
|
/**
|
|
385
373
|
* The caller's direct conversation with an agent, found or created.
|
|
386
374
|
* `provide` is stored only when the agent has no settings there yet.
|
|
@@ -420,10 +408,14 @@ export interface ConversationsApiIface {
|
|
|
420
408
|
}) => Promise<ConversationListIface>;
|
|
421
409
|
/** I/O-free handle. */
|
|
422
410
|
get: (conversationId: string) => ConversationHandleIface;
|
|
423
|
-
/**
|
|
411
|
+
/**
|
|
412
|
+
* Full-text search over the caller's conversations (or one, or those in a project and the
|
|
413
|
+
* projects below it), newest first.
|
|
414
|
+
*/
|
|
424
415
|
search: (args: {
|
|
425
416
|
q: string;
|
|
426
417
|
conversationId?: string;
|
|
418
|
+
projectId?: string;
|
|
427
419
|
cursor?: string;
|
|
428
420
|
limit?: number;
|
|
429
421
|
} & SignalOptionsIface) => Promise<SearchMessagesPageIface>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createParticipantConfigurationApi
|
|
3
|
+
} from "./participant-configuration.mjs";
|
|
1
4
|
import {
|
|
2
5
|
PROCESS_CAPABILITIES,
|
|
3
6
|
ProcessInspectionOperation,
|
|
@@ -34,7 +37,6 @@ import {
|
|
|
34
37
|
scheduleRunResultSchema,
|
|
35
38
|
DecisionEventState,
|
|
36
39
|
decisionRecordListSchema,
|
|
37
|
-
homeConversationRequestSchema,
|
|
38
40
|
decisionsPageSchema,
|
|
39
41
|
markReadRequestSchema,
|
|
40
42
|
messageDeliveriesSchema,
|
|
@@ -47,10 +49,7 @@ import {
|
|
|
47
49
|
participantListSchema,
|
|
48
50
|
participantProvideResponseSchema,
|
|
49
51
|
participantSchema,
|
|
50
|
-
postConversationEventRequestSchema,
|
|
51
52
|
provideParticipantRequestSchema,
|
|
52
|
-
postConversationEventResponseSchema,
|
|
53
|
-
pushDeliveryOpenResponseSchema,
|
|
54
53
|
reactionRequestSchema,
|
|
55
54
|
reactionsResponseSchema,
|
|
56
55
|
readStateSchema,
|
|
@@ -722,7 +721,10 @@ const createConversationHandle = (context, conversationId, starter) => {
|
|
|
722
721
|
})).deliveries,
|
|
723
722
|
message: (args, options) => http.request({
|
|
724
723
|
method: HttpMethod.Get,
|
|
725
|
-
path: messagePath(conversationId, args.messageId)
|
|
724
|
+
path: "messageId" in args ? messagePath(conversationId, args.messageId) : conversationPath(
|
|
725
|
+
conversationId,
|
|
726
|
+
`/turns/${encodePath(args.turnId)}/messages/${args.fromSeq}`
|
|
727
|
+
),
|
|
726
728
|
response: conversationMessageSchema,
|
|
727
729
|
signal: options?.signal
|
|
728
730
|
}),
|
|
@@ -737,13 +739,6 @@ const createConversationHandle = (context, conversationId, starter) => {
|
|
|
737
739
|
signal: options?.signal
|
|
738
740
|
});
|
|
739
741
|
},
|
|
740
|
-
postEvent: (event, options) => http.request({
|
|
741
|
-
method: HttpMethod.Post,
|
|
742
|
-
path: conversationPath(conversationId, "/events"),
|
|
743
|
-
body: { schema: postConversationEventRequestSchema, value: event },
|
|
744
|
-
response: postConversationEventResponseSchema,
|
|
745
|
-
signal: options?.signal
|
|
746
|
-
}),
|
|
747
742
|
typing: async (args, options) => {
|
|
748
743
|
await http.request({
|
|
749
744
|
method: HttpMethod.Post,
|
|
@@ -753,15 +748,6 @@ const createConversationHandle = (context, conversationId, starter) => {
|
|
|
753
748
|
signal: options?.signal
|
|
754
749
|
});
|
|
755
750
|
},
|
|
756
|
-
recordPushOpen: (args, options) => http.request({
|
|
757
|
-
method: HttpMethod.Post,
|
|
758
|
-
path: conversationPath(
|
|
759
|
-
conversationId,
|
|
760
|
-
`/push-deliveries/${encodeURIComponent(args.deliveryId)}/open`
|
|
761
|
-
),
|
|
762
|
-
response: pushDeliveryOpenResponseSchema,
|
|
763
|
-
signal: options?.signal
|
|
764
|
-
}),
|
|
765
751
|
markRead: (args, options) => http.request({
|
|
766
752
|
method: HttpMethod.Post,
|
|
767
753
|
path: conversationPath(conversationId, "/read"),
|
|
@@ -819,7 +805,8 @@ const createConversationHandle = (context, conversationId, starter) => {
|
|
|
819
805
|
response: participantProvideResponseSchema,
|
|
820
806
|
signal: options?.signal
|
|
821
807
|
});
|
|
822
|
-
}
|
|
808
|
+
},
|
|
809
|
+
configuration: createParticipantConfigurationApi({ context, conversationId })
|
|
823
810
|
}
|
|
824
811
|
),
|
|
825
812
|
turns: async (options) => {
|
|
@@ -1189,6 +1176,7 @@ const createConversationsApi = (context, starter) => {
|
|
|
1189
1176
|
query: {
|
|
1190
1177
|
q: args.q,
|
|
1191
1178
|
conversationId: args.conversationId,
|
|
1179
|
+
projectId: args.projectId,
|
|
1192
1180
|
cursor: args.cursor,
|
|
1193
1181
|
limit: args.limit
|
|
1194
1182
|
},
|
|
@@ -1349,46 +1337,6 @@ const createProjectConversationsApi = (args) => {
|
|
|
1349
1337
|
}
|
|
1350
1338
|
return opened(conversation);
|
|
1351
1339
|
},
|
|
1352
|
-
home: async ({ id, provide, signal }) => {
|
|
1353
|
-
const document = provideDocumentOf(provide);
|
|
1354
|
-
const placed = document.harness == null ? null : await withWorkersEnvironment({
|
|
1355
|
-
context,
|
|
1356
|
-
projectId,
|
|
1357
|
-
harness: document.harness,
|
|
1358
|
-
owner: { kind: LocalHostOwnerKind.Conversation, id },
|
|
1359
|
-
signal
|
|
1360
|
-
});
|
|
1361
|
-
const homeId = placed?.ownerId ?? id;
|
|
1362
|
-
const discard = () => void placed?.created?.discard().catch(() => void 0);
|
|
1363
|
-
try {
|
|
1364
|
-
const { conversation } = await context.http.request({
|
|
1365
|
-
method: HttpMethod.Post,
|
|
1366
|
-
path: "/v1/conversations/home",
|
|
1367
|
-
body: {
|
|
1368
|
-
schema: homeConversationRequestSchema,
|
|
1369
|
-
value: {
|
|
1370
|
-
projectId,
|
|
1371
|
-
id: homeId,
|
|
1372
|
-
provide: placed == null ? document : { ...document, harness: placed.harness }
|
|
1373
|
-
}
|
|
1374
|
-
},
|
|
1375
|
-
response: conversationResponseSchema,
|
|
1376
|
-
signal
|
|
1377
|
-
});
|
|
1378
|
-
if (conversation.id !== homeId) discard();
|
|
1379
|
-
return opened(conversation);
|
|
1380
|
-
} catch (cause) {
|
|
1381
|
-
discard();
|
|
1382
|
-
throw cause;
|
|
1383
|
-
}
|
|
1384
|
-
},
|
|
1385
|
-
findHome: async (options) => (await context.http.request({
|
|
1386
|
-
method: HttpMethod.Get,
|
|
1387
|
-
path: "/v1/conversations/home",
|
|
1388
|
-
query: { projectId },
|
|
1389
|
-
response: conversationLookupSchema,
|
|
1390
|
-
signal: options?.signal
|
|
1391
|
-
})).conversation,
|
|
1392
1340
|
direct: async ({ id, agent, provide, actor, signal }) => {
|
|
1393
1341
|
const started = await startAgent(args.start, {
|
|
1394
1342
|
projectId,
|