@finalai/agents 0.13.0 → 0.15.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.
Files changed (48) hide show
  1. package/README.md +7 -1
  2. package/dist/modules/agent-client/api.d.mts +35 -0
  3. package/dist/modules/agent-client/api.mjs +110 -0
  4. package/dist/modules/agent-client/api.mjs.map +7 -0
  5. package/dist/modules/agent-client/channels.mjs +9 -1
  6. package/dist/modules/agent-client/channels.mjs.map +2 -2
  7. package/dist/modules/agent-client/client.d.mts +29 -7
  8. package/dist/modules/agent-client/client.mjs +15 -12
  9. package/dist/modules/agent-client/client.mjs.map +2 -2
  10. package/dist/modules/agent-client/conversations.d.mts +17 -25
  11. package/dist/modules/agent-client/conversations.mjs +10 -62
  12. package/dist/modules/agent-client/conversations.mjs.map +2 -2
  13. package/dist/modules/agent-client/defaults.d.mts +0 -4
  14. package/dist/modules/agent-client/defaults.mjs +1 -52
  15. package/dist/modules/agent-client/defaults.mjs.map +2 -2
  16. package/dist/modules/agent-client/index.d.mts +2 -33
  17. package/dist/modules/agent-client/index.mjs +3 -109
  18. package/dist/modules/agent-client/index.mjs.map +2 -2
  19. package/dist/modules/agent-client/integrations.d.mts +5 -1
  20. package/dist/modules/agent-client/integrations.mjs +9 -1
  21. package/dist/modules/agent-client/integrations.mjs.map +2 -2
  22. package/dist/modules/agent-client/node.d.mts +2 -0
  23. package/dist/modules/agent-client/node.mjs +62 -0
  24. package/dist/modules/agent-client/node.mjs.map +7 -0
  25. package/dist/modules/agent-client/organization.d.mts +83 -0
  26. package/dist/modules/agent-client/organization.mjs +209 -0
  27. package/dist/modules/agent-client/organization.mjs.map +7 -0
  28. package/dist/modules/agent-client/participant-configuration.d.mts +21 -0
  29. package/dist/modules/agent-client/participant-configuration.mjs +38 -0
  30. package/dist/modules/agent-client/participant-configuration.mjs.map +7 -0
  31. package/dist/modules/agent-client/portable.d.mts +3 -0
  32. package/dist/modules/agent-client/portable.mjs +28 -0
  33. package/dist/modules/agent-client/portable.mjs.map +7 -0
  34. package/dist/modules/agent-client/project.d.mts +3 -0
  35. package/dist/modules/agent-client/project.mjs +3 -1
  36. package/dist/modules/agent-client/project.mjs.map +2 -2
  37. package/dist/modules/agent-client/provide.d.mts +0 -1
  38. package/dist/modules/agent-client/provide.mjs +0 -1
  39. package/dist/modules/agent-client/provide.mjs.map +2 -2
  40. package/dist/modules/agent-client/sandboxes.d.mts +8 -1
  41. package/dist/modules/agent-client/sandboxes.mjs +9 -0
  42. package/dist/modules/agent-client/sandboxes.mjs.map +2 -2
  43. package/dist/modules/agent-client/sessions.d.mts +8 -1
  44. package/dist/modules/agent-client/sessions.mjs +24 -5
  45. package/dist/modules/agent-client/sessions.mjs.map +2 -2
  46. package/dist/modules/cli/cli.mjs +2 -1
  47. package/dist/modules/cli/cli.mjs.map +2 -2
  48. package/package.json +7 -6
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.findHome()` and `findDirect({ agent })` look up without creating.
101
+ `conversations.findDirect({ agent })` looks up without creating.
102
102
 
103
103
  ## Where things run
104
104
 
@@ -118,6 +118,12 @@ gives the model a shell in that backend. A server provides every capability and
118
118
  creates its client with `createClient({ auth, localCompute: false })`, so an
119
119
  omission fails instead.
120
120
 
121
+ In browsers, React Native and Workers, `@finalai/agents/client` resolves (through
122
+ its `browser` and `react-native` export conditions) to a build that imports
123
+ nothing Node-only and serves no compute: `localCompute` defaults to false there,
124
+ and serving in-process tools needs your own `localHosts.dial`. No bundler
125
+ configuration is needed.
126
+
121
127
  An agent is always passed as an object: the value you defined, or one fetched
122
128
  with `project.agents.get({ name } | { id } | { hash })`. A fetched agent is data
123
129
  only; starting one that has in-process tools fails and names them.
@@ -0,0 +1,35 @@
1
+ export * from '@finalai/agent-protocol/agent-platform';
2
+ export { Capability, FilesAccess, ScreenAccess, ShellAccess, type CapabilityAccess, } from '@finalai/agent-protocol';
3
+ export { AcpAuthMode, type AcpApiIface, type AcpConnectArgsIface } from "./acp.mjs";
4
+ export { createTextCollector, isUserMessageFor, sessionUpdateOf, textOf, turnEndOf, type AcpSessionUpdateIface, type TurnEndIface, } from "./acp-frames.mjs";
5
+ export type { AgentInput, AgentValue, AgentValueCodecIface } from "./agent-input.mjs";
6
+ export type { ActorOptionIface, ChannelAppsApiIface, ChannelBindingsApiIface, ChannelSourceIface, ChannelSourceOf, ChannelTicketsApiIface, IdentityLinksApiIface, InstallChannelArgsIface, ProjectChannelsApiIface, PublishChannelArgsIface, UpdateChannelBindingArgsIface, } from "./channels.mjs";
7
+ export { DEFAULT_AGENTS_HOST, type AgentClientIface, type AgentsApiIface, type AppApiIface, type CreateClientOptionsIface, type DecisionsApiIface, type InferenceApiIface, type PeopleApiIface, type PlatformIdentityApiIface, type RealtimeApiIface, } from "./client.mjs";
8
+ export { CollectionEventKind, CollectionResyncReason, type CollectionEvent, type CollectionEventsOptionsIface, type CollectionResyncEventIface, } from "./collection-events.mjs";
9
+ export { ConfigOptionCategory, configSelectFor, configSelectsOf, type ConfigSelectChoiceIface, type ConfigSelectIface, type SessionConfigOptionIface, } from "./config-options.mjs";
10
+ export type { EnumInput, SignalOptionsIface } from "./context.mjs";
11
+ export type { AllowedEndpointsApiIface, BudgetsApiIface, ModelCredentialGrantsApiIface, ModelCredentialsApiIface, OrganizationApiIface, OrganizationPolicyApiIface, SpendingRestrictionsApiIface, } from "./organization.mjs";
12
+ export type { ParticipantConfigurationApiIface } from "./participant-configuration.mjs";
13
+ export type { ConversationChannelRoutesApiIface, ConversationContextApiIface, ConversationContextEntryInputIface, ConversationDecisionsApiIface, ConversationInputsApiIface, ConversationLabelsApiIface, ConversationReadGrantsApiIface, ConversationResourcesIface, ResourceSubscriptionsApiIface, SendInputArgsIface, } from "./conversation-resources.mjs";
14
+ export { TURN_OPEN_SESSION_STATES, isNewerMessageVersion, messageVersionOf, type MessageVersionIface, } from "./conversations.mjs";
15
+ export type { ConversationAgentTurnIface, ConversationEvent, ConversationEventMetaIface, ConversationEventsOptionsIface, ConversationHandleIface, ConversationsApiIface, CreateConversationArgsIface, ListMessagesOptionsIface, OpenedConversationIface, ParticipantCreateInput, ParticipantsApiIface, ProjectConversationsApiIface, SandboxFileContentArgsIface, SandboxFileContentRequestIface, SendMessageOptionsIface, SentMessageIface, UploadAttachmentArgsIface, } from "./conversations.mjs";
16
+ export { AgentClientErrorName, ClientErrorCode, DecisionErrorReason, clientError, decisionError, isClientError, isDecisionError, isRealtimeSubscriptionError, isRequirementsUnmetError, isTerminalRealtimeError, isTurnRejectedError, realtimeSubscriptionError, requirementsUnmetError, turnRejectedError, type AgentClientError, type ClientErrorIface, type DecisionErrorIface, type RealtimeSubscriptionErrorIface, type RequirementsUnmetErrorIface, type TurnRejectedErrorIface, } from "./errors.mjs";
17
+ export { EVENTS_POLL_INTERVAL_MS, type EventsApiIface, type EventSubscriptionsApiIface, type ListEventsOptionsIface, type StreamEventsOptionsIface, } from "./events.mjs";
18
+ export { defaultStreamTiming, type StreamTimingIface } from "./frame-stream.mjs";
19
+ export type { AgentClientAuth, FetchIface, HeadersOption } from "./http.mjs";
20
+ export type { AcpAdaptersApiIface, DefinitionSelectorIface, HarnessesApiIface, SubscriptionAllowancesApiIface, } from "./harnesses.mjs";
21
+ export type { IntegrationsApiIface } from "./integrations.mjs";
22
+ export { SessionLiveEventKind, type SessionLiveEvent } from "./live-stream.mjs";
23
+ export type { LocalComputeIface } from "./local-host.mjs";
24
+ export type { OAuthClientsApiIface, SignInReturnOriginsApiIface } from "./oauth-clients.mjs";
25
+ export type { ProjectClientIface } from "./project.mjs";
26
+ export type { AgentSelectorIface, ProjectAgentsApiIface } from "./project-agents.mjs";
27
+ export type { ProjectApiKeysApiIface, ProjectMembersApiIface, ProjectResourceApiIface, ProjectsApiIface, } from "./projects.mjs";
28
+ export type { ProjectPublisherApiIface, PublicNamesApiIface, PublisherHandleIface, PublishersApiIface, } from "./publishers.mjs";
29
+ export { provideDocumentOf, resourceIdOf, type ProvideIface, type ProvidePatchIface, type ResourceRef, type ResourceRefIface, } from "./provide.mjs";
30
+ export { createGatewayRealtimeTransport, type GatewayConnect, type GatewayConnectionIface, type GatewayRealtimeTransportOptionsIface, type RealtimeSubscribeOptionsIface, type RealtimeTransportFrameIface, type RealtimeTransportIface, } from "./realtime.mjs";
31
+ export { SANDBOX_FILE_URI_SCHEME, createSandboxFileUri, parseSandboxFileUri, type SandboxFileTargetIface, } from "./sandbox-uri.mjs";
32
+ export type { SandboxProvidersApiIface } from "./sandbox-providers.mjs";
33
+ export type { CreateSandboxOptionsIface, SandboxEnvironmentValueIface, SandboxHandleIface, SandboxOwnerIface, SandboxSetupRefIface, SandboxSetupsApiIface, SandboxesApiIface, } from "./sandboxes.mjs";
34
+ export type { ProjectSchedulesApiIface } from "./schedules.mjs";
35
+ export type { CreateSessionArgsIface, CreatedSessionIface, ForkSessionOptionsIface, ProjectSessionsApiIface, RespondArgs, SendOptionsIface, SessionHandleIface, SessionsApiIface, StreamOptionsIface, TurnHandleIface, TurnResultIface, } from "./sessions.mjs";
@@ -0,0 +1,110 @@
1
+ export * from "@finalai/agent-protocol/agent-platform";
2
+ import {
3
+ Capability,
4
+ FilesAccess,
5
+ ScreenAccess,
6
+ ShellAccess
7
+ } from "@finalai/agent-protocol";
8
+ import { AcpAuthMode } from "./acp.mjs";
9
+ import {
10
+ createTextCollector,
11
+ isUserMessageFor,
12
+ sessionUpdateOf,
13
+ textOf,
14
+ turnEndOf
15
+ } from "./acp-frames.mjs";
16
+ import {
17
+ DEFAULT_AGENTS_HOST
18
+ } from "./client.mjs";
19
+ import {
20
+ CollectionEventKind,
21
+ CollectionResyncReason
22
+ } from "./collection-events.mjs";
23
+ import {
24
+ ConfigOptionCategory,
25
+ configSelectFor,
26
+ configSelectsOf
27
+ } from "./config-options.mjs";
28
+ import {
29
+ TURN_OPEN_SESSION_STATES,
30
+ isNewerMessageVersion,
31
+ messageVersionOf
32
+ } from "./conversations.mjs";
33
+ import {
34
+ AgentClientErrorName,
35
+ ClientErrorCode,
36
+ DecisionErrorReason,
37
+ clientError,
38
+ decisionError,
39
+ isClientError,
40
+ isDecisionError,
41
+ isRealtimeSubscriptionError,
42
+ isRequirementsUnmetError,
43
+ isTerminalRealtimeError,
44
+ isTurnRejectedError,
45
+ realtimeSubscriptionError,
46
+ requirementsUnmetError,
47
+ turnRejectedError
48
+ } from "./errors.mjs";
49
+ import {
50
+ EVENTS_POLL_INTERVAL_MS
51
+ } from "./events.mjs";
52
+ import { defaultStreamTiming } from "./frame-stream.mjs";
53
+ import { SessionLiveEventKind } from "./live-stream.mjs";
54
+ import {
55
+ provideDocumentOf,
56
+ resourceIdOf
57
+ } from "./provide.mjs";
58
+ import {
59
+ createGatewayRealtimeTransport
60
+ } from "./realtime.mjs";
61
+ import {
62
+ SANDBOX_FILE_URI_SCHEME,
63
+ createSandboxFileUri,
64
+ parseSandboxFileUri
65
+ } from "./sandbox-uri.mjs";
66
+ export {
67
+ AcpAuthMode,
68
+ AgentClientErrorName,
69
+ Capability,
70
+ ClientErrorCode,
71
+ CollectionEventKind,
72
+ CollectionResyncReason,
73
+ ConfigOptionCategory,
74
+ DEFAULT_AGENTS_HOST,
75
+ DecisionErrorReason,
76
+ EVENTS_POLL_INTERVAL_MS,
77
+ FilesAccess,
78
+ SANDBOX_FILE_URI_SCHEME,
79
+ ScreenAccess,
80
+ SessionLiveEventKind,
81
+ ShellAccess,
82
+ TURN_OPEN_SESSION_STATES,
83
+ clientError,
84
+ configSelectFor,
85
+ configSelectsOf,
86
+ createGatewayRealtimeTransport,
87
+ createSandboxFileUri,
88
+ createTextCollector,
89
+ decisionError,
90
+ defaultStreamTiming,
91
+ isClientError,
92
+ isDecisionError,
93
+ isNewerMessageVersion,
94
+ isRealtimeSubscriptionError,
95
+ isRequirementsUnmetError,
96
+ isTerminalRealtimeError,
97
+ isTurnRejectedError,
98
+ isUserMessageFor,
99
+ messageVersionOf,
100
+ parseSandboxFileUri,
101
+ provideDocumentOf,
102
+ realtimeSubscriptionError,
103
+ requirementsUnmetError,
104
+ resourceIdOf,
105
+ sessionUpdateOf,
106
+ textOf,
107
+ turnEndOf,
108
+ turnRejectedError
109
+ };
110
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/agent-client/api.ts"],
4
+ "sourcesContent": ["// Everything `@finalai/agents/client` exports in every runtime except\n// `createClient`, which each runtime's entry binds to its own defaults.\n// Wire types come from `@finalai/agent-protocol/agent-platform`, re-exported\n// here so consumers need one import.\n\nexport * from '@finalai/agent-protocol/agent-platform';\nexport {\n Capability,\n FilesAccess,\n ScreenAccess,\n ShellAccess,\n type CapabilityAccess,\n} from '@finalai/agent-protocol';\nexport { AcpAuthMode, type AcpApiIface, type AcpConnectArgsIface } from \"./acp.mjs\";\nexport {\n createTextCollector,\n isUserMessageFor,\n sessionUpdateOf,\n textOf,\n turnEndOf,\n type AcpSessionUpdateIface,\n type TurnEndIface,\n} from \"./acp-frames.mjs\";\nexport type { AgentInput, AgentValue, AgentValueCodecIface } from \"./agent-input.mjs\";\nexport type {\n ActorOptionIface,\n ChannelAppsApiIface,\n ChannelBindingsApiIface,\n ChannelSourceIface,\n ChannelSourceOf,\n ChannelTicketsApiIface,\n IdentityLinksApiIface,\n InstallChannelArgsIface,\n ProjectChannelsApiIface,\n PublishChannelArgsIface,\n UpdateChannelBindingArgsIface,\n} from \"./channels.mjs\";\nexport {\n DEFAULT_AGENTS_HOST,\n type AgentClientIface,\n type AgentsApiIface,\n type AppApiIface,\n type CreateClientOptionsIface,\n type DecisionsApiIface,\n type InferenceApiIface,\n type PeopleApiIface,\n type PlatformIdentityApiIface,\n type RealtimeApiIface,\n} from \"./client.mjs\";\nexport {\n CollectionEventKind,\n CollectionResyncReason,\n type CollectionEvent,\n type CollectionEventsOptionsIface,\n type CollectionResyncEventIface,\n} from \"./collection-events.mjs\";\nexport {\n ConfigOptionCategory,\n configSelectFor,\n configSelectsOf,\n type ConfigSelectChoiceIface,\n type ConfigSelectIface,\n type SessionConfigOptionIface,\n} from \"./config-options.mjs\";\nexport type { EnumInput, SignalOptionsIface } from \"./context.mjs\";\nexport type {\n AllowedEndpointsApiIface,\n BudgetsApiIface,\n ModelCredentialGrantsApiIface,\n ModelCredentialsApiIface,\n OrganizationApiIface,\n OrganizationPolicyApiIface,\n SpendingRestrictionsApiIface,\n} from \"./organization.mjs\";\nexport type { ParticipantConfigurationApiIface } from \"./participant-configuration.mjs\";\nexport type {\n ConversationChannelRoutesApiIface,\n ConversationContextApiIface,\n ConversationContextEntryInputIface,\n ConversationDecisionsApiIface,\n ConversationInputsApiIface,\n ConversationLabelsApiIface,\n ConversationReadGrantsApiIface,\n ConversationResourcesIface,\n ResourceSubscriptionsApiIface,\n SendInputArgsIface,\n} from \"./conversation-resources.mjs\";\nexport {\n TURN_OPEN_SESSION_STATES,\n isNewerMessageVersion,\n messageVersionOf,\n type MessageVersionIface,\n} from \"./conversations.mjs\";\nexport type {\n ConversationAgentTurnIface,\n ConversationEvent,\n ConversationEventMetaIface,\n ConversationEventsOptionsIface,\n ConversationHandleIface,\n ConversationsApiIface,\n CreateConversationArgsIface,\n ListMessagesOptionsIface,\n OpenedConversationIface,\n ParticipantCreateInput,\n ParticipantsApiIface,\n ProjectConversationsApiIface,\n SandboxFileContentArgsIface,\n SandboxFileContentRequestIface,\n SendMessageOptionsIface,\n SentMessageIface,\n UploadAttachmentArgsIface,\n} from \"./conversations.mjs\";\nexport {\n AgentClientErrorName,\n ClientErrorCode,\n DecisionErrorReason,\n clientError,\n decisionError,\n isClientError,\n isDecisionError,\n isRealtimeSubscriptionError,\n isRequirementsUnmetError,\n isTerminalRealtimeError,\n isTurnRejectedError,\n realtimeSubscriptionError,\n requirementsUnmetError,\n turnRejectedError,\n type AgentClientError,\n type ClientErrorIface,\n type DecisionErrorIface,\n type RealtimeSubscriptionErrorIface,\n type RequirementsUnmetErrorIface,\n type TurnRejectedErrorIface,\n} from \"./errors.mjs\";\nexport {\n EVENTS_POLL_INTERVAL_MS,\n type EventsApiIface,\n type EventSubscriptionsApiIface,\n type ListEventsOptionsIface,\n type StreamEventsOptionsIface,\n} from \"./events.mjs\";\nexport { defaultStreamTiming, type StreamTimingIface } from \"./frame-stream.mjs\";\nexport type { AgentClientAuth, FetchIface, HeadersOption } from \"./http.mjs\";\nexport type {\n AcpAdaptersApiIface,\n DefinitionSelectorIface,\n HarnessesApiIface,\n SubscriptionAllowancesApiIface,\n} from \"./harnesses.mjs\";\nexport type { IntegrationsApiIface } from \"./integrations.mjs\";\nexport { SessionLiveEventKind, type SessionLiveEvent } from \"./live-stream.mjs\";\nexport type { LocalComputeIface } from \"./local-host.mjs\";\nexport type { OAuthClientsApiIface, SignInReturnOriginsApiIface } from \"./oauth-clients.mjs\";\nexport type { ProjectClientIface } from \"./project.mjs\";\nexport type { AgentSelectorIface, ProjectAgentsApiIface } from \"./project-agents.mjs\";\nexport type {\n ProjectApiKeysApiIface,\n ProjectMembersApiIface,\n ProjectResourceApiIface,\n ProjectsApiIface,\n} from \"./projects.mjs\";\nexport type {\n ProjectPublisherApiIface,\n PublicNamesApiIface,\n PublisherHandleIface,\n PublishersApiIface,\n} from \"./publishers.mjs\";\nexport {\n provideDocumentOf,\n resourceIdOf,\n type ProvideIface,\n type ProvidePatchIface,\n type ResourceRef,\n type ResourceRefIface,\n} from \"./provide.mjs\";\nexport {\n createGatewayRealtimeTransport,\n type GatewayConnect,\n type GatewayConnectionIface,\n type GatewayRealtimeTransportOptionsIface,\n type RealtimeSubscribeOptionsIface,\n type RealtimeTransportFrameIface,\n type RealtimeTransportIface,\n} from \"./realtime.mjs\";\nexport {\n SANDBOX_FILE_URI_SCHEME,\n createSandboxFileUri,\n parseSandboxFileUri,\n type SandboxFileTargetIface,\n} from \"./sandbox-uri.mjs\";\nexport type { SandboxProvidersApiIface } from \"./sandbox-providers.mjs\";\nexport type {\n CreateSandboxOptionsIface,\n SandboxEnvironmentValueIface,\n SandboxHandleIface,\n SandboxOwnerIface,\n SandboxSetupRefIface,\n SandboxSetupsApiIface,\n SandboxesApiIface,\n} from \"./sandboxes.mjs\";\nexport type { ProjectSchedulesApiIface } from \"./schedules.mjs\";\nexport type {\n CreateSessionArgsIface,\n CreatedSessionIface,\n ForkSessionOptionsIface,\n ProjectSessionsApiIface,\n RespondArgs,\n SendOptionsIface,\n SessionHandleIface,\n SessionsApiIface,\n StreamOptionsIface,\n TurnHandleIface,\n TurnResultIface,\n} from \"./sessions.mjs\";\n"],
5
+ "mappings": "AAKA,cAAc;AACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAA+D;AACxE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAeP;AAAA,EACE;AAAA,OAUK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAwBP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAoBP;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,OAOK;AACP;AAAA,EACE;AAAA,OAKK;AACP,SAAS,2BAAmD;AAS5D,SAAS,4BAAmD;AAiB5D;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;",
6
+ "names": []
7
+ }
@@ -71,7 +71,12 @@ const createProjectChannelsApi = (args) => {
71
71
  path: installsPath,
72
72
  body: {
73
73
  schema: installChannelRequestSchema,
74
- value: { ...install, agents: { provide: provideDocumentOf(agents.provide) } }
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,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,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AAO,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;",
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,QACh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AAM;AAC1C,YAAM,IAAI,KAAK,QAAQ;AAAA,QACrB,QAAQ,WAAW;AAAA,QACnB,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC,EAAE;AAAA,QACpC,MAAM,EAAE,QAAQ,wCAAwC,MAAM;AAAA,QAC9D,UAAU;AAAA,QACV;AAAA,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";
@@ -6,11 +6,12 @@ import { type SignalOptionsIface } from "./context.mjs";
6
6
  import { type ConversationsApiIface } from "./conversations.mjs";
7
7
  import { type EventsApiIface, type EventSubscriptionsApiIface } from "./events.mjs";
8
8
  import { type StreamTimingIface } from "./frame-stream.mjs";
9
- import { type AgentClientAuth, type FetchIface, type HeadersOption } from "./http.mjs";
9
+ import { type AgentClientAuth, type FetchIface, type HeadersOption, type HttpIface } from "./http.mjs";
10
10
  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. */
@@ -19,10 +20,11 @@ export interface CreateClientOptionsIface {
19
20
  auth: AgentClientAuth;
20
21
  /**
21
22
  * Whether this process provides the files and shell an agent requires when
22
- * the caller leaves them out (default true), so the model's file edits and
23
- * commands run here, on this machine. A server should provide every
24
- * capability explicitly and pass false, so an omission fails with
25
- * `requirements_unmet` instead of giving the model a shell in the server.
23
+ * the caller leaves them out, so the model's file edits and commands run
24
+ * here, on this machine. Defaults to true in Node and false in browsers and
25
+ * React Native, which have no files or shell to give. A server should
26
+ * provide every capability explicitly and pass false, so an omission fails
27
+ * with `requirements_unmet` instead of giving the model a shell in the server.
26
28
  */
27
29
  localCompute?: boolean;
28
30
  /**
@@ -74,6 +76,13 @@ export interface AgentsApiIface {
74
76
  limit?: number;
75
77
  projectId?: string;
76
78
  }) => Promise<AgentListIface>;
79
+ /**
80
+ * One agent the caller can use, by id, in whichever project owns it; also one that was never
81
+ * published (`hash` and `revisionId` are null). Archived agents are not found.
82
+ */
83
+ get: (args: {
84
+ id: string;
85
+ } & SignalOptionsIface) => Promise<AgentSummaryIface>;
77
86
  }
78
87
  export interface PeopleApiIface {
79
88
  /** One page of the caller's organization members, by name; pass `nextCursor` as `cursor` for the next. */
@@ -141,6 +150,8 @@ export interface AgentClientIface {
141
150
  platformIdentity: PlatformIdentityApiIface;
142
151
  decisions: DecisionsApiIface;
143
152
  health: (options?: SignalOptionsIface) => Promise<HealthResponseIface>;
153
+ /** The caller's organization: model credentials, budgets and policies. */
154
+ organization: OrganizationApiIface;
144
155
  agents: AgentsApiIface;
145
156
  people: PeopleApiIface;
146
157
  realtime: RealtimeApiIface;
@@ -168,4 +179,15 @@ export interface AgentClientIface {
168
179
  close: () => void;
169
180
  [Symbol.asyncDispose]: () => Promise<void>;
170
181
  }
171
- export declare const createClient: (options: CreateClientOptionsIface) => AgentClientIface;
182
+ /**
183
+ * What `createClient` uses unless a seam replaces it, where that differs by
184
+ * runtime: Node serves compute and dials the local host socket itself;
185
+ * browsers and React Native do neither unless the caller passes the seams.
186
+ */
187
+ export interface ClientRuntimeIface {
188
+ /** `localCompute` when the caller leaves it out. */
189
+ localCompute: boolean;
190
+ compute: () => LocalComputeIface;
191
+ dial: (http: HttpIface) => (path: string, signal?: AbortSignal) => Promise<LocalHostSocketIface>;
192
+ }
193
+ export declare const createClientFor: (runtime: ClientRuntimeIface, options: CreateClientOptionsIface) => AgentClientIface;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  agentListSchema,
3
3
  agentRealtimeTopics,
4
+ agentSummarySchema,
4
5
  decisionResponseSchema,
5
6
  healthResponseSchema,
6
7
  inferenceOfferingSchema,
@@ -17,12 +18,7 @@ import {
17
18
  } from "./channels.mjs";
18
19
  import { encodePath } from "./context.mjs";
19
20
  import { createConversationsApi } from "./conversations.mjs";
20
- import {
21
- defaultAgentCodec,
22
- defaultChannelSourceOf,
23
- defaultLocalCompute,
24
- defaultLocalHostDial
25
- } from "./defaults.mjs";
21
+ import { defaultAgentCodec, defaultChannelSourceOf } from "./defaults.mjs";
26
22
  import { clientError, ClientErrorCode } from "./errors.mjs";
27
23
  import {
28
24
  createEventsApi,
@@ -38,10 +34,11 @@ import {
38
34
  } from "./realtime.mjs";
39
35
  import { createProjectClient } from "./project.mjs";
40
36
  import { createProjectsApi } from "./projects.mjs";
37
+ import { createOrganizationApi } from "./organization.mjs";
41
38
  import { createPublishersApi } from "./publishers.mjs";
42
39
  import { createSessionsApi } from "./sessions.mjs";
43
40
  const DEFAULT_AGENTS_HOST = "https://agent-session.final.ai";
44
- const createClient = (options) => {
41
+ const createClientFor = (runtime, options) => {
45
42
  const http = createHttp({
46
43
  host: options.host ?? DEFAULT_AGENTS_HOST,
47
44
  auth: options.auth,
@@ -108,13 +105,12 @@ const createClient = (options) => {
108
105
  now: options.now ?? Date.now
109
106
  };
110
107
  const hosts = /* @__PURE__ */ new Set();
111
- const localCompute = defaultLocalCompute();
112
108
  const start = {
113
109
  context,
114
110
  codec: options.agentCodec ?? defaultAgentCodec,
115
- localCompute: options.localCompute ?? true,
116
- compute: { ...localCompute, ...options.localHosts?.compute },
117
- dial: options.localHosts?.dial ?? defaultLocalHostDial(http),
111
+ localCompute: options.localCompute ?? runtime.localCompute,
112
+ compute: { ...runtime.compute(), ...options.localHosts?.compute },
113
+ dial: options.localHosts?.dial ?? runtime.dial(http),
118
114
  hosts
119
115
  };
120
116
  const channelSourceOf = options.channelSourceOf ?? defaultChannelSourceOf;
@@ -148,6 +144,12 @@ const createClient = (options) => {
148
144
  },
149
145
  response: agentListSchema,
150
146
  signal: listOptions?.signal
147
+ }),
148
+ get: ({ id, signal }) => http.request({
149
+ method: HttpMethod.Get,
150
+ path: `/v1/agents/${encodePath(id)}`,
151
+ response: agentSummarySchema,
152
+ signal
151
153
  })
152
154
  },
153
155
  people: (() => {
@@ -177,6 +179,7 @@ const createClient = (options) => {
177
179
  project: ({ id }) => createProjectClient({ context, start, channelSourceOf, projectId: id }),
178
180
  projects: createProjectsApi(context),
179
181
  events: createEventsApi({ context, projectId: null }),
182
+ organization: createOrganizationApi(context),
180
183
  app: {
181
184
  eventSubscriptions: createEventSubscriptionsApi({
182
185
  context,
@@ -219,6 +222,6 @@ const createClient = (options) => {
219
222
  };
220
223
  export {
221
224
  DEFAULT_AGENTS_HOST,
222
- createClient
225
+ createClientFor
223
226
  };
224
227
  //# sourceMappingURL=client.mjs.map
@@ -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,OAUK;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;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAIK;AAEP,SAAS,2BAAoD;AAC7D,SAAS,yBAAgD;AACzD,SAAS,2BAAoD;AAC7D,SAAS,yBAAgD;AAIlD,MAAM,sBAAsB;AA6J5B,MAAM,eAAe,CAAC,YAAwD;AACnF,QAAM,OAAO,WAAW;AAAA,IACtB,MAAM,QAAQ,QAAQ;AAAA,IACtB,MAAM,QAAQ;AAAA,IACd,SAAS,QAAQ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AAU,CAAC,oBACT,KAAK,QAAQ;AAAA,QACX,QAAQ,WAAW;AAAA,QACnB,MAAM;AAAA,QACN,UAAU;AAAA,QACV,QAAQ,iBAAiB;AAAA,MAC3B,CAAC;AAAA,IACL;AAAA,IACA,kBAAkB;AAAA,MAChB,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,MAC5B,KAAK,QAAQ;AAAA,QACX,QAAQ,WAAW;AAAA,QACnB,MAAM;AAAA,QACN,MAAM,EAAE,QAAQ,uCAAuC,MAAM;AAAA,QAC7D,UAAU;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACL;AAAA,IACA,WAAW;AAAA,MACT,KAAK,OAAO,EAAE,IAAI,OAAO,OAErB,MAAM,KAAK,QAAQ;AAAA,QACjB,QAAQ,WAAW;AAAA,QACnB,MAAM,iBAAiB,WAAW,EAAE,CAAC;AAAA,QACrC,UAAU;AAAA,QACV;AAAA,QACA,SAAS,EAAE,YAAY,GAAG;AAAA,MAC5B,CAAC,GACD;AAAA,IACN;AAAA,IACA,UAAU,kBAAkB,OAAO;AAAA,IACnC,eAAe,uBAAuB,SAAS,WAAW;AAAA,IAC1D,iBAAiB,yBAAyB,OAAO;AAAA,IACjD,gBAAgB,wBAAwB,OAAO;AAAA,IAC/C,KAAK,aAAa,EAAE,KAAK,CAAC;AAAA,EAC5B;AACF;",
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 { defaultAgentCodec, defaultChannelSourceOf } 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 type HttpIface,\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, so the model's file edits and commands run\n * here, on this machine. Defaults to true in Node and false in browsers and\n * React Native, which have no files or shell to give. A server should\n * provide every capability explicitly and pass false, so an omission fails\n * with `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\n/**\n * What `createClient` uses unless a seam replaces it, where that differs by\n * runtime: Node serves compute and dials the local host socket itself;\n * browsers and React Native do neither unless the caller passes the seams.\n */\nexport interface ClientRuntimeIface {\n /** `localCompute` when the caller leaves it out. */\n localCompute: boolean;\n compute: () => LocalComputeIface;\n dial: (http: HttpIface) => (path: string, signal?: AbortSignal) => Promise<LocalHostSocketIface>;\n}\n\nexport const createClientFor = (\n runtime: ClientRuntimeIface,\n options: CreateClientOptionsIface,\n): 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 start: AgentStartDepsIface = {\n context,\n codec: options.agentCodec ?? defaultAgentCodec,\n localCompute: options.localCompute ?? runtime.localCompute,\n compute: { ...runtime.compute(), ...options.localHosts?.compute },\n dial: options.localHosts?.dial ?? runtime.dial(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,SAAS,mBAAmB,8BAA8B;AAC1D,SAAS,aAAa,uBAAuB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,2BAAmD;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAIK;AAEP,SAAS,2BAAoD;AAC7D,SAAS,yBAAgD;AACzD,SAAS,6BAAwD;AACjE,SAAS,2BAAoD;AAC7D,SAAS,yBAAgD;AAIlD,MAAM,sBAAsB;AAiL5B,MAAM,kBAAkB,CAC7B,SACA,YACqB;AACrB,QAAM,OAAO,WAA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