@collective-intelligence/external-apps-server-sdk 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,19 @@
3
3
  export type ResourceJsonValue = null | boolean | number | string | readonly ResourceJsonValue[] | Readonly<{
4
4
  [key: string]: ResourceJsonValue;
5
5
  }>;
6
+ /** A File upload request for one File field of the entity schema. */
7
+ export type EntityUploadInput = Readonly<{
8
+ field: string;
9
+ filename: string;
10
+ mimeType: string;
11
+ }>;
12
+ /** PUT the file bytes to `url` with `headers`; then write `{ upload: uploadId }`. */
13
+ export type EntityUploadSlot = Readonly<{
14
+ headers: Readonly<Record<string, string>>;
15
+ method: "PUT";
16
+ uploadId: string;
17
+ url: string;
18
+ }>;
6
19
  export type ExternalApplicationsGetContextErrors = {
7
20
  /**
8
21
  * Error
@@ -12,6 +25,7 @@ export type ExternalApplicationsGetContextErrors = {
12
25
  error: {
13
26
  code: "invalid_request";
14
27
  message: string;
28
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
15
29
  retryable: false;
16
30
  };
17
31
  };
@@ -23,6 +37,7 @@ export type ExternalApplicationsGetContextErrors = {
23
37
  error: {
24
38
  code: "authentication_required";
25
39
  message: string;
40
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
26
41
  retryable: false;
27
42
  };
28
43
  };
@@ -34,6 +49,7 @@ export type ExternalApplicationsGetContextErrors = {
34
49
  error: {
35
50
  code: "authorization_denied";
36
51
  message: string;
52
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
37
53
  retryable: false;
38
54
  };
39
55
  };
@@ -45,6 +61,7 @@ export type ExternalApplicationsGetContextErrors = {
45
61
  error: {
46
62
  code: "operation_not_allowed";
47
63
  message: string;
64
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
48
65
  retryable: false;
49
66
  };
50
67
  } | {
@@ -52,6 +69,7 @@ export type ExternalApplicationsGetContextErrors = {
52
69
  error: {
53
70
  code: "not_found";
54
71
  message: string;
72
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
55
73
  retryable: false;
56
74
  };
57
75
  };
@@ -63,6 +81,7 @@ export type ExternalApplicationsGetContextErrors = {
63
81
  error: {
64
82
  code: "conflict";
65
83
  message: string;
84
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
66
85
  retryable: false;
67
86
  };
68
87
  };
@@ -74,6 +93,7 @@ export type ExternalApplicationsGetContextErrors = {
74
93
  error: {
75
94
  code: "internal_error";
76
95
  message: string;
96
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
77
97
  retryable: false;
78
98
  };
79
99
  };
@@ -85,11 +105,93 @@ export type ExternalApplicationsGetContextErrors = {
85
105
  error: {
86
106
  code: "temporarily_unavailable";
87
107
  message: string;
108
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
88
109
  retryable: true;
89
110
  };
90
111
  };
91
112
  };
92
113
  export type ExternalApplicationsGetContextError = ExternalApplicationsGetContextErrors[keyof ExternalApplicationsGetContextErrors];
114
+ export type ExternalApplicationsListAppUsersResponses = {
115
+ /**
116
+ * Success
117
+ */
118
+ 200: {
119
+ correlationId: string;
120
+ result: {
121
+ items: Array<{
122
+ email: string | null;
123
+ name: string | null;
124
+ userId: string;
125
+ }>;
126
+ };
127
+ };
128
+ };
129
+ export type ExternalApplicationsListAppUsersResponse = ExternalApplicationsListAppUsersResponses[keyof ExternalApplicationsListAppUsersResponses];
130
+ export type ExternalApplicationsCreateOrGetAppUserData = {
131
+ body: {
132
+ email: string;
133
+ name: string;
134
+ roles: Array<string>;
135
+ };
136
+ headers: {
137
+ authorization?: string;
138
+ "x-organization-id": string;
139
+ "x-correlation-id"?: string;
140
+ "x-external-audit-issuer"?: string;
141
+ "x-external-audit-subject"?: string;
142
+ "x-external-caller-kind"?: "anonymous_visitor";
143
+ "x-external-ci-user-id"?: string;
144
+ "x-external-server-role"?: string;
145
+ };
146
+ path?: never;
147
+ query?: never;
148
+ url: "/application/v1/users";
149
+ };
150
+ export type ExternalApplicationsCreateOrGetAppUserResponses = {
151
+ /**
152
+ * Success
153
+ */
154
+ 200: {
155
+ correlationId: string;
156
+ result: {
157
+ email: string | null;
158
+ name: string | null;
159
+ userId: string;
160
+ created: boolean;
161
+ kind: "member" | "external_app_user";
162
+ };
163
+ };
164
+ };
165
+ export type ExternalApplicationsCreateOrGetAppUserResponse = ExternalApplicationsCreateOrGetAppUserResponses[keyof ExternalApplicationsCreateOrGetAppUserResponses];
166
+ export type ExternalApplicationsGetAppUserResponses = {
167
+ /**
168
+ * Success
169
+ */
170
+ 200: {
171
+ correlationId: string;
172
+ result: {
173
+ email: string | null;
174
+ name: string | null;
175
+ userId: string;
176
+ };
177
+ };
178
+ };
179
+ export type ExternalApplicationsGetAppUserResponse = ExternalApplicationsGetAppUserResponses[keyof ExternalApplicationsGetAppUserResponses];
180
+ export type ExternalApplicationsListAppRolesResponses = {
181
+ /**
182
+ * Success
183
+ */
184
+ 200: {
185
+ correlationId: string;
186
+ result: {
187
+ items: Array<{
188
+ id: string;
189
+ key: string;
190
+ }>;
191
+ };
192
+ };
193
+ };
194
+ export type ExternalApplicationsListAppRolesResponse = ExternalApplicationsListAppRolesResponses[keyof ExternalApplicationsListAppRolesResponses];
93
195
  export type JsonValue = boolean | null | number | readonly JsonValue[] | Readonly<{
94
196
  readonly [key: string]: JsonValue;
95
197
  }> | string;
