@keystrokehq/keystroke 0.1.20 → 0.1.22

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 (41) hide show
  1. package/dist/agent.cjs +72 -54
  2. package/dist/agent.cjs.map +1 -1
  3. package/dist/agent.d.cts +2 -2
  4. package/dist/agent.d.mts +2 -2
  5. package/dist/agent.mjs +71 -52
  6. package/dist/agent.mjs.map +1 -1
  7. package/dist/{dist-KpQEao0i.mjs → dist-B1Pjv-cM.mjs} +666 -21
  8. package/dist/dist-B1Pjv-cM.mjs.map +1 -0
  9. package/dist/{dist-BFCT4aiu.cjs → dist-D69ocJ7u.cjs} +728 -23
  10. package/dist/dist-D69ocJ7u.cjs.map +1 -0
  11. package/dist/{index-Dlu1kaci.d.cts → index-BQOZkLWG.d.cts} +10 -34
  12. package/dist/index-BQOZkLWG.d.cts.map +1 -0
  13. package/dist/{index-I9DneAMW.d.mts → index-CGf1NwA4.d.mts} +10 -34
  14. package/dist/index-CGf1NwA4.d.mts.map +1 -0
  15. package/dist/{index-BUYoOHa1.d.mts → index-WHR4qX4x.d.mts} +10 -3
  16. package/dist/index-WHR4qX4x.d.mts.map +1 -0
  17. package/dist/{index-Dzm0OSN4.d.cts → index-wpyFrBvl.d.cts} +10 -3
  18. package/dist/index-wpyFrBvl.d.cts.map +1 -0
  19. package/dist/{token-dA7JRmgB.cjs → token-DZEJHEnH.cjs} +2 -2
  20. package/dist/{token-dA7JRmgB.cjs.map → token-DZEJHEnH.cjs.map} +1 -1
  21. package/dist/{token-shJjdG3B.mjs → token-D_x8iwF8.mjs} +2 -2
  22. package/dist/{token-shJjdG3B.mjs.map → token-D_x8iwF8.mjs.map} +1 -1
  23. package/dist/trigger.cjs +1 -1
  24. package/dist/trigger.d.cts +2 -2
  25. package/dist/trigger.d.mts +2 -2
  26. package/dist/trigger.mjs +1 -1
  27. package/dist/workflow.cjs +3 -1
  28. package/dist/workflow.d.cts +2 -2
  29. package/dist/workflow.d.mts +2 -2
  30. package/dist/workflow.mjs +2 -2
  31. package/package.json +2 -2
  32. package/dist/dist-BFCT4aiu.cjs.map +0 -1
  33. package/dist/dist-BekOBuw8.cjs +0 -665
  34. package/dist/dist-BekOBuw8.cjs.map +0 -1
  35. package/dist/dist-C-1uJk5f.mjs +0 -612
  36. package/dist/dist-C-1uJk5f.mjs.map +0 -1
  37. package/dist/dist-KpQEao0i.mjs.map +0 -1
  38. package/dist/index-BUYoOHa1.d.mts.map +0 -1
  39. package/dist/index-Dlu1kaci.d.cts.map +0 -1
  40. package/dist/index-Dzm0OSN4.d.cts.map +0 -1
  41. package/dist/index-I9DneAMW.d.mts.map +0 -1
package/dist/agent.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_dist = require("./dist-BKL5duJl.cjs");
3
3
  const require_dist$1 = require("./dist-DqZUy3u_.cjs");
4
- const require_dist$2 = require("./dist-BFCT4aiu.cjs");
4
+ const require_dist$2 = require("./dist-D69ocJ7u.cjs");
5
5
  const require_dist$3 = require("./dist-D2U-6NPJ.cjs");
6
6
  let zod = require("zod");
7
7
  let node_async_hooks = require("node:async_hooks");
@@ -1609,8 +1609,53 @@ async function resolveAgentWorkspaceRoot(agentId, sessionId, options) {
1609
1609
  sessionRoot
1610
1610
  };
1611
1611
  }
