@keystrokehq/keystroke 0.0.158 → 0.0.160
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 +162 -5
- 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 +161 -6
- 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-lDHLFeHS.mjs → dist-BAzfOMfz.mjs} +3 -4
- package/dist/{dist-lDHLFeHS.mjs.map → dist-BAzfOMfz.mjs.map} +1 -1
- package/dist/{dist-C2-wphiV.cjs → dist-BkkOal_e.cjs} +3 -4
- package/dist/{dist-C2-wphiV.cjs.map → dist-BkkOal_e.cjs.map} +1 -1
- package/dist/{dist-BsLHL5ev.mjs → dist-C8t_Snfd.mjs} +32 -5
- package/dist/dist-C8t_Snfd.mjs.map +1 -0
- package/dist/{dist-BPL6RGOX.cjs → dist-DFXV_Io5.cjs} +7 -2
- package/dist/dist-DFXV_Io5.cjs.map +1 -0
- package/dist/{dist-B_PNHSDU.mjs → dist-DM1Na5CA.mjs} +2 -3
- package/dist/dist-DM1Na5CA.mjs.map +1 -0
- package/dist/{dist-BN4tLQ4S.cjs → dist-fqWJTm0u.cjs} +37 -4
- package/dist/dist-fqWJTm0u.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-DuYf0Fdc.d.cts → index-BbwuSuxl.d.mts} +29 -7
- package/dist/index-BbwuSuxl.d.mts.map +1 -0
- 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-CaW3JRFU.d.cts.map +1 -0
- package/dist/{index-BNcrFoZi.d.mts → index-CaW3JRFU.d.mts} +15 -2
- package/dist/index-CaW3JRFU.d.mts.map +1 -0
- 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-CyCx29m7.d.mts → index-DaxRr-x9.d.cts} +29 -7
- package/dist/index-DaxRr-x9.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-BUmyUoC2.d.mts → index-p6yOVMbx.d.mts} +12 -4
- package/dist/index-p6yOVMbx.d.mts.map +1 -0
- package/dist/{mistral-DIdWCzNl.mjs → mistral-BRIv8KXE.mjs} +2 -2
- package/dist/{mistral-DIdWCzNl.mjs.map → mistral-BRIv8KXE.mjs.map} +1 -1
- package/dist/{mistral-jf7ZLGhZ.cjs → mistral-DUKMgFL1.cjs} +2 -2
- package/dist/{mistral-jf7ZLGhZ.cjs.map → mistral-DUKMgFL1.cjs.map} +1 -1
- package/dist/sandbox.d.cts +1 -1
- package/dist/sandbox.d.mts +1 -1
- package/dist/{sse-DL0amYvP.mjs → sse-Ba5sWI6l.mjs} +2 -2
- package/dist/{sse-DL0amYvP.mjs.map → sse-Ba5sWI6l.mjs.map} +1 -1
- package/dist/{sse-cQ49VLYa.cjs → sse-jvB09Ct-.cjs} +2 -2
- package/dist/{sse-cQ49VLYa.cjs.map → sse-jvB09Ct-.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-BN4tLQ4S.cjs.map +0 -1
- package/dist/dist-BPL6RGOX.cjs.map +0 -1
- package/dist/dist-B_PNHSDU.mjs.map +0 -1
- package/dist/dist-BsLHL5ev.mjs.map +0 -1
- package/dist/index-BNcrFoZi.d.cts.map +0 -1
- package/dist/index-BNcrFoZi.d.mts.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/action.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_dist = require("./dist-
|
|
2
|
+
const require_dist = require("./dist-DFXV_Io5.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;
|
package/dist/action.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { C as
|
|
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, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
|
|
1
|
+
import { C as defineCredential, E as toCredentialRequirement, S as credentialInputSchema, T as normalizeCredentialList, a as CredentialInput, 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 isCredentialInput, x as credential, y as ResolvedCredentials } from "./index-CaW3JRFU.cjs";
|
|
2
|
+
import { C as runWithRunSignal, S as runOutsideActionExecution, _ as isAction, a as ResolveActionCredentialsFn, b as registerWorkflowRunGetter, c as WorkflowActionDefinition, d as createStepInvocation, f as defineAction, g as getWorkflowRunHandle, h as getRunSignal, i as AgentRunOptions, l as WorkflowRunHandle, m as getActionCredentialRequirements, n as ActionDefinition, o as ResolveActionToolOptions, p as executeAction, r as ActionDefinitionInput, s as StepInvocation, t as ActionCredentialConsumer, u as actionCoreSchema, v as isStepInvocation, w as runWithinActionExecution, x as resolveActionTool, y as isWithinActionExecution } from "./index-D7upoVsK.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, type WorkflowRunHandle, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
|
package/dist/action.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { C as
|
|
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, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
|
|
1
|
+
import { C as defineCredential, E as toCredentialRequirement, S as credentialInputSchema, T as normalizeCredentialList, a as CredentialInput, 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 isCredentialInput, x as credential, y as ResolvedCredentials } from "./index-CaW3JRFU.mjs";
|
|
2
|
+
import { C as runWithRunSignal, S as runOutsideActionExecution, _ as isAction, a as ResolveActionCredentialsFn, b as registerWorkflowRunGetter, c as WorkflowActionDefinition, d as createStepInvocation, f as defineAction, g as getWorkflowRunHandle, h as getRunSignal, i as AgentRunOptions, l as WorkflowRunHandle, m as getActionCredentialRequirements, n as ActionDefinition, o as ResolveActionToolOptions, p as executeAction, r as ActionDefinitionInput, s as StepInvocation, t as ActionCredentialConsumer, u as actionCoreSchema, v as isStepInvocation, w as runWithinActionExecution, x as resolveActionTool, y as isWithinActionExecution } from "./index-CgMisiAc.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, type WorkflowRunHandle, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
|
package/dist/action.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as normalizeCredentialList, S as isCredentialInput, a as getActionCredentialRequirements, b as credentialInputSchema, c as isAction, d as registerWorkflowRunGetter, f as resolveActionTool, g as CREDENTIAL_SCOPE_LEVELS, h as runWithinActionExecution, i as executeAction, l as isStepInvocation, m as runWithRunSignal, n as createStepInvocation, o as getRunSignal, p as runOutsideActionExecution, r as defineAction, s as getWorkflowRunHandle, t as actionCoreSchema, u as isWithinActionExecution, v as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, w as toCredentialRequirement, x as defineCredential, y as credential } from "./dist-
|
|
1
|
+
import { C as normalizeCredentialList, S as isCredentialInput, a as getActionCredentialRequirements, b as credentialInputSchema, c as isAction, d as registerWorkflowRunGetter, f as resolveActionTool, g as CREDENTIAL_SCOPE_LEVELS, h as runWithinActionExecution, i as executeAction, l as isStepInvocation, m as runWithRunSignal, n as createStepInvocation, o as getRunSignal, p as runOutsideActionExecution, r as defineAction, s as getWorkflowRunHandle, t as actionCoreSchema, u as isWithinActionExecution, v as DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, w as toCredentialRequirement, x as defineCredential, y as credential } from "./dist-DM1Na5CA.mjs";
|
|
2
2
|
export { CREDENTIAL_SCOPE_LEVELS, DEFAULT_CREDENTIAL_RESOLUTION_CHAIN, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
|
package/dist/agent-types.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as AgentState, c as AgentToolUpdateCallback,
|
|
1
|
+
import { a as AgentState, c as AgentToolUpdateCallback, f as AssistantMessage, g as UserMessage, h as TextContent, i as AgentMessage, l as ThinkingLevel, m as Model, n as AgentOptions, o as AgentTool, p as Message, r as AgentEvent, s as AgentToolResult } from "./index-Dr-3nl0A.cjs";
|
|
2
2
|
export type { AgentEvent, AgentMessage, AgentOptions, AgentState, AgentTool, AgentToolResult, AgentToolUpdateCallback, AssistantMessage, Message, Model, TextContent, ThinkingLevel, UserMessage };
|
package/dist/agent-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as AgentState, c as AgentToolUpdateCallback,
|
|
1
|
+
import { a as AgentState, c as AgentToolUpdateCallback, f as AssistantMessage, g as UserMessage, h as TextContent, i as AgentMessage, l as ThinkingLevel, m as Model, n as AgentOptions, o as AgentTool, p as Message, r as AgentEvent, s as AgentToolResult } from "./index-0KyTNuR1.mjs";
|
|
2
2
|
export type { AgentEvent, AgentMessage, AgentOptions, AgentState, AgentTool, AgentToolResult, AgentToolUpdateCallback, AssistantMessage, Message, Model, TextContent, ThinkingLevel, UserMessage };
|
package/dist/agent.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_dist$1 = require("./dist-DnGkWV6x.cjs");
|
|
3
|
-
const require_dist$2 = require("./dist-
|
|
3
|
+
const require_dist$2 = require("./dist-DFXV_Io5.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-CwSaKHrs.cjs");
|
|
7
|
-
const require_dist$3 = require("./dist-
|
|
7
|
+
const require_dist$3 = require("./dist-BkkOal_e.cjs");
|
|
8
8
|
let zod = require("zod");
|
|
9
9
|
let node_async_hooks = require("node:async_hooks");
|
|
10
10
|
let node_fs = require("node:fs");
|
|
@@ -901,7 +901,7 @@ function loadGoogleVertexProviderModule() {
|
|
|
901
901
|
return googleVertexProviderModulePromise;
|
|
902
902
|
}
|
|
903
903
|
function loadMistralProviderModule() {
|
|
904
|
-
mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-
|
|
904
|
+
mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-DUKMgFL1.cjs")).then((module) => {
|
|
905
905
|
const provider = module;
|
|
906
906
|
return {
|
|
907
907
|
stream: provider.streamMistral,
|
|
@@ -1026,6 +1026,9 @@ function resolveApiProvider(api) {
|
|
|
1026
1026
|
function streamSimple(model, context, options) {
|
|
1027
1027
|
return resolveApiProvider(model.api).streamSimple(model, context, options);
|
|
1028
1028
|
}
|
|
1029
|
+
async function completeSimple(model, context, options) {
|
|
1030
|
+
return streamSimple(model, context, options).result();
|
|
1031
|
+
}
|
|
1029
1032
|
//#endregion
|
|
1030
1033
|
//#region ../../node_modules/.pnpm/typebox@1.1.38/node_modules/typebox/build/schema/types/_guard.mjs
|
|
1031
1034
|
function IsGuardInterface(value) {
|
|
@@ -13395,7 +13398,7 @@ function readMd(path, limit) {
|
|
|
13395
13398
|
chars: content.length
|
|
13396
13399
|
};
|
|
13397
13400
|
}
|
|
13398
|
-
function extractText(content) {
|
|
13401
|
+
function extractText$1(content) {
|
|
13399
13402
|
if (typeof content === "string") return content;
|
|
13400
13403
|
if (Array.isArray(content)) {
|
|
13401
13404
|
const parts = [];
|
|
@@ -13449,7 +13452,7 @@ function extractSessionRows(file) {
|
|
|
13449
13452
|
continue;
|
|
13450
13453
|
}
|
|
13451
13454
|
if (obj.type !== "message" || !obj.message) continue;
|
|
13452
|
-
const text = extractText(obj.message.content);
|
|
13455
|
+
const text = extractText$1(obj.message.content);
|
|
13453
13456
|
if (!text) continue;
|
|
13454
13457
|
rows.push({
|
|
13455
13458
|
line_no: i + 1,
|
|
@@ -14172,6 +14175,158 @@ function defineSubagentTool(input) {
|
|
|
14172
14175
|
subagentTool[SUBAGENT_TOOL] = metadata;
|
|
14173
14176
|
return subagentTool;
|
|
14174
14177
|
}
|
|
14178
|
+
/**
|
|
14179
|
+
* Best-effort provider `tool_choice` for forcing a named tool. Returns `undefined`
|
|
14180
|
+
* when the API shape is unknown so callers can rely on prompt + validate + retry.
|
|
14181
|
+
*/
|
|
14182
|
+
function forceToolChoice(api, toolName) {
|
|
14183
|
+
switch (api) {
|
|
14184
|
+
case "anthropic-messages": return {
|
|
14185
|
+
type: "tool",
|
|
14186
|
+
name: toolName
|
|
14187
|
+
};
|
|
14188
|
+
case "openai-completions":
|
|
14189
|
+
case "openai-responses":
|
|
14190
|
+
case "azure-openai-responses": return {
|
|
14191
|
+
type: "function",
|
|
14192
|
+
function: { name: toolName }
|
|
14193
|
+
};
|
|
14194
|
+
case "bedrock-converse-stream": return { tool: { name: toolName } };
|
|
14195
|
+
case "google-generative-ai":
|
|
14196
|
+
case "google-vertex": return "any";
|
|
14197
|
+
default: return;
|
|
14198
|
+
}
|
|
14199
|
+
}
|
|
14200
|
+
const RESPOND_TOOL_NAME = "respond";
|
|
14201
|
+
const STRUCTURED_OUTPUT_INSTRUCTION = "Respond only by calling `respond` with arguments matching the schema; do not answer in plain text.";
|
|
14202
|
+
const MAX_OBJECT_ATTEMPTS = 3;
|
|
14203
|
+
/** Same validation as `defineAgent` — format check before catalog lookup. */
|
|
14204
|
+
function resolvePromptModel(model) {
|
|
14205
|
+
return resolveAgentModel(AgentModelIdSchema.parse(model));
|
|
14206
|
+
}
|
|
14207
|
+
/**
|
|
14208
|
+
* pi-ai types tool `parameters` as TypeBox `TSchema`, but providers consume JSON Schema
|
|
14209
|
+
* at runtime. Same bridge as `resolveActionTool` in `@keystrokehq/action`.
|
|
14210
|
+
*/
|
|
14211
|
+
function buildToolParameters(schema) {
|
|
14212
|
+
return require_dist$2.toolParameters(schema);
|
|
14213
|
+
}
|
|
14214
|
+
function extractText(message) {
|
|
14215
|
+
return message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
14216
|
+
}
|
|
14217
|
+
function extractToolCall(message) {
|
|
14218
|
+
return message.content.find((part) => part.type === "toolCall");
|
|
14219
|
+
}
|
|
14220
|
+
function needsEnvelope(schema) {
|
|
14221
|
+
const json = zod.z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
14222
|
+
if (typeof json !== "object" || json === null || !("type" in json)) return true;
|
|
14223
|
+
return json.type !== "object";
|
|
14224
|
+
}
|
|
14225
|
+
function wrapSchemaForTool(schema) {
|
|
14226
|
+
if (!needsEnvelope(schema)) return {
|
|
14227
|
+
toolSchema: schema,
|
|
14228
|
+
unwrap: (args) => args
|
|
14229
|
+
};
|
|
14230
|
+
const envelopeSchema = zod.z.object({ result: schema });
|
|
14231
|
+
return {
|
|
14232
|
+
toolSchema: envelopeSchema,
|
|
14233
|
+
unwrap: (args) => envelopeSchema.parse(args).result
|
|
14234
|
+
};
|
|
14235
|
+
}
|
|
14236
|
+
function buildRespondTool(schema) {
|
|
14237
|
+
return {
|
|
14238
|
+
name: RESPOND_TOOL_NAME,
|
|
14239
|
+
description: "Return the final result.",
|
|
14240
|
+
parameters: buildToolParameters(schema)
|
|
14241
|
+
};
|
|
14242
|
+
}
|
|
14243
|
+
function resolvePromptReasoning(thinkingLevel) {
|
|
14244
|
+
if (!thinkingLevel || thinkingLevel === "off") return;
|
|
14245
|
+
return thinkingLevel;
|
|
14246
|
+
}
|
|
14247
|
+
function formatValidationError(error) {
|
|
14248
|
+
return error instanceof Error ? error.message : String(error);
|
|
14249
|
+
}
|
|
14250
|
+
async function runPromptText(opts) {
|
|
14251
|
+
const model = resolvePromptModel(opts.model);
|
|
14252
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14253
|
+
const message = await completeSimple(model, {
|
|
14254
|
+
systemPrompt: opts.system,
|
|
14255
|
+
messages: [{
|
|
14256
|
+
role: "user",
|
|
14257
|
+
content: opts.prompt,
|
|
14258
|
+
timestamp: Date.now()
|
|
14259
|
+
}]
|
|
14260
|
+
}, {
|
|
14261
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14262
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14263
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {}
|
|
14264
|
+
});
|
|
14265
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14266
|
+
return extractText(message);
|
|
14267
|
+
}
|
|
14268
|
+
async function runPromptObject(opts) {
|
|
14269
|
+
const schema = opts.outputSchema;
|
|
14270
|
+
if (!schema) throw new Error("outputSchema is required for structured LLM output");
|
|
14271
|
+
const model = resolvePromptModel(opts.model);
|
|
14272
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14273
|
+
const { toolSchema, unwrap } = wrapSchemaForTool(schema);
|
|
14274
|
+
const tool = buildRespondTool(toolSchema);
|
|
14275
|
+
const toolChoice = forceToolChoice(model.api, RESPOND_TOOL_NAME);
|
|
14276
|
+
const systemPrompt = [opts.system, STRUCTURED_OUTPUT_INSTRUCTION].filter(Boolean).join("\n\n");
|
|
14277
|
+
const messages = [{
|
|
14278
|
+
role: "user",
|
|
14279
|
+
content: opts.prompt,
|
|
14280
|
+
timestamp: Date.now()
|
|
14281
|
+
}];
|
|
14282
|
+
let lastError;
|
|
14283
|
+
for (let attempt = 0; attempt < MAX_OBJECT_ATTEMPTS; attempt++) {
|
|
14284
|
+
let message;
|
|
14285
|
+
let toolCall;
|
|
14286
|
+
try {
|
|
14287
|
+
message = await completeSimple(model, {
|
|
14288
|
+
systemPrompt,
|
|
14289
|
+
messages,
|
|
14290
|
+
tools: [tool]
|
|
14291
|
+
}, {
|
|
14292
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14293
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14294
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {},
|
|
14295
|
+
...toolChoice !== void 0 ? { toolChoice } : {}
|
|
14296
|
+
});
|
|
14297
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14298
|
+
toolCall = extractToolCall(message);
|
|
14299
|
+
if (!toolCall) throw new Error("Model did not return a tool call");
|
|
14300
|
+
return schema.parse(unwrap(toolCall.arguments));
|
|
14301
|
+
} catch (error) {
|
|
14302
|
+
lastError = error;
|
|
14303
|
+
if (attempt === MAX_OBJECT_ATTEMPTS - 1) break;
|
|
14304
|
+
const correction = `Validation failed: ${formatValidationError(error)}. Call respond again with valid arguments.`;
|
|
14305
|
+
if (message && toolCall) messages.push(message, {
|
|
14306
|
+
role: "toolResult",
|
|
14307
|
+
toolCallId: toolCall.id,
|
|
14308
|
+
toolName: toolCall.name,
|
|
14309
|
+
content: [{
|
|
14310
|
+
type: "text",
|
|
14311
|
+
text: correction
|
|
14312
|
+
}],
|
|
14313
|
+
isError: true,
|
|
14314
|
+
timestamp: Date.now()
|
|
14315
|
+
});
|
|
14316
|
+
else if (message) messages.push(message, {
|
|
14317
|
+
role: "user",
|
|
14318
|
+
content: correction,
|
|
14319
|
+
timestamp: Date.now()
|
|
14320
|
+
});
|
|
14321
|
+
}
|
|
14322
|
+
}
|
|
14323
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
14324
|
+
}
|
|
14325
|
+
/** One-shot LLM generation for workflow `promptLlm` steps (pi-ai transport). */
|
|
14326
|
+
async function runLlm(opts) {
|
|
14327
|
+
if (opts.outputSchema) return runPromptObject(opts);
|
|
14328
|
+
return runPromptText(opts);
|
|
14329
|
+
}
|
|
14175
14330
|
//#endregion
|
|
14176
14331
|
exports.AgentCreateInputSchema = AgentCreateInputSchema;
|
|
14177
14332
|
exports.AgentModelIdSchema = AgentModelIdSchema;
|
|
@@ -14189,6 +14344,7 @@ exports.defineMcp = require_dist$3.defineMcp;
|
|
|
14189
14344
|
exports.defineSubagentTool = defineSubagentTool;
|
|
14190
14345
|
exports.defineTool = defineTool;
|
|
14191
14346
|
exports.errorMessage = errorMessage;
|
|
14347
|
+
exports.forceToolChoice = forceToolChoice;
|
|
14192
14348
|
exports.getModel = require_event_stream.getModel;
|
|
14193
14349
|
exports.getSubagentToolMetadata = getSubagentToolMetadata;
|
|
14194
14350
|
exports.isMcp = require_dist$3.isMcp;
|
|
@@ -14205,6 +14361,7 @@ exports.resolveAgentTools = resolveAgentTools;
|
|
|
14205
14361
|
exports.resolveAgentWorkspaceRoot = resolveAgentWorkspaceRoot;
|
|
14206
14362
|
exports.resolveThinkingLevel = resolveThinkingLevel;
|
|
14207
14363
|
exports.runAgentPrompt = runAgentPrompt;
|
|
14364
|
+
exports.runLlm = runLlm;
|
|
14208
14365
|
exports.snapshot = snapshot;
|
|
14209
14366
|
|
|
14210
14367
|
//# sourceMappingURL=agent.cjs.map
|