@collective-intelligence/external-apps-client-sdk 0.2.19 → 0.2.21

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/effect.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as CiTransportError, E as CiErrorCode, O as FederatedAuthError, T as CiError, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, k as FederatedAuthErrorCode, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-DaANR0QD.js";
2
- import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-dVoDg4IP.js";
1
+ import { D as CiTransportError, E as CiErrorCode, O as FederatedAuthError, T as CiError, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, k as FederatedAuthErrorCode, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-Db0c8eg9.js";
2
+ import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-BIyZo-CO.js";
3
3
  import * as Schema from "effect/Schema";
4
4
  /**
5
5
  * The wire Schemas of the CI envelopes that `./effect` exports. The Type of
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import { A as errors_exports, C as isClientOperationId, D as CiTransportError, O as FederatedAuthError, 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-DaANR0QD.js";
2
- import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-dVoDg4IP.js";
3
- import { t as createResourceClient } from "./resources-DhUOIac7.js";
1
+ import { A as errors_exports, C as isClientOperationId, D as CiTransportError, O as FederatedAuthError, 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-Db0c8eg9.js";
2
+ import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-BIyZo-CO.js";
3
+ import { t as createResourceClient } from "./resources-B6e3qsBD.js";
4
+ import * as Schema from "effect/Schema";
4
5
  import * as Clock from "effect/Clock";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Duration from "effect/Duration";
@@ -89,7 +90,7 @@ const createServerSessionAuth = (options) => {
89
90
  */
90
91
  /** A read of the source; a rejection is a transport failure. */
91
92
  const read = (call) => Effect.tryPromise({
92
- catch: (cause) => cause instanceof CiTransportError ? cause : new CiTransportError({ cause }),
93
+ catch: (cause) => Schema.is(CiTransportError)(cause) ? cause : new CiTransportError({ cause }),
93
94
  try: call
94
95
  }).pipe(Effect.map(toCiResult));
95
96
  const sourceOf = (runs) => ({
@@ -1,4 +1,5 @@
1
- import { D as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-DaANR0QD.js";
1
+ import { D as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-Db0c8eg9.js";
2
+ import * as Schema from "effect/Schema";
2
3
  import * as Layer from "effect/Layer";
3
4
  import * as ManagedRuntime from "effect/ManagedRuntime";
4
5
  /**
@@ -92,7 +93,7 @@ const createLegacyResourceClient = (options) => {
92
93
  try {
93
94
  return await runtime.runPromise(call(correlationId, requestOptions), signal === void 0 ? void 0 : { signal });
94
95
  } catch (error) {
95
- if (error instanceof CiTransportError) return {
96
+ if (Schema.is(CiTransportError)(error)) return {
96
97
  correlationId,
97
98
  error: unavailable(error.cause),
98
99
  ok: false
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-DaANR0QD.js";
2
- import { t as createResourceClient } from "./resources-DhUOIac7.js";
1
+ import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-Db0c8eg9.js";
2
+ import { t as createResourceClient } from "./resources-B6e3qsBD.js";
3
3
  export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
@@ -1,4 +1,4 @@
1
- import { D as CiTransportError, O as FederatedAuthError, S as fromCiResult, T as CiError, _ as backendErrorCode, b as proxyHttpOptions, j as ciErrorCodes, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-DaANR0QD.js";
1
+ import { D as CiTransportError, O as FederatedAuthError, S as fromCiResult, T as CiError, _ as backendErrorCode, b as proxyHttpOptions, j as ciErrorCodes, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-Db0c8eg9.js";
2
2
  import * as Predicate from "effect/Predicate";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Arr from "effect/Array";
@@ -900,7 +900,7 @@ const make$3 = (executeResult) => CiClient.of({
900
900
  */
901
901
  const executeOf = (executor) => (operationId, input, options) => Effect.tryPromise({
902
902
  catch: (error) => {
903
- if (error instanceof CiTransportError) return error;
903
+ if (Schema.is(CiTransportError)(error)) return error;
904
904
  throw error;
905
905
  },
906
906
  try: (signal) => executor.execute(operationId, input, {
@@ -1102,13 +1102,9 @@ var FederatedAuth = class extends Context.Service()("@collective-intelligence/ex
1102
1102
  const configurationError = (message) => new FederatedAuthError("configuration_error", message);
1103
1103
  const transportError = (cause) => new CiTransportError({ cause });
1104
1104
  const loginRequired = () => new FederatedAuthError("reauthorization_required", "A new CI login is required");
1105
- const readJson = (response) => Effect.promise(async () => {
1106
- try {
1107
- return await response.json();
1108
- } catch {
1109
- return null;
1110
- }
1111
- });
1105
+ /** The JSON text of a value; callers turn a value that JSON cannot write, bad input, into a Defect. */
1106
+ const encodeJsonText = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
1107
+ const readJson = (response) => Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
1112
1108
  /** The browser navigation; without one, a configuration error. */
1113
1109
  const navigation = (navigate) => {
1114
1110
  if (navigate !== void 0) return (url) => Effect.sync(() => navigate(url));
@@ -1272,7 +1268,7 @@ const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1272
1268
  state: createOauthRandomValue(crypto),
1273
1269
  verifier: pkce.verifier
1274
1270
  };
1275
- storage.setItem(storageKey, JSON.stringify(transaction));
1271
+ storage.setItem(storageKey, yield* encodeJsonText(transaction).pipe(Effect.orDie));
1276
1272
  const authorizationUrl = new URL("/oauth/authorize", tenantOrigin);
1277
1273
  authorizationUrl.searchParams.set("client_id", options.clientId);
1278
1274
  authorizationUrl.searchParams.set("redirect_uri", redirectUri.href);
@@ -1571,13 +1567,7 @@ const make$1 = (options) => {
1571
1567
  signal
1572
1568
  })
1573
1569
  });
1574
- const payload = yield* Effect.promise(async () => {
1575
- try {
1576
- return await response.json();
1577
- } catch {
1578
- return null;
1579
- }
1580
- });
1570
+ const payload = yield* Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
1581
1571
  return yield* runIdOf(response, payload);
1582
1572
  }) });
1583
1573
  };
@@ -1616,7 +1606,7 @@ const mapAuthState = (state) => {
1616
1606
  };
1617
1607
  /** The message of a failed session read; a transport failure names its cause. */
1618
1608
  const failureMessage = (error) => {
1619
- if (error instanceof CiTransportError) return failureMessage(error.cause);
1609
+ if (Schema.is(CiTransportError)(error)) return failureMessage(error.cause);
1620
1610
  return error instanceof Error && error.message !== "" ? error.message : "CI session verification is unavailable";
1621
1611
  };
1622
1612
  const resolvedPaths = (options) => ({
@@ -128,7 +128,7 @@ const decodeCiError = Schema.decodeUnknownOption(CiError);
128
128
  * becomes `internal`, so an Expected Error always has its class.
129
129
  */
130
130
  const toCiError = (error) => {
131
- if (error instanceof CiError) return error;
131
+ if (Schema.is(CiError)(error)) return error;
132
132
  const { details, ...fields } = error;
133
133
  return decodeCiError({
134
134
  ...fields,
@@ -144,7 +144,7 @@ const toCiError = (error) => {
144
144
  })));
145
145
  };
146
146
  /** Internal. The envelope with a `CiError` instance as its error (AC-015). */
147
- const toCiResult = (result) => result.ok || result.error instanceof CiError ? result : {
147
+ const toCiResult = (result) => result.ok || Schema.is(CiError)(result.error) ? result : {
148
148
  correlationId: result.correlationId,
149
149
  error: toCiError(result.error),
150
150
  ok: false
@@ -394,22 +394,10 @@ const clientFailure = (error) => ({
394
394
  error,
395
395
  ok: false
396
396
  });
397
- const responseJson = (response) => Effect.promise(async () => {
398
- try {
399
- return await response.json();
400
- } catch {
401
- return null;
402
- }
403
- });
397
+ const responseJson = (response) => Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
404
398
  const transportError$1 = (cause) => new CiTransportError({ cause });
405
399
  /** The bearer token of `authorization`; `null` when it fails. */
406
- const accessToken = (authorization) => Effect.promise(async () => {
407
- try {
408
- return { token: await authorization?.() };
409
- } catch {
410
- return null;
411
- }
412
- });
400
+ const accessToken = (authorization) => Effect.tryPromise(() => Promise.resolve(authorization?.())).pipe(Effect.map((token) => ({ token })), Effect.orElseSucceed(() => null));
413
401
  /**
414
402
  * The HTTP adapter of `CiClient`: one operation per dedicated Application
415
403
  * HTTP route. A CI error answer is a `CiError` in the envelope, and so is an
@@ -8488,13 +8476,7 @@ const makeEntityHttpExecute = (options) => {
8488
8476
  });
8489
8477
  if (destination.kind === "ci") headers.set("x-organization-id", destination.organizationId);
8490
8478
  if (authentication.mode === "federated") {
8491
- const token = yield* Effect.promise(async () => {
8492
- try {
8493
- return { value: await authentication.auth.getAccessToken() };
8494
- } catch {
8495
- return null;
8496
- }
8497
- });
8479
+ const token = yield* Effect.tryPromise(() => Promise.resolve(authentication.auth.getAccessToken())).pipe(Effect.map((value) => ({ value })), Effect.orElseSucceed(() => null));
8498
8480
  if (token === null) return failure$1(request, {
8499
8481
  code: "unauthenticated",
8500
8482
  message: "CI login is required",
@@ -8520,7 +8502,7 @@ const makeEntityHttpExecute = (options) => {
8520
8502
  });
8521
8503
  const result = yield* Effect.tryPromise({
8522
8504
  catch: transportError,
8523
- try: async () => await response.json()
8505
+ try: () => response.json()
8524
8506
  });
8525
8507
  return yield* Effect.try({
8526
8508
  catch: transportError,
@@ -8539,7 +8521,7 @@ const runEntityRequest = async (runtime, effect, request) => {
8539
8521
  try {
8540
8522
  return await runtime.runPromise(effect, signal === void 0 ? void 0 : { signal });
8541
8523
  } catch (error) {
8542
- if (!(error instanceof CiTransportError) && signal?.aborted !== true) throw error;
8524
+ if (!Schema.is(CiTransportError)(error) && signal?.aborted !== true) throw error;
8543
8525
  return {
8544
8526
  correlationId: request.correlationId,
8545
8527
  error: {
@@ -8591,7 +8573,7 @@ const capabilityOf = {
8591
8573
  };
8592
8574
  /** The adapter over an `EntityTransport` of the app; a rejection fails with `CiTransportError`. */
8593
8575
  const fromEntityTransport = (transport) => (request, options) => Effect.tryPromise({
8594
- catch: (cause) => cause instanceof CiTransportError ? cause : new CiTransportError({ cause }),
8576
+ catch: (cause) => Schema.is(CiTransportError)(cause) ? cause : new CiTransportError({ cause }),
8595
8577
  try: (signal) => transport.execute(request, { signal: options.signal === void 0 ? signal : AbortSignal.any([options.signal, signal]) })
8596
8578
  });
8597
8579
  /** Internal. The envelope core of the entity client of one definition. */
@@ -144,20 +144,25 @@ The declaration of an Agent sets the most it can do: its tools, scopes, approval
144
144
 
145
145
  ## Approvals
146
146
 
147
- An entry in a `tools` list can be a `ToolBinding` instead of a bare reference. A binding can rename the tool, set its settings, narrow its Knowledge and choose an approval mode, and you can bind one tool several times under different names:
147
+ An entry in a `tools` list can be a `ToolBinding` instead of a bare reference. A binding can rename the tool, give it a Binding Description, set its Binding Settings and choose an approval mode, and you can bind one tool several times under different names:
148
148
 
149
149
  ```ts
150
150
  tools: [
151
151
  {
152
152
  tool: "builtin.core.knowledge.tools.query",
153
- name: "member-query",
154
- settings: { limit: 10 },
155
- knowledge: { domains: { include: [membersDomain] } },
153
+ name: "lead-query",
154
+ description: "Search the Leads of the CRM",
155
+ settings: {
156
+ // The Knowledge tools' form marks this field "x-fqn-of": "knowledge-entity-schema".
157
+ allowedEntitySchemaIds: [leadSchemaFqn]
158
+ },
156
159
  approval: { rule: "Escalations" }
157
160
  }
158
161
  ]
159
162
  ```
160
163
 
164
+ `name`, `description` and `approval` work the same way for every tool. The model sees the Binding Description in place of the tool's own description. `settings` holds the tool's own options, and the tool's Binding Settings Form defines them, so install fails on a key that the form does not define. A field that the form marks with `x-fqn-of` takes FQNs, and install translates each FQN into the id of the installing Organization's record. Install fails when an FQN names no record of that Organization, and the error names every such FQN of the binding. A binding has no tool-specific property.
165
+
161
166
  `approval` has three modes. `"never"` makes no approval request for the binding. `"always"` pauses for an explicit decision by the user who started the call, and that user's eligibility to approve does not approve the call. `{ rule: "<rule name>" }` uses an approval rule of the installing Organization, with that rule's reviewers and expiry. Install fails when no rule has the name, so create the rule in the target Organization before you install a demo package that uses one.
162
167
 
163
168
  Approval pauses the call and leaves the tool visible. With `"always"`, the model still sees the tool definition and can decide to call it, and the call then waits for a person.
@@ -312,7 +317,7 @@ An agent reads data only through the tools it is bound to. The core packages pro
312
317
 
313
318
  Knowledge Query has seven intents: `autocomplete`, `search`, `facets`, `facet_values`, `count`, `get` and `relation_members`. `search`, `count` and the two facet intents need an `entitySchemaId`, and `get` needs an `entityId`. A missing id fails with `invalid_input`, so tell the model in the Skill or the Role to find schema ids with Knowledge `catalog` first and never to invent one. When a schema has record or indexed-file embeddings, Query also runs semantic retrieval on PostgreSQL with pgvector, and the model never sees the vectors or the embedding provider.
314
319
 
315
- Two settings decide what these tools can read. A binding's `knowledge` field narrows a tool to included or excluded domains and entity schemas, as the `member-query` binding above does. `dataAccess` on `declareAgent`, `declareSkill` or `declareWorkflow` decides, separately for `knowledge`, `documents` and `datasets`, whose permission applies. With `"user"`, the run reads what the acting person can read. With the declaration's own kind (`"agent"`, `"skill"` or `"workflow"`), which is the default, the run reads its configured resources without the caller's permission on the source. `dataAccess` grants no extra tool bindings.
320
+ Two settings decide what these tools can read. The Binding Settings of a Knowledge tool narrow it to allowed or excluded domains and entity schemas (`allowedDomainIds`, `excludedDomainIds`, `allowedEntitySchemaIds` and `excludedEntitySchemaIds`), as the `lead-query` binding above does. The Information tools take `allowedEntitySchemaIds` in the same way, and when Advanced Retrieval loads Expand Passage and Read Source Range, they use its Binding Settings. `dataAccess` on `declareAgent`, `declareSkill` or `declareWorkflow` decides, separately for `knowledge`, `documents` and `datasets`, whose permission applies. With `"user"`, the run reads what the acting person can read. With the declaration's own kind (`"agent"`, `"skill"` or `"workflow"`), which is the default, the run reads its configured resources without the caller's permission on the source. `dataAccess` grants no extra tool bindings.
316
321
 
317
322
  ```ts
318
323
  const dataAccess = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Framework-neutral client for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -75,5 +75,5 @@
75
75
  "ultracite": "7.10.7",
76
76
  "vitest": "5.0.2"
77
77
  },
78
- "gitHead": "971beeea23167578d9a5f8ef371ad7d8bdd245dc"
78
+ "gitHead": "b0f4929291e18278637c715476bb981c6d63db15"
79
79
  }