@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.
- package/dist/action.cjs +2 -1
- package/dist/action.d.cts +2 -2
- package/dist/action.d.mts +2 -2
- package/dist/action.mjs +2 -2
- package/dist/agent.cjs +144 -116
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +2 -2
- package/dist/agent.d.mts +2 -2
- package/dist/agent.mjs +144 -117
- package/dist/agent.mjs.map +1 -1
- package/dist/credentials.cjs +1 -1
- package/dist/credentials.mjs +1 -1
- package/dist/{dist-DzfOPx7X.mjs → dist-BUfE2se6.mjs} +3 -3
- package/dist/{dist-DzfOPx7X.mjs.map → dist-BUfE2se6.mjs.map} +1 -1
- package/dist/{dist-DJhg5KTL.cjs → dist-BkC9pJIu.cjs} +3 -3
- package/dist/{dist-DJhg5KTL.cjs.map → dist-BkC9pJIu.cjs.map} +1 -1
- package/dist/{dist-DKGeSeMa.cjs → dist-C8RdaDkW.cjs} +110 -79
- package/dist/dist-C8RdaDkW.cjs.map +1 -0
- package/dist/{dist-cDEt5yzO.mjs → dist-DY_F2zw5.mjs} +110 -79
- package/dist/dist-DY_F2zw5.mjs.map +1 -0
- package/dist/{dist-DG2RS68d.cjs → dist-DnqDVVpK.cjs} +11 -1
- package/dist/{dist-DG2RS68d.cjs.map → dist-DnqDVVpK.cjs.map} +1 -1
- package/dist/{dist-CAGgGvND.mjs → dist-SGAuX401.mjs} +6 -2
- package/dist/{dist-CAGgGvND.mjs.map → dist-SGAuX401.mjs.map} +1 -1
- package/dist/{index-CfK7yBQI.d.cts → index-B6BYxmgO.d.cts} +14 -3
- package/dist/index-B6BYxmgO.d.cts.map +1 -0
- package/dist/{index-DwZkaYLS.d.mts → index-DsP83E4y.d.mts} +10 -3
- package/dist/index-DsP83E4y.d.mts.map +1 -0
- package/dist/{index-by6PXA-8.d.mts → index-DtcAWajc.d.mts} +14 -3
- package/dist/index-DtcAWajc.d.mts.map +1 -0
- package/dist/{index-L5a2mf72.d.cts → index-FlkwP4zn.d.cts} +7 -3
- package/dist/index-FlkwP4zn.d.cts.map +1 -0
- package/dist/{index-CBgXyNH2.d.mts → index-TLlgJ1q1.d.mts} +7 -3
- package/dist/index-TLlgJ1q1.d.mts.map +1 -0
- package/dist/{index-C6_DVB_V.d.cts → index-i9JrhOqL.d.cts} +10 -3
- package/dist/index-i9JrhOqL.d.cts.map +1 -0
- package/dist/{mistral-CGHbHFQG.mjs → mistral-DUtxOD_C.mjs} +2 -2
- package/dist/{mistral-CGHbHFQG.mjs.map → mistral-DUtxOD_C.mjs.map} +1 -1
- package/dist/{mistral-9mfXttcp.cjs → mistral-DXb4X3t4.cjs} +2 -2
- package/dist/{mistral-9mfXttcp.cjs.map → mistral-DXb4X3t4.cjs.map} +1 -1
- package/dist/{sse-CcbP5P9d.mjs → sse-DezHFNKg.mjs} +2 -2
- package/dist/{sse-CcbP5P9d.mjs.map → sse-DezHFNKg.mjs.map} +1 -1
- package/dist/{sse-DSHssCpN.cjs → sse-SwZnScle.cjs} +2 -2
- package/dist/{sse-DSHssCpN.cjs.map → sse-SwZnScle.cjs.map} +1 -1
- package/dist/trigger.cjs +1 -1
- package/dist/trigger.d.cts +2 -2
- package/dist/trigger.d.mts +2 -2
- package/dist/trigger.mjs +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.mts +2 -2
- package/dist/workflow.mjs +1 -1
- package/package.json +1 -1
- package/dist/dist-DKGeSeMa.cjs.map +0 -1
- package/dist/dist-cDEt5yzO.mjs.map +0 -1
- package/dist/index-C6_DVB_V.d.cts.map +0 -1
- package/dist/index-CBgXyNH2.d.mts.map +0 -1
- package/dist/index-CfK7yBQI.d.cts.map +0 -1
- package/dist/index-DwZkaYLS.d.mts.map +0 -1
- package/dist/index-L5a2mf72.d.cts.map +0 -1
- package/dist/index-by6PXA-8.d.mts.map +0 -1
package/dist/agent.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { l as ThinkingLevel, u as getModel } from "./index-BcMCpDKh.cjs";
|
|
2
|
-
import { A as messages, B as
|
|
2
|
+
import { A as messages, B as AgentCreateInput, C as createAgent, D as errorMessage, E as defineTool, F as resolveAgentId, G as ThinkingLevelSchema, H as DEFAULT_THINKING_LEVEL, I as resolveAgentTools, K as parseAgentCreateInput, L as resolveAgentWorkspaceRoot, M as prepareAgentSession, N as prompt, O as getSubagentToolMetadata, P as resolveAgentAssets, R as runAgentPrompt, S as buildAgentRuntime, T as defineSubagentTool, U as ModelRef, V as AgentCreateInputSchema, W as ModelRefSchema, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentToolInherit, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as normalizeAgentDefinition, k as loadAssetManifest, l as DefineAgentOptions, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as resolveThinkingLevel, r as AgentConfig, s as AgentSnapshot, t as Agent, u as DefineSubagentToolInput, v as SubagentTool, w as defineAgent, x as SubagentToolMetadata, y as SubagentToolDetails, z as snapshot } from "./index-FlkwP4zn.cjs";
|
|
3
3
|
import { a as McpDefinition, c as McpServerOptions, d as McpTransport, f as connectMcpDefinition, g as isMcp, h as defineMcp, i as McpConnection, l as McpStdioOptions, m as connectMcpStdio, n as McpAuthOptions, o as McpDefinitionInput, p as connectMcpServer, r as McpCallToolOptions, s as McpHttpTransport, t as ToolCredentialResolver, u as McpStdioTransport } from "./index-MfPRY7cK.cjs";
|
|
4
|
-
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineAgentOptions, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, type ModelRef, ModelRefSchema, type PromptInput, type PromptResponse, type ResolvedAgentAssets, type RunAgentPromptOptions, SUBAGENT_TOOL, type SandboxedAgentRuntime, SessionAgentMismatchError, type SubagentTool, type SubagentToolDetails, type SubagentToolInherit, type SubagentToolMetadata, type ThinkingLevel, ThinkingLevelSchema, type ToolCredentialResolver, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
4
|
+
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineAgentOptions, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, type ModelRef, ModelRefSchema, type PromptInput, type PromptResponse, type ResolvedAgentAssets, type RunAgentPromptOptions, SUBAGENT_TOOL, type SandboxedAgentRuntime, SessionAgentMismatchError, type SubagentTool, type SubagentToolDetails, type SubagentToolInherit, type SubagentToolMetadata, type ThinkingLevel, ThinkingLevelSchema, type ToolCredentialResolver, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
package/dist/agent.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { l as ThinkingLevel, u as getModel } from "./index-Bd_asjgz.mjs";
|
|
2
|
-
import { A as messages, B as
|
|
2
|
+
import { A as messages, B as AgentCreateInput, C as createAgent, D as errorMessage, E as defineTool, F as resolveAgentId, G as ThinkingLevelSchema, H as DEFAULT_THINKING_LEVEL, I as resolveAgentTools, K as parseAgentCreateInput, L as resolveAgentWorkspaceRoot, M as prepareAgentSession, N as prompt, O as getSubagentToolMetadata, P as resolveAgentAssets, R as runAgentPrompt, S as buildAgentRuntime, T as defineSubagentTool, U as ModelRef, V as AgentCreateInputSchema, W as ModelRefSchema, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentToolInherit, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as normalizeAgentDefinition, k as loadAssetManifest, l as DefineAgentOptions, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as resolveThinkingLevel, r as AgentConfig, s as AgentSnapshot, t as Agent, u as DefineSubagentToolInput, v as SubagentTool, w as defineAgent, x as SubagentToolMetadata, y as SubagentToolDetails, z as snapshot } from "./index-TLlgJ1q1.mjs";
|
|
3
3
|
import { a as McpDefinition, c as McpServerOptions, d as McpTransport, f as connectMcpDefinition, g as isMcp, h as defineMcp, i as McpConnection, l as McpStdioOptions, m as connectMcpStdio, n as McpAuthOptions, o as McpDefinitionInput, p as connectMcpServer, r as McpCallToolOptions, s as McpHttpTransport, t as ToolCredentialResolver, u as McpStdioTransport } from "./index-ptRM3z9H.mjs";
|
|
4
|
-
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineAgentOptions, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, type ModelRef, ModelRefSchema, type PromptInput, type PromptResponse, type ResolvedAgentAssets, type RunAgentPromptOptions, SUBAGENT_TOOL, type SandboxedAgentRuntime, SessionAgentMismatchError, type SubagentTool, type SubagentToolDetails, type SubagentToolInherit, type SubagentToolMetadata, type ThinkingLevel, ThinkingLevelSchema, type ToolCredentialResolver, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
4
|
+
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineAgentOptions, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, type ModelRef, ModelRefSchema, type PromptInput, type PromptResponse, type ResolvedAgentAssets, type RunAgentPromptOptions, SUBAGENT_TOOL, type SandboxedAgentRuntime, SessionAgentMismatchError, type SubagentTool, type SubagentToolDetails, type SubagentToolInherit, type SubagentToolMetadata, type ThinkingLevel, ThinkingLevelSchema, type ToolCredentialResolver, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
package/dist/agent.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { $ as Options, $t as IsMap, An as IsSymbol$1, At as Unreachable, Bn as __require, Bt as IsRef$1, Cn as IsMinLength$2, Ct as IsInteger$2, Dn as IsObject$1, Dt as IsCodec, En as IsNumber$1, Et as IsBigInt$2, Fn as Symbols, Ft as IsUnion, G as ensureWorkspaceDir, Gt as IsArray$2, Ht as IsFunction$2, In as guard_exports, It as Union, Jt as IsOptional, K as materializeSandbox, Kt as Base, Ln as __commonJSMin, Lt as IsObject$2, Mn as IsUnsafePropertyKey, Mt as IsEnum$1, Nn as IsValueLike, Nt as IsCyclic, On as IsObjectNotArray$1, Ot as Hash, Pn as Keys$1, Pt as Unknown, Q as Instantiate, Qt as Get$3, Rt as _Object_, Sn as IsMaxLength$2, St as IsIterator$2, Tn as IsNull$1, Tt as IsBoolean$2, Ut as IsConstructor$2, Vt as Ref$1, W as defineSandbox, Wt as IsAsyncIterator$2, X as resolveSandboxRoot, Xt as IsPromise, Y as resolveAppRootFromModule, Yt as Optional, Z as Evaluate$1, Zt as IsSchema$1, _n as IsGreaterThan$1, _t as IsLiteralBigInt, a as createSandbox, an as EveryAll, at as RecordPattern, bn as IsLessEqualThan$1, bt as IsLiteralString, c as defineTool$1, cn as IsAsyncIterator$1, ct as EnumToUnion, d as resolveRunProvider, dn as IsClassInstance, dt as String$1, en as IsSet, et as Compare, fn as IsConstructor$1, ft as IsSymbol$2, gn as IsGreaterEqualThan$1, gt as IsLiteral, hn as IsFunction$1, ht as IsNull$2, i as createJustBashProvider, in as Every$1, it as IsRecord, jn as IsUndefined$1, jt as IsIntersect, kn as IsString$1, kt as hash_exports, ln as IsBigInt$1, lt as TemplateLiteralDecode, mn as IsEqual$1, mt as Number$1, nn as Entries$2, nt as IsVoid, o as defaultWorkspacesRoot, on as HasPropertyKey$1, ot as RecordValue, pn as IsDeepEqual$1, pt as IsNumber$2, q as packAssetDirs, qt as IsBase, r as createInvokeToolBridge, rn as EntriesRegExp, rt as IsUndefined$2, s as defineSkill, sn as IsArray$1, st as IsTuple, tn as IsTypeArray, tt as IsTemplateLiteral, u as materializeSkills, un as IsBoolean$1, ut as IsString$2, vn as IsInteger$1, vt as IsLiteralBoolean, wn as IsMultipleOf$1, wt as Boolean$1, xn as IsLessThan$1, xt as Literal, yn as IsIterator$1, yt as IsLiteralNumber, zn as __exportAll, zt as IsNever } from "./dist-f_JGyGWx.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { d as resolveActionTool, l as isWithinActionExecution, o as getWorkflowRunHandle, s as isAction } from "./dist-SGAuX401.mjs";
|
|
3
3
|
import "./env-api-keys-BSMeSmLq.mjs";
|
|
4
4
|
import { i as getModel, t as AssistantMessageEventStream } from "./event-stream-C7YBbzsc.mjs";
|
|
5
5
|
import "./json-parse-BhvKZ346.mjs";
|
|
6
|
-
import { C as isMcp, S as defineMcp, a as resolveActionCredentials, b as connectMcpServer, c as appendEvent, d as getSession, f as listMessageEvents, g as getTraceContext, h as captureConsole, i as isCredentialError, l as createSession, m as touchSession, n as captureCredentialToolErrors, o as resolveMcpTools, p as resolveRunSourceFromTraceContext, r as createCredentialResolver, s as MESSAGE_EVENT_TYPE$1, t as buildCredentialRunContext, u as getAgentByRoute, v as withSpan, x as connectMcpStdio, y as connectMcpDefinition } from "./dist-
|
|
6
|
+
import { C as isMcp, S as defineMcp, a as resolveActionCredentials, b as connectMcpServer, c as appendEvent, d as getSession, f as listMessageEvents, g as getTraceContext, h as captureConsole, i as isCredentialError, l as createSession, m as touchSession, n as captureCredentialToolErrors, o as resolveMcpTools, p as resolveRunSourceFromTraceContext, r as createCredentialResolver, s as MESSAGE_EVENT_TYPE$1, t as buildCredentialRunContext, u as getAgentByRoute, v as withSpan, x as connectMcpStdio, y as connectMcpDefinition } from "./dist-BUfE2se6.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import { z } from "zod";
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
10
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
10
11
|
import { basename, dirname, join } from "node:path";
|
|
11
12
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -927,7 +928,7 @@ function loadGoogleVertexProviderModule() {
|
|
|
927
928
|
return googleVertexProviderModulePromise;
|
|
928
929
|
}
|
|
929
930
|
function loadMistralProviderModule() {
|
|
930
|
-
mistralProviderModulePromise ||= import("./mistral-
|
|
931
|
+
mistralProviderModulePromise ||= import("./mistral-DUtxOD_C.mjs").then((module) => {
|
|
931
932
|
const provider = module;
|
|
932
933
|
return {
|
|
933
934
|
stream: provider.streamMistral,
|
|
@@ -13669,6 +13670,131 @@ function errorMessage(snapshot) {
|
|
|
13669
13670
|
function defineTool(tool) {
|
|
13670
13671
|
return tool;
|
|
13671
13672
|
}
|
|
13673
|
+
/** Tracks an in-flight agent prompt (subagents/tools must not become workflow steps). */
|
|
13674
|
+
const executingAgentPrompt = new AsyncLocalStorage();
|
|
13675
|
+
function runWithinAgentPromptExecution(fn) {
|
|
13676
|
+
return executingAgentPrompt.run(true, fn);
|
|
13677
|
+
}
|
|
13678
|
+
function isWithinAgentPromptExecution() {
|
|
13679
|
+
return executingAgentPrompt.getStore() === true;
|
|
13680
|
+
}
|
|
13681
|
+
const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
|
|
13682
|
+
function shouldPersistAgentEvent(event) {
|
|
13683
|
+
return !SKIPPED_EVENT_TYPES.has(event.type);
|
|
13684
|
+
}
|
|
13685
|
+
async function persistSessionEvent(options) {
|
|
13686
|
+
const { sessionId, memoryConfig, eventType, payload } = options;
|
|
13687
|
+
const seq = await appendEvent(sessionId, eventType, payload);
|
|
13688
|
+
if (memoryConfig) try {
|
|
13689
|
+
await appendSessionLine(memoryConfig, sessionId, {
|
|
13690
|
+
seq,
|
|
13691
|
+
eventType,
|
|
13692
|
+
payload,
|
|
13693
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
13694
|
+
});
|
|
13695
|
+
} catch (err) {
|
|
13696
|
+
console.error("[memory] transcript append failed:", err);
|
|
13697
|
+
}
|
|
13698
|
+
return seq;
|
|
13699
|
+
}
|
|
13700
|
+
async function persistAgentEvent(sessionId, event, memoryConfig) {
|
|
13701
|
+
await persistSessionEvent({
|
|
13702
|
+
sessionId,
|
|
13703
|
+
memoryConfig,
|
|
13704
|
+
eventType: event.type,
|
|
13705
|
+
payload: event
|
|
13706
|
+
});
|
|
13707
|
+
if (event.type === "message_end") await persistSessionEvent({
|
|
13708
|
+
sessionId,
|
|
13709
|
+
memoryConfig,
|
|
13710
|
+
eventType: MESSAGE_EVENT_TYPE$1,
|
|
13711
|
+
payload: event.message
|
|
13712
|
+
});
|
|
13713
|
+
}
|
|
13714
|
+
async function prepareAgentSession(agentId, sessionId) {
|
|
13715
|
+
if (sessionId) {
|
|
13716
|
+
const session = await getSession(sessionId);
|
|
13717
|
+
if (!session) await createSession(agentId, sessionId, await resolveRunSourceFromTraceContext());
|
|
13718
|
+
else if (session.agentId !== agentId) throw new SessionAgentMismatchError(sessionId);
|
|
13719
|
+
return { sessionId };
|
|
13720
|
+
}
|
|
13721
|
+
return { sessionId: (await createSession(agentId, void 0, await resolveRunSourceFromTraceContext())).id };
|
|
13722
|
+
}
|
|
13723
|
+
async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
13724
|
+
const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
|
|
13725
|
+
const priorMessages = await listMessageEvents(sessionId);
|
|
13726
|
+
const runPrompt = async () => {
|
|
13727
|
+
const runtime = await agent.buildRuntime({
|
|
13728
|
+
agentId,
|
|
13729
|
+
sessionId,
|
|
13730
|
+
messages: priorMessages
|
|
13731
|
+
}, {
|
|
13732
|
+
...options,
|
|
13733
|
+
credentials: buildCredentialRunContext({ request: {
|
|
13734
|
+
...options.credentials,
|
|
13735
|
+
...input.context
|
|
13736
|
+
} })
|
|
13737
|
+
});
|
|
13738
|
+
const memoryConfig = runtime.memory?.config;
|
|
13739
|
+
const unsubscribe = runtime.pi.subscribe(async (event) => {
|
|
13740
|
+
if (!shouldPersistAgentEvent(event)) return;
|
|
13741
|
+
await persistAgentEvent(sessionId, event, memoryConfig);
|
|
13742
|
+
});
|
|
13743
|
+
try {
|
|
13744
|
+
const snapshot = await captureConsole(async () => prompt(runtime, input.message));
|
|
13745
|
+
const credentialError = runtime.takeCredentialError?.();
|
|
13746
|
+
if (credentialError && isCredentialError(credentialError)) throw credentialError;
|
|
13747
|
+
await touchSession(sessionId);
|
|
13748
|
+
return {
|
|
13749
|
+
sessionId,
|
|
13750
|
+
messages: messages(snapshot),
|
|
13751
|
+
error: errorMessage(snapshot) ?? null
|
|
13752
|
+
};
|
|
13753
|
+
} finally {
|
|
13754
|
+
unsubscribe();
|
|
13755
|
+
try {
|
|
13756
|
+
runtime.memory?.reindexSessions();
|
|
13757
|
+
} catch (err) {
|
|
13758
|
+
console.error("[memory] session reindex failed:", err);
|
|
13759
|
+
}
|
|
13760
|
+
runtime.memory?.close();
|
|
13761
|
+
await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
|
|
13762
|
+
await runtime.sandbox.dispose();
|
|
13763
|
+
}
|
|
13764
|
+
};
|
|
13765
|
+
if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);
|
|
13766
|
+
const parent = getTraceContext();
|
|
13767
|
+
return withSpan({
|
|
13768
|
+
kind: "agent_session",
|
|
13769
|
+
name: agentId,
|
|
13770
|
+
refId: sessionId,
|
|
13771
|
+
traceId: parent?.traceId ?? sessionId,
|
|
13772
|
+
metadata: {
|
|
13773
|
+
agentId,
|
|
13774
|
+
trigger: options.tracing?.trigger ?? (parent ? "subagent" : "api"),
|
|
13775
|
+
...options.tracing
|
|
13776
|
+
}
|
|
13777
|
+
}, () => runWithinAgentPromptExecution(runPrompt));
|
|
13778
|
+
}
|
|
13779
|
+
var SessionAgentMismatchError = class extends Error {
|
|
13780
|
+
constructor(sessionId) {
|
|
13781
|
+
super(`Session ${sessionId} does not belong to this agent`);
|
|
13782
|
+
this.name = "SessionAgentMismatchError";
|
|
13783
|
+
}
|
|
13784
|
+
};
|
|
13785
|
+
/** Resolves an agent id from the DB registry by key when not passed explicitly. */
|
|
13786
|
+
async function resolveAgentId(agentKey, explicitId) {
|
|
13787
|
+
if (explicitId) return explicitId;
|
|
13788
|
+
const registered = await getAgentByRoute(`/agents/${agentKey}`);
|
|
13789
|
+
if (!registered?.id) throw new Error(`Agent "${agentKey}" is not registered; pass agentId or sync the project before prompting.`);
|
|
13790
|
+
return registered.id;
|
|
13791
|
+
}
|
|
13792
|
+
async function runDirectAgentPrompt(agent, agentKey, defaultRunPrompt, promptInput, runPrompt) {
|
|
13793
|
+
return runAgentPrompt(agent, await resolveAgentId(agentKey, promptInput.agentId), promptInput, {
|
|
13794
|
+
...defaultRunPrompt,
|
|
13795
|
+
...runPrompt
|
|
13796
|
+
});
|
|
13797
|
+
}
|
|
13672
13798
|
/**
|
|
13673
13799
|
* Resolve the host directory backing `/workspace` for an agent prompt.
|
|
13674
13800
|
*
|
|
@@ -13895,110 +14021,6 @@ function normalizeAgentDefinition(input, options = {}) {
|
|
|
13895
14021
|
...input.memory !== void 0 ? { memory: input.memory } : {}
|
|
13896
14022
|
};
|
|
13897
14023
|
}
|
|
13898
|
-
const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
|
|
13899
|
-
function shouldPersistAgentEvent(event) {
|
|
13900
|
-
return !SKIPPED_EVENT_TYPES.has(event.type);
|
|
13901
|
-
}
|
|
13902
|
-
async function persistSessionEvent(options) {
|
|
13903
|
-
const { sessionId, memoryConfig, eventType, payload } = options;
|
|
13904
|
-
const seq = await appendEvent(sessionId, eventType, payload);
|
|
13905
|
-
if (memoryConfig) try {
|
|
13906
|
-
await appendSessionLine(memoryConfig, sessionId, {
|
|
13907
|
-
seq,
|
|
13908
|
-
eventType,
|
|
13909
|
-
payload,
|
|
13910
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
13911
|
-
});
|
|
13912
|
-
} catch (err) {
|
|
13913
|
-
console.error("[memory] transcript append failed:", err);
|
|
13914
|
-
}
|
|
13915
|
-
return seq;
|
|
13916
|
-
}
|
|
13917
|
-
async function persistAgentEvent(sessionId, event, memoryConfig) {
|
|
13918
|
-
await persistSessionEvent({
|
|
13919
|
-
sessionId,
|
|
13920
|
-
memoryConfig,
|
|
13921
|
-
eventType: event.type,
|
|
13922
|
-
payload: event
|
|
13923
|
-
});
|
|
13924
|
-
if (event.type === "message_end") await persistSessionEvent({
|
|
13925
|
-
sessionId,
|
|
13926
|
-
memoryConfig,
|
|
13927
|
-
eventType: MESSAGE_EVENT_TYPE$1,
|
|
13928
|
-
payload: event.message
|
|
13929
|
-
});
|
|
13930
|
-
}
|
|
13931
|
-
async function prepareAgentSession(agentId, sessionId) {
|
|
13932
|
-
if (sessionId) {
|
|
13933
|
-
const session = await getSession(sessionId);
|
|
13934
|
-
if (!session) await createSession(agentId, sessionId, await resolveRunSourceFromTraceContext());
|
|
13935
|
-
else if (session.agentId !== agentId) throw new SessionAgentMismatchError(sessionId);
|
|
13936
|
-
return { sessionId };
|
|
13937
|
-
}
|
|
13938
|
-
return { sessionId: (await createSession(agentId, void 0, await resolveRunSourceFromTraceContext())).id };
|
|
13939
|
-
}
|
|
13940
|
-
async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
13941
|
-
const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
|
|
13942
|
-
const priorMessages = await listMessageEvents(sessionId);
|
|
13943
|
-
const runPrompt = async () => {
|
|
13944
|
-
const runtime = await agent.buildRuntime({
|
|
13945
|
-
agentId,
|
|
13946
|
-
sessionId,
|
|
13947
|
-
messages: priorMessages
|
|
13948
|
-
}, {
|
|
13949
|
-
...options,
|
|
13950
|
-
credentials: buildCredentialRunContext({ request: {
|
|
13951
|
-
...options.credentials,
|
|
13952
|
-
...input.context
|
|
13953
|
-
} })
|
|
13954
|
-
});
|
|
13955
|
-
const memoryConfig = runtime.memory?.config;
|
|
13956
|
-
const unsubscribe = runtime.pi.subscribe(async (event) => {
|
|
13957
|
-
if (!shouldPersistAgentEvent(event)) return;
|
|
13958
|
-
await persistAgentEvent(sessionId, event, memoryConfig);
|
|
13959
|
-
});
|
|
13960
|
-
try {
|
|
13961
|
-
const snapshot = await captureConsole(async () => prompt(runtime, input.message));
|
|
13962
|
-
const credentialError = runtime.takeCredentialError?.();
|
|
13963
|
-
if (credentialError && isCredentialError(credentialError)) throw credentialError;
|
|
13964
|
-
await touchSession(sessionId);
|
|
13965
|
-
return {
|
|
13966
|
-
sessionId,
|
|
13967
|
-
messages: messages(snapshot),
|
|
13968
|
-
error: errorMessage(snapshot) ?? null
|
|
13969
|
-
};
|
|
13970
|
-
} finally {
|
|
13971
|
-
unsubscribe();
|
|
13972
|
-
try {
|
|
13973
|
-
runtime.memory?.reindexSessions();
|
|
13974
|
-
} catch (err) {
|
|
13975
|
-
console.error("[memory] session reindex failed:", err);
|
|
13976
|
-
}
|
|
13977
|
-
runtime.memory?.close();
|
|
13978
|
-
await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
|
|
13979
|
-
await runtime.sandbox.dispose();
|
|
13980
|
-
}
|
|
13981
|
-
};
|
|
13982
|
-
if (options.skipAgentSessionSpan) return runPrompt();
|
|
13983
|
-
const parent = getTraceContext();
|
|
13984
|
-
return withSpan({
|
|
13985
|
-
kind: "agent_session",
|
|
13986
|
-
name: agentId,
|
|
13987
|
-
refId: sessionId,
|
|
13988
|
-
traceId: parent?.traceId ?? sessionId,
|
|
13989
|
-
metadata: {
|
|
13990
|
-
agentId,
|
|
13991
|
-
trigger: options.tracing?.trigger ?? (parent ? "subagent" : "api"),
|
|
13992
|
-
...options.tracing
|
|
13993
|
-
}
|
|
13994
|
-
}, runPrompt);
|
|
13995
|
-
}
|
|
13996
|
-
var SessionAgentMismatchError = class extends Error {
|
|
13997
|
-
constructor(sessionId) {
|
|
13998
|
-
super(`Session ${sessionId} does not belong to this agent`);
|
|
13999
|
-
this.name = "SessionAgentMismatchError";
|
|
14000
|
-
}
|
|
14001
|
-
};
|
|
14002
14024
|
/**
|
|
14003
14025
|
* Define an agent: normalized config plus a pipeline that builds sandbox + pi runtime on demand.
|
|
14004
14026
|
*/
|
|
@@ -14013,14 +14035,19 @@ function defineAgent(input, options = {}) {
|
|
|
14013
14035
|
...def,
|
|
14014
14036
|
key,
|
|
14015
14037
|
buildRuntime: (ctx, runPrompt) => buildAgentRuntime(def, ctx, runPrompt ?? options.runPrompt),
|
|
14016
|
-
prompt:
|
|
14017
|
-
|
|
14018
|
-
if (!
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
|
|
14022
|
-
|
|
14023
|
-
|
|
14038
|
+
prompt: (promptInput, runPrompt) => {
|
|
14039
|
+
const handle = getWorkflowRunHandle();
|
|
14040
|
+
if (handle?.agentRunner && !isWithinActionExecution() && !isWithinAgentPromptExecution()) {
|
|
14041
|
+
const { stepId, ...mergedRunPrompt } = {
|
|
14042
|
+
...options.runPrompt,
|
|
14043
|
+
...runPrompt
|
|
14044
|
+
};
|
|
14045
|
+
return handle.agentRunner(agent, promptInput, {
|
|
14046
|
+
id: stepId,
|
|
14047
|
+
runPrompt: mergedRunPrompt
|
|
14048
|
+
});
|
|
14049
|
+
}
|
|
14050
|
+
return runDirectAgentPrompt(agent, key, options.runPrompt, promptInput, runPrompt);
|
|
14024
14051
|
}
|
|
14025
14052
|
};
|
|
14026
14053
|
return agent;
|
|
@@ -14063,7 +14090,7 @@ function defineSubagentTool(input) {
|
|
|
14063
14090
|
tool: toolDef.name,
|
|
14064
14091
|
type: "subagent"
|
|
14065
14092
|
}
|
|
14066
|
-
}, () => agent.
|
|
14093
|
+
}, async () => runDirectAgentPrompt(agent, agent.key, void 0, { message: toMessage(params) }, { tracing: { trigger: "subagent" } }));
|
|
14067
14094
|
if (result.error) throw new Error(result.error);
|
|
14068
14095
|
return {
|
|
14069
14096
|
content: [{
|
|
@@ -14081,6 +14108,6 @@ function defineSubagentTool(input) {
|
|
|
14081
14108
|
return subagentTool;
|
|
14082
14109
|
}
|
|
14083
14110
|
//#endregion
|
|
14084
|
-
export { AgentCreateInputSchema, DEFAULT_THINKING_LEVEL, ModelRefSchema, SUBAGENT_TOOL, SessionAgentMismatchError, ThinkingLevelSchema, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
14111
|
+
export { AgentCreateInputSchema, DEFAULT_THINKING_LEVEL, ModelRefSchema, SUBAGENT_TOOL, SessionAgentMismatchError, ThinkingLevelSchema, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
14085
14112
|
|
|
14086
14113
|
//# sourceMappingURL=agent.mjs.map
|