@fitzzero/quickdraw-core 5.1.2 → 5.1.3

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.
Files changed (124) hide show
  1. package/README.md +793 -57
  2. package/dist/{admin-DWWrT1h6.d.ts → admin-CS7JB_UH.d.ts} +2 -2
  3. package/dist/{adminSchemas-D4bFKsrb.d.ts → adminSchemas-29cGgrg5.d.ts} +1 -1
  4. package/dist/{auth-DXiSJZaf.d.ts → auth-DtdYjrZ9.d.ts} +11 -7
  5. package/dist/{caller-BT-Mv4bD.d.ts → caller-BTwGl7vm.d.ts} +183 -15
  6. package/dist/chunk-2FDSKLBO.js +82 -0
  7. package/dist/chunk-2FDSKLBO.js.map +1 -0
  8. package/dist/{chunk-GSIPUNJL.js → chunk-64I6MYBC.js} +139 -792
  9. package/dist/chunk-64I6MYBC.js.map +1 -0
  10. package/dist/chunk-7473HK24.js +17 -0
  11. package/dist/chunk-7473HK24.js.map +1 -0
  12. package/dist/chunk-7Y5ROPXL.js +33 -0
  13. package/dist/chunk-7Y5ROPXL.js.map +1 -0
  14. package/dist/chunk-A2RBQD66.js +7 -0
  15. package/dist/chunk-A2RBQD66.js.map +1 -0
  16. package/dist/chunk-ASAMUGHG.js +651 -0
  17. package/dist/chunk-ASAMUGHG.js.map +1 -0
  18. package/dist/{chunk-B2P7AZ25.js → chunk-CYE4UBOB.js} +6 -4
  19. package/dist/chunk-CYE4UBOB.js.map +1 -0
  20. package/dist/chunk-DNP65TD5.js +832 -0
  21. package/dist/chunk-DNP65TD5.js.map +1 -0
  22. package/dist/{chunk-5CGO426C.js → chunk-GYLWEJHW.js} +5 -1
  23. package/dist/chunk-GYLWEJHW.js.map +1 -0
  24. package/dist/{chunk-AONAFOYU.js → chunk-I3JCFS7H.js} +25 -13
  25. package/dist/chunk-I3JCFS7H.js.map +1 -0
  26. package/dist/{chunk-X5CWPX7H.js → chunk-IIQ3WMJK.js} +13 -2
  27. package/dist/chunk-IIQ3WMJK.js.map +1 -0
  28. package/dist/{chunk-6K5BY47X.js → chunk-JVTONQFI.js} +1277 -277
  29. package/dist/chunk-JVTONQFI.js.map +1 -0
  30. package/dist/{chunk-RL4VKLBX.js → chunk-KKQANRLG.js} +2 -2
  31. package/dist/{chunk-RL4VKLBX.js.map → chunk-KKQANRLG.js.map} +1 -1
  32. package/dist/{chunk-GKH3LJ7N.js → chunk-MPQAT55F.js} +38 -205
  33. package/dist/chunk-MPQAT55F.js.map +1 -0
  34. package/dist/chunk-NX2V6SIL.js +202 -0
  35. package/dist/chunk-NX2V6SIL.js.map +1 -0
  36. package/dist/{chunk-7QCUX4TK.js → chunk-NZHA4TZD.js} +72 -175
  37. package/dist/chunk-NZHA4TZD.js.map +1 -0
  38. package/dist/{chunk-MBH6IDSM.js → chunk-OCZJ4EYV.js} +40 -17
  39. package/dist/chunk-OCZJ4EYV.js.map +1 -0
  40. package/dist/{chunk-RJ5I2VO3.js → chunk-PHCURHC7.js} +6 -6
  41. package/dist/chunk-PHCURHC7.js.map +1 -0
  42. package/dist/{chunk-4YO5H5ON.js → chunk-Q4OGQM5I.js} +4 -10
  43. package/dist/chunk-Q4OGQM5I.js.map +1 -0
  44. package/dist/chunk-QSU47XEX.js +13 -0
  45. package/dist/chunk-QSU47XEX.js.map +1 -0
  46. package/dist/{chunk-LCC7HNFP.js → chunk-RZXJTDH5.js} +2 -2
  47. package/dist/{chunk-Z2LZ7IZ7.js → chunk-SN3OZVEQ.js} +5 -31
  48. package/dist/chunk-SN3OZVEQ.js.map +1 -0
  49. package/dist/{chunk-Z5ILULF2.js → chunk-SQ5VUG77.js} +4 -3
  50. package/dist/{chunk-Z5ILULF2.js.map → chunk-SQ5VUG77.js.map} +1 -1
  51. package/dist/chunk-STH5DLQP.js +1192 -0
  52. package/dist/chunk-STH5DLQP.js.map +1 -0
  53. package/dist/{chunk-NMXYENH4.js → chunk-VZFJTKIW.js} +6 -6
  54. package/dist/{chunk-753VJIUP.js → chunk-X4ZU4QH5.js} +43 -9
  55. package/dist/chunk-X4ZU4QH5.js.map +1 -0
  56. package/dist/chunk-XD7SRDUY.js +188 -0
  57. package/dist/chunk-XD7SRDUY.js.map +1 -0
  58. package/dist/chunk-Z7I6SONO.js +825 -0
  59. package/dist/chunk-Z7I6SONO.js.map +1 -0
  60. package/dist/cli/quickdraw-docs.js +131 -113
  61. package/dist/cli/quickdraw-docs.js.map +1 -1
  62. package/dist/client/core.d.ts +387 -0
  63. package/dist/client/core.js +109 -0
  64. package/dist/client/core.js.map +1 -0
  65. package/dist/client/index.d.ts +30 -193
  66. package/dist/client/index.js +56 -217
  67. package/dist/client/index.js.map +1 -1
  68. package/dist/{clientTypes-hWcPUVS9.d.ts → clientTypes-CUUNJwWs.d.ts} +3 -3
  69. package/dist/{connection-CgijdGpT.d.ts → connection-2EeQ_Et0.d.ts} +16 -9
  70. package/dist/{createServer-Cp-Wk500.d.ts → createServer-Bx5HOcYK.d.ts} +37 -9
  71. package/dist/{createTestApp-BB_PkqQ7.d.ts → createTestApp-DAMANT79.d.ts} +36 -9
  72. package/dist/{envelope-DzWyIXjj.d.ts → envelope-BMBaxppV.d.ts} +200 -8
  73. package/dist/{http-DotQ5bj8.d.ts → http-YzLAar3w.d.ts} +15 -50
  74. package/dist/index.d.ts +7 -6
  75. package/dist/index.js +61 -28
  76. package/dist/index.js.map +1 -1
  77. package/dist/{infer-BmoZsL9a.d.ts → infer-Br62cnyW.d.ts} +39 -1
  78. package/dist/{metrics-DW80Exve.d.ts → metrics-CTVpw0gu.d.ts} +2 -2
  79. package/dist/parser.js +2 -1
  80. package/dist/prisma/index.d.ts +13 -6
  81. package/dist/prisma/index.js +155 -9
  82. package/dist/prisma/index.js.map +1 -1
  83. package/dist/remote-N7OUAGOW.js +15 -0
  84. package/dist/remote-N7OUAGOW.js.map +1 -0
  85. package/dist/server/auth/index.d.ts +3 -3
  86. package/dist/server/auth/index.js +5 -3
  87. package/dist/server/auth/index.js.map +1 -1
  88. package/dist/server/index.d.ts +140 -36
  89. package/dist/server/index.js +162 -55
  90. package/dist/server/index.js.map +1 -1
  91. package/dist/server/mcp/index.d.ts +34 -18
  92. package/dist/server/mcp/index.js +29 -12
  93. package/dist/server/mcp/index.js.map +1 -1
  94. package/dist/server/otel.d.ts +3 -3
  95. package/dist/{sharing-UDLn1049.d.ts → sharing-BrsmlDv_.d.ts} +3 -3
  96. package/dist/testing/client.d.ts +13 -13
  97. package/dist/testing/client.js +17 -10
  98. package/dist/testing/client.js.map +1 -1
  99. package/dist/testing/index.d.ts +49 -12
  100. package/dist/testing/index.js +102 -19
  101. package/dist/testing/index.js.map +1 -1
  102. package/dist/testing/mock.d.ts +5 -5
  103. package/dist/testing/mock.js +15 -9
  104. package/dist/tracked-BR5b2O-U.d.ts +43 -0
  105. package/dist/{types-CYliTP65.d.ts → types-CLRCQGnO.d.ts} +4 -3
  106. package/dist/types-tMagHbjy.d.ts +151 -0
  107. package/dist/utils/index.d.ts +16 -4
  108. package/dist/utils/index.js +6 -3
  109. package/package.json +5 -1
  110. package/dist/chunk-4YO5H5ON.js.map +0 -1
  111. package/dist/chunk-5CGO426C.js.map +0 -1
  112. package/dist/chunk-6K5BY47X.js.map +0 -1
  113. package/dist/chunk-753VJIUP.js.map +0 -1
  114. package/dist/chunk-7QCUX4TK.js.map +0 -1
  115. package/dist/chunk-AONAFOYU.js.map +0 -1
  116. package/dist/chunk-B2P7AZ25.js.map +0 -1
  117. package/dist/chunk-GKH3LJ7N.js.map +0 -1
  118. package/dist/chunk-GSIPUNJL.js.map +0 -1
  119. package/dist/chunk-MBH6IDSM.js.map +0 -1
  120. package/dist/chunk-RJ5I2VO3.js.map +0 -1
  121. package/dist/chunk-X5CWPX7H.js.map +0 -1
  122. package/dist/chunk-Z2LZ7IZ7.js.map +0 -1
  123. /package/dist/{chunk-LCC7HNFP.js.map → chunk-RZXJTDH5.js.map} +0 -0
  124. /package/dist/{chunk-NMXYENH4.js.map → chunk-VZFJTKIW.js.map} +0 -0
