@keystrokehq/keystroke 1.0.8 → 1.0.9

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 (91) hide show
  1. package/dist/action.cjs +3 -1
  2. package/dist/action.d.cts +3 -3
  3. package/dist/action.d.mts +3 -3
  4. package/dist/action.mjs +2 -2
  5. package/dist/agent.cjs +21 -10
  6. package/dist/agent.cjs.map +1 -1
  7. package/dist/agent.d.cts +2 -2
  8. package/dist/agent.d.mts +2 -2
  9. package/dist/agent.mjs +21 -10
  10. package/dist/agent.mjs.map +1 -1
  11. package/dist/app.cjs +1 -1
  12. package/dist/app.d.cts +2 -2
  13. package/dist/app.d.mts +2 -2
  14. package/dist/app.mjs +1 -1
  15. package/dist/client.cjs +13 -7
  16. package/dist/client.cjs.map +1 -1
  17. package/dist/client.d.cts.map +1 -1
  18. package/dist/client.d.mts.map +1 -1
  19. package/dist/client.mjs +13 -7
  20. package/dist/client.mjs.map +1 -1
  21. package/dist/config.d.cts +1 -1
  22. package/dist/config.d.mts +1 -1
  23. package/dist/credentials.cjs +1 -1
  24. package/dist/credentials.d.cts +1 -1
  25. package/dist/credentials.d.mts +1 -1
  26. package/dist/credentials.mjs +1 -1
  27. package/dist/{dist-DQL6zTI5.cjs → dist-C0fPHFaM.cjs} +20 -11
  28. package/dist/dist-C0fPHFaM.cjs.map +1 -0
  29. package/dist/{dist-DqFdFpiB.mjs → dist-CppO7361.mjs} +92 -9
  30. package/dist/dist-CppO7361.mjs.map +1 -0
  31. package/dist/{dist-C5otI4u3.cjs → dist-DivFQzKG.cjs} +236 -41
  32. package/dist/dist-DivFQzKG.cjs.map +1 -0
  33. package/dist/{dist-DOMwPx7V.cjs → dist-HI6bM6LK.cjs} +103 -8
  34. package/dist/dist-HI6bM6LK.cjs.map +1 -0
  35. package/dist/{dist-IUl7Bexl.mjs → dist-UzTnzZem.mjs} +231 -42
  36. package/dist/dist-UzTnzZem.mjs.map +1 -0
  37. package/dist/{dist-BpkCqbil.mjs → dist-nvW8vbKn.mjs} +20 -11
  38. package/dist/dist-nvW8vbKn.mjs.map +1 -0
  39. package/dist/{index-BMqj40Li.d.cts → index-3P7ec4Vo.d.cts} +4 -2
  40. package/dist/index-3P7ec4Vo.d.cts.map +1 -0
  41. package/dist/{index-nUAXCgEe.d.cts → index-BTz2OMAM.d.cts} +13 -3
  42. package/dist/index-BTz2OMAM.d.cts.map +1 -0
  43. package/dist/{index-8_UEbXaF.d.mts → index-Cq2F2XdS.d.mts} +13 -3
  44. package/dist/index-Cq2F2XdS.d.mts.map +1 -0
  45. package/dist/{index-Dgy9MjuX.d.cts → index-D4dAsbJr.d.cts} +20 -3
  46. package/dist/index-D4dAsbJr.d.cts.map +1 -0
  47. package/dist/{index-CWZAGTad.d.mts → index-D7UUmswR.d.mts} +4 -2
  48. package/dist/index-D7UUmswR.d.mts.map +1 -0
  49. package/dist/{index-BeBgntxT.d.mts → index-DdAOmbQc.d.mts} +9 -16
  50. package/dist/index-DdAOmbQc.d.mts.map +1 -0
  51. package/dist/{index-BY9SPR2h.d.cts → index-Ohwnfidc.d.cts} +9 -16
  52. package/dist/index-Ohwnfidc.d.cts.map +1 -0
  53. package/dist/{index-Bl4VEelg.d.mts → index-Sx9T2i0u.d.mts} +20 -3
  54. package/dist/index-Sx9T2i0u.d.mts.map +1 -0
  55. package/dist/{index-e9f4pcX4.d.cts → index-WT4ULMiw.d.cts} +14 -3
  56. package/dist/index-WT4ULMiw.d.cts.map +1 -0
  57. package/dist/{index-e9f4pcX4.d.mts → index-WT4ULMiw.d.mts} +14 -3
  58. package/dist/index-WT4ULMiw.d.mts.map +1 -0
  59. package/dist/{mistral-wOLLEgb9.cjs → mistral-CSlOhLAJ.cjs} +2 -2
  60. package/dist/{mistral-wOLLEgb9.cjs.map → mistral-CSlOhLAJ.cjs.map} +1 -1
  61. package/dist/{mistral-CMDejXQt.mjs → mistral-StBMjPiK.mjs} +2 -2
  62. package/dist/{mistral-CMDejXQt.mjs.map → mistral-StBMjPiK.mjs.map} +1 -1
  63. package/dist/{sse-DI7TsPKG.mjs → sse-CDOw-yuH.mjs} +2 -2
  64. package/dist/{sse-DI7TsPKG.mjs.map → sse-CDOw-yuH.mjs.map} +1 -1
  65. package/dist/{sse-Dzs73rQw.cjs → sse-CZOklzgA.cjs} +2 -2
  66. package/dist/{sse-Dzs73rQw.cjs.map → sse-CZOklzgA.cjs.map} +1 -1
  67. package/dist/trigger.cjs +1 -1
  68. package/dist/trigger.d.cts +3 -3
  69. package/dist/trigger.d.mts +3 -3
  70. package/dist/trigger.mjs +1 -1
  71. package/dist/workflow.cjs +1 -1
  72. package/dist/workflow.d.cts +2 -2
  73. package/dist/workflow.d.mts +2 -2
  74. package/dist/workflow.mjs +1 -1
  75. package/package.json +1 -1
  76. package/dist/dist-BpkCqbil.mjs.map +0 -1
  77. package/dist/dist-C5otI4u3.cjs.map +0 -1
  78. package/dist/dist-DOMwPx7V.cjs.map +0 -1
  79. package/dist/dist-DQL6zTI5.cjs.map +0 -1
  80. package/dist/dist-DqFdFpiB.mjs.map +0 -1
  81. package/dist/dist-IUl7Bexl.mjs.map +0 -1
  82. package/dist/index-8_UEbXaF.d.mts.map +0 -1
  83. package/dist/index-BMqj40Li.d.cts.map +0 -1
  84. package/dist/index-BY9SPR2h.d.cts.map +0 -1
  85. package/dist/index-BeBgntxT.d.mts.map +0 -1
  86. package/dist/index-Bl4VEelg.d.mts.map +0 -1
  87. package/dist/index-CWZAGTad.d.mts.map +0 -1
  88. package/dist/index-Dgy9MjuX.d.cts.map +0 -1
  89. package/dist/index-e9f4pcX4.d.cts.map +0 -1
  90. package/dist/index-e9f4pcX4.d.mts.map +0 -1
  91. package/dist/index-nUAXCgEe.d.cts.map +0 -1
package/dist/app.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-DOMwPx7V.cjs");
2
+ const require_dist = require("./dist-HI6bM6LK.cjs");
3
3
  require("zod");
4
4
  //#region ../app/dist/index.mjs
5
5
  function appCredentialFor(slug, input) {
package/dist/app.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as Credential, v as ResolvedCredentials } from "./index-e9f4pcX4.cjs";
2
- import { c as WorkflowActionDefinition, r as ActionDefinitionInput } from "./index-Dgy9MjuX.cjs";
1
+ import { n as Credential, y as ResolvedCredentials } from "./index-WT4ULMiw.cjs";
2
+ import { l as WorkflowActionDefinition, r as ActionDefinitionInput } from "./index-D4dAsbJr.cjs";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region ../app/dist/index.d.mts
package/dist/app.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as Credential, v as ResolvedCredentials } from "./index-e9f4pcX4.mjs";
2
- import { c as WorkflowActionDefinition, r as ActionDefinitionInput } from "./index-Bl4VEelg.mjs";
1
+ import { n as Credential, y as ResolvedCredentials } from "./index-WT4ULMiw.mjs";
2
+ import { l as WorkflowActionDefinition, r as ActionDefinitionInput } from "./index-Sx9T2i0u.mjs";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region ../app/dist/index.d.mts
package/dist/app.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as defineAction, y as credential } from "./dist-DqFdFpiB.mjs";
1
+ import { r as defineAction, x as credential } from "./dist-CppO7361.mjs";
2
2
  import "zod";
3
3
  //#region ../app/dist/index.mjs
4
4
  function appCredentialFor(slug, input) {
package/dist/client.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-DHdmVzO2.cjs");
3
- const require_dist = require("./dist-DOMwPx7V.cjs");
3
+ const require_dist = require("./dist-HI6bM6LK.cjs");
4
4
  let ky = require("ky");
5
5
  ky = require_chunk.__toESM(ky, 1);
6
6
  //#region src/client.ts
@@ -24,18 +24,24 @@ function resolveKeystrokeClientTarget(options = {}) {
24
24
  headers: apiKey ? { "x-api-key": apiKey } : {}
25
25
  };
26
26
  }
