@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/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-lWDTuftA.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-BIbZjRd7.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-lWDTuftA.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-DiqTL3ZF.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-DuG294d1.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,
|
|
@@ -13741,13 +13744,32 @@ function runWithinAgentPromptExecution(fn) {
|
|
|
13741
13744
|
function isWithinAgentPromptExecution() {
|
|
13742
13745
|
return executingAgentPrompt.getStore() === true;
|
|
13743
13746
|
}
|
|
13747
|
+
function llmUsageFromAssistantMessage(message) {
|
|
13748
|
+
const usage = message.usage;
|
|
13749
|
+
if (!usage) return null;
|
|
13750
|
+
return {
|
|
13751
|
+
label: message.responseModel ?? message.model ?? "unknown-model",
|
|
13752
|
+
quantity: usage.totalTokens,
|
|
13753
|
+
amount: usage.cost.total,
|
|
13754
|
+
metadata: {
|
|
13755
|
+
provider: message.provider,
|
|
13756
|
+
model: message.model,
|
|
13757
|
+
responseModel: message.responseModel ?? null,
|
|
13758
|
+
input: usage.input,
|
|
13759
|
+
output: usage.output,
|
|
13760
|
+
cacheRead: usage.cacheRead,
|
|
13761
|
+
cacheWrite: usage.cacheWrite,
|
|
13762
|
+
cost: usage.cost
|
|
13763
|
+
}
|
|
13764
|
+
};
|
|
13765
|
+
}
|
|
13744
13766
|
const SKIPPED_EVENT_TYPES = new Set(["message_update", "tool_execution_update"]);
|
|
13745
13767
|
function shouldPersistAgentEvent(event) {
|
|
13746
13768
|
return !SKIPPED_EVENT_TYPES.has(event.type);
|
|
13747
13769
|
}
|
|
13748
13770
|
async function persistSessionEvent(options) {
|
|
13749
|
-
const { sessionId, memoryConfig, eventType, payload } = options;
|
|
13750
|
-
const seq = await require_dist$3.appendEvent(sessionId, eventType, payload);
|
|
13771
|
+
const { sessionId, runId, memoryConfig, eventType, payload } = options;
|
|
13772
|
+
const seq = await require_dist$3.appendEvent(sessionId, eventType, payload, { runId });
|
|
13751
13773
|
if (memoryConfig) try {
|
|
13752
13774
|
await appendSessionLine(memoryConfig, sessionId, {
|
|
13753
13775
|
seq,
|
|
@@ -13760,15 +13782,19 @@ async function persistSessionEvent(options) {
|
|
|
13760
13782
|
}
|
|
13761
13783
|
return seq;
|
|
13762
13784
|
}
|
|
13763
|
-
async function persistAgentEvent(sessionId, event,
|
|
13785
|
+
async function persistAgentEvent(sessionId, event, options) {
|
|
13786
|
+
const runId = options?.runId ?? null;
|
|
13787
|
+
const memoryConfig = options?.memoryConfig;
|
|
13764
13788
|
await persistSessionEvent({
|
|
13765
13789
|
sessionId,
|
|
13790
|
+
runId,
|
|
13766
13791
|
memoryConfig,
|
|
13767
13792
|
eventType: event.type,
|
|
13768
13793
|
payload: event
|
|
13769
13794
|
});
|
|
13770
13795
|
if (event.type === "message_end") await persistSessionEvent({
|
|
13771
13796
|
sessionId,
|
|
13797
|
+
runId,
|
|
13772
13798
|
memoryConfig,
|
|
13773
13799
|
eventType: require_dist$3.MESSAGE_EVENT_TYPE,
|
|
13774
13800
|
payload: event.message
|
|
@@ -13786,49 +13812,93 @@ async function prepareAgentSession(agentId, sessionId, options) {
|
|
|
13786
13812
|
async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
13787
13813
|
const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
|
|
13788
13814
|
const priorMessages = await require_dist$3.listMessageEvents(sessionId);
|
|
13815
|
+
const runSource = await require_dist$3.resolveAgentRunSourceFromSession(sessionId);
|
|
13816
|
+
const runId = await require_dist$3.createAgentRun({
|
|
13817
|
+
sessionId,
|
|
13818
|
+
agentId,
|
|
13819
|
+
sourceKind: runSource.sourceKind,
|
|
13820
|
+
sourceId: runSource.sourceId,
|
|
13821
|
+
ranByUserId: runSource.ranByUserId
|
|
13822
|
+
});
|
|
13789
13823
|
const runPrompt = async () => {
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13795
|
-
...options,
|
|
13796
|
-
credentials: require_dist$3.buildCredentialRunContext({ request: {
|
|
13797
|
-
...options.credentials,
|
|
13798
|
-
...input.context
|
|
13799
|
-
} })
|
|
13800
|
-
});
|
|
13801
|
-
const memoryConfig = runtime.memory?.config;
|
|
13802
|
-
const unsubscribe = runtime.pi.subscribe(async (event) => {
|
|
13803
|
-
if (!shouldPersistAgentEvent(event)) return;
|
|
13804
|
-
await persistAgentEvent(sessionId, event, memoryConfig);
|
|
13805
|
-
});
|
|
13824
|
+
let promptError = null;
|
|
13825
|
+
let runtime;
|
|
13826
|
+
let unsubscribe;
|
|
13827
|
+
let onAbort;
|
|
13828
|
+
const pendingHandlers = /* @__PURE__ */ new Set();
|
|
13806
13829
|
const signal = require_dist$2.getRunSignal();
|
|
13807
|
-
const onAbort = () => runtime.pi.abort();
|
|
13808
|
-
if (signal.aborted) onAbort();
|
|
13809
|
-
else signal.addEventListener("abort", onAbort, { once: true });
|
|
13810
13830
|
try {
|
|
13811
|
-
|
|
13812
|
-
|
|
13831
|
+
runtime = await agent.buildRuntime({
|
|
13832
|
+
agentId,
|
|
13833
|
+
sessionId,
|
|
13834
|
+
messages: priorMessages
|
|
13835
|
+
}, {
|
|
13836
|
+
...options,
|
|
13837
|
+
credentials: require_dist$3.buildCredentialRunContext({ request: {
|
|
13838
|
+
...options.credentials,
|
|
13839
|
+
...input.context
|
|
13840
|
+
} })
|
|
13841
|
+
});
|
|
13842
|
+
const activeRuntime = runtime;
|
|
13843
|
+
const memoryConfig = activeRuntime.memory?.config;
|
|
13844
|
+
unsubscribe = activeRuntime.pi.subscribe((event) => {
|
|
13845
|
+
if (!shouldPersistAgentEvent(event)) return;
|
|
13846
|
+
const tracked = (async () => {
|
|
13847
|
+
await persistAgentEvent(sessionId, event, {
|
|
13848
|
+
runId,
|
|
13849
|
+
memoryConfig
|
|
13850
|
+
});
|
|
13851
|
+
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
13852
|
+
const usage = llmUsageFromAssistantMessage(event.message);
|
|
13853
|
+
if (usage) await require_dist$3.recordLlmUsageFromAssistantMessage({
|
|
13854
|
+
runId,
|
|
13855
|
+
usage
|
|
13856
|
+
});
|
|
13857
|
+
}
|
|
13858
|
+
})().finally(() => {
|
|
13859
|
+
pendingHandlers.delete(tracked);
|
|
13860
|
+
});
|
|
13861
|
+
pendingHandlers.add(tracked);
|
|
13862
|
+
return tracked;
|
|
13863
|
+
});
|
|
13864
|
+
onAbort = () => activeRuntime.pi.abort();
|
|
13865
|
+
if (signal.aborted) onAbort();
|
|
13866
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
13867
|
+
const snapshot = await require_dist$3.captureConsole(async () => prompt(activeRuntime, input.message));
|
|
13868
|
+
const credentialError = activeRuntime.takeCredentialError?.();
|
|
13813
13869
|
if (credentialError && require_dist$3.isCredentialError(credentialError)) throw credentialError;
|
|
13814
13870
|
await require_dist$3.touchSession(sessionId);
|
|
13815
13871
|
return {
|
|
13816
13872
|
sessionId,
|
|
13873
|
+
runId,
|
|
13817
13874
|
messages: messages(snapshot),
|
|
13818
13875
|
error: errorMessage(snapshot) ?? null,
|
|
13819
13876
|
canceled: signal.aborted
|
|
13820
13877
|
};
|
|
13878
|
+
} catch (error) {
|
|
13879
|
+
promptError = error;
|
|
13880
|
+
throw error;
|
|
13821
13881
|
} finally {
|
|
13822
|
-
signal.removeEventListener("abort", onAbort);
|
|
13823
|
-
unsubscribe();
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
|
|
13882
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
13883
|
+
unsubscribe?.();
|
|
13884
|
+
await Promise.allSettled([...pendingHandlers]);
|
|
13885
|
+
if (runtime) {
|
|
13886
|
+
try {
|
|
13887
|
+
runtime.memory?.reindexSessions();
|
|
13888
|
+
} catch (err) {
|
|
13889
|
+
console.error("[memory] session reindex failed:", err);
|
|
13890
|
+
}
|
|
13891
|
+
runtime.memory?.close();
|
|
13892
|
+
await Promise.all(runtime.mcpConnections.map((connection) => connection.close()));
|
|
13893
|
+
await runtime.sandbox.dispose();
|
|
13894
|
+
}
|
|
13895
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
13896
|
+
await require_dist$3.finalizeAgentRunFromPrompt({
|
|
13897
|
+
runId,
|
|
13898
|
+
status: promptError ? "failed" : signal.aborted ? "canceled" : "completed",
|
|
13899
|
+
error: promptError,
|
|
13900
|
+
finishedAt
|
|
13901
|
+
});
|
|
13832
13902
|
}
|
|
13833
13903
|
};
|
|
13834
13904
|
if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);
|
|
@@ -14172,6 +14242,164 @@ function defineSubagentTool(input) {
|
|
|
14172
14242
|
subagentTool[SUBAGENT_TOOL] = metadata;
|
|
14173
14243
|
return subagentTool;
|
|
14174
14244
|
}
|
|
14245
|
+
/**
|
|
14246
|
+
* Best-effort provider `tool_choice` for forcing a named tool. Returns `undefined`
|
|
14247
|
+
* when the API shape is unknown so callers can rely on prompt + validate + retry.
|
|
14248
|
+
*/
|
|
14249
|
+
function forceToolChoice(api, toolName) {
|
|
14250
|
+
switch (api) {
|
|
14251
|
+
case "anthropic-messages": return {
|
|
14252
|
+
type: "tool",
|
|
14253
|
+
name: toolName
|
|
14254
|
+
};
|
|
14255
|
+
case "openai-completions":
|
|
14256
|
+
case "openai-responses":
|
|
14257
|
+
case "azure-openai-responses": return {
|
|
14258
|
+
type: "function",
|
|
14259
|
+
function: { name: toolName }
|
|
14260
|
+
};
|
|
14261
|
+
case "bedrock-converse-stream": return { tool: { name: toolName } };
|
|
14262
|
+
case "google-generative-ai":
|
|
14263
|
+
case "google-vertex": return "any";
|
|
14264
|
+
default: return;
|
|
14265
|
+
}
|
|
14266
|
+
}
|
|
14267
|
+
const RESPOND_TOOL_NAME = "respond";
|
|
14268
|
+
const STRUCTURED_OUTPUT_INSTRUCTION = "Respond only by calling `respond` with arguments matching the schema; do not answer in plain text.";
|
|
14269
|
+
const MAX_OBJECT_ATTEMPTS = 3;
|
|
14270
|
+
/** Same validation as `defineAgent` — format check before catalog lookup. */
|
|
14271
|
+
function resolvePromptModel(model) {
|
|
14272
|
+
return resolveAgentModel(AgentModelIdSchema.parse(model));
|
|
14273
|
+
}
|
|
14274
|
+
/**
|
|
14275
|
+
* pi-ai types tool `parameters` as TypeBox `TSchema`, but providers consume JSON Schema
|
|
14276
|
+
* at runtime. Same bridge as `resolveActionTool` in `@keystrokehq/action`.
|
|
14277
|
+
*/
|
|
14278
|
+
function buildToolParameters(schema) {
|
|
14279
|
+
return require_dist$2.toolParameters(schema);
|
|
14280
|
+
}
|
|
14281
|
+
function extractText(message) {
|
|
14282
|
+
return message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
14283
|
+
}
|
|
14284
|
+
function extractToolCall(message) {
|
|
14285
|
+
return message.content.find((part) => part.type === "toolCall");
|
|
14286
|
+
}
|
|
14287
|
+
function needsEnvelope(schema) {
|
|
14288
|
+
const json = zod.z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
14289
|
+
if (typeof json !== "object" || json === null || !("type" in json)) return true;
|
|
14290
|
+
return json.type !== "object";
|
|
14291
|
+
}
|
|
14292
|
+
function wrapSchemaForTool(schema) {
|
|
14293
|
+
if (!needsEnvelope(schema)) return {
|
|
14294
|
+
toolSchema: schema,
|
|
14295
|
+
unwrap: (args) => args
|
|
14296
|
+
};
|
|
14297
|
+
const envelopeSchema = zod.z.object({ result: schema });
|
|
14298
|
+
return {
|
|
14299
|
+
toolSchema: envelopeSchema,
|
|
14300
|
+
unwrap: (args) => envelopeSchema.parse(args).result
|
|
14301
|
+
};
|
|
14302
|
+
}
|
|
14303
|
+
function buildRespondTool(schema) {
|
|
14304
|
+
return {
|
|
14305
|
+
name: RESPOND_TOOL_NAME,
|
|
14306
|
+
description: "Return the final result.",
|
|
14307
|
+
parameters: buildToolParameters(schema)
|
|
14308
|
+
};
|
|
14309
|
+
}
|
|
14310
|
+
function resolvePromptReasoning(thinkingLevel) {
|
|
14311
|
+
if (!thinkingLevel || thinkingLevel === "off") return;
|
|
14312
|
+
return thinkingLevel;
|
|
14313
|
+
}
|
|
14314
|
+
function formatValidationError(error) {
|
|
14315
|
+
return error instanceof Error ? error.message : String(error);
|
|
14316
|
+
}
|
|
14317
|
+
async function recordUsageFromMessage(message, hooks) {
|
|
14318
|
+
const usage = llmUsageFromAssistantMessage(message);
|
|
14319
|
+
if (usage) await hooks?.onUsage?.(usage);
|
|
14320
|
+
}
|
|
14321
|
+
async function runPromptText(opts, hooks) {
|
|
14322
|
+
const model = resolvePromptModel(opts.model);
|
|
14323
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14324
|
+
const message = await completeSimple(model, {
|
|
14325
|
+
systemPrompt: opts.system,
|
|
14326
|
+
messages: [{
|
|
14327
|
+
role: "user",
|
|
14328
|
+
content: opts.prompt,
|
|
14329
|
+
timestamp: Date.now()
|
|
14330
|
+
}]
|
|
14331
|
+
}, {
|
|
14332
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14333
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14334
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {}
|
|
14335
|
+
});
|
|
14336
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14337
|
+
await recordUsageFromMessage(message, hooks);
|
|
14338
|
+
return extractText(message);
|
|
14339
|
+
}
|
|
14340
|
+
async function runPromptObject(opts, hooks) {
|
|
14341
|
+
const schema = opts.outputSchema;
|
|
14342
|
+
if (!schema) throw new Error("outputSchema is required for structured LLM output");
|
|
14343
|
+
const model = resolvePromptModel(opts.model);
|
|
14344
|
+
const reasoning = resolvePromptReasoning(opts.thinkingLevel);
|
|
14345
|
+
const { toolSchema, unwrap } = wrapSchemaForTool(schema);
|
|
14346
|
+
const tool = buildRespondTool(toolSchema);
|
|
14347
|
+
const toolChoice = forceToolChoice(model.api, RESPOND_TOOL_NAME);
|
|
14348
|
+
const systemPrompt = [opts.system, STRUCTURED_OUTPUT_INSTRUCTION].filter(Boolean).join("\n\n");
|
|
14349
|
+
const messages = [{
|
|
14350
|
+
role: "user",
|
|
14351
|
+
content: opts.prompt,
|
|
14352
|
+
timestamp: Date.now()
|
|
14353
|
+
}];
|
|
14354
|
+
let lastError;
|
|
14355
|
+
for (let attempt = 0; attempt < MAX_OBJECT_ATTEMPTS; attempt++) {
|
|
14356
|
+
let message;
|
|
14357
|
+
let toolCall;
|
|
14358
|
+
try {
|
|
14359
|
+
message = await completeSimple(model, {
|
|
14360
|
+
systemPrompt,
|
|
14361
|
+
messages,
|
|
14362
|
+
tools: [tool]
|
|
14363
|
+
}, {
|
|
14364
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
14365
|
+
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
14366
|
+
...opts.maxTokens !== void 0 ? { maxTokens: opts.maxTokens } : {},
|
|
14367
|
+
...toolChoice !== void 0 ? { toolChoice } : {}
|
|
14368
|
+
});
|
|
14369
|
+
if (message.stopReason === "error") throw new Error(message.errorMessage ?? "LLM request failed");
|
|
14370
|
+
await recordUsageFromMessage(message, hooks);
|
|
14371
|
+
toolCall = extractToolCall(message);
|
|
14372
|
+
if (!toolCall) throw new Error("Model did not return a tool call");
|
|
14373
|
+
return schema.parse(unwrap(toolCall.arguments));
|
|
14374
|
+
} catch (error) {
|
|
14375
|
+
lastError = error;
|
|
14376
|
+
if (attempt === MAX_OBJECT_ATTEMPTS - 1) break;
|
|
14377
|
+
const correction = `Validation failed: ${formatValidationError(error)}. Call respond again with valid arguments.`;
|
|
14378
|
+
if (message && toolCall) messages.push(message, {
|
|
14379
|
+
role: "toolResult",
|
|
14380
|
+
toolCallId: toolCall.id,
|
|
14381
|
+
toolName: toolCall.name,
|
|
14382
|
+
content: [{
|
|
14383
|
+
type: "text",
|
|
14384
|
+
text: correction
|
|
14385
|
+
}],
|
|
14386
|
+
isError: true,
|
|
14387
|
+
timestamp: Date.now()
|
|
14388
|
+
});
|
|
14389
|
+
else if (message) messages.push(message, {
|
|
14390
|
+
role: "user",
|
|
14391
|
+
content: correction,
|
|
14392
|
+
timestamp: Date.now()
|
|
14393
|
+
});
|
|
14394
|
+
}
|
|
14395
|
+
}
|
|
14396
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
14397
|
+
}
|
|
14398
|
+
/** One-shot LLM generation for workflow `promptLlm` steps (pi-ai transport). */
|
|
14399
|
+
async function runLlm(opts, hooks) {
|
|
14400
|
+
if (opts.outputSchema) return runPromptObject(opts, hooks);
|
|
14401
|
+
return runPromptText(opts, hooks);
|
|
14402
|
+
}
|
|
14175
14403
|
//#endregion
|
|
14176
14404
|
exports.AgentCreateInputSchema = AgentCreateInputSchema;
|
|
14177
14405
|
exports.AgentModelIdSchema = AgentModelIdSchema;
|
|
@@ -14189,6 +14417,7 @@ exports.defineMcp = require_dist$3.defineMcp;
|
|
|
14189
14417
|
exports.defineSubagentTool = defineSubagentTool;
|
|
14190
14418
|
exports.defineTool = defineTool;
|
|
14191
14419
|
exports.errorMessage = errorMessage;
|
|
14420
|
+
exports.forceToolChoice = forceToolChoice;
|
|
14192
14421
|
exports.getModel = require_event_stream.getModel;
|
|
14193
14422
|
exports.getSubagentToolMetadata = getSubagentToolMetadata;
|
|
14194
14423
|
exports.isMcp = require_dist$3.isMcp;
|
|
@@ -14205,6 +14434,7 @@ exports.resolveAgentTools = resolveAgentTools;
|
|
|
14205
14434
|
exports.resolveAgentWorkspaceRoot = resolveAgentWorkspaceRoot;
|
|
14206
14435
|
exports.resolveThinkingLevel = resolveThinkingLevel;
|
|
14207
14436
|
exports.runAgentPrompt = runAgentPrompt;
|
|
14437
|
+
exports.runLlm = runLlm;
|
|
14208
14438
|
exports.snapshot = snapshot;
|
|
14209
14439
|
|
|
14210
14440
|
//# sourceMappingURL=agent.cjs.map
|