1612
+ const subagentParameters = zod.z.object({ message: zod.z.string().describe("Task or question for the subagent") });
1613
+ function defaultToMessage(params) {
1614
+ if (typeof params === "object" && params !== null && "message" in params) {
1615
+ const message = params.message;
1616
+ if (typeof message === "string" && message.length > 0) return message;
1617
+ }
1618
+ throw new Error("Subagent tool params must include a non-empty \"message\" string.");
1619
+ }
1620
+ function toSubagentTool(agent) {
1621
+ const name = agent.slug;
1622
+ return require_dist.defineTool({
1623
+ name,
1624
+ label: name,
1625
+ description: agent.description ?? name,
1626
+ parameters: subagentParameters,
1627
+ async execute(toolCallId, params, signal) {
1628
+ if (signal?.aborted) throw new Error("Operation aborted");
1629
+ const result = await require_dist$2.withSpan({
1630
+ kind: "tool_call",
1631
+ name,
1632
+ refId: toolCallId,
1633
+ metadata: {
1634
+ tool: name,
1635
+ type: "subagent"
1636
+ }
1637
+ }, async () => runDirectAgentPrompt(agent, agent.slug, { message: defaultToMessage(params) }, { tracing: { trigger: "subagent" } }));
1638
+ if (result.error) throw new Error(result.error);
1639
+ return {
1640
+ content: [{
1641
+ type: "text",
1642
+ text: result.text
1643
+ }],
1644
+ details: {
1645
+ sessionId: result.sessionId,
1646
+ error: result.error
1647
+ }
1648
+ };
1649
+ }
1650
+ });
1651
+ }
1652
+ function assertUniqueToolName(seen, tool) {
1653
+ if (seen.has(tool.name)) throw new Error(`Duplicate agent tool name "${tool.name}" in tools[]`);
1654
+ seen.add(tool.name);
1655
+ }
1612
1656
  async function resolveAgentTools(tools, resolver, options) {
1613
1657
  const prepared = [];
1658
+ const seenNames = /* @__PURE__ */ new Set();
1614
1659
  const mcpToolSet = {};
1615
1660
  const mcpConnections = [];
1616
1661
  for (const item of tools) {
@@ -1621,7 +1666,7 @@ async function resolveAgentTools(tools, resolver, options) {
1621
1666
  continue;
1622
1667
  }
1623
1668
  if (require_dist$1.isAction(item)) {
1624
- prepared.push(require_dist$1.resolveActionTool(item, {
1669
+ const tool = require_dist$1.resolveActionTool(item, {
1625
1670
  resolveCredentials: (requirements, consumer, contextOverride) => require_dist$2.resolveActionCredentials(requirements, {
1626
1671
  resolveCredentials: resolver.resolve.bind(resolver),
1627
1672
  consumer,
@@ -1633,9 +1678,24 @@ async function resolveAgentTools(tools, resolver, options) {
1633
1678
  id: item.slug
1634
1679
  },
1635
1680
  mcpCredentialContext: options?.mcpCredentialContext
1636
- }));
1681
+ });
1682
+ assertUniqueToolName(seenNames, tool);
1683
+ prepared.push(tool);
1684
+ continue;
1685
+ }
1686
+ if (require_dist$2.isWorkflow(item)) {
1687
+ const tool = require_dist$2.resolveWorkflowTool(item);
1688
+ assertUniqueToolName(seenNames, tool);
1689
+ prepared.push(tool);
1637
1690
  continue;
1638
1691
  }
1692
+ if (isAgent(item)) {
1693
+ const tool = toSubagentTool(item);
1694
+ assertUniqueToolName(seenNames, tool);
1695
+ prepared.push(tool);
1696
+ continue;
1697
+ }
1698
+ assertUniqueToolName(seenNames, item);
1639
1699
  prepared.push(item);
1640
1700
  }
1641
1701
  return {
@@ -1791,6 +1851,11 @@ function normalizeAgentDefinition(input, options = {}) {
1791
1851
  ...input.web !== void 0 ? { web: input.web } : {}
1792
1852
  };
1793
1853
  }
1854
+ const AGENT = Symbol.for("keystroke.agent");
1855
+ function isAgent(value) {
1856
+ if (typeof value !== "object" || value === null) return false;
1857
+ return value[AGENT] === true;
1858
+ }
1794
1859
  /**
1795
1860
  * Define an agent: normalized config plus a pipeline that builds sandbox + pi runtime on demand.
1796
1861
  */
@@ -1814,57 +1879,11 @@ function defineAgent(input) {
1814
1879
  });
1815
1880
  }
1816
1881
  return runDirectAgentPrompt(agent, slug, promptInput, runPrompt);
1817
- })
1882
+ }),
1883
+ [AGENT]: true
1818
1884
  };