27
+ function buildExecutePayload(input) {
28
+ const context = require_dist.getRegisteredMcpCredentialContext();
29
+ return {
30
+ app: input.app,
31
+ tool: input.tool,
32
+ arguments: input.arguments ?? {},
33
+ version: input.version,
34
+ ...context?.assignmentTarget ? { assignmentTarget: context.assignmentTarget } : {},
35
+ ...context?.consumerId ? { consumerId: context.consumerId } : {}
36
+ };
37
+ }
27
38
  function createKeystrokeClient(options = {}) {
28
39
  const api = ky.default.create({ ...options.ky });
29
40
  return { tools: { execute: (input) => {
30
41
  const target = resolveKeystrokeClientTarget(options);
31
42
  return api.post(target.executePath, {
32
43
  headers: target.headers,
33
- json: {
34
- app: input.app,
35
- tool: input.tool,
36
- arguments: input.arguments ?? {},
37
- version: input.version
38
- }
44
+ json: buildExecutePayload(input)
39
45
  }).json();
40
46
  } } };
41
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.cjs","names":["getRegisteredProjectScopeId"],"sources":["../src/client.ts"],"sourcesContent":["import { getRegisteredProjectScopeId } from \"@keystrokehq/action\";\nimport ky, { type KyInstance, type Options } from \"ky\";\n\nexport type KeystrokeClientOptions = {\n /** Defaults to process.env.KEYSTROKE_API_KEY */\n apiKey?: string;\n /** Defaults to PUBLIC_PLATFORM_URL, PLATFORM_URL, or http://localhost:3002 */\n platformUrl?: string;\n ky?: Options;\n};\n\ntype KeystrokeClientTarget = {\n executePath: string;\n headers: Record<string, string>;\n};\n\nfunction resolveKeystrokePlatformUrl(options: KeystrokeClientOptions): string {\n return (\n options.platformUrl ??\n process.env.PUBLIC_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n \"http://localhost:3002\"\n ).replace(/\\/+$/, \"\");\n}\n\n/** Worker containers use PLATFORM_URL + /internal/projects/:id/mcp; CLI uses /mcp + org API key. */\nexport function resolveKeystrokeClientTarget(\n options: KeystrokeClientOptions = {},\n): KeystrokeClientTarget {\n const platformUrl = resolveKeystrokePlatformUrl(options);\n const workerToken = process.env.WORKER_INTERNAL_TOKEN?.trim();\n\n // The machine token identifies a worker. The project is the one bound for this run — the job\n // handler resolves it from the agent DB record (resolveAgentProjectId), binds it via\n // runWithProjectScope, and registers the getter so the facade reads it without importing\n // `@keystrokehq/database`. The platform resolves the credential instance server-side from\n // {app, project} (project → org → user). No PROJECT_ID env var.\n if (workerToken) {\n const projectId = getRegisteredProjectScopeId() ?? \"default\";\n return {\n executePath: `${platformUrl}/internal/projects/${encodeURIComponent(projectId)}/mcp/execute`,\n headers: { Authorization: `Bearer ${workerToken}` },\n };\n }\n\n const apiKey = options.apiKey ?? process.env.KEYSTROKE_API_KEY;\n return {\n executePath: `${platformUrl}/mcp/execute`,\n headers: apiKey ? { \"x-api-key\": apiKey } : {},\n };\n}\n\nexport type ExecuteToolInput = {\n app: string;\n tool: string;\n arguments?: Record<string, unknown>;\n /** Pinned provider toolkit version (e.g. `20260501_01`); forwarded to the provider on execute. */\n version: string;\n};\n\nexport type KeystrokeClient = {\n tools: {\n execute: (input: ExecuteToolInput) => Promise<{ ok: boolean; result: unknown }>;\n };\n};\n\nexport function createKeystrokeClient(options: KeystrokeClientOptions = {}): KeystrokeClient {\n const api: KyInstance = ky.create({\n ...options.ky,\n });\n\n return {\n tools: {\n execute: (input) => {\n const target = resolveKeystrokeClientTarget(options);\n return api\n .post(target.executePath, {\n headers: target.headers,\n json: {\n app: input.app,\n tool: input.tool,\n arguments: input.arguments ?? {},\n version: input.version,\n },\n })\n .json<{ ok: boolean; result: unknown }>();\n },\n },\n };\n}\n"],"mappings":";;;;;;AAgBA,SAAS,4BAA4B,SAAyC;CAC5E,QACE,QAAQ,eACR,QAAQ,IAAI,uBACZ,QAAQ,IAAI,gBACZ,yBACA,QAAQ,QAAQ,EAAE;AACtB;;AAGA,SAAgB,6BACd,UAAkC,CAAC,GACZ;CACvB,MAAM,cAAc,4BAA4B,OAAO;CACvD,MAAM,cAAc,QAAQ,IAAI,uBAAuB,KAAK;CAO5D,IAAI,aAAa;EACf,MAAM,YAAYA,aAAAA,4BAA4B,KAAK;EACnD,OAAO;GACL,aAAa,GAAG,YAAY,qBAAqB,mBAAmB,SAAS,EAAE;GAC/E,SAAS,EAAE,eAAe,UAAU,cAAc;EACpD;CACF;CAEA,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAC7C,OAAO;EACL,aAAa,GAAG,YAAY;EAC5B,SAAS,SAAS,EAAE,aAAa,OAAO,IAAI,CAAC;CAC/C;AACF;AAgBA,SAAgB,sBAAsB,UAAkC,CAAC,GAAoB;CAC3F,MAAM,MAAkB,GAAA,QAAG,OAAO,EAChC,GAAG,QAAQ,GACb,CAAC;CAED,OAAO,EACL,OAAO,EACL,UAAU,UAAU;EAClB,MAAM,SAAS,6BAA6B,OAAO;EACnD,OAAO,IACJ,KAAK,OAAO,aAAa;GACxB,SAAS,OAAO;GAChB,MAAM;IACJ,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,WAAW,MAAM,aAAa,CAAC;IAC/B,SAAS,MAAM;GACjB;EACF,CAAC,EACA,KAAuC;CAC5C,EACF,EACF;AACF"}
1
+ {"version":3,"file":"client.cjs","names":["getRegisteredProjectScopeId","getRegisteredMcpCredentialContext"],"sources":["../src/client.ts"],"sourcesContent":["import {\n getRegisteredMcpCredentialContext,\n getRegisteredProjectScopeId,\n} from \"@keystrokehq/action\";\nimport ky, { type KyInstance, type Options } from \"ky\";\n\nexport type KeystrokeClientOptions = {\n /** Defaults to process.env.KEYSTROKE_API_KEY */\n apiKey?: string;\n /** Defaults to PUBLIC_PLATFORM_URL, PLATFORM_URL, or http://localhost:3002 */\n platformUrl?: string;\n ky?: Options;\n};\n\ntype KeystrokeClientTarget = {\n executePath: string;\n headers: Record<string, string>;\n};\n\nfunction resolveKeystrokePlatformUrl(options: KeystrokeClientOptions): string {\n return (\n options.platformUrl ??\n process.env.PUBLIC_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n \"http://localhost:3002\"\n ).replace(/\\/+$/, \"\");\n}\n\n/** Worker containers use PLATFORM_URL + /internal/projects/:id/mcp; CLI uses /mcp + org API key. */\nexport function resolveKeystrokeClientTarget(\n options: KeystrokeClientOptions = {},\n): KeystrokeClientTarget {\n const platformUrl = resolveKeystrokePlatformUrl(options);\n const workerToken = process.env.WORKER_INTERNAL_TOKEN?.trim();\n\n // The machine token identifies a worker. The project is the one bound for this run — the job\n // handler resolves it from the agent DB record (resolveAgentProjectId), binds it via\n // runWithProjectScope, and registers the getter so the facade reads it without importing\n // `@keystrokehq/database`. The platform resolves the credential instance server-side from\n // {app, project} (project → org). User-scoped creds require an explicit binding.\n if (workerToken) {\n const projectId = getRegisteredProjectScopeId() ?? \"default\";\n return {\n executePath: `${platformUrl}/internal/projects/${encodeURIComponent(projectId)}/mcp/execute`,\n headers: { Authorization: `Bearer ${workerToken}` },\n };\n }\n\n const apiKey = options.apiKey ?? process.env.KEYSTROKE_API_KEY;\n return {\n executePath: `${platformUrl}/mcp/execute`,\n headers: apiKey ? { \"x-api-key\": apiKey } : {},\n };\n}\n\nexport type ExecuteToolInput = {\n app: string;\n tool: string;\n arguments?: Record<string, unknown>;\n /** Pinned provider toolkit version (e.g. `20260501_01`); forwarded to the provider on execute. */\n version: string;\n};\n\nfunction buildExecutePayload(input: ExecuteToolInput) {\n const context = getRegisteredMcpCredentialContext();\n return {\n app: input.app,\n tool: input.tool,\n arguments: input.arguments ?? {},\n version: input.version,\n ...(context?.assignmentTarget ? { assignmentTarget: context.assignmentTarget } : {}),\n ...(context?.consumerId ? { consumerId: context.consumerId } : {}),\n };\n}\n\nexport type KeystrokeClient = {\n tools: {\n execute: (input: ExecuteToolInput) => Promise<{ ok: boolean; result: unknown }>;\n };\n};\n\nexport function createKeystrokeClient(options: KeystrokeClientOptions = {}): KeystrokeClient {\n const api: KyInstance = ky.create({\n ...options.ky,\n });\n\n return {\n tools: {\n execute: (input) => {\n const target = resolveKeystrokeClientTarget(options);\n return api\n .post(target.executePath, {\n headers: target.headers,\n json: buildExecutePayload(input),\n })\n .json<{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- {"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;KAGY,sBAAA;kDAEV,MAAA,WAFgC;EAIhC,WAAA;EACA,EAAA,GAAK,OAAO;AAAA;AAAA,KAGT,qBAAA;EACH,WAAA;EACA,OAAA,EAAS,MAAM;AAAA;AALH;AAAA,iBAkBE,4BAAA,CACd,OAAA,GAAS,sBAAA,GACR,qBAAqB;AAAA,KAwBZ,gBAAA;EACV,GAAA;EACA,IAAA;EACA,SAAA,GAAY,MAAM,mBA1ClB;EA4CA,OAAA;AAAA;AAAA,KAGU,eAAA;EACV,KAAA;IACE,OAAA,GAAU,KAAA,EAAO,gBAAA,KAAqB,OAAO;MAAG,EAAA;MAAa,MAAA;IAAA;EAAA;AAAA;AAAA,iBAIjD,qBAAA,CAAsB,OAAA,GAAS,sBAAA,GAA8B,eAAe"}
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;KAMY,sBAAA;kDAEV,MAAA,WAFgC;EAIhC,WAAA;EACA,EAAA,GAAK,OAAO;AAAA;AAAA,KAGT,qBAAA;EACH,WAAA;EACA,OAAA,EAAS,MAAM;AAAA;AALH;AAAA,iBAkBE,4BAAA,CACd,OAAA,GAAS,sBAAA,GACR,qBAAqB;AAAA,KAwBZ,gBAAA;EACV,GAAA;EACA,IAAA;EACA,SAAA,GAAY,MAAM,mBA1ClB;EA4CA,OAAA;AAAA;AAAA,KAeU,eAAA;EACV,KAAA;IACE,OAAA,GAAU,KAAA,EAAO,gBAAA,KAAqB,OAAO;MAAG,EAAA;MAAa,MAAA;IAAA;EAAA;AAAA;AAAA,iBAIjD,qBAAA,CAAsB,OAAA,GAAS,sBAAA,GAA8B,eAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;KAGY,sBAAA;kDAEV,MAAA,WAFgC;EAIhC,WAAA;EACA,EAAA,GAAK,OAAO;AAAA;AAAA,KAGT,qBAAA;EACH,WAAA;EACA,OAAA,EAAS,MAAM;AAAA;AALH;AAAA,iBAkBE,4BAAA,CACd,OAAA,GAAS,sBAAA,GACR,qBAAqB;AAAA,KAwBZ,gBAAA;EACV,GAAA;EACA,IAAA;EACA,SAAA,GAAY,MAAM,mBA1ClB;EA4CA,OAAA;AAAA;AAAA,KAGU,eAAA;EACV,KAAA;IACE,OAAA,GAAU,KAAA,EAAO,gBAAA,KAAqB,OAAO;MAAG,EAAA;MAAa,MAAA;IAAA;EAAA;AAAA;AAAA,iBAIjD,qBAAA,CAAsB,OAAA,GAAS,sBAAA,GAA8B,eAAe"}
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;KAMY,sBAAA;kDAEV,MAAA,WAFgC;EAIhC,WAAA;EACA,EAAA,GAAK,OAAO;AAAA;AAAA,KAGT,qBAAA;EACH,WAAA;EACA,OAAA,EAAS,MAAM;AAAA;AALH;AAAA,iBAkBE,4BAAA,CACd,OAAA,GAAS,sBAAA,GACR,qBAAqB;AAAA,KAwBZ,gBAAA;EACV,GAAA;EACA,IAAA;EACA,SAAA,GAAY,MAAM,mBA1ClB;EA4CA,OAAA;AAAA;AAAA,KAeU,eAAA;EACV,KAAA;IACE,OAAA,GAAU,KAAA,EAAO,gBAAA,KAAqB,OAAO;MAAG,EAAA;MAAa,MAAA;IAAA;EAAA;AAAA;AAAA,iBAIjD,qBAAA,CAAsB,OAAA,GAAS,sBAAA,GAA8B,eAAe"}
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { o as getRegisteredProjectScopeId } from "./dist-DqFdFpiB.mjs";
1
+ import { o as getRegisteredMcpCredentialContext, s as getRegisteredProjectScopeId } from "./dist-CppO7361.mjs";
2
2
  import ky from "ky";
3
3
  //#region src/client.ts
4
4
  function resolveKeystrokePlatformUrl(options) {
@@ -21,18 +21,24 @@ function resolveKeystrokeClientTarget(options = {}) {
21
21
  headers: apiKey ? { "x-api-key": apiKey } : {}
22
22
  };
23
23
  }
24
+ function buildExecutePayload(input) {
25
+ const context = getRegisteredMcpCredentialContext();
26
+ return {
27
+ app: input.app,
28
+ tool: input.tool,
29
+ arguments: input.arguments ?? {},
30
+ version: input.version,
31
+ ...context?.assignmentTarget ? { assignmentTarget: context.assignmentTarget } : {},
32
+ ...context?.consumerId ? { consumerId: context.consumerId } : {}
33
+ };
34
+ }
24
35
  function createKeystrokeClient(options = {}) {
25
36
  const api = ky.create({ ...options.ky });
26
37
  return { tools: { execute: (input) => {
27
38
  const target = resolveKeystrokeClientTarget(options);
28
39
  return api.post(target.executePath, {
29
40
  headers: target.headers,
30
- json: {
31
- app: input.app,
32
- tool: input.tool,
33
- arguments: input.arguments ?? {},
34
- version: input.version
35
- }
41
+ json: buildExecutePayload(input)
36
42
  }).json();
37
43
  } } };
38
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import { getRegisteredProjectScopeId } from \"@keystrokehq/action\";\nimport ky, { type KyInstance, type Options } from \"ky\";\n\nexport type KeystrokeClientOptions = {\n /** Defaults to process.env.KEYSTROKE_API_KEY */\n apiKey?: string;\n /** Defaults to PUBLIC_PLATFORM_URL, PLATFORM_URL, or http://localhost:3002 */\n platformUrl?: string;\n ky?: Options;\n};\n\ntype KeystrokeClientTarget = {\n executePath: string;\n headers: Record<string, string>;\n};\n\nfunction resolveKeystrokePlatformUrl(options: KeystrokeClientOptions): string {\n return (\n options.platformUrl ??\n process.env.PUBLIC_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n \"http://localhost:3002\"\n ).replace(/\\/+$/, \"\");\n}\n\n/** Worker containers use PLATFORM_URL + /internal/projects/:id/mcp; CLI uses /mcp + org API key. */\nexport function resolveKeystrokeClientTarget(\n options: KeystrokeClientOptions = {},\n): KeystrokeClientTarget {\n const platformUrl = resolveKeystrokePlatformUrl(options);\n const workerToken = process.env.WORKER_INTERNAL_TOKEN?.trim();\n\n // The machine token identifies a worker. The project is the one bound for this run — the job\n // handler resolves it from the agent DB record (resolveAgentProjectId), binds it via\n // runWithProjectScope, and registers the getter so the facade reads it without importing\n // `@keystrokehq/database`. The platform resolves the credential instance server-side from\n // {app, project} (project → org → user). No PROJECT_ID env var.\n if (workerToken) {\n const projectId = getRegisteredProjectScopeId() ?? \"default\";\n return {\n executePath: `${platformUrl}/internal/projects/${encodeURIComponent(projectId)}/mcp/execute`,\n headers: { Authorization: `Bearer ${workerToken}` },\n };\n }\n\n const apiKey = options.apiKey ?? process.env.KEYSTROKE_API_KEY;\n return {\n executePath: `${platformUrl}/mcp/execute`,\n headers: apiKey ? { \"x-api-key\": apiKey } : {},\n };\n}\n\nexport type ExecuteToolInput = {\n app: string;\n tool: string;\n arguments?: Record<string, unknown>;\n /** Pinned provider toolkit version (e.g. `20260501_01`); forwarded to the provider on execute. */\n version: string;\n};\n\nexport type KeystrokeClient = {\n tools: {\n execute: (input: ExecuteToolInput) => Promise<{ ok: boolean; result: unknown }>;\n };\n};\n\nexport function createKeystrokeClient(options: KeystrokeClientOptions = {}): KeystrokeClient {\n const api: KyInstance = ky.create({\n ...options.ky,\n });\n\n return {\n tools: {\n execute: (input) => {\n const target = resolveKeystrokeClientTarget(options);\n return api\n .post(target.executePath, {\n headers: target.headers,\n json: {\n app: input.app,\n tool: input.tool,\n arguments: input.arguments ?? {},\n version: input.version,\n },\n })\n .json<{ ok: boolean; result: unknown }>();\n },\n },\n };\n}\n"],"mappings":";;;AAgBA,SAAS,4BAA4B,SAAyC;CAC5E,QACE,QAAQ,eACR,QAAQ,IAAI,uBACZ,QAAQ,IAAI,gBACZ,yBACA,QAAQ,QAAQ,EAAE;AACtB;;AAGA,SAAgB,6BACd,UAAkC,CAAC,GACZ;CACvB,MAAM,cAAc,4BAA4B,OAAO;CACvD,MAAM,cAAc,QAAQ,IAAI,uBAAuB,KAAK;CAO5D,IAAI,aAAa;EACf,MAAM,YAAY,4BAA4B,KAAK;EACnD,OAAO;GACL,aAAa,GAAG,YAAY,qBAAqB,mBAAmB,SAAS,EAAE;GAC/E,SAAS,EAAE,eAAe,UAAU,cAAc;EACpD;CACF;CAEA,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAC7C,OAAO;EACL,aAAa,GAAG,YAAY;EAC5B,SAAS,SAAS,EAAE,aAAa,OAAO,IAAI,CAAC;CAC/C;AACF;AAgBA,SAAgB,sBAAsB,UAAkC,CAAC,GAAoB;CAC3F,MAAM,MAAkB,GAAG,OAAO,EAChC,GAAG,QAAQ,GACb,CAAC;CAED,OAAO,EACL,OAAO,EACL,UAAU,UAAU;EAClB,MAAM,SAAS,6BAA6B,OAAO;EACnD,OAAO,IACJ,KAAK,OAAO,aAAa;GACxB,SAAS,OAAO;GAChB,MAAM;IACJ,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,WAAW,MAAM,aAAa,CAAC;IAC/B,SAAS,MAAM;GACjB;EACF,CAAC,EACA,KAAuC;CAC5C,EACF,EACF;AACF"}
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n getRegisteredMcpCredentialContext,\n getRegisteredProjectScopeId,\n} from \"@keystrokehq/action\";\nimport ky, { type KyInstance, type Options } from \"ky\";\n\nexport type KeystrokeClientOptions = {\n /** Defaults to process.env.KEYSTROKE_API_KEY */\n apiKey?: string;\n /** Defaults to PUBLIC_PLATFORM_URL, PLATFORM_URL, or http://localhost:3002 */\n platformUrl?: string;\n ky?: Options;\n};\n\ntype KeystrokeClientTarget = {\n executePath: string;\n headers: Record<string, string>;\n};\n\nfunction resolveKeystrokePlatformUrl(options: KeystrokeClientOptions): string {\n return (\n options.platformUrl ??\n process.env.PUBLIC_PLATFORM_URL ??\n process.env.PLATFORM_URL ??\n \"http://localhost:3002\"\n ).replace(/\\/+$/, \"\");\n}\n\n/** Worker containers use PLATFORM_URL + /internal/projects/:id/mcp; CLI uses /mcp + org API key. */\nexport function resolveKeystrokeClientTarget(\n options: KeystrokeClientOptions = {},\n): KeystrokeClientTarget {\n const platformUrl = resolveKeystrokePlatformUrl(options);\n const workerToken = process.env.WORKER_INTERNAL_TOKEN?.trim();\n\n // The machine token identifies a worker. The project is the one bound for this run — the job\n // handler resolves it from the agent DB record (resolveAgentProjectId), binds it via\n // runWithProjectScope, and registers the getter so the facade reads it without importing\n // `@keystrokehq/database`. The platform resolves the credential instance server-side from\n // {app, project} (project → org). User-scoped creds require an explicit binding.\n if (workerToken) {\n const projectId = getRegisteredProjectScopeId() ?? \"default\";\n return {\n executePath: `${platformUrl}/internal/projects/${encodeURIComponent(projectId)}/mcp/execute`,\n headers: { Authorization: `Bearer ${workerToken}` },\n };\n }\n\n const apiKey = options.apiKey ?? process.env.KEYSTROKE_API_KEY;\n return {\n executePath: `${platformUrl}/mcp/execute`,\n headers: apiKey ? { \"x-api-key\": apiKey } : {},\n };\n}\n\nexport type ExecuteToolInput = {\n app: string;\n tool: string;\n arguments?: Record<string, unknown>;\n /** Pinned provider toolkit version (e.g. `20260501_01`); forwarded to the provider on execute. */\n version: string;\n};\n\nfunction buildExecutePayload(input: ExecuteToolInput) {\n const context = getRegisteredMcpCredentialContext();\n return {\n app: input.app,\n tool: input.tool,\n arguments: input.arguments ?? {},\n version: input.version,\n ...(context?.assignmentTarget ? { assignmentTarget: context.assignmentTarget } : {}),\n ...(context?.consumerId ? { consumerId: context.consumerId } : {}),\n };\n}\n\nexport type KeystrokeClient = {\n tools: {\n execute: (input: ExecuteToolInput) => Promise<{ ok: boolean; result: unknown }>;\n };\n};\n\nexport function createKeystrokeClient(options: KeystrokeClientOptions = {}): KeystrokeClient {\n const api: KyInstance = ky.create({\n ...options.ky,\n });\n\n return {\n tools: {\n execute: (input) => {\n const target = resolveKeystrokeClientTarget(options);\n return api\n .post(target.executePath, {\n headers: target.headers,\n json: buildExecutePayload(input),\n })\n .json<{ ok: boolean; result: unknown }>();\n },\n },\n };\n}\n"],"mappings":";;;AAmBA,SAAS,4BAA4B,SAAyC;CAC5E,QACE,QAAQ,eACR,QAAQ,IAAI,uBACZ,QAAQ,IAAI,gBACZ,yBACA,QAAQ,QAAQ,EAAE;AACtB;;AAGA,SAAgB,6BACd,UAAkC,CAAC,GACZ;CACvB,MAAM,cAAc,4BAA4B,OAAO;CACvD,MAAM,cAAc,QAAQ,IAAI,uBAAuB,KAAK;CAO5D,IAAI,aAAa;EACf,MAAM,YAAY,4BAA4B,KAAK;EACnD,OAAO;GACL,aAAa,GAAG,YAAY,qBAAqB,mBAAmB,SAAS,EAAE;GAC/E,SAAS,EAAE,eAAe,UAAU,cAAc;EACpD;CACF;CAEA,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAC7C,OAAO;EACL,aAAa,GAAG,YAAY;EAC5B,SAAS,SAAS,EAAE,aAAa,OAAO,IAAI,CAAC;CAC/C;AACF;AAUA,SAAS,oBAAoB,OAAyB;CACpD,MAAM,UAAU,kCAAkC;CAClD,OAAO;EACL,KAAK,MAAM;EACX,MAAM,MAAM;EACZ,WAAW,MAAM,aAAa,CAAC;EAC/B,SAAS,MAAM;EACf,GAAI,SAAS,mBAAmB,EAAE,kBAAkB,QAAQ,iBAAiB,IAAI,CAAC;EAClF,GAAI,SAAS,aAAa,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;CAClE;AACF;AAQA,SAAgB,sBAAsB,UAAkC,CAAC,GAAoB;CAC3F,MAAM,MAAkB,GAAG,OAAO,EAChC,GAAG,QAAQ,GACb,CAAC;CAED,OAAO,EACL,OAAO,EACL,UAAU,UAAU;EAClB,MAAM,SAAS,6BAA6B,OAAO;EACnD,OAAO,IACJ,KAAK,OAAO,aAAa;GACxB,SAAS,OAAO;GAChB,MAAM,oBAAoB,KAAK;EACjC,CAAC,EACA,KAAuC;CAC5C,EACF,EACF;AACF"}
package/dist/config.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { h as OAuthTokenRefreshRegistry } from "./index-e9f4pcX4.cjs";
1
+ import { g as OAuthTokenRefreshRegistry } from "./index-WT4ULMiw.cjs";
2
2
  import { Context, Hono } from "hono";
