@keystrokehq/keystroke 0.0.101 → 0.0.102

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 (61) hide show
  1. package/dist/action.cjs +2 -1
  2. package/dist/action.d.cts +2 -2
  3. package/dist/action.d.mts +2 -2
  4. package/dist/action.mjs +2 -2
  5. package/dist/agent.cjs +144 -116
  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 +144 -117
  10. package/dist/agent.mjs.map +1 -1
  11. package/dist/credentials.cjs +1 -1
  12. package/dist/credentials.mjs +1 -1
  13. package/dist/{dist-DzfOPx7X.mjs → dist-BUfE2se6.mjs} +3 -3
  14. package/dist/{dist-DzfOPx7X.mjs.map → dist-BUfE2se6.mjs.map} +1 -1
  15. package/dist/{dist-DJhg5KTL.cjs → dist-BkC9pJIu.cjs} +3 -3
  16. package/dist/{dist-DJhg5KTL.cjs.map → dist-BkC9pJIu.cjs.map} +1 -1
  17. package/dist/{dist-DKGeSeMa.cjs → dist-C8RdaDkW.cjs} +110 -79
  18. package/dist/dist-C8RdaDkW.cjs.map +1 -0
  19. package/dist/{dist-cDEt5yzO.mjs → dist-DY_F2zw5.mjs} +110 -79
  20. package/dist/dist-DY_F2zw5.mjs.map +1 -0
  21. package/dist/{dist-DG2RS68d.cjs → dist-DnqDVVpK.cjs} +11 -1
  22. package/dist/{dist-DG2RS68d.cjs.map → dist-DnqDVVpK.cjs.map} +1 -1
  23. package/dist/{dist-CAGgGvND.mjs → dist-SGAuX401.mjs} +6 -2
  24. package/dist/{dist-CAGgGvND.mjs.map → dist-SGAuX401.mjs.map} +1 -1
  25. package/dist/{index-CfK7yBQI.d.cts → index-B6BYxmgO.d.cts} +14 -3
  26. package/dist/index-B6BYxmgO.d.cts.map +1 -0
  27. package/dist/{index-DwZkaYLS.d.mts → index-DsP83E4y.d.mts} +10 -3
  28. package/dist/index-DsP83E4y.d.mts.map +1 -0
  29. package/dist/{index-by6PXA-8.d.mts → index-DtcAWajc.d.mts} +14 -3
  30. package/dist/index-DtcAWajc.d.mts.map +1 -0
  31. package/dist/{index-L5a2mf72.d.cts → index-FlkwP4zn.d.cts} +7 -3
  32. package/dist/index-FlkwP4zn.d.cts.map +1 -0
  33. package/dist/{index-CBgXyNH2.d.mts → index-TLlgJ1q1.d.mts} +7 -3
  34. package/dist/index-TLlgJ1q1.d.mts.map +1 -0
  35. package/dist/{index-C6_DVB_V.d.cts → index-i9JrhOqL.d.cts} +10 -3
  36. package/dist/index-i9JrhOqL.d.cts.map +1 -0
  37. package/dist/{mistral-CGHbHFQG.mjs → mistral-DUtxOD_C.mjs} +2 -2
  38. package/dist/{mistral-CGHbHFQG.mjs.map → mistral-DUtxOD_C.mjs.map} +1 -1
  39. package/dist/{mistral-9mfXttcp.cjs → mistral-DXb4X3t4.cjs} +2 -2
  40. package/dist/{mistral-9mfXttcp.cjs.map → mistral-DXb4X3t4.cjs.map} +1 -1
  41. package/dist/{sse-CcbP5P9d.mjs → sse-DezHFNKg.mjs} +2 -2
  42. package/dist/{sse-CcbP5P9d.mjs.map → sse-DezHFNKg.mjs.map} +1 -1
  43. package/dist/{sse-DSHssCpN.cjs → sse-SwZnScle.cjs} +2 -2
  44. package/dist/{sse-DSHssCpN.cjs.map → sse-SwZnScle.cjs.map} +1 -1
  45. package/dist/trigger.cjs +1 -1
  46. package/dist/trigger.d.cts +2 -2
  47. package/dist/trigger.d.mts +2 -2
  48. package/dist/trigger.mjs +1 -1
  49. package/dist/workflow.cjs +1 -1
  50. package/dist/workflow.d.cts +2 -2
  51. package/dist/workflow.d.mts +2 -2
  52. package/dist/workflow.mjs +1 -1
  53. package/package.json +1 -1
  54. package/dist/dist-DKGeSeMa.cjs.map +0 -1
  55. package/dist/dist-cDEt5yzO.mjs.map +0 -1
  56. package/dist/index-C6_DVB_V.d.cts.map +0 -1
  57. package/dist/index-CBgXyNH2.d.mts.map +0 -1
  58. package/dist/index-CfK7yBQI.d.cts.map +0 -1
  59. package/dist/index-DwZkaYLS.d.mts.map +0 -1
  60. package/dist/index-L5a2mf72.d.cts.map +0 -1
  61. package/dist/index-by6PXA-8.d.mts.map +0 -1
