@executor-js/cli 0.0.1 → 0.0.2

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.js CHANGED
@@ -12,32 +12,42 @@ import { Command } from "commander";
12
12
  // ../storage-core/src/factory.ts
13
13
  import { Effect } from "effect";
14
14
 
15
+ // ../storage-core/src/errors.ts
16
+ import { Data } from "effect";
17
+ var StorageError = class extends Data.TaggedError("StorageError") {
18
+ };
19
+ var UniqueViolationError = class extends Data.TaggedError(
20
+ "UniqueViolationError"
21
+ ) {
22
+ };
23
+
15
24
  // ../sdk/src/ids.ts
16
25
  import { Schema } from "effect";
17
26
  var ScopeId = Schema.String.pipe(Schema.brand("ScopeId"));
18
27
  var ToolId = Schema.String.pipe(Schema.brand("ToolId"));
19
28
  var SecretId = Schema.String.pipe(Schema.brand("SecretId"));
20
29
  var PolicyId = Schema.String.pipe(Schema.brand("PolicyId"));
30
+ var ConnectionId = Schema.String.pipe(Schema.brand("ConnectionId"));
21
31
 
22
32
  // ../sdk/src/scope.ts
23
33
  import { Schema as Schema2 } from "effect";
24
34
  var Scope = class extends Schema2.Class("Scope")({
25
35
  id: ScopeId,
26
36
  name: Schema2.String,
27
- createdAt: Schema2.DateFromNumber
37
+ createdAt: Schema2.Date
28
38
  }) {
29
39
  };
30
40
 
31
41
  // ../sdk/src/errors.ts