3
3
 
4
4
  //#region ../oauth/dist/index.d.mts
package/dist/config.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { h as OAuthTokenRefreshRegistry } from "./index-e9f4pcX4.mjs";
1
+ import { g as OAuthTokenRefreshRegistry } from "./index-WT4ULMiw.mjs";
2
2
  import { Context, Hono } from "hono";
3
3
 
4
4
  //#region ../oauth/dist/index.d.mts
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-DOMwPx7V.cjs");
2
+ const require_dist = require("./dist-HI6bM6LK.cjs");
3
3
  exports.CREDENTIAL_SCOPE_TYPES = require_dist.CREDENTIAL_SCOPE_TYPES;
4
4
  exports.credential = require_dist.credential;
5
5
  exports.credentialInputSchema = require_dist.credentialInputSchema;
@@ -1,2 +1,2 @@
1
- import { C as isCredentialInput, S as defineCredential, T as toCredentialRequirement, a as CredentialInput, b as credential, d as DefineOAuthCredentialInput, f as DefineStaticCredentialInput, l as CredentialScopeType, n as Credential, o as CredentialList, p as NormalizeCredential, r as CredentialAuthKind, s as CredentialRequirement, t as CREDENTIAL_SCOPE_TYPES, u as DefineCredentialInput, v as ResolvedCredentials, w as normalizeCredentialList, x as credentialInputSchema } from "./index-e9f4pcX4.cjs";
1
+ import { C as defineCredential, E as toCredentialRequirement, S as credentialInputSchema, T as normalizeCredentialList, c as CredentialRequirement, d as DefineCredentialInput, f as DefineOAuthCredentialInput, i as CredentialAuthKind, m as NormalizeCredential, n as Credential, o as CredentialInput, p as DefineStaticCredentialInput, s as CredentialList, t as CREDENTIAL_SCOPE_TYPES, u as CredentialScopeType, w as isCredentialInput, x as credential, y as ResolvedCredentials } from "./index-WT4ULMiw.cjs";
2
2
  export { CREDENTIAL_SCOPE_TYPES, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeType, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolvedCredentials, credential, credentialInputSchema, defineCredential, isCredentialInput, normalizeCredentialList, toCredentialRequirement };