1819
1885
  return agent;
1820
1886
  }
1821
- const SUBAGENT_TOOL = Symbol.for("keystroke.subagent.tool");
1822
- function getSubagentToolMetadata(tool) {
1823
- return tool[SUBAGENT_TOOL];
1824
- }
1825
- function defaultToMessage(params) {
1826
- if (typeof params === "object" && params !== null && "message" in params) {
1827
- const message = params.message;
1828
- if (typeof message === "string" && message.length > 0) return message;
1829
- }
1830
- throw new Error("Subagent tool params must include a \"message\" string, or pass toMessage to defineSubagentTool.");
1831
- }
1832
- function defineSubagentTool(input) {
1833
- const { agent, inherit, toMessage = defaultToMessage, ...toolDef } = input;
1834
- const metadata = {
1835
- agent,
1836
- inherit
1837
- };
1838
- const subagentTool = require_dist.defineTool({
1839
- ...toolDef,
1840
- description: toolDef.description ?? toolDef.label,
1841
- async execute(toolCallId, params, signal) {
1842
- if (signal?.aborted) throw new Error("Operation aborted");
1843
- const result = await require_dist$2.withSpan({
1844
- kind: "tool_call",
1845
- name: toolDef.name,
1846
- refId: toolCallId,
1847
- metadata: {
1848
- tool: toolDef.name,
1849
- type: "subagent"
1850
- }
1851
- }, async () => runDirectAgentPrompt(agent, agent.slug, { message: toMessage(params) }, { tracing: { trigger: "subagent" } }));
1852
- if (result.error) throw new Error(result.error);
1853
- return {
1854
- content: [{
1855
- type: "text",
1856
- text: result.text
1857
- }],
1858
- details: {
1859
- sessionId: result.sessionId,
1860
- error: result.error
1861
- }
1862
- };
1863
- }
1864
- });
1865
- subagentTool[SUBAGENT_TOOL] = metadata;
1866
- return subagentTool;
1867
- }
1868
1887
  const STATIC_MODEL_IDS = new Set([
1869
1888
  "alibaba/qwen-3-14b",
1870
1889
  "alibaba/qwen-3-235b",
@@ -2262,10 +2281,10 @@ async function runLlm(opts, hooks) {
2262
2281
  return runPromptText(opts, hooks);
2263
2282
  }
2264
2283
  //#endregion
2284
+ exports.AGENT = AGENT;
2265
2285
  exports.AgentCreateInputSchema = AgentCreateInputSchema;
2266
2286
  exports.AgentModelIdSchema = AgentModelIdSchema;
2267
2287
  exports.DEFAULT_THINKING_LEVEL = DEFAULT_THINKING_LEVEL;
2268
- exports.SUBAGENT_TOOL = SUBAGENT_TOOL;
2269
2288
  exports.SessionAgentMismatchError = SessionAgentMismatchError;
2270
2289
  exports.ThinkingLevelSchema = ThinkingLevelSchema;
2271
2290
  exports.agentModelIdsFromStoredManifest = agentModelIdsFromStoredManifest;
@@ -2275,9 +2294,8 @@ exports.connectMcpServer = require_dist$2.connectMcpServer;
2275
2294
  exports.connectMcpStdio = require_dist$2.connectMcpStdio;
2276
2295
  exports.defineAgent = defineAgent;
2277
2296
  exports.defineMcp = require_dist$2.defineMcp;
2278
- exports.defineSubagentTool = defineSubagentTool;
2279
2297
  exports.defineTool = require_dist.defineTool;
2280
- exports.getSubagentToolMetadata = getSubagentToolMetadata;
2298
+ exports.isAgent = isAgent;
2281
2299
  exports.isMcp = require_dist$2.isMcp;
2282
2300
  exports.loadAssetManifest = require_dist$3.loadAssetManifest;
2283
2301
  exports.modelSupportsMediaType = require_dist.modelSupportsMediaType;