32
- import { Data, Schema as Schema3 } from "effect";
33
- var ToolNotFoundError = class extends Schema3.TaggedError()(
42
+ import { Data as Data2, Schema as Schema3 } from "effect";
43
+ var ToolNotFoundError = class extends Schema3.TaggedErrorClass()(
34
44
  "ToolNotFoundError",
35
45
  { toolId: ToolId }
36
46
  ) {
37
47
  };
38
- var ToolInvocationError = class extends Data.TaggedError("ToolInvocationError") {
48
+ var ToolInvocationError = class extends Data2.TaggedError("ToolInvocationError") {
39
49
  };
40
- var PluginNotLoadedError = class extends Schema3.TaggedError()(
50
+ var PluginNotLoadedError = class extends Schema3.TaggedErrorClass()(
41
51
  "PluginNotLoadedError",
42
52
  {
43
53
  pluginId: Schema3.String,
@@ -45,7 +55,7 @@ var PluginNotLoadedError = class extends Schema3.TaggedError()(
45
55
  }
46
56
  ) {
47
57
  };
48
- var NoHandlerError = class extends Schema3.TaggedError()(
58
+ var NoHandlerError = class extends Schema3.TaggedErrorClass()(
49
59
  "NoHandlerError",
50
60
  {
51
61
  toolId: ToolId,
@@ -53,22 +63,30 @@ var NoHandlerError = class extends Schema3.TaggedError()(
53
63
  }
54
64
  ) {
55
65
  };
56
- var SourceNotFoundError = class extends Schema3.TaggedError()(
66
+ var ToolBlockedError = class extends Schema3.TaggedErrorClass()(
67
+ "ToolBlockedError",
68
+ {
69
+ toolId: ToolId,
70
+ pattern: Schema3.String
71
+ }
72
+ ) {
73
+ };
74
+ var SourceNotFoundError = class extends Schema3.TaggedErrorClass()(
57
75
  "SourceNotFoundError",
58
76
  { sourceId: Schema3.String }
59
77
  ) {
60
78
  };
61
- var SourceRemovalNotAllowedError = class extends Schema3.TaggedError()(
79
+ var SourceRemovalNotAllowedError = class extends Schema3.TaggedErrorClass()(
62
80
  "SourceRemovalNotAllowedError",
63
81
  { sourceId: Schema3.String }
64
82
  ) {
65
83
  };
66
- var SecretNotFoundError = class extends Schema3.TaggedError()(
84
+ var SecretNotFoundError = class extends Schema3.TaggedErrorClass()(
67
85
  "SecretNotFoundError",
68
86
  { secretId: SecretId }
69
87
  ) {
70
88
  };
71
- var SecretResolutionError = class extends Schema3.TaggedError()(
89
+ var SecretResolutionError = class extends Schema3.TaggedErrorClass()(
72
90
  "SecretResolutionError",
73
91
  {
74
92
  secretId: SecretId,
@@ -76,6 +94,44 @@ var SecretResolutionError = class extends Schema3.TaggedError()(
76
94
  }
77
95
  ) {
78
96
  };
97
+ var SecretOwnedByConnectionError = class extends Schema3.TaggedErrorClass()(
98
+ "SecretOwnedByConnectionError",
99
+ {
100
+ secretId: SecretId,
101
+ connectionId: ConnectionId
102
+ }
103
+ ) {
104
+ };
105
+ var ConnectionNotFoundError = class extends Schema3.TaggedErrorClass()(
106
+ "ConnectionNotFoundError",
107
+ { connectionId: ConnectionId }
108
+ ) {
109
+ };
110
+ var ConnectionProviderNotRegisteredError = class extends Schema3.TaggedErrorClass()(
111
+ "ConnectionProviderNotRegisteredError",
112
+ {
113
+ provider: Schema3.String,
114
+ connectionId: Schema3.optional(ConnectionId)
115
+ }
116
+ ) {
117
+ };
118
+ var ConnectionRefreshNotSupportedError = class extends Schema3.TaggedErrorClass()(
119
+ "ConnectionRefreshNotSupportedError",
120
+ {
121
+ connectionId: ConnectionId,
122
+ provider: Schema3.String
123
+ }
124
+ ) {
125
+ };
126
+ var ConnectionReauthRequiredError = class extends Schema3.TaggedErrorClass()(
127
+ "ConnectionReauthRequiredError",
128
+ {
129
+ connectionId: ConnectionId,
130
+ provider: Schema3.String,
131
+ message: Schema3.String
132
+ }
133
+ ) {
134
+ };
79
135
 
80
136
  // ../sdk/src/types.ts
81
137
  import { Schema as Schema4 } from "effect";
@@ -88,7 +144,7 @@ var ToolSchema = class extends Schema4.Class("ToolSchema")({
88
144
  inputTypeScript: Schema4.optional(Schema4.String),
89
145
  outputTypeScript: Schema4.optional(Schema4.String),
90
146
  typeScriptDefinitions: Schema4.optional(
91
- Schema4.Record({ key: Schema4.String, value: Schema4.String })
147
+ Schema4.Record(Schema4.String, Schema4.String)
92
148
  )
93
149
  }) {
94
150
  };
@@ -99,7 +155,7 @@ var SourceDetectionResult = class extends Schema4.Class(
99
155
  kind: Schema4.String,
100
156
  /** Confidence tier — UI uses this to pick a winner when multiple
101
157
  * plugins claim a URL. */
102
- confidence: Schema4.Literal("high", "medium", "low"),
158
+ confidence: Schema4.Literals(["high", "medium", "low"]),
103
159
  /** The (possibly normalized) endpoint the plugin will use. */
104
160
  endpoint: Schema4.String,
105
161
  /** Human-readable name suggestion, typically derived from spec title
@@ -181,79 +237,503 @@ var coreSchema = {
181
237
  // provider key). Actual values never touch this table — they live in
182
238
  // the secret provider (keychain, 1password, file, etc.) and are
183
239
  // resolved on demand via `ctx.secrets.get(id)`.
240
+ //
241
+ // `owned_by_connection_id` ties the row to a connection. Connection-
242
+ // owned secrets are plumbing, not user-facing values: `ctx.secrets.list`
243
+ // filters them out (the user sees the Connection instead), and
244
+ // `ctx.secrets.remove` refuses to delete them (Connection.remove is
245
+ // the single owner of the lifecycle). The FK is nullable so existing
246
+ // "bare" secrets (API keys entered by the user, pre-connection OAuth
247
+ // rows during migration) remain visible and removable unchanged.
184
248
  secret: {
185
249
  fields: {
186
250
  id: { type: "string", required: true },
187
251
  scope_id: { type: "string", required: true, index: true },
188
252
  name: { type: "string", required: true },
189
253
  provider: { type: "string", required: true, index: true },
254
+ owned_by_connection_id: {
255
+ type: "string",
256
+ required: false,
257
+ index: true
258
+ },
259
+ created_at: { type: "date", required: true }
260
+ }
261
+ },
262
+ // Connections — sign-in state for one identity against one remote
263
+ // provider. A Connection owns one or more `secret` rows (access +
264
+ // refresh tokens, etc.) via `secret.owned_by_connection_id`, and the
265
+ // SDK exposes `ctx.connections.accessToken(id)` which transparently
266
+ // refreshes the backing secrets when they're near expiry. Plugins
267
+ // contribute refresh behavior via `plugin.connectionProviders[].refresh`
268
+ // keyed by `provider`, same pattern as `secretProviders`.
269
+ //
270
+ // `provider_state` is plugin-owned opaque JSON — token endpoint URL,
271
+ // scopes, issuer, auth-server metadata — whatever the provider's
272
+ // refresh handler needs to re-hit the token endpoint. It's NOT
273
+ // sensitive (all secrets go through the provider-backed secret rows);
274
+ // it's just enough metadata to drive a refresh without re-running
275
+ // discovery.
276
+ connection: {
277
+ fields: {
278
+ id: { type: "string", required: true },
279
+ scope_id: { type: "string", required: true, index: true },
280
+ /** Routing key into `plugin.connectionProviders`. Typical shape
281
+ * is `${pluginId}:${kind}` (e.g. `openapi:oauth2`, `mcp:oauth2`,
282
+ * `google-discovery:google`). Mirrors `secret.provider`. */
283
+ provider: { type: "string", required: true, index: true },
284
+ /** Display label shown in the Connections UI. Usually the account
285
+ * email / handle / org name the user signed in as. */
286
+ identity_label: { type: "string", required: false },
287
+ /** Stable id of the access-token secret. Always present. */
288
+ access_token_secret_id: { type: "string", required: true },
289
+ /** Stable id of the refresh-token secret. Null for flows that
290
+ * don't mint a refresh token (client_credentials, etc.). */
291
+ refresh_token_secret_id: { type: "string", required: false },
292
+ /** Epoch ms when the access token expires. Null if the provider
293
+ * didn't declare an expiry. Used as the refresh trigger. Stored as
294
+ * `bigint` because `Date.now()` overflows int32. */
295
+ expires_at: { type: "number", required: false, bigint: true },
296
+ /** Scope string as returned by the token endpoint. */
297
+ scope: { type: "string", required: false },
298
+ /** Opaque plugin-owned JSON — token endpoint URL, scopes list,
299
+ * discovery hints, etc. Never sensitive. */
300
+ provider_state: { type: "json", required: false },
301
+ created_at: { type: "date", required: true },
302
+ updated_at: { type: "date", required: true }
303
+ }
304
+ },
305
+ // Pending OAuth authorization rows shared by every OAuth-capable plugin.
306
+ // Rows are short-lived and deleted after completion/cancel; the resulting
307
+ // `connection` row is the durable sign-in state.
308
+ oauth2_session: {
309
+ fields: {
310
+ id: { type: "string", required: true },
311
+ scope_id: { type: "string", required: true, index: true },
312
+ plugin_id: { type: "string", required: true, index: true },
313
+ strategy: { type: "string", required: true },
314
+ connection_id: { type: "string", required: true, index: true },
315
+ token_scope: { type: "string", required: true },
316
+ redirect_url: { type: "string", required: true },
317
+ payload: { type: "json", required: true },
318
+ expires_at: { type: "number", required: true, bigint: true },
190
319
  created_at: { type: "date", required: true }
191
320
  }
321
+ },
322
+ // User-authored overrides for tool permissions. Each row is one rule:
323
+ // a glob-ish pattern + an action (approve / require_approval / block).
324
+ // Resolution walks the scope stack innermost-first, then `position`
325
+ // ascending within each scope; first match wins. Plugin-derived
326
+ // annotations from `resolveAnnotations` apply only when no rule
327
+ // matches.
328
+ //
329
+ // Pattern grammar (v1):
330
+ // - `*` every tool id (universal)
331
+ // - `vercel.dns.create` exact tool id
332
+ // - `vercel.dns.*` any tool whose id starts with `vercel.dns.`
333
+ // - `vercel.*` plugin-wide
334
+ // No `**`, no brace expansion, no leading-`*` prefixes (`*foo`, `*.foo`).
335
+ tool_policy: {
336
+ fields: {
337
+ id: { type: "string", required: true },
338
+ scope_id: { type: "string", required: true, index: true },
339
+ pattern: { type: "string", required: true },
340
+ /** "approve" | "require_approval" | "block". */
341
+ action: { type: "string", required: true },
342
+ /** Fractional-indexing key (Jira lexorank style). Lower lex order =
343
+ * higher precedence. New rules default to a key generated above
344
+ * the current minimum. Strings instead of numbers so we can
345
+ * always lengthen the key to insert between two adjacent rows
346
+ * without precision loss; see `fractional-indexing` in
347
+ * `policies.ts`. */
348
+ position: { type: "string", required: true, index: true },
349
+ created_at: { type: "date", required: true },
350
+ updated_at: { type: "date", required: true }
351
+ }
192
352
  }
193
353
  };
194
354
 
195
- // ../sdk/src/secrets.ts
355
+ // ../sdk/src/policies.ts
196
356
  import { Schema as Schema5 } from "effect";
197
- var SecretRef = class extends Schema5.Class("SecretRef")({
357
+ var ToolPolicyActionSchema = Schema5.Literals([
358
+ "approve",
359
+ "require_approval",
360
+ "block"
361
+ ]);
362
+
363
+ // ../sdk/src/secrets.ts
364
+ import { Schema as Schema6 } from "effect";
365
+ var SecretRef = class extends Schema6.Class("SecretRef")({
198
366
  id: SecretId,
199
367
  scopeId: ScopeId,
200
368
  /** Human-readable label (e.g. "Cloudflare API Token") */
201
- name: Schema5.String,
369
+ name: Schema6.String,
202
370
  /** Which provider holds the value */
203
- provider: Schema5.String,
204
- createdAt: Schema5.DateFromNumber
371
+ provider: Schema6.String,
372
+ createdAt: Schema6.Date
205
373
  }) {
206
374
  };
207
- var SetSecretInput = class extends Schema5.Class(
375
+ var SetSecretInput = class extends Schema6.Class(
208
376
  "SetSecretInput"
209
377
  )({
210
378
  id: SecretId,
379
+ /** Scope id to own this secret. Must be one of the executor's
380
+ * configured scopes. */
381
+ scope: ScopeId,
211
382
  /** Display name shown in secret-list UI. */
212
- name: Schema5.String,
383
+ name: Schema6.String,
213
384
  /** The secret value itself — never persisted outside the provider. */
214
- value: Schema5.String,
385
+ value: Schema6.String,
215
386
  /** Optional provider routing. If unset the executor picks the first
216
387
  * writable provider in registration order. */
217
- provider: Schema5.optional(Schema5.String)
388
+ provider: Schema6.optional(Schema6.String)
389
+ }) {
390
+ };
391
+
392
+ // ../sdk/src/secret-backed-value.ts
393
+ import { Effect as Effect3, Schema as Schema7 } from "effect";
394
+ var SecretBackedValue = Schema7.Union([
395
+ Schema7.String,
396
+ Schema7.Struct({
397
+ secretId: Schema7.String,
398
+ prefix: Schema7.optional(Schema7.String)
399
+ })
400
+ ]);
401
+ var SecretBackedMap = Schema7.Record(Schema7.String, SecretBackedValue);
402
+
403
+ // ../sdk/src/connections.ts
404
+ import { Data as Data3, Schema as Schema8 } from "effect";
405
+ var ConnectionProviderState = Schema8.Record(Schema8.String, Schema8.Unknown);
406
+ var ConnectionRef = class extends Schema8.Class("ConnectionRef")({
407
+ id: ConnectionId,
408
+ scopeId: ScopeId,
409
+ provider: Schema8.String,
410
+ identityLabel: Schema8.NullOr(Schema8.String),
411
+ accessTokenSecretId: SecretId,
412
+ refreshTokenSecretId: Schema8.NullOr(SecretId),
413
+ /** Epoch ms when the access token expires; null if not declared. */
414
+ expiresAt: Schema8.NullOr(Schema8.Number),
415
+ /** OAuth-style scope string as returned by the token endpoint. Named
416
+ * `oauthScope` to avoid collision with the executor scope id. */
417
+ oauthScope: Schema8.NullOr(Schema8.String),
418
+ providerState: Schema8.NullOr(ConnectionProviderState),
419
+ createdAt: Schema8.Date,
420
+ updatedAt: Schema8.Date
421
+ }) {
422
+ };
423
+ var TokenMaterial = class extends Schema8.Class("TokenMaterial")({
424
+ /** Target secret id. Plugins typically derive this from the source id
425
+ * + a stable suffix (e.g. `${sourceId}.access_token`). */
426
+ secretId: SecretId,
427
+ /** Display name stamped on the secret row. Only visible to code — the
428
+ * Connections UI hides connection-owned secrets. */
429
+ name: Schema8.String,
430
+ value: Schema8.String
431
+ }) {
432
+ };
433
+ var CreateConnectionInput = class extends Schema8.Class(
434
+ "CreateConnectionInput"
435
+ )({
436
+ id: ConnectionId,
437
+ /** Executor scope id that will own this connection + its backing
438
+ * secrets. This is the sharing boundary: a user scope is personal,
439
+ * an org/workspace scope is shared with descendants. */
440
+ scope: ScopeId,
441
+ provider: Schema8.String,
442
+ identityLabel: Schema8.NullOr(Schema8.String),
443
+ accessToken: TokenMaterial,
444
+ refreshToken: Schema8.NullOr(TokenMaterial),
445
+ expiresAt: Schema8.NullOr(Schema8.Number),
446
+ /** OAuth-style scope string. Distinct from the executor scope above. */
447
+ oauthScope: Schema8.NullOr(Schema8.String),
448
+ providerState: Schema8.NullOr(ConnectionProviderState)
449
+ }) {
450
+ };
451
+ var ConnectionRefreshError = class extends Data3.TaggedError(
452
+ "ConnectionRefreshError"
453
+ ) {
454
+ };
455
+ var UpdateConnectionTokensInput = class extends Schema8.Class(
456
+ "UpdateConnectionTokensInput"
457
+ )({
458
+ id: ConnectionId,
459
+ accessToken: Schema8.String,
460
+ refreshToken: Schema8.optional(Schema8.NullOr(Schema8.String)),
461
+ expiresAt: Schema8.optional(Schema8.NullOr(Schema8.Number)),
462
+ oauthScope: Schema8.optional(Schema8.NullOr(Schema8.String)),
463
+ providerState: Schema8.optional(Schema8.NullOr(ConnectionProviderState)),
464
+ identityLabel: Schema8.optional(Schema8.NullOr(Schema8.String))
218
465
  }) {
219
466
  };
220
467
 
221
468
  // ../sdk/src/elicitation.ts
222
- import { Schema as Schema6 } from "effect";
223
- var FormElicitation = class extends Schema6.TaggedClass()("FormElicitation", {
224
- message: Schema6.String,
469
+ import { Schema as Schema9 } from "effect";
470
+ var FormElicitation = class extends Schema9.TaggedClass()("FormElicitation", {
471
+ message: Schema9.String,
225
472
  /** JSON Schema describing the fields to collect */
226
- requestedSchema: Schema6.Record({ key: Schema6.String, value: Schema6.Unknown })
473
+ requestedSchema: Schema9.Record(Schema9.String, Schema9.Unknown)
227
474
  }) {
228
475
  };
229
- var UrlElicitation = class extends Schema6.TaggedClass()("UrlElicitation", {
230
- message: Schema6.String,
231
- url: Schema6.String,
476
+ var UrlElicitation = class extends Schema9.TaggedClass()("UrlElicitation", {
477
+ message: Schema9.String,
478
+ url: Schema9.String,
232
479
  /** Unique ID so the host can correlate the callback */
233
- elicitationId: Schema6.String
480
+ elicitationId: Schema9.String
234
481
  }) {
235
482
  };
236
- var ElicitationAction = Schema6.Literal("accept", "decline", "cancel");
237
- var ElicitationResponse = class extends Schema6.Class("ElicitationResponse")({
483
+ var ElicitationAction = Schema9.Literals(["accept", "decline", "cancel"]);
484
+ var ElicitationResponse = class extends Schema9.Class("ElicitationResponse")({
238
485
  action: ElicitationAction,
239
486
  /** Present when action is "accept" — the data the user provided */
240
- content: Schema6.optional(Schema6.Record({ key: Schema6.String, value: Schema6.Unknown }))
487
+ content: Schema9.optional(Schema9.Record(Schema9.String, Schema9.Unknown))
241
488
  }) {
242
489
  };
243
- var ElicitationDeclinedError = class extends Schema6.TaggedError()(
490
+ var ElicitationDeclinedError = class extends Schema9.TaggedErrorClass()(
244
491
  "ElicitationDeclinedError",
245
492
  {
246
493
  toolId: ToolId,
247
- action: Schema6.Literal("decline", "cancel")
494
+ action: Schema9.Literals(["decline", "cancel"])
248
495
  }
249
496
  ) {
250
497
  };
251
498
 
252
499
  // ../sdk/src/blob.ts
253
- import { Effect as Effect4 } from "effect";
500
+ import { Effect as Effect6 } from "effect";
501
+
502
+ // ../sdk/src/oauth.ts
503
+ import { Effect as Effect7, Schema as Schema10 } from "effect";
504
+ var OAuthDynamicDcrStrategy = Schema10.Struct({
505
+ kind: Schema10.Literal("dynamic-dcr"),
506
+ /** Scopes to request. Defaults to whatever `scopes_supported`
507
+ * advertises; caller can narrow or extend. */
508
+ scopes: Schema10.optional(Schema10.Array(Schema10.String))
509
+ });
510
+ var OAuthAuthorizationCodeStrategy = Schema10.Struct({
511
+ kind: Schema10.Literal("authorization-code"),
512
+ authorizationEndpoint: Schema10.String,
513
+ tokenEndpoint: Schema10.String,
514
+ /** Expected authorization-server issuer for ID token validation. Some
515
+ * providers use a token endpoint host that differs from issuer, or a
516
+ * path-scoped issuer such as Okta custom authorization servers. */
517
+ issuerUrl: Schema10.optional(Schema10.NullOr(Schema10.String)),
518
+ /** Secret id holding the `client_id`. Using a secret row rather than
519
+ * an inline string so the value lives at the scope where the caller
520
+ * configured it and shadowing behaves consistently. */
521
+ clientIdSecretId: Schema10.String,
522
+ /** Secret id for `client_secret`. Null for public clients using
523
+ * PKCE without a confidential secret. */
524
+ clientSecretSecretId: Schema10.NullOr(Schema10.String),
525
+ scopes: Schema10.Array(Schema10.String),
526
+ /** Separator between scopes. RFC 6749 says space; some providers
527
+ * (GitHub classic) use comma. */
528
+ scopeSeparator: Schema10.optional(Schema10.String),
529
+ /** Provider-specific params injected at authorization URL build time
530
+ * (Google's `access_type=offline`, `prompt=consent`, ...). */
531
+ extraAuthorizationParams: Schema10.optional(
532
+ Schema10.Record(Schema10.String, Schema10.String)
533
+ ),
534
+ /** `"body"` (default) sends client creds in the form body; `"basic"`
535
+ * uses HTTP Basic auth. Stripe-style servers require basic. */
536
+ clientAuth: Schema10.optional(Schema10.Literals(["body", "basic"]))
537
+ });
538
+ var OAuthClientCredentialsStrategy = Schema10.Struct({
539
+ kind: Schema10.Literal("client-credentials"),
540
+ tokenEndpoint: Schema10.String,
541
+ clientIdSecretId: Schema10.String,
542
+ clientSecretSecretId: Schema10.String,
543
+ scopes: Schema10.optional(Schema10.Array(Schema10.String)),
544
+ scopeSeparator: Schema10.optional(Schema10.String),
545
+ clientAuth: Schema10.optional(Schema10.Literals(["body", "basic"]))
546
+ });
547
+ var OAuthStrategy = Schema10.Union([
548
+ OAuthDynamicDcrStrategy,
549
+ OAuthAuthorizationCodeStrategy,
550
+ OAuthClientCredentialsStrategy
551
+ ]);
552
+ var OAuthProviderState = Schema10.Union([
553
+ Schema10.Struct({
554
+ kind: Schema10.Literal("dynamic-dcr"),
555
+ tokenEndpoint: Schema10.String,
556
+ issuerUrl: Schema10.optional(Schema10.NullOr(Schema10.String)),
557
+ authorizationServerUrl: Schema10.optional(Schema10.NullOr(Schema10.String)),
558
+ authorizationServerMetadataUrl: Schema10.NullOr(Schema10.String),
559
+ idTokenSigningAlgValuesSupported: Schema10.optional(
560
+ Schema10.Array(Schema10.String)
561
+ ),
562
+ /** DCR-minted client_id. Embedded inline (not a secret) — DCR
563
+ * clients are public-ish by design; the secret part (if the AS
564
+ * issued one) is a separate secret row. */
565
+ clientId: Schema10.String,
566
+ clientSecretSecretId: Schema10.NullOr(Schema10.String),
567
+ clientAuth: Schema10.Literals(["body", "basic"]),
568
+ scopes: Schema10.Array(Schema10.String).pipe(Schema10.withDecodingDefaultType(Effect7.succeed([]))),
569
+ scopeSeparator: Schema10.optional(Schema10.String),
570
+ scope: Schema10.NullOr(Schema10.String)
571
+ }),
572
+ Schema10.Struct({
573
+ kind: Schema10.Literal("authorization-code"),
574
+ tokenEndpoint: Schema10.String,
575
+ issuerUrl: Schema10.optional(Schema10.NullOr(Schema10.String)),
576
+ clientIdSecretId: Schema10.String,
577
+ clientSecretSecretId: Schema10.NullOr(Schema10.String),
578
+ clientAuth: Schema10.Literals(["body", "basic"]),
579
+ scopes: Schema10.Array(Schema10.String).pipe(Schema10.withDecodingDefaultType(Effect7.succeed([]))),
580
+ scopeSeparator: Schema10.optional(Schema10.String),
581
+ scope: Schema10.NullOr(Schema10.String)
582
+ }),
583
+ Schema10.Struct({
584
+ kind: Schema10.Literal("client-credentials"),
585
+ tokenEndpoint: Schema10.String,
586
+ clientIdSecretId: Schema10.String,
587
+ clientSecretSecretId: Schema10.String,
588
+ scopes: Schema10.Array(Schema10.String),
589
+ scopeSeparator: Schema10.optional(Schema10.String),
590
+ clientAuth: Schema10.Literals(["body", "basic"]),
591
+ scope: Schema10.NullOr(Schema10.String)
592
+ })
593
+ ]);
594
+ var OAuthProbeError = class extends Schema10.TaggedErrorClass()(
595
+ "OAuthProbeError",
596
+ {
597
+ message: Schema10.String
598
+ }
599
+ ) {
600
+ static annotations = { httpApiStatus: 400 };
601
+ };
602
+ var OAuthStartError = class extends Schema10.TaggedErrorClass()(
603
+ "OAuthStartError",
604
+ {
605
+ message: Schema10.String
606
+ }
607
+ ) {
608
+ static annotations = { httpApiStatus: 400 };
609
+ };
610
+ var OAuthCompleteError = class extends Schema10.TaggedErrorClass()(
611
+ "OAuthCompleteError",
612
+ {
613
+ message: Schema10.String,
614
+ /** RFC 6749 §5.2 error code, when the token endpoint returned one.
615
+ * Callers distinguish terminal failures (`invalid_grant` ⇒
616
+ * re-auth required) from transient ones. */
617
+ code: Schema10.optional(Schema10.String)
618
+ }
619
+ ) {
620
+ static annotations = { httpApiStatus: 400 };
621
+ };
622
+ var OAuthSessionNotFoundError = class extends Schema10.TaggedErrorClass()(
623
+ "OAuthSessionNotFoundError",
624
+ {
625
+ sessionId: Schema10.String
626
+ }
627
+ ) {
628
+ static annotations = { httpApiStatus: 404 };
629
+ };
630
+ var OAUTH2_SESSION_TTL_MS = 15 * 60 * 1e3;
631
+
632
+ // ../sdk/src/oauth-helpers.ts
633
+ import { Data as Data4, Effect as Effect8 } from "effect";
634
+ var OAuth2Error = class extends Data4.TaggedError("OAuth2Error") {
635
+ };
636
+
637
+ // ../sdk/src/oauth-service.ts
638
+ import { Effect as Effect10, Schema as Schema12 } from "effect";
639
+
640
+ // ../sdk/src/oauth-discovery.ts
641
+ import { Data as Data5, Effect as Effect9, Result, Schema as Schema11 } from "effect";
642
+ var OAuthDiscoveryError = class extends Data5.TaggedError(
643
+ "OAuthDiscoveryError"
644
+ ) {
645
+ };
646
+ var StringArray = Schema11.Array(Schema11.String);
647
+ var OAuthProtectedResourceMetadataSchema = Schema11.Struct({
648
+ resource: Schema11.optional(Schema11.String),
649
+ authorization_servers: Schema11.optional(StringArray),
650
+ scopes_supported: Schema11.optional(StringArray),
651
+ bearer_methods_supported: Schema11.optional(StringArray),
652
+ resource_documentation: Schema11.optional(Schema11.String)
653
+ }).annotate({ identifier: "OAuthProtectedResourceMetadata" });
654
+ var OAuthAuthorizationServerMetadataSchema = Schema11.Struct({
655
+ issuer: Schema11.String,
656
+ authorization_endpoint: Schema11.String,
657
+ token_endpoint: Schema11.String,
658
+ registration_endpoint: Schema11.optional(Schema11.String),
659
+ scopes_supported: Schema11.optional(StringArray),
660
+ response_types_supported: Schema11.optional(StringArray),
661
+ grant_types_supported: Schema11.optional(StringArray),
662
+ code_challenge_methods_supported: Schema11.optional(StringArray),
663
+ token_endpoint_auth_methods_supported: Schema11.optional(StringArray),
664
+ revocation_endpoint: Schema11.optional(Schema11.String),
665
+ introspection_endpoint: Schema11.optional(Schema11.String),
666
+ userinfo_endpoint: Schema11.optional(Schema11.String),
667
+ id_token_signing_alg_values_supported: Schema11.optional(StringArray)
668
+ }).annotate({ identifier: "OAuthAuthorizationServerMetadata" });
669
+ var OAuthClientInformationSchema = Schema11.Struct({
670
+ client_id: Schema11.String,
671
+ client_secret: Schema11.optional(Schema11.String),
672
+ client_id_issued_at: Schema11.optional(Schema11.Number),
673
+ client_secret_expires_at: Schema11.optional(Schema11.Number),
674
+ registration_access_token: Schema11.optional(Schema11.String),
675
+ registration_client_uri: Schema11.optional(Schema11.String),
676
+ token_endpoint_auth_method: Schema11.optional(Schema11.String),
677
+ grant_types: Schema11.optional(StringArray),
678
+ response_types: Schema11.optional(StringArray),
679
+ redirect_uris: Schema11.optional(StringArray),
680
+ client_name: Schema11.optional(Schema11.String),
681
+ scope: Schema11.optional(Schema11.String)
682
+ }).annotate({ identifier: "OAuthClientInformation" });
683
+ var decodeResourceMetadata = Schema11.decodeUnknownEffect(
684
+ OAuthProtectedResourceMetadataSchema
685
+ );
686
+ var decodeAuthServerMetadata = Schema11.decodeUnknownEffect(
687
+ OAuthAuthorizationServerMetadataSchema
688
+ );
689
+ var decodeClientInformation = Schema11.decodeUnknownEffect(
690
+ OAuthClientInformationSchema
691
+ );
692
+
693
+ // ../sdk/src/oauth-service.ts
694
+ var OAuthAuthorizationServerMetadataJson = Schema12.Record(Schema12.String, Schema12.Unknown);
695
+ var OAuthClientInformationJson = Schema12.Record(Schema12.String, Schema12.Unknown);
696
+ var DynamicDcrSessionPayload = Schema12.Struct({
697
+ kind: Schema12.Literal("dynamic-dcr"),
698
+ identityLabel: Schema12.NullOr(Schema12.String),
699
+ codeVerifier: Schema12.String,
700
+ authorizationServerUrl: Schema12.String,
701
+ authorizationServerMetadataUrl: Schema12.String,
702
+ authorizationServerMetadata: OAuthAuthorizationServerMetadataJson,
703
+ clientInformation: OAuthClientInformationJson,
704
+ resourceMetadataUrl: Schema12.NullOr(Schema12.String),
705
+ resourceMetadata: Schema12.NullOr(
706
+ Schema12.Record(Schema12.String, Schema12.Unknown)
707
+ ),
708
+ scopes: Schema12.Array(Schema12.String)
709
+ });
710
+ var AuthorizationCodeSessionPayload = Schema12.Struct({
711
+ kind: Schema12.Literal("authorization-code"),
712
+ identityLabel: Schema12.NullOr(Schema12.String),
713
+ codeVerifier: Schema12.String,
714
+ authorizationEndpoint: Schema12.String,
715
+ tokenEndpoint: Schema12.String,
716
+ issuerUrl: Schema12.NullOr(Schema12.String).pipe(Schema12.withDecodingDefaultType(Effect10.succeed(null))),
717
+ clientIdSecretId: Schema12.String,
718
+ clientSecretSecretId: Schema12.NullOr(Schema12.String),
719
+ scopes: Schema12.Array(Schema12.String),
720
+ scopeSeparator: Schema12.optional(Schema12.String),
721
+ clientAuth: Schema12.Literals(["body", "basic"])
722
+ });
723
+ var OAuthSessionPayload = Schema12.Union([
724
+ DynamicDcrSessionPayload,
725
+ AuthorizationCodeSessionPayload
726
+ ]);
727
+ var decodeSessionPayload = Schema12.decodeUnknownSync(OAuthSessionPayload);
728
+ var encodeSessionPayload = Schema12.encodeSync(OAuthSessionPayload);
729
+
730
+ // ../sdk/src/executor.ts
731
+ import { Context, Deferred, Effect as Effect12, Option, Result as Result2, Schema as Schema13, Semaphore } from "effect";
732
+
733
+ // ../sdk/src/scoped-adapter.ts
734
+ import { Effect as Effect11 } from "effect";
254
735
 
255
736
  // ../sdk/src/executor.ts
256
- import { Effect as Effect5, FiberRef } from "effect";
257
737
  var collectSchemas = (plugins) => {
258
738
  const merged = { ...coreSchema };
259
739
  for (const plugin of plugins) {
@@ -269,12 +749,13 @@ var collectSchemas = (plugins) => {
269
749
  }
270
750
  return merged;
271
751
  };
272
- var activeAdapterRef = FiberRef.unsafeMake(
273
- null
752
+ var activeAdapterRef = Context.Reference(
753
+ "executor/ActiveAdapter",
754
+ { defaultValue: () => null }
274
755
  );
275
756
 
276
757
  // ../storage-core/src/testing/memory.ts
277
- import { Effect as Effect6 } from "effect";
758
+ import { Effect as Effect13 } from "effect";
278
759
 
279
760
  // src/utils/get-config.ts
280
761
  import { existsSync } from "fs";
@@ -401,7 +882,8 @@ var generateDrizzleSchema = async ({
401
882
  const cols = item.columns.map((c) => `table.${c}`).join(", ");
402
883
  lines.push(` primaryKey({ columns: [${cols}] }),`);
403
884
  } else {
404
- lines.push(` ${item.kind}("${item.name}").on(table.${item.on}),`);
885
+ const cols = Array.isArray(item.on) ? item.on.map((c) => `table.${c}`).join(", ") : `table.${item.on}`;
886
+ lines.push(` ${item.kind}("${item.name}").on(${cols}),`);
405
887
  }
406
888
  }
407
889
  lines.push(`]`);
@@ -410,11 +892,10 @@ var generateDrizzleSchema = async ({
410
892
  if (hasScopeId) {
411
893
  extras.push({ kind: "primaryKey", columns: ["scope_id", "id"] });
412
894
  }
413
- const tableSchema = `export const ${tableKey} = ${dialect}Table("${modelName}", {
414
- id: ${id},
415
- ${Object.entries(fields).filter(([fieldName]) => fieldName !== "id").map(([fieldName, attr]) => {
895
+ const fieldLines = Object.entries(fields).filter(([fieldName]) => fieldName !== "id").map(([fieldName, attr]) => {
416
896
  const physical = attr.fieldName ?? fieldName;
417
- if (attr.index && !attr.unique) {
897
+ const isToolPolicyCompositeField = tableKey === "tool_policy" && (physical === "scope_id" || physical === "position");
898
+ if (attr.index && !attr.unique && !isToolPolicyCompositeField) {
418
899
  extras.push({
419
900
  kind: "index",
420
901
  name: `${tableKey}_${physical}_idx`,
@@ -449,7 +930,17 @@ var generateDrizzleSchema = async ({
449
930
  }
450
931
  }
451
932
  return `${physical}: ${col}${attr.required !== false ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${attr.references.model}.${attr.references.field ?? "id"}, { onDelete: '${attr.references.onDelete || "cascade"}' })` : ""}`;
452
- }).join(",\n ")}
933
+ }).join(",\n ");
934
+ if (tableKey === "tool_policy") {
935
+ extras.push({
936
+ kind: "index",
937
+ name: "tool_policy_scope_id_position_idx",
938
+ on: ["scope_id", "position"]
939
+ });
940
+ }
941
+ const tableSchema = `export const ${tableKey} = ${dialect}Table("${modelName}", {
942
+ id: ${id},
943
+ ${fieldLines}
453
944
  }${assignExtras(extras)});`;
454
945
  code += `
455
946
  ${tableSchema}
@@ -577,7 +1068,9 @@ function generateImport({
577
1068
  if (field.bigint) hasBigint = true;
578
1069
  if (field.type === "json") hasJson = true;
579
1070
  if (field.type === "boolean") hasBoolean = true;
580
- if (field.type === "number" || field.type === "number[]") hasNumber = true;
1071
+ if (field.type === "number" && !field.bigint || field.type === "number[]") {
1072
+ hasNumber = true;
1073
+ }
581
1074
  if (field.type === "date") hasDate = true;
582
1075
  if (field.index && !field.unique) hasIndex = true;
583
1076
  if (field.index && field.unique) hasUniqueIndex = true;