@@ -1,2 +1,2 @@
1
- import { C as isCredentialInput, S as defineCredential, T as toCredentialRequirement, a as CredentialInput, b as credential, d as DefineOAuthCredentialInput, f as DefineStaticCredentialInput, l as CredentialScopeType, n as Credential, o as CredentialList, p as NormalizeCredential, r as CredentialAuthKind, s as CredentialRequirement, t as CREDENTIAL_SCOPE_TYPES, u as DefineCredentialInput, v as ResolvedCredentials, w as normalizeCredentialList, x as credentialInputSchema } from "./index-e9f4pcX4.mjs";
1
+ import { C as defineCredential, E as toCredentialRequirement, S as credentialInputSchema, T as normalizeCredentialList, c as CredentialRequirement, d as DefineCredentialInput, f as DefineOAuthCredentialInput, i as CredentialAuthKind, m as NormalizeCredential, n as Credential, o as CredentialInput, p as DefineStaticCredentialInput, s as CredentialList, t as CREDENTIAL_SCOPE_TYPES, u as CredentialScopeType, w as isCredentialInput, x as credential, y as ResolvedCredentials } from "./index-WT4ULMiw.mjs";
2
2
  export { CREDENTIAL_SCOPE_TYPES, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeType, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolvedCredentials, credential, credentialInputSchema, defineCredential, isCredentialInput, normalizeCredentialList, toCredentialRequirement };
@@ -1,2 +1,2 @@
1
- import { S as isCredentialInput, T as toCredentialRequirement, b as credentialInputSchema, v as CREDENTIAL_SCOPE_TYPES, w as normalizeCredentialList, x as defineCredential, y as credential } from "./dist-DqFdFpiB.mjs";
1
+ import { C as defineCredential, D as toCredentialRequirement, E as normalizeCredentialList, S as credentialInputSchema, b as CREDENTIAL_SCOPE_TYPES, w as isCredentialInput, x as credential } from "./dist-CppO7361.mjs";
2
2
  export { CREDENTIAL_SCOPE_TYPES, credential, credentialInputSchema, defineCredential, isCredentialInput, normalizeCredentialList, toCredentialRequirement };
@@ -1,5 +1,5 @@
1
- const require_dist = require("./dist-DOMwPx7V.cjs");
2
- const require_dist$1 = require("./dist-C5otI4u3.cjs");
1
+ const require_dist = require("./dist-HI6bM6LK.cjs");
2
+ const require_dist$1 = require("./dist-DivFQzKG.cjs");
3
3
  let zod = require("zod");
4
4
  let node_async_hooks = require("node:async_hooks");
5
5
  //#region ../workflow/dist/index.mjs
