@keystrokehq/keystroke 1.0.6 → 1.0.7

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.
Files changed (53) hide show
  1. package/dist/action.cjs +1 -1
  2. package/dist/action.mjs +1 -1
  3. package/dist/agent.cjs +110 -14
  4. package/dist/agent.cjs.map +1 -1
  5. package/dist/agent.d.cts +1 -1
  6. package/dist/agent.d.mts +1 -1
  7. package/dist/agent.mjs +110 -14
  8. package/dist/agent.mjs.map +1 -1
  9. package/dist/app.cjs +1 -1
  10. package/dist/app.mjs +1 -1
  11. package/dist/client.cjs +1 -1
  12. package/dist/client.mjs +1 -1
  13. package/dist/credentials.cjs +1 -1
  14. package/dist/credentials.mjs +1 -1
  15. package/dist/{dist-pErVjN3p.mjs → dist-BpkCqbil.mjs} +3 -3
  16. package/dist/{dist-pErVjN3p.mjs.map → dist-BpkCqbil.mjs.map} +1 -1
  17. package/dist/{dist-DBE-7Q9K.cjs → dist-C5otI4u3.cjs} +58 -7
  18. package/dist/dist-C5otI4u3.cjs.map +1 -0
  19. package/dist/{dist-hu4oHsK8.cjs → dist-DOMwPx7V.cjs} +54 -14
  20. package/dist/dist-DOMwPx7V.cjs.map +1 -0
  21. package/dist/{dist-B4CrrSM0.cjs → dist-DQL6zTI5.cjs} +3 -3
  22. package/dist/{dist-B4CrrSM0.cjs.map → dist-DQL6zTI5.cjs.map} +1 -1
  23. package/dist/{dist-6ug9ozqR.mjs → dist-DqFdFpiB.mjs} +54 -14
  24. package/dist/dist-DqFdFpiB.mjs.map +1 -0
  25. package/dist/{dist-BgFLp5DL.mjs → dist-IUl7Bexl.mjs} +41 -8
  26. package/dist/dist-IUl7Bexl.mjs.map +1 -0
  27. package/dist/{index-Dd0B13U7.d.cts → index-BY9SPR2h.d.cts} +2 -1
  28. package/dist/index-BY9SPR2h.d.cts.map +1 -0
  29. package/dist/{index-IhPXtbNf.d.mts → index-BeBgntxT.d.mts} +2 -1
  30. package/dist/index-BeBgntxT.d.mts.map +1 -0
  31. package/dist/index-e9f4pcX4.d.cts.map +1 -1
  32. package/dist/index-e9f4pcX4.d.mts.map +1 -1
  33. package/dist/{mistral-B1ULILEc.mjs → mistral-CMDejXQt.mjs} +2 -2
  34. package/dist/{mistral-B1ULILEc.mjs.map → mistral-CMDejXQt.mjs.map} +1 -1
  35. package/dist/{mistral-WPrOS6Bw.cjs → mistral-wOLLEgb9.cjs} +2 -2
  36. package/dist/{mistral-WPrOS6Bw.cjs.map → mistral-wOLLEgb9.cjs.map} +1 -1
  37. package/dist/{sse-B3mQ3cnH.mjs → sse-DI7TsPKG.mjs} +2 -2
  38. package/dist/{sse-B3mQ3cnH.mjs.map → sse-DI7TsPKG.mjs.map} +1 -1
  39. package/dist/{sse-7gbBPR9G.cjs → sse-Dzs73rQw.cjs} +2 -2
  40. package/dist/{sse-7gbBPR9G.cjs.map → sse-Dzs73rQw.cjs.map} +1 -1
  41. package/dist/trigger.cjs +1 -1
  42. package/dist/trigger.d.cts +1 -1
  43. package/dist/trigger.d.mts +1 -1
  44. package/dist/trigger.mjs +1 -1
  45. package/dist/workflow.cjs +1 -1
  46. package/dist/workflow.mjs +1 -1
  47. package/package.json +3 -3
  48. package/dist/dist-6ug9ozqR.mjs.map +0 -1
  49. package/dist/dist-BgFLp5DL.mjs.map +0 -1
  50. package/dist/dist-DBE-7Q9K.cjs.map +0 -1
  51. package/dist/dist-hu4oHsK8.cjs.map +0 -1
  52. package/dist/index-Dd0B13U7.d.cts.map +0 -1
  53. package/dist/index-IhPXtbNf.d.mts.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-hu4oHsK8.cjs");
2
+ const require_dist = require("./dist-DOMwPx7V.cjs");
3
3
  exports.CREDENTIAL_SCOPE_TYPES = require_dist.CREDENTIAL_SCOPE_TYPES;
