@keystrokehq/keystroke 0.0.159 → 0.0.161
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 +1 -1
- package/dist/action.d.cts +3 -3
- package/dist/action.d.mts +3 -3
- package/dist/action.mjs +1 -1
- package/dist/agent-types.d.cts +1 -1
- package/dist/agent-types.d.mts +1 -1
- package/dist/agent.cjs +269 -39
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +4 -4
- package/dist/agent.d.mts +4 -4
- package/dist/agent.mjs +268 -40
- package/dist/agent.mjs.map +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/credentials.cjs +1 -1
- package/dist/credentials.d.cts +1 -1
- package/dist/credentials.d.mts +1 -1
- package/dist/credentials.mjs +1 -1
- package/dist/{dist-XKCtZShd.mjs → dist-BIbZjRd7.mjs} +4 -2
- package/dist/dist-BIbZjRd7.mjs.map +1 -0
- package/dist/{dist-DALSxODo.mjs → dist-CQH7Ircq.mjs} +32 -5
- package/dist/dist-CQH7Ircq.mjs.map +1 -0
- package/dist/{dist-lYNbBwe5.mjs → dist-DXzvN8aq.mjs} +210 -6
- package/dist/{dist-lYNbBwe5.mjs.map → dist-DXzvN8aq.mjs.map} +1 -1
- package/dist/{dist-u0RYk4-X.cjs → dist-DiqTL3ZF.cjs} +233 -5
- package/dist/{dist-u0RYk4-X.cjs.map → dist-DiqTL3ZF.cjs.map} +1 -1
- package/dist/{dist-D5jH3nQI.cjs → dist-lWDTuftA.cjs} +9 -1
- package/dist/dist-lWDTuftA.cjs.map +1 -0
- package/dist/{dist-DhBV2U_0.cjs → dist-mblcM3Bv.cjs} +37 -4
- package/dist/dist-mblcM3Bv.cjs.map +1 -0
- package/dist/{index-BcMCpDKh.d.cts → index-0KyTNuR1.d.mts} +5 -5
- package/dist/{index-Bd_asjgz.d.mts.map → index-0KyTNuR1.d.mts.map} +1 -1
- package/dist/{index-CUrU-w2Y.d.cts → index-BAIg1_V_.d.mts} +3 -3
- package/dist/{index-Qnwdoq7U.d.mts.map → index-BAIg1_V_.d.mts.map} +1 -1
- package/dist/{index-B4HxxDhO.d.cts → index-Bjg-QRlL.d.cts} +2 -2
- package/dist/{index-B4HxxDhO.d.cts.map → index-Bjg-QRlL.d.cts.map} +1 -1
- package/dist/{index-BNcrFoZi.d.cts → index-CaW3JRFU.d.cts} +15 -2
- package/dist/{index-BNcrFoZi.d.mts.map → index-CaW3JRFU.d.cts.map} +1 -1
- package/dist/{index-BNcrFoZi.d.mts → index-CaW3JRFU.d.mts} +15 -2
- package/dist/{index-BNcrFoZi.d.cts.map → index-CaW3JRFU.d.mts.map} +1 -1
- package/dist/{index-Bbe9CzYo.d.mts → index-CgMisiAc.d.mts} +7 -4
- package/dist/index-CgMisiAc.d.mts.map +1 -0
- package/dist/{index-Qnwdoq7U.d.mts → index-CsGfxjDx.d.cts} +3 -3
- package/dist/{index-CUrU-w2Y.d.cts.map → index-CsGfxjDx.d.cts.map} +1 -1
- package/dist/{index-CqbBhKYv.d.mts → index-CxjY9wjs.d.mts} +2 -2
- package/dist/{index-CqbBhKYv.d.mts.map → index-CxjY9wjs.d.mts.map} +1 -1
- package/dist/{index-BmXIGJlQ.d.cts → index-D7upoVsK.d.cts} +7 -4
- package/dist/index-D7upoVsK.d.cts.map +1 -0
- package/dist/{index-DuYf0Fdc.d.cts → index-DIm3_7or.d.cts} +41 -7
- package/dist/index-DIm3_7or.d.cts.map +1 -0
- package/dist/{index-jLW9DNA0.d.cts → index-DkQoSfqQ.d.cts} +12 -4
- package/dist/index-DkQoSfqQ.d.cts.map +1 -0
- package/dist/{index-Bd_asjgz.d.mts → index-Dr-3nl0A.d.cts} +5 -5
- package/dist/{index-BcMCpDKh.d.cts.map → index-Dr-3nl0A.d.cts.map} +1 -1
- package/dist/{index-CyCx29m7.d.mts → index-IVnunyAF.d.mts} +41 -7
- package/dist/index-IVnunyAF.d.mts.map +1 -0
- package/dist/{index-BUmyUoC2.d.mts → index-p6yOVMbx.d.mts} +12 -4
- package/dist/index-p6yOVMbx.d.mts.map +1 -0
- package/dist/{mistral-CWlaNuqc.mjs → mistral-CDuUHkpO.mjs} +2 -2
- package/dist/{mistral-CWlaNuqc.mjs.map → mistral-CDuUHkpO.mjs.map} +1 -1
- package/dist/{mistral-DIpD1PUg.cjs → mistral-DuG294d1.cjs} +2 -2
- package/dist/{mistral-DIpD1PUg.cjs.map → mistral-DuG294d1.cjs.map} +1 -1
- package/dist/sandbox.d.cts +1 -1
- package/dist/sandbox.d.mts +1 -1
- package/dist/{sse-DuzdM7Va.mjs → sse-BBd2aLiw.mjs} +2 -2
- package/dist/{sse-DuzdM7Va.mjs.map → sse-BBd2aLiw.mjs.map} +1 -1
- package/dist/{sse-DXvz9wn_.cjs → sse-DCsg_ELF.cjs} +2 -2
- package/dist/{sse-DXvz9wn_.cjs.map → sse-DCsg_ELF.cjs.map} +1 -1
- package/dist/trigger.cjs +1 -1
- package/dist/trigger.d.cts +3 -3
- package/dist/trigger.d.mts +3 -3
- package/dist/trigger.mjs +1 -1
- package/dist/workflow.cjs +2 -1
- package/dist/workflow.d.cts +3 -2
- package/dist/workflow.d.mts +3 -2
- package/dist/workflow.mjs +2 -2
- package/package.json +1 -1
- package/dist/dist-D5jH3nQI.cjs.map +0 -1
- package/dist/dist-DALSxODo.mjs.map +0 -1
- package/dist/dist-DhBV2U_0.cjs.map +0 -1
- package/dist/dist-XKCtZShd.mjs.map +0 -1
- package/dist/index-BUmyUoC2.d.mts.map +0 -1
- package/dist/index-Bbe9CzYo.d.mts.map +0 -1
- package/dist/index-BmXIGJlQ.d.cts.map +0 -1
- package/dist/index-CyCx29m7.d.mts.map +0 -1
- package/dist/index-DuYf0Fdc.d.cts.map +0 -1
- package/dist/index-jLW9DNA0.d.cts.map +0 -1
package/dist/agent.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as ThinkingLevel, u as getModel } from "./index-
|
|
2
|
-
import { A as
|
|
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-
|
|
4
|
-
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentModelId, AgentModelIdSchema, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, 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, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
1
|
+
import { l as ThinkingLevel, u as getModel } from "./index-Dr-3nl0A.cjs";
|
|
2
|
+
import { A as loadAssetManifest, B as runLlm, C as createAgent, D as errorMessage, E as defineTool, F as resolveAgentAssets, G as AgentModelIdSchema, H as AgentCreateInput, I as resolveAgentId, J as parseAgentCreateInput, K as DEFAULT_THINKING_LEVEL, L as resolveAgentTools, M as normalizeAgentDefinition, N as prepareAgentSession, O as forceToolChoice, P as prompt, R as resolveAgentWorkspaceRoot, S as buildAgentRuntime, T as defineSubagentTool, U as AgentCreateInputSchema, V as snapshot, W as AgentModelId, X as resolveThinkingLevel, Y as resolveAgentModel, _ 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 messages, k as getSubagentToolMetadata, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as ThinkingLevelSchema, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SubagentTool, w as defineAgent, x as SubagentToolMetadata, y as SubagentToolDetails, z as runAgentPrompt } from "./index-DIm3_7or.cjs";
|
|
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-CsGfxjDx.cjs";
|
|
4
|
+
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentModelId, AgentModelIdSchema, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineSubagentToolInput, type ForcedToolChoice, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, 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, forceToolChoice, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, runLlm, snapshot };
|
package/dist/agent.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as ThinkingLevel, u as getModel } from "./index-
|
|
2
|
-
import { A as
|
|
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-
|
|
4
|
-
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentModelId, AgentModelIdSchema, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineSubagentToolInput, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, 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, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
1
|
+
import { l as ThinkingLevel, u as getModel } from "./index-0KyTNuR1.mjs";
|
|
2
|
+
import { A as loadAssetManifest, B as runLlm, C as createAgent, D as errorMessage, E as defineTool, F as resolveAgentAssets, G as AgentModelIdSchema, H as AgentCreateInput, I as resolveAgentId, J as parseAgentCreateInput, K as DEFAULT_THINKING_LEVEL, L as resolveAgentTools, M as normalizeAgentDefinition, N as prepareAgentSession, O as forceToolChoice, P as prompt, R as resolveAgentWorkspaceRoot, S as buildAgentRuntime, T as defineSubagentTool, U as AgentCreateInputSchema, V as snapshot, W as AgentModelId, X as resolveThinkingLevel, Y as resolveAgentModel, _ 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 messages, k as getSubagentToolMetadata, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as ThinkingLevelSchema, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SubagentTool, w as defineAgent, x as SubagentToolMetadata, y as SubagentToolDetails, z as runAgentPrompt } from "./index-IVnunyAF.mjs";
|
|
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-BAIg1_V_.mjs";
|
|
4
|
+
export { type Agent, type AgentAssetInput, type AgentConfig, type AgentCreateInput, AgentCreateInputSchema, type AgentDefinition, type AgentDefinitionInput, type AgentModelId, AgentModelIdSchema, type AgentRuntime, type AgentSnapshot, type BuildAgentRuntimeContext, DEFAULT_THINKING_LEVEL, type DefineSubagentToolInput, type ForcedToolChoice, type McpAuthOptions, type McpCallToolOptions, type McpConnection, type McpDefinition, type McpDefinitionInput, type McpHttpTransport, type McpServerOptions, type McpStdioOptions, type McpStdioTransport, type McpTransport, 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, forceToolChoice, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, runLlm, snapshot };
|
package/dist/agent.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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, 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-Dv44b9V1.mjs";
|
|
2
|
-
import { c as isAction, f as resolveActionTool, o as getRunSignal, s as getWorkflowRunHandle, u as isWithinActionExecution } from "./dist-
|
|
2
|
+
import { T as toolParameters, c as isAction, f as resolveActionTool, o as getRunSignal, s as getWorkflowRunHandle, u as isWithinActionExecution } from "./dist-BIbZjRd7.mjs";
|
|
3
3
|
import "./env-api-keys-mjSaOeuP.mjs";
|
|
4
4
|
import { i as getModel, t as AssistantMessageEventStream } from "./event-stream-C7YBbzsc.mjs";
|
|
5
5
|
import "./json-parse-Drlv-g_X.mjs";
|
|
6
|
-
import { C as isMcp,
|
|
6
|
+
import { C as connectMcpDefinition, D as isMcp, E as defineMcp, S as withSpan, T as connectMcpStdio, _ as resolveRunSourceFromTraceContext, a as resolveActionCredentials, b as getTraceContext, c as appendEvent, d as finalizeAgentRunFromPrompt, f as getAgentByRoute, g as resolveAgentRunSourceFromSession, h as recordLlmUsageFromAssistantMessage, i as isCredentialError, l as createAgentRun, m as listMessageEvents, n as captureCredentialToolErrors, o as resolveMcpTools, p as getSession, r as createCredentialResolver, s as MESSAGE_EVENT_TYPE$1, t as buildCredentialRunContext, u as createSession, v as touchSession, w as connectMcpServer, y as captureConsole } from "./dist-DXzvN8aq.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -900,7 +900,7 @@ function loadGoogleVertexProviderModule() {
|
|
|
900
900
|
return googleVertexProviderModulePromise;
|
|
901
901
|
}
|
|
902
902
|
function loadMistralProviderModule() {
|
|
903
|
-
mistralProviderModulePromise ||= import("./mistral-
|
|
903
|
+
mistralProviderModulePromise ||= import("./mistral-CDuUHkpO.mjs").then((module) => {
|
|
904
904
|
const provider = module;
|
|
905
905
|
return {
|
|
906
906
|
stream: provider.streamMistral,
|
|
@@ -1025,6 +1025,9 @@ function resolveApiProvider(api) {
|
|
|
1025
1025
|
function streamSimple(model, context, options) {
|
|
1026
1026
|
return resolveApiProvider(model.api).streamSimple(model, context, options);
|
|
1027
1027
|
}
|
|
1028
|
+
async function completeSimple(model, context, options) {
|
|
1029
|
+
return streamSimple(model, context, options).result();
|
|
1030
|
+
}
|
|
1028
1031
|
//#endregion
|
|
1029
1032
|
//#region ../../node_modules/.pnpm/typebox@1.1.38/node_modules/typebox/build/schema/types/_guard.mjs
|
|
1030
1033
|
function IsGuardInterface(value) {
|
|
@@ -13384,7 +13387,7 @@ function readMd(path, limit) {
|
|
|
13384
13387
|
chars: content.length
|
|
13385
13388
|
};
|
|
13386
13389
|
}
|
|
13387
|
-
function extractText(content) {
|
|
13390
|
+
function extractText$1(content) {
|
|
13388
13391
|
if (typeof content === "string") return content;
|
|
13389
13392
|
if (Array.isArray(content)) {
|
|
13390
13393
|
const parts = [];
|
|
@@ -13438,7 +13441,7 @@ function extractSessionRows(file) {
|
|
|
13438
13441
|
continue;
|
|
13439
13442
|
}
|
|
13440
13443
|
if (obj.type !== "message" || !obj.message) continue;
|
|
13441
|
-
const text = extractText(obj.message.content);
|
|
13444
|
+
const text = extractText$1(obj.message.content);
|
|
13442
13445
|
if (!text) continue;
|
|
13443
13446
|
rows.push({
|
|
13444
13447
|
line_no: i + 1,
|
|
@@ -13730,13 +13733,32 @@ function runWithinAgentPromptExecution(fn) {
|
|
|
13730
13733
|
function isWithinAgentPromptExecution() {
|
|
13731
13734
|
return executingAgentPrompt.getStore() === true;
|
|
13732
13735
|
}
|
|
13736
|
+
function llmUsageFromAssistantMessage(message) {
|
|
13737
|
+
const usage = message.usage;
|
|
13738
|
+
if (!usage) return null;
|
|
13739
|
+
return {
|
|
13740
|
+
label: message.responseModel ?? message.model ?? "unknown-model",
|
|
13741
|
+
quantity: usage.totalTokens,
|
|
13742
|
+
amount: usage.cost.total,
|
|
13743
|
+
metadata: {
|
|
13744
|
+
provider: message.provider,
|
|
13745
|
+
model: message.model,
|
|
13746
|
+
responseModel: message.responseModel ?? null,
|
|
13747
|
+
input: usage.input,
|
|
13748
|
+
output: usage.output,
|
|
13749
|
+
cacheRead: usage.cacheRead,
|
|
13750
|
+
cacheWrite: usage.cacheWrite,
|
|
13751
|
+
cost: usage.cost
|
|
13752
|
+
}
|
|
13753
|
+
};
|
|
13754
|
+
}
|
|
13733
13755
|
const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
|
|
13734
13756
|
function shouldPersistAgentEvent(event) {
|
|
13735
13757
|
return !SKIPPED_EVENT_TYPES.has(event.type);
|
|
13736
13758
|
}
|
|
13737
13759
|
async function persistSessionEvent(options) {
|
|
13738
|
-
const { sessionId, memoryConfig, eventType, payload } = options;
|
|
13739
|
-
const seq = await appendEvent(sessionId, eventType, payload);
|
|
13760
|
+
const { sessionId, runId, memoryConfig, eventType, payload } = options;
|
|
13761
|
+
const seq = await appendEvent(sessionId, eventType, payload, { runId });
|
|
13740
13762
|
if (memoryConfig) try {
|
|
13741
13763
|
await appendSessionLine(memoryConfig, sessionId, {
|
|
13742
13764
|
seq,
|
|
@@ -13749,15 +13771,19 @@ async function persistSessionEvent(options) {
|
|
|
13749
13771
|
}
|
|
13750
13772
|
return seq;
|
|
13751
13773
|
}
|
|
13752
|
-
async function persistAgentEvent(sessionId, event,
|
|
13774
|
+
async function persistAgentEvent(sessionId, event, options) {
|
|
13775
|
+
const runId = options?.runId ?? null;
|
|
13776
|
+
const memoryConfig = options?.memoryConfig;
|
|
13753
13777
|
await persistSessionEvent({
|
|
13754
13778
|
sessionId,
|
|
13779
|
+
runId,
|
|
13755
13780
|
memoryConfig,
|
|
13756
13781
|
eventType: event.type,
|
|
13757
13782
|
payload: event
|
|
13758
13783
|
});
|
|
13759
13784
|
if (event.type === "message_end") await persistSessionEvent({
|
|
13760
13785
|
sessionId,
|
|
13786
|
+
runId,
|
|
13761
13787
|
memoryConfig,
|
|
13762
13788
|
eventType: MESSAGE_EVENT_TYPE$1,
|
|
13763
13789
|
payload: event.message
|
|
@@ -13775,49 +13801,93 @@ async function prepareAgentSession(agentId, sessionId, options) {
|
|
|
13775
13801
|
async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
13776
13802
|
const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
|
|
13777
13803
|
const priorMessages = await listMessageEvents(sessionId);
|
|
13804
|
+
const runSource = await resolveAgentRunSourceFromSession(sessionId);
|
|
13805
|
+
const runId = await createAgentRun({
|
|
13806
|
+
sessionId,
|
|
13807
|
+
agentId,
|
|
13808
|
+
sourceKind: runSource.sourceKind,
|
|
13809
|
+
sourceId: runSource.sourceId,
|
|
13810
|
+
ranByUserId: runSource.ranByUserId
|
|
13811
|
+
});
|
|
13778
13812
|
const runPrompt = async () => {
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
...options,
|
|
13785
|
-
credentials: buildCredentialRunContext({ request: {
|
|
13786
|
-
...options.credentials,
|
|
13787
|
-
...input.context
|
|
13788
|
-
} })
|
|
13789
|
-
});
|
|
13790
|
-
const memoryConfig = runtime.memory?.config;
|
|
13791
|
-
const unsubscribe = runtime.pi.subscribe(async (event) => {
|
|
13792
|
-
if (!shouldPersistAgentEvent(event)) return;
|
|
13793
|
-
await persistAgentEvent(sessionId, event, memoryConfig);
|
|
13794
|
-
});
|
|
13813
|
+
let promptError = null;
|
|
13814
|
+
let runtime;
|
|
13815
|
+
let unsubscribe;
|
|
13816
|
+
let onAbort;
|
|
13817
|
+
const pendingHandlers = /* @__PURE__ */ new Set();
|
|
13795
13818
|
const signal = getRunSignal();
|
|
13796
|
-
const onAbort = () => runtime.pi.abort();
|
|
13797
|
-
if (signal.aborted) onAbort();
|
|
13798
|
-
else signal.addEventListener("abort", onAbort, { once: true });
|
|
13799
13819
|
try {
|
|
13800
|
-
|
|
13801
|
-
|
|
13820
|
+
runtime = await agent.buildRuntime({
|
|
13821
|
+
agentId,
|
|
13822
|
+
sessionId,
|
|
13823
|
+
messages: priorMessages
|
|
13824
|
+
}, {
|
|
13825
|
+
...options,
|
|
13826
|
+
credentials: buildCredentialRunContext({ request: {
|
|
13827
|
+
...options.credentials,
|
|
13828
|
+
...input.context
|
|
13829
|
+
} })
|
|
13830
|
+
});
|
|
13831
|
+
const activeRuntime = runtime;
|
|
13832
|
+
const memoryConfig = activeRuntime.memory?.config;
|
|
13833
|
+
unsubscribe = activeRuntime.pi.subscribe((event) => {
|
|
13834
|
+
if (!shouldPersistAgentEvent(event)) return;
|
|
13835
|
+
const tracked = (async () => {
|
|
13836
|
+
await persistAgentEvent(sessionId, event, {
|
|
13837
|
+
runId,
|
|
13838
|
+
memoryConfig
|
|
13839
|
+
});
|
|
13840
|
+
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
13841
|
+
const usage = llmUsageFromAssistantMessage(event.message);
|
|
13842
|
+
if (usage) await recordLlmUsageFromAssistantMessage({
|
|
13843
|
+
runId,
|
|
13844
|
+
usage
|
|
13845
|
+
});
|
|
13846
|
+
}
|
|
13847
|
+
})().finally(() => {
|
|
13848
|
+
pendingHandlers.delete(tracked);
|
|
13849
|
+
});
|
|
13850
|
+
pendingHandlers.add(tracked);
|
|
13851
|
+
return tracked;
|
|
13852
|
+
});
|
|
13853
|
+
onAbort = () => activeRuntime.pi.abort();
|
|
13854
|
+
if (signal.aborted) onAbort();
|
|
13855
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
13856
|
+
const snapshot = await captureConsole(async () => prompt(activeRuntime, input.message));
|
|
13857
|
+
const credentialError = activeRuntime.takeCredentialError?.();
|
|
13802
13858
|
if (credentialError && isCredentialError(credentialError)) throw credentialError;
|
|
13803
13859
|
await touchSession(sessionId);
|
|
13804
13860
|
return {
|
|
13805
13861
|
sessionId,
|
|
13862
|
+
runId,
|
|
13806
13863
|
messages: messages(snapshot),
|
|
13807
13864
|
error: errorMessage(snapshot) ?? null,
|
|
13808
13865
|
canceled: signal.aborted
|
|
13809
13866
|
};
|
|
13867
|
+
} catch (error) {
|
|
13868
|
+
promptError = error;
|
|
13869
|
+
throw error;
|
|
13810
13870
|
} finally {
|
|
13811
|
-
signal.removeEventListener("abort", onAbort);
|
|
13812
|
-
unsubscribe();
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13871
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
13872
|
+
unsubscribe?.();
|
|
13873
|
+
await Promise.allSettled([...pendingHandlers]);
|
|
13874
|
+
if (runtime) {
|
|
13875
|
+
try {
|
|
13876
|
+
runtime.memory?.reindexSessions();
|
|
13877
|
+
} catch (err) {
|
|
13878
|
+
console.error("[memory] session reindex failed:", err);
|
|
13879
|
+
}
|
|
13880
|
+
runtime.memory?.close();
|
|
13881
|
+
await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
|
|
13882
|
+
await runtime.sandbox.dispose();
|
|
13883
|
+
}
|
|
13884
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
13885
|
+
await finalizeAgentRunFromPrompt({
|
|
13886
|
+
runId,
|
|
13887
|
+
status: promptError ? "failed" : signal.aborted ? "canceled" : "completed",
|
|
13888
|
+
error: promptError,
|
|
13889
|
+
finishedAt
|
|
13890
|
+
});
|
|
13821
13891
|
}
|
|
13822
13892
|
};
|
|
13823
13893
|
if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);
|
|
@@ -14161,7 +14231,165 @@ function defineSubagentTool(input) {
|
|
|
14161
14231
|
subagentTool[SUBAGENT_TOOL] = metadata;
|
|
14162
14232
|
return subagentTool;
|
|
14163
14233
|
}
|
|
14234
|
+
/**
|
|
14235
|
+
* Best-effort provider `tool_choice` for forcing a named tool. Returns `undefined`
|
|
14236
|
+
* when the API shape is unknown so callers can rely on prompt + validate + retry.
|
|
14237
|
+
*/
|
|
14238
|
+
function forceToolChoice(api, toolName) {
|
|
14239
|
+
switch (api) {
|
|
14240
|
+
case "anthropic-messages": return {
|
|
14241
|
+
type: "tool",
|
|
14242
|
+
name: toolName
|
|
14243
|
+
};
|
|
14244
|
+
case "openai-completions":
|
|
14245
|
+
case "openai-responses":
|
|
14246
|
+
case "azure-openai-responses": return {
|
|
14247
|
+
type: "function",
|
|
14248
|
+
function: { name: toolName }
|
|
14249
|
+
};
|
|
14250
|
+
case "bedrock-converse-stream": return { tool: { name: toolName } };
|
|
14251
|
+
case "google-generative-ai":
|
|
14252
|
+
case "google-vertex": return "any";
|
|
14253
|
+
default: return;
|
|
14254
|
+
}
|
|
14255
|
+
}
|
|
14256
|
+
const RESPOND_TOOL_NAME = "respond";
|
|
14257
|
+
const STRUCTURED_OUTPUT_INSTRUCTION = "Respond only by calling `respond` with arguments matching the schema; do not answer in plain text.";
|
|
14258
|
+
const MAX_OBJECT_ATTEMPTS = 3;
|
|
14259
|
+
/** Same validation as `defineAgent` — format check before catalog lookup. */
|
|
14260
|
+
function resolvePromptModel(model) {
|
|
14261
|
+
return resolveAgentModel(AgentModelIdSchema.parse(model));
|
|
14262
|
+
}
|
|
14263
|
+
/**
|
|
14264
|
+
* pi-ai types tool `parameters` as TypeBox `TSchema`, but providers consume JSON Schema
|
|
14265
|
+
* at runtime. Same bridge as `resolveActionTool` in `@keystrokehq/action`.
|
|
14266
|
+
*/
|
|
14267
|
+
function buildToolParameters(schema) {
|
|
14268
|
+
return toolParameters(schema);
|
|
14269
|
+
}
|
|
14270
|
+
function extractText(message) {
|
|
14271
|
+
return message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
14272
|
+
}
|
|
14273
|
+
function extractToolCall(message) {
|
|
14274
|
+
return message.content.find((part) => part.type === "toolCall");
|
|
14275
|
+
}
|
|
14276
|
+
function needsEnvelope(schema) {
|
|
14277
|
+
const json = z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
14278
|
+
if (typeof json !== "object" || json === null || !("type" in json)) return true;
|
|
14279
|
+
return json.type !== "object";
|
|
14280
|
+
}
|
|
14281
|
+
function wrapSchemaForTool(schema) {
|
|
14282
|
+
if (!needsEnvelope(schema)) return {
|
|
14283
|
+
toolSchema: schema,
|
|
14284
|
+
unwrap: (args) => args
|
|
14285
|
+
};
|
|
14286
|
+
const envelopeSchema = z.object({ result: schema });
|
|
14287
|
+
return {
|
|
14288
|
+
toolSchema: envelopeSchema,
|
|
14289
|
+
unwrap: (args) => envelopeSchema.parse(args).result
|
|
14290
|
+
};
|
|
14291
|
+
}
|
|
14292
|
+
function buildRespondTool(schema) {
|
|
14293
|
+
return {
|
|
14294
|
+
name: RESPOND_TOOL_NAME,
|
|
14295
|
+
description: "Return the final result.",
|
|
14296
|
+
parameters: buildToolParameters(schema)
|
|
14297
|
+
};
|
|
14298
|
+
}
|
|
14299
|
+
function resolvePromptReasoning(thinkingLevel) {
|
|
14300
|
+
if (!thinkingLevel || thinkingLevel === "off") return;
|
|
14301
|
+
return thinkingLevel;
|
|
14302
|
+
}
|
|
14303
|
+
function formatValidationError(error) {
|
|
14304
|
+
return error instanceof Error ? error.message : String(error);
|
|
14305
|
+
}
|
|
14306
|
+
async function recordUsageFromMessage(message, hooks) {
|
|
14307
|
+
const usage = llmUsageFromAssistantMessage(message);
|
|
14308
|
+
if (usage) await hooks?.onUsage?.(usage);
|
|
14309
|
+
}
|
|
14310
|
+
async function runPromptText(opts, hooks) {
|
|
14311
|
+
const model = resolvePromptModel(opts.model);
|
|
14312
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14313
|
+
const message = await completeSimple(model, {
|
|
14314
|
+
systemPrompt: opts.system,
|
|
14315
|
+
messages: [{
|
|
14316
|
+
role: "user",
|
|
14317
|
+
content: opts.prompt,
|
|
14318
|
+
timestamp: Date.now()
|
|
14319
|
+
}]
|
|
14320
|
+
}, {
|
|
14321
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14322
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14323
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {}
|
|
14324
|
+
});
|
|
14325
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14326
|
+
await recordUsageFromMessage(message, hooks);
|
|
14327
|
+
return extractText(message);
|
|
14328
|
+
}
|
|
14329
|
+
async function runPromptObject(opts, hooks) {
|
|
14330
|
+
const schema = opts.outputSchema;
|
|
14331
|
+
if (!schema) throw new Error("outputSchema is required for structured LLM output");
|
|
14332
|
+
const model = resolvePromptModel(opts.model);
|
|
14333
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14334
|
+
const { toolSchema, unwrap } = wrapSchemaForTool(schema);
|
|
14335
|
+
const tool = buildRespondTool(toolSchema);
|
|
14336
|
+
const toolChoice = forceToolChoice(model.api, RESPOND_TOOL_NAME);
|
|
14337
|
+
const systemPrompt = [opts.system, STRUCTURED_OUTPUT_INSTRUCTION].filter(Boolean).join("\n\n");
|
|
14338
|
+
const messages = [{
|
|
14339
|
+
role: "user",
|
|
14340
|
+
content: opts.prompt,
|
|
14341
|
+
timestamp: Date.now()
|
|
14342
|
+
}];
|
|
14343
|
+
let lastError;
|
|
14344
|
+
for (let attempt = 0; attempt < MAX_OBJECT_ATTEMPTS; attempt++) {
|
|
14345
|
+
let message;
|
|
14346
|
+
let toolCall;
|
|
14347
|
+
try {
|
|
14348
|
+
message = await completeSimple(model, {
|
|
14349
|
+
systemPrompt,
|
|
14350
|
+
messages,
|
|
14351
|
+
tools: [tool]
|
|
14352
|
+
}, {
|
|
14353
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14354
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14355
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {},
|
|
14356
|
+
...toolChoice !== void 0 ? { toolChoice } : {}
|
|
14357
|
+
});
|
|
14358
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14359
|
+
await recordUsageFromMessage(message, hooks);
|
|
14360
|
+
toolCall = extractToolCall(message);
|
|
14361
|
+
if (!toolCall) throw new Error("Model did not return a tool call");
|
|
14362
|
+
return schema.parse(unwrap(toolCall.arguments));
|
|
14363
|
+
} catch (error) {
|
|
14364
|
+
lastError = error;
|
|
14365
|
+
if (attempt === MAX_OBJECT_ATTEMPTS - 1) break;
|
|
14366
|
+
const correction = `Validation failed: ${formatValidationError(error)}. Call respond again with valid arguments.`;
|
|
14367
|
+
if (message && toolCall) messages.push(message, {
|
|
14368
|
+
role: "toolResult",
|
|
14369
|
+
toolCallId: toolCall.id,
|
|
14370
|
+
toolName: toolCall.name,
|
|
14371
|
+
content: [{
|
|
14372
|
+
type: "text",
|
|
14373
|
+
text: correction
|
|
14374
|
+
}],
|
|
14375
|
+
isError: true,
|
|
14376
|
+
timestamp: Date.now()
|
|
14377
|
+
});
|
|
14378
|
+
else if (message) messages.push(message, {
|
|
14379
|
+
role: "user",
|
|
14380
|
+
content: correction,
|
|
14381
|
+
timestamp: Date.now()
|
|
14382
|
+
});
|
|
14383
|
+
}
|
|
14384
|
+
}
|
|
14385
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
14386
|
+
}
|
|
14387
|
+
/** One-shot LLM generation for workflow `promptLlm` steps (pi-ai transport). */
|
|
14388
|
+
async function runLlm(opts, hooks) {
|
|
14389
|
+
if (opts.outputSchema) return runPromptObject(opts, hooks);
|
|
14390
|
+
return runPromptText(opts, hooks);
|
|
14391
|
+
}
|
|
14164
14392
|
//#endregion
|
|
14165
|
-
export { AgentCreateInputSchema, AgentModelIdSchema, DEFAULT_THINKING_LEVEL, 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, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, snapshot };
|
|
14393
|
+
export { AgentCreateInputSchema, AgentModelIdSchema, DEFAULT_THINKING_LEVEL, SUBAGENT_TOOL, SessionAgentMismatchError, ThinkingLevelSchema, buildAgentRuntime, connectMcpDefinition, connectMcpServer, connectMcpStdio, createAgent, defineAgent, defineMcp, defineSubagentTool, defineTool, errorMessage, forceToolChoice, getModel, getSubagentToolMetadata, isMcp, loadAssetManifest, messages, normalizeAgentDefinition, parseAgentCreateInput, prepareAgentSession, prompt, resolveAgentAssets, resolveAgentId, resolveAgentModel, resolveAgentTools, resolveAgentWorkspaceRoot, resolveThinkingLevel, runAgentPrompt, runLlm, snapshot };
|
|
14166
14394
|
|
|
14167
14395
|
//# sourceMappingURL=agent.mjs.map
|