@collective-intelligence/external-apps-client-sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,67 +1,270 @@
1
- import { B as ConversationHistory, D as CiError$1, F as JsonValue, G as SearchQuery, H as JsonObject, K as WorkflowInvokeTarget, M as CiError$2, R as AgentInvokeTarget, U as KnowledgeQuery, W as QueryFilter, c as FederatedSessionIdentity, i as ClientFetch, s as FederatedAuthState, v as ClientOperationDefinition, z as ConversationContinueTarget } from "./proxy-B4MA1pat.js";
2
- import { n as ClientSdkClient } from "./client-C-o7Az4B.js";
3
- import "./resources-Du03G6Wo.js";
4
- import "effect/Context";
5
- import "effect/Effect";
6
- import "effect/Layer";
1
+ import { $t as ClientOperationInput, An as ExternalApplicationIntentDispatchOutcome, Cn as KnowledgeQuery, Dn as AccessCheckResponse, En as WorkflowInvokeTarget, Et as ProxyTransportOptions, Mt as FederatedSessionIdentity, On as AccessTarget, Ot as ClientFetch, Qt as ClientOperationId, Sn as JsonObject, Tn as SearchQuery, Zt as ClientOperationDefinition, _n as AgentInvokeTarget, bn as ExternalApplicationChatOperationId, cn as CiTransportError, dn as CiError$2, en as ClientOperationMap, jn as ExternalApplicationIntentDispatchState, jt as FederatedAuthState, kn as ExternalApplicationIntent, mn as JsonValue, nn as OperationExecutionOptions, on as CiError$1, pn as CiResult, rn as TypedOperationExecutor, tn as ClientOperationOutput, vn as ConversationContinueTarget, wn as QueryFilter, xn as ExternalApplicationIntentDispatchInput, yn as ConversationHistory } from "./resources-D_PdfDpJ.js";
2
+ import "effect/Clock";
3
+ import * as Config from "effect/Config";
4
+ import * as Context from "effect/Context";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
7
  import "effect/Stream";