@@ -1,15 +1,15 @@
1
- import { A as AnyService, d as Caller } from '../../caller-BT-Mv4bD.js';
1
+ import { A as AnyService, d as Caller } from '../../caller-BTwGl7vm.js';
2
2
  import { IncomingHttpHeaders, IncomingMessage } from 'node:http';
3
- import { ap as MethodName, d as StandardSchemaV1, c as InferOutput } from '../../infer-BmoZsL9a.js';
3
+ import { ap as MethodName, d as StandardSchemaV1, c as InferOutput } from '../../infer-Br62cnyW.js';
4
4
  import { Q as QuickdrawError, a as ErrorCode } from '../../errors-S-bxEIBC.js';
5
- import { P as PrincipalOfServices, C as ContractOfServices, D as Dispatcher, H as HttpRouter } from '../../http-DotQ5bj8.js';
6
- import { a as McpContext, b as McpContextOf, M as MaybePromise } from '../../types-CYliTP65.js';
5
+ import { P as PrincipalOfServices, M as McpContextOfServices, C as ContractOfServices, D as Dispatcher, H as HttpRouter } from '../../http-YzLAar3w.js';
6
+ import { M as MaybePromise, P as Principal } from '../../types-CLRCQGnO.js';
7
7
  import { L as Logger } from '../../logger-Yz93KzdV.js';
