@collective-intelligence/external-apps-client-sdk 0.3.8 → 0.4.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.
package/AGENTS.md CHANGED
@@ -39,3 +39,4 @@ package `README.md` holds the full API.
39
39
  ## Platform guide
40
40
 
41
41
  - [docs/guide/index.md](docs/guide/index.md): read before choosing CI primitives for a solution or demo, or when a task needs the platform model (architecture, access, data, AI, template).
42
+ - [docs/guide/platform/built-ins.md](docs/guide/platform/built-ins.md): read before declaring a tool, workflow node, trigger, connector, connection, schema or notification channel, to reuse the `builtin.` FQN that CI already ships and to check which built-in packages an Organization has installed.
package/README.md CHANGED
@@ -13,9 +13,11 @@ to the Server SDK.
13
13
 
14
14
  `createFederatedAuth` implements the public OAuth authorization-code flow with
15
15
  PKCE. It validates same-origin return targets, keeps the login transaction in
16
- session storage, exchanges the callback code, tracks token expiry, and supports
17
- logout and reauthorization. A server runtime remains responsible for any
18
- confidential proxy credentials and durable application sessions.
16
+ session storage, exchanges the callback code, tracks token expiry, renews the
17
+ Access token while the page stays open, and supports logout and
18
+ reauthorization. A server runtime remains responsible for any confidential
19
+ proxy credentials and durable application sessions. See
20
+ [Session renewal in the browser](#session-renewal-in-the-browser).
19
21
 
20
22
  `createClient` binds a typed transport to CI operations for agents, attachments,
21
23
  the chat, context, Knowledge, runs, skills, and workflows. Call
@@ -38,6 +40,51 @@ plus slack) before throwing `Run did not finish`; pass `deadlineMs` to change
38
40
  it and `signal` to cancel. Polling starts every `idleMs` (50 ms) and backs off
39
41
  to at most one second while no new events arrive.
40
42
 