@@ -174,6 +276,40 @@ export type KnowledgeQuery = {
174
276
  op: "autocomplete";
175
277
  });
176
278
  export type ExternalApplicationOperationRequest = {
279
+ input: {
280
+ userId: string;
281
+ };
282
+ operationId: "users_get";
283
+ } | {
284
+ input: {
285
+ page?: number;
286
+ pageSize?: number;
287
+ };
288
+ operationId: "users_list";
289
+ } | {
290
+ input: {
291
+ userId: string;
292
+ };
293
+ operationId: "users_deactivate";
294
+ } | {
295
+ input: Record<string, never>;
296
+ operationId: "roles_list";
297
+ } | {
298
+ input: {
299
+ userId: string;
300
+ roles: string[];
301
+ };
302
+ operationId: "roles_assign";
303
+ } | {
304
+ input: {
305
+ userId: string;
306
+ roles: string[];
307
+ };
308
+ operationId: "roles_revoke";
309
+ } | {
310
+ input: ExternalApplicationsCreateOrGetAppUserData["body"];
311
+ operationId: "users_create_or_get";
312
+ } | {
177
313
  input: JsonObject | unknown[];
178
314
  operationId: "context_get";
179
315
  } | {
@@ -375,7 +511,15 @@ export interface EnvelopeSuccess<Id extends string, Result> {
375
511
  operationId: Id;
376
512
  result: Result;
377
513
  }
378
- export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get", JsonObject> | EnvelopeSuccess<"knowledge_query", JsonObject> | EnvelopeSuccess<"knowledge_get_entity_schema_snapshot", JsonObject> | EnvelopeSuccess<"knowledge_search_entities", JsonObject> | EnvelopeSuccess<"knowledge_facets", JsonObject> | EnvelopeSuccess<"knowledge_get_schema_query_context", JsonObject> | EnvelopeSuccess<"knowledge_autocomplete", JsonObject> | EnvelopeSuccess<"knowledge_get_entity", JsonObject> | EnvelopeSuccess<"knowledge_create_entity", JsonObject> | EnvelopeSuccess<"knowledge_update_entity", JsonObject> | EnvelopeSuccess<"knowledge_upsert_entity", JsonObject> | EnvelopeSuccess<"knowledge_delete_entity", JsonObject> | EnvelopeSuccess<"knowledge_traverse", JsonObject> | EnvelopeSuccess<"knowledge_create_relation", JsonObject> | EnvelopeSuccess<"knowledge_update_relation", JsonObject> | EnvelopeSuccess<"knowledge_delete_relation", JsonObject> | EnvelopeSuccess<"agents_list", JsonObject> | EnvelopeSuccess<"agents_invoke", {
514
+ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"users_get", ApplicationUser> | EnvelopeSuccess<"users_list", ApplicationUserPage> | EnvelopeSuccess<"users_deactivate", {
515
+ userId: string;
516
+ }> | EnvelopeSuccess<"roles_list", {
517
+ items: ApplicationRole[];
518
+ }> | EnvelopeSuccess<"roles_assign", {
519
+ userId: string;
520
+ }> | EnvelopeSuccess<"roles_revoke", {
521
+ userId: string;
522
+ }> | EnvelopeSuccess<"users_create_or_get", ApplicationUserResolution> | EnvelopeSuccess<"context_get", JsonObject> | EnvelopeSuccess<"knowledge_query", JsonObject> | EnvelopeSuccess<"knowledge_get_entity_schema_snapshot", JsonObject> | EnvelopeSuccess<"knowledge_search_entities", JsonObject> | EnvelopeSuccess<"knowledge_facets", JsonObject> | EnvelopeSuccess<"knowledge_get_schema_query_context", JsonObject> | EnvelopeSuccess<"knowledge_autocomplete", JsonObject> | EnvelopeSuccess<"knowledge_get_entity", JsonObject> | EnvelopeSuccess<"knowledge_create_entity", JsonObject> | EnvelopeSuccess<"knowledge_update_entity", JsonObject> | EnvelopeSuccess<"knowledge_upsert_entity", JsonObject> | EnvelopeSuccess<"knowledge_delete_entity", JsonObject> | EnvelopeSuccess<"knowledge_traverse", JsonObject> | EnvelopeSuccess<"knowledge_create_relation", JsonObject> | EnvelopeSuccess<"knowledge_update_relation", JsonObject> | EnvelopeSuccess<"knowledge_delete_relation", JsonObject> | EnvelopeSuccess<"agents_list", JsonObject> | EnvelopeSuccess<"agents_invoke", {
379
523
  runId: string;
380
524
  }> | EnvelopeSuccess<"skills_list", JsonObject> | EnvelopeSuccess<"skills_invoke", {
381
525
  runId: string;
@@ -393,28 +537,11 @@ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get",
393
537
  conversationId: string;
394
538
  runId: string;
395
539
  }> | EnvelopeSuccess<"conversations_history", ConversationHistory>;
396
- /**
397
- * Operations only the confidential application itself may invoke. They stay
398
- * out of `externalApplicationOperationIds`, so browser clients and the user
399
- * proxy never offer them.
400
- */
401
- /** A person whose only role in the application's Organization is `member`. */
402
- interface MemberUser {
403
- email: string | null;
404
- name: string | null;
405
- userId: string;
406
- }
407
- /**
408
- * How create-or-get resolved the email: a new user, an existing CI user who
409
- * joined the Organization as a member, or a user who already was one.
410
- */
411
- type MemberUserResolution = "created" | "existing" | "linked";
412
- interface MemberUserPage {
413
- items: MemberUser[];
414
- page: number;
415
- pageSize: number;
416
- totalItems: number;
417
- }
540
+ /** User details returned by the application's user-management gateway. */
541
+ type ApplicationUser = ExternalApplicationsGetAppUserResponse["result"];
542
+ type ApplicationUserResolution = ExternalApplicationsCreateOrGetAppUserResponse["result"];
543
+ type ApplicationUserPage = ExternalApplicationsListAppUsersResponse["result"];
544
+ type ApplicationRole = ExternalApplicationsListAppRolesResponse["result"]["items"][number];
418
545
  declare const storageFileIdBrand: unique symbol;
419
546
  /** A durable private file of the application's Organization. */
420
547
  type StorageFileId = string & Readonly<{
@@ -435,32 +562,9 @@ export type ExternalApplicationServiceOperationRequest = {
435
562
  operationId: "files_upload";
436
563
  } | {
437
564
  input: {
438
- email: string;
439
- name: string;
565
+ origin: string;
440
566
  };
441
- operationId: "members_create_or_get";
442
- } | {
443
- input: {
444
- userId: string;
445
- };
446
- operationId: "members_get";
447
- } | {
448
- input: {
449
- page?: number;
450
- pageSize?: number;
451
- };
452
- operationId: "members_list";
453
- } | {
454
- input: {
455
- name: string;
456
- userId: string;
457
- };
458
- operationId: "members_update";
459
- } | {
460
- input: {
461
- userId: string;
462
- };
463
- operationId: "members_remove";
567
+ operationId: "origins_set_runtime";
464
568
  } | {
465
569
  input: {
466
570
  userId: string;
@@ -479,10 +583,8 @@ export interface UserCompanyLinks {
479
583
  }
480
584
  export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"files_upload", {
481
585
  storageFileId: StorageFileId;
482
- }> | EnvelopeSuccess<"members_create_or_get", MemberUser & {
483
- outcome: MemberUserResolution;
484
- }> | EnvelopeSuccess<"members_get", MemberUser> | EnvelopeSuccess<"members_list", MemberUserPage> | EnvelopeSuccess<"members_update", MemberUser> | EnvelopeSuccess<"members_remove", {
485
- userId: string;
586
+ }> | EnvelopeSuccess<"origins_set_runtime", {
587
+ origin: string;
486
588
  }> | EnvelopeSuccess<"users_list_company_links", UserCompanyLinks> | EnvelopeSuccess<"users_link_companies", UserCompanyLinks>;
487
589
  /** Every operation a confidential server client may invoke. */
488
590
  export type ExternalApplicationServerOperationRequest = ExternalApplicationOperationRequest | ExternalApplicationServiceOperationRequest;
@@ -652,6 +754,8 @@ export interface ServerInvocationContext {
652
754
  readonly callerKind?: "anonymous_visitor";
653
755
  readonly correlationId?: string;
654
756
  readonly organizationId: string;
757
+ /** Selects a Server Role for this call; omission uses the credential default. */
758
+ readonly serverRole?: string;
655
759
  readonly signal?: AbortSignal;
656
760
  readonly traceparent?: string;
657
761
  }
@@ -662,13 +766,52 @@ export type ManagedInput<Input> = Input extends {
662
766
  readonly idempotencyKey?: string;
663
767
  } : Input;
664
768
  export type ManagedOperationInput<Id extends ExternalApplicationServerOperationId> = ManagedInput<OperationInput<Id>>;
665
- export type ServerOperationRequest<Id extends ExternalApplicationServerOperationId> = ManagedOperationInput<Id> & ServerInvocationContext;
769
+ export type ServerOperationRequest<Id extends ExternalApplicationServerOperationId> = OperationInput<Id> extends Readonly<Record<string, never>> ? ServerInvocationContext : ManagedOperationInput<Id> & ServerInvocationContext;
666
770
  export type ServerOperationMethod<Id extends ExternalApplicationServerOperationId> = (request: ServerOperationRequest<Id>) => Promise<ExternalApplicationOperationResult<Id>>;
667
771
  /** One message to send; `idempotencyKey` is generated when omitted. */
668
772
  export type ServerMessageSendRequest = Omit<MessageSendInput, "idempotencyKey"> & Readonly<{
669
773
  idempotencyKey?: string;
670
774
  }> & ServerInvocationContext;
671
775
  export type ServerMessageSendMethod = (request: ServerMessageSendRequest) => Promise<MessageSendResult>;
776
+ /** A File upload slot for one File field of an entity schema, named by id or FQN. */
777
+ export type ServerResourceUploadRequest = EntityUploadInput & Readonly<{
778
+ schemaId: string;
779
+ /** Bound on each attempt's request and response body. Defaults to 10 seconds. */
780
+ timeoutMs?: number;
781
+ }> & ServerInvocationContext;
782
+ declare const resourceFailureCodes: readonly [
783
+ "conflict",
784
+ "forbidden",
785
+ "internal",
786
+ "invalid_request",
787
+ "not_found",
788
+ "unauthenticated",
789
+ "unavailable",
790
+ "upload_not_supported"
791
+ ];
792
+ /** Why CI's resources API refused the request. */
793
+ export type ServerResourceFailure = Readonly<{
794
+ correlationId: string;
795
+ error: Readonly<{
796
+ code: (typeof resourceFailureCodes)[number];
797
+ details?: Readonly<Record<string, ResourceJsonValue>>;
798
+ message: string;
799
+ retryable: boolean;
800
+ }>;
801
+ }>;
802
+ /** PUT the bytes to `result.url` with `result.headers`, then write `{ upload: uploadId }`. */
803
+ export type ServerResourceUploadResult = Readonly<{
804
+ error: ServerResourceFailure;
805
+ ok: false;
806
+ }> | Readonly<{
807
+ ok: true;
808
+ value: Readonly<{
809
+ correlationId: string;
810
+ operationId: "resources_create_upload";
811
+ result: EntityUploadSlot;
812
+ }>;
813
+ }>;
814
+ export type ServerResourceUploadMethod = (request: ServerResourceUploadRequest) => Promise<ServerResourceUploadResult>;
672
815
  export type RunOperationId = "runs_cancel" | "runs_get" | "runs_stream";
673
816
  export type ServerRunStatus = "accepted" | "cancelled" | "failed" | "running" | "succeeded";
674
817
  /**
@@ -779,21 +922,6 @@ export interface ServerClient {
779
922
  updateRelation: ServerOperationMethod<"knowledge_update_relation">;
780
923
  upsertEntity: ServerOperationMethod<"knowledge_upsert_entity">;
781
924
  }>;
782
- /**
783
- * Member users of the application's Organization: people whose only role
784
- * there is `member`. Needs `members:read` (get, list) or `members:write`
785
- * (createOrGet, update, remove) and confidential credentials; a user with
786
- * any other role is refused. `createOrGet` resolves an email to the same
787
- * user on every call and never sends CI's activation invitation. `remove`
788
- * ends the membership and keeps the CI user.
789
- */
790
- readonly members: Readonly<{
791
- createOrGet: ServerOperationMethod<"members_create_or_get">;
792
- get: ServerOperationMethod<"members_get">;
793
- list: ServerOperationMethod<"members_list">;
794
- remove: ServerOperationMethod<"members_remove">;
795
- update: ServerOperationMethod<"members_update">;
796
- }>;
797
925
  /**
798
926
  * Sends one message through a messaging connection that an administrator
799
927
  * granted to the application. Needs the `messaging:send` scope. A repeat
@@ -803,6 +931,31 @@ export interface ServerClient {
803
931
  readonly messages: Readonly<{
804
932
  send: ServerMessageSendMethod;
805
933
  }>;
934
+ /**
935
+ * The application's browser origins in its Organization. `setRuntime({ origin })`
936
+ * replaces the application's one runtime origin, such as the URL of the
937
+ * current deployment, beside the `allowedOrigins` its package declares.
938
+ * Needs the `origins:write` scope and confidential credentials.
939
+ */
940
+ readonly origins: Readonly<{
941
+ setRuntime: ServerOperationMethod<"origins_set_runtime">;
942
+ }>;
943
+ /**
944
+ * CI's resources API. `createUpload` asks a single-use File upload slot for
945
+ * one File field of an entity schema; the entity write then names its
946
+ * `uploadId` as `{ upload }`. Slots follow entity writes: the member's
947
+ * delegated token writes as that member; the service credential writes as
948
+ * the Organization default service principal, only on schemas its own
949
+ * package declares.
950
+ */
951
+ readonly resources: Readonly<{
952
+ createUpload: ServerResourceUploadMethod;
953
+ }>;
954
+ readonly roles: Readonly<{
955
+ assign: ServerOperationMethod<"roles_assign">;
956
+ list: ServerOperationMethod<"roles_list">;
957
+ revoke: ServerOperationMethod<"roles_revoke">;
958
+ }>;
806
959
  readonly runs: Readonly<{
807
960
  cancel: ServerRunOperationMethod<"runs_cancel", ServerRun>;
808
961
  get: ServerRunOperationMethod<"runs_get", ServerRun>;
@@ -813,12 +966,17 @@ export interface ServerClient {
813
966
  list: ServerOperationMethod<"skills_list">;
814
967
  }>;
815
968
  /**
816
- * Organization members' links to the company entities they act for.
817
- * Confidential service credentials only; the Organization is the caller's.
969
+ * Application users and their role-bounded lifecycle. User tokens and service
970
+ * credentials are authorized by CI on each call. Company-link operations
971
+ * remain limited to service credentials and Organization members.
818
972
  */
819
973
  readonly users: Readonly<{
974
+ createOrGet: ServerOperationMethod<"users_create_or_get">;
975
+ deactivate: ServerOperationMethod<"users_deactivate">;
976
+ get: ServerOperationMethod<"users_get">;
820
977
  /** Links `userId` to `entityIds`, keeping existing links; returns all of them. */
821
978
  linkCompanies: ServerOperationMethod<"users_link_companies">;
979
+ list: ServerOperationMethod<"users_list">;
822
980
  listCompanyLinks: ServerOperationMethod<"users_list_company_links">;
823
981
  }>;
824
982
  readonly workflows: Readonly<{
@@ -885,11 +1043,12 @@ export declare const exchangeMemberSession: (request: MemberSessionExchangeReque
885
1043
  export declare const uuidV7: () => string;
886
1044
 
887
1045
  export {
1046
+ ApplicationRole as ServerApplicationRole,
1047
+ ApplicationUser as ServerApplicationUser,
1048
+ ApplicationUserPage as ServerApplicationUserPage,
1049
+ ApplicationUserResolution as ServerApplicationUserResolution,
888
1050
  DurableFileUpload as ServerDurableFileUpload,
889
1051
  MemberSessionExchangeError$1 as MemberSessionExchangeError,
890
- MemberUser as ServerMemberUser,
891
- MemberUserPage as ServerMemberUserPage,
892
- MemberUserResolution as ServerMemberUserResolution,
893
1052
  MessageContent as ServerMessageContent,
894
1053
  MessageReceipt as ServerMessageReceipt,
895
1054
  MessageSendErrorCode as ServerMessageSendErrorCode,