@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.
@@ -5,6 +5,69 @@ import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
6
  import * as Stream from "effect/Stream";
7
7
  import "effect/ManagedRuntime";
8
+ type AccessCheckResponse = {
9
+ accessVersion: number;
10
+ answers: Array<'allowed' | 'denied'>;
11
+ };
12
+ type AccessTarget = {
13
+ code: string;
14
+ kind: 'capability';
15
+ mode: 'manage' | 'on' | 'read';
16
+ } | {
17
+ access: 'read' | 'write';
18
+ fqn: string;
19
+ kind: 'entity_schema';
20
+ } | {
21
+ id: string;
22
+ kind: 'dataset';
23
+ } | {
24
+ fqn: string;
25
+ kind: 'agent' | 'intent' | 'skill' | 'workflow';
26
+ };
27
+ type ExternalApplicationIntentDispatchState = {
28
+ kind: 'starting';
29
+ } | {
30
+ kind: 'running';
31
+ } | {
32
+ kind: 'completed';
33
+ result: unknown;
34
+ } | {
35
+ kind: 'failed';
36
+ reason: string;
37
+ };
38
+ type ExternalApplicationIntentDispatchOutcome = {
39
+ handle: string;
40
+ kind: 'completed';
41
+ result: unknown;
42
+ } | {
43
+ handle: string;
44
+ kind: 'started';
45
+ } | {
46
+ fields: Array<{
47
+ path: string;
48
+ problem: 'missing' | 'invalid';
49
+ reason: string;
50
+ }>;
51
+ kind: 'needs_input';
52
+ } | {
53
+ kind: 'not_allowed';
54
+ } | {
55
+ handle?: string;
56
+ kind: 'failed';
57
+ reason: string;
58
+ };
59
+ type ExternalApplicationIntent = {
60
+ description: string;
61
+ displayName: string;
62
+ fqn: string;
63
+ inputSchema: {
64
+ [key: string]: unknown;
65
+ };
66
+ outputSchema: {
67
+ [key: string]: unknown;
68
+ };
69
+ resultMode: 'sync' | 'async';
70
+ };
8
71
  type ExternalApplicationRunSource = {
9
72
  documentId: string;
10
73
  downloadUrl: string;
@@ -49,6 +112,109 @@ type ExternalApplicationsPutRunFeedbackResponses = {
49
112
  };
50
113
  };
51
114
  type ExternalApplicationsPutRunFeedbackResponse = ExternalApplicationsPutRunFeedbackResponses[keyof ExternalApplicationsPutRunFeedbackResponses];