43
+ ## Session renewal in the browser
44
+
45
+ The Access token of `createFederatedAuth` lasts 300 seconds. CI returns a
46
+ Renewal credential at sign-in. The SDK keeps it only in the memory of the tab,
47
+ never in browser storage. `getAccessToken()` renews the Access token while the
48
+ page stays open:
49
+
50
+ - A call in the last 30 seconds of the Access token, or after its expiry,
51
+ sends one renewal request; calls at the same time share it. There is no
52
+ timer: the renewal happens at the next call.
53
+ - Each renewal replaces the Renewal credential (Rotation). After it,
54
+ `expiresAt` of the state is the expiry of the new Access token.
55
+ - A reload, a new tab or a return to the application starts with no Renewal
56
+ credential. It uses Redirect renewal: `beginLogin` or `reauthorize` sends
57
+ the browser to CI, which returns a new code with no prompt while the CI
58
+ session is live.
59
+ - Each tab has its own sign-in. It ends 7 days after that sign-in, or with the
60
+ CI session if that is earlier.
61
+
62
+ When `getAccessToken()` fails, read `getState()` before you act. Branch on the
63
+ state, not on the error code alone:
64
+
65
+ | State | Error code | Cause | Action |
66
+ | --------------- | -------------------------- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
67
+ | `authenticated` | `renewal_unavailable` | CI did not answer the renewal: a network error, a timeout, a `5xx`, a `429` or an unreadable answer | Retry later. The session and its Renewal credential stay, also after the Access token expires. |
68
+ | `expired` | `reauthorization_required` | CI refused the renewal (any other `4xx`), or the session has no Renewal credential and expired | Keep unsaved state, then call `reauthorize`. It leaves the page. |
69
+ | `anonymous` | `reauthorization_required` | A logout in this tab or in another tab of the Application ended the session during the call | Show the signed-out view. Start a sign-in only when the user asks for it. |
70
+
71
+ Before it fails with `renewal_unavailable`, the SDK tries the renewal up to
72
+ three times, after waits of 250 ms and 1 s, with 8 s for each attempt. A `429`
73
+ fails at once, with no retry.
74
+
75
+ `logout()` signs out every tab of the Application in this browser. It first
76
+ sends a notice to the other tabs through a `BroadcastChannel`; they go to
77
+ `anonymous` and ignore renewal answers that arrive later. Then it calls CI,
78
+ which ends every Federated authorization of the Application in the CI session
79
+ of the user. A tab in `expired` logs out too, with its last Access token. The
80
+ call to CI is best effort: when CI cannot be reached, the SDK does not retry,
81
+ and the local state and the other tabs are still cleared. Where
82
+ `BroadcastChannel` is not available, no notice is sent.
83
+
84
+ An SDK version from before session renewal ignores the Renewal credential and
85
+ keeps the 300 second session against the same CI. The CI wire contract is in
86
+ [Access token renewal](../../../docs/architecture/external-app-gateway.md#access-token-renewal).
87
+
41
88
  ## Workflow results and read recovery
42
89
 
43
90
  A successful Workflow with a declared output contract exposes its persisted
package/dist/chat.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { x as ClientOperationMap } from "./proxy-DRPEFvaV.js";
2
- import { i as OrganizationClient } from "./client-_rl-iXS8.js";
1
+ import { x as ClientOperationMap } from "./proxy-BceN4mU3.js";
2
+ import { i as OrganizationClient } from "./client-DR9lGYcy.js";
3
3
  import { ChatTransport } from "@collective-intelligence/ai-core/chat";
4
4
  /** The organization client whose chat domain the transport calls. */
5
5
  type ChatTransportClient = Pick<OrganizationClient<ClientOperationMap>, "chat">;
package/dist/chat.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as CiTransportError } from "./errors-C3UmgGGu.js";
1
+ import { r as CiTransportError } from "./errors-B4-Jo4j3.js";
2
2
  import { AiFailureError } from "@collective-intelligence/ai-core";
3
3
  import * as Predicate from "effect/Predicate";
4
4
  import * as Schema from "effect/Schema";
@@ -1,4 +1,4 @@
1
- import { C as OperationExecutionOptions, D as CiError, P as CiResult, S as ClientOperationOutput, V as ExternalApplicationChatOperationId, b as ClientOperationInput, i as ClientFetch, k as CiTransportError, n as ProxyTransportOptions, w as TypedOperationExecutor, x as ClientOperationMap, y as ClientOperationId } from "./proxy-DRPEFvaV.js";
1
+ import { C as OperationExecutionOptions, D as CiError, P as CiResult, S as ClientOperationOutput, V as ExternalApplicationChatOperationId, b as ClientOperationInput, i as ClientFetch, k as CiTransportError, n as ProxyTransportOptions, w as TypedOperationExecutor, x as ClientOperationMap, y as ClientOperationId } from "./proxy-BceN4mU3.js";
2
2
  import "effect/Clock";
3
3
  import * as Config from "effect/Config";
4
4
  import * as Context from "effect/Context";
