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