package/dist/action.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-DG2RS68d.cjs");
2
+ const require_dist = require("./dist-DnqDVVpK.cjs");
3
3
  exports.CREDENTIAL_SCOPE_LEVELS = require_dist.CREDENTIAL_SCOPE_LEVELS;
4
4
  exports.DEFAULT_CREDENTIAL_RESOLUTION_CHAIN = require_dist.DEFAULT_CREDENTIAL_RESOLUTION_CHAIN;
5
5
  exports.actionCoreSchema = require_dist.actionCoreSchema;
@@ -14,6 +14,7 @@ exports.getWorkflowRunHandle = require_dist.getWorkflowRunHandle;
14
14
  exports.isAction = require_dist.isAction;
15
15
  exports.isCredentialInput = require_dist.isCredentialInput;
16
16
  exports.isStepInvocation = require_dist.isStepInvocation;
17
+ exports.isWithinActionExecution = require_dist.isWithinActionExecution;
17
18
  exports.normalizeCredentialList = require_dist.normalizeCredentialList;
18
19
  exports.registerWorkflowRunGetter = require_dist.registerWorkflowRunGetter;
19
20
  exports.resolveActionTool = require_dist.resolveActionTool;
package/dist/action.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { C as normalizeCredentialList, S as isCredentialInput, _ as ResolvedCredentials, a as CredentialInput, b as credentialInputSchema, d as DefineCredentialInput, f as DefineOAuthCredentialInput, l as CredentialScopeLevel, m as NormalizeCredential, n as Credential, o as CredentialList, p as DefineStaticCredentialInput, r as CredentialAuthKind, s as CredentialRequirement, t as CREDENTIAL_SCOPE_LEVELS, u as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, w as toCredentialRequirement, x as defineCredential, y as credential } from "./index-CiuCYKLw.cjs";
2
- import { _ as resolveActionTool, a as ResolveActionToolOptions, c as actionCoreSchema, d as executeAction, f as getActionCredentialRequirements, g as registerWorkflowRunGetter, h as isStepInvocation, i as ResolveActionCredentialsFn, l as createStepInvocation, m as isAction, n as ActionDefinition, o as StepInvocation, p as getWorkflowRunHandle, r as ActionDefinitionInput, s as WorkflowActionDefinition, t as ActionCredentialConsumer, u as defineAction, v as runOutsideActionExecution, y as runWithinActionExecution } from "./index-CfK7yBQI.cjs";
3
- export { type ActionCredentialConsumer, type ActionDefinition, type ActionDefinitionInput, CREDENTIAL_SCOPE_LEVELS, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeLevel, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolveActionCredentialsFn, type ResolveActionToolOptions, type ResolvedCredentials, type StepInvocation, type WorkflowActionDefinition, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
2
+ import { _ as isWithinActionExecution, a as ResolveActionCredentialsFn, b as runOutsideActionExecution, c as WorkflowActionDefinition, d as defineAction, f as executeAction, g as isStepInvocation, h as isAction, i as AgentRunOptions, l as actionCoreSchema, m as getWorkflowRunHandle, n as ActionDefinition, o as ResolveActionToolOptions, p as getActionCredentialRequirements, r as ActionDefinitionInput, s as StepInvocation, t as ActionCredentialConsumer, u as createStepInvocation, v as registerWorkflowRunGetter, x as runWithinActionExecution, y as resolveActionTool } from "./index-B6BYxmgO.cjs";
3
+ export { type ActionCredentialConsumer, type ActionDefinition, type ActionDefinitionInput, type AgentRunOptions, CREDENTIAL_SCOPE_LEVELS, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeLevel, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolveActionCredentialsFn, type ResolveActionToolOptions, type ResolvedCredentials, type StepInvocation, type WorkflowActionDefinition, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
package/dist/action.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { C as normalizeCredentialList, S as isCredentialInput, _ as ResolvedCredentials, a as CredentialInput, b as credentialInputSchema, d as DefineCredentialInput, f as DefineOAuthCredentialInput, l as CredentialScopeLevel, m as NormalizeCredential, n as Credential, o as CredentialList, p as DefineStaticCredentialInput, r as CredentialAuthKind, s as CredentialRequirement, t as CREDENTIAL_SCOPE_LEVELS, u as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, w as toCredentialRequirement, x as defineCredential, y as credential } from "./index-CiuCYKLw.mjs";
2
- import { _ as resolveActionTool, a as ResolveActionToolOptions, c as actionCoreSchema, d as executeAction, f as getActionCredentialRequirements, g as registerWorkflowRunGetter, h as isStepInvocation, i as ResolveActionCredentialsFn, l as createStepInvocation, m as isAction, n as ActionDefinition, o as StepInvocation, p as getWorkflowRunHandle, r as ActionDefinitionInput, s as WorkflowActionDefinition, t as ActionCredentialConsumer, u as defineAction, v as runOutsideActionExecution, y as runWithinActionExecution } from "./index-by6PXA-8.mjs";
3
- export { type ActionCredentialConsumer, type ActionDefinition, type ActionDefinitionInput, CREDENTIAL_SCOPE_LEVELS, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeLevel, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolveActionCredentialsFn, type ResolveActionToolOptions, type ResolvedCredentials, type StepInvocation, type WorkflowActionDefinition, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
2
+ import { _ as isWithinActionExecution, a as ResolveActionCredentialsFn, b as runOutsideActionExecution, c as WorkflowActionDefinition, d as defineAction, f as executeAction, g as isStepInvocation, h as isAction, i as AgentRunOptions, l as actionCoreSchema, m as getWorkflowRunHandle, n as ActionDefinition, o as ResolveActionToolOptions, p as getActionCredentialRequirements, r as ActionDefinitionInput, s as StepInvocation, t as ActionCredentialConsumer, u as createStepInvocation, v as registerWorkflowRunGetter, x as runWithinActionExecution, y as resolveActionTool } from "./index-DtcAWajc.mjs";
3
+ export { type ActionCredentialConsumer, type ActionDefinition, type ActionDefinitionInput, type AgentRunOptions, CREDENTIAL_SCOPE_LEVELS, type Credential, type CredentialAuthKind, type CredentialInput, type CredentialList, type CredentialRequirement, type CredentialScopeLevel, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, type DefineCredentialInput, type DefineOAuthCredentialInput, type DefineStaticCredentialInput, type NormalizeCredential, type ResolveActionCredentialsFn, type ResolveActionToolOptions, type ResolvedCredentials, type StepInvocation, type WorkflowActionDefinition, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
package/dist/action.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as credentialInputSchema, a as getActionCredentialRequirements, b as normalizeCredentialList, c as isStepInvocation, d as runOutsideActionExecution, f as runWithinActionExecution, g as credential, h as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, i as executeAction, l as registerWorkflowRunGetter, n as createStepInvocation, o as getWorkflowRunHandle, p as CREDENTIAL_SCOPE_LEVELS, r as defineAction, s as isAction, t as actionCoreSchema, u as resolveActionTool, v as defineCredential, x as toCredentialRequirement, y as isCredentialInput } from "./dist-CAGgGvND.mjs";
2
- export { CREDENTIAL_SCOPE_LEVELS, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
1
+ import { S as toCredentialRequirement, _ as credential, a as getActionCredentialRequirements, b as isCredentialInput, c as isStepInvocation, d as resolveActionTool, f as runOutsideActionExecution, g as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, i as executeAction, l as isWithinActionExecution, m as CREDENTIAL_SCOPE_LEVELS, n as createStepInvocation, o as getWorkflowRunHandle, p as runWithinActionExecution, r as defineAction, s as isAction, t as actionCoreSchema, u as registerWorkflowRunGetter, v as credentialInputSchema, x as normalizeCredentialList, y as defineCredential } from "./dist-SGAuX401.mjs";
2
+ export { CREDENTIAL_SCOPE_LEVELS, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithinActionExecution, toCredentialRequirement };
package/dist/agent.cjs CHANGED
@@ -1,11 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_dist$1 = require("./dist-CLqJza2Y.cjs");
3
- const require_dist$2 = require("./dist-DG2RS68d.cjs");
3
+ const require_dist$2 = require("./dist-DnqDVVpK.cjs");
4
4
  require("./env-api-keys-BFptfIIs.cjs");
5
5
  const require_event_stream = require("./event-stream-CS-ls7wC.cjs");
6
6
  require("./json-parse-CpkTvzp8.cjs");
7
- const require_dist$3 = require("./dist-DJhg5KTL.cjs");
7
+ const require_dist$3 = require("./dist-BkC9pJIu.cjs");
8
8
  let zod = require("zod");
9
+ let node_async_hooks = require("node:async_hooks");
9
10
  let node_module = require("node:module");
10
11
  let node_fs = require("node:fs");
11
12
  let node_path = require("node:path");
@@ -928,7 +929,7 @@ function loadGoogleVertexProviderModule() {
928
929
  return googleVertexProviderModulePromise;
929
930
  }
930
931
  function loadMistralProviderModule() {
931
- mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-9mfXttcp.cjs")).then((module) => {
932
+ mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-DXb4X3t4.cjs")).then((module) => {
932
933
  const provider = module;
933
934
  return {
934
935
  stream: provider.streamMistral,
@@ -13680,6 +13681,131 @@ function errorMessage(snapshot) {
13680
13681
  function defineTool(tool) {
13681
13682
  return tool;
13682
13683
  }
13684
+ /** Tracks an in-flight agent prompt (subagents/tools must not become workflow steps). */
13685
+ const executingAgentPrompt = new node_async_hooks.AsyncLocalStorage();
13686
+ function runWithinAgentPromptExecution(fn) {
13687
+ return executingAgentPrompt.run(true, fn);
13688
+ }
13689
+ function isWithinAgentPromptExecution() {
13690
+ return executingAgentPrompt.getStore() === true;
13691
+ }
13692
+ const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
13693
+ function shouldPersistAgentEvent(event) {
13694
+ return !SKIPPED_EVENT_TYPES.has(event.type);
13695
+ }
13696
+ async function persistSessionEvent(options) {
13697
+ const { sessionId, memoryConfig, eventType, payload } = options;
13698
+ const seq = await require_dist$3.appendEvent(sessionId, eventType, payload);
13699
+ if (memoryConfig) try {
13700
+ await appendSessionLine(memoryConfig, sessionId, {
13701
+ seq,
13702
+ eventType,
13703
+ payload,
13704
+ createdAt: /* @__PURE__ */ new Date()
13705
+ });
13706
+ } catch (err) {
13707
+ console.error("[memory] transcript append failed:", err);
13708
+ }
13709
+ return seq;
13710
+ }
13711
+ async function persistAgentEvent(sessionId, event, memoryConfig) {
13712
+ await persistSessionEvent({
13713
+ sessionId,
13714
+ memoryConfig,
13715
+ eventType: event.type,
13716
+ payload: event
13717
+ });
13718
+ if (event.type === "message_end") await persistSessionEvent({
13719
+ sessionId,
13720
+ memoryConfig,
13721
+ eventType: require_dist$3.MESSAGE_EVENT_TYPE,
13722
+ payload: event.message
13723
+ });
13724
+ }
13725
+ async function prepareAgentSession(agentId, sessionId) {
13726
+ if (sessionId) {
13727
+ const session = await require_dist$3.getSession(sessionId);
13728
+ if (!session) await require_dist$3.createSession(agentId, sessionId, await require_dist$3.resolveRunSourceFromTraceContext());
13729
+ else if (session.agentId !== agentId) throw new SessionAgentMismatchError(sessionId);
13730
+ return { sessionId };
13731
+ }
13732
+ return { sessionId: (await require_dist$3.createSession(agentId, void 0, await require_dist$3.resolveRunSourceFromTraceContext())).id };
13733
+ }
13734
+ async function runAgentPrompt(agent, agentId, input, options = {}) {
13735
+ const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
13736
+ const priorMessages = await require_dist$3.listMessageEvents(sessionId);
13737
+ const runPrompt = async () => {
13738
+ const runtime = await agent.buildRuntime({
13739
+ agentId,
13740
+ sessionId,
13741
+ messages: priorMessages
13742
+ }, {
13743
+ ...options,
13744
+ credentials: require_dist$3.buildCredentialRunContext({ request: {
13745
+ ...options.credentials,
13746
+ ...input.context
13747
+ } })
13748
+ });
13749
+ const memoryConfig = runtime.memory?.config;
13750
+ const unsubscribe = runtime.pi.subscribe(async (event) => {
13751
+ if (!shouldPersistAgentEvent(event)) return;
13752
+ await persistAgentEvent(sessionId, event, memoryConfig);
13753
+ });
13754
+ try {
13755
+ const snapshot = await require_dist$3.captureConsole(async () => prompt(runtime, input.message));
13756
+ const credentialError = runtime.takeCredentialError?.();
13757
+ if (credentialError && require_dist$3.isCredentialError(credentialError)) throw credentialError;
13758
+ await require_dist$3.touchSession(sessionId);
13759
+ return {
13760
+ sessionId,
13761
+ messages: messages(snapshot),
13762
+ error: errorMessage(snapshot) ?? null
13763
+ };
13764
+ } finally {
13765
+ unsubscribe();
13766
+ try {
13767
+ runtime.memory?.reindexSessions();
13768
+ } catch (err) {
13769
+ console.error("[memory] session reindex failed:", err);
13770
+ }
13771
+ runtime.memory?.close();
13772
+ await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
13773
+ await runtime.sandbox.dispose();
13774
+ }
13775
+ };
13776
+ if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);
13777
+ const parent = require_dist$3.getTraceContext();
13778
+ return require_dist$3.withSpan({
13779
+ kind: "agent_session",
13780
+ name: agentId,
13781
+ refId: sessionId,
13782
+ traceId: parent?.traceId ?? sessionId,
13783
+ metadata: {
13784
+ agentId,
13785
+ trigger: options.tracing?.trigger ?? (parent ? "subagent" : "api"),
13786
+ ...options.tracing
13787
+ }
13788
+ }, () => runWithinAgentPromptExecution(runPrompt));
13789
+ }
13790
+ var SessionAgentMismatchError = class extends Error {
13791
+ constructor(sessionId) {
13792
+ super(`Session ${sessionId} does not belong to this agent`);
13793
+ this.name = "SessionAgentMismatchError";
13794
+ }
13795
+ };
13796
+ /** Resolves an agent id from the DB registry by key when not passed explicitly. */
13797
+ async function resolveAgentId(agentKey, explicitId) {
13798
+ if (explicitId) return explicitId;
13799
+ const registered = await require_dist$3.getAgentByRoute(`/agents/${agentKey}`);
13800
+ if (!registered?.id) throw new Error(`Agent "${agentKey}" is not registered; pass agentId or sync the project before prompting.`);
13801
+ return registered.id;
13802
+ }
13803
+ async function runDirectAgentPrompt(agent, agentKey, defaultRunPrompt, promptInput, runPrompt) {
13804
+ return runAgentPrompt(agent, await resolveAgentId(agentKey, promptInput.agentId), promptInput, {
13805
+ ...defaultRunPrompt,
13806
+ ...runPrompt
13807
+ });
13808
+ }
13683
13809
  /**
13684
13810
  * Resolve the host directory backing `/workspace` for an agent prompt.
13685
13811
  *
@@ -13906,110 +14032,6 @@ function normalizeAgentDefinition(input, options = {}) {
13906
14032
  ...input.memory !== void 0 ? { memory: input.memory } : {}
13907
14033
  };
13908
14034
  }
13909
- const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
13910
- function shouldPersistAgentEvent(event) {
13911
- return !SKIPPED_EVENT_TYPES.has(event.type);
13912
- }
13913
- async function persistSessionEvent(options) {
13914
- const { sessionId, memoryConfig, eventType, payload } = options;
13915
- const seq = await require_dist$3.appendEvent(sessionId, eventType, payload);
13916
- if (memoryConfig) try {
13917
- await appendSessionLine(memoryConfig, sessionId, {
13918
- seq,
13919
- eventType,
13920
- payload,
13921
- createdAt: /* @__PURE__ */ new Date()
13922
- });
13923
- } catch (err) {
13924
- console.error("[memory] transcript append failed:", err);
13925
- }
13926
- return seq;
13927
- }
13928
- async function persistAgentEvent(sessionId, event, memoryConfig) {
13929
- await persistSessionEvent({
13930
- sessionId,
13931
- memoryConfig,
13932
- eventType: event.type,
13933
- payload: event
13934
- });
13935
- if (event.type === "message_end") await persistSessionEvent({
13936
- sessionId,
13937
- memoryConfig,
13938
- eventType: require_dist$3.MESSAGE_EVENT_TYPE,
13939
- payload: event.message
13940
- });
13941
- }
13942
- async function prepareAgentSession(agentId, sessionId) {
13943
- if (sessionId) {
13944
- const session = await require_dist$3.getSession(sessionId);
13945
- if (!session) await require_dist$3.createSession(agentId, sessionId, await require_dist$3.resolveRunSourceFromTraceContext());
13946
- else if (session.agentId !== agentId) throw new SessionAgentMismatchError(sessionId);
13947
- return { sessionId };
13948
- }
13949
- return { sessionId: (await require_dist$3.createSession(agentId, void 0, await require_dist$3.resolveRunSourceFromTraceContext())).id };
13950
- }
13951
- async function runAgentPrompt(agent, agentId, input, options = {}) {
13952
- const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
13953
- const priorMessages = await require_dist$3.listMessageEvents(sessionId);
13954
- const runPrompt = async () => {
13955
- const runtime = await agent.buildRuntime({
13956
- agentId,
13957
- sessionId,
13958
- messages: priorMessages
13959
- }, {
13960
- ...options,
13961
- credentials: require_dist$3.buildCredentialRunContext({ request: {
13962
- ...options.credentials,
13963
- ...input.context
13964
- } })
13965
- });
13966
- const memoryConfig = runtime.memory?.config;
13967
- const unsubscribe = runtime.pi.subscribe(async (event) => {
13968
- if (!shouldPersistAgentEvent(event)) return;
13969
- await persistAgentEvent(sessionId, event, memoryConfig);
13970
- });
13971
- try {
13972
- const snapshot = await require_dist$3.captureConsole(async () => prompt(runtime, input.message));
13973
- const credentialError = runtime.takeCredentialError?.();
13974
- if (credentialError && require_dist$3.isCredentialError(credentialError)) throw credentialError;
13975
- await require_dist$3.touchSession(sessionId);
13976
- return {
13977
- sessionId,
13978
- messages: messages(snapshot),
13979
- error: errorMessage(snapshot) ?? null
13980
- };
13981
- } finally {
13982
- unsubscribe();
13983
- try {
13984
- runtime.memory?.reindexSessions();
13985
- } catch (err) {
13986
- console.error("[memory] session reindex failed:", err);
13987
- }
13988
- runtime.memory?.close();
13989
- await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
13990
- await runtime.sandbox.dispose();
13991
- }
13992
- };
13993
- if (options.skipAgentSessionSpan) return runPrompt();
13994
- const parent = require_dist$3.getTraceContext();
13995
- return require_dist$3.withSpan({
13996
- kind: "agent_session",
13997
- name: agentId,
13998
- refId: sessionId,
13999
- traceId: parent?.traceId ?? sessionId,
14000
- metadata: {
14001
- agentId,
14002
- trigger: options.tracing?.trigger ?? (parent ? "subagent" : "api"),
14003
- ...options.tracing
14004
- }
14005
- }, runPrompt);
14006
- }
14007
- var SessionAgentMismatchError = class extends Error {
14008
- constructor(sessionId) {
14009
- super(`Session ${sessionId} does not belong to this agent`);
14010
- this.name = "SessionAgentMismatchError";
14011
- }
14012
- };
14013
14035
  /**
14014
14036
  * Define an agent: normalized config plus a pipeline that builds sandbox + pi runtime on demand.
14015
14037
  */
@@ -14024,14 +14046,19 @@ function defineAgent(input, options = {}) {
14024
14046
  ...def,
14025
14047
  key,
14026
14048
  buildRuntime: (ctx, runPrompt) => buildAgentRuntime(def, ctx, runPrompt ?? options.runPrompt),
14027
- prompt: async (promptInput, runPrompt) => {
14028
- let agentId = promptInput.agentId;
14029
- if (!agentId) agentId = (await require_dist$3.getAgentByRoute(`/agents/${key}`))?.id;
14030
- if (!agentId) throw new Error("agentId is required when calling Agent.prompt(); pass agentId or define the agent with { key }");
14031
- return runAgentPrompt(agent, agentId, promptInput, {
14032
- ...options.runPrompt,
14033
- ...runPrompt
14034
- });
14049
+ prompt: (promptInput, runPrompt) => {
14050
+ const handle = require_dist$2.getWorkflowRunHandle();
14051
+ if (handle?.agentRunner && !require_dist$2.isWithinActionExecution() && !isWithinAgentPromptExecution()) {
14052
+ const { stepId, ...mergedRunPrompt } = {
14053
+ ...options.runPrompt,
14054
+ ...runPrompt
14055
+ };
14056
+ return handle.agentRunner(agent, promptInput, {
14057
+ id: stepId,
14058
+ runPrompt: mergedRunPrompt
14059
+ });
14060
+ }
14061
+ return runDirectAgentPrompt(agent, key, options.runPrompt, promptInput, runPrompt);
14035
14062
  }
14036
14063
  };
14037
14064
  return agent;
@@ -14074,7 +14101,7 @@ function defineSubagentTool(input) {
14074
14101
  tool: toolDef.name,
14075
14102
  type: "subagent"
14076
14103
  }
14077
- }, () => agent.prompt({ message: toMessage(params) }, { tracing: { trigger: "subagent" } }));
14104
+ }, async () => runDirectAgentPrompt(agent, agent.key, void 0, { message: toMessage(params) }, { tracing: { trigger: "subagent" } }));
14078
14105
  if (result.error) throw new Error(result.error);
14079
14106
  return {
14080
14107
  content: [{
@@ -14118,6 +14145,7 @@ exports.parseAgentCreateInput = parseAgentCreateInput;
14118
14145
  exports.prepareAgentSession = prepareAgentSession;
14119
14146
  exports.prompt = prompt;
14120
14147
  exports.resolveAgentAssets = resolveAgentAssets;
14148
+ exports.resolveAgentId = resolveAgentId;
14121
14149
  exports.resolveAgentTools = resolveAgentTools;
14122
14150
  exports.resolveAgentWorkspaceRoot = resolveAgentWorkspaceRoot;
14123
14151
  exports.resolveThinkingLevel = resolveThinkingLevel;