@keystrokehq/keystroke 1.0.6 → 1.0.8
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.mjs +1 -1
- package/dist/agent.cjs +110 -14
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +1 -1
- package/dist/agent.d.mts +1 -1
- package/dist/agent.mjs +110 -14
- package/dist/agent.mjs.map +1 -1
- package/dist/app.cjs +1 -1
- package/dist/app.mjs +1 -1
- package/dist/client.cjs +1 -1
- package/dist/client.mjs +1 -1
- package/dist/credentials.cjs +1 -1
- package/dist/credentials.mjs +1 -1
- package/dist/{dist-pErVjN3p.mjs → dist-BpkCqbil.mjs} +3 -3
- package/dist/{dist-pErVjN3p.mjs.map → dist-BpkCqbil.mjs.map} +1 -1
- package/dist/{dist-DBE-7Q9K.cjs → dist-C5otI4u3.cjs} +58 -7
- package/dist/dist-C5otI4u3.cjs.map +1 -0
- package/dist/{dist-hu4oHsK8.cjs → dist-DOMwPx7V.cjs} +54 -14
- package/dist/dist-DOMwPx7V.cjs.map +1 -0
- package/dist/{dist-B4CrrSM0.cjs → dist-DQL6zTI5.cjs} +3 -3
- package/dist/{dist-B4CrrSM0.cjs.map → dist-DQL6zTI5.cjs.map} +1 -1
- package/dist/{dist-6ug9ozqR.mjs → dist-DqFdFpiB.mjs} +54 -14
- package/dist/dist-DqFdFpiB.mjs.map +1 -0
- package/dist/{dist-BgFLp5DL.mjs → dist-IUl7Bexl.mjs} +41 -8
- package/dist/dist-IUl7Bexl.mjs.map +1 -0
- package/dist/{index-Dd0B13U7.d.cts → index-BY9SPR2h.d.cts} +2 -1
- package/dist/index-BY9SPR2h.d.cts.map +1 -0
- package/dist/{index-IhPXtbNf.d.mts → index-BeBgntxT.d.mts} +2 -1
- package/dist/index-BeBgntxT.d.mts.map +1 -0
- package/dist/index-e9f4pcX4.d.cts.map +1 -1
- package/dist/index-e9f4pcX4.d.mts.map +1 -1
- package/dist/{mistral-B1ULILEc.mjs → mistral-CMDejXQt.mjs} +2 -2
- package/dist/{mistral-B1ULILEc.mjs.map → mistral-CMDejXQt.mjs.map} +1 -1
- package/dist/{mistral-WPrOS6Bw.cjs → mistral-wOLLEgb9.cjs} +2 -2
- package/dist/{mistral-WPrOS6Bw.cjs.map → mistral-wOLLEgb9.cjs.map} +1 -1
- package/dist/{sse-B3mQ3cnH.mjs → sse-DI7TsPKG.mjs} +2 -2
- package/dist/{sse-B3mQ3cnH.mjs.map → sse-DI7TsPKG.mjs.map} +1 -1
- package/dist/{sse-7gbBPR9G.cjs → sse-Dzs73rQw.cjs} +2 -2
- package/dist/{sse-7gbBPR9G.cjs.map → sse-Dzs73rQw.cjs.map} +1 -1
- package/dist/trigger.cjs +8 -7
- package/dist/trigger.cjs.map +1 -1
- package/dist/trigger.d.cts +1 -1
- package/dist/trigger.d.mts +1 -1
- package/dist/trigger.mjs +8 -7
- package/dist/trigger.mjs.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +1 -1
- package/package.json +3 -3
- package/dist/dist-6ug9ozqR.mjs.map +0 -1
- package/dist/dist-BgFLp5DL.mjs.map +0 -1
- package/dist/dist-DBE-7Q9K.cjs.map +0 -1
- package/dist/dist-hu4oHsK8.cjs.map +0 -1
- package/dist/index-Dd0B13U7.d.cts.map +0 -1
- package/dist/index-IhPXtbNf.d.mts.map +0 -1
package/dist/agent.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as ThinkingLevel, u as getModel } from "./index-BByNfhJU.cjs";
|
|
2
|
-
import { A as forceToolChoice, B as runAgentPrompt, C as SubagentToolMetadata, D as defineSubagentTool, E as defineAgent, F as prompt, G as AgentModelId, H as snapshot, I as resolveAgentAssets, J as ThinkingLevelSchema, K as AgentModelIdSchema, L as resolveAgentId, M as messages, N as normalizeAgentDefinition, O as defineTool, P as prepareAgentSession, R as resolveAgentTools, S as SubagentToolInherit, T as createAgent, U as AgentCreateInput, V as runLlm, W as AgentCreateInputSchema, X as resolveAgentModel, Y as parseAgentCreateInput, Z as resolveThinkingLevel, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentTool, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as getSubagentToolMetadata, k as errorMessage, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as DEFAULT_THINKING_LEVEL, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SessionLifecycle, w as buildAgentRuntime, x as SubagentToolDetails, y as SessionLifecycleContext, z as resolveAgentWorkspaceRoot } from "./index-
|
|
2
|
+
import { A as forceToolChoice, B as runAgentPrompt, C as SubagentToolMetadata, D as defineSubagentTool, E as defineAgent, F as prompt, G as AgentModelId, H as snapshot, I as resolveAgentAssets, J as ThinkingLevelSchema, K as AgentModelIdSchema, L as resolveAgentId, M as messages, N as normalizeAgentDefinition, O as defineTool, P as prepareAgentSession, R as resolveAgentTools, S as SubagentToolInherit, T as createAgent, U as AgentCreateInput, V as runLlm, W as AgentCreateInputSchema, X as resolveAgentModel, Y as parseAgentCreateInput, Z as resolveThinkingLevel, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentTool, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as getSubagentToolMetadata, k as errorMessage, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as DEFAULT_THINKING_LEVEL, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SessionLifecycle, w as buildAgentRuntime, x as SubagentToolDetails, y as SessionLifecycleContext, z as resolveAgentWorkspaceRoot } from "./index-BY9SPR2h.cjs";
|
|
3
3
|
import { a as McpDefinition, c as McpServerOptions, d as McpTransport, f as connectMcpDefinition, g as isMcp, h as defineMcp, i as McpConnection, l as McpStdioOptions, m as connectMcpStdio, n as McpAuthOptions, o as McpDefinitionInput, p as connectMcpServer, r as McpCallToolOptions, s as McpHttpTransport, t as ToolCredentialResolver, u as McpStdioTransport } from "./index-nUAXCgEe.cjs";
|
|
4
4
|
import { z as loadAssetManifest } from "./index-DstR-eGs.cjs";
|
|
5
5
|
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 SessionLifecycle, type SessionLifecycleContext, 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,5 +1,5 @@
|
|
|
1
1
|
import { l as ThinkingLevel, u as getModel } from "./index-ClGiGBy7.mjs";
|
|
2
|
-
import { A as forceToolChoice, B as runAgentPrompt, C as SubagentToolMetadata, D as defineSubagentTool, E as defineAgent, F as prompt, G as AgentModelId, H as snapshot, I as resolveAgentAssets, J as ThinkingLevelSchema, K as AgentModelIdSchema, L as resolveAgentId, M as messages, N as normalizeAgentDefinition, O as defineTool, P as prepareAgentSession, R as resolveAgentTools, S as SubagentToolInherit, T as createAgent, U as AgentCreateInput, V as runLlm, W as AgentCreateInputSchema, X as resolveAgentModel, Y as parseAgentCreateInput, Z as resolveThinkingLevel, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentTool, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as getSubagentToolMetadata, k as errorMessage, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as DEFAULT_THINKING_LEVEL, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SessionLifecycle, w as buildAgentRuntime, x as SubagentToolDetails, y as SessionLifecycleContext, z as resolveAgentWorkspaceRoot } from "./index-
|
|
2
|
+
import { A as forceToolChoice, B as runAgentPrompt, C as SubagentToolMetadata, D as defineSubagentTool, E as defineAgent, F as prompt, G as AgentModelId, H as snapshot, I as resolveAgentAssets, J as ThinkingLevelSchema, K as AgentModelIdSchema, L as resolveAgentId, M as messages, N as normalizeAgentDefinition, O as defineTool, P as prepareAgentSession, R as resolveAgentTools, S as SubagentToolInherit, T as createAgent, U as AgentCreateInput, V as runLlm, W as AgentCreateInputSchema, X as resolveAgentModel, Y as parseAgentCreateInput, Z as resolveThinkingLevel, _ as SessionAgentMismatchError, a as AgentDefinitionInput, b as SubagentTool, c as BuildAgentRuntimeContext, d as PromptInput, f as PromptResponse, g as SandboxedAgentRuntime, h as SUBAGENT_TOOL, i as AgentDefinition, j as getSubagentToolMetadata, k as errorMessage, l as DefineSubagentToolInput, m as RunAgentPromptOptions, n as AgentAssetInput, o as AgentRuntime, p as ResolvedAgentAssets, q as DEFAULT_THINKING_LEVEL, r as AgentConfig, s as AgentSnapshot, t as Agent, u as ForcedToolChoice, v as SessionLifecycle, w as buildAgentRuntime, x as SubagentToolDetails, y as SessionLifecycleContext, z as resolveAgentWorkspaceRoot } from "./index-BeBgntxT.mjs";
|
|
3
3
|
import { a as McpDefinition, c as McpServerOptions, d as McpTransport, f as connectMcpDefinition, g as isMcp, h as defineMcp, i as McpConnection, l as McpStdioOptions, m as connectMcpStdio, n as McpAuthOptions, o as McpDefinitionInput, p as connectMcpServer, r as McpCallToolOptions, s as McpHttpTransport, t as ToolCredentialResolver, u as McpStdioTransport } from "./index-8_UEbXaF.mjs";
|
|
4
4
|
import { z as loadAssetManifest } from "./index-B3iWqXUd.mjs";
|
|
5
5
|
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 SessionLifecycle, type SessionLifecycleContext, 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,6 +1,6 @@
|
|
|
1
1
|
import { i as __require, r as __exportAll, t as __commonJSMin } from "./chunk-D0VCBZRD.mjs";
|
|
2
|
-
import { E as toolParameters, c as getWorkflowRunHandle, d as isWithinActionExecution, l as isAction, m as resolveActionTool, s as getRunSignal } from "./dist-
|
|
3
|
-
import { A as
|
|
2
|
+
import { E as toolParameters, c as getWorkflowRunHandle, d as isWithinActionExecution, l as isAction, m as resolveActionTool, s as getRunSignal } from "./dist-DqFdFpiB.mjs";
|
|
3
|
+
import { A as resolveRunSourceFromTraceContext, C as clearLiveMessage, D as getSession, E as getProjectScopeId, F as getTraceContext, L as withSpan, M as setSessionTitle, N as touchSession, O as listMessageEvents, P as captureConsole, S as appendEvent, T as getAgentByRoute, a as resolveActionCredentials, b as MESSAGE_EVENT_TYPE, c as connectMcpServer, d as isMcp, i as isCredentialError, j as setSessionLiveMessage, k as recordLlmUsageFromAssistantMessage, l as connectMcpStdio, n as captureCredentialToolErrors, o as resolveMcpTools, r as createCredentialResolver, s as connectMcpDefinition, t as buildCredentialRunContext, u as defineMcp, w as createSession, x as addAgentSessionDuration } from "./dist-IUl7Bexl.mjs";
|
|
4
4
|
import { $t as _Object_, An as IsFunction$1, At as IsNull$2, Bn as IsNull$1, Bt as IsBoolean$2, Cn as IsAsyncIterator$1, Ct as EnumToUnion, Dn as IsConstructor$1, Dt as IsSymbol$2, En as IsClassInstance, Et as String$1, Fn as IsLessEqualThan$1, Ft as IsLiteralString, Gn as IsSymbol$1, Gt as Unreachable, Hn as IsObject$1, Ht as IsCodec, In as IsLessThan$1, It as Literal, J as getBoundAppRoot, Jn as IsValueLike, Jt as IsCyclic, Kn as IsUndefined$1, Kt as IsIntersect, Ln as IsMaxLength$2, Lt as IsIterator$2, Mn as IsGreaterThan$1, Mt as IsLiteralBigInt, Nn as IsInteger$1, Nt as IsLiteralBoolean, On as IsDeepEqual$1, Ot as IsNumber$2, Pn as IsIterator$1, Pt as IsLiteralNumber, Qt as IsObject$2, Rn as IsMinLength$2, Rt as IsInteger$2, Sn as IsArray$1, St as IsTuple, Tn as IsBoolean$1, Tt as IsString$2, Un as IsObjectNotArray$1, Ut as Hash, Vn as IsNumber$1, Vt as IsBigInt$2, Wn as IsString$1, Wt as hash_exports, X as materializeSandbox, Xn as Symbols, Xt as IsUnion, Y as loadAssetManifest, Yn as Keys$1, Yt as Unknown, Zn as guard_exports, Zt as Union, _n as Entries$2, _t as IsVoid, a as defaultWorkspacesRoot, an as IsAsyncIterator$2, bn as EveryAll, bt as RecordPattern, cn as IsBase, ct as ensureWorkspaceDir, dn as IsPromise, dt as resolveSessionRoot, en as IsNever, fn as IsSchema$1, ft as Evaluate$1, gn as IsTypeArray, gt as IsTemplateLiteral, hn as IsSet, ht as Compare, i as createSandbox, in as IsConstructor$2, jn as IsGreaterEqualThan$1, jt as IsLiteral, kn as IsEqual$1, kt as Number$1, l as materializeSkills, ln as IsOptional, lt as resolveAgentRoot, mn as IsMap, mt as Options, n as createInvokeToolBridge, nn as Ref$1, o as defineSkill, on as IsArray$2, p as sandboxSystemPromptInjection, pn as Get$3, pt as Instantiate, qn as IsUnsafePropertyKey, qt as IsEnum$1, rn as IsFunction$2, sn as Base, tn as IsRef$1, tt as resolveSandboxDefinition, un as Optional, vn as EntriesRegExp, vt as IsUndefined$2, wn as IsBigInt$1, wt as TemplateLiteralDecode, xn as HasPropertyKey$1, xt as RecordValue, yn as Every$1, yt as IsRecord, zn as IsMultipleOf$1, zt as Boolean$1 } from "./dist-CRsUBf24.mjs";
|
|
5
5
|
import "./env-api-keys-24ayFQZr.mjs";
|
|
6
6
|
import { i as getModel, t as AssistantMessageEventStream } from "./event-stream-C7YBbzsc.mjs";
|
|
@@ -901,7 +901,7 @@ function loadGoogleVertexProviderModule() {
|
|
|
901
901
|
return googleVertexProviderModulePromise;
|
|
902
902
|
}
|
|
903
903
|
function loadMistralProviderModule() {
|
|
904
|
-
mistralProviderModulePromise ||= import("./mistral-
|
|
904
|
+
mistralProviderModulePromise ||= import("./mistral-CMDejXQt.mjs").then((module) => {
|
|
905
905
|
const provider = module;
|
|
906
906
|
return {
|
|
907
907
|
stream: provider.streamMistral,
|
|
@@ -5314,7 +5314,7 @@ function validateToolArguments(tool, toolCall) {
|
|
|
5314
5314
|
throw new Error(errorMessage);
|
|
5315
5315
|
}
|
|
5316
5316
|
//#endregion
|
|
5317
|
-
//#region ../agent/dist/schemas-
|
|
5317
|
+
//#region ../agent/dist/schemas-DCBOj0XY.mjs
|
|
5318
5318
|
const getModelLoose = getModel;
|
|
5319
5319
|
const AGENT_MODEL_ID_PATTERN = /^[a-z0-9-]+\/.+/;
|
|
5320
5320
|
const AgentModelIdSchema = z.custom((value) => typeof value === "string" && AGENT_MODEL_ID_PATTERN.test(value), "model must be vendor/model-id");
|
|
@@ -13616,6 +13616,17 @@ function ensureSessionsDir(sessionsDir) {
|
|
|
13616
13616
|
function defineTool$1(tool) {
|
|
13617
13617
|
return tool;
|
|
13618
13618
|
}
|
|
13619
|
+
function prefixLines(prefix, text) {
|
|
13620
|
+
return text.split("\n").map((line, index) => index === 0 ? `${prefix} ${line}` : ` ${line}`).join("\n");
|
|
13621
|
+
}
|
|
13622
|
+
/** Unified-diff-style replacement preview for tool results and chat display. */
|
|
13623
|
+
function formatTextReplacement(oldText, newText) {
|
|
13624
|
+
return `${prefixLines("-", oldText)}\n${prefixLines("+", newText)}`;
|
|
13625
|
+
}
|
|
13626
|
+
function truncateForToolPreview(text, limit = 4e3) {
|
|
13627
|
+
if (text.length <= limit) return text;
|
|
13628
|
+
return `${text.slice(0, limit)}\n\n[Truncated — ${text.length} characters total]`;
|
|
13629
|
+
}
|
|
13619
13630
|
const memoryPathSchema = String$1({ description: "Relative path under the memory dir (e.g. MEMORY.md, USER.md, archive/note.md)." });
|
|
13620
13631
|
const searchScopeSchema = Union([
|
|
13621
13632
|
Literal("archive"),
|
|
@@ -13717,7 +13728,7 @@ function createMemoryTool(config, db) {
|
|
|
13717
13728
|
return {
|
|
13718
13729
|
content: [{
|
|
13719
13730
|
type: "text",
|
|
13720
|
-
text: `Wrote ${displayPath(config, filePath)}`
|
|
13731
|
+
text: `Wrote ${displayPath(config, filePath)}\n\n${truncateForToolPreview(params.content)}`
|
|
13721
13732
|
}],
|
|
13722
13733
|
details: {}
|
|
13723
13734
|
};
|
|
@@ -13731,7 +13742,7 @@ function createMemoryTool(config, db) {
|
|
|
13731
13742
|
return {
|
|
13732
13743
|
content: [{
|
|
13733
13744
|
type: "text",
|
|
13734
|
-
text: `Edited ${displayPath(config, filePath)}`
|
|
13745
|
+
text: `Edited ${displayPath(config, filePath)}\n\n${formatTextReplacement(params.oldText, params.newText)}`
|
|
13735
13746
|
}],
|
|
13736
13747
|
details: {}
|
|
13737
13748
|
};
|
|
@@ -13810,9 +13821,9 @@ function seedMemoryFiles(config, options) {
|
|
|
13810
13821
|
}
|
|
13811
13822
|
ensureMdFiles(config.memoryFile, config.userFile);
|
|
13812
13823
|
}
|
|
13813
|
-
function createDefaultMemory(options = {}) {
|
|
13824
|
+
function createDefaultMemory(options = {}, env = process.env) {
|
|
13814
13825
|
return { async create({ agentId }) {
|
|
13815
|
-
const paths = agentPaths(agentId);
|
|
13826
|
+
const paths = agentPaths(agentId, env);
|
|
13816
13827
|
const config = loadMemoryConfig(paths.memoryDir, paths.sessionsDir, options);
|
|
13817
13828
|
seedMemoryFiles(config, options);
|
|
13818
13829
|
ensureArchiveDir(config.archiveDir);
|
|
@@ -13882,6 +13893,66 @@ function runWithinAgentPromptExecution(fn) {
|
|
|
13882
13893
|
function isWithinAgentPromptExecution() {
|
|
13883
13894
|
return executingAgentPrompt.getStore() === true;
|
|
13884
13895
|
}
|
|
13896
|
+
const TITLE_MODEL_ID = "deepseek/deepseek-v4-flash";
|
|
13897
|
+
const TITLE_SYSTEM_PROMPT = [
|
|
13898
|
+
"You are an expert chat title generator.",
|
|
13899
|
+
"",
|
|
13900
|
+
"Given the conversation so far (initial user message), generate a short, clear, and natural title (max 6-8 words) that captures the main topic or goal.",
|
|
13901
|
+
"",
|
|
13902
|
+
"Rules:",
|
|
13903
|
+
"- Be specific and descriptive; avoid vague titles like \"Conversation\" or \"Question\"",
|
|
13904
|
+
"- Prefer action-oriented or outcome-focused phrasing when possible",
|
|
13905
|
+
"- Use title case",
|
|
13906
|
+
"- Keep it under 65 characters when possible",
|
|
13907
|
+
"- Do not use quotes or emojis",
|
|
13908
|
+
"- Return ONLY the title, nothing else",
|
|
13909
|
+
"",
|
|
13910
|
+
"Examples:",
|
|
13911
|
+
"",
|
|
13912
|
+
"User: How do I set up a new Next.js project with TypeScript?",
|
|
13913
|
+
"→ Setting Up Next.js Project with TypeScript",
|
|
13914
|
+
"",
|
|
13915
|
+
"User: Help me debug this React hook that's causing infinite re-renders. Here's the code...",
|
|
13916
|
+
"→ Debugging Infinite Re-render in React Hook",
|
|
13917
|
+
"",
|
|
13918
|
+
"User: Write a cold email sequence for fundraising from YC alums",
|
|
13919
|
+
"→ YC Alumni Fundraising Cold Email Sequence"
|
|
13920
|
+
].join("\n");
|
|
13921
|
+
const MAX_INPUT_CHARS = 2e3;
|
|
13922
|
+
const MAX_TITLE_CHARS = 65;
|
|
13923
|
+
function normalizeTitle(raw) {
|
|
13924
|
+
const trimmed = raw.replace(/\s+/g, " ").trim().replace(/^["'`]+|["'`]+$/g, "").replace(/[.!?,;:]+$/g, "").trim();
|
|
13925
|
+
if (!trimmed) return null;
|
|
13926
|
+
return trimmed.length > MAX_TITLE_CHARS ? `${trimmed.slice(0, MAX_TITLE_CHARS).trim()}…` : trimmed;
|
|
13927
|
+
}
|
|
13928
|
+
/** Generate a concise chat title from the user's opening message. Returns null on empty output. */
|
|
13929
|
+
async function generateSessionTitle(message) {
|
|
13930
|
+
const input = message.trim();
|
|
13931
|
+
if (!input) return null;
|
|
13932
|
+
return normalizeTitle((await completeSimple(resolveAgentModel(TITLE_MODEL_ID), {
|
|
13933
|
+
systemPrompt: TITLE_SYSTEM_PROMPT,
|
|
13934
|
+
messages: [{
|
|
13935
|
+
role: "user",
|
|
13936
|
+
content: input.slice(0, MAX_INPUT_CHARS),
|
|
13937
|
+
timestamp: Date.now()
|
|
13938
|
+
}]
|
|
13939
|
+
}, {
|
|
13940
|
+
maxTokens: 32,
|
|
13941
|
+
temperature: .3
|
|
13942
|
+
})).content.filter((part) => part.type === "text").map((part) => part.text).join(" "));
|
|
13943
|
+
}
|
|
13944
|
+
/**
|
|
13945
|
+
* Generate and persist a session title from the opening message. Never throws — titling is a
|
|
13946
|
+
* best-effort enhancement that must not affect the prompt run.
|
|
13947
|
+
*/
|
|
13948
|
+
async function generateAndStoreSessionTitle(sessionId, message) {
|
|
13949
|
+
try {
|
|
13950
|
+
const title = await generateSessionTitle(message);
|
|
13951
|
+
if (title) await setSessionTitle(sessionId, title);
|
|
13952
|
+
} catch (err) {
|
|
13953
|
+
console.error("[session] title generation failed:", err);
|
|
13954
|
+
}
|
|
13955
|
+
}
|
|
13885
13956
|
function llmUsageFromAssistantMessage(message) {
|
|
13886
13957
|
const usage = message.usage;
|
|
13887
13958
|
if (!usage) return null;
|
|
@@ -13976,6 +14047,7 @@ async function prepareAgentSession(agentId, sessionId, options) {
|
|
|
13976
14047
|
async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
13977
14048
|
const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
|
|
13978
14049
|
const priorMessages = await listMessageEvents(sessionId);
|
|
14050
|
+
const titleTask = priorMessages.length === 0 ? generateAndStoreSessionTitle(sessionId, input.message) : void 0;
|
|
13979
14051
|
const runPrompt = async () => {
|
|
13980
14052
|
let runtime;
|
|
13981
14053
|
let unsubscribe;
|
|
@@ -13983,6 +14055,8 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
|
13983
14055
|
const pendingHandlers = /* @__PURE__ */ new Set();
|
|
13984
14056
|
const signal = getRunSignal();
|
|
13985
14057
|
let promptDurationMs = 0;
|
|
14058
|
+
let lastLiveWriteAt = 0;
|
|
14059
|
+
const LIVE_MESSAGE_WRITE_INTERVAL_MS = 400;
|
|
13986
14060
|
try {
|
|
13987
14061
|
runtime = await agent.buildRuntime({
|
|
13988
14062
|
agentId,
|
|
@@ -13997,15 +14071,31 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
|
13997
14071
|
});
|
|
13998
14072
|
const activeRuntime = runtime;
|
|
13999
14073
|
unsubscribe = activeRuntime.pi.subscribe((event) => {
|
|
14074
|
+
if (event.type === "message_start" || event.type === "message_update") {
|
|
14075
|
+
const now = Date.now();
|
|
14076
|
+
if (now - lastLiveWriteAt >= LIVE_MESSAGE_WRITE_INTERVAL_MS) {
|
|
14077
|
+
lastLiveWriteAt = now;
|
|
14078
|
+
setSessionLiveMessage(sessionId, event.message).catch((err) => {
|
|
14079
|
+
console.error("[session] live message persist failed:", err);
|
|
14080
|
+
});
|
|
14081
|
+
}
|
|
14082
|
+
}
|
|
14000
14083
|
if (!shouldPersistAgentEvent(event)) return;
|
|
14001
14084
|
const tracked = (async () => {
|
|
14002
14085
|
await persistAgentEvent(activeRuntime.agentId, sessionId, event);
|
|
14003
|
-
if (event.type === "message_end"
|
|
14004
|
-
|
|
14005
|
-
|
|
14006
|
-
|
|
14007
|
-
|
|
14008
|
-
}
|
|
14086
|
+
if (event.type === "message_end") {
|
|
14087
|
+
try {
|
|
14088
|
+
await clearLiveMessage(sessionId);
|
|
14089
|
+
} catch (err) {
|
|
14090
|
+
console.error("[session] live message clear failed:", err);
|
|
14091
|
+
}
|
|
14092
|
+
if (event.message.role === "assistant") {
|
|
14093
|
+
const usage = llmUsageFromAssistantMessage(event.message);
|
|
14094
|
+
if (usage) await recordLlmUsageFromAssistantMessage({
|
|
14095
|
+
sessionId,
|
|
14096
|
+
usage
|
|
14097
|
+
});
|
|
14098
|
+
}
|
|
14009
14099
|
}
|
|
14010
14100
|
})().finally(() => {
|
|
14011
14101
|
pendingHandlers.delete(tracked);
|
|
@@ -14055,6 +14145,12 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
|
|
|
14055
14145
|
await runtime.sandbox.dispose();
|
|
14056
14146
|
}
|
|
14057
14147
|
await addAgentSessionDuration(sessionId, promptDurationMs);
|
|
14148
|
+
try {
|
|
14149
|
+
await clearLiveMessage(sessionId);
|
|
14150
|
+
} catch (err) {
|
|
14151
|
+
console.error("[session] live message clear failed:", err);
|
|
14152
|
+
}
|
|
14153
|
+
if (titleTask) await titleTask;
|
|
14058
14154
|
}
|
|
14059
14155
|
};
|
|
14060
14156
|
if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);
|