4
4
  exports.actionCoreSchema = require_dist.actionCoreSchema;
5
5
  exports.createStepInvocation = require_dist.createStepInvocation;
package/dist/action.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { S as isCredentialInput, T as toCredentialRequirement, _ as runWithinActionExecution, a as getActionCredentialRequirements, b as credentialInputSchema, c as getWorkflowRunHandle, d as isWithinActionExecution, f as registerProjectScopeGetter, g as runWithRunSignal, h as runOutsideActionExecution, i as executeAction, l as isAction, m as resolveActionTool, n as createStepInvocation, o as getRegisteredProjectScopeId, p as registerWorkflowRunGetter, r as defineAction, s as getRunSignal, t as actionCoreSchema, u as isStepInvocation, v as CREDENTIAL_SCOPE_TYPES, w as normalizeCredentialList, x as defineCredential, y as credential } from "./dist-6ug9ozqR.mjs";
1
+ import { S as isCredentialInput, T as toCredentialRequirement, _ as runWithinActionExecution, a as getActionCredentialRequirements, b as credentialInputSchema, c as getWorkflowRunHandle, d as isWithinActionExecution, f as registerProjectScopeGetter, g as runWithRunSignal, h as runOutsideActionExecution, i as executeAction, l as isAction, m as resolveActionTool, n as createStepInvocation, o as getRegisteredProjectScopeId, p as registerWorkflowRunGetter, r as defineAction, s as getRunSignal, t as actionCoreSchema, u as isStepInvocation, v as CREDENTIAL_SCOPE_TYPES, w as normalizeCredentialList, x as defineCredential, y as credential } from "./dist-DqFdFpiB.mjs";
2
2
  export { CREDENTIAL_SCOPE_TYPES, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getRegisteredProjectScopeId, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerProjectScopeGetter, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
package/dist/agent.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-DHdmVzO2.cjs");
3
- const require_dist$1 = require("./dist-hu4oHsK8.cjs");
4
- const require_dist$2 = require("./dist-DBE-7Q9K.cjs");
3
+ const require_dist$1 = require("./dist-DOMwPx7V.cjs");
4
+ const require_dist$2 = require("./dist-C5otI4u3.cjs");
5
5
  const require_dist$3 = require("./dist-DO51rYHS.cjs");
6
6
  require("./env-api-keys-BFptfIIs.cjs");
7
7
  const require_event_stream = require("./event-stream-CS-ls7wC.cjs");
@@ -902,7 +902,7 @@ function loadGoogleVertexProviderModule() {
902
902
  return googleVertexProviderModulePromise;
903
903
  }
904
904
  function loadMistralProviderModule() {
905
- mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-WPrOS6Bw.cjs")).then((module) => {
905
+ mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-wOLLEgb9.cjs")).then((module) => {
906
906
  const provider = module;
907
907
  return {
908
908
  stream: provider.streamMistral,
@@ -5325,7 +5325,7 @@ function validateToolArguments(tool, toolCall) {
5325
5325
  throw new Error(errorMessage);
5326
5326
  }
5327
5327
  //#endregion
5328
- //#region ../agent/dist/schemas-BLmL2ciI.mjs
5328
+ //#region ../agent/dist/schemas-DCBOj0XY.mjs
5329
5329
  const getModelLoose = require_event_stream.getModel;
5330
5330
  const AGENT_MODEL_ID_PATTERN = /^[a-z0-9-]+\/.+/;
5331
5331
  const AgentModelIdSchema = zod.z.custom((value) => typeof value === "string" && AGENT_MODEL_ID_PATTERN.test(value), "model must be vendor/model-id");
@@ -13627,6 +13627,17 @@ function ensureSessionsDir(sessionsDir) {
13627
13627
  function defineTool$1(tool) {
13628
13628
  return tool;
13629
13629
  }
13630
+ function prefixLines(prefix, text) {
13631
+ return text.split("\n").map((line, index) => index === 0 ? `${prefix} ${line}` : ` ${line}`).join("\n");
13632
+ }
13633
+ /** Unified-diff-style replacement preview for tool results and chat display. */
13634
+ function formatTextReplacement(oldText, newText) {
13635
+ return `${prefixLines("-", oldText)}\n${prefixLines("+", newText)}`;
13636
+ }
13637
+ function truncateForToolPreview(text, limit = 4e3) {
13638
+ if (text.length <= limit) return text;
13639
+ return `${text.slice(0, limit)}\n\n[Truncated — ${text.length} characters total]`;
13640
+ }
13630
13641
  const memoryPathSchema = require_dist$3.String({ description: "Relative path under the memory dir (e.g. MEMORY.md, USER.md, archive/note.md)." });
13631
13642
  const searchScopeSchema = require_dist$3.Union([
13632
13643
  require_dist$3.Literal("archive"),
@@ -13728,7 +13739,7 @@ function createMemoryTool(config, db) {
13728
13739
  return {
13729
13740
  content: [{
13730
13741
  type: "text",
13731
- text: `Wrote ${displayPath(config, filePath)}`
13742
+ text: `Wrote ${displayPath(config, filePath)}\n\n${truncateForToolPreview(params.content)}`
13732
13743
  }],
13733
13744
  details: {}
13734
13745
  };
@@ -13742,7 +13753,7 @@ function createMemoryTool(config, db) {
13742
13753
  return {
13743
13754
  content: [{
13744
13755
  type: "text",
13745
- text: `Edited ${displayPath(config, filePath)}`
13756
+ text: `Edited ${displayPath(config, filePath)}\n\n${formatTextReplacement(params.oldText, params.newText)}`
13746
13757
  }],
13747
13758
  details: {}
13748
13759
  };
@@ -13821,9 +13832,9 @@ function seedMemoryFiles(config, options) {
13821
13832
  }
13822
13833
  ensureMdFiles(config.memoryFile, config.userFile);
13823
13834
  }
13824
- function createDefaultMemory(options = {}) {
13835
+ function createDefaultMemory(options = {}, env = process.env) {
13825
13836
  return { async create({ agentId }) {
13826
- const paths = agentPaths(agentId);
13837
+ const paths = agentPaths(agentId, env);
13827
13838
  const config = loadMemoryConfig(paths.memoryDir, paths.sessionsDir, options);
13828
13839
  seedMemoryFiles(config, options);
13829
13840
  ensureArchiveDir(config.archiveDir);
@@ -13893,6 +13904,66 @@ function runWithinAgentPromptExecution(fn) {
13893
13904
  function isWithinAgentPromptExecution() {
13894
13905
  return executingAgentPrompt.getStore() === true;
13895
13906
  }
13907
+ const TITLE_MODEL_ID = "deepseek/deepseek-v4-flash";
13908
+ const TITLE_SYSTEM_PROMPT = [
13909
+ "You are an expert chat title generator.",
13910
+ "",
13911
+ "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.",
13912
+ "",
13913
+ "Rules:",
13914
+ "- Be specific and descriptive; avoid vague titles like \"Conversation\" or \"Question\"",
13915
+ "- Prefer action-oriented or outcome-focused phrasing when possible",
13916
+ "- Use title case",
13917
+ "- Keep it under 65 characters when possible",
13918
+ "- Do not use quotes or emojis",
13919
+ "- Return ONLY the title, nothing else",
13920
+ "",
13921
+ "Examples:",
13922
+ "",
13923
+ "User: How do I set up a new Next.js project with TypeScript?",
13924
+ "→ Setting Up Next.js Project with TypeScript",
13925
+ "",
13926
+ "User: Help me debug this React hook that's causing infinite re-renders. Here's the code...",
13927
+ "→ Debugging Infinite Re-render in React Hook",
13928
+ "",
13929
+ "User: Write a cold email sequence for fundraising from YC alums",
13930
+ "→ YC Alumni Fundraising Cold Email Sequence"
13931
+ ].join("\n");
13932
+ const MAX_INPUT_CHARS = 2e3;
13933
+ const MAX_TITLE_CHARS = 65;
13934
+ function normalizeTitle(raw) {
13935
+ const trimmed = raw.replace(/\s+/g, " ").trim().replace(/^["'`]+|["'`]+$/g, "").replace(/[.!?,;:]+$/g, "").trim();
13936
+ if (!trimmed) return null;
13937
+ return trimmed.length > MAX_TITLE_CHARS ? `${trimmed.slice(0, MAX_TITLE_CHARS).trim()}…` : trimmed;
13938
+ }
13939
+ /** Generate a concise chat title from the user's opening message. Returns null on empty output. */
13940
+ async function generateSessionTitle(message) {
13941
+ const input = message.trim();
13942
+ if (!input) return null;
13943
+ return normalizeTitle((await completeSimple(resolveAgentModel(TITLE_MODEL_ID), {
13944
+ systemPrompt: TITLE_SYSTEM_PROMPT,
13945
+ messages: [{
13946
+ role: "user",
13947
+ content: input.slice(0, MAX_INPUT_CHARS),
13948
+ timestamp: Date.now()
13949
+ }]
13950
+ }, {
13951
+ maxTokens: 32,
13952
+ temperature: .3
13953
+ })).content.filter((part) => part.type === "text").map((part) => part.text).join(" "));
13954
+ }
13955
+ /**
13956
+ * Generate and persist a session title from the opening message. Never throws — titling is a
13957
+ * best-effort enhancement that must not affect the prompt run.
13958
+ */
13959
+ async function generateAndStoreSessionTitle(sessionId, message) {
13960
+ try {
13961
+ const title = await generateSessionTitle(message);
13962
+ if (title) await require_dist$2.setSessionTitle(sessionId, title);
13963
+ } catch (err) {
13964
+ console.error("[session] title generation failed:", err);
13965
+ }
13966
+ }
13896
13967
  function llmUsageFromAssistantMessage(message) {
13897
13968
  const usage = message.usage;
13898
13969
  if (!usage) return null;
@@ -13987,6 +14058,7 @@ async function prepareAgentSession(agentId, sessionId, options) {
13987
14058
  async function runAgentPrompt(agent, agentId, input, options = {}) {
13988
14059
  const { sessionId } = await prepareAgentSession(agentId, input.sessionId);
13989
14060
  const priorMessages = await require_dist$2.listMessageEvents(sessionId);
14061
+ const titleTask = priorMessages.length === 0 ? generateAndStoreSessionTitle(sessionId, input.message) : void 0;
13990
14062
  const runPrompt = async () => {
13991
14063
  let runtime;
13992
14064
  let unsubscribe;
@@ -13994,6 +14066,8 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
13994
14066
  const pendingHandlers = /* @__PURE__ */ new Set();
13995
14067
  const signal = require_dist$1.getRunSignal();
13996
14068
  let promptDurationMs = 0;
14069
+ let lastLiveWriteAt = 0;
14070
+ const LIVE_MESSAGE_WRITE_INTERVAL_MS = 400;
13997
14071
  try {
13998
14072
  runtime = await agent.buildRuntime({
13999
14073
  agentId,
@@ -14008,15 +14082,31 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
14008
14082
  });
14009
14083
  const activeRuntime = runtime;
14010
14084
  unsubscribe = activeRuntime.pi.subscribe((event) => {
14085
+ if (event.type === "message_start" || event.type === "message_update") {
14086
+ const now = Date.now();
14087
+ if (now - lastLiveWriteAt >= LIVE_MESSAGE_WRITE_INTERVAL_MS) {
14088
+ lastLiveWriteAt = now;
14089
+ require_dist$2.setSessionLiveMessage(sessionId, event.message).catch((err) => {
14090
+ console.error("[session] live message persist failed:", err);
14091
+ });
14092
+ }
14093
+ }
14011
14094
  if (!shouldPersistAgentEvent(event)) return;
14012
14095
  const tracked = (async () => {
14013
14096
  await persistAgentEvent(activeRuntime.agentId, sessionId, event);
14014
- if (event.type === "message_end" && event.message.role === "assistant") {
14015
- const usage = llmUsageFromAssistantMessage(event.message);
14016
- if (usage) await require_dist$2.recordLlmUsageFromAssistantMessage({
14017
- sessionId,
14018
- usage
14019
- });
14097
+ if (event.type === "message_end") {
14098
+ try {
14099
+ await require_dist$2.clearLiveMessage(sessionId);
14100
+ } catch (err) {
14101
+ console.error("[session] live message clear failed:", err);
14102
+ }
14103
+ if (event.message.role === "assistant") {
14104
+ const usage = llmUsageFromAssistantMessage(event.message);
14105
+ if (usage) await require_dist$2.recordLlmUsageFromAssistantMessage({
14106
+ sessionId,
14107
+ usage
14108
+ });
14109
+ }
14020
14110
  }
14021
14111
  })().finally(() => {
14022
14112
  pendingHandlers.delete(tracked);
@@ -14066,6 +14156,12 @@ async function runAgentPrompt(agent, agentId, input, options = {}) {
14066
14156
  await runtime.sandbox.dispose();
14067
14157
  }
14068
14158
  await require_dist$2.addAgentSessionDuration(sessionId, promptDurationMs);
14159
+ try {
14160
+ await require_dist$2.clearLiveMessage(sessionId);
14161
+ } catch (err) {
14162
+ console.error("[session] live message clear failed:", err);
14163
+ }
14164
+ if (titleTask) await titleTask;
14069
14165
  }
14070
14166
  };
14071
14167
  if (options.skipAgentSessionSpan) return runWithinAgentPromptExecution(runPrompt);