@@ -305,7 +305,7 @@ async function runDurableStep(state, options) {
305
305
  metadata
306
306
  }, async () => require_dist$1.captureConsole(async () => {
307
307
  try {
308
- const result = await options.execute();
308
+ const result = await options.execute(correlationId);
309
309
  await eventLog.append({
310
310
  id: `step_completed:${runId}:${correlationId}`,
311
311
  runId,
@@ -344,17 +344,22 @@ function createActionRunner(state, options = {}) {
344
344
  metadataKey: "actionKey",
345
345
  replayMessage: "action replayed from checkpoint",
346
346
  parseCached: (cached) => action.output.parse(cached),
347
- execute: async () => {
347
+ execute: async (correlationId) => {
348
348
  const requirements = withCredentialScopeOverride(require_dist.getActionCredentialRequirements(action), runOptions?.credentialScope);
349
- return require_dist.executeAction(action, input, requirements?.length ? await require_dist$1.resolveActionCredentials(requirements, {
349
+ const credentials = requirements?.length ? await require_dist$1.resolveActionCredentials(requirements, {
350
350
  resolveCredentials: options.resolveCredentials,
351
351
  context: options.credentialContext,
352
352
  oauthAdapter: options.oauthAdapter,
353
353
  consumer: {
354
354
  kind: "action",
355
- name: action.slug
355
+ name: action.slug,
356
+ id: correlationId
356
357
  }
357
- }) : {});
358
+ }) : {};
359
+ return require_dist.runWithMcpCredentialContext({
360
+ ...options.mcpCredentialContext,
361
+ consumerId: correlationId
362
+ }, () => require_dist.executeAction(action, input, credentials));
358
363
  }
359
364
  });
360
365
  }
@@ -373,7 +378,7 @@ function createAgentStepRunner(state, runAgent) {
373
378
  id: options?.id,
374
379
  metadataKey: "agentKey",
375
380
  replayMessage: "agent step replayed from checkpoint",
376
- execute: () => runAgent(agent, input, options?.runPrompt)
381
+ execute: (_correlationId) => runAgent(agent, input, options?.runPrompt)
377
382
  });
378
383
  };
379
384
  }
@@ -390,7 +395,7 @@ function createLlmStepRunner(state, runLlm) {
390
395
  metadataKey: "llmKey",
391
396
  replayMessage: "llm step replayed from checkpoint",
392
397
  parseCached: (cached) => opts.outputSchema ? opts.outputSchema.parse(cached) : cached,
393
- execute: () => runLlm(opts)
398
+ execute: (_correlationId) => runLlm(opts)
394
399
  });
395
400
  }
396
401
  const storage = new node_async_hooks.AsyncLocalStorage();