8
- /** One equality filter on a dotted data path of a topic's records. */
9
- type RealtimeTopicFilter = Readonly<{
10
- field: string;
11
- eq: string | number | boolean | null;
12
- }>;
13
- /** The records of one entity schema, named by FQN or id, optionally filtered. */
14
- type RealtimeTopic = Readonly<{
15
- schema: string;
16
- filter?: RealtimeTopicFilter;
17
- }>;
18
- /** A record of a subscribed topic changed; refetch it, the event carries ids only. */
19
- type RealtimeChange = Readonly<{
20
- id: string;
21
- op: "create" | "update" | "delete";
22
- revision: string;
23
- topic: RealtimeTopic;
24
- }>;
25
- /** One stable key per topic, whatever the key order of the object. */
26
- declare const realtimeTopicKey: ({ filter, schema }: RealtimeTopic) => string;
27
- type PageEvents = Readonly<{
28
- addEventListener: (type: string, listener: () => void) => void;
29
- removeEventListener: (type: string, listener: () => void) => void;
30
- }>;
31
- type RealtimeDocument = PageEvents & Readonly<{
32
- visibilityState: DocumentVisibilityState;
33
- }>;
34
- type RealtimeWindow = PageEvents;
35
- /** One dispatched Server-Sent Event. */
36
- type RealtimeStreamEvent = Readonly<{
37
- type: string;
38
- data: string;
39
- /** The `id:` of this event, when it carried one. */
40
- id: string | undefined;
8
+ import "effect/ManagedRuntime";
9
+ type DirectTransportOptions = Readonly<{
10
+ auth: Readonly<{
11
+ getAccessToken: () => Promise<string> | string;
12
+ }>;
13
+ fetch?: ClientFetch;
14
+ tenantUrl: string;
41
15
  }>;
42
16
  /**
43
- * How a stream ended: `status` when the server refused it, and the
44
- * reconnect delay the server asked for with `retry:` or `Retry-After`.
17
+ * The Vanilla Facade of `CiClient.layerDirect`, in a runtime of its own;
18
+ * `close` disposes it. A bad `tenantUrl` throws `TypeError`.
45
19
  */
46
- type RealtimeStreamEnd = Readonly<{
47
- status: number | undefined;
48
- retryMilliseconds: number | undefined;
49
- }>;
50
- type RealtimeStreamHandlers = Readonly<{
51
- onOpen: () => void;
52
- onEvent: (event: RealtimeStreamEvent) => void;
53
- /** A comment or an `id:`-only frame: the server is alive. */
54
- onPing: (id?: string) => void;
55
- /** Called once, unless the stream was closed by the client. */
56
- onEnd: (end: RealtimeStreamEnd) => void;
20
+ declare const createDirectTransport: <Operations extends ClientOperationMap>(options: DirectTransportOptions) => TypedOperationExecutor<Operations> & Readonly<{
21
+ close: () => Promise<void>;
57
22
  }>;
58
- type RealtimeEventSource = Readonly<{
59
- close: () => void;
23
+ type Input<Id extends ClientOperationId> = ClientOperationMap[Id]["input"];
24
+ type Output<Id extends ClientOperationId> = ClientOperationMap[Id]["output"];
25
+ /** One CI operation as its `CiResult` envelope; only a transport failure fails. */
26
+ type ExecuteResult<R = never> = <Id extends ClientOperationId>(operationId: Id, input: Input<Id>, options: OperationExecutionOptions) => Effect.Effect<CiResult<Output<Id>>, CiTransportError, R>;
27
+ type CiClientValue = Readonly<{
28
+ /**
29
+ * The result of one operation. An Expected Error of CI fails with
30
+ * `CiError`; a request that does not reach CI fails with
31
+ * `CiTransportError`. Interruption cancels the request.
32
+ */
33
+ execute: <Id extends ClientOperationId>(operationId: Id, input: Input<Id>, options: OperationExecutionOptions) => Effect.Effect<Output<Id>, CiError$1 | CiTransportError>;
34
+ /** The same call as its envelope, which keeps the correlation id of CI. */
35
+ executeResult: ExecuteResult;
60
36
  }>;
61
- /** Opens one event stream; `close` stops it without calling `onEnd`. */
62
- type RealtimeEventSourceFactory = (url: string, handlers: RealtimeStreamHandlers) => RealtimeEventSource;
63
- /** Reads `text/event-stream` with `fetch`, so pings and refusals are visible. */
64
- declare const createFetchEventSourceFactory: (fetch: ClientFetch) => RealtimeEventSourceFactory;
37
+ declare const CiClient_base: Context.ServiceClass<CiClient, "@collective-intelligence/external-apps-client-sdk/CiClient", Readonly<{
38
+ /**
39
+ * The result of one operation. An Expected Error of CI fails with
40
+ * `CiError`; a request that does not reach CI fails with
41
+ * `CiTransportError`. Interruption cancels the request.
42
+ */
43
+ execute: <Id extends ClientOperationId>(operationId: Id, input: Input<Id>, options: OperationExecutionOptions) => Effect.Effect<Output<Id>, CiError$1 | CiTransportError>;
44
+ /** The same call as its envelope, which keeps the correlation id of CI. */
45
+ executeResult: ExecuteResult;
46
+ }>>;
47
+ declare class CiClient extends CiClient_base {}
48
+ /** `CiClient` over the tenant Application HTTP API; a bad `tenantUrl` dies with `TypeError`. */
49
+ declare const layerDirect: (options: DirectTransportOptions) => Layer.Layer<CiClient, never, never>;
50
+ /** `CiClient` over the app's protocol proxy; a bad `serverUrl` or `path` dies with `TypeError`. */
51
+ declare const layerProxy: (options: ProxyTransportOptions) => Layer.Layer<CiClient, never, never>;
52
+ /** `CiClient` over a `TypedOperationExecutor`, such as the transport of `createClient`. */
53
+ declare const layerFromExecutor: <Operations extends ClientOperationMap>(executor: TypedOperationExecutor<Operations>) => Layer.Layer<CiClient, never, never>;
54
+ /** `layerDirect` with options that Effect `Config` reads. */
55
+ declare const layerDirectConfig: (config: Config.Wrap<DirectTransportOptions>) => Layer.Layer<CiClient, Config.ConfigError, never>;
56
+ /** `layerProxy` with options that Effect `Config` reads. */
57
+ declare const layerProxyConfig: (config: Config.Wrap<ProxyTransportOptions>) => Layer.Layer<CiClient, Config.ConfigError, never>;
58
+ /** The `chat_*` operation of each method of the chat domain. */
59
+ declare const chatOperations: {
60
+ readonly agentConversations: {
61
+ readonly cancelTurn: "chat_agent_conversations_cancel_turn";
62
+ readonly close: "chat_agent_conversations_close";
63
+ readonly submitTurn: "chat_agent_conversations_submit_turn";
64
+ };
65
+ readonly agents: {
66
+ readonly list: "chat_agents_list";
67
+ };
68
+ readonly approvals: {
69
+ readonly decide: "chat_approvals_decide";
70
+ readonly get: "chat_approvals_get";
71
+ readonly reject: "chat_approvals_reject";
72
+ readonly search: "chat_approvals_search";
73
+ readonly searchRequests: "chat_approvals_search_requests";
74
+ readonly withdraw: "chat_approvals_withdraw";
75
+ };
76
+ readonly artifacts: {
77
+ readonly progress: "chat_artifacts_progress";
78
+ };
79
+ readonly attachments: {
80
+ readonly capabilities: "chat_attachments_capabilities";
81
+ readonly downloadUrl: "chat_attachments_download_url";
82
+ readonly upload: "chat_attachments_upload";
83
+ };
84
+ readonly compaction: {
85
+ readonly compact: "chat_compaction_compact";
86
+ readonly get: "chat_compaction_get";
87
+ readonly regenerate: "chat_compaction_regenerate";
88
+ readonly reset: "chat_compaction_reset";
89
+ };
90
+ readonly conversations: {
91
+ readonly create: "chat_conversations_create";
92
+ readonly delete: "chat_conversations_delete";
93
+ readonly get: "chat_conversations_get";
94
+ readonly list: "chat_conversations_list";
95
+ readonly transcript: "chat_conversations_transcript";
96
+ readonly update: "chat_conversations_update";
97
+ };
98
+ readonly evidence: {
99
+ readonly resolve: "chat_evidence_resolve";
100
+ };
101
+ readonly feedback: {
102
+ readonly clear: "chat_feedback_clear";
103
+ readonly upsert: "chat_feedback_upsert";
104
+ };
105
+ readonly interactions: {
106
+ readonly respond: "chat_interactions_respond";
107
+ readonly stream: "chat_interactions_stream";
108
+ };
109
+ readonly permissions: {
110
+ readonly decideWait: "chat_permissions_decide_wait";
111
+ readonly list: "chat_permissions_list";
112
+ readonly revoke: "chat_permissions_revoke";
113
+ readonly update: "chat_permissions_update";
114
+ };
115
+ readonly placeContext: {
116
+ readonly get: "chat_place_context_get";
117
+ };
118
+ readonly presentation: {
119
+ readonly get: "chat_presentation_get";
120
+ readonly stream: "chat_presentation_stream";
121
+ };
122
+ readonly projects: {
123
+ readonly create: "chat_projects_create";
124
+ readonly delete: "chat_projects_delete";
125
+ readonly deleteFile: "chat_projects_delete_file";
126
+ readonly fileDownloadUrl: "chat_projects_file_download_url";
127
+ readonly list: "chat_projects_list";
128
+ readonly listFiles: "chat_projects_list_files";
129
+ readonly update: "chat_projects_update";
130
+ readonly uploadFile: "chat_projects_upload_file";
131
+ };
132
+ readonly queuedMessages: {
133
+ readonly create: "chat_queued_messages_create";
134
+ readonly delete: "chat_queued_messages_delete";
135
+ readonly list: "chat_queued_messages_list";
136
+ readonly update: "chat_queued_messages_update";
137
+ };
138
+ readonly skills: {
139
+ readonly list: "chat_skills_list";
140
+ };
141
+ readonly speech: {
142
+ readonly availability: "chat_speech_availability";
143
+ readonly createClip: "chat_speech_create_clip";
144
+ readonly readAloudPart: "chat_speech_read_aloud_part";
145
+ readonly transcribe: "chat_speech_transcribe";
146
+ };
147
+ readonly steeringMessages: {
148
+ readonly send: "chat_steering_messages_send";
149
+ };
150
+ readonly tools: {
151
+ readonly list: "chat_tools_list";
152
+ };
153
+ readonly turns: {
154
+ readonly cancel: "chat_turns_cancel";
155
+ readonly stream: "chat_turns_stream";
156
+ readonly submit: "chat_turns_submit";
157
+ };
158
+ };
159
+ type ChatOperations = typeof chatOperations;
160
+ /** The `chat_*` operation id of one method of the chat domain. */
161
+ type ChatOperationOf<Group extends keyof ChatOperations, Method extends keyof ChatOperations[Group]> = Extract<ChatOperations[Group][Method], ExternalApplicationChatOperationId>;
162
+ type ChatEffect<Id extends ExternalApplicationChatOperationId> = (input: ClientOperationMap[Id]["input"], options: OperationExecutionOptions) => Effect.Effect<ClientOperationMap[Id]["output"], CiError$1 | CiTransportError>;
163
+ type ChatValue = Readonly<{ [Group in keyof ChatOperations]: Readonly<{ [Method in keyof ChatOperations[Group]]: ChatEffect<ChatOperationOf<Group, Method>>; }>; }>;
164
+ declare const Chat_base: Context.ServiceClass<Chat, "@collective-intelligence/external-apps-client-sdk/Chat", Readonly<{
165
+ readonly agentConversations: Readonly<{
166
+ readonly cancelTurn: ChatEffect<"chat_agent_conversations_cancel_turn">;
167
+ readonly close: ChatEffect<"chat_agent_conversations_close">;
168
+ readonly submitTurn: ChatEffect<"chat_agent_conversations_submit_turn">;
169
+ }>;
170
+ readonly agents: Readonly<{
171
+ readonly list: ChatEffect<"chat_agents_list">;
172
+ }>;
173
+ readonly approvals: Readonly<{
174
+ readonly decide: ChatEffect<"chat_approvals_decide">;
175
+ readonly get: ChatEffect<"chat_approvals_get">;
176
+ readonly reject: ChatEffect<"chat_approvals_reject">;
177
+ readonly search: ChatEffect<"chat_approvals_search">;
178
+ readonly searchRequests: ChatEffect<"chat_approvals_search_requests">;
179
+ readonly withdraw: ChatEffect<"chat_approvals_withdraw">;
180
+ }>;
181
+ readonly artifacts: Readonly<{
182
+ readonly progress: ChatEffect<"chat_artifacts_progress">;
183
+ }>;
184
+ readonly attachments: Readonly<{
185
+ readonly capabilities: ChatEffect<"chat_attachments_capabilities">;
186
+ readonly downloadUrl: ChatEffect<"chat_attachments_download_url">;
187
+ readonly upload: ChatEffect<"chat_attachments_upload">;
188
+ }>;
189
+ readonly compaction: Readonly<{
190
+ readonly compact: ChatEffect<"chat_compaction_compact">;
191
+ readonly get: ChatEffect<"chat_compaction_get">;
192
+ readonly regenerate: ChatEffect<"chat_compaction_regenerate">;
193
+ readonly reset: ChatEffect<"chat_compaction_reset">;
194
+ }>;
195
+ readonly conversations: Readonly<{
196
+ readonly create: ChatEffect<"chat_conversations_create">;
197
+ readonly delete: ChatEffect<"chat_conversations_delete">;
198
+ readonly get: ChatEffect<"chat_conversations_get">;
199
+ readonly list: ChatEffect<"chat_conversations_list">;
200
+ readonly transcript: ChatEffect<"chat_conversations_transcript">;
201
+ readonly update: ChatEffect<"chat_conversations_update">;
202
+ }>;
203
+ readonly evidence: Readonly<{
204
+ readonly resolve: ChatEffect<"chat_evidence_resolve">;
205
+ }>;
206
+ readonly feedback: Readonly<{
207
+ readonly clear: ChatEffect<"chat_feedback_clear">;
208
+ readonly upsert: ChatEffect<"chat_feedback_upsert">;
209
+ }>;
210
+ readonly interactions: Readonly<{
211
+ readonly respond: ChatEffect<"chat_interactions_respond">;
212
+ readonly stream: ChatEffect<"chat_interactions_stream">;
213
+ }>;
214
+ readonly permissions: Readonly<{
215
+ readonly decideWait: ChatEffect<"chat_permissions_decide_wait">;
216
+ readonly list: ChatEffect<"chat_permissions_list">;
217
+ readonly revoke: ChatEffect<"chat_permissions_revoke">;
218
+ readonly update: ChatEffect<"chat_permissions_update">;
219
+ }>;
220
+ readonly placeContext: Readonly<{
221
+ readonly get: ChatEffect<"chat_place_context_get">;
222
+ }>;
223
+ readonly presentation: Readonly<{
224
+ readonly get: ChatEffect<"chat_presentation_get">;
225
+ readonly stream: ChatEffect<"chat_presentation_stream">;
226
+ }>;
227
+ readonly projects: Readonly<{
228
+ readonly create: ChatEffect<"chat_projects_create">;
229
+ readonly delete: ChatEffect<"chat_projects_delete">;
230
+ readonly deleteFile: ChatEffect<"chat_projects_delete_file">;
231
+ readonly fileDownloadUrl: ChatEffect<"chat_projects_file_download_url">;
232
+ readonly list: ChatEffect<"chat_projects_list">;
233
+ readonly listFiles: ChatEffect<"chat_projects_list_files">;
234
+ readonly update: ChatEffect<"chat_projects_update">;
235
+ readonly uploadFile: ChatEffect<"chat_projects_upload_file">;
236
+ }>;
237
+ readonly queuedMessages: Readonly<{
238
+ readonly create: ChatEffect<"chat_queued_messages_create">;
239
+ readonly delete: ChatEffect<"chat_queued_messages_delete">;
240
+ readonly list: ChatEffect<"chat_queued_messages_list">;
241
+ readonly update: ChatEffect<"chat_queued_messages_update">;
242
+ }>;
243
+ readonly skills: Readonly<{
244
+ readonly list: ChatEffect<"chat_skills_list">;
245
+ }>;
246
+ readonly speech: Readonly<{
247
+ readonly availability: ChatEffect<"chat_speech_availability">;
248
+ readonly createClip: ChatEffect<"chat_speech_create_clip">;
249
+ readonly readAloudPart: ChatEffect<"chat_speech_read_aloud_part">;
250
+ readonly transcribe: ChatEffect<"chat_speech_transcribe">;
251
+ }>;
252
+ readonly steeringMessages: Readonly<{
253
+ readonly send: ChatEffect<"chat_steering_messages_send">;
254
+ }>;
255
+ readonly tools: Readonly<{
256
+ readonly list: ChatEffect<"chat_tools_list">;
257
+ }>;
258
+ readonly turns: Readonly<{
259
+ readonly cancel: ChatEffect<"chat_turns_cancel">;
260
+ readonly stream: ChatEffect<"chat_turns_stream">;
261
+ readonly submit: ChatEffect<"chat_turns_submit">;
262
+ }>;
263
+ }>>;
264
+ declare class Chat extends Chat_base {}
265
+ /** `Chat` over the `CiClient` of the context. */
266
+ declare const layer$1: Layer.Layer<Chat, never, CiClient>;
267
+ type ChatClient<Operations extends ClientOperationMap, Scoped extends boolean> = Readonly<{ [Group in keyof ChatOperations]: Readonly<{ [Method in keyof ChatOperations[Group]]: DomainOperation<Operations, ChatOperationOf<Group, Method>, Scoped>; }>; }>;
65
268
  type DelegatedRuntimeState = Readonly<{
66
269
  status: "checking" | "anonymous" | "expired";
67
270
  }> | Readonly<{
@@ -662,6 +865,19 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
662
865
  conversations_history: ClientOperationDefinition<{
663
866
  conversationId: string;
664
867
  }, ConversationHistory>;
868
+ intents_list: ClientOperationDefinition<Readonly<Record<string, never>>, {
869
+ intents: Array<ExternalApplicationIntent>;
870
+ }>;
871
+ intents_dispatch: ClientOperationDefinition<ExternalApplicationIntentDispatchInput, ExternalApplicationIntentDispatchOutcome>;
872
+ intents_get: ClientOperationDefinition<{
873
+ handle: string;
874
+ }, ExternalApplicationIntentDispatchState>;
875
+ intents_wait: ClientOperationDefinition<{
876
+ handle: string;
877
+ }, ExternalApplicationIntentDispatchState>;
878
+ access_check: ClientOperationDefinition<{
879
+ targets: Array<AccessTarget>;
880
+ }, AccessCheckResponse>;
665
881
  } & {
666
882
  chat_conversations_list: ClientOperationDefinition<{
667
883
  query?: {
@@ -781,6 +997,22 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
781
997
  completedAt: string | null;
782
998
  createdAt: string;
783
999
  input: string;
1000
+ intentCards?: Array<{
1001
+ displayName?: string;
1002
+ fqn: string;
1003
+ handle: string;
1004
+ state: {
1005
+ kind: "running";
1006
+ } | {
1007
+ kind: "completed";
1008
+ result: unknown;
1009
+ } | {
1010
+ kind: "failed";
1011
+ reason: string;
1012
+ } | {
1013
+ kind: "ended";
1014
+ };
1015
+ }>;
784
1016
  message: string | null;
785
1017
  sequence: number;
786
1018
  status: "pending" | "completed" | "failed" | "cancelled";
@@ -828,6 +1060,27 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
828
1060
  unavailableReason: string | null;
829
1061
  }>;
830
1062
  content: string;
1063
+ contextTrail?: Array<{
1064
+ at: string;
1065
+ data: {
1066
+ [key: string]: unknown;
1067
+ };
1068
+ event: string;
1069
+ source: string;
1070
+ } | {
1071
+ at: string;
1072
+ data: {
1073
+ [key: string]: unknown;
1074
+ } & {
1075
+ "@type": string;
1076
+ };
1077
+ source: string;
1078
+ } | {
1079
+ app: string;
1080
+ at: string;
1081
+ page: string;
1082
+ title: string;
1083
+ }>;
831
1084
  conversationId: string;
832
1085
  currentUserFeedback?: {
833
1086
  sentiment: "positive" | "negative" | null;
@@ -847,6 +1100,22 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
847
1100
  conversationId: string;
848
1101
  durationMs: number;
849
1102
  inputTokens: number;
1103
+ intentCards?: Array<{
1104
+ displayName?: string;
1105
+ fqn: string;
1106
+ handle: string;
1107
+ state: {
1108
+ kind: "running";
1109
+ } | {
1110
+ kind: "completed";
1111
+ result: unknown;
1112
+ } | {
1113
+ kind: "failed";
1114
+ reason: string;
1115
+ } | {
1116
+ kind: "ended";
1117
+ };
1118
+ }>;
850
1119
  invocationId: string;
851
1120
  memoryEvidence: {
852
1121
  events: Array<{
@@ -947,6 +1216,27 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
947
1216
  body: {
948
1217
  attachmentIds?: Array<string>;
949
1218
  clientTurnId?: string;
1219
+ contextTrail?: Array<{
1220
+ at: string;
1221
+ data: {
1222
+ [key: string]: unknown;
1223
+ };
1224
+ event: string;
1225
+ source: string;
1226
+ } | {
1227
+ at: string;
1228
+ data: {
1229
+ [key: string]: unknown;
1230
+ } & {
1231
+ "@type": string;
1232
+ };
1233
+ source: string;
1234
+ } | {
1235
+ app: string;
1236
+ at: string;
1237
+ page: string;
1238
+ title: string;
1239
+ }>;
950
1240
  conversationId?: string;
951
1241
  directTool?: {
952
1242
  handle: string;
@@ -954,7 +1244,21 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
954
1244
  [key: string]: unknown;
955
1245
  };
956
1246
  };
957
- message: string;
1247
+ message?: string;
1248
+ preparedTurn?: {
1249
+ fqn: string;
1250
+ inputs: {
1251
+ [key: string]: unknown;
1252
+ };
1253
+ kind: "intent";
1254
+ } | {
1255
+ kind: "message";
1256
+ text: string;
1257
+ } | {
1258
+ kind: "skill";
1259
+ skillId: string;
1260
+ text: string;
1261
+ };
958
1262
  selectedCapabilities?: Array<{
959
1263
  id: string;
960
1264
  kind: "skill" | "tool";
@@ -978,6 +1282,27 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
978
1282
  body: {
979
1283
  attachmentIds?: Array<string>;
980
1284
  clientTurnId?: string;
1285
+ contextTrail?: Array<{
1286
+ at: string;
1287
+ data: {
1288
+ [key: string]: unknown;
1289
+ };
1290
+ event: string;
1291
+ source: string;
1292
+ } | {
1293
+ at: string;
1294
+ data: {
1295
+ [key: string]: unknown;
1296
+ } & {
1297
+ "@type": string;
1298
+ };
1299
+ source: string;
1300
+ } | {
1301
+ app: string;
1302
+ at: string;
1303
+ page: string;
1304
+ title: string;
1305
+ }>;
981
1306
  conversationId?: string;
982
1307
  directTool?: {
983
1308
  handle: string;
@@ -985,7 +1310,21 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
985
1310
  [key: string]: unknown;
986
1311
  };
987
1312
  };
988
- message: string;
1313
+ message?: string;
1314
+ preparedTurn?: {
1315
+ fqn: string;
1316
+ inputs: {
1317
+ [key: string]: unknown;
1318
+ };
1319
+ kind: "intent";
1320
+ } | {
1321
+ kind: "message";
1322
+ text: string;
1323
+ } | {
1324
+ kind: "skill";
1325
+ skillId: string;
1326
+ text: string;
1327
+ };
989
1328
  selectedCapabilities?: Array<{
990
1329
  id: string;
991
1330
  kind: "skill" | "tool";
@@ -1126,6 +1465,8 @@ declare const createDelegatedApplicationRuntime: (options: DelegatedApplicationR
1126
1465
  body?: never;
1127
1466
  path?: never;
1128
1467
  }, {
1468
+ contextTrailEnabled: boolean;
1469
+ contextTrailVisible: boolean;
1129
1470
  places: Array<{
1130
1471
  id: string;
1131
1472
  kind: "studio_app" | "external_app";
@@ -2237,6 +2578,140 @@ type FixedWorkflowClient<Input> = Readonly<{
2237
2578
  declare const createFixedWorkflowClient: <Input>(options: FixedWorkflowClientOptions<Input>) => FixedWorkflowClient<Input> & Readonly<{
2238
2579
  close: () => Promise<void>;
2239
2580
  }>;
2581
+ type CiStreamPage = ClientOperationOutput<ClientOperationMap, "runs_stream">;
2582
+ type CiStreamEvent = CiStreamPage["events"][number];
2583
+ type CiRunCancellation = ClientOperationOutput<ClientOperationMap, "runs_cancel">;
2584
+ declare const nextStreamCursor: (page: CiStreamPage) => string | null;
2585
+ type RunFollowOptions = Readonly<{
2586
+ /** Total wait before the follow fails with `CiError` `unavailable`. */
2587
+ deadlineMs?: number;
2588
+ /**
2589
+ * First wait between polls in milliseconds (default 50). It doubles while
2590
+ * no new event arrives, up to one second or `idleMs` if larger.
2591
+ */
2592
+ idleMs?: number;
2593
+ runId: string;
2594
+ }>;
2595
+ /**
2596
+ * Ten minutes: a skill run's five-minute AI deadline plus queueing and
2597
+ * delivery slack. Long runs return a `runId` immediately; follow is how
2598
+ * callers wait for their outcome.
2599
+ */
2600
+ declare const DEFAULT_FOLLOW_RUN_DEADLINE_MS = 600000;
2601
+ type RunsValue = Readonly<{
2602
+ /**
2603
+ * Follows a run of `organizationId` until it finishes, and succeeds with
2604
+ * its last event page. A failed read fails with its `CiError`; a run that
2605
+ * does not finish before the deadline fails with `CiError` `unavailable`.
2606
+ */
2607
+ follow: (options: RunFollowOptions & Readonly<{
2608
+ organizationId: string;
2609
+ }>) => Effect.Effect<CiStreamPage, CiError$1 | CiTransportError>;
2610
+ }>;
2611
+ declare const Runs_base: Context.ServiceClass<Runs, "@collective-intelligence/external-apps-client-sdk/Runs", Readonly<{
2612
+ /**
2613
+ * Follows a run of `organizationId` until it finishes, and succeeds with
2614
+ * its last event page. A failed read fails with its `CiError`; a run that
2615
+ * does not finish before the deadline fails with `CiError` `unavailable`.
2616
+ */
2617
+ follow: (options: RunFollowOptions & Readonly<{
2618
+ organizationId: string;
2619
+ }>) => Effect.Effect<CiStreamPage, CiError$1 | CiTransportError>;
2620
+ }>>;
2621
+ declare class Runs extends Runs_base {}
2622
+ /** `Runs` over the `CiClient` of the context. */
2623
+ declare const layer: Layer.Layer<Runs, never, CiClient>;
2624
+ type FollowRunSource = Readonly<{
2625
+ get: (input: Readonly<{
2626
+ runId: string;
2627
+ }>) => Promise<CiResult<unknown>>;
2628
+ stream: (input: Readonly<{
2629
+ afterCursor?: string;
2630
+ runId: string;
2631
+ }>) => Promise<CiResult<CiStreamPage>>;
2632
+ }>;
2633
+ type FollowRunOptions = Readonly<{
2634
+ /**
2635
+ * Total wait before `followRun` rejects with `CiError` `unavailable`
2636
+ * ("Run did not finish"). Defaults to
2637
+ * {@link DEFAULT_FOLLOW_RUN_DEADLINE_MS}.
2638
+ */
2639
+ deadlineMs?: number;
2640
+ /**
2641
+ * First wait between polls in milliseconds (default 50). It doubles while
2642
+ * no new event arrives, up to one second or `idleMs` if larger.
2643
+ */
2644
+ idleMs?: number;
2645
+ now?: () => number;
2646
+ runId: string;
2647
+ /** Stops following and cancels in-flight requests made by `runs.follow`. */
2648
+ signal?: AbortSignal;
2649
+ sleep?: (ms: number) => Promise<void>;
2650
+ }>;
2651
+ /**
2652
+ * Follows dedicated run events until a terminal event or snapshot status.
2653
+ * Resolves with the last event page read. A failed read rejects with its
2654
+ * `CiError`; a source that rejects gives `CiTransportError`; an abort
2655
+ * rejects with `signal.reason`.
2656
+ */
2657
+ declare const followRun: (runs: FollowRunSource, options: FollowRunOptions) => Promise<CiStreamPage>;
2658
+ /** One dispatched Server-Sent Event. */
2659
+ type RealtimeStreamEvent = Readonly<{
2660
+ type: string;
2661
+ data: string;
2662
+ /** The `id:` of this event, when it carried one. */
2663
+ id: string | undefined;
2664
+ }>;
2665
+ /**
2666
+ * How a stream ended: `status` when the server refused it, and the
2667
+ * reconnect delay the server asked for with `retry:` or `Retry-After`.
2668
+ */
2669
+ type RealtimeStreamEnd = Readonly<{
2670
+ status: number | undefined;
2671
+ retryMilliseconds: number | undefined;
2672
+ }>;
2673
+ type RealtimeStreamHandlers = Readonly<{
2674
+ onOpen: () => void;
2675
+ onEvent: (event: RealtimeStreamEvent) => void;
2676
+ /** A comment or an `id:`-only frame: the server is alive. */
2677
+ onPing: (id?: string) => void;
2678
+ /** Called once, unless the stream was closed by the client. */
2679
+ onEnd: (end: RealtimeStreamEnd) => void;
2680
+ }>;
2681
+ type RealtimeEventSource = Readonly<{
2682
+ close: () => void;
2683
+ }>;
2684
+ /** Opens one event stream; `close` stops it without calling `onEnd`. */
2685
+ type RealtimeEventSourceFactory = (url: string, handlers: RealtimeStreamHandlers) => RealtimeEventSource;
2686
+ /** Reads `text/event-stream` with `fetch`, so pings and refusals are visible. */
2687
+ declare const createFetchEventSourceFactory: (fetch: ClientFetch) => RealtimeEventSourceFactory;
2688
+ type PageEvents = Readonly<{
2689
+ addEventListener: (type: string, listener: () => void) => void;
2690
+ removeEventListener: (type: string, listener: () => void) => void;
2691
+ }>;
2692
+ type RealtimeDocument = PageEvents & Readonly<{
2693
+ visibilityState: DocumentVisibilityState;
2694
+ }>;
2695
+ type RealtimeWindow = PageEvents;
2696
+ /** One equality filter on a dotted data path of a topic's records. */
2697
+ type RealtimeTopicFilter = Readonly<{
2698
+ field: string;
2699
+ eq: string | number | boolean | null;
2700
+ }>;
2701
+ /** The records of one entity schema, named by FQN or id, optionally filtered. */
2702
+ type RealtimeTopic = Readonly<{
2703
+ schema: string;
2704
+ filter?: RealtimeTopicFilter;
2705
+ }>;
2706
+ /** A record of a subscribed topic changed; refetch it, the event carries ids only. */
2707
+ type RealtimeChange = Readonly<{
2708
+ id: string;
2709
+ op: "create" | "update" | "delete";
2710
+ revision: string;
2711
+ topic: RealtimeTopic;
2712
+ }>;
2713
+ /** One stable key per topic, whatever the key order of the object. */
2714
+ declare const realtimeTopicKey: ({ filter, schema }: RealtimeTopic) => string;
2240
2715
  /** Schedules `callback` after `milliseconds`; the result cancels it. */
2241
2716
  type RealtimeTimers = Readonly<{
2242
2717
  schedule: (callback: () => void, milliseconds: number) => () => void;
@@ -2313,4 +2788,123 @@ declare const CiError: typeof CiError$1;
2313
2788
  * keeps the envelope shape; each instance of the `CiError` class has it.
2314
2789
  */
2315
2790
  type CiError = CiError$2;
2316
- export { RealtimeChange as C, realtimeTopicKey as E, RealtimeWindow as S, RealtimeTopicFilter as T, RealtimeStreamEnd as _, RealtimeClientStatus as a, createFetchEventSourceFactory as b, FixedWorkflowClient as c, DelegatedApplicationRuntime as d, DelegatedApplicationRuntimeOptions as f, RealtimeEventSourceFactory as g, RealtimeEventSource as h, RealtimeClientState as i, FixedWorkflowClientOptions as l, createDelegatedApplicationRuntime as m, RealtimeClient as n, RealtimeTimers as o, DelegatedRuntimeState as p, RealtimeClientOptions as r, createRealtimeClient as s, CiError as t, createFixedWorkflowClient as u, RealtimeStreamEvent as v, RealtimeTopic as w, RealtimeDocument as x, RealtimeStreamHandlers as y };
2791
+ /** The state of a Dispatch Record, as the server wait answers it. */
2792
+ type IntentDispatchState = ClientOperationMap["intents_wait"]["output"];
2793
+ /** The end of a started dispatch: the Intent Result, or why the run failed. */
2794
+ type IntentDispatchEnd = Extract<IntentDispatchState, Readonly<{
2795
+ kind: "completed" | "failed";
2796
+ }>>;
2797
+ type SignalOptions$1 = Readonly<{
2798
+ signal?: AbortSignal;
2799
+ }>;
2800
+ /** One intents method: organization-bound when `Scoped`. */
2801
+ type IntentsMethod<Input, Output, Scoped extends boolean> = (input: Scoped extends true ? Input : Input & Readonly<{
2802
+ organizationId: string;
2803
+ }>, options?: SignalOptions$1) => Promise<CiResult<Output>>;
2804
+ /**
2805
+ * The input of a dispatch with an optional idempotency key. The caller gives
2806
+ * one key for each user action, so that a repeat replays the dispatch; each
2807
+ * call that gives none gets a new key.
2808
+ */
2809
+ type IntentDispatchRequest<Input> = Input extends Readonly<{
2810
+ idempotencyKey: string;
2811
+ }> ? Omit<Input, "idempotencyKey"> & Readonly<{
2812
+ idempotencyKey?: string;
2813
+ }> : never;
2814
+ type IntentsClient<Operations extends ClientOperationMap, Scoped extends boolean> = Readonly<{
2815
+ dispatch: IntentsMethod<IntentDispatchRequest<ClientOperationInput<Operations, "intents_dispatch">>, ClientOperationOutput<Operations, "intents_dispatch">, Scoped>;
2816
+ get: DomainOperation<Operations, "intents_get", Scoped>;
2817
+ /** Lists the Intents that the caller may trigger now. */
2818
+ list: IntentsMethod<Readonly<Record<never, never>>, ClientOperationOutput<Operations, "intents_list">, Scoped>;
2819
+ /** Resolves with the end of the run, or with the first CI error of a wait. */
2820
+ wait: IntentsMethod<Readonly<{
2821
+ handle: string;
2822
+ }>, IntentDispatchEnd, Scoped>;
2823
+ }>;
2824
+ declare const clientSdkProtocolVersion: "v1";
2825
+ type SignalOptions = Readonly<{
2826
+ signal?: AbortSignal;
2827
+ }>;
2828
+ type FollowRunCall<Scoped extends boolean> = Scoped extends true ? (options: FollowRunOptions) => Promise<CiStreamPage> : (options: FollowRunOptions & Readonly<{
2829
+ organizationId: string;
2830
+ }>) => Promise<CiStreamPage>;
2831
+ type ScopedOperation<Operations extends ClientOperationMap, Id extends ClientOperationId> = (input: ClientOperationInput<Operations, Id>, options?: SignalOptions) => Promise<CiResult<ClientOperationOutput<Operations, Id>>>;
2832
+ type RootOperation<Operations extends ClientOperationMap, Id extends ClientOperationId> = (input: ClientOperationInput<Operations, Id> & Readonly<{
2833
+ organizationId: string;
2834
+ }>, options?: SignalOptions) => Promise<CiResult<ClientOperationOutput<Operations, Id>>>;
2835
+ /** Internal. One domain method: organization-bound when `Scoped`. */
2836
+ type DomainOperation<Operations extends ClientOperationMap, Id extends ClientOperationId, Scoped extends boolean> = Scoped extends true ? ScopedOperation<Operations, Id> : RootOperation<Operations, Id>;
2837
+ type ClientDomains<Operations extends ClientOperationMap, Scoped extends boolean> = Readonly<{
2838
+ /** The Access Check: one answer per target, with the Access Version. */
2839
+ access: Readonly<{
2840
+ check: DomainOperation<Operations, "access_check", Scoped>;
2841
+ }>;
2842
+ agents: Readonly<{
2843
+ invoke: DomainOperation<Operations, "agents_invoke", Scoped>;
2844
+ list: DomainOperation<Operations, "agents_list", Scoped>;
2845
+ }>;
2846
+ attachments: Readonly<{
2847
+ downloadUrl: DomainOperation<Operations, "attachments_download_url", Scoped>;
2848
+ upload: DomainOperation<Operations, "attachments_upload", Scoped>;
2849
+ }>;
2850
+ /** The External App chat (`/chat/...`), for a signed-in app user. */
2851
+ chat: ChatClient<Operations, Scoped>;
2852
+ context: Readonly<{
2853
+ get: DomainOperation<Operations, "context_get", Scoped>;
2854
+ }>;
2855
+ /** Intents: list, dispatch, read, and wait until the run ends. */
2856
+ intents: IntentsClient<Operations, Scoped>;
2857
+ knowledge: Readonly<{
2858
+ autocomplete: DomainOperation<Operations, "knowledge_autocomplete", Scoped>;
2859
+ createEntity: DomainOperation<Operations, "knowledge_create_entity", Scoped>;
2860
+ deleteEntity: DomainOperation<Operations, "knowledge_delete_entity", Scoped>;
2861
+ facets: DomainOperation<Operations, "knowledge_facets", Scoped>;
2862
+ getEntity: DomainOperation<Operations, "knowledge_get_entity", Scoped>;
2863
+ getEntitySchemaSnapshot: DomainOperation<Operations, "knowledge_get_entity_schema_snapshot", Scoped>;
2864
+ getSchemaQueryContext: DomainOperation<Operations, "knowledge_get_schema_query_context", Scoped>;
2865
+ query: DomainOperation<Operations, "knowledge_query", Scoped>;
2866
+ searchEntities: DomainOperation<Operations, "knowledge_search_entities", Scoped>;
2867
+ updateEntity: DomainOperation<Operations, "knowledge_update_entity", Scoped>;
2868
+ upsertEntity: DomainOperation<Operations, "knowledge_upsert_entity", Scoped>;
2869
+ }>;
2870
+ runs: Readonly<{
2871
+ cancel: DomainOperation<Operations, "runs_cancel", Scoped>;
2872
+ follow: FollowRunCall<Scoped>;
2873
+ get: DomainOperation<Operations, "runs_get", Scoped>;
2874
+ stream: DomainOperation<Operations, "runs_stream", Scoped>;
2875
+ }>;
2876
+ skills: Readonly<{
2877
+ invoke: DomainOperation<Operations, "skills_invoke", Scoped>;
2878
+ list: DomainOperation<Operations, "skills_list", Scoped>;
2879
+ }>;
2880
+ workflows: Readonly<{
2881
+ invoke: DomainOperation<Operations, "workflows_invoke", Scoped>;
2882
+ list: DomainOperation<Operations, "workflows_list", Scoped>;
2883
+ }>;
2884
+ }>;
2885
+ type OrganizationClient<Operations extends ClientOperationMap> = ClientDomains<Operations, true> & Readonly<{
2886
+ organizationId: string;
2887
+ }>;
2888
+ type ClientSdkClient<Operations extends ClientOperationMap> = Omit<ClientDomains<Operations, false>, "context"> & TypedOperationExecutor<Operations> & Readonly<{
2889
+ context: ClientDomains<Operations, false>["context"] & Readonly<{
2890
+ forOrganization: (organizationId: string) => OrganizationClient<Operations>;
2891
+ }>;
2892
+ forOrganization: (organizationId: string) => OrganizationClient<Operations>;
2893
+ protocolVersion: typeof clientSdkProtocolVersion;
2894
+ }>;
2895
+ type ClientSdkEntrypoint = Readonly<{
2896
+ protocolVersion: typeof clientSdkProtocolVersion;
2897
+ }>;
2898
+ /**
2899
+ * The Vanilla Facade of `CiClient` and `Runs` over `transport`, in one
2900
+ * runtime; `close` disposes it. A CI error answer resolves
2901
+ * `{ ok: false, error }` with a `CiError`; `runs.follow` rejects with it. A
2902
+ * transport failure rejects with `CiTransportError`, an abort with
2903
+ * `signal.reason`.
2904
+ */
2905
+ declare const createClient: <Operations extends ClientOperationMap>(options: {
2906
+ readonly transport: TypedOperationExecutor<Operations>;
2907
+ }) => ClientSdkClient<Operations> & Readonly<{
2908
+ close: () => Promise<void>;
2909
+ }>;
2910
+ export { layerDirect as $, DEFAULT_FOLLOW_RUN_DEADLINE_MS as A, FixedWorkflowClientOptions as B, RealtimeStreamEnd as C, FollowRunOptions as D, createFetchEventSourceFactory as E, CiRunCancellation as F, createDelegatedApplicationRuntime as G, DelegatedApplicationRuntime as H, CiStreamEvent as I, ChatValue as J, ChatClient as K, CiStreamPage as L, Runs as M, RunsValue as N, FollowRunSource as O, layer as P, ExecuteResult as Q, nextStreamCursor as R, RealtimeEventSourceFactory as S, RealtimeStreamHandlers as T, DelegatedApplicationRuntimeOptions as U, createFixedWorkflowClient as V, DelegatedRuntimeState as W, CiClient as X, layer$1 as Y, CiClientValue as Z, RealtimeTopicFilter as _, clientSdkProtocolVersion as a, createDirectTransport as at, RealtimeWindow as b, CiError as c, RealtimeClientState as d, layerDirectConfig as et, RealtimeClientStatus as f, RealtimeTopic as g, RealtimeChange as h, OrganizationClient as i, DirectTransportOptions as it, RunFollowOptions as j, followRun as k, RealtimeClient as l, createRealtimeClient as m, ClientSdkClient as n, layerProxy as nt, createClient as o, RealtimeTimers as p, Chat as q, ClientSdkEntrypoint as r, layerProxyConfig as rt, IntentsClient as s, ClientDomains as t, layerFromExecutor as tt, RealtimeClientOptions as u, realtimeTopicKey as v, RealtimeStreamEvent as w, RealtimeEventSource as x, RealtimeDocument as y, FixedWorkflowClient as z };