package/dist/effect.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as FederatedAuthError, D as CiError, O as CiErrorCode, d as FederatedAuthValue, f as layerFederated, h as layerServerSessionConfig, i as ClientFetch, j as FederatedAuthErrorCode, k as CiTransportError, m as layerServerSession, p as layerFederatedConfig, u as FederatedAuth } from "./proxy-DRPEFvaV.js";
2
- import { A as layerProxyConfig, C as CiClient, D as layerDirectConfig, E as layerDirect, O as layerFromExecutor, S as layer, T as ExecuteResult, _ as CiStreamPage$1, b as Chat, d as RunFollowOptions, f as Runs, k as layerProxy, m as layer$5, p as RunsValue, u as DEFAULT_FOLLOW_RUN_DEADLINE_MS, w as CiClientValue, x as ChatValue } from "./client-_rl-iXS8.js";
3
- import { C as RealtimeChange, T as RealtimeTopicFilter, f as DelegatedApplicationRuntimeOptions, p as DelegatedRuntimeState, w as RealtimeTopic } from "./index-DFCHAlar.js";
4
- import { _ as layerLegacy, a as LegacyResourceClient, c as LegacyResourcesValue, d as ResourcesFromEntityTransportOptions, f as ResourcesLayerOptions, g as layerFromEntityTransport, h as layerConfig$3, i as makeEntityHttpExecute, l as ResourceEntityClient, m as layer$4, o as LegacyResources, p as ResourcesValue, s as LegacyResourcesLayerOptions, u as Resources, v as layerLegacyConfig } from "./resources-r2t8pcv2.js";
1
+ import { A as FederatedAuthError, D as CiError, O as CiErrorCode, d as FederatedAuthValue, f as layerFederated, h as layerServerSessionConfig, i as ClientFetch, j as FederatedAuthErrorCode, k as CiTransportError, m as layerServerSession, p as layerFederatedConfig, u as FederatedAuth } from "./proxy-BceN4mU3.js";
2
+ import { A as layerProxyConfig, C as CiClient, D as layerDirectConfig, E as layerDirect, O as layerFromExecutor, S as layer, T as ExecuteResult, _ as CiStreamPage$1, b as Chat, d as RunFollowOptions, f as Runs, k as layerProxy, m as layer$5, p as RunsValue, u as DEFAULT_FOLLOW_RUN_DEADLINE_MS, w as CiClientValue, x as ChatValue } from "./client-DR9lGYcy.js";
3
+ import { C as RealtimeChange, T as RealtimeTopicFilter, f as DelegatedApplicationRuntimeOptions, p as DelegatedRuntimeState, w as RealtimeTopic } from "./index-_tusNazf.js";
4
+ import { _ as layerLegacy, a as LegacyResourceClient, c as LegacyResourcesValue, d as ResourcesFromEntityTransportOptions, f as ResourcesLayerOptions, g as layerFromEntityTransport, h as layerConfig$3, i as makeEntityHttpExecute, l as ResourceEntityClient, m as layer$4, o as LegacyResources, p as ResourcesValue, s as LegacyResourcesLayerOptions, u as Resources, v as layerLegacyConfig } from "./resources-DFkLnuj9.js";
5
5
  import * as Schema from "effect/Schema";
6
6
  import * as Config from "effect/Config";
7
7
  import * as Context from "effect/Context";
@@ -144,7 +144,7 @@ declare class DelegatedRuntime extends DelegatedRuntime_base {}
144
144
  * `FederatedAuth`, `CiClient` and `Runs`. A bad `authBasePath` fails with
145
145
  * `configuration_error`; a bad `origin` or `proxyPath` dies with `TypeError`.
146
146
  */
147
- declare const layer$1: (options: DelegatedApplicationRuntimeOptions) => Layer.Layer<CiClient | Runs | FederatedAuth | DelegatedRuntime, FederatedAuthError, never>;
147
+ declare const layer$1: (options: DelegatedApplicationRuntimeOptions) => Layer.Layer<Runs | CiClient | FederatedAuth | DelegatedRuntime, FederatedAuthError, never>;
148
148
  /** `layer` with options that Effect `Config` reads. */