@@ -455,7 +460,11 @@ async function executeWorkflow(workflow, input, options = {}) {
455
460
  const actionRunner = createActionRunner(state, {
456
461
  resolveCredentials: options.resolveCredentials,
457
462
  credentialContext: options.credentialContext,
458
- oauthAdapter: options.oauthAdapter
463
+ oauthAdapter: options.oauthAdapter,
464
+ mcpCredentialContext: { assignmentTarget: {
465
+ type: "workflow",
466
+ key: workflow.slug
467
+ } }
459
468
  });
460
469
  const ctx = {
461
470
  runId,
@@ -591,4 +600,4 @@ Object.defineProperty(exports, "serializeWorkflowError", {
591
600
  }
592
601
  });
593
602
 
594
- //# sourceMappingURL=dist-DQL6zTI5.cjs.map
603
+ //# sourceMappingURL=dist-C0fPHFaM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dist-C0fPHFaM.cjs","names":["z","withSpan","logSystem","captureConsole","normalizeCredentialList","getActionCredentialRequirements","resolveActionCredentials","runWithMcpCredentialContext","executeAction","AsyncLocalStorage","registerWorkflowRunGetter","getRunSignal","getWorkflowRunHandle"],"sources":["../../workflow/dist/index.mjs"],"sourcesContent":["import { z } from \"zod\";\nimport { executeAction, getActionCredentialRequirements, getRunSignal, getWorkflowRunHandle, normalizeCredentialList, registerWorkflowRunGetter, runWithMcpCredentialContext } from \"@keystrokehq/action\";\nimport { captureConsole, logSystem, withSpan } from \"@keystrokehq/tracing\";\nimport { resolveActionCredentials } from \"@keystrokehq/credentials\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n//#region src/run-canceled-error.ts\nvar RunCanceledError = class extends Error {\n\tconstructor(runId) {\n\t\tsuper(runId ? `Workflow run ${runId} was canceled` : \"Workflow run was canceled\");\n\t\tthis.name = \"RunCanceledError\";\n\t}\n};\nfunction isRunCanceledError(error) {\n\treturn error instanceof RunCanceledError;\n}\n//#endregion\n//#region src/workflow-definition.ts\nconst zodSchema = z.custom((v) => v instanceof z.ZodType, \"must be a Zod schema\");\n/** Runtime validation for an unbranded workflow definition. */\nconst workflowCoreSchema = z.object({\n\tslug: z.string().trim().min(1),\n\tname: z.string().optional(),\n\tdescription: z.string().optional(),\n\tsubscription: z.object({ mode: z.enum([\"system\", \"subscribable\"]).optional() }).optional(),\n\tinput: zodSchema,\n\toutput: zodSchema,\n\trun: z.function()\n});\nconst WORKFLOW = Symbol.for(\"keystroke.workflow\");\n/**\n* Validates brand + shape via `workflowCoreSchema` so discovery and guards\n* reject malformed definitions.\n*/\nfunction isWorkflow(value) {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tif (!(WORKFLOW in value) || value[WORKFLOW] !== true) return false;\n\treturn workflowCoreSchema.safeParse(value).success;\n}\n//#endregion\n//#region src/define-workflow.ts\nfunction defineWorkflow(def) {\n\tconst result = workflowCoreSchema.safeParse(def);\n\tif (!result.success) throw new Error(`Invalid workflow definition: ${formatIssues(result.error.issues)}`);\n\treturn {\n\t\t...result.data,\n\t\t[WORKFLOW]: true\n\t};\n}\nfunction formatIssues(issues) {\n\treturn issues.map((issue) => {\n\t\treturn `${issue.path.length > 0 ? `${issue.path.join(\".\")}: ` : \"\"}${issue.message}`;\n\t}).join(\"; \");\n}\n//#endregion\n//#region src/replay/error.ts\nfunction serializeWorkflowError(error) {\n\tif (error instanceof Error) return {\n\t\tname: error.name,\n\t\tmessage: error.message\n\t};\n\treturn { message: String(error) };\n}\n/** Rebuild an Error from a recorded error so replay re-raises the same failure. */\nfunction deserializeWorkflowError(data) {\n\tconst serialized = data;\n\tconst error = new Error(serialized?.message ?? \"Workflow step failed\");\n\tif (serialized?.name) error.name = serialized.name;\n\treturn error;\n}\n//#endregion\n//#region src/replay/duration.ts\nconst UNIT_MS = {\n\tms: 1,\n\ts: 1e3,\n\tm: 6e4,\n\th: 36e5,\n\td: 864e5\n};\n/** Resolve a sleep duration to an absolute resume time. */\nfunction resolveResumeAt(duration, now = /* @__PURE__ */ new Date()) {\n\tif (duration instanceof Date) return duration;\n\tif (typeof duration === \"number\") return new Date(now.getTime() + Math.max(0, duration));\n\treturn new Date(now.getTime() + parseDurationToMs(duration));\n}\nfunction parseDurationToMs(value) {\n\tconst match = /^(\\d+(?:\\.\\d+)?)\\s*(ms|s|m|h|d)$/.exec(value.trim());\n\tif (!match) throw new Error(`Invalid sleep duration \"${value}\". Use a number of ms, a Date, or a string like \"5s\", \"10m\", \"1h\".`);\n\tconst amount = Number(match[1]);\n\tconst unit = match[2];\n\treturn Math.round(amount * UNIT_MS[unit]);\n}\n//#endregion\n//#region src/replay/events-consumer.ts\n/** Indexes replay events by correlationId for O(1) cache-hit checks during replay. */\nvar EventsConsumer = class {\n\tbyCorrelationId = /* @__PURE__ */ new Map();\n\tconstructor(events) {\n\t\tfor (const event of events) {\n\t\t\tif (!event.correlationId) continue;\n\t\t\tconst list = this.byCorrelationId.get(event.correlationId);\n\t\t\tif (list) list.push(event);\n\t\t\telse this.byCorrelationId.set(event.correlationId, [event]);\n\t\t}\n\t}\n\tevents(correlationId) {\n\t\treturn this.byCorrelationId.get(correlationId) ?? [];\n\t}\n\thasEventType(correlationId, type) {\n\t\treturn this.events(correlationId).some((event) => event.type === type);\n\t}\n\t/**\n\t* Cache lookup for a step. Returns the recorded output on a `step_completed`,\n\t* re-raises the recorded error on a terminal `step_failed` (so a permanently\n\t* failed step is not re-executed), and otherwise reports a miss — including\n\t* when only `step_retrying` events exist (the step re-runs on the next pass).\n\t*/\n\tgetStepResult(correlationId) {\n\t\tconst events = this.events(correlationId);\n\t\tconst failed = events.find((event) => event.type === \"step_failed\");\n\t\tif (failed) throw deserializeWorkflowError(failed.data);\n\t\tconst completed = events.find((event) => event.type === \"step_completed\");\n\t\tif (completed) return {\n\t\t\tcompleted: true,\n\t\t\tresult: completed.data\n\t\t};\n\t\treturn { completed: false };\n\t}\n\t/** Number of prior `step_retrying` events recorded for a step (= failed attempts so far). */\n\tcountRetrying(correlationId) {\n\t\treturn this.events(correlationId).filter((event) => event.type === \"step_retrying\").length;\n\t}\n\tisSleepCompleted(correlationId) {\n\t\treturn this.hasEventType(correlationId, \"sleep_completed\");\n\t}\n\t/** Returns the persisted resumeAt for a scheduled-but-not-completed sleep, if any. */\n\tgetSleepResumeAt(correlationId) {\n\t\tconst scheduled = this.events(correlationId).find((event) => event.type === \"sleep_scheduled\");\n\t\tif (!scheduled) return;\n\t\tconst data = scheduled.data;\n\t\treturn data?.resumeAt ? new Date(data.resumeAt) : void 0;\n\t}\n\tgetHookToken(correlationId) {\n\t\treturn (this.events(correlationId).find((event) => event.type === \"hook_created\")?.data)?.token;\n\t}\n\tgetHookResult(correlationId) {\n\t\tconst resumed = this.events(correlationId).find((event) => event.type === \"hook_resumed\");\n\t\tif (!resumed) return { resolved: false };\n\t\treturn {\n\t\t\tresolved: true,\n\t\t\tpayload: resumed.data?.payload\n\t\t};\n\t}\n};\n//#endregion\n//#region src/replay/suspension.ts\n/** A promise that never settles — returned by a suspending primitive so the body parks. */\nfunction createPendingPromise() {\n\treturn new Promise(() => {});\n}\n/**\n* Collects pending items requested within a single tick and resolves once, so\n* parallel suspensions (e.g. Promise.all of two sleeps) batch into one suspension.\n*/\nvar SuspensionCoordinator = class {\n\titems = /* @__PURE__ */ new Map();\n\tscheduled = false;\n\tresolve;\n\tpromise;\n\tconstructor() {\n\t\tthis.promise = new Promise((resolve) => {\n\t\t\tthis.resolve = resolve;\n\t\t});\n\t}\n\trequest(item) {\n\t\tthis.items.set(item.correlationId, item);\n\t\tif (!this.scheduled) {\n\t\t\tthis.scheduled = true;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.resolve([...this.items.values()]);\n\t\t\t});\n\t\t}\n\t}\n\twaitForSuspension() {\n\t\treturn this.promise;\n\t}\n};\n//#endregion\n//#region src/replay/replay-context.ts\nfunction createReplayState(params) {\n\treturn {\n\t\trunId: params.runId,\n\t\tconsumer: params.consumer,\n\t\tcoordinator: params.coordinator,\n\t\teventLog: params.eventLog,\n\t\tnewEvents: [],\n\t\tnow: params.now ?? /* @__PURE__ */ new Date(),\n\t\thookBaseUrl: params.hookBaseUrl,\n\t\tsleepCounter: 0,\n\t\thookCounter: 0,\n\t\tstepOccurrences: /* @__PURE__ */ new Map(),\n\t\tstepCorrelationIds: /* @__PURE__ */ new Set()\n\t};\n}\n/**\n* Allocate the correlation id for a step. An explicit `.stepId(x)` maps to\n* `step:x` (and must be unique within a run); otherwise the key is\n* `step:<actionKey>#<occurrence>` so that two calls to the same action get\n* distinct, replay-stable ids and inserting an unrelated call never shifts the\n* ids of later calls (unlike a single global ordinal).\n*/\nfunction nextStepCorrelationId(state, actionKey, explicitId) {\n\tif (explicitId !== void 0) {\n\t\tconst correlationId = `step:${explicitId}`;\n\t\tif (state.stepCorrelationIds.has(correlationId)) throw new Error(`Duplicate step id \"${explicitId}\" in workflow run ${state.runId}`);\n\t\tstate.stepCorrelationIds.add(correlationId);\n\t\treturn correlationId;\n\t}\n\tconst occurrence = state.stepOccurrences.get(actionKey) ?? 0;\n\tstate.stepOccurrences.set(actionKey, occurrence + 1);\n\tconst correlationId = `step:${actionKey}#${occurrence}`;\n\tstate.stepCorrelationIds.add(correlationId);\n\treturn correlationId;\n}\nfunction createSleep(state) {\n\treturn function sleep(duration) {\n\t\tconst correlationId = `sleep#${state.sleepCounter++}`;\n\t\tif (state.consumer.isSleepCompleted(correlationId)) return Promise.resolve();\n\t\tconst scheduledResumeAt = state.consumer.getSleepResumeAt(correlationId);\n\t\tconst resumeAt = scheduledResumeAt ?? resolveResumeAt(duration, state.now);\n\t\tif (scheduledResumeAt && resumeAt.getTime() <= state.now.getTime()) {\n\t\t\tstate.newEvents.push({\n\t\t\t\tid: `sleep_completed:${state.runId}:${correlationId}`,\n\t\t\t\trunId: state.runId,\n\t\t\t\ttype: \"sleep_completed\",\n\t\t\t\tcorrelationId\n\t\t\t});\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tif (!scheduledResumeAt) state.newEvents.push({\n\t\t\tid: `sleep_scheduled:${state.runId}:${correlationId}`,\n\t\t\trunId: state.runId,\n\t\t\ttype: \"sleep_scheduled\",\n\t\t\tcorrelationId,\n\t\t\tdata: { resumeAt: resumeAt.toISOString() }\n\t\t});\n\t\tstate.coordinator.request({\n\t\t\tkind: \"sleep\",\n\t\t\tcorrelationId,\n\t\t\tresumeAt\n\t\t});\n\t\treturn createPendingPromise();\n\t};\n}\nfunction createHook(state) {\n\treturn function hook(options) {\n\t\tconst correlationId = `hook#${state.hookCounter++}`;\n\t\tconst token = options?.token ?? state.consumer.getHookToken(correlationId) ?? `hook_${crypto.randomUUID()}`;\n\t\treturn {\n\t\t\ttoken,\n\t\t\tresumeUrl: state.hookBaseUrl ? `${state.hookBaseUrl}/hooks/${token}/resume` : `/hooks/${token}/resume`,\n\t\t\tthen(onFulfilled, onRejected) {\n\t\t\t\tconst result = state.consumer.getHookResult(correlationId);\n\t\t\t\tif (result.resolved) {\n\t\t\t\t\tconst payload = options?.schema ? options.schema.parse(result.payload) : result.payload;\n\t\t\t\t\treturn Promise.resolve(payload).then(onFulfilled, onRejected);\n\t\t\t\t}\n\t\t\t\tif (!state.consumer.hasEventType(correlationId, \"hook_created\")) state.newEvents.push({\n\t\t\t\t\tid: `hook_created:${state.runId}:${correlationId}`,\n\t\t\t\t\trunId: state.runId,\n\t\t\t\t\ttype: \"hook_created\",\n\t\t\t\t\tcorrelationId,\n\t\t\t\t\tdata: { token }\n\t\t\t\t});\n\t\t\t\tstate.coordinator.request({\n\t\t\t\t\tkind: \"hook\",\n\t\t\t\t\tcorrelationId,\n\t\t\t\t\ttoken\n\t\t\t\t});\n\t\t\t\treturn createPendingPromise().then(onFulfilled, onRejected);\n\t\t\t}\n\t\t};\n\t};\n}\n//#endregion\n//#region src/run-durable-step.ts\n/**\n* Shared durable-step shell: resolve a stable `correlation_id`, short-circuit\n* from the event log on a cache hit, otherwise execute and append\n* `step_completed` immediately (per-step crash durability). A thrown step\n* appends `step_retrying` (non-fatal, re-run on the next attempt) and\n* rethrows; the terminal `step_failed` is written by the job handler once the\n* queue exhausts retries.\n*/\nasync function runDurableStep(state, options) {\n\tconst { runId, consumer, eventLog } = state;\n\tgetRunSignal().throwIfAborted();\n\tconst correlationId = nextStepCorrelationId(state, options.key, options.id);\n\tconst cached = consumer.getStepResult(correlationId);\n\tconst metadata = {\n\t\trunId,\n\t\t[options.metadataKey]: options.key,\n\t\tcorrelationId\n\t};\n\tif (cached.completed) {\n\t\tawait withSpan({\n\t\t\tkind: options.kind,\n\t\t\tname: options.key,\n\t\t\trefId: `${runId}:${correlationId}`,\n\t\t\tmetadata: {\n\t\t\t\t...metadata,\n\t\t\t\treplayed: true\n\t\t\t}\n\t\t}, async () => {\n\t\t\tawait logSystem(\"info\", options.replayMessage, metadata);\n\t\t});\n\t\treturn options.parseCached ? options.parseCached(cached.result) : cached.result;\n\t}\n\treturn withSpan({\n\t\tkind: options.kind,\n\t\tname: options.key,\n\t\trefId: `${runId}:${correlationId}`,\n\t\tmetadata\n\t}, async () => captureConsole(async () => {\n\t\ttry {\n\t\t\tconst result = await options.execute(correlationId);\n\t\t\tawait eventLog.append({\n\t\t\t\tid: `step_completed:${runId}:${correlationId}`,\n\t\t\t\trunId,\n\t\t\t\ttype: \"step_completed\",\n\t\t\t\tcorrelationId,\n\t\t\t\tdata: result\n\t\t\t});\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tconst attempt = consumer.countRetrying(correlationId);\n\t\t\tawait eventLog.append({\n\t\t\t\tid: `step_retrying:${runId}:${correlationId}:${attempt}`,\n\t\t\t\trunId,\n\t\t\t\ttype: \"step_retrying\",\n\t\t\t\tcorrelationId,\n\t\t\t\tdata: serializeWorkflowError(error)\n\t\t\t});\n\t\t\tstate.failedCorrelationId = correlationId;\n\t\t\tthrow error;\n\t\t}\n\t}));\n}\n//#endregion\n//#region src/create-action-runner.ts\nfunction withCredentialScopeOverride(requirements, scope) {\n\tif (!requirements || !scope) return requirements;\n\treturn normalizeCredentialList(requirements).map((requirement) => ({\n\t\t...requirement,\n\t\tscope\n\t}));\n}\n/** Builds the per-run action runner; durability lives in {@link runDurableStep}. */\nfunction createActionRunner(state, options = {}) {\n\treturn (action, input, runOptions) => runDurableStep(state, {\n\t\tkind: \"action\",\n\t\tkey: action.slug,\n\t\tid: runOptions?.id,\n\t\tmetadataKey: \"actionKey\",\n\t\treplayMessage: \"action replayed from checkpoint\",\n\t\tparseCached: (cached) => action.output.parse(cached),\n\t\texecute: async (correlationId) => {\n\t\t\tconst requirements = withCredentialScopeOverride(getActionCredentialRequirements(action), runOptions?.credentialScope);\n\t\t\tconst credentials = requirements?.length ? await resolveActionCredentials(requirements, {\n\t\t\t\tresolveCredentials: options.resolveCredentials,\n\t\t\t\tcontext: options.credentialContext,\n\t\t\t\toauthAdapter: options.oauthAdapter,\n\t\t\t\tconsumer: {\n\t\t\t\t\tkind: \"action\",\n\t\t\t\t\tname: action.slug,\n\t\t\t\t\tid: correlationId\n\t\t\t\t}\n\t\t\t}) : {};\n\t\t\treturn runWithMcpCredentialContext({\n\t\t\t\t...options.mcpCredentialContext,\n\t\t\t\tconsumerId: correlationId\n\t\t\t}, () => executeAction(action, input, credentials));\n\t\t}\n\t});\n}\n//#endregion\n//#region src/create-agent-step-runner.ts\n/**\n* Builds the per-run agent runner: each `agent.prompt()` in a workflow body\n* becomes a durable step keyed `step:<agentKey>#<occurrence>` (same scheme as\n* actions). The actual prompt execution is delegated to `runAgent`, supplied\n* by the host (server) via `executeWorkflow({ runAgent })`.\n*/\nfunction createAgentStepRunner(state, runAgent) {\n\treturn (agent, input, options) => {\n\t\tconst slug = agent.slug;\n\t\treturn runDurableStep(state, {\n\t\t\tkind: \"agent_session\",\n\t\t\tkey: slug,\n\t\t\tid: options?.id,\n\t\t\tmetadataKey: \"agentKey\",\n\t\t\treplayMessage: \"agent step replayed from checkpoint\",\n\t\t\texecute: (_correlationId) => runAgent(agent, input, options?.runPrompt)\n\t\t});\n\t};\n}\n//#endregion\n//#region src/create-llm-step-runner.ts\n/**\n* Builds the per-run LLM runner: each `promptLlm()` in a workflow body becomes a\n* durable step keyed `step:promptLlm#<occurrence>`. The actual LLM call is\n* delegated to `runLlm`, supplied by the host (server) via `executeWorkflow({ runLlm })`.\n*/\nfunction createLlmStepRunner(state, runLlm) {\n\treturn (opts) => runDurableStep(state, {\n\t\tkind: \"llm\",\n\t\tkey: \"promptLlm\",\n\t\tid: opts.stepId,\n\t\tmetadataKey: \"llmKey\",\n\t\treplayMessage: \"llm step replayed from checkpoint\",\n\t\tparseCached: (cached) => opts.outputSchema ? opts.outputSchema.parse(cached) : cached,\n\t\texecute: (_correlationId) => runLlm(opts)\n\t});\n}\n//#endregion\n//#region src/run-context.ts\nconst storage = new AsyncLocalStorage();\nregisterWorkflowRunGetter(() => {\n\tconst store = storage.getStore();\n\tif (!store) return;\n\treturn {\n\t\tactionRunner: store.actionRunner,\n\t\tagentRunner: store.agentRunner,\n\t\tllmRunner: store.llmRunner\n\t};\n});\nfunction runWithWorkflowContext(store, fn) {\n\treturn storage.run(store, fn);\n}\n//#endregion\n//#region src/replay/memory-event-log.ts\n/** In-memory durable log for inline execution and tests. */\nvar MemoryEventLog = class {\n\tevents = [];\n\tids = /* @__PURE__ */ new Set();\n\tasync append(event) {\n\t\tconst id = event.id ?? crypto.randomUUID();\n\t\tif (this.ids.has(id)) return false;\n\t\tthis.ids.add(id);\n\t\tthis.events.push({\n\t\t\tid,\n\t\t\trunId: event.runId,\n\t\t\tseq: this.events.length,\n\t\t\ttype: event.type,\n\t\t\tcorrelationId: event.correlationId ?? null,\n\t\t\tdata: event.data ?? null\n\t\t});\n\t\treturn true;\n\t}\n\tasync listReplay(runId) {\n\t\treturn this.events.filter((event) => event.runId === runId).map((event) => ({ ...event }));\n\t}\n};\n//#endregion\n//#region src/execute-workflow.ts\n/**\n* The single way to run a workflow: replay its event log from the top, execute\n* un-cached primitives, and either complete/fail or suspend at the first\n* un-satisfied sleep/hook. New events (sleep_scheduled/sleep_completed/\n* hook_created/run_completed/run_failed) are flushed before returning.\n*\n* Durability comes entirely from the log — a suspended run resumes by calling\n* this again with the same `runId` and event log once the sleep is due or the\n* hook is resumed.\n*/\nasync function executeWorkflow(workflow, input, options = {}) {\n\tconst runId = options.runId ?? crypto.randomUUID();\n\tconst eventLog = options.eventLog ?? new MemoryEventLog();\n\tconst signal = getRunSignal();\n\tconst consumer = new EventsConsumer(await eventLog.listReplay(runId));\n\tconst coordinator = new SuspensionCoordinator();\n\tconst state = createReplayState({\n\t\trunId,\n\t\tconsumer,\n\t\tcoordinator,\n\t\teventLog,\n\t\thookBaseUrl: options.hookBaseUrl,\n\t\tnow: options.now\n\t});\n\tconst actionRunner = createActionRunner(state, {\n\t\tresolveCredentials: options.resolveCredentials,\n\t\tcredentialContext: options.credentialContext,\n\t\toauthAdapter: options.oauthAdapter,\n\t\tmcpCredentialContext: { assignmentTarget: {\n\t\t\ttype: \"workflow\",\n\t\t\tkey: workflow.slug\n\t\t} }\n\t});\n\tconst ctx = {\n\t\trunId,\n\t\tsleep: createSleep(state),\n\t\thook: createHook(state),\n\t\t...options.context\n\t};\n\tconst agentRunner = options.runAgent ? createAgentStepRunner(state, options.runAgent) : void 0;\n\tconst llmRunner = options.runLlm ? createLlmStepRunner(state, options.runLlm) : void 0;\n\tconst validatedInput = workflow.input.parse(input);\n\tconst bodyPromise = runWithWorkflowContext({\n\t\tactionRunner,\n\t\tagentRunner,\n\t\tllmRunner,\n\t\trunId\n\t}, () => captureConsole(async () => workflow.run(validatedInput, ctx)));\n\tlet onAbort;\n\tconst waitForAbort = signal.aborted ? Promise.resolve({ type: \"canceled\" }) : new Promise((resolve) => {\n\t\tonAbort = () => resolve({ type: \"canceled\" });\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n\tconst outcome = await Promise.race([\n\t\tbodyPromise.then((output) => ({\n\t\t\ttype: \"done\",\n\t\t\toutput\n\t\t}), (error) => ({\n\t\t\ttype: \"error\",\n\t\t\terror\n\t\t})),\n\t\tcoordinator.waitForSuspension().then((items) => ({\n\t\t\ttype: \"suspended\",\n\t\t\titems\n\t\t})),\n\t\twaitForAbort\n\t]);\n\tif (onAbort) signal.removeEventListener(\"abort\", onAbort);\n\tlet result;\n\tif (outcome.type === \"suspended\") {\n\t\tbodyPromise.catch(() => {});\n\t\tresult = {\n\t\t\tstatus: \"suspended\",\n\t\t\titems: outcome.items\n\t\t};\n\t} else if (outcome.type === \"done\") {\n\t\tconst output = workflow.output.parse(outcome.output);\n\t\tstate.newEvents.push({\n\t\t\tid: `run_completed:${runId}`,\n\t\t\trunId,\n\t\t\ttype: \"run_completed\",\n\t\t\tdata: { output }\n\t\t});\n\t\tresult = {\n\t\t\tstatus: \"completed\",\n\t\t\toutput\n\t\t};\n\t} else if (outcome.type === \"canceled\" || isRunCanceledError(outcome.error)) {\n\t\tbodyPromise.catch(() => {});\n\t\tstate.newEvents.push({\n\t\t\tid: `run_canceled:${runId}`,\n\t\t\trunId,\n\t\t\ttype: \"run_canceled\"\n\t\t});\n\t\tresult = { status: \"canceled\" };\n\t} else result = {\n\t\tstatus: \"failed\",\n\t\terror: outcome.error,\n\t\tfailedCorrelationId: state.failedCorrelationId\n\t};\n\tfor (const event of state.newEvents) await eventLog.append(event);\n\treturn result;\n}\n//#endregion\n//#region src/prompt-llm.ts\nfunction promptLlm(prompt, opts) {\n\tconst handle = getWorkflowRunHandle();\n\tif (!handle?.llmRunner) throw new Error(\"promptLlm must run inside a workflow with an injected llm executor (executeWorkflow({ runLlm })).\");\n\treturn handle.llmRunner({\n\t\tprompt,\n\t\t...opts\n\t});\n}\n//#endregion\nexport { MemoryEventLog, RunCanceledError, defineWorkflow, deserializeWorkflowError, execute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AAS;GACR,QAAQ;GACR,OAAO,QAAQ;EAChB;CACD,OAAO,IAAI,QAAQ,SAAS,QAAQ;EACnC,MAAM,SAAS,SAAS,OAAO,MAAM,QAAQ,MAAM;EACnD,MAAM,UAAU,KAAK;GACpB,IAAI,iBAAiB;GACrB;GACA,MAAM;GACN,MAAM,EAAE,OAAO;EAChB,CAAC;EACD,SAAS;GACR,QAAQ;GACR;EACD;CACD,OAAO,IAAI,QAAQ,SAAS,cAAc,mBAAmB,QAAQ,KAAK,GAAG;EAC5E,YAAY,YAAY,CAAC,CAAC;EAC1B,MAAM,UAAU,KAAK;GACpB,IAAI,gBAAgB;GACpB;GACA,MAAM;EACP,CAAC;EACD,SAAS,EAAE,QAAQ,WAAW;CAC/B,OAAO,SAAS;EACf,QAAQ;EACR,OAAO,QAAQ;EACf,qBAAqB,MAAM;CAC5B;CACA,KAAK,MAAM,SAAS,MAAM,WAAW,MAAM,SAAS,OAAO,KAAK;CAChE,OAAO;AACR;AAGA,SAAS,UAAU,QAAQ,MAAM;CAChC,MAAM,SAASS,aAAAA,qBAAqB;CACpC,IAAI,CAAC,QAAQ,WAAW,MAAM,IAAI,MAAM,mGAAmG;CAC3I,OAAO,OAAO,UAAU;EACvB;EACA,GAAG;CACJ,CAAC;AACF"}
@@ -683,7 +683,8 @@ const storedRouteManifestEntryV2Schema = z.discriminatedUnion("kind", [
683
683
  systemPrompt: z.string(),
684
684
  toolCount: z.number().int().nonnegative(),
685
685
  credentialCount: z.number().int().nonnegative(),
686
- credentialKeys: z.array(z.string()).default([])
686
+ appSlugs: z.array(z.string()).default([]),
687
+ toolSlugs: z.array(z.string()).default([])
687
688
  }),
688
689
  z.object({
689
690
  kind: z.literal("workflow"),
@@ -1117,6 +1118,45 @@ z.object({
1117
1118
  }).refine((input) => input.label !== void 0 || input.isDefault !== void 0 || input.value !== void 0, { message: "At least one field is required" });
1118
1119
  z.array(AppCredentialSummarySchema);
1119
1120
  z.array(AppCredentialSummarySchema);
1121
+ const CredentialAssignmentTargetTypeSchema = z.enum(["workflow", "agent"]);
1122
+ const CredentialAssignmentRecordSchema = z.object({
1123
+ id: z.string(),
1124
+ targetType: CredentialAssignmentTargetTypeSchema,
1125
+ targetKey: z.string(),
1126
+ consumerId: z.string(),
1127
+ credentialSlug: z.string(),
1128
+ instanceId: z.string(),
1129
+ credential: z.string().optional(),
1130
+ scopeType: z.enum([
1131
+ "organization",
1132
+ "project",
1133
+ "user"
1134
+ ]).optional(),
1135
+ createdAt: z.string(),
1136
+ updatedAt: z.string()
1137
+ });
1138
+ z.object({ assignments: z.array(CredentialAssignmentRecordSchema) });
1139
+ z.object({
1140
+ targetType: CredentialAssignmentTargetTypeSchema,
1141
+ targetKey: z.string().min(1),
1142
+ /** Omit or '*' for wildcard assignment. */
1143
+ consumerId: z.string().optional(),
1144
+ credential: z.string().min(1)
1145
+ });
1146
+ z.object({
1147
+ targetType: CredentialAssignmentTargetTypeSchema,
1148
+ targetKey: z.string().min(1)
1149
+ });
1150
+ z.object({
1151
+ targetType: CredentialAssignmentTargetTypeSchema,
1152
+ targetKey: z.string().min(1)
1153
+ });
1154
+ const CredentialConsumerSummarySchema = z.object({
1155
+ consumerId: z.string(),
1156
+ label: z.string(),
1157
+ appSlugs: z.array(z.string())
1158
+ });
1159
+ z.object({ consumers: z.array(CredentialConsumerSummarySchema) });
1120
1160
  const McpConnectionStatusSchema = z.enum([
1121
1161
  "INITIATED",
1122
1162
  "ACTIVE",
@@ -1147,12 +1187,20 @@ const KeystrokeCredentialSchema = z.object({
1147
1187
  entityId: z.string(),
1148
1188
  instanceId: z.string()
1149
1189
  });
1190
+ const McpCredentialAssignmentTargetSchema = z.object({
1191
+ type: CredentialAssignmentTargetTypeSchema,
1192
+ key: z.string().trim().min(1)
1193
+ });
1150
1194
  z.object({
1151
1195
  app: z.string().trim().min(1),
1152
1196
  tool: z.string().trim().min(1),
1153
1197
  arguments: z.record(z.string(), z.unknown()).default({}),
1154
1198
  /** Pinned provider toolkit version, sourced from the app definition; forwarded to the provider. */
1155
- version: z.string().trim().min(1)
1199
+ version: z.string().trim().min(1),
1200
+ /** When set, platform MCP resolve checks credential assignments before scope defaults. */
1201
+ assignmentTarget: McpCredentialAssignmentTargetSchema.optional(),
1202
+ /** Tool/step consumer id for assignment lookup (action slug or workflow step correlation id). */
1203
+ consumerId: z.string().trim().min(1).optional()
1156
1204
  });
1157
1205
  const TeamRequestTypeSchema = z.enum([
1158
1206
  "org-deletion",
@@ -1794,7 +1842,9 @@ z.object({
1794
1842
  });
1795
1843
  const CredentialInstanceRecordSchema = z.object({
1796
1844
  id: z.string(),
1797
- key: z.string(),
1845
+ appSlug: z.string(),
1846
+ slug: z.string(),
1847
+ name: z.string().nullable(),
1798
1848
  scopeType: CredentialScopeTypeSchema,
1799
1849
  scopeId: z.string().nullable(),
1800
1850
  label: z.string().nullable(),
@@ -1804,6 +1854,8 @@ const CredentialInstanceRecordSchema = z.object({
1804
1854
  z.object({ instances: z.array(CredentialInstanceRecordSchema) });
1805
1855
  z.object({
1806
1856
  key: z.string().min(1),
1857
+ slug: z.string().min(1).optional(),
1858
+ name: z.string().nullable().optional(),
1807
1859
  scopeType: CredentialScopeTypeSchema,
1808
1860
  scopeId: z.string().nullable().optional(),
1809
1861
  label: z.string().nullable().optional(),
@@ -1811,6 +1863,8 @@ z.object({
1811
1863
  value: z.record(z.string(), z.unknown()).refine((value) => Object.keys(value).length > 0, { message: "value must be a non-empty object" })
1812
1864
  });
1813
1865
  z.object({
1866
+ slug: z.string().min(1).optional(),
1867
+ name: z.string().nullable().optional(),
1814
1868
  label: z.string().nullable().optional(),
1815
1869
  isDefault: z.boolean().optional(),
1816
1870
  value: z.record(z.string(), z.unknown()).refine((value) => Object.keys(value).length > 0, { message: "value must be a non-empty object" }).optional()
@@ -2334,11 +2388,11 @@ function runWithRunSignal(signal, fn) {
2334
2388
  function getRunSignal() {
2335
2389
  return runSignalStorage.getStore() ?? NEVER_ABORT;
2336
2390
  }
2337
- const REGISTRY_KEY$1 = Symbol.for("keystroke.workflowRunGetter");
2391
+ const REGISTRY_KEY$2 = Symbol.for("keystroke.workflowRunGetter");
2338
2392
  function registry$1() {
2339
2393
  const globalScope = globalThis;
2340
- if (!globalScope[REGISTRY_KEY$1]) globalScope[REGISTRY_KEY$1] = {};
2341
- return globalScope[REGISTRY_KEY$1];
2394
+ if (!globalScope[REGISTRY_KEY$2]) globalScope[REGISTRY_KEY$2] = {};
2395
+ return globalScope[REGISTRY_KEY$2];
2342
2396
  }
2343
2397
  function registerWorkflowRunGetter(fn) {
2344
2398
  registry$1().getter = fn;
@@ -2429,6 +2483,32 @@ async function executeAction(action, input, credentials = {}) {
2429
2483
  const result = await action.run(validatedInput, credentials);
2430
2484
  return action.output.parse(result);
2431
2485
  }
2486
+ /**
2487
+ * The store lives in a global `Symbol.for` slot rather than a module-level `const` so a single
2488
+ * `AsyncLocalStorage` instance is shared even when the bundled `@keystrokehq/keystroke` facade
2489
+ * ships its own copy of this module: the worker sets context via `runWithMcpCredentialContext`
2490
+ * and the facade reads it via `getRegisteredMcpCredentialContext` against the same instance.
2491
+ */
2492
+ const REGISTRY_KEY$1 = Symbol.for("keystroke.mcpCredentialContextStore");
2493
+ function store() {
2494
+ const globalScope = globalThis;
2495
+ if (!globalScope[REGISTRY_KEY$1]) globalScope[REGISTRY_KEY$1] = new AsyncLocalStorage();
2496
+ return globalScope[REGISTRY_KEY$1];
2497
+ }
2498
+ function getRegisteredMcpCredentialContext() {
2499
+ return store().getStore();
2500
+ }
2501
+ /**
2502
+ * Run `fn` with MCP credential context active for its entire async execution. Nested calls merge
2503
+ * over the enclosing context, so an agent's assignment target and a per-tool consumer id compose.
2504
+ */
2505
+ function runWithMcpCredentialContext(context, fn) {
2506
+ const als = store();
2507
+ return als.run({
2508
+ ...als.getStore(),
2509
+ ...context
2510
+ }, fn);
2511
+ }
2432
2512
  function resolveActionTool(action, options) {
2433
2513
  const consumer = options?.consumer ?? {
2434
2514
  kind: "tool",
@@ -2446,7 +2526,10 @@ function resolveActionTool(action, options) {
2446
2526
  if (!options?.resolveCredentials) throw new Error(`Missing credential resolver for action "${action.slug}"`);
2447
2527
  credentials = await options.resolveCredentials(requirements, consumer, options.contextOverride);
2448
2528
  }
2449
- const output = await runOutsideActionExecution(() => executeAction(action, params, credentials));
2529
+ const output = await runWithMcpCredentialContext({
2530
+ ...options?.mcpCredentialContext,
2531
+ consumerId: consumer.id ?? consumer.name
2532
+ }, () => runOutsideActionExecution(() => executeAction(action, params, credentials)));
2450
2533
  return {
2451
2534
  content: [{
2452
2535
  type: "text",
@@ -2476,6 +2559,6 @@ function getRegisteredProjectScopeId() {
2476
2559
  return registry().getter?.();
2477
2560
  }
2478
2561
  //#endregion
2479
- export { mcpEntityId as C, toolParameters as E, isCredentialInput as S, toCredentialRequirement as T, runWithinActionExecution as _, getActionCredentialRequirements as a, credentialInputSchema as b, getWorkflowRunHandle as c, isWithinActionExecution as d, registerProjectScopeGetter as f, runWithRunSignal as g, runOutsideActionExecution as h, executeAction as i, isAction as l, resolveActionTool as m, createStepInvocation as n, getRegisteredProjectScopeId as o, registerWorkflowRunGetter as p, defineAction as r, getRunSignal as s, actionCoreSchema as t, isStepInvocation as u, CREDENTIAL_SCOPE_TYPES as v, normalizeCredentialList as w, defineCredential as x, credential as y };
2562
+ export { defineCredential as C, toCredentialRequirement as D, normalizeCredentialList as E, toolParameters as O, credentialInputSchema as S, mcpEntityId as T, runWithMcpCredentialContext as _, getActionCredentialRequirements as a, CREDENTIAL_SCOPE_TYPES as b, getRunSignal as c, isStepInvocation as d, isWithinActionExecution as f, runOutsideActionExecution as g, resolveActionTool as h, executeAction as i, getWorkflowRunHandle as l, registerWorkflowRunGetter as m, createStepInvocation as n, getRegisteredMcpCredentialContext as o, registerProjectScopeGetter as p, defineAction as r, getRegisteredProjectScopeId as s, actionCoreSchema as t, isAction as u, runWithRunSignal as v, isCredentialInput as w, credential as x, runWithinActionExecution as y };
2480
2563
 
2481
- //# sourceMappingURL=dist-DqFdFpiB.mjs.map
2564
+ //# sourceMappingURL=dist-CppO7361.mjs.map