@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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as FederatedAuthError, C as OperationExecutionOptions, E as isClientOperationId, F as JsonValue, G as SearchQuery, H as JsonObject, I as OperationRequest, K as WorkflowInvokeTarget, L as OperationSuccess, N as CiErrorCode, P as CiResult, S as ClientOperationOutput, T as clientOperationIds, U as KnowledgeQuery, W as QueryFilter, _ as createServerSessionAuth, a as FederatedAuth, b as ClientOperationInput, c as FederatedSessionIdentity, g as ServerSessionAuthOptions, i as ClientFetch, j as FederatedAuthErrorCode, k as CiTransportError, l as createFederatedAuth, n as ProxyTransportOptions, o as FederatedAuthOptions, r as createProxyTransport, s as FederatedAuthState, t as ProxyAuthentication, v as ClientOperationDefinition, w as TypedOperationExecutor, x as ClientOperationMap, y as ClientOperationId } from "./proxy-DRPEFvaV.js";
2
- import { M as createDirectTransport, _ as CiStreamPage, a as clientSdkProtocolVersion, c as FollowRunSource, g as CiStreamEvent, h as CiRunCancellation, i as OrganizationClient, j as DirectTransportOptions, l as followRun, n as ClientSdkClient, o as createClient, r as ClientSdkEntrypoint, s as FollowRunOptions, t as ClientDomains, u as DEFAULT_FOLLOW_RUN_DEADLINE_MS, v as nextStreamCursor, y as ChatClient } from "./client-_rl-iXS8.js";
3
- import { C as RealtimeChange, E as realtimeTopicKey, S as RealtimeWindow, T as RealtimeTopicFilter, _ as RealtimeStreamEnd, a as RealtimeClientStatus, b as createFetchEventSourceFactory, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, f as DelegatedApplicationRuntimeOptions, g as RealtimeEventSourceFactory, h as RealtimeEventSource, i as RealtimeClientState, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as RealtimeStreamEvent, w as RealtimeTopic, x as RealtimeDocument, y as RealtimeStreamHandlers } from "./index-DFCHAlar.js";
4
- 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-r2t8pcv2.js";
1
+ import { A as FederatedAuthError, C as OperationExecutionOptions, E as isClientOperationId, F as JsonValue, G as SearchQuery, H as JsonObject, I as OperationRequest, K as WorkflowInvokeTarget, L as OperationSuccess, N as CiErrorCode, P as CiResult, S as ClientOperationOutput, T as clientOperationIds, U as KnowledgeQuery, W as QueryFilter, _ as createServerSessionAuth, a as FederatedAuth, b as ClientOperationInput, c as FederatedSessionIdentity, g as ServerSessionAuthOptions, i as ClientFetch, j as FederatedAuthErrorCode, k as CiTransportError, l as createFederatedAuth, n as ProxyTransportOptions, o as FederatedAuthOptions, r as createProxyTransport, s as FederatedAuthState, t as ProxyAuthentication, v as ClientOperationDefinition, w as TypedOperationExecutor, x as ClientOperationMap, y as ClientOperationId } from "./proxy-BceN4mU3.js";
2
+ import { M as createDirectTransport, _ as CiStreamPage, a as clientSdkProtocolVersion, c as FollowRunSource, g as CiStreamEvent, h as CiRunCancellation, i as OrganizationClient, j as DirectTransportOptions, l as followRun, n as ClientSdkClient, o as createClient, r as ClientSdkEntrypoint, s as FollowRunOptions, t as ClientDomains, u as DEFAULT_FOLLOW_RUN_DEADLINE_MS, v as nextStreamCursor, y as ChatClient } from "./client-DR9lGYcy.js";
3
+ import { C as RealtimeChange, E as realtimeTopicKey, S as RealtimeWindow, T as RealtimeTopicFilter, _ as RealtimeStreamEnd, a as RealtimeClientStatus, b as createFetchEventSourceFactory, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, f as DelegatedApplicationRuntimeOptions, g as RealtimeEventSourceFactory, h as RealtimeEventSource, i as RealtimeClientState, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as RealtimeStreamEvent, w as RealtimeTopic, x as RealtimeDocument, y as RealtimeStreamHandlers } from "./index-_tusNazf.js";
4
+ 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-DFkLnuj9.js";
5
5
  export { type ChatClient, CiError, type CiErrorCode, type CiResult, type CiRunCancellation, type CiStreamEvent, type CiStreamPage, CiTransportError, type ClientDomains, type ClientFetch, type ClientOperationDefinition, type ClientOperationId, type ClientOperationInput, type ClientOperationMap, type ClientOperationOutput, type ClientSdkClient, type ClientSdkEntrypoint, DEFAULT_FOLLOW_RUN_DEADLINE_MS, type DelegatedApplicationRuntime, type DelegatedApplicationRuntimeOptions, type DelegatedRuntimeState, type DirectTransportOptions, 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 FederatedAuth, FederatedAuthError, type FederatedAuthErrorCode, type FederatedAuthOptions, type FederatedAuthState, type FederatedSessionIdentity, type FixedWorkflowClient, type FixedWorkflowClientOptions, type FollowRunOptions, type FollowRunSource, type IdempotencyKey, type JsonObject, type JsonValue, type KnowledgeQuery, type OperationExecutionOptions, type OperationRequest, type OperationSuccess, type OrganizationClient, type PortableResourceSchema, type ProxyAuthentication, type ProxyTransportOptions, type QueryFilter, type RealtimeChange, type RealtimeClient, type RealtimeClientOptions, type RealtimeClientState, type RealtimeClientStatus, type RealtimeDocument, type RealtimeEventSource, type RealtimeEventSourceFactory, type RealtimeStreamEnd, type RealtimeStreamEvent, type RealtimeStreamHandlers, type RealtimeTimers, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeWindow, 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, type SearchQuery, type ServerSessionAuthOptions, type TypedOperationExecutor, type WorkflowInvokeTarget, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityBatchRefusedError, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { i as FederatedAuthError, o as errors_exports, r as CiTransportError } from "./errors-C3UmgGGu.js";
2
- import { C as isClientOperationId, T as createFetchEventSourceFactory, b as proxyHttpOptions, d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol, v as directHttpOptions, w as toCiResult, x as clientOperationIds, y as makeHttpExecute } from "./service-l8wUAlPK.js";
3
- import { F as currentLink, M as layer$3, N as layerFromFactory, P as layerBrowser, S as layerFromExecutor, T as make, _ as followSource, a as layer$2, c as layerFederated, g as Runs, h as DEFAULT_FOLLOW_RUN_DEADLINE_MS, i as FixedWorkflows, j as realtimeTopicKey, k as makeConnection, m as mapChatOperations, n as layer$1, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layer, y as CiClient } from "./service-D-POpqlt.js";
4
- import { t as createResourceClient } from "./resources-BZKqGxBT.js";
1
+ import { i as FederatedAuthError, o as errors_exports, r as CiTransportError } from "./errors-B4-Jo4j3.js";
2
+ import { C as isClientOperationId, T as createFetchEventSourceFactory, b as proxyHttpOptions, d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol, v as directHttpOptions, w as toCiResult, x as clientOperationIds, y as makeHttpExecute } from "./service-CimYXTmK.js";
3
+ import { F as currentLink, M as layer$3, N as layerFromFactory, P as layerBrowser, S as layerFromExecutor, T as make, _ as followSource, a as layer$2, c as layerFederated, g as Runs, h as DEFAULT_FOLLOW_RUN_DEADLINE_MS, i as FixedWorkflows, j as realtimeTopicKey, k as makeConnection, m as mapChatOperations, n as layer$1, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layer, y as CiClient } from "./service-CREcfOem.js";
4
+ import { t as createResourceClient } from "./resources-BiYIVzGa.js";
5
5
  import * as Schema from "effect/Schema";
6
6
  import * as Clock from "effect/Clock";
7
7
  import * as Context from "effect/Context";
@@ -2652,8 +2652,12 @@ type OperationSuccess<Id extends ClientOperationId> = Id extends ExternalApplica
2652
2652
  /** Code of an Expected Error that CI returns for an operation. */
2653
2653
  declare const CiErrorCode: Schema.Literals<readonly ["unauthenticated", "forbidden", "not_found", "conflict", "invalid_request", "rate_limited", "unavailable", "internal"]>;
2654
2654
  type CiErrorCode = typeof CiErrorCode.Type;
2655
- /** Code of an Expected Error of the federated sign-in flow. */
2656
- declare const FederatedAuthErrorCode: Schema.Literals<readonly ["configuration_error", "invalid_return_target", "invalid_callback", "invalid_state", "transaction_expired", "authorization_failed", "token_exchange_failed", "reauthorization_required"]>;
2655
+ /**
2656
+ * Code of an Expected Error of the federated sign-in flow.
2657
+ * `renewal_unavailable` is retryable: CI did not answer a renewal, the
2658
+ * session stays authenticated, and the next call renews again.
2659
+ */
2660
+ declare const FederatedAuthErrorCode: Schema.Literals<readonly ["configuration_error", "invalid_return_target", "invalid_callback", "invalid_state", "transaction_expired", "authorization_failed", "token_exchange_failed", "reauthorization_required", "renewal_unavailable"]>;
2657
2661
  type FederatedAuthErrorCode = typeof FederatedAuthErrorCode.Type;
2658
2662
  declare const CiError_base: Schema.Class<CiError, Schema.TaggedStruct<"CiError", {
2659
2663
  readonly code: Schema.Literals<readonly ["unauthenticated", "forbidden", "not_found", "conflict", "invalid_request", "rate_limited", "unavailable", "internal"]>;
@@ -2668,7 +2672,7 @@ type FederatedAuthErrorFields = Readonly<{
2668
2672
  message: string;
2669
2673
  }>;
2670
2674
  declare const FederatedAuthError_base: Schema.Class<FederatedAuthError, Schema.TaggedStruct<"FederatedAuthError", {
2671
- readonly code: Schema.Literals<readonly ["configuration_error", "invalid_return_target", "invalid_callback", "invalid_state", "transaction_expired", "authorization_failed", "token_exchange_failed", "reauthorization_required"]>;
2675
+ readonly code: Schema.Literals<readonly ["configuration_error", "invalid_return_target", "invalid_callback", "invalid_state", "transaction_expired", "authorization_failed", "token_exchange_failed", "reauthorization_required", "renewal_unavailable"]>;
2672
2676
  readonly message: Schema.String;
2673
2677
  }>, import("effect/Cause").YieldableError>;
2674
2678
  /** An Expected Error of the federated sign-in flow. */
@@ -1,5 +1,5 @@
1
- import { r as CiTransportError } from "./errors-C3UmgGGu.js";
2
- import { l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-l8wUAlPK.js";
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-CimYXTmK.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,4 +1,4 @@
1
- import { D as CiError, i as ClientFetch, k as CiTransportError, t as ProxyAuthentication } from "./proxy-DRPEFvaV.js";
1
+ import { D as CiError, i as ClientFetch, k as CiTransportError, t as ProxyAuthentication } from "./proxy-BceN4mU3.js";
2
2
  import * as Config from "effect/Config";
3
3
  import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
@@ -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-r2t8pcv2.js";
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-DFkLnuj9.js";
2
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 };
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-l8wUAlPK.js";
2
- import { t as createResourceClient } from "./resources-BZKqGxBT.js";
1
+ import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-CimYXTmK.js";
2
+ import { t as createResourceClient } from "./resources-BiYIVzGa.js";
3
3
  export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
@@ -1,5 +1,5 @@
1
- import { i as FederatedAuthError, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-C3UmgGGu.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-l8wUAlPK.js";
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-CimYXTmK.js";
3
3
  import * as Predicate from "effect/Predicate";
4
4
  import * as Schema from "effect/Schema";
5
5
  import * as Arr from "effect/Array";
@@ -25,8 +25,8 @@ import * as Random from "effect/Random";
25
25
  import * as Schedule from "effect/Schedule";
26
26
  import * as Stream from "effect/Stream";
27
27
  import * as Deferred from "effect/Deferred";
28
- import * as Data from "effect/Data";
29
28
  import * as Equal from "effect/Equal";
29
+ import * as Data from "effect/Data";
30
30
  import * as Exit from "effect/Exit";
31
31
  const topicSetDebounceMilliseconds = 300;
32
32
  const pingTimeoutMilliseconds = 45e3;
@@ -1041,7 +1041,8 @@ const createPkcePair = async (crypto = globalThis.crypto) => {
1041
1041
  * Internal. The client SDK Session of one `FederatedAuth`: one tagged enum,
1042
1042
  * the pure `transition` that the store applies to its value
1043
1043
  * `{ epoch, session }`, and `toPublicState`, the public projection. The access
1044
- * token is a field of `Authenticated`, so no other state holds one.
1044
+ * token and the Renewal credential are private fields of `Authenticated`;
1045
+ * `Expired` keeps only the last access token, for `logout`.
1045
1046
  */
1046
1047
  const SessionEnum = Data.taggedEnum();
1047
1048
  const matchSession = SessionEnum.$match;
@@ -1064,7 +1065,7 @@ const transition = (value, event) => {
1064
1065
  session: Anonymous()
1065
1066
  }),
1066
1067
  LoginStarted: () => ({
1067
- epoch: value.epoch,
1068
+ epoch: value.epoch + 1,
1068
1069
  session: Redirecting()
1069
1070
  }),
1070
1071
  Settled: ({ epoch, session }) => epoch === value.epoch ? {
@@ -1073,7 +1074,7 @@ const transition = (value, event) => {
1073
1074
  } : value,
1074
1075
  TokenExpired: () => value.session._tag === "Authenticated" ? {
1075
1076
  epoch: value.epoch,
1076
- session: Expired()
1077
+ session: Expired({ accessToken: value.session.accessToken })
1077
1078
  } : value
1078
1079
  });
1079
1080
  if (!Equal.equals(next.session, value.session)) return next;
@@ -1119,7 +1120,7 @@ const navigation = (navigate) => {
1119
1120
  /**
1120
1121
  * The synchronous store of one Session: one value `{ epoch, session }` that
1121
1122
  * only `dispatch` changes. `dispatch` assigns the next value, then notifies
1122
- * when the Session changed, so a listener reads the new state. A dispatch
1123
+ * when the public state changed, so a listener reads the new state. A dispatch
1123
1124
  * that a listener makes is applied after the current notification ends. A
1124
1125
  * listener that throws stops no other listener and no queued change; the
1125
1126
  * first error is thrown when the queue is empty.
@@ -1145,7 +1146,9 @@ const makeState = () => {
1145
1146
  const previous = value;
1146
1147
  value = transition(previous, next);
1147
1148
  if (value.session === previous.session) continue;
1148
- state = toPublicState(value.session);
1149
+ const changed = toPublicState(value.session);
1150
+ if (Equal.equals(changed, state)) continue;
1151
+ state = changed;
1149
1152
  for (const listener of listeners) try {
1150
1153
  listener(state);
1151
1154
  } catch (error) {
@@ -1190,6 +1193,17 @@ const makeCompletion = () => {
1190
1193
  };
1191
1194
  const transactionLifetimeMs = 6e5;
1192
1195
  const maxReturnTargetLength = 2048;
1196
+ /** `getAccessToken` renews `min(30 s, lifetime / 10)` before expiry. */
1197
+ const maxRenewalMarginMs = 3e4;
1198
+ /**
1199
+ * The waits before the second and the third renewal attempt. With 8 s per
1200
+ * attempt, the last one starts by 17.25 s, inside CI's 30 s reuse window.
1201
+ */
1202
+ const renewalRetryWaitsMs = [250, 1e3];
1203
+ const renewalAttemptTimeoutMs = 8e3;
1204
+ /** After a refusal, the wait for the logout notice of another tab. */
1205
+ const refusalGraceMillis = 500;
1206
+ const formContentType = { "content-type": "application/x-www-form-urlencoded" };
1193
1207
  /** An absolute URL without credentials, else `null`. */
1194
1208
  const absoluteUrl = (value) => {
1195
1209
  try {
@@ -1228,15 +1242,24 @@ const parseToken = (value, now) => {
1228
1242
  const accessToken = own("access_token");
1229
1243
  const expiresIn = own("expires_in");
1230
1244
  if (typeof accessToken !== "string" || accessToken.length === 0 || typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || expiresIn <= 0 || own("token_type") !== "Bearer") return null;
1245
+ const lifetimeMs = expiresIn * 1e3;
1246
+ const refreshToken = own("refresh_token");
1231
1247
  return {
1232
1248
  accessToken,
1233
- expiresAt: now + expiresIn * 1e3
1249
+ expiresAt: now + lifetimeMs,
1250
+ refreshToken: typeof refreshToken === "string" && refreshToken.length > 0 ? refreshToken : null,
1251
+ renewAt: now + lifetimeMs - Math.min(maxRenewalMarginMs, lifetimeMs / 10)
1234
1252
  };
1235
1253
  };
1254
+ const unanswered = { kind: "unanswered" };
1255
+ /** The logout notice between the tabs of one Application in one browser. */
1256
+ const logoutNotice = { type: "logout" };
1236
1257
  /**
1237
1258
  * The session of browser federated sign-in: one PKCE login transaction in
1238
- * `sessionStorage`, and the access token in memory only. A configuration
1239
- * error fails with `FederatedAuthError`.
1259
+ * `sessionStorage`, and the access token and the Renewal credential in
1260
+ * memory only. A logout tells the other tabs through the `BroadcastChannel`
1261
+ * of the client, which the scope closes. A configuration error fails with
1262
+ * `FederatedAuthError`.
1240
1263
  */
1241
1264
  const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1242
1265
  const tenantUrl = yield* parseUrl(options.tenantUrl, "tenantUrl");
@@ -1253,7 +1276,104 @@ const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1253
1276
  const storageKey = `ci:federated-auth:${redirectUri.origin}:${options.clientId}`;
1254
1277
  const { changes, dispatch, epoch, getState, session, subscribe } = makeState();
1255
1278
  const completion = makeCompletion();
1279
+ const renewal = makeCompletion();
1256
1280
  let rememberedReturnTo;
1281
+ /** The local part of a logout, also on the notice of another tab. */
1282
+ const clearLocal = () => {
1283
+ completion.reset();
1284
+ renewal.reset();
1285
+ rememberedReturnTo = void 0;
1286
+ storage.removeItem(storageKey);
1287
+ dispatch(LoggedOut());
1288
+ };
1289
+ const channel = yield* Effect.acquireRelease(Effect.sync(() => {
1290
+ if (typeof globalThis.BroadcastChannel !== "function") return null;
1291
+ const opened = new BroadcastChannel(`ci-federated-auth:${options.clientId}`);
1292
+ opened.addEventListener("message", (event) => {
1293
+ if (asRecord$1(event.data)?.type === logoutNotice.type) clearLocal();
1294
+ });
1295
+ return opened;
1296
+ }), (opened) => Effect.sync(() => opened?.close()));
1297
+ const renewalAttempt = (refreshToken) => Effect.tryPromise((signal) => fetch(new URL("/oauth/token", tenantOrigin), {
1298
+ body: new URLSearchParams({
1299
+ client_id: options.clientId,
1300
+ grant_type: "refresh_token",
1301
+ refresh_token: refreshToken
1302
+ }),
1303
+ headers: formContentType,
1304
+ method: "POST",
1305
+ signal
1306
+ })).pipe(Effect.flatMap((response) => {
1307
+ if (response.status === 429) return Effect.succeed({ kind: "throttled" });
1308
+ if (response.status >= 400 && response.status < 500) return Effect.succeed({ kind: "refused" });
1309
+ if (!response.ok) return Effect.succeed(unanswered);
1310
+ return Effect.map(readJson(response), (body) => {
1311
+ const token = parseToken(body, now());
1312
+ return token === null ? unanswered : {
1313
+ kind: "renewed",
1314
+ token
1315
+ };
1316
+ });
1317
+ }), Effect.timeoutOrElse({
1318
+ duration: renewalAttemptTimeoutMs,
1319
+ orElse: () => Effect.succeed(unanswered)
1320
+ }), Effect.orElseSucceed(() => unanswered));
1321
+ /** Up to 3 attempts with one credential, while CI does not answer. */
1322
+ const requestRenewal = Effect.fnUntraced(function* requestRenewal(refreshToken) {
1323
+ let answer = yield* renewalAttempt(refreshToken);
1324
+ for (const wait of renewalRetryWaitsMs) {
1325
+ if (answer.kind !== "unanswered") break;
1326
+ yield* Effect.sleep(wait);
1327
+ answer = yield* renewalAttempt(refreshToken);
1328
+ }
1329
+ return answer;
1330
+ });
1331
+ /**
1332
+ * One renewal of `held`. CI's refusal drops the credential, then waits the
1333
+ * grace for the logout notice of another tab: with no notice the Session
1334
+ * becomes Expired. A result that ends after a logout or a notice changes
1335
+ * nothing (SDK-1).
1336
+ */
1337
+ const renew = Effect.fnUntraced(function* renew(held, refreshToken) {
1338
+ const started = epoch();
1339
+ const answer = yield* requestRenewal(refreshToken);
1340
+ if (answer.kind === "refused") {
1341
+ dispatch(Settled({
1342
+ epoch: started,
1343
+ session: Authenticated({
1344
+ ...held,
1345
+ refreshToken: null
1346
+ })
1347
+ }));
1348
+ yield* Effect.sleep(refusalGraceMillis);
1349
+ dispatch(Settled({
1350
+ epoch: started,
1351
+ session: Expired({ accessToken: held.accessToken })
1352
+ }));
1353
+ return yield* loginRequired();
1354
+ }
1355
+ if (answer.kind === "renewed") {
1356
+ const { token } = answer;
1357
+ dispatch(Settled({
1358
+ epoch: started,
1359
+ session: Authenticated({
1360
+ ...token,
1361
+ identity: null,
1362
+ refreshToken: token.refreshToken ?? refreshToken
1363
+ })
1364
+ }));
1365
+ }
1366
+ if (epoch() !== started) return yield* loginRequired();
1367
+ return answer.kind === "renewed" ? answer.token.accessToken : yield* new FederatedAuthError("renewal_unavailable", "CI did not answer the session renewal");
1368
+ });
1369
+ /** The held token until it expires, for a session with no credential. */
1370
+ const untilExpiry = (accessToken, expiresAt) => Effect.suspend(() => {
1371
+ if (expiresAt <= now()) {
1372
+ dispatch(TokenExpired());
1373
+ return Effect.fail(loginRequired());
1374
+ }
1375
+ return Effect.succeed(accessToken);
1376
+ });
1257
1377
  const normalizedReturnTarget = (value) => Effect.suspend(() => {
1258
1378
  if (value.length > maxReturnTargetLength) return Effect.fail(new FederatedAuthError("invalid_return_target", "The return target is too long"));
1259
1379
  const target = new URL(value, redirectUri.origin);
@@ -1278,6 +1398,7 @@ const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1278
1398
  authorizationUrl.searchParams.set("code_challenge", pkce.challenge);
1279
1399
  authorizationUrl.searchParams.set("code_challenge_method", pkce.method);
1280
1400
  completion.reset();
1401
+ renewal.reset();
1281
1402
  dispatch(LoginStarted());
1282
1403
  yield* navigate(authorizationUrl.href);
1283
1404
  return authorizationUrl.href;
@@ -1350,22 +1471,34 @@ const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1350
1471
  getAccessToken: Effect.suspend(() => {
1351
1472
  const current = session();
1352
1473
  if (current._tag !== "Authenticated" || current.accessToken === null) return Effect.fail(loginRequired());
1353
- if (current.expiresAt <= now()) {
1354
- dispatch(TokenExpired());
1355
- return Effect.fail(loginRequired());
1356
- }
1357
- return Effect.succeed(current.accessToken);
1474
+ if (now() < current.renewAt) return Effect.succeed(current.accessToken);
1475
+ return renewal.run(current.refreshToken === null ? untilExpiry(current.accessToken, current.expiresAt) : renew(current, current.refreshToken));
1358
1476
  }),
1359
1477
  getState,
1360
1478
  logout: Effect.suspend(() => {
1361
1479
  const current = session();
1362
- const accessToken = current._tag === "Authenticated" ? current.accessToken : null;
1363
- completion.reset();
1364
- rememberedReturnTo = void 0;
1365
- storage.removeItem(storageKey);
1366
- dispatch(LoggedOut());
1367
- return accessToken === null ? Effect.void : Effect.tryPromise((signal) => fetch(new URL("/oauth/logout", tenantOrigin), {
1368
- headers: { authorization: `Bearer ${accessToken}` },
1480
+ const accessToken = current._tag === "Authenticated" || current._tag === "Expired" ? current.accessToken : null;
1481
+ const refreshToken = current._tag === "Authenticated" ? current.refreshToken : null;
1482
+ clearLocal();
1483
+ channel?.postMessage(logoutNotice);
1484
+ if (accessToken === null) return Effect.void;
1485
+ const request = refreshToken === null ? {
1486
+ body: new URLSearchParams({ client_id: options.clientId }),
1487
+ headers: {
1488
+ ...formContentType,
1489
+ authorization: `Bearer ${accessToken}`
1490
+ }
1491
+ } : {
1492
+ body: new URLSearchParams({
1493
+ access_token: accessToken,
1494
+ client_id: options.clientId,
1495
+ token: refreshToken,
1496
+ token_type_hint: "refresh_token"
1497
+ }),
1498
+ headers: formContentType
1499
+ };
1500
+ return Effect.tryPromise((signal) => fetch(new URL("/oauth/logout", tenantOrigin), {
1501
+ ...request,
1369
1502
  method: "POST",
1370
1503
  signal
1371
1504
  })).pipe(Effect.ignore);
@@ -1458,15 +1591,18 @@ const makeServerSession = Effect.fnUntraced(function* makeServerSession(options)
1458
1591
  invalidSession("The application session is invalid");
1459
1592
  return;
1460
1593
  }
1461
- settle(expiresAt <= now() ? Expired() : Authenticated({
1594
+ settle(expiresAt <= now() ? Expired({ accessToken: null }) : Authenticated({
1462
1595
  accessToken: null,
1463
1596
  expiresAt,
1464
- identity
1597
+ identity,
1598
+ refreshToken: null,
1599
+ renewAt: expiresAt
1465
1600
  }));
1466
1601
  });
1467
1602
  const beginLogin = ({ returnTo }) => Effect.suspend(() => {
1468
1603
  rememberedReturnTo = returnTo;
1469
1604
  const url = `${origin}${basePath}/login?returnTo=${encodeURIComponent(returnTo)}`;
1605
+ completion.reset();
1470
1606
  dispatch(LoginStarted());
1471
1607
  return Effect.as(navigate(url), url);
1472
1608
  });
@@ -1,4 +1,4 @@
1
- import { c as __commonJSMin, l as __toESM, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-C3UmgGGu.js";
1
+ import { c as __commonJSMin, l as __toESM, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-B4-Jo4j3.js";
2
2
  import * as Predicate from "effect/Predicate";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Config from "effect/Config";
package/docs/errors.md CHANGED
@@ -26,6 +26,17 @@ class extends `Error`, and `.` and `/effect` export the same class.
26
26
  - A run that does not finish before `deadlineMs` rejects with `CiError`
27
27
  `unavailable` (`retryable: true`).
28
28
 
29
+ ## `getAccessToken` failures
30
+
31
+ `createFederatedAuth().getAccessToken()` fails with `FederatedAuthError`.
32
+ Branch on `getState()` and the code together:
33
+
34
+ | State | `code` | When | What the Application does |
35
+ | --------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
36
+ | `authenticated` | `renewal_unavailable` | CI did not answer the renewal after up to three attempts: a network error, a timeout, a 5xx or an unreadable answer; a 429 at once | Retry later. The session and its Renewal credential stay. |
37
+ | `expired` | `reauthorization_required` | CI refused the renewal, or the session has no Renewal credential and its Access token expired | Keep unsaved state, then call `reauthorize`. |
38
+ | `anonymous` | `reauthorization_required` | A logout in this tab or another tab of the Application ended the session during the call | Show the signed-out view. Sign in again only on a user action. |
39
+
29
40
  ## Rules
30
41
 
31
42
  - Branch with `instanceof` (Promise) or `Effect.catchTag` (Effect), then on
@@ -67,7 +67,7 @@ declareTool({
67
67
 
68
68
  `usageScopes` decides where the tool can appear: in a Skill, in chat, or in automation. The template needs `automation` so that the Lead qualifier Agent can use the tool. When you omit `usageScopes`, the tool appears in all three places, and an explicit empty list makes it unavailable everywhere. The model reads `toolGuidance.useWhen` and `toolGuidance.inputRequirementsSummary` to decide when to call the tool and what to pass, so write both for the model.
69
69
 
70
- A package can also bind built-in tools for web search (Exa or Tavily, which need an API key), website scraping, image generation, email, notifications, OCR, speech transcription and synthesis, and report building. External applications can use `publish-run-event`.
70
+ A package can also bind built-in tools for web search (Exa or Tavily, which need an API key), website scraping, image generation, email, notifications, OCR, speech transcription and synthesis, and report building. External applications can use `publish-run-event`. The [Built-in catalog](../platform/built-ins.md) lists every built-in tool and says which ones are ready after install.
71
71
 
72
72
  ## Skills
73
73
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Connect outside systems, map their fields to Knowledge schemas, and run and watch imports.
4
4
 
5
- A connector keeps a Data resource in sync with an outside system. CI has two kinds. A Knowledge connector imports records from a source such as Notion, HubSpot or a SQL database into Knowledge records. A Documents connector imports files from Microsoft 365 or Google Drive into one Connected Collection of Documents. The [Data resources](index.md) overview compares Knowledge, Datasets and Documents, and the [Documents](documents.md) page covers Document Collections.
5
+ A connector keeps a Data resource in sync with an outside system. CI has two kinds. A Knowledge connector imports records from a source such as Notion, HubSpot or a SQL database into Knowledge records. A Documents connector imports files from Microsoft 365 or Google Drive into one Connected Collection of Documents. The [Data resources](index.md) overview compares Knowledge, Datasets and Documents, and the [Documents](documents.md) page covers Document Collections. The [Built-in catalog](../platform/built-ins.md) lists every connector and connection type that CI ships.
6
6
 
7
7
  A Knowledge import passes through several stages: CI reads the source page by page, stages the records, commits the accepted ones into Knowledge, and then indexes them for search. An app or agent that reads imported data has to wait for the stage it needs. Most of this page covers Knowledge connectors. The last section compares them with Documents connectors.
8
8
 
@@ -40,7 +40,7 @@ Executable kinds also take an `implementation` class from `@collective-intellige
40
40
  | `declareEventListener` | Selectors plus `normalizeWebhook` or `poll` |
41
41
  | `declareNotificationChannel` | `deliver` |
42
42
 
43
- A component refers to another component of the same package through the handle that its `declare*` call returned. For a built-in component or one from another package, pass the FQN string instead, for example `"builtin.core.knowledge.tools.query"`. TypeScript does not check these strings. Install resolves them and rolls the package back when one does not exist, and the SDK publishes no list of built-in FQNs, so the template pins its FQNs in a `bun test` that catches a typo before deploy.
43
+ A component refers to another component of the same package through the handle that its `declare*` call returned. For a built-in component or one from another package, pass the FQN string instead, for example `"builtin.core.knowledge.tools.query"`. TypeScript does not check these strings. Install resolves them and rolls the package back when one does not exist. The [Built-in catalog](../platform/built-ins.md) lists what CI ships, and the template pins the FQNs that it uses in a `bun test` that catches a typo before deploy.
44
44
 
45
45
  A package that declares Agents or Skills needs a person to install it; an install with no signed-in user fails. A package can depend on another package by FQN only, for example `dependencies: [{ fqn: "com.acme.base" }]`, and each install picks the latest eligible release of the dependency by promotion order.
46
46
 
@@ -61,6 +61,7 @@ GITHUB_TOKEN=$(gh auth token) opensrc path collective-intelligence-solutions/sdk
61
61
  - [Platform architecture](platform/architecture.md): The parts of Collective Intelligence, the three integration models, and how a package moves from build to install.
62
62
  - [Entrypoints](platform/entrypoints.md): The ways people, apps and agents enter CI at runtime, and the package subpaths that your code imports.
63
63
  - [Grants and permissions](platform/access.md): How CI decides what a user, a Group, an app or an API key may do, and how to change it in the template.
64
+ - [Built-in catalog](platform/built-ins.md): Every tool, workflow node, trigger, connector, schema, channel and MCP operation that CI ships, and which ones are already installed in an Organization.
64
65
  - Data resources
65
66
  - [Data resources](data/index.md): Choose between Knowledge, Datasets and Documents, and see where each kind keeps its data.
66
67
  - [Knowledge](data/knowledge.md): Declare schemas, store typed records, query them, and read and watch them from an external app.