149
- declare const layerConfig: (config: Config.Wrap<DelegatedApplicationRuntimeOptions>) => Layer.Layer<CiClient | Runs | FederatedAuth | DelegatedRuntime, Config.ConfigError | FederatedAuthError, never>;
149
+ declare const layerConfig: (config: Config.Wrap<DelegatedApplicationRuntimeOptions>) => Layer.Layer<Runs | CiClient | FederatedAuth | DelegatedRuntime, Config.ConfigError | FederatedAuthError, never>;
150
150
  export { Chat, type ChatValue, CiClient, type CiClientValue, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, type DelegatedRuntimeValue, type ExecuteResult, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, type FederatedAuthValue, type FixedWorkflowRequest, FixedWorkflows, type FixedWorkflowsLayerOptions, type FixedWorkflowsValue, type LegacyResourceClient, LegacyResources, type LegacyResourcesLayerOptions, type LegacyResourcesValue, type RealtimeChange, RealtimeClient, type RealtimeClientLayerOptions, type RealtimeResync, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeUpdate, type ResourceEntityClient, Resources, type ResourcesFromEntityTransportOptions, type ResourcesLayerOptions, type ResourcesValue, type RunFollowOptions, Runs, type RunsValue, layer as layerChat, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer$1 as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$2 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$3 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$4 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$5 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, makeEntityHttpExecute, subscribe };
package/dist/effect.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as FederatedAuthErrorCode, i as FederatedAuthError, n as CiErrorCode, r as CiTransportError, t as CiError } from "./errors-C3UmgGGu.js";
2
- import { a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$4, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-l8wUAlPK.js";
3
- import { A as subscribe, C as layerProxy, D as layer$3, E as RealtimeClient, O as layerConfig$2, S as layerFromExecutor, a as layer$2, b as layerDirect, c as layerFederated, d as layerServerSessionConfig, f as Chat, g as Runs, h as DEFAULT_FOLLOW_RUN_DEADLINE_MS, i as FixedWorkflows, l as layerFederatedConfig, n as layer$1, o as layerConfig$1, p as layer, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layer$5, w as layerProxyConfig, x as layerDirectConfig, y as CiClient } from "./service-D-POpqlt.js";
1
+ import { a as FederatedAuthErrorCode, i as FederatedAuthError, n as CiErrorCode, r as CiTransportError, t as CiError } from "./errors-B4-Jo4j3.js";
2
+ import { a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$4, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-CimYXTmK.js";
3
+ import { A as subscribe, C as layerProxy, D as layer$3, E as RealtimeClient, O as layerConfig$2, S as layerFromExecutor, a as layer$2, b as layerDirect, c as layerFederated, d as layerServerSessionConfig, f as Chat, g as Runs, h as DEFAULT_FOLLOW_RUN_DEADLINE_MS, i as FixedWorkflows, l as layerFederatedConfig, n as layer$1, o as layerConfig$1, p as layer, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layer$5, w as layerProxyConfig, x as layerDirectConfig, y as CiClient } from "./service-CREcfOem.js";
4
4
  import * as Schema from "effect/Schema";
5
5
  /**
6
6
  * The wire Schemas of the CI envelopes that `./effect` exports. The Type of
@@ -50,7 +50,11 @@ var errors_exports = /* @__PURE__ */ __exportAll({
50
50
  });
51
51
  /** Code of an Expected Error that CI returns for an operation. */
52
52
  const CiErrorCode = Schema.Literals(ciErrorCodes);
53
- /** Code of an Expected Error of the federated sign-in flow. */
53
+ /**
54
+ * Code of an Expected Error of the federated sign-in flow.
55
+ * `renewal_unavailable` is retryable: CI did not answer a renewal, the
56
+ * session stays authenticated, and the next call renews again.
57
+ */
54
58
  const FederatedAuthErrorCode = Schema.Literals([
55
59
  "configuration_error",
56
60
  "invalid_return_target",
@@ -59,7 +63,8 @@ const FederatedAuthErrorCode = Schema.Literals([
59
63
  "transaction_expired",
60
64
  "authorization_failed",
61
65
  "token_exchange_failed",
62
- "reauthorization_required"
66
+ "reauthorization_required",
67
+ "renewal_unavailable"
63
68
  ]);
64
69
  /** An Expected Error that CI returns for an operation. */
65
70
  var CiError = class extends Schema.TaggedError()("CiError", {