115
+ type ExternalApplicationsCheckAccessData = {
116
+ body: {
117
+ targets: Array<AccessTarget>;
118
+ };
119
+ headers: {
120
+ authorization?: string;
121
+ 'x-organization-id': string;
122
+ 'x-correlation-id'?: string;
123
+ 'x-external-audit-issuer'?: string;
124
+ 'x-external-audit-subject'?: string;
125
+ 'x-external-caller-kind'?: 'anonymous_visitor';
126
+ 'x-external-ci-user-id'?: string;
127
+ };
128
+ path?: never;
129
+ query?: never;
130
+ url: '/application/v1/access/check';
131
+ };
132
+ type ExternalApplicationsCheckAccessResponses = {
133
+ /**
134
+ * Success
135
+ */
136
+ 200: {
137
+ correlationId: string;
138
+ result: AccessCheckResponse;
139
+ };
140
+ };
141
+ type ExternalApplicationsCheckAccessResponse = ExternalApplicationsCheckAccessResponses[keyof ExternalApplicationsCheckAccessResponses];
142
+ type ExternalApplicationsListIntentsResponses = {
143
+ /**
144
+ * Success
145
+ */
146
+ 200: {
147
+ correlationId: string;
148
+ result: {
149
+ intents: Array<ExternalApplicationIntent>;
150
+ };
151
+ };
152
+ };
153
+ type ExternalApplicationsListIntentsResponse = ExternalApplicationsListIntentsResponses[keyof ExternalApplicationsListIntentsResponses];
154
+ type ExternalApplicationsDispatchIntentData = {
155
+ body: {
156
+ fqn: string;
157
+ inputs: {
158
+ [key: string]: unknown;
159
+ };
160
+ resultTarget: 'notification';
161
+ returnPage?: {
162
+ pageId: string;
163
+ params: {
164
+ [key: string]: string;
165
+ };
166
+ };
167
+ } | {
168
+ fqn: string;
169
+ inputs: {
170
+ [key: string]: unknown;
171
+ };
172
+ resultTarget: 'nothing';
173
+ };
174
+ headers: {
175
+ authorization?: string;
176
+ 'x-organization-id': string;
177
+ 'x-correlation-id'?: string;
178
+ 'x-external-audit-issuer'?: string;
179
+ 'x-external-audit-subject'?: string;
180
+ 'x-external-caller-kind'?: 'anonymous_visitor';
181
+ 'x-external-ci-user-id'?: string;
182
+ 'idempotency-key': string;
183
+ };
184
+ path?: never;
185
+ query?: never;
186
+ url: '/application/v1/intents/dispatches';
187
+ };
188
+ type ExternalApplicationsDispatchIntentResponses = {
189
+ /**
190
+ * Success
191
+ */
192
+ 200: {
193
+ correlationId: string;
194
+ result: ExternalApplicationIntentDispatchOutcome;
195
+ };
196
+ };
197
+ type ExternalApplicationsDispatchIntentResponse = ExternalApplicationsDispatchIntentResponses[keyof ExternalApplicationsDispatchIntentResponses];
198
+ type ExternalApplicationsGetIntentDispatchResponses = {
199
+ /**
200
+ * Success
201
+ */
202
+ 200: {
203
+ correlationId: string;
204
+ result: ExternalApplicationIntentDispatchState;
205
+ };
206
+ };
207
+ type ExternalApplicationsGetIntentDispatchResponse = ExternalApplicationsGetIntentDispatchResponses[keyof ExternalApplicationsGetIntentDispatchResponses];
208
+ type ExternalApplicationsWaitIntentDispatchResponses = {
209
+ /**
210
+ * Success
211
+ */
212
+ 200: {
213
+ correlationId: string;
214
+ result: ExternalApplicationIntentDispatchState;
215
+ };
216
+ };
217
+ type ExternalApplicationsWaitIntentDispatchResponse = ExternalApplicationsWaitIntentDispatchResponses[keyof ExternalApplicationsWaitIntentDispatchResponses];
52
218
  type ExternalAppChatConversationsListData = {
53
219
  body?: never;
54
220
  headers: {
@@ -220,6 +386,27 @@ type ExternalAppChatChatTurnData = {
220
386
  body: {
221
387
  attachmentIds?: Array<string>;
222
388
  clientTurnId?: string;
389
+ contextTrail?: Array<{
390
+ at: string;
391
+ data: {
392
+ [key: string]: unknown;
393
+ };
394
+ event: string;
395
+ source: string;
396
+ } | {
397
+ at: string;
398
+ data: {
399
+ [key: string]: unknown;
400
+ } & {
401
+ '@type': string;
402
+ };
403
+ source: string;
404
+ } | {
405
+ app: string;
406
+ at: string;
407
+ page: string;
408
+ title: string;
409
+ }>;
223
410
  conversationId?: string;
224
411
  directTool?: {
225
412
  handle: string;
@@ -227,7 +414,21 @@ type ExternalAppChatChatTurnData = {
227
414
  [key: string]: unknown;
228
415
  };
229
416
  };
230
- message: string;
417
+ message?: string;
418
+ preparedTurn?: {
419
+ fqn: string;
420
+ inputs: {
421
+ [key: string]: unknown;
422
+ };
423
+ kind: 'intent';
424
+ } | {
425
+ kind: 'message';
426
+ text: string;
427
+ } | {
428
+ kind: 'skill';
429
+ skillId: string;
430
+ text: string;
431
+ };
231
432
  selectedCapabilities?: Array<{
232
433
  id: string;
233
434
  kind: 'skill' | 'tool';
@@ -263,6 +464,27 @@ type ExternalAppChatChatStreamData = {
263
464
  body: {
264
465
  attachmentIds?: Array<string>;
265
466
  clientTurnId?: string;
467
+ contextTrail?: Array<{
468
+ at: string;
469
+ data: {
470
+ [key: string]: unknown;
471
+ };
472
+ event: string;
473
+ source: string;
474
+ } | {
475
+ at: string;
476
+ data: {
477
+ [key: string]: unknown;
478
+ } & {
479
+ '@type': string;
480
+ };
481
+ source: string;
482
+ } | {
483
+ app: string;
484
+ at: string;
485
+ page: string;
486
+ title: string;
487
+ }>;
266
488
  conversationId?: string;
267
489
  directTool?: {
268
490
  handle: string;
@@ -270,7 +492,21 @@ type ExternalAppChatChatStreamData = {
270
492
  [key: string]: unknown;
271
493
  };
272
494
  };
273
- message: string;
495
+ message?: string;
496
+ preparedTurn?: {
497
+ fqn: string;
498
+ inputs: {
499
+ [key: string]: unknown;
500
+ };
501
+ kind: 'intent';
502
+ } | {
503
+ kind: 'message';
504
+ text: string;
505
+ } | {
506
+ kind: 'skill';
507
+ skillId: string;
508
+ text: string;
509
+ };
274
510
  selectedCapabilities?: Array<{
275
511
  id: string;
276
512
  kind: 'skill' | 'tool';
@@ -506,6 +742,8 @@ type ExternalAppChatChatPlaceContextResponses = {
506
742
  * Success
507
743
  */
508
744
  200: {
745
+ contextTrailEnabled: boolean;
746
+ contextTrailVisible: boolean;
509
747
  places: Array<{
510
748
  id: string;
511
749
  kind: 'studio_app' | 'external_app';
@@ -621,6 +859,22 @@ type ExternalAppChatConversationTranscriptGetResponses = {
621
859
  completedAt: string | null;
622
860
  createdAt: string;
623
861
  input: string;
862
+ intentCards?: Array<{
863
+ displayName?: string;
864
+ fqn: string;
865
+ handle: string;
866
+ state: {
867
+ kind: 'running';
868
+ } | {
869
+ kind: 'completed';
870
+ result: unknown;
871
+ } | {
872
+ kind: 'failed';
873
+ reason: string;
874
+ } | {
875
+ kind: 'ended';
876
+ };
877
+ }>;
624
878
  message: string | null;
625
879
  sequence: number;
626
880
  status: 'pending' | 'completed' | 'failed' | 'cancelled';
@@ -668,6 +922,27 @@ type ExternalAppChatConversationTranscriptGetResponses = {
668
922
  unavailableReason: string | null;
669
923
  }>;
670
924
  content: string;
925
+ contextTrail?: Array<{
926
+ at: string;
927
+ data: {
928
+ [key: string]: unknown;
929
+ };
930
+ event: string;
931
+ source: string;
932
+ } | {
933
+ at: string;
934
+ data: {
935
+ [key: string]: unknown;
936
+ } & {
937
+ '@type': string;
938
+ };
939
+ source: string;
940
+ } | {
941
+ app: string;
942
+ at: string;
943
+ page: string;
944
+ title: string;
945
+ }>;
671
946
  conversationId: string;
672
947
  currentUserFeedback?: {
673
948
  sentiment: 'positive' | 'negative' | null;
@@ -687,6 +962,22 @@ type ExternalAppChatConversationTranscriptGetResponses = {
687
962
  conversationId: string;
688
963
  durationMs: number;
689
964
  inputTokens: number;
965
+ intentCards?: Array<{
966
+ displayName?: string;
967
+ fqn: string;
968
+ handle: string;
969
+ state: {
970
+ kind: 'running';
971
+ } | {
972
+ kind: 'completed';
973
+ result: unknown;
974
+ } | {
975
+ kind: 'failed';
976
+ reason: string;
977
+ } | {
978
+ kind: 'ended';
979
+ };
980
+ }>;
690
981
  invocationId: string;
691
982
  memoryEvidence: {
692
983
  events: Array<{
@@ -2355,6 +2646,14 @@ type KnowledgeQuery = {
2355
2646
  } | (SearchQuery & {
2356
2647
  op: "autocomplete";
2357
2648
  });
2649
+ /**
2650
+ * One Intent Dispatch: the idempotency key with the dispatch body. A return
2651
+ * page goes only with the `notification` Result Target, and CI drops the one
2652
+ * of an app: only Studio dispatches keep a return page.
2653
+ */
2654
+ type ExternalApplicationIntentDispatchInput = ExternalApplicationsDispatchIntentData["body"] & {
2655
+ idempotencyKey: string;
2656
+ };
2358
2657
  /** The `path`, `query` and `body` of a generated operation; the transport sets its headers and URL. */
2359
2658
  type ChatRequest<Data> = Omit<Data, "headers" | "url">;
2360
2659
  interface ChatOperation<Data extends Readonly<{
@@ -2610,6 +2909,25 @@ type ExternalApplicationOperationRequest = {
2610
2909
  conversationId: string;
2611
2910
  };
2612
2911
  operationId: "conversations_history";
2912
+ } | {
2913
+ input: Readonly<Record<string, never>>;
2914
+ operationId: "intents_list";
2915
+ } | {
2916
+ input: ExternalApplicationIntentDispatchInput;
2917
+ operationId: "intents_dispatch";
2918
+ } | {
2919
+ input: {
2920
+ handle: string;
2921
+ };
2922
+ operationId: "intents_get";
2923
+ } | {
2924
+ input: {
2925
+ handle: string;
2926
+ };
2927
+ operationId: "intents_wait";
2928
+ } | {
2929
+ input: ExternalApplicationsCheckAccessData["body"];
2930
+ operationId: "access_check";
2613
2931
  };
2614
2932
  interface EnvelopeSuccess<Id extends string, Result> {
2615
2933
  correlationId: string;
@@ -2633,7 +2951,7 @@ type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get", JsonOb
2633
2951
  }> | EnvelopeSuccess<"conversations_continue", {
2634
2952
  conversationId: string;
2635
2953
  runId: string;
2636
- }> | EnvelopeSuccess<"conversations_history", ConversationHistory>;
2954
+ }> | EnvelopeSuccess<"conversations_history", ConversationHistory> | EnvelopeSuccess<"intents_list", ExternalApplicationsListIntentsResponse["result"]> | EnvelopeSuccess<"intents_dispatch", ExternalApplicationsDispatchIntentResponse["result"]> | EnvelopeSuccess<"intents_get", ExternalApplicationsGetIntentDispatchResponse["result"]> | EnvelopeSuccess<"intents_wait", ExternalApplicationsWaitIntentDispatchResponse["result"]> | EnvelopeSuccess<"access_check", ExternalApplicationsCheckAccessResponse["result"]>;
2637
2955
  declare const storageFileIdBrand: unique symbol;
2638
2956
  /** A durable private file of the application's Organization. */
2639
2957
  type StorageFileId = string & Readonly<{
@@ -2746,7 +3064,7 @@ declare const CiTransportError_base: Schema.Class<CiTransportError, Schema.Tagge
2746
3064
  /** The request did not reach CI, or CI's response was not readable. */
2747
3065
  declare class CiTransportError extends CiTransportError_base {}
2748
3066
  /** Generated, curated external-application operation authority: the application and the chat operations. */
2749
- declare const clientOperationIds: readonly ["context_get", "knowledge_query", "knowledge_get_entity_schema_snapshot", "knowledge_search_entities", "knowledge_facets", "knowledge_get_schema_query_context", "knowledge_autocomplete", "knowledge_get_entity", "knowledge_create_entity", "knowledge_update_entity", "knowledge_upsert_entity", "knowledge_delete_entity", "agents_list", "agents_invoke", "skills_list", "skills_invoke", "workflows_list", "workflows_invoke", "runs_get", "runs_stream", "runs_cancel", "attachments_upload", "attachments_download_url", "conversations_continue", "conversations_history", "chat_conversations_list", "chat_conversations_create", "chat_conversations_get", "chat_conversations_update", "chat_conversations_delete", "chat_conversations_transcript", "chat_turns_submit", "chat_turns_stream", "chat_turns_cancel", "chat_steering_messages_send", "chat_queued_messages_create", "chat_queued_messages_list", "chat_queued_messages_update", "chat_queued_messages_delete", "chat_place_context_get", "chat_presentation_get", "chat_presentation_stream", "chat_agents_list", "chat_skills_list", "chat_tools_list", "chat_agent_conversations_submit_turn", "chat_agent_conversations_cancel_turn", "chat_agent_conversations_close", "chat_attachments_upload", "chat_attachments_download_url", "chat_attachments_capabilities", "chat_feedback_upsert", "chat_feedback_clear", "chat_approvals_search_requests", "chat_approvals_search", "chat_approvals_get", "chat_approvals_decide", "chat_approvals_reject", "chat_approvals_withdraw", "chat_permissions_decide_wait", "chat_permissions_list", "chat_permissions_update", "chat_permissions_revoke", "chat_artifacts_progress", "chat_compaction_get", "chat_compaction_compact", "chat_compaction_regenerate", "chat_compaction_reset", "chat_evidence_resolve", "chat_interactions_respond", "chat_interactions_stream", "chat_projects_list", "chat_projects_create", "chat_projects_update", "chat_projects_delete", "chat_projects_list_files", "chat_projects_upload_file", "chat_projects_delete_file", "chat_projects_file_download_url", "chat_speech_create_clip", "chat_speech_transcribe", "chat_speech_availability", "chat_speech_read_aloud_part"];
3067
+ declare const clientOperationIds: readonly ["context_get", "knowledge_query", "knowledge_get_entity_schema_snapshot", "knowledge_search_entities", "knowledge_facets", "knowledge_get_schema_query_context", "knowledge_autocomplete", "knowledge_get_entity", "knowledge_create_entity", "knowledge_update_entity", "knowledge_upsert_entity", "knowledge_delete_entity", "agents_list", "agents_invoke", "skills_list", "skills_invoke", "workflows_list", "workflows_invoke", "runs_get", "runs_stream", "runs_cancel", "attachments_upload", "attachments_download_url", "conversations_continue", "conversations_history", "intents_list", "intents_dispatch", "intents_get", "intents_wait", "access_check", "chat_conversations_list", "chat_conversations_create", "chat_conversations_get", "chat_conversations_update", "chat_conversations_delete", "chat_conversations_transcript", "chat_turns_submit", "chat_turns_stream", "chat_turns_cancel", "chat_steering_messages_send", "chat_queued_messages_create", "chat_queued_messages_list", "chat_queued_messages_update", "chat_queued_messages_delete", "chat_place_context_get", "chat_presentation_get", "chat_presentation_stream", "chat_agents_list", "chat_skills_list", "chat_tools_list", "chat_agent_conversations_submit_turn", "chat_agent_conversations_cancel_turn", "chat_agent_conversations_close", "chat_attachments_upload", "chat_attachments_download_url", "chat_attachments_capabilities", "chat_feedback_upsert", "chat_feedback_clear", "chat_approvals_search_requests", "chat_approvals_search", "chat_approvals_get", "chat_approvals_decide", "chat_approvals_reject", "chat_approvals_withdraw", "chat_permissions_decide_wait", "chat_permissions_list", "chat_permissions_update", "chat_permissions_revoke", "chat_artifacts_progress", "chat_compaction_get", "chat_compaction_compact", "chat_compaction_regenerate", "chat_compaction_reset", "chat_evidence_resolve", "chat_interactions_respond", "chat_interactions_stream", "chat_projects_list", "chat_projects_create", "chat_projects_update", "chat_projects_delete", "chat_projects_list_files", "chat_projects_upload_file", "chat_projects_delete_file", "chat_projects_file_download_url", "chat_speech_create_clip", "chat_speech_transcribe", "chat_speech_availability", "chat_speech_read_aloud_part"];
2750
3068
  type ClientOperationId = ExternalApplicationOperationId | ExternalApplicationChatOperationId;
2751
3069
  declare const isClientOperationId: (value: string) => value is ClientOperationId;
2752
3070
  interface ClientOperationDefinition<Input, Output> {
@@ -2763,6 +3081,97 @@ type OperationExecutionOptions = Readonly<{
2763
3081
  interface TypedOperationExecutor<Operations extends ClientOperationMap> {
2764
3082
  readonly execute: <Id extends ClientOperationId>(operationId: Id, input: ClientOperationInput<Operations, Id>, options?: OperationExecutionOptions) => Promise<CiResult<ClientOperationOutput<Operations, Id>>>;
2765
3083
  }
3084
+ /** A sign-in step, as a sign-in route answers it with HTTP 200. */
3085
+ declare const SignInStep: Schema.Union<readonly [Schema.Struct<{
3086
+ readonly emailCode: Schema.Boolean;
3087
+ readonly password: Schema.Boolean;
3088
+ readonly registrationOpen: Schema.Boolean;
3089
+ readonly ssoProviders: Schema.$Array<Schema.Struct<{
3090
+ readonly displayName: Schema.String;
3091
+ readonly id: Schema.String;
3092
+ }>>;
3093
+ readonly step: Schema.Literal<"methods">;
3094
+ }>, Schema.Struct<{
3095
+ readonly attemptsLeft: Schema.Int;
3096
+ readonly step: Schema.Literal<"invalid_code">;
3097
+ }>, Schema.Struct<{
3098
+ readonly allowedDomains: Schema.$Array<Schema.String>;
3099
+ readonly step: Schema.Literal<"email_domain_not_allowed">;
3100
+ }>, Schema.Struct<{
3101
+ readonly provider: Schema.Struct<{
3102
+ readonly displayName: Schema.String;
3103
+ readonly id: Schema.String;
3104
+ }>;
3105
+ readonly step: Schema.Literal<"sso_required">;
3106
+ }>, Schema.Struct<{
3107
+ readonly registered: Schema.Boolean;
3108
+ readonly step: Schema.Literal<"signed_in">;
3109
+ }>, Schema.Struct<{
3110
+ readonly seconds: Schema.Int;
3111
+ readonly step: Schema.Literal<"retry_after">;
3112
+ }>, Schema.Struct<{
3113
+ readonly step: Schema.Literals<readonly ["access_denied", "code_expired", "code_sent", "no_sign_in_method", "redirect_to_web", "registration_required"]>;
3114
+ }>]>;
3115
+ /**
3116
+ * The one result of every `auth.signIn` call. `redirect_to_web` means that
3117
+ * the sign-in continues on the CI page: the SDK has sent the browser there.
3118
+ */
3119
+ type SignInStep = typeof SignInStep.Type;
3120
+ /** The page that the browser returns to after a sign-in on the CI page; `/` when absent. */
3121
+ type ReturnTarget$1 = Readonly<{
3122
+ returnTo?: string;
3123
+ }>;
3124
+ /** The languages of the person, as `ui_locales`; CI takes them when it opens a challenge. */
3125
+ type Languages = Readonly<{
3126
+ uiLocales?: string;
3127
+ }>;
3128
+ type SignInMethodsInput = ReturnTarget$1 & Languages;
3129
+ type SignInStartInput = ReturnTarget$1 & Languages & Readonly<{
3130
+ email: string;
3131
+ }>;
3132
+ type SignInVerifyInput = ReturnTarget$1 & Readonly<{
3133
+ code: string;
3134
+ }>;
3135
+ type SignInCompleteInput = ReturnTarget$1 & Readonly<{
3136
+ name: string;
3137
+ }>;
3138
+ /** `provider` is the `id` of an SSO provider of a `methods` or `sso_required` step. */
3139
+ type SignInSsoInput = ReturnTarget$1 & Readonly<{
3140
+ provider: string;
3141
+ }>;
3142
+ type SignInCallError = CiTransportError | FederatedAuthError;
3143
+ type SignInValue = Readonly<{
3144
+ /** Opens a Sign-In Challenge and answers the methods that the app allows. */
3145
+ methods: (input?: SignInMethodsInput) => Effect.Effect<SignInStep, SignInCallError>;
3146
+ /** The email step; it opens a challenge when the browser holds none. */
3147
+ start: (input: SignInStartInput) => Effect.Effect<SignInStep, SignInCallError>;
3148
+ /** The code step. */
3149
+ verify: (input: SignInVerifyInput) => Effect.Effect<SignInStep, SignInCallError>;
3150
+ /** The name step of a new person, after `registration_required`. */
3151
+ complete: (input: SignInCompleteInput) => Effect.Effect<SignInStep, SignInCallError>;
3152
+ /**
3153
+ * Sends the browser to the SSO provider through the BFF, as `beginLogin`
3154
+ * sends it to the CI page; it gives `redirect_to_web`.
3155
+ */
3156
+ sso: (input: SignInSsoInput) => Effect.Effect<SignInStep, FederatedAuthError>;
3157
+ }>;
3158
+ declare const SignIn_base: Context.ServiceClass<SignIn, "@collective-intelligence/external-apps-client-sdk/SignIn", Readonly<{
3159
+ /** Opens a Sign-In Challenge and answers the methods that the app allows. */
3160
+ methods: (input?: SignInMethodsInput) => Effect.Effect<SignInStep, SignInCallError>;
3161
+ /** The email step; it opens a challenge when the browser holds none. */
3162
+ start: (input: SignInStartInput) => Effect.Effect<SignInStep, SignInCallError>;
3163
+ /** The code step. */
3164
+ verify: (input: SignInVerifyInput) => Effect.Effect<SignInStep, SignInCallError>;
3165
+ /** The name step of a new person, after `registration_required`. */
3166
+ complete: (input: SignInCompleteInput) => Effect.Effect<SignInStep, SignInCallError>;
3167
+ /**
3168
+ * Sends the browser to the SSO provider through the BFF, as `beginLogin`
3169
+ * sends it to the CI page; it gives `redirect_to_web`.
3170
+ */
3171
+ sso: (input: SignInSsoInput) => Effect.Effect<SignInStep, FederatedAuthError>;
3172
+ }>>;
3173
+ /** `auth.signIn` of a sealed-cookie BFF session; `layerServerSessionAuth` provides it. */
3174
+ declare class SignIn extends SignIn_base {}
2766
3175
  type ServerSessionAuthOptions = Readonly<{
2767
3176
  basePath: string;
2768
3177
  fetch?: ClientFetch;
@@ -2770,14 +3179,37 @@ type ServerSessionAuthOptions = Readonly<{
2770
3179
  now?: () => number;
2771
3180
  origin?: string;
2772
3181
  }>;
3182
+ /**
3183
+ * `FederatedAuth` of a sealed-cookie BFF, with the headless steps of
3184
+ * Embedded Sign-In. Each `signIn` call resolves one `SignInStep`, also for a
3185
+ * refusal such as `invalid_code`; it rejects only with `CiTransportError`,
3186
+ * when it gets no step, or with `FederatedAuthError` `configuration_error`,
3187
+ * when it cannot navigate. The calls run one at a time.
3188
+ */
3189
+ type ServerSessionAuth = FederatedAuth & Readonly<{
3190
+ close: () => Promise<void>;
3191
+ signIn: Readonly<{
3192
+ /** Opens a Sign-In Challenge and resolves the `methods` step. */
3193
+ methods: (input?: SignInMethodsInput) => Promise<SignInStep>;
3194
+ /** The email step; it opens a challenge when the browser holds none. */
3195
+ start: (input: SignInStartInput) => Promise<SignInStep>;
3196
+ /** The code step. */
3197
+ verify: (input: SignInVerifyInput) => Promise<SignInStep>;
3198
+ /** The name step of a new person, after `registration_required`. */
3199
+ complete: (input: SignInCompleteInput) => Promise<SignInStep>;
3200
+ /**
3201
+ * Sends the browser to the SSO provider through the BFF, as
3202
+ * `beginLogin` sends it to the CI page; it resolves `redirect_to_web`.
3203
+ */
3204
+ sso: (input: SignInSsoInput) => Promise<SignInStep>;
3205
+ }>;
3206
+ }>;
2773
3207
  /**
2774
3208
  * Browser session client for a sealed-cookie BFF. The access token never
2775
3209
  * leaves the server. A bad option throws `FederatedAuthError`
2776
3210
  * `configuration_error`. `close` disposes the runtime of the client.
2777
3211
  */
2778
- declare const createServerSessionAuth: (options: ServerSessionAuthOptions) => FederatedAuth & Readonly<{
2779
- close: () => Promise<void>;
2780
- }>;
3212
+ declare const createServerSessionAuth: (options: ServerSessionAuthOptions) => ServerSessionAuth;
2781
3213
  type ReturnTarget = Readonly<{
2782
3214
  returnTo: string;
2783
3215
  }>;
@@ -2814,12 +3246,15 @@ declare const FederatedAuth_base: Context.ServiceClass<FederatedAuth$1, "@collec
2814
3246
  declare class FederatedAuth$1 extends FederatedAuth_base {}
2815
3247
  /** `FederatedAuth` of browser federated sign-in; a bad option fails with `configuration_error`. */
2816
3248
  declare const layerFederated: (options: FederatedAuthOptions) => Layer.Layer<FederatedAuth$1, FederatedAuthError, never>;
2817
- /** `FederatedAuth` of a sealed-cookie BFF session; a bad option fails with `configuration_error`. */
2818
- declare const layerServerSession: (options: ServerSessionAuthOptions) => Layer.Layer<FederatedAuth$1, FederatedAuthError, never>;
3249
+ /**
3250
+ * `FederatedAuth` and `SignIn` of a sealed-cookie BFF session, over one
3251
+ * Session; a bad option fails with `configuration_error`.
3252
+ */
3253
+ declare const layerServerSession: (options: ServerSessionAuthOptions) => Layer.Layer<FederatedAuth$1 | SignIn, FederatedAuthError, never>;
2819
3254
  /** `layerFederated` with options that Effect `Config` reads. */
2820
- declare const layerFederatedConfig: (config: Config.Wrap<FederatedAuthOptions>) => Layer.Layer<FederatedAuth$1, Config.ConfigError | FederatedAuthError, never>;
3255
+ declare const layerFederatedConfig: (config: Config.Wrap<FederatedAuthOptions>) => Layer.Layer<FederatedAuth$1, FederatedAuthError | Config.ConfigError, never>;
2821
3256
  /** `layerServerSession` with options that Effect `Config` reads. */
2822
- declare const layerServerSessionConfig: (config: Config.Wrap<ServerSessionAuthOptions>) => Layer.Layer<FederatedAuth$1, Config.ConfigError | FederatedAuthError, never>;
3257
+ declare const layerServerSessionConfig: (config: Config.Wrap<ServerSessionAuthOptions>) => Layer.Layer<FederatedAuth$1 | SignIn, FederatedAuthError | Config.ConfigError, never>;
2823
3258
  /**
2824
3259
  * The signed-in CI user as the application's BFF reports it: the fields of
2825
3260
  * CI's `/oauth/identity`, read live by the server, plus email and name.
@@ -2907,4 +3342,591 @@ type ProxyTransportOptions = Readonly<{
2907
3342
  declare const createProxyTransport: <Operations extends ClientOperationMap>(options: ProxyTransportOptions) => TypedOperationExecutor<Operations> & Readonly<{
2908
3343
  close: () => Promise<void>;
2909
3344
  }>;
2910
- export { FederatedAuthError as A, ConversationHistory as B, OperationExecutionOptions as C, CiError as D, isClientOperationId as E, JsonValue as F, SearchQuery as G, JsonObject as H, OperationRequest as I, WorkflowInvokeTarget as K, OperationSuccess as L, CiError$1 as M, CiErrorCode$1 as N, CiErrorCode as O, CiResult as P, AgentInvokeTarget as R, ClientOperationOutput as S, clientOperationIds as T, KnowledgeQuery as U, ExternalApplicationChatOperationId as V, QueryFilter as W, createServerSessionAuth as _, FederatedAuth as a, ClientOperationInput as b, FederatedSessionIdentity as c, FederatedAuthValue as d, layerFederated as f, ServerSessionAuthOptions as g, layerServerSessionConfig as h, ClientFetch as i, FederatedAuthErrorCode as j, CiTransportError as k, createFederatedAuth as l, layerServerSession as m, ProxyTransportOptions as n, FederatedAuthOptions as o, layerFederatedConfig as p, createProxyTransport as r, FederatedAuthState as s, ProxyAuthentication as t, FederatedAuth$1 as u, ClientOperationDefinition as v, TypedOperationExecutor as w, ClientOperationMap as x, ClientOperationId as y, ConversationContinueTarget as z };
3345
+ type ResourceJsonValue = null | boolean | number | string | readonly ResourceJsonValue[] | Readonly<{
3346
+ [key: string]: ResourceJsonValue;
3347
+ }>;
3348
+ /** Opaque wire identity. Callers must not infer or concatenate its internals. */
3349
+ type ResourceId = string;
3350
+ type ResourceRecordId = ResourceId;
3351
+ /** Opaque concurrency token independent from source timestamps. */
3352
+ type ResourceRevision = string;
3353
+ /** Opaque pagination position issued and consumed only by a resource adapter. */
3354
+ type ResourceCursor = string;
3355
+ type IdempotencyKey = string;
3356
+ type ResourceIdentityField = Readonly<{
3357
+ name: string;
3358
+ type: "number" | "string";
3359
+ }>;
3360
+ type ResourceCapabilities = Readonly<{
3361
+ /** All-or-nothing entity batches; each op also needs its own capability. */
3362
+ batch?: boolean;
3363
+ create?: boolean;
3364
+ /** Common entity deletion is always soft deletion. */
3365
+ delete?: boolean;
3366
+ get?: boolean;
3367
+ hardDelete?: boolean;
3368
+ includeDeleted?: boolean;
3369
+ restore?: boolean;
3370
+ search: true;
3371
+ softDelete?: boolean;
3372
+ update?: boolean;
3373
+ /** File uploads for the File fields of a common entity resource. */
3374
+ upload?: boolean;
3375
+ }>;
3376
+ type ResourcePaginationMode = "cursor" | "page";
3377
+ type PortableResourceSchema = Readonly<Record<string, ResourceJsonValue>>;
3378
+ type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>> = Readonly<{
3379
+ capabilities: ResourceCapabilities;
3380
+ concurrency: "revision";
3381
+ id: string;
3382
+ identity: Readonly<{
3383
+ fields: readonly [ResourceIdentityField, ...ResourceIdentityField[]];
3384
+ }>;
3385
+ query: Readonly<{
3386
+ filterableFields: readonly string[];
3387
+ pagination: Readonly<{
3388
+ modes: readonly ResourcePaginationMode[];
3389
+ }>;
3390
+ sortableFields: readonly string[];
3391
+ textSearchFields?: readonly string[];
3392
+ }>;
3393
+ schemas: Readonly<{
3394
+ create?: PortableResourceSchema;
3395
+ entity: PortableResourceSchema;
3396
+ update?: PortableResourceSchema;
3397
+ }>;
3398
+ version: string;
3399
+ /** Portable UI metadata; required/enum/nullability remain in schemas. */
3400
+ metadata?: Readonly<Record<string, ResourceJsonValue>>;
3401
+ /** Type-only slots keep definition values portable and serializable. */
3402
+ readonly __types?: Readonly<{
3403
+ create: Create;
3404
+ entity: Entity;
3405
+ update: Update;
3406
+ }>;
3407
+ }>;
3408
+ type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
3409
+ /**
3410
+ * A filter predicate. `field` names a declared filterable field, or a path
3411
+ * through at most three fields that hold Entity References to a field of
3412
+ * the last target, such as `company.industry` or
3413
+ * `contacts.company.parent.industry`. On a field that holds Entity
3414
+ * References, `is_empty` means no reference. User fields accept identity
3415
+ * predicates for one ID and `contains_any`, `contains_all`, `contains_none`
3416
+ * for multiple IDs, plus empty/not-empty aliases. CI validates operators
3417
+ * against the actual field semantic; UUID shape alone does not declare User.
3418
+ */
3419
+ type ResourceFilter = Readonly<{
3420
+ field: string;
3421
+ operator: "contains" | "contains_all" | "contains_any" | "contains_none" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
3422
+ value: FilterValue;
3423
+ }> | Readonly<{
3424
+ field: string;
3425
+ operator: "is_empty" | "is_not_empty" | "is_not_null" | "is_null";
3426
+ }> | Readonly<{
3427
+ filters: readonly ResourceFilter[];
3428
+ operator: "and" | "or";
3429
+ }> | Readonly<{
3430
+ filter: ResourceFilter;
3431
+ operator: "not";
3432
+ }>;
3433
+ type ResourceSort = Readonly<{
3434
+ direction: "asc" | "desc";
3435
+ field: string;
3436
+ }>;
3437
+ type ResourcePagination = Readonly<{
3438
+ mode: "cursor";
3439
+ cursor?: ResourceCursor;
3440
+ limit: number;
3441
+ }> | Readonly<{
3442
+ mode: "page";
3443
+ page: number;
3444
+ pageSize: number;
3445
+ }>;
3446
+ type ResourceListQuery = Readonly<{
3447
+ filter?: ResourceFilter;
3448
+ /**
3449
+ * Include Paths, such as `["company", "contacts.company"]`: relation
3450
+ * fields whose records each item carries in `included`.
3451
+ */
3452
+ include?: readonly string[];
3453
+ includeDeleted?: boolean;
3454
+ pagination: ResourcePagination;
3455
+ sort?: readonly ResourceSort[];
3456
+ textSearch?: string;
3457
+ }>;
3458
+ /**
3459
+ * What the caller may write of a record, as CI's write policies decide it:
3460
+ * `write` tells whether a write policy admits the record, and
3461
+ * `writableFields` names the schema fields that those policies may change;
3462
+ * none when `write` is false. A hint for the UI: CI decides each write again.
3463
+ */
3464
+ type ResourceRecordAccess = Readonly<{
3465
+ writableFields: readonly string[];
3466
+ write: boolean;
3467
+ }>;
3468
+ type ResourceRecord<Entity> = Readonly<{
3469
+ /** The caller's access; absent when CI answers none, as an older CI does. */
3470
+ access?: ResourceRecordAccess;
3471
+ deletedAt?: string;
3472
+ id: ResourceRecordId;
3473
+ /**
3474
+ * The records of the read's Include Paths by relation field key: one
3475
+ * record, or the records of a `many` field in reference order. Untyped:
3476
+ * the target schemas are CI's.
3477
+ */
3478
+ included?: Readonly<Record<string, ResourceJsonValue>>;
3479
+ revision: ResourceRevision;
3480
+ /** The keys whose included records were cut to the first 100. */
3481
+ truncated?: readonly string[];
3482
+ value: Entity;
3483
+ }>;
3484
+ type ResourceListResult<Entity> = Readonly<{
3485
+ items: readonly ResourceRecord<Entity>[];
3486
+ nextCursor?: ResourceCursor;
3487
+ pagination: "cursor";
3488
+ }> | Readonly<{
3489
+ items: readonly ResourceRecord<Entity>[];
3490
+ page: number;
3491
+ pageSize: number;
3492
+ pagination: "page";
3493
+ totalItems: number;
3494
+ totalPages: number;
3495
+ }>;
3496
+ type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable" |
3497
+ /** The CI Organization storage can not take a presigned File upload. */
3498
+ "upload_not_supported";
3499
+ /** Stable, content-free diagnostics for request-wide Knowledge read limits. */
3500
+ type EntityReadLimitDetails = Readonly<{
3501
+ reason: "read_limit_exceeded";
3502
+ budget: "work" | "nodes" | "relation_ids" | "bytes";
3503
+ }>;
3504
+ type ResourceError = Readonly<{
3505
+ code: ResourceErrorCode;
3506
+ /** Client-observed dispatch outcome; uncertainty never proves rollback. */
3507
+ outcome?: "not_dispatched" | "rejected" | "uncertain";
3508
+ details?: Readonly<Record<string, ResourceJsonValue>>;
3509
+ message: string;
3510
+ retryable: boolean;
3511
+ }>;
3512
+ type ResourceResult<Value> = Readonly<{
3513
+ correlationId: string;
3514
+ ok: true;
3515
+ value: Value;
3516
+ }> | Readonly<{
3517
+ correlationId: string;
3518
+ error: ResourceError;
3519
+ ok: false;
3520
+ }>;
3521
+ type ResourceRequestOptions = Readonly<{
3522
+ signal?: AbortSignal;
3523
+ }>;
3524
+ type ResourceListRequest = Readonly<{
3525
+ operation: "list";
3526
+ query: ResourceListQuery;
3527
+ requestId: string;
3528
+ resourceId: string;
3529
+ }>;
3530
+ type ResourceGetRequest = Readonly<{
3531
+ id: ResourceRecordId;
3532
+ includeDeleted?: boolean;
3533
+ operation: "get";
3534
+ requestId: string;
3535
+ resourceId: string;
3536
+ }>;
3537
+ type ResourceCreateRequest<Create> = Readonly<{
3538
+ idempotencyKey: IdempotencyKey;
3539
+ operation: "create";
3540
+ requestId: string;
3541
+ resourceId: string;
3542
+ value: Create;
3543
+ }>;
3544
+ type ResourceUpdateRequest<Update> = Readonly<{
3545
+ expectedRevision: ResourceRevision;
3546
+ id: ResourceRecordId;
3547
+ idempotencyKey?: IdempotencyKey;
3548
+ operation: "update";
3549
+ requestId: string;
3550
+ resourceId: string;
3551
+ value: Update;
3552
+ }>;
3553
+ type ResourceLifecycleRequest = Readonly<{
3554
+ expectedRevision: ResourceRevision;
3555
+ id: ResourceRecordId;
3556
+ idempotencyKey?: IdempotencyKey;
3557
+ operation: "hard_delete" | "restore" | "soft_delete";
3558
+ requestId: string;
3559
+ resourceId: string;
3560
+ }>;
3561
+ type ResourceTransportRequest = ResourceCreateRequest<unknown> | ResourceGetRequest | ResourceLifecycleRequest | ResourceListRequest | ResourceUpdateRequest<unknown>;
3562
+ interface ResourceTransport {
3563
+ readonly execute: (request: ResourceTransportRequest, options?: ResourceRequestOptions) => Promise<ResourceResult<unknown>>;
3564
+ }
3565
+ type ResourceMutationInput<Value> = Readonly<{
3566
+ expectedRevision: ResourceRevision;
3567
+ id: ResourceRecordId;
3568
+ idempotencyKey?: IdempotencyKey;
3569
+ value: Value;
3570
+ }>;
3571
+ type ResourceLifecycleInput = Readonly<{
3572
+ expectedRevision: ResourceRevision;
3573
+ id: ResourceRecordId;
3574
+ idempotencyKey?: IdempotencyKey;
3575
+ }>;
3576
+ type ResourceCreateInput<Value> = Readonly<{
3577
+ idempotencyKey: IdempotencyKey;
3578
+ value: Value;
3579
+ }>;
3580
+ interface ResourceClient<Entity, Create = Entity, Update = Partial<Entity>> {
3581
+ readonly capabilities: ResourceCapabilities;
3582
+ readonly create: (input: ResourceCreateInput<Create>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
3583
+ readonly definition: ResourceDefinition<Entity, Create, Update>;
3584
+ readonly get: (input: Readonly<{
3585
+ id: ResourceRecordId;
3586
+ includeDeleted?: boolean;
3587
+ }>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
3588
+ readonly hardDelete: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<void>>;
3589
+ readonly list: (query: ResourceListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceListResult<Entity>>>;
3590
+ readonly restore: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
3591
+ readonly softDelete: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
3592
+ readonly update: (input: ResourceMutationInput<Update>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
3593
+ }
3594
+ /** Common entity operations. Generic resource lifecycle/cursor APIs remain separate. */
3595
+ type EntityOperation = "list_members" | "list" | "get" | "create" | "update" | "delete" | "restore" | "upload" | "batch";
3596
+ /**
3597
+ * An entity search. It pages by the `nextCursor` of the previous page, or by
3598
+ * number for a page-numbered view; CI refuses a page past its first 10,000
3599
+ * records. `textSearch` searches all text of the record.
3600
+ */
3601
+ type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDeleted"> & Readonly<{
3602
+ /** Count every match; else CI stops the total at 10,000. */
3603
+ exactTotal?: boolean;
3604
+ pagination: ResourcePagination;
3605
+ }>;
3606
+ /**
3607
+ * A page of an entity search. `total` is the Capped Total: exact up to
3608
+ * 10,000 records unless the search asks for `exactTotal`;
3609
+ * `totalIsLowerBound` tells that more records match. `facetsPartial` tells
3610
+ * that facets count only the first 100,000 candidates. `nextCursor` pages
3611
+ * the same search; it is null on the last page.
3612
+ */
3613
+ type EntityPage<Value> = Readonly<{
3614
+ facetsPartial: boolean;
3615
+ items: readonly ResourceRecord<Value>[];
3616
+ nextCursor: ResourceCursor | null;
3617
+ total: number;
3618
+ totalIsLowerBound: boolean;
3619
+ }> & (Readonly<{
3620
+ pagination: "cursor";
3621
+ }> | Readonly<{
3622
+ pagination: "page";
3623
+ page: number;
3624
+ pageSize: number;
3625
+ }>);
3626
+ /** Member schemas are resolved by CI, independently of the parent resource. */
3627
+ type EntityMemberValue = Readonly<Record<string, ResourceJsonValue>>;
3628
+ type EntityCreateInput<Value> = ResourceCreateInput<Value>;
3629
+ type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
3630
+ idempotencyKey: IdempotencyKey;
3631
+ }>;
3632
+ type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
3633
+ idempotencyKey: IdempotencyKey;
3634
+ }>;
3635
+ /** A restore of a soft-deleted record at the revision its delete gave. */
3636
+ type EntityRestoreInput = EntityDeleteInput;
3637
+ /** One op of an entity batch: the single write it stands for, without a key. */
3638
+ type EntityBatchOp<Create = unknown, Patch = unknown> = Readonly<{
3639
+ op: "create";
3640
+ value: Create;
3641
+ }> | Readonly<{
3642
+ op: "update";
3643
+ id: ResourceRecordId;
3644
+ expectedRevision: ResourceRevision;
3645
+ value: Patch;
3646
+ }> | Readonly<{
3647
+ op: "delete" | "restore";
3648
+ id: ResourceRecordId;
3649
+ expectedRevision: ResourceRevision;
3650
+ }>;
3651
+ /**
3652
+ * 1 to 100 ops on the records of one resource, under one key. CI commits
3653
+ * every op or none; the same key with the same ops replays the answer, and
3654
+ * with other ops answers `conflict`.
3655
+ */
3656
+ type EntityBatchInput<Create = unknown, Patch = unknown> = Readonly<{
3657
+ idempotencyKey: IdempotencyKey;
3658
+ ops: readonly EntityBatchOp<Create, Patch>[];
3659
+ }>;
3660
+ /** An op that CI refused; `id` is absent for a `create`. */
3661
+ type EntityBatchRefusal = Readonly<{
3662
+ index: number;
3663
+ id?: ResourceRecordId;
3664
+ reason: "conflict" | "forbidden" | "invalid_request" | "not_found";
3665
+ }>;
3666
+ /**
3667
+ * The `details` of a refused batch, which CI wrote nothing for. The error
3668
+ * `code` is the `reason` of the first refused op. `refused` holds the
3669
+ * refused ops that CI found: CI checks the ops in stages and stops at the
3670
+ * first stage that refuses an op, so an op that a later stage would refuse
3671
+ * can be absent.
3672
+ */
3673
+ type EntityBatchRefusedDetails = Readonly<{
3674
+ reason: "batch_refused";
3675
+ refused: readonly EntityBatchRefusal[];
3676
+ }>;
3677
+ /** A File upload request for one File field of the entity schema. */
3678
+ type EntityUploadInput = Readonly<{
3679
+ field: string;
3680
+ filename: string;
3681
+ mimeType: string;
3682
+ /**
3683
+ * The file size in bytes, a non-negative integer such as `File.size`. CI
3684
+ * refuses a slot over the field's limit with `invalid_request` and
3685
+ * `details.reason: "file_too_large"`; storage may refuse a PUT of another
3686
+ * size.
3687
+ */
3688
+ size: number;
3689
+ }>;
3690
+ /** PUT the file bytes to `url` with `headers`; then write `{ upload: uploadId }`. */
3691
+ type EntityUploadSlot = Readonly<{
3692
+ headers: Readonly<Record<string, string>>;
3693
+ method: "PUT";
3694
+ uploadId: string;
3695
+ url: string;
3696
+ }>;
3697
+ /** The read-time value of one file of a File field. */
3698
+ type EntityFileValue = Readonly<{
3699
+ id: string;
3700
+ url: string;
3701
+ filename: string;
3702
+ mimeType: string | null;
3703
+ size: number | null;
3704
+ source: "managed" | "external_url";
3705
+ }>;
3706
+ /** `{ upload }` adds a File upload; `{ id }`, or a File value read before, keeps that file. */
3707
+ type EntityFileWrite = Readonly<{
3708
+ upload: string;
3709
+ id?: never;
3710
+ }> | Readonly<{
3711
+ id: string;
3712
+ upload?: never;
3713
+ }>;
3714
+ /**
3715
+ * The write form of a File field key: one file or `null` for a single field,
3716
+ * an ordered array for a multiple field, `null` removes every file. Omit the
3717
+ * key to keep its files unchanged.
3718
+ */
3719
+ type EntityFileFieldWrite = EntityFileWrite | readonly EntityFileWrite[] | null;
3720
+ type EntityRequestIdentity = Readonly<{
3721
+ requestId: string;
3722
+ resourceId: string;
3723
+ }>;
3724
+ type EntityRequest<Create = unknown, Patch = unknown> = EntityRequestIdentity & (Readonly<{
3725
+ operation: "list";
3726
+ query: EntityListQuery;
3727
+ }> | Readonly<{
3728
+ operation: "list_members";
3729
+ parentId: ResourceRecordId;
3730
+ field: string;
3731
+ query: EntityListQuery;
3732
+ }> | Readonly<{
3733
+ operation: "get";
3734
+ id: ResourceRecordId;
3735
+ include?: readonly string[];
3736
+ }> | (Readonly<{
3737
+ operation: "create";
3738
+ }> & EntityCreateInput<Create>) | (Readonly<{
3739
+ operation: "update";
3740
+ }> & EntityUpdateInput<Patch>) | (Readonly<{
3741
+ operation: "delete";
3742
+ }> & EntityDeleteInput) | (Readonly<{
3743
+ operation: "restore";
3744
+ }> & EntityRestoreInput) | (Readonly<{
3745
+ operation: "upload";
3746
+ }> & EntityUploadInput) | (Readonly<{
3747
+ operation: "batch";
3748
+ }> & EntityBatchInput<Create, Patch>));
3749
+ type EntityOperationResult<Value, Operation extends EntityOperation> = Operation extends "list_members" ? EntityPage<EntityMemberValue> : Operation extends "list" ? EntityPage<Value> : Operation extends "upload" ? EntityUploadSlot : Operation extends "batch" ? readonly ResourceRecord<Value>[] : ResourceRecord<Value>;
3750
+ /** Codecs return safe typed failures without coercing values or performing I/O. */
3751
+ type EntityProtocol<Value, Create = Value, Patch = Partial<Value>> = Readonly<{
3752
+ decodeRequest: (input: unknown) => ResourceResult<EntityRequest<Create, Patch>>;
3753
+ decodeResult: <Operation extends EntityOperation>(operation: Operation, input: unknown, correlationId: string) => ResourceResult<EntityOperationResult<Value, Operation>>;
3754
+ }>;
3755
+ interface EntityTransport {
3756
+ readonly execute: (request: EntityRequest, options?: ResourceRequestOptions) => Promise<ResourceResult<unknown>>;
3757
+ }
3758
+ /** A logical write retains its key, payload and edited revision on explicit resubmission. */
3759
+ interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
3760
+ /** Filter, sort and page the resolved member schema; includes remain bounded. */
3761
+ readonly listMembers: (parentId: ResourceRecordId, field: string, query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<EntityMemberValue>>>;
3762
+ readonly definition: ResourceDefinition<Value, Create, Patch>;
3763
+ readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
3764
+ readonly get: (input: Readonly<{
3765
+ id: ResourceRecordId;
3766
+ include?: readonly string[];
3767
+ }>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
3768
+ readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
3769
+ readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
3770
+ readonly delete: (input: EntityDeleteInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
3771
+ /**
3772
+ * Makes a soft-deleted record live again; requires the `restore`
3773
+ * capability. A stale revision answers `conflict`; a live record answers
3774
+ * itself unchanged. A connector record whose delete also removed its
3775
+ * remote ref answers `conflict` and stays deleted.
3776
+ */
3777
+ readonly restore: (input: EntityRestoreInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
3778
+ /** A single-use File upload slot; requires the `upload` capability. */
3779
+ readonly upload: (input: EntityUploadInput, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityUploadSlot>>;
3780
+ /**
3781
+ * Commits every op or none, each by the rules of its single write;
3782
+ * requires the `batch` capability and the capability of each op. The
3783
+ * answer holds the record of each op in op order. A refused batch writes
3784
+ * nothing and lists the refused ops that CI found in
3785
+ * `EntityBatchRefusedDetails`. A second op on one record is `conflict`:
3786
+ * the caller cannot know the revision that the first op gives.
3787
+ */
3788
+ readonly batch: (input: EntityBatchInput<Create, Patch>) => Promise<ResourceResult<readonly ResourceRecord<Value>[]>>;
3789
+ }
3790
+ type ClientOptions<Value, Create, Patch> = Readonly<{
3791
+ definition: ResourceDefinition<Value, Create, Patch>;
3792
+ requestId?: () => string;
3793
+ }>;
3794
+ declare function createResourceClient<Value, Create = Value, Patch = Partial<Value>>(options: ClientOptions<Value, Create, Patch> & Readonly<{
3795
+ protocol: "entity";
3796
+ transport: EntityTransport;
3797
+ }>): EntityClient<Value, Create, Patch> & Readonly<{
3798
+ close: () => Promise<void>;
3799
+ }>;
3800
+ declare function createResourceClient<Value, Create = Value, Patch = Partial<Value>>(options: ClientOptions<Value, Create, Patch> & Readonly<{
3801
+ transport: ResourceTransport;
3802
+ }>): ResourceClient<Value, Create, Patch> & Readonly<{
3803
+ close: () => Promise<void>;
3804
+ }>;
3805
+ /** Narrow a decoded resource failure to its documented request-wide read limit. */
3806
+ declare const isEntityReadLimitError: (error: ResourceError) => error is ResourceError & Readonly<{
3807
+ code: "invalid_request";
3808
+ details: EntityReadLimitDetails;
3809
+ }>;
3810
+ /** Narrow a decoded resource failure to a refused batch and its refused ops. */
3811
+ declare const isEntityBatchRefusedError: (error: ResourceError) => error is ResourceError & Readonly<{
3812
+ details: EntityBatchRefusedDetails;
3813
+ }>;
3814
+ /** Common entity wire codec; transport and persistence remain with their owners. */
3815
+ declare const createEntityProtocol: <Value, Create = Value, Patch = Partial<Value>>(definition: ResourceDefinition<Value, Create, Patch>) => EntityProtocol<Value, Create, Patch>;
3816
+ /** One entity request as its envelope; only a transport failure fails. */
3817
+ type EntityExecute = (request: EntityRequest, options: ResourceRequestOptions) => Effect.Effect<ResourceResult<unknown>, CiTransportError>;
3818
+ type ResourceFailure = CiError | CiTransportError;
3819
+ /** The entity client of one Resource Definition for `./effect`. */
3820
+ type ResourceEntityClient<Value, Create, Patch> = Readonly<{
3821
+ definition: ResourceDefinition<Value, Create, Patch>;
3822
+ get: (input: Readonly<{
3823
+ id: ResourceRecordId;
3824
+ include?: readonly string[];
3825
+ }>) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
3826
+ list: (query: EntityListQuery) => Effect.Effect<EntityPage<Value>, ResourceFailure>;
3827
+ listMembers: (parentId: ResourceRecordId, field: string, query: EntityListQuery) => Effect.Effect<EntityPage<EntityMemberValue>, ResourceFailure>;
3828
+ create: (input: EntityCreateInput<Create>) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
3829
+ update: (input: EntityUpdateInput<Patch>) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
3830
+ delete: (input: EntityDeleteInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
3831
+ restore: (input: EntityRestoreInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
3832
+ upload: (input: EntityUploadInput) => Effect.Effect<EntityUploadSlot, ResourceFailure>;
3833
+ /** Every op or none; a refused batch fails with its refused ops in `details`. */
3834
+ batch: (input: EntityBatchInput<Create, Patch>) => Effect.Effect<readonly ResourceRecord<Value>[], ResourceFailure>;
3835
+ }>;
3836
+ type ResourcesValue = Readonly<{
3837
+ /** The entity client of `definition`; a bad destination dies with `TypeError`. */
3838
+ bind: <Value, Create = Value, Patch = Partial<Value>>(definition: ResourceDefinition<Value, Create, Patch>) => ResourceEntityClient<Value, Create, Patch>;
3839
+ }>;
3840
+ declare const Resources_base: Context.ServiceClass<Resources, "@collective-intelligence/external-apps-client-sdk/Resources", Readonly<{
3841
+ /** The entity client of `definition`; a bad destination dies with `TypeError`. */
3842
+ bind: <Value, Create = Value, Patch = Partial<Value>>(definition: ResourceDefinition<Value, Create, Patch>) => ResourceEntityClient<Value, Create, Patch>;
3843
+ }>>;
3844
+ declare class Resources extends Resources_base {}
3845
+ type ResourcesLayerOptions = Readonly<{
3846
+ authentication: ProxyAuthentication;
3847
+ /** The HTTP destination of each Resource Definition, by its id. */
3848
+ destination: (resourceId: string) => EntityHttpDestination;
3849
+ fetch?: ClientFetch;
3850
+ requestId?: () => string;
3851
+ }>;
3852
+ /** `Resources` over the entity HTTP routes of `destination`. */
3853
+ declare const layer: (options: ResourcesLayerOptions) => Layer.Layer<Resources, never, never>;
3854
+ /** `layer` with options that Effect `Config` reads. */
3855
+ declare const layerConfig: (config: Config.Wrap<ResourcesLayerOptions>) => Layer.Layer<Resources, Config.ConfigError, never>;
3856
+ type ResourcesFromEntityTransportOptions = Readonly<{
3857
+ requestId?: () => string;
3858
+ transport: EntityTransport;
3859
+ }>;
3860
+ /**
3861
+ * `Resources` over an `EntityTransport` of the app, as
3862
+ * `createResourceClient` with `protocol: "entity"`. A rejection of the
3863
+ * transport fails with `CiTransportError`.
3864
+ */
3865
+ declare const layerFromEntityTransport: (options: ResourcesFromEntityTransportOptions) => Layer.Layer<Resources, never, never>;
3866
+ /**
3867
+ * The legacy resource client of one Resource Definition for `./effect`,
3868
+ * with the lifecycle operations. It fails as a `Resources` client does.
3869
+ */
3870
+ type LegacyResourceClient<Entity, Create, Update> = Readonly<{
3871
+ create: (input: ResourceCreateInput<Create>) => Effect.Effect<ResourceRecord<Entity>, ResourceFailure>;
3872
+ definition: ResourceDefinition<Entity, Create, Update>;
3873
+ get: (input: Readonly<{
3874
+ id: ResourceRecordId;
3875
+ includeDeleted?: boolean;
3876
+ }>) => Effect.Effect<ResourceRecord<Entity>, ResourceFailure>;
3877
+ hardDelete: (input: ResourceLifecycleInput) => Effect.Effect<void, ResourceFailure>;
3878
+ list: (query: ResourceListQuery) => Effect.Effect<ResourceListResult<Entity>, ResourceFailure>;
3879
+ restore: (input: ResourceLifecycleInput) => Effect.Effect<ResourceRecord<Entity>, ResourceFailure>;
3880
+ softDelete: (input: ResourceLifecycleInput) => Effect.Effect<ResourceRecord<Entity>, ResourceFailure>;
3881
+ update: (input: ResourceMutationInput<Update>) => Effect.Effect<ResourceRecord<Entity>, ResourceFailure>;
3882
+ }>;
3883
+ type LegacyResourcesValue = Readonly<{
3884
+ /** The legacy client of `definition` over the `ResourceTransport` of the layer. */
3885
+ bind: <Entity, Create = Entity, Update = Partial<Entity>>(definition: ResourceDefinition<Entity, Create, Update>) => LegacyResourceClient<Entity, Create, Update>;
3886
+ }>;
3887
+ declare const LegacyResources_base: Context.ServiceClass<LegacyResources, "@collective-intelligence/external-apps-client-sdk/LegacyResources", Readonly<{
3888
+ /** The legacy client of `definition` over the `ResourceTransport` of the layer. */
3889
+ bind: <Entity, Create = Entity, Update = Partial<Entity>>(definition: ResourceDefinition<Entity, Create, Update>) => LegacyResourceClient<Entity, Create, Update>;
3890
+ }>>;
3891
+ /** The `./effect` form of `createResourceClient` over a `ResourceTransport`. */
3892
+ declare class LegacyResources extends LegacyResources_base {}
3893
+ type LegacyResourcesLayerOptions = Readonly<{
3894
+ requestId?: () => string;
3895
+ transport: ResourceTransport;
3896
+ }>;
3897
+ /** `LegacyResources` over the `ResourceTransport` of `options`. */
3898
+ declare const layerLegacy: (options: LegacyResourcesLayerOptions) => Layer.Layer<LegacyResources, never, never>;
3899
+ /** `layerLegacy` with options that Effect `Config` reads. */
3900
+ declare const layerLegacyConfig: (config: Config.Wrap<LegacyResourcesLayerOptions>) => Layer.Layer<LegacyResources, Config.ConfigError, never>;
3901
+ type EntityHttpDestination = Readonly<{
3902
+ kind: "gateway";
3903
+ endpoint: string;
3904
+ }> | Readonly<{
3905
+ kind: "ci";
3906
+ tenantUrl: string;
3907
+ schemaFqn: string;
3908
+ organizationId: string;
3909
+ }>;
3910
+ type EntityHttpTransportOptions = Readonly<{
3911
+ destination: EntityHttpDestination;
3912
+ authentication: ProxyAuthentication;
3913
+ fetch?: ClientFetch;
3914
+ }>;
3915
+ /**
3916
+ * The entity HTTP adapter of one destination, the `./effect` form of
3917
+ * `createEntityHttpTransport`: each request is an Effect that runs in the
3918
+ * fiber of its caller. Early cancellation and a failed login stay envelopes,
3919
+ * as the request was not sent; a request that does not reach the server, or
3920
+ * an answer that cannot be read, fails with `CiTransportError`. A
3921
+ * destination without its CI selectors, or an endpoint with credentials,
3922
+ * query or fragment, throws `TypeError`.
3923
+ */
3924
+ declare const makeEntityHttpExecute: (options: EntityHttpTransportOptions) => EntityExecute;
3925
+ /**
3926
+ * The Vanilla Facade of the entity HTTP adapter, in a runtime of its own;
3927
+ * `close` disposes it.
3928
+ */
3929
+ declare const createEntityHttpTransport: (options: EntityHttpTransportOptions) => EntityTransport & Readonly<{
3930
+ close: () => Promise<void>;
3931
+ }>;
3932
+ export { ResourceDefinition as $, ClientOperationInput as $t, EntityFileFieldWrite as A, ExternalApplicationIntentDispatchOutcome as An, FederatedAuthOptions as At, EntityRequest as B, ServerSessionAuth as Bt, EntityBatchInput as C, KnowledgeQuery as Cn, ResourceTransportRequest as Ct, EntityClient as D, AccessCheckResponse as Dn, createProxyTransport as Dt, EntityBatchRefusedDetails as E, WorkflowInvokeTarget as En, ProxyTransportOptions as Et, EntityOperation as F, FederatedAuthValue as Ft, EntityUploadSlot as G, SignInMethodsInput as Gt, EntityTransport as H, createServerSessionAuth as Ht, EntityOperationResult as I, layerFederated as It, ResourceCapabilities as J, SignInStep as Jt, IdempotencyKey as K, SignInSsoInput as Kt, EntityPage as L, layerFederatedConfig as Lt, EntityFileWrite as M, FederatedSessionIdentity as Mt, EntityListQuery as N, createFederatedAuth as Nt, EntityCreateInput as O, AccessTarget as On, ClientFetch as Ot, EntityMemberValue as P, FederatedAuth$1 as Pt, ResourceCursor as Q, ClientOperationId as Qt, EntityProtocol as R, layerServerSession as Rt, createResourceClient as S, JsonObject as Sn, ResourceTransport as St, EntityBatchRefusal as T, SearchQuery as Tn, ProxyAuthentication as Tt, EntityUpdateInput as U, SignIn as Ut, EntityRestoreInput as V, ServerSessionAuthOptions as Vt, EntityUploadInput as W, SignInCompleteInput as Wt, ResourceCreateInput as X, SignInVerifyInput as Xt, ResourceClient as Y, SignInValue as Yt, ResourceCreateRequest as Z, ClientOperationDefinition as Zt, layerLegacy as _, AgentInvokeTarget as _n, ResourceRecordId as _t, LegacyResourceClient as a, isClientOperationId as an, ResourceIdentityField as at, isEntityBatchRefusedError as b, ExternalApplicationChatOperationId as bn, ResourceRevision as bt, LegacyResourcesValue as c, CiTransportError as cn, ResourceLifecycleRequest as ct, ResourcesFromEntityTransportOptions as d, CiError$1 as dn, ResourceListResult as dt, ClientOperationMap as en, ResourceError as et, ResourcesLayerOptions as f, CiErrorCode$1 as fn, ResourceMutationInput as ft, layerFromEntityTransport as g, OperationSuccess as gn, ResourceRecordAccess as gt, layerConfig as h, OperationRequest as hn, ResourceRecord as ht, makeEntityHttpExecute as i, clientOperationIds as in, ResourceId as it, EntityFileValue as j, ExternalApplicationIntentDispatchState as jn, FederatedAuthState as jt, EntityDeleteInput as k, ExternalApplicationIntent as kn, FederatedAuth as kt, ResourceEntityClient as l, FederatedAuthError as ln, ResourceListQuery as lt, layer as m, JsonValue as mn, ResourcePaginationMode as mt, EntityHttpTransportOptions as n, OperationExecutionOptions as nn, ResourceFilter as nt, LegacyResources as o, CiError as on, ResourceJsonValue as ot, ResourcesValue as p, CiResult as pn, ResourcePagination as pt, PortableResourceSchema as q, SignInStartInput as qt, createEntityHttpTransport as r, TypedOperationExecutor as rn, ResourceGetRequest as rt, LegacyResourcesLayerOptions as s, CiErrorCode as sn, ResourceLifecycleInput as st, EntityHttpDestination as t, ClientOperationOutput as tn, ResourceErrorCode as tt, Resources as u, FederatedAuthErrorCode as un, ResourceListRequest as ut, layerLegacyConfig as v, ConversationContinueTarget as vn, ResourceRequestOptions as vt, EntityBatchOp as w, QueryFilter as wn, ResourceUpdateRequest as wt, isEntityReadLimitError as x, ExternalApplicationIntentDispatchInput as xn, ResourceSort as xt, createEntityProtocol as y, ConversationHistory as yn, ResourceResult as yt, EntityReadLimitDetails as z, layerServerSessionConfig as zt };