8
- import { A as AuthenticateResult } from '../../auth-DXiSJZaf.js';
8
+ import { A as AuthenticateResult } from '../../auth-DtdYjrZ9.js';
9
9
  import { Readable, Writable } from 'node:stream';
10
10
  import { A as AllowedOrigin } from '../../origins-kvpxnVcW.js';
11
- import '../../envelope-DzWyIXjj.js';
12
- import '../../metrics-DW80Exve.js';
11
+ import '../../envelope-BMBaxppV.js';
12
+ import '../../metrics-CTVpw0gu.js';
13
13
  import 'socket.io';
14
14
 
15
15
  /** The JSON Schema of a tool's arguments. MCP requires an object schema. */
@@ -72,8 +72,7 @@ interface McpHttpRequest {
72
72
  }
73
73
  /** The session or request a tool call arrives on, as the registry's `principal` and `context` see it. */
74
74
  type McpRequest = McpStdioRequest | McpHttpRequest;
75
- /** The type of `ctx.mcp` for the services of `S`: their app's `QuickdrawTypes["mcp"]`. */
76
- type McpContextOfServices<S extends readonly AnyService[]> = [S[number]] extends [never] ? McpContext : McpContextOf<NonNullable<S[number]["~types"]>>;
75
+
77
76
  /** How a tool call ended: what the tool returned, or why it failed. */
