@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,5 +1,5 @@
1
- import { r as CiTransportError } from "./errors-B4-Jo4j3.js";
2
- import { l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-w6n_gspU.js";
1
+ import { r as CiTransportError } from "./errors-DRzZfurr.js";
2
+ import { l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-B0QOswoK.js";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Layer from "effect/Layer";
5
5
  import * as ManagedRuntime from "effect/ManagedRuntime";
@@ -1,2 +1,2 @@
1
- import { $ as ResourceDefinition, A as EntityFileFieldWrite, B as EntityRequest, C as EntityBatchInput, Ct as ResourceUpdateRequest, D as EntityClient, E as EntityBatchRefusedDetails, F as EntityOperation, G as EntityUploadSlot, H as EntityTransport, I as EntityOperationResult, J as ResourceCapabilities, K as IdempotencyKey, L as EntityPage, M as EntityFileWrite, N as EntityListQuery, O as EntityCreateInput, P as EntityMemberValue, Q as ResourceCursor, R as EntityProtocol, S as createResourceClient, St as ResourceTransportRequest, T as EntityBatchRefusal, U as EntityUpdateInput, V as EntityRestoreInput, W as EntityUploadInput, X as ResourceCreateInput, Y as ResourceClient, Z as ResourceCreateRequest, _t as ResourceRequestOptions, at as ResourceIdentityField, b as isEntityBatchRefusedError, bt as ResourceSort, ct as ResourceLifecycleRequest, dt as ResourceListResult, et as ResourceError, ft as ResourceMutationInput, gt as ResourceRecordId, ht as ResourceRecord, it as ResourceId, j as EntityFileValue, k as EntityDeleteInput, lt as ResourceListQuery, mt as ResourcePaginationMode, n as EntityHttpTransportOptions, nt as ResourceFilter, ot as ResourceJsonValue, pt as ResourcePagination, q as PortableResourceSchema, r as createEntityHttpTransport, rt as ResourceGetRequest, st as ResourceLifecycleInput, t as EntityHttpDestination, tt as ResourceErrorCode, ut as ResourceListRequest, vt as ResourceResult, w as EntityBatchOp, x as isEntityReadLimitError, xt as ResourceTransport, y as createEntityProtocol, yt as ResourceRevision, z as EntityReadLimitDetails } from "./resources-Du03G6Wo.js";
2
- export { type EntityBatchInput, type EntityBatchOp, type EntityBatchRefusal, type EntityBatchRefusedDetails, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type IdempotencyKey, type PortableResourceSchema, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
1
+ import { $ as ResourceDefinition, A as EntityFileFieldWrite, B as EntityRequest, C as EntityBatchInput, Ct as ResourceTransportRequest, D as EntityClient, E as EntityBatchRefusedDetails, F as EntityOperation, G as EntityUploadSlot, H as EntityTransport, I as EntityOperationResult, J as ResourceCapabilities, K as IdempotencyKey, L as EntityPage, M as EntityFileWrite, N as EntityListQuery, O as EntityCreateInput, P as EntityMemberValue, Q as ResourceCursor, R as EntityProtocol, S as createResourceClient, St as ResourceTransport, T as EntityBatchRefusal, U as EntityUpdateInput, V as EntityRestoreInput, W as EntityUploadInput, X as ResourceCreateInput, Y as ResourceClient, Z as ResourceCreateRequest, _t as ResourceRecordId, at as ResourceIdentityField, b as isEntityBatchRefusedError, bt as ResourceRevision, ct as ResourceLifecycleRequest, dt as ResourceListResult, et as ResourceError, ft as ResourceMutationInput, gt as ResourceRecordAccess, ht as ResourceRecord, it as ResourceId, j as EntityFileValue, k as EntityDeleteInput, lt as ResourceListQuery, mt as ResourcePaginationMode, n as EntityHttpTransportOptions, nt as ResourceFilter, ot as ResourceJsonValue, pt as ResourcePagination, q as PortableResourceSchema, r as createEntityHttpTransport, rt as ResourceGetRequest, st as ResourceLifecycleInput, t as EntityHttpDestination, tt as ResourceErrorCode, ut as ResourceListRequest, vt as ResourceRequestOptions, w as EntityBatchOp, wt as ResourceUpdateRequest, x as isEntityReadLimitError, xt as ResourceSort, y as createEntityProtocol, yt as ResourceResult, z as EntityReadLimitDetails } from "./resources-D_PdfDpJ.js";
2
+ export { type EntityBatchInput, type EntityBatchOp, type EntityBatchRefusal, type EntityBatchRefusedDetails, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type IdempotencyKey, type PortableResourceSchema, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordAccess, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
package/dist/resources.js CHANGED
@@ -1,3 +1,3 @@
1
- import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-w6n_gspU.js";
2
- import { t as createResourceClient } from "./resources-DCOTahAB.js";
1
+ import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-B0QOswoK.js";
2
+ import { t as createResourceClient } from "./resources-Vd7ESXEA.js";
3
3
  export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
@@ -1,11 +1,11 @@
1
- import { c as __commonJSMin, l as __toESM, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-B4-Jo4j3.js";
2
- import * as Predicate from "effect/Predicate";
1
+ import { c as __commonJSMin, l as __toESM, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-DRzZfurr.js";
2
+ import * as Option from "effect/Option";
3
3
  import * as Schema from "effect/Schema";
4
+ import * as Predicate from "effect/Predicate";
4
5
  import * as Config from "effect/Config";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Effect from "effect/Effect";
7
8
  import * as Layer from "effect/Layer";
8
- import * as Option from "effect/Option";
9
9
  import * as ManagedRuntime from "effect/ManagedRuntime";
10
10
  const emptyBlock = () => ({
11
11
  comment: false,
@@ -134,7 +134,12 @@ const externalApplicationOperationIds = completeOperationRegistry([
134
134
  "attachments_upload",
135
135
  "attachments_download_url",
136
136
  "conversations_continue",
137
- "conversations_history"
137
+ "conversations_history",
138
+ "intents_list",
139
+ "intents_dispatch",
140
+ "intents_get",
141
+ "intents_wait",
142
+ "access_check"
138
143
  ]);
139
144
  /** Runtime counterpart of `ExternalApplicationChatOperationId`. */
140
145
  const externalApplicationChatOperationIds = completeChatOperationRegistry([
@@ -358,6 +363,35 @@ const runCall = (operationId, record) => {
358
363
  default: return null;
359
364
  }
360
365
  };
366
+ /**
367
+ * The Intent routes. A dispatch sends its idempotency key as a header and
368
+ * the rest of its input as the body; a read or a wait names the handle.
369
+ */
370
+ const intentCall = (operationId, record) => {
371
+ if (operationId === "intents_list") return {
372
+ method: "GET",
373
+ parse: "json",
374
+ pathname: "/intents"
375
+ };
376
+ if (operationId === "intents_dispatch") {
377
+ const { idempotencyKey, ...body } = record;
378
+ return typeof idempotencyKey === "string" && idempotencyKey.length > 0 ? {
379
+ body,
380
+ idempotencyKey,
381
+ method: "POST",
382
+ parse: "json",
383
+ pathname: "/intents/dispatches"
384
+ } : null;
385
+ }
386
+ const handle = textField(record, "handle");
387
+ if (handle === void 0) return null;
388
+ const pathname = `/intents/dispatches/${encodeURIComponent(handle)}`;
389
+ return {
390
+ method: "GET",
391
+ parse: "json",
392
+ pathname: operationId === "intents_wait" ? `${pathname}/wait` : pathname
393
+ };
394
+ };
361
395
  /** The External App chat route of each `chat_*` operation; `path` is checked against the generated route. */
362
396
  const chatRoutes = {
363
397
  chat_agent_conversations_cancel_turn: {
@@ -668,6 +702,12 @@ const dedicatedHttpCall = (operationId, input) => {
668
702
  parse: "json",
669
703
  pathname: "/context"
670
704
  };
705
+ case "access_check": return {
706
+ body: input,
707
+ method: "POST",
708
+ parse: "json",
709
+ pathname: "/access/check"
710
+ };
671
711
  case "knowledge_query":
672
712
  case "knowledge_get_entity_schema_snapshot":
673
713
  case "knowledge_get_schema_query_context":
@@ -690,6 +730,10 @@ const dedicatedHttpCall = (operationId, input) => {
690
730
  case "runs_cancel":
691
731
  case "attachments_upload":
692
732
  case "attachments_download_url": return runCall(operationId, record);
733
+ case "intents_list":
734
+ case "intents_dispatch":
735
+ case "intents_get":
736
+ case "intents_wait": return intentCall(operationId, record);
693
737
  default: return null;
694
738
  }
695
739
  };
@@ -8592,6 +8636,13 @@ const createEntityProtocol = (definition) => {
8592
8636
  ]
8593
8637
  });
8594
8638
  const record = objectSchema({
8639
+ access: objectSchema({
8640
+ writableFields: {
8641
+ items: { type: "string" },
8642
+ type: "array"
8643
+ },
8644
+ write: { type: "boolean" }
8645
+ }),
8595
8646
  deletedAt: {
8596
8647
  pattern: "^\\d{4}-\\d{2}-\\d{2}T",
8597
8648
  type: "string"
@@ -8912,7 +8963,10 @@ const makeEntityHttpExecute = (options) => {
8912
8963
  "content-type": "application/json",
8913
8964
  "x-correlation-id": request.requestId
8914
8965
  });
8915
- if (destination.kind === "ci") headers.set("x-organization-id", destination.organizationId);
8966
+ if (destination.kind === "ci") {
8967
+ headers.set("x-organization-id", destination.organizationId);
8968
+ headers.set("x-ci-record-access", "1");
8969
+ }
8916
8970
  if (authentication.mode === "federated") {
8917
8971
  const token = yield* Effect.tryPromise(() => Promise.resolve(authentication.auth.getAccessToken())).pipe(Effect.map((value) => ({ value })), Effect.orElseSucceed(() => null));
8918
8972
  if (token === null) return failure$1(request, {
@@ -1,7 +1,7 @@
1
- import { i as FederatedAuthError, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-B4-Jo4j3.js";
2
- import { E as retryAfterMilliseconds, S as fromCiResult, T as createFetchEventSourceFactory, _ as backendErrorCode, b as proxyHttpOptions, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-w6n_gspU.js";
3
- import * as Predicate from "effect/Predicate";
1
+ import { i as FederatedAuthError, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-DRzZfurr.js";
2
+ import { E as retryAfterMilliseconds, S as fromCiResult, T as createFetchEventSourceFactory, _ as backendErrorCode, b as proxyHttpOptions, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-B0QOswoK.js";
4
3
  import * as Schema from "effect/Schema";
4
+ import * as Predicate from "effect/Predicate";
5
5
  import * as Arr from "effect/Array";
6
6
  import * as Cause from "effect/Cause";
7
7
  import * as Clock from "effect/Clock";
@@ -27,6 +27,7 @@ import * as Stream from "effect/Stream";
27
27
  import * as Deferred from "effect/Deferred";
28
28
  import * as Equal from "effect/Equal";
29
29
  import * as Data from "effect/Data";
30
+ import * as Semaphore from "effect/Semaphore";
30
31
  import * as Exit from "effect/Exit";
31
32
  const topicSetDebounceMilliseconds = 300;
32
33
  const pingTimeoutMilliseconds = 45e3;
@@ -1100,6 +1101,102 @@ const toPublicState = (session) => matchSession(session, {
1100
1101
  }),
1101
1102
  Redirecting: () => ({ status: "redirecting" })
1102
1103
  });
1104
+ /**
1105
+ * Embedded Sign-In on the session of a sealed-cookie BFF (ARC-017): the
1106
+ * headless `auth.signIn` steps over the sign-in routes of the server SDK at
1107
+ * `<basePath>/sign-in/*`. Each call gives one `SignInStep` (Q85). It fails
1108
+ * only when it gets no step, with `CiTransportError`: a network error, or an
1109
+ * answer that is not a step with HTTP 200, such as `409 login_conflict` or
1110
+ * `503 user_auth_unavailable`. The calls of one client run one at a time, so
1111
+ * the Sign-In Challenge of the browser gets one request at a time (AC-221).
1112
+ */
1113
+ const SsoProvider = Schema.Struct({
1114
+ displayName: Schema.String,
1115
+ id: Schema.String
1116
+ });
1117
+ /** A sign-in step, as a sign-in route answers it with HTTP 200. */
1118
+ const SignInStep = Schema.Union([
1119
+ Schema.Struct({
1120
+ emailCode: Schema.Boolean,
1121
+ password: Schema.Boolean,
1122
+ registrationOpen: Schema.Boolean,
1123
+ ssoProviders: Schema.Array(SsoProvider),
1124
+ step: Schema.Literal("methods")
1125
+ }),
1126
+ Schema.Struct({
1127
+ attemptsLeft: Schema.Int,
1128
+ step: Schema.Literal("invalid_code")
1129
+ }),
1130
+ Schema.Struct({
1131
+ allowedDomains: Schema.Array(Schema.String),
1132
+ step: Schema.Literal("email_domain_not_allowed")
1133
+ }),
1134
+ Schema.Struct({
1135
+ provider: SsoProvider,
1136
+ step: Schema.Literal("sso_required")
1137
+ }),
1138
+ Schema.Struct({
1139
+ registered: Schema.Boolean,
1140
+ step: Schema.Literal("signed_in")
1141
+ }),
1142
+ Schema.Struct({
1143
+ seconds: Schema.Int,
1144
+ step: Schema.Literal("retry_after")
1145
+ }),
1146
+ Schema.Struct({ step: Schema.Literals([
1147
+ "access_denied",
1148
+ "code_expired",
1149
+ "code_sent",
1150
+ "no_sign_in_method",
1151
+ "redirect_to_web",
1152
+ "registration_required"
1153
+ ]) })
1154
+ ]);
1155
+ /** `auth.signIn` of a sealed-cookie BFF session; `layerServerSessionAuth` provides it. */
1156
+ var SignIn = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/SignIn") {};
1157
+ /** The JSON text of a request body; the bodies are records of strings. */
1158
+ const encodeJsonText$1 = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
1159
+ const decodeStep = Schema.decodeUnknownEffect(SignInStep);
1160
+ const fault = (cause) => new CiTransportError({ cause });
1161
+ const redirectToWeb = { step: "redirect_to_web" };
1162
+ /** The step of an answer; any other answer is a fault. */
1163
+ const stepOf = (response) => response.status === 200 ? Effect.tryPromise({
1164
+ catch: fault,
1165
+ try: () => response.json()
1166
+ }).pipe(Effect.flatMap((body) => decodeStep(body).pipe(Effect.mapError(fault)))) : Effect.fail(fault(/* @__PURE__ */ new Error(`The sign-in route answered HTTP ${response.status}`)));
1167
+ const makeSignIn = Effect.fnUntraced(function* makeSignIn(session) {
1168
+ const oneAtATime = (yield* Semaphore.make(1)).withPermits(1);
1169
+ const { fetch } = session;
1170
+ /** One step of the challenge: a POST of the JSON `body` to the route. */
1171
+ const send = (route, { returnTo = "/", ...body }) => Effect.gen(function* sendStep() {
1172
+ const started = session.epoch();
1173
+ const text = yield* encodeJsonText$1(body).pipe(Effect.orDie);
1174
+ const response = yield* Effect.tryPromise({
1175
+ catch: fault,
1176
+ try: (signal) => fetch(session.url(`/sign-in/${route}`), {
1177
+ body: text,
1178
+ credentials: "same-origin",
1179
+ headers: { "content-type": "application/json" },
1180
+ method: "POST",
1181
+ signal
1182
+ })
1183
+ });
1184
+ const step = yield* stepOf(response);
1185
+ if (step.step === "signed_in") yield* session.readSession(started);
1186
+ if (step.step === "redirect_to_web") yield* session.beginLogin({ returnTo });
1187
+ return step;
1188
+ }).pipe(oneAtATime);
1189
+ return SignIn.of({
1190
+ complete: Effect.fn("SignIn.complete")((input) => send("complete", input)),
1191
+ methods: Effect.fn("SignIn.methods")((input) => send("methods", input ?? {})),
1192
+ sso: Effect.fn("SignIn.sso")(({ provider, returnTo = "/" }) => session.redirect(session.url(`/sign-in/sso?${new URLSearchParams({
1193
+ provider,
1194
+ returnTo
1195
+ })}`), returnTo), Effect.as(redirectToWeb), oneAtATime),
1196
+ start: Effect.fn("SignIn.start")((input) => send("start", input)),
1197
+ verify: Effect.fn("SignIn.verify")((input) => send("verify", input))
1198
+ });
1199
+ });
1103
1200
  var FederatedAuth = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/FederatedAuth") {};
1104
1201
  const configurationError = (message) => new FederatedAuthError("configuration_error", message);
1105
1202
  const transportError = (cause) => new CiTransportError({ cause });
@@ -1556,8 +1653,11 @@ const makeServerSession = Effect.fnUntraced(function* makeServerSession(options)
1556
1653
  const { changes, dispatch, epoch, getState, subscribe } = makeState();
1557
1654
  const completion = makeCompletion();
1558
1655
  let rememberedReturnTo;
1559
- const refresh = Effect.fnUntraced(function* refresh() {
1560
- const started = epoch();
1656
+ /**
1657
+ * Reads the session of the BFF and settles it under `started`. A logout
1658
+ * increments the epoch, so a read that ends after it changes nothing.
1659
+ */
1660
+ const readSession = Effect.fnUntraced(function* readSession(started) {
1561
1661
  const settle = (session) => {
1562
1662
  dispatch(Settled({
1563
1663
  epoch: started,
@@ -1599,17 +1699,26 @@ const makeServerSession = Effect.fnUntraced(function* makeServerSession(options)
1599
1699
  renewAt: expiresAt
1600
1700
  }));
1601
1701
  });
1602
- const beginLogin = ({ returnTo }) => Effect.suspend(() => {
1702
+ /** A sign-in on a page: the browser leaves for `url`, then returns to `returnTo`. */
1703
+ const redirect = (url, returnTo) => Effect.suspend(() => {
1603
1704
  rememberedReturnTo = returnTo;
1604
- const url = `${origin}${basePath}/login?returnTo=${encodeURIComponent(returnTo)}`;
1605
1705
  completion.reset();
1606
1706
  dispatch(LoginStarted());
1607
1707
  return Effect.as(navigate(url), url);
1608
1708
  });
1609
- return FederatedAuth.of({
1709
+ const beginLogin = ({ returnTo }) => redirect(`${origin}${basePath}/login?returnTo=${encodeURIComponent(returnTo)}`, returnTo);
1710
+ const signIn = yield* makeSignIn({
1711
+ beginLogin,
1712
+ epoch,
1713
+ fetch,
1714
+ readSession,
1715
+ redirect,
1716
+ url: (path) => `${origin}${basePath}${path}`
1717
+ });
1718
+ const auth = FederatedAuth.of({
1610
1719
  beginLogin,
1611
1720
  changes,
1612
- completeLogin: () => completion.run(Effect.flatMap(refresh(), () => {
1721
+ completeLogin: () => completion.run(Effect.flatMap(Effect.suspend(() => readSession(epoch())), () => {
1613
1722
  const state = getState();
1614
1723
  return state.status === "error" ? Effect.fail(state.error) : Effect.succeed({ returnTo: rememberedReturnTo ?? "/" });
1615
1724
  })),
@@ -1630,11 +1739,15 @@ const makeServerSession = Effect.fnUntraced(function* makeServerSession(options)
1630
1739
  }),
1631
1740
  subscribe
1632
1741
  });
1742
+ return Context.make(FederatedAuth, auth).pipe(Context.add(SignIn, signIn));
1633
1743
  });
1634
1744
  /** `FederatedAuth` of browser federated sign-in; a bad option fails with `configuration_error`. */
1635
1745
  const layerFederated = (options) => Layer.effect(FederatedAuth, makeFederated(options));
1636
- /** `FederatedAuth` of a sealed-cookie BFF session; a bad option fails with `configuration_error`. */
1637
- const layerServerSession = (options) => Layer.effect(FederatedAuth, makeServerSession(options));
1746
+ /**
1747
+ * `FederatedAuth` and `SignIn` of a sealed-cookie BFF session, over one
1748
+ * Session; a bad option fails with `configuration_error`.
1749
+ */
1750
+ const layerServerSession = (options) => Layer.effectContext(makeServerSession(options));
1638
1751
  /** `layerFederated` with options that Effect `Config` reads. */
1639
1752
  const layerFederatedConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerFederated));
1640
1753
  /** `layerServerSession` with options that Effect `Config` reads. */
@@ -1883,4 +1996,4 @@ const layer = (options) => {
1883
1996
  };
1884
1997
  /** `layer` with options that Effect `Config` reads. */
1885
1998
  const layerConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layer));
1886
- export { subscribe as A, layerProxy as C, layer$4 as D, RealtimeClient as E, currentLink as F, layer$5 as M, layerFromFactory as N, layerConfig$2 as O, layerBrowser as P, layerFromExecutor as S, make$4 as T, followSource as _, layer$1 as a, layerDirect as b, layerFederated as c, layerServerSessionConfig as d, Chat as f, Runs as g, DEFAULT_FOLLOW_RUN_DEADLINE_MS as h, FixedWorkflows as i, realtimeTopicKey as j, makeConnection as k, layerFederatedConfig as l, mapChatOperations as m, layer as n, layerConfig$1 as o, layer$2 as p, layerConfig as r, FederatedAuth as s, DelegatedRuntime as t, layerServerSession as u, layer$3 as v, layerProxyConfig as w, layerDirectConfig as x, CiClient as y };
1999
+ export { makeConnection as A, layerFromExecutor as C, RealtimeClient as D, make$4 as E, layerBrowser as F, currentLink as I, realtimeTopicKey as M, layer$5 as N, layer$4 as O, layerFromFactory as P, layerDirectConfig as S, layerProxyConfig as T, Runs as _, layer$1 as a, CiClient as b, layerFederated as c, layerServerSessionConfig as d, SignIn as f, DEFAULT_FOLLOW_RUN_DEADLINE_MS as g, mapChatOperations as h, FixedWorkflows as i, subscribe as j, layerConfig$2 as k, layerFederatedConfig as l, layer$2 as m, layer as n, layerConfig$1 as o, Chat as p, layerConfig as r, FederatedAuth as s, DelegatedRuntime as t, layerServerSession as u, followSource as v, layerProxy as w, layerDirect as x, layer$3 as y };
package/docs/chat.md CHANGED
@@ -47,3 +47,21 @@ const transport = createChatTransport(client.forOrganization(organizationId))
47
47
  (retryable). An aborted call rejects with the reason of its signal.
48
48
  - `openPresentationStream` opens one connection. Follow a run with
49
49
  `followPresentation` of ai-core: it reconnects. Do not reconnect yourself.
50
+
51
+ ## Intents, the Access Check and the browser session store
52
+
53
+ - `createIntentTransport(org)` (`/chat`) is the `IntentTransport` over
54
+ `client.intents`; give it to `<AiProvider intents>`. `createAccessPort(org)`
55
+ is the `AccessCheckPort` over `client.access`; give it as the `access` host
56
+ port. `createBrowserSessionStore()` is the `sessions` host port; it keeps
57
+ the pending Intent waits and the Assistant Sidebar state in
58
+ `sessionStorage`, so they survive a reload.
59
+ - Call `client.intents.dispatch` with one `idempotencyKey` for each user
60
+ action, and the same key only to retry it. Read the outcome `kind`:
61
+ `needs_input` and `not_allowed` are outcomes; `conflict` means the key was
62
+ used for another request.
63
+ - Read or wait with an Intent Handle only as the user who dispatched it; anyone
64
+ else gets `not_found`. `wait` repeats the bounded server wait until the run
65
+ ends.
66
+ - Send at most 200 targets in one `client.access.check`. Treat its answers as
67
+ display hints: CI checks every call.
package/docs/effect.md CHANGED
@@ -23,6 +23,7 @@ reads Effect `Config`.
23
23
  | `CiClient` | `layerCiClientDirect`, `layerCiClientProxy`, `layerCiClientFromExecutor`, `...Config` | `createClient`, `createDirectTransport`, `createProxyTransport` |
24
24
  | `Runs` | `layerRuns` (needs `CiClient`) | `followRun`, `client.runs.follow` |
25
25
  | `FederatedAuth` | `layerFederatedAuth`, `layerServerSessionAuth`, `...Config` | `createFederatedAuth`, `createServerSessionAuth` |
26
+ | `SignIn` | `layerServerSessionAuth`, `...Config` (with `FederatedAuth`) | `createServerSessionAuth().signIn` |
26
27
  | `FixedWorkflows` | `layerFixedWorkflows`, `layerFixedWorkflowsConfig` | `createFixedWorkflowClient` |
27
28
  | `DelegatedRuntime` | `layerDelegatedRuntime`, `layerDelegatedRuntimeConfig` | `createDelegatedApplicationRuntime` |
28
29
  | `Resources` | `layerResources`, `layerResourcesConfig`, `layerResourcesFromEntityTransport` | `createResourceClient` (`protocol: "entity"`), `createEntityHttpTransport` |
@@ -31,6 +32,9 @@ reads Effect `Config`.
31
32
 
32
33
  - `CiClient.execute` puts the `CiError` of CI in the error channel;
33
34
  `executeResult` keeps the `CiResult` envelope with the correlation id.
35
+ - `SignIn` succeeds with a `SignInStep` for every sign-in outcome; it fails
36
+ only with `CiTransportError` (no step) or `FederatedAuthError`
37
+ `configuration_error` (no navigation).
34
38
  - A `...Config` layer takes `Config.Wrap` of the layer options: give each
35
39
  field as a `Config`, and a function field as `Config.succeed(fn)`.
36
40
 
package/docs/errors.md CHANGED
@@ -25,6 +25,11 @@ class extends `Error`, and `.` and `/effect` export the same class.
25
25
  `outcome` `rejected` for a read and `uncertain` for a write.
26
26
  - A run that does not finish before `deadlineMs` rejects with `CiError`
27
27
  `unavailable` (`retryable: true`).
28
+ - `createServerSessionAuth().signIn` resolves a `SignInStep` for every
29
+ sign-in outcome, also a refusal such as `invalid_code`: branch on `step`.
30
+ It rejects with `CiTransportError` only when it gets no step: a network
31
+ error, or a BFF answer other than a step with HTTP 200 (`cause` names the
32
+ status).
28
33
 
29
34
  ## `getAccessToken` failures
30
35
 
@@ -77,7 +77,9 @@ ci login <api-url> --organization <organization-id>
77
77
  ci whoami
78
78
  ```
79
79
 
80
- `ci login` asks you to approve the device in the Dashboard and stores a 30-day CLI Session in your user profile. `ci upgrade` updates a global install.
80
+ `ci login` asks you to approve the device in the Dashboard and stores a 30-day CLI Session in your user profile. `ci upgrade` updates a global install. For a pipeline, `ci login <api-url> --pipeline-token --name <name> --expires <date|never>` issues a Pipeline Token instead: store it as `CI_MANAGEMENT_TOKEN` and pass `--organization`.
81
+
82
+ The Backend declares the oldest `ci` version it supports. Before a command that calls the Backend, a released `ci` reads this minimum from the discovery document. If `ci` is older, the command stops with `CliVersionUnsupportedError` and tells you to run `ci upgrade`.
81
83
 
82
84
  > **Note:** `ci login` needs the API URL. It reads the tenant's discovery document at
83
85
  > `/.well-known/ci-configuration` and rejects a Dashboard URL as "not a CI API
@@ -209,11 +211,12 @@ The Connect Studio link that the Dashboard shows only tells the Studio desktop a
209
211
 
210
212
  #### Held by pipelines and scripts
211
213
 
212
- | Credential | Type | Lifetime or rotation | Used for |
213
- | ------------------------------------------- | ------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
214
- | API key | Opaque secret with the prefix `dpk_` | No expiry at creation; a rotation keeps the old secret 24 hours; a revocation ends both | Calls with a service principal's grants, cut to a Max Privileges template |
215
- | `CI_MANAGEMENT_TOKEN` | Environment variable with an API key or a session token | That of the token it holds | Unattended `ci` commands; an API key fixes the Organization |
216
- | Publisher credential (`CI_PUBLISHER_TOKEN`) | Opaque secret for one exact package name | Optional expiry; a revocation stops it at once | Publish and promote for that package only |
214
+ | Credential | Type | Lifetime or rotation | Used for |
215
+ | ------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
216
+ | Pipeline Token | Opaque secret with the prefix `cpt_`; a session of a technical account | The end chosen when it is issued, or never; the account or a Tenant Admin revokes it | Unattended `ci` commands and calls as that account, such as `ci deploy` |
217
+ | API key | Opaque secret with the prefix `dpk_` | No expiry at creation; a rotation keeps the old secret 24 hours; a revocation ends both | Calls with a service principal's grants, cut to a Max Privileges template |
218
+ | `CI_MANAGEMENT_TOKEN` | Environment variable with a Pipeline Token, an API key or a session token | That of the token it holds | Unattended `ci` commands; an API key fixes the Organization |
219
+ | Publisher credential (`CI_PUBLISHER_TOKEN`) | Opaque secret for one exact package name | Optional expiry; a revocation stops it at once | Publish and promote for that package only |
217
220
 
218
221
  #### Held by your external app
219
222
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Framework-neutral client for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -62,7 +62,7 @@
62
62
  "ajv-formats": "3.0.1"
63
63
  },
64
64
  "peerDependencies": {
65
- "@collective-intelligence/ai-core": "0.5.0",
65
+ "@collective-intelligence/ai-core": "0.6.0",
66
66
  "effect": "^4.1.0"
67
67
  },
68
68
  "peerDependenciesMeta": {
@@ -71,7 +71,7 @@
71
71
  }
72
72
  },
73
73
  "devDependencies": {
74
- "@collective-intelligence/ai-core": "0.5.0",
74
+ "@collective-intelligence/ai-core": "0.6.0",
75
75
  "@effect/eslint-plugin": "0.3.2",
76
76
  "@effect/vitest": "4.1.4",
77
77
  "@oxlint/plugins": "1.94.0",
@@ -88,5 +88,5 @@
88
88
  "ultracite": "7.10.7",
89
89
  "vitest": "5.0.2"
90
90
  },
91
- "gitHead": "a8245252c396252c381dafd86a4fcb31af310906"
91
+ "gitHead": "94535cc59ece904d4a9374a368edb09222688bb6"
92
92
  }