78
77
  type McpCallResult = {
79
78
  readonly ok: true;
@@ -99,6 +98,18 @@ interface McpToolResult {
99
98
  interface McpCallOptions {
100
99
  /** The session or request the call arrived on. */
101
100
  readonly request: McpRequest;
101
+ /**
102
+ * Who the call acts for, when the app signed the caller in itself (its own
103
+ * MCP transport over `callMethod`, an in-process assistant): the
104
+ * registry's `principal` hook is not asked. `null` calls anonymously, and
105
+ * so does `undefined`: the hook is asked only when the key is absent. The
106
+ * `context` hook, bound arguments and the call's concurrency lane see this
107
+ * principal. One that carries no `serviceAccess` gets the grants the
108
+ * server's `auth.loadServiceAccess` loads, at each call, as `qd.caller`
109
+ * gives them; one that carries grants (`{}` included) keeps them. An
110
+ * in-process option: the HTTP routes never read it from a request.
111
+ */
112
+ readonly principal?: Principal | null;
102
113
  /** Cancels the call. Only queries stop early; a mutation runs to its end. */
103
114
  readonly signal?: AbortSignal;
104
115
  /**
@@ -125,8 +136,9 @@ interface McpToolCall<S extends readonly AnyService[] = readonly AnyService[], A
125
136
  */
126
137
  readonly arguments: Args;
127
138
  /**
128
- * Who the call acts for, from the registry's `principal`. `null` only for
129
- * an anonymous caller of a tool with `access: "public"`.
139
+ * Who the call acts for, from the registry's `principal` hook or the
140
+ * call's own `principal` option. `null` only for an anonymous caller of a
141
+ * tool with `access: "public"`.
130
142
  */
131
143
  readonly principal: PrincipalOfServices<S> | null;
132
144
  /** The fields the registry's `context` produced for the call, if any. */
@@ -239,7 +251,9 @@ interface McpRegistryOptions<S extends readonly AnyService[], Tools extends read
239
251
  * Without it every call is anonymous. An HTTP request's queries share the
240
252
  * lane of its bearer token: a hook that authenticates by anything else (a
241
253
  * cookie, an API key header) must refuse a request whose bearer token it
242
- * does not verify, or a caller makes a lane per made-up token.
254
+ * does not verify, or a caller makes a lane per made-up token. A call
255
+ * whose options give `principal` (an app that signed the caller in
256
+ * itself) is not asked about.
243
257
  */
244
258
  readonly principal?: (request: McpRequest) => MaybePromise<AuthenticateResult<PrincipalOfServices<S>>>;
245
259
  /**
@@ -289,16 +303,18 @@ interface McpRegistry {
289
303
  has(name: string): boolean;
290
304
  /**
291
305
  * Calls the tool `name` with the client's `args` in the session of
292
- * `options.request`. Resolves with the tool's value or its failure (an
293
- * unknown name is `NOT_FOUND`), after `options.respond` was given it.
294
- * Never rejects.
306
+ * `options.request`, as `options.principal` when it is given. Resolves
307
+ * with the tool's value or its failure (an unknown name is `NOT_FOUND`),
308
+ * after `options.respond` was given it. Never rejects.
295
309
  */
296
310
  call(name: string, args: unknown, options: McpCallOptions): Promise<McpCallResult>;
297
311
  /**
298
312
  * Calls a method's tool by its service and method name with the method's
299
313
  * `input` as it is, without the tool's argument mapping: the shape 4.1's
300
- * HTTP route took. Bound arguments are filled as for `call`. A method that
301
- * is not a tool is `NOT_FOUND`.
314
+ * HTTP route took. Bound arguments are filled as for `call`, and
315
+ * `options.principal` says who calls as for `call`: an app's own MCP
316
+ * transport over it passes the caller it signed in. A method that is not
317
+ * a tool is `NOT_FOUND`.
302
318
  */
303
319
  callMethod(service: string, method: string, input: unknown, options: McpCallOptions): Promise<McpCallResult>;
304
320
  }
@@ -452,4 +468,4 @@ type McpHttpReply = {
452
468
  */
453
469
  declare function createMcpHttpRouter(options: McpHttpRouterOptions): HttpRouter;
454
470
 
455
- export { type DescribeToolsOptions, MCP_PROTOCOL_VERSION, type McpBindCall, type McpBinder, type McpCallOptions, type McpCallResult, type McpContextOfServices, type McpCustomTool, type McpHttpReply, type McpHttpRequest, type McpHttpRouterOptions, type McpInputSchema, type McpMethodRef, type McpRegistry, type McpRegistryOptions, type McpRequest, type McpStdioRequest, type McpStdioServer, type McpStdioServerOptions, type McpTextContent, type McpTool, type McpToolAccess, type McpToolAnnotations, type McpToolArguments, type McpToolCall, type McpToolInputSchema, type McpToolResult, bootstrapMcpServer, createMcpHttpRouter, createMcpRegistry, createMcpStdioServer, describeTools, toToolResult };
471
+ export { type DescribeToolsOptions, MCP_PROTOCOL_VERSION, type McpBindCall, type McpBinder, type McpCallOptions, type McpCallResult, McpContextOfServices, type McpCustomTool, type McpHttpReply, type McpHttpRequest, type McpHttpRouterOptions, type McpInputSchema, type McpMethodRef, type McpRegistry, type McpRegistryOptions, type McpRequest, type McpStdioRequest, type McpStdioServer, type McpStdioServerOptions, type McpTextContent, type McpTool, type McpToolAccess, type McpToolAnnotations, type McpToolArguments, type McpToolCall, type McpToolInputSchema, type McpToolResult, bootstrapMcpServer, createMcpHttpRouter, createMcpRegistry, createMcpStdioServer, describeTools, toToolResult };
@@ -3,6 +3,7 @@ import {
3
3
  } from "../../chunk-XNLWBZIG.js";
4
4
  import {
5
5
  NEVER_ABORTED,
6
+ callerGrantsOf,
6
7
  checkKind,
7
8
  inputKeys,
8
9
  lazyMembers,
@@ -11,38 +12,42 @@ import {
11
12
  pointerToken,
12
13
  referenced,
13
14
  runtimeOf,
14
- toQuickdrawError
15
- } from "../../chunk-MBH6IDSM.js";
15
+ toQuickdrawError,
16
+ withCallerGrants
17
+ } from "../../chunk-OCZJ4EYV.js";
16
18
  import {
17
19
  describeError
18
- } from "../../chunk-LCC7HNFP.js";
20
+ } from "../../chunk-RZXJTDH5.js";
19
21
  import {
20
22
  originAllowlist
21
23
  } from "../../chunk-NO4M6PO5.js";
22
24
  import {
23
25
  isForbiddenCredential,
24
26
  isJsonRequest,
27
+ isPrincipal,
25
28
  isRefusal,
26
29
  readJsonInput,
27
30
  toPrincipal,
28
31
  unreadable
29
- } from "../../chunk-RJ5I2VO3.js";
32
+ } from "../../chunk-PHCURHC7.js";
30
33
  import "../../chunk-DUBU3BB3.js";
31
34
  import "../../chunk-AK23XSWD.js";
35
+ import {
36
+ consoleLogger
37
+ } from "../../chunk-DKE6QO26.js";
32
38
  import {
33
39
  hasJsonSchema,
34
40
  isStandardSchema
35
41
  } from "../../chunk-47AEXVDM.js";
36
- import "../../chunk-Z2LZ7IZ7.js";
37
- import {
38
- consoleLogger
39
- } from "../../chunk-DKE6QO26.js";
42
+ import "../../chunk-SN3OZVEQ.js";
43
+ import "../../chunk-7Y5ROPXL.js";
40
44
  import {
41
45
  INTERNAL_MESSAGE,
42
46
  QuickdrawError,
43
47
  httpStatus,
44
48
  toWire
45
- } from "../../chunk-4YO5H5ON.js";
49
+ } from "../../chunk-Q4OGQM5I.js";
50
+ import "../../chunk-QSU47XEX.js";
46
51
 
47
52
  // src/server/mcp/tools.ts
48
53
  var JSON_SCHEMA_TARGET = "draft-07";
@@ -347,8 +352,20 @@ async function contextOf(settings, request, principal) {
347
352
  }
348
353
  return fields;
349
354
  }
350
- async function openSession(settings, request) {
351
- const principal = await principalOf(settings, request);
355
+ function givenPrincipal(principal) {
356
+ if (principal === null || principal === void 0) {
357
+ return null;
358
+ }
359
+ if (!isPrincipal(principal)) {
360
+ throw new TypeError(
361
+ "An MCP call's principal must be a principal with a non-empty string userId, or null"
362
+ );
363
+ }
364
+ return principal;
365
+ }
366
+ async function openSession(settings, options) {
367
+ const { request } = options;
368
+ const principal = Object.hasOwn(options, "principal") ? await withCallerGrants(givenPrincipal(options.principal), callerGrantsOf(settings.dispatcher)) : await principalOf(settings, request);
352
369
  const mcp = await contextOf(settings, request, principal);
353
370
  return { principal, mcp, connectionId: laneOf(request, principal) };
354
371
  }
@@ -617,7 +634,7 @@ function resolveRegistry(options) {
617
634
  async function inSession(settings, name, options, run) {
618
635
  let session;
619
636
  try {
620
- session = await openSession(settings, options.request);
637
+ session = await openSession(settings, options);
621
638
  } catch (error) {
622
639
  return settle(settings, options, failure(settings, error, name));
623
640
  }