@ai-setting/roy-agent-core 1.7.44 → 1.7.47

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 (59) hide show
  1. package/dist/config/index.js +4 -4
  2. package/dist/env/agent/index.js +7 -7
  3. package/dist/env/commands/index.js +4 -4
  4. package/dist/env/debug/index.js +4 -4
  5. package/dist/env/event-source/index.js +8 -7
  6. package/dist/env/hook/index.js +2 -2
  7. package/dist/env/index.js +24 -23
  8. package/dist/env/llm/index.js +15 -5
  9. package/dist/env/log-trace/index.js +4 -4
  10. package/dist/env/mcp/index.js +4 -4
  11. package/dist/env/memory/index.js +4 -4
  12. package/dist/env/plugin/index.js +8 -6
  13. package/dist/env/prompt/index.js +4 -4
  14. package/dist/env/session/index.js +7 -7
  15. package/dist/env/session/storage/index.js +3 -3
  16. package/dist/env/skill/index.js +4 -4
  17. package/dist/env/task/delegate/index.js +2 -2
  18. package/dist/env/task/index.js +6 -6
  19. package/dist/env/task/plugins/index.js +2 -2
  20. package/dist/env/task/storage/index.js +1 -1
  21. package/dist/env/tool/index.js +4 -4
  22. package/dist/env/workflow/engine/index.js +3 -3
  23. package/dist/env/workflow/index.js +11 -11
  24. package/dist/env/workflow/tools/index.js +8 -8
  25. package/dist/index.js +37 -30
  26. package/dist/shared/@ai-setting/{roy-agent-core-cysnmvcy.js → roy-agent-core-0r90298w.js} +1 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-qfktfbrr.js → roy-agent-core-1rm32m5t.js} +3 -3
  28. package/dist/shared/@ai-setting/{roy-agent-core-a236mps6.js → roy-agent-core-3j4by8rj.js} +35 -2
  29. package/dist/shared/@ai-setting/{roy-agent-core-wybj8emq.js → roy-agent-core-4m02hnqf.js} +1 -1
  30. package/dist/shared/@ai-setting/{roy-agent-core-jawzpf5k.js → roy-agent-core-4nnv0dze.js} +1 -1
  31. package/dist/shared/@ai-setting/{roy-agent-core-cw89yj9d.js → roy-agent-core-54wzmvnb.js} +1 -1
  32. package/dist/shared/@ai-setting/{roy-agent-core-jjw7xcxv.js → roy-agent-core-55hkeft7.js} +2 -2
  33. package/dist/shared/@ai-setting/{roy-agent-core-rmn29nrh.js → roy-agent-core-64f22h1g.js} +1 -11
  34. package/dist/shared/@ai-setting/{roy-agent-core-eakjnbaj.js → roy-agent-core-7p5zf8ay.js} +4 -4
  35. package/dist/shared/@ai-setting/{roy-agent-core-qhw8jp6j.js → roy-agent-core-83mk8wrn.js} +2 -2
  36. package/dist/shared/@ai-setting/roy-agent-core-ajtsk20z.js +2396 -0
  37. package/dist/shared/@ai-setting/{roy-agent-core-pc8x07p0.js → roy-agent-core-amp8qckb.js} +1 -1
  38. package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +11 -0
  39. package/dist/shared/@ai-setting/{roy-agent-core-2f2nqx7g.js → roy-agent-core-b09eqhhz.js} +86 -60
  40. package/dist/shared/@ai-setting/{roy-agent-core-0gmnp1jt.js → roy-agent-core-bjrtwfta.js} +41 -6
  41. package/dist/shared/@ai-setting/{roy-agent-core-ts56bz5e.js → roy-agent-core-d94ddn0r.js} +3 -3
  42. package/dist/shared/@ai-setting/{roy-agent-core-rczz7e81.js → roy-agent-core-dabnevwe.js} +1 -1
  43. package/dist/shared/@ai-setting/{roy-agent-core-9t675te0.js → roy-agent-core-ead21w5c.js} +2 -2
  44. package/dist/shared/@ai-setting/{roy-agent-core-c95tpapc.js → roy-agent-core-gy1zfe0d.js} +2 -2
  45. package/dist/shared/@ai-setting/{roy-agent-core-5tzc2spk.js → roy-agent-core-h93v6p6y.js} +2 -2
  46. package/dist/shared/@ai-setting/{roy-agent-core-f18jk3cw.js → roy-agent-core-hxazjj4p.js} +1 -1
  47. package/dist/shared/@ai-setting/{roy-agent-core-3h7ajma5.js → roy-agent-core-jfptxs4f.js} +1 -1
  48. package/dist/shared/@ai-setting/{roy-agent-core-4m0t4y9w.js → roy-agent-core-nvcqp6p9.js} +1 -1
  49. package/dist/shared/@ai-setting/{roy-agent-core-jadrj0bz.js → roy-agent-core-p1p9mr8f.js} +13 -0
  50. package/dist/shared/@ai-setting/{roy-agent-core-65q93n1k.js → roy-agent-core-pk1b3kvf.js} +1 -1
  51. package/dist/shared/@ai-setting/{roy-agent-core-n1ceexfz.js → roy-agent-core-qvaqmj3f.js} +1 -1
  52. package/dist/shared/@ai-setting/{roy-agent-core-6mnwqcqf.js → roy-agent-core-v5vs1jby.js} +1 -1
  53. package/dist/shared/@ai-setting/{roy-agent-core-z6kv2mdp.js → roy-agent-core-y1fp2mgf.js} +18 -35
  54. package/dist/shared/@ai-setting/{roy-agent-core-asxe1nt4.js → roy-agent-core-ygnva439.js} +2 -2
  55. package/dist/shared/@ai-setting/{roy-agent-core-8xgk89y4.js → roy-agent-core-yjqj3taz.js} +4 -4
  56. package/dist/shared/@ai-setting/{roy-agent-core-w3tq0j5c.js → roy-agent-core-zrgaemma.js} +1 -1
  57. package/dist/shared/@ai-setting/{roy-agent-core-2ahddbdf.js → roy-agent-core-zy3hqfwg.js} +251 -53
  58. package/package.json +1 -1
  59. package/dist/shared/@ai-setting/roy-agent-core-0zgcfcnq.js +0 -1720
@@ -10,7 +10,7 @@ import {
10
10
  } from "./roy-agent-core-7hh0brvs.js";
11
11
  import {
12
12
  BaseComponent
13
- } from "./roy-agent-core-9t675te0.js";
13
+ } from "./roy-agent-core-ead21w5c.js";
14
14
  import {
15
15
  createLogger,
16
16
  init_logger
@@ -0,0 +1,11 @@
1
+ // src/env/plugin/types.ts
2
+ class BasePlugin {
3
+ version = "1.0.0";
4
+ description;
5
+ priority = 0;
6
+ constructor() {}
7
+ init(env) {}
8
+ dispose() {}
9
+ }
10
+
11
+ export { BasePlugin };
@@ -4,24 +4,25 @@ import {
4
4
  import {
5
5
  TaskTagPlugin,
6
6
  createLarkCliTaskNotifyHook,
7
- createPerTaskGroupChatPlugin
8
- } from "./roy-agent-core-0zgcfcnq.js";
7
+ createPerTaskGroupChatPlugin,
8
+ mergeChatOwnership
9
+ } from "./roy-agent-core-ajtsk20z.js";
9
10
  import {
10
11
  getSharedEventStore
11
12
  } from "./roy-agent-core-xyys5m1a.js";
12
13
  import {
13
14
  normalizeLarkAtMentions
14
- } from "./roy-agent-core-rmn29nrh.js";
15
+ } from "./roy-agent-core-64f22h1g.js";
15
16
  import {
16
17
  envKeyToConfigKey
17
18
  } from "./roy-agent-core-7hh0brvs.js";
18
19
  import {
19
20
  BaseComponent
20
- } from "./roy-agent-core-9t675te0.js";
21
+ } from "./roy-agent-core-ead21w5c.js";
21
22
  import {
22
23
  globalHookManager,
23
24
  init_global_hook_manager
24
- } from "./roy-agent-core-a236mps6.js";
25
+ } from "./roy-agent-core-3j4by8rj.js";
25
26
  import {
26
27
  init_context
27
28
  } from "./roy-agent-core-wn59p0zw.js";
@@ -1028,6 +1029,9 @@ class LarkCliInstance {
1028
1029
  child;
1029
1030
  buffer = "";
1030
1031
  eventHandler;
1032
+ cardRoutingPorts;
1033
+ chatNameCache = new Map;
1034
+ pluginInstances = new Map;
1031
1035
  static SHARED_SEEN = new Map;
1032
1036
  static SHARED_MSG_TTL_MS = 10 * 60 * 1000;
1033
1037
  static SHARED_MSG_MAX = 1000;
@@ -1138,6 +1142,7 @@ class LarkCliInstance {
1138
1142
  for (const pluginName of plugins) {
1139
1143
  const plugin = await this.importPlugin(pluginName);
1140
1144
  if (plugin) {
1145
+ this.pluginInstances.set(pluginName, plugin);
1141
1146
  const hookPoints = this.getPluginHookPoints(plugin);
1142
1147
  this.registerPluginHooks(plugin);
1143
1148
  this.loadedPlugins.push({
@@ -1149,6 +1154,20 @@ class LarkCliInstance {
1149
1154
  console.error(`[LarkCliInstance] Failed to import plugin "${pluginName}". ` + `plugin name=${pluginName} 不在 BUILT_IN_PLUGIN_FACTORIES 注册表里`);
1150
1155
  }
1151
1156
  }
1157
+ this.wireCardRoutingGroupProvider();
1158
+ }
1159
+ wireCardRoutingGroupProvider() {
1160
+ const notifyHook = this.pluginInstances.get("LarkCliTaskNotifyPlugin");
1161
+ const perTaskGroup = this.pluginInstances.get("PerTaskGroupChatPlugin");
1162
+ if (!notifyHook || typeof notifyHook.setCardRoutingPorts !== "function")
1163
+ return;
1164
+ if (!perTaskGroup || typeof perTaskGroup.ensureGroupChat !== "function")
1165
+ return;
1166
+ notifyHook.setCardRoutingPorts({
1167
+ ...this.cardRoutingPorts ?? {},
1168
+ ensureTaskGroupChat: (task) => perTaskGroup.ensureGroupChat(task)
1169
+ });
1170
+ console.debug("[LarkCliInstance] Card routing cross-wired: " + "LarkCliTaskNotifyPlugin.ensureTaskGroupChat ← PerTaskGroupChatPlugin");
1152
1171
  }
1153
1172
  getPluginHookPoints(plugin) {
1154
1173
  if (Array.isArray(plugin.hooks)) {
@@ -1190,6 +1209,7 @@ class LarkCliInstance {
1190
1209
  this.injectTaskUpdater(plugin);
1191
1210
  this.injectTaskGetter(plugin);
1192
1211
  this.injectSessionComponent(plugin);
1212
+ this.injectCardRoutingPorts(plugin);
1193
1213
  if (typeof plugin.init === "function") {
1194
1214
  const pluginEnv = {
1195
1215
  getComponent: () => null,
@@ -1294,6 +1314,67 @@ class LarkCliInstance {
1294
1314
  }
1295
1315
  plugin.setTaskGetter((id) => taskComponent.getTask(id));
1296
1316
  }
1317
+ injectCardRoutingPorts(plugin) {
1318
+ if (typeof plugin.setCardRoutingPorts !== "function")
1319
+ return;
1320
+ const taskComponent = this.environment?.getComponent?.("task");
1321
+ const sessionComponent = this.environment?.getComponent?.("session");
1322
+ const lookupChatOwnership = async (chatId) => {
1323
+ if (!chatId)
1324
+ return;
1325
+ try {
1326
+ let boundTaskId;
1327
+ if (sessionComponent?.getChatTaskBinding) {
1328
+ try {
1329
+ const binding = await sessionComponent.getChatTaskBinding(chatId);
1330
+ if (binding && typeof binding.taskId === "number") {
1331
+ boundTaskId = binding.taskId;
1332
+ }
1333
+ } catch {}
1334
+ }
1335
+ let candidates = [];
1336
+ if (taskComponent?.findTasksByContextValue) {
1337
+ const tasks = await taskComponent.findTasksByContextValue(chatId, 50);
1338
+ candidates = (tasks ?? []).map((t) => ({
1339
+ id: t.id,
1340
+ context: t.context
1341
+ }));
1342
+ }
1343
+ const chatName = await this.lookupChatName(chatId);
1344
+ return mergeChatOwnership(chatId, candidates, { boundTaskId, chatName });
1345
+ } catch (error) {
1346
+ if (isPluginDebugEnabled()) {
1347
+ console.debug(`[LarkCliInstance] lookupChatOwnership failed for ${chatId}: ${error}`);
1348
+ }
1349
+ return;
1350
+ }
1351
+ };
1352
+ this.cardRoutingPorts = {
1353
+ lookupChatOwnership,
1354
+ getTask: taskComponent?.getTask ? (id) => taskComponent.getTask(id) : undefined
1355
+ };
1356
+ plugin.setCardRoutingPorts({ ...this.cardRoutingPorts });
1357
+ }
1358
+ async lookupChatName(chatId) {
1359
+ const cached = this.chatNameCache.get(chatId);
1360
+ if (cached !== undefined)
1361
+ return cached || undefined;
1362
+ try {
1363
+ const runner = getLarkCliRunner();
1364
+ const result = await runner.run(`lark-cli ${this.config.profile ? `--profile ${this.config.profile} ` : ""}im chats get --chat-id ${chatId}`);
1365
+ if (result.code !== 0) {
1366
+ this.chatNameCache.set(chatId, "");
1367
+ return;
1368
+ }
1369
+ const parsed = JSON.parse(result.stdout || "{}");
1370
+ const name = parsed?.data?.name ?? parsed?.data?.chat?.name ?? parsed?.name;
1371
+ this.chatNameCache.set(chatId, typeof name === "string" ? name : "");
1372
+ return typeof name === "string" ? name : undefined;
1373
+ } catch {
1374
+ this.chatNameCache.set(chatId, "");
1375
+ return;
1376
+ }
1377
+ }
1297
1378
  injectSessionComponent(plugin) {
1298
1379
  if (typeof plugin.setSessionComponent !== "function") {
1299
1380
  return;
@@ -1797,28 +1878,6 @@ ${headline}
1797
1878
  },
1798
1879
  setRunner(runner) {
1799
1880
  setLarkCliRunner(runner);
1800
- },
1801
- async postProcessNotifyEvent(input) {
1802
- try {
1803
- const chats = dedupeChatIds(input.resolvedChatIds ?? []);
1804
- if (chats.length === 0) {
1805
- logger.info(`[larkCliHandler] postProcessNotifyEvent: no resolved target chat for ` + `taskId=${input.notifyEvent.taskId}; skip mirror.`);
1806
- return;
1807
- }
1808
- for (const chatId of chats) {
1809
- try {
1810
- await sendMarkdownToChat(chatId, input.formattedPrompt, input.profile);
1811
- } catch (err) {
1812
- const errMsg = err instanceof Error ? err.message : String(err);
1813
- logger.error(`[larkCliHandler] postProcessNotifyEvent: send failed for chatId=${chatId}`, { error: errMsg });
1814
- }
1815
- }
1816
- } catch (err) {
1817
- const errMsg = err instanceof Error ? err.message : String(err);
1818
- logger.error(`[larkCliHandler] postProcessNotifyEvent failed`, {
1819
- error: errMsg
1820
- });
1821
- }
1822
1881
  }
1823
1882
  };
1824
1883
  if (larkCliHandler.extractReplyContext) {
@@ -1827,39 +1886,6 @@ if (larkCliHandler.extractReplyContext) {
1827
1886
  if (larkCliHandler.buildNotifyHandlePrompt) {
1828
1887
  larkCliHandler.buildNotifyHandlePrompt = wrapFunction(larkCliHandler.buildNotifyHandlePrompt, "buildNotifyHandlePrompt", { recordParams: true, recordResult: false, recordError: true });
1829
1888
  }
1830
- if (larkCliHandler.postProcessNotifyEvent) {
1831
- larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", {
1832
- recordParams: true,
1833
- recordResult: false,
1834
- recordError: true,
1835
- paramFilter: (args) => ({
1836
- taskId: args[0]?.notifyEvent?.taskId,
1837
- resolvedChatIds: args[0]?.resolvedChatIds
1838
- }),
1839
- flattenParamFilter: true
1840
- });
1841
- }
1842
- function dedupeChatIds(ids) {
1843
- const out = [];
1844
- const seen = new Set;
1845
- for (const id of ids) {
1846
- if (typeof id === "string" && id.length > 0 && !seen.has(id)) {
1847
- seen.add(id);
1848
- out.push(id);
1849
- }
1850
- }
1851
- return out;
1852
- }
1853
- async function sendMarkdownToChat(chatId, markdown, profile) {
1854
- const profileFlag = profile ? `--profile ${profile} ` : "";
1855
- const runner = getLarkCliRunner();
1856
- const safeMd = markdown.replace(/'/g, `'\\''`);
1857
- const command = `lark-cli ${profileFlag}im +messages-send ` + `--chat-id "${chatId}" --as bot --markdown '${safeMd}'`;
1858
- const result = await runner.run(command);
1859
- if (result.code !== 0) {
1860
- throw new Error(`messages-send exit ${result.code}: ${result.stderr || "(no stderr)"}`);
1861
- }
1862
- }
1863
1889
  var _larkCliRunner = defaultLarkCliRunner;
1864
1890
  function getLarkCliRunner() {
1865
1891
  return _larkCliRunner;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  truncateOutputInline
3
- } from "./roy-agent-core-jjw7xcxv.js";
3
+ } from "./roy-agent-core-55hkeft7.js";
4
4
  import {
5
5
  AgentRegistry
6
6
  } from "./roy-agent-core-za09t5g3.js";
@@ -9,11 +9,12 @@ import {
9
9
  } from "./roy-agent-core-4cj6hram.js";
10
10
  import {
11
11
  SessionMessageConverter
12
- } from "./roy-agent-core-65q93n1k.js";
12
+ } from "./roy-agent-core-pk1b3kvf.js";
13
13
  import {
14
+ parseToolArgsStrict,
14
15
  safeParseToolArgs,
15
16
  withTimeout
16
- } from "./roy-agent-core-2ahddbdf.js";
17
+ } from "./roy-agent-core-zy3hqfwg.js";
17
18
  import {
18
19
  getCurrentBgTaskId
19
20
  } from "./roy-agent-core-c1v263jn.js";
@@ -29,11 +30,11 @@ import {
29
30
  } from "./roy-agent-core-7hh0brvs.js";
30
31
  import {
31
32
  BaseComponent
32
- } from "./roy-agent-core-9t675te0.js";
33
+ } from "./roy-agent-core-ead21w5c.js";
33
34
  import {
34
35
  globalHookManager,
35
36
  init_global_hook_manager
36
- } from "./roy-agent-core-a236mps6.js";
37
+ } from "./roy-agent-core-3j4by8rj.js";
37
38
  import {
38
39
  init_context
39
40
  } from "./roy-agent-core-wn59p0zw.js";
@@ -1042,7 +1043,37 @@ class AgentComponent extends BaseComponent {
1042
1043
  }
1043
1044
  const func = toolCall.function;
1044
1045
  const tcName = func?.name || toolCall.name || "unknown";
1045
- const tcArgs = this.parseToolCallArguments(toolCall);
1046
+ const tcArgsParsed = this.parseToolCallArgumentsStrict(toolCall);
1047
+ if (!tcArgsParsed.ok) {
1048
+ const invalidMessage = tcArgsParsed.error ?? "invalid tool arguments";
1049
+ logger2.warn(`[ReAct] 工具参数不可解析,已拒绝执行(未跑任何命令/无副作用): ` + `tool=${tcName} error=${invalidMessage}`);
1050
+ this.pushEnvEvent({
1051
+ type: "tool.error",
1052
+ payload: { error: invalidMessage, toolName: tcName }
1053
+ });
1054
+ this.pushMessage(hookCtx, {
1055
+ role: "tool",
1056
+ content: [{
1057
+ type: "tool-result",
1058
+ toolCallId: toolCall.id,
1059
+ toolName: tcName,
1060
+ output: JSON.stringify({
1061
+ success: false,
1062
+ error: invalidMessage,
1063
+ hint: "上一次调用的 arguments 不是合法 JSON(上游输出可能损坏)。请重新调用,并确保 arguments 是合法 JSON 对象,不要包含任何 XML/标记文本。"
1064
+ })
1065
+ }]
1066
+ });
1067
+ hookCtx.toolResult = {
1068
+ id: toolCall.id,
1069
+ name: tcName,
1070
+ success: false,
1071
+ result: { success: false, output: "", error: invalidMessage }
1072
+ };
1073
+ iterProcessedCount++;
1074
+ continue;
1075
+ }
1076
+ const tcArgs = tcArgsParsed.args;
1046
1077
  hookCtx.currentToolCall = {
1047
1078
  id: toolCall.id,
1048
1079
  name: tcName,
@@ -1493,6 +1524,10 @@ class AgentComponent extends BaseComponent {
1493
1524
  const rawArgs = toolCall.function?.arguments ?? toolCall.arguments;
1494
1525
  return safeParseToolArgs(rawArgs);
1495
1526
  }
1527
+ parseToolCallArgumentsStrict(toolCall) {
1528
+ const rawArgs = toolCall.function?.arguments ?? toolCall.arguments;
1529
+ return parseToolArgsStrict(rawArgs);
1530
+ }
1496
1531
  async executeTool(ctx) {
1497
1532
  const toolCall = ctx.currentToolCall;
1498
1533
  const toolName = toolCall.function?.name || toolCall.name || "unknown";
@@ -10,14 +10,14 @@ import {
10
10
  } from "./roy-agent-core-7hh0brvs.js";
11
11
  import {
12
12
  BaseComponent
13
- } from "./roy-agent-core-9t675te0.js";
13
+ } from "./roy-agent-core-ead21w5c.js";
14
14
  import {
15
15
  createHook
16
- } from "./roy-agent-core-cw89yj9d.js";
16
+ } from "./roy-agent-core-54wzmvnb.js";
17
17
  import {
18
18
  globalHookManager,
19
19
  init_global_hook_manager
20
- } from "./roy-agent-core-a236mps6.js";
20
+ } from "./roy-agent-core-3j4by8rj.js";
21
21
  import {
22
22
  createLogger,
23
23
  init_logger
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  AgentComponentAdapter,
9
9
  init_agent_component_adapter
10
- } from "./roy-agent-core-3h7ajma5.js";
10
+ } from "./roy-agent-core-jfptxs4f.js";
11
11
  import {
12
12
  PythonCallNode,
13
13
  SkillNode,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createHook
3
- } from "./roy-agent-core-cw89yj9d.js";
3
+ } from "./roy-agent-core-54wzmvnb.js";
4
4
  import {
5
5
  HookManager
6
- } from "./roy-agent-core-a236mps6.js";
6
+ } from "./roy-agent-core-3j4by8rj.js";
7
7
 
8
8
  // src/env/component.ts
9
9
  class BaseComponent {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MemorySessionStore,
3
3
  SQLiteSessionStore
4
- } from "./roy-agent-core-5tzc2spk.js";
4
+ } from "./roy-agent-core-h93v6p6y.js";
5
5
  import {
6
6
  init_search_query_parser,
7
7
  matchesQuery,
@@ -12,7 +12,7 @@ import {
12
12
  } from "./roy-agent-core-7hh0brvs.js";
13
13
  import {
14
14
  BaseComponent
15
- } from "./roy-agent-core-9t675te0.js";
15
+ } from "./roy-agent-core-ead21w5c.js";
16
16
  import {
17
17
  TracedAs,
18
18
  init_decorator
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  SessionMessageConverter
3
- } from "./roy-agent-core-65q93n1k.js";
3
+ } from "./roy-agent-core-pk1b3kvf.js";
4
4
  import {
5
5
  canonicalizeParts
6
- } from "./roy-agent-core-2ahddbdf.js";
6
+ } from "./roy-agent-core-zy3hqfwg.js";
7
7
  import {
8
8
  createLogger,
9
9
  init_logger
@@ -8,7 +8,7 @@ import {
8
8
  } from "./roy-agent-core-qxnbvgwe.js";
9
9
  import {
10
10
  BaseComponent
11
- } from "./roy-agent-core-9t675te0.js";
11
+ } from "./roy-agent-core-ead21w5c.js";
12
12
  import {
13
13
  __require
14
14
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  globalHookManager,
11
11
  init_global_hook_manager
12
- } from "./roy-agent-core-a236mps6.js";
12
+ } from "./roy-agent-core-3j4by8rj.js";
13
13
  import {
14
14
  TracedAs,
15
15
  init_decorator,
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  globalHookManager,
22
22
  init_global_hook_manager
23
- } from "./roy-agent-core-a236mps6.js";
23
+ } from "./roy-agent-core-3j4by8rj.js";
24
24
  import {
25
25
  init_context
26
26
  } from "./roy-agent-core-wn59p0zw.js";
@@ -1107,6 +1107,19 @@ var init_sqlite_task_store = __esm(() => {
1107
1107
  const rows = stmt.all(`%${query}%`, `%${query}%`, limit);
1108
1108
  return rows.map((row) => this.rowToTask(row));
1109
1109
  }
1110
+ async findTasksByContextValue(value, limit = 50) {
1111
+ await this.initialize();
1112
+ if (!value)
1113
+ return [];
1114
+ const sql = `
1115
+ SELECT * FROM task
1116
+ WHERE context LIKE ?
1117
+ ORDER BY updated_at DESC
1118
+ LIMIT ?
1119
+ `;
1120
+ const rows = this.db.prepare(sql).all(`%${value}%`, limit);
1121
+ return rows.map((row) => this.rowToTask(row));
1122
+ }
1110
1123
  rowToTag(row) {
1111
1124
  return {
1112
1125
  id: row.id,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  safeParseToolArgs
3
- } from "./roy-agent-core-2ahddbdf.js";
3
+ } from "./roy-agent-core-zy3hqfwg.js";
4
4
 
5
5
  // src/env/session/session-message-converter.ts
6
6
  import { randomUUID } from "crypto";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-7hh0brvs.js";
5
5
  import {
6
6
  BaseComponent
7
- } from "./roy-agent-core-9t675te0.js";
7
+ } from "./roy-agent-core-ead21w5c.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
@@ -6,7 +6,7 @@ import {
6
6
  } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-9t675te0.js";
9
+ } from "./roy-agent-core-ead21w5c.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
@@ -6,9 +6,11 @@ import {
6
6
  sniffImageMime
7
7
  } from "./roy-agent-core-zjdzk1gg.js";
8
8
  import {
9
+ buildOpencodeHeaders,
9
10
  invoke,
10
- invokeNonStream
11
- } from "./roy-agent-core-2ahddbdf.js";
11
+ invokeNonStream,
12
+ toolParametersToJsonSchema
13
+ } from "./roy-agent-core-zy3hqfwg.js";
12
14
  import {
13
15
  ContextError,
14
16
  ErrorCodes
@@ -19,12 +21,12 @@ import {
19
21
  } from "./roy-agent-core-7hh0brvs.js";
20
22
  import {
21
23
  BaseComponent
22
- } from "./roy-agent-core-9t675te0.js";
24
+ } from "./roy-agent-core-ead21w5c.js";
23
25
  import {
24
26
  LLMHookPoints,
25
27
  globalHookManager,
26
28
  init_global_hook_manager
27
- } from "./roy-agent-core-a236mps6.js";
29
+ } from "./roy-agent-core-3j4by8rj.js";
28
30
  import {
29
31
  TracedAs,
30
32
  init_decorator,
@@ -49,7 +51,6 @@ import {
49
51
  stream as piStream,
50
52
  getModel
51
53
  } from "@earendil-works/pi-ai";
52
- import { zodToJsonSchema } from "zod-to-json-schema";
53
54
  var logger = createLogger("llm:adapter-pi-ai");
54
55
  var KNOWN_PROVIDER_APIS = {
55
56
  anthropic: { api: "anthropic-messages", contextLimit: 200000, maxTokensLimit: 8192 },
@@ -157,33 +158,8 @@ function safeJson(s) {
157
158
  return {};
158
159
  }
159
160
  }
160
- function isZodSchema(obj) {
161
- return !!obj && typeof obj === "object" && "_def" in obj;
162
- }
163
161
  function convertToolParameters(parameters) {
164
- if (parameters == null)
165
- return { type: "object", properties: {} };
166
- if (typeof parameters !== "object")
167
- return { type: "object", properties: {} };
168
- if (isZodSchema(parameters)) {
169
- try {
170
- const jsonSchema = zodToJsonSchema(parameters, "zod");
171
- if ("$ref" in jsonSchema && jsonSchema.definitions) {
172
- const def = jsonSchema.definitions.zod;
173
- if (def && def.type === "object" && def.properties) {
174
- return def;
175
- }
176
- }
177
- return jsonSchema;
178
- } catch {
179
- return { type: "object", properties: {} };
180
- }
181
- }
182
- const paramsObj = parameters;
183
- if (paramsObj.type === "object" && paramsObj.properties) {
184
- return paramsObj;
185
- }
186
- return { type: "object", properties: {} };
162
+ return toolParametersToJsonSchema(parameters);
187
163
  }
188
164
  function toPiTools(tools) {
189
165
  if (!tools)
@@ -194,6 +170,10 @@ function toPiTools(tools) {
194
170
  parameters: convertToolParameters(t.parameters)
195
171
  }));
196
172
  }
173
+ function piRequestExtras(req) {
174
+ const headers = buildOpencodeHeaders(req.provider, req.sessionId, req.baseURL);
175
+ return Object.keys(headers).length > 0 ? { headers } : {};
176
+ }
197
177
  function fromAssistantMessage(msg) {
198
178
  let text = "";
199
179
  const toolCalls = [];
@@ -247,7 +227,8 @@ class PiAiAdapter {
247
227
  baseURL: req.baseURL,
248
228
  temperature: req.temperature,
249
229
  maxTokens: req.maxTokens,
250
- signal: req.signal
230
+ signal: req.signal,
231
+ ...piRequestExtras(req)
251
232
  });
252
233
  return fromAssistantMessage(msg);
253
234
  }
@@ -260,7 +241,7 @@ class PiAiAdapter {
260
241
  messages: toPiMessages(req.messages),
261
242
  tools: toPiTools(req.tools)
262
243
  };
263
- const eventStream = piStream(model, ctx, { apiKey: req.apiKey, baseURL: req.baseURL, temperature: req.temperature, maxTokens: req.maxTokens, signal: req.signal });
244
+ const eventStream = piStream(model, ctx, { apiKey: req.apiKey, baseURL: req.baseURL, temperature: req.temperature, maxTokens: req.maxTokens, signal: req.signal, ...piRequestExtras(req) });
264
245
  return { events: eventStream, result: async () => fromAssistantMessage(await eventStream.result()) };
265
246
  }
266
247
  async embed(_req) {
@@ -417,7 +398,8 @@ class AiSdkAdapter {
417
398
  tools: req.tools,
418
399
  temperature: req.temperature,
419
400
  maxTokens: req.maxTokens,
420
- model: req.modelId
401
+ model: `${req.provider}/${req.modelId}`,
402
+ context: req.sessionId ? { sessionId: req.sessionId } : undefined
421
403
  };
422
404
  }
423
405
  }
@@ -1211,7 +1193,8 @@ class LLMComponent extends BaseComponent {
1211
1193
  maxTokens: ctx.maxTokens,
1212
1194
  apiKey: ctx.invokeConfig.apiKey || "",
1213
1195
  baseURL: ctx.invokeConfig.baseURL,
1214
- signal: ctx.abortSignal
1196
+ signal: ctx.abortSignal,
1197
+ sessionId: request.context?.sessionId
1215
1198
  };
1216
1199
  let output = {
1217
1200
  content: "",
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-3h7ajma5.js";
4
+ } from "./roy-agent-core-jfptxs4f.js";
5
5
  import"./roy-agent-core-1db4vpc6.js";
6
6
  import"./roy-agent-core-e25xkv53.js";
7
- import"./roy-agent-core-a236mps6.js";
7
+ import"./roy-agent-core-3j4by8rj.js";
8
8
  import"./roy-agent-core-wn59p0zw.js";
9
9
  import"./roy-agent-core-zbb3sk72.js";
10
10
  import"./roy-agent-core-a9pbda78.js";
@@ -27,11 +27,11 @@ import {
27
27
  BackgroundTaskManager,
28
28
  createDelegateTool,
29
29
  createStopTool
30
- } from "./roy-agent-core-4m0t4y9w.js";
30
+ } from "./roy-agent-core-nvcqp6p9.js";
31
31
  import {
32
32
  SQLiteTaskStore,
33
33
  getDefaultTaskDbPath
34
- } from "./roy-agent-core-jadrj0bz.js";
34
+ } from "./roy-agent-core-p1p9mr8f.js";
35
35
  import {
36
36
  TaskHookPoints
37
37
  } from "./roy-agent-core-1pg0fepg.js";
@@ -40,11 +40,11 @@ import {
40
40
  } from "./roy-agent-core-7hh0brvs.js";
41
41
  import {
42
42
  BaseComponent
43
- } from "./roy-agent-core-9t675te0.js";
43
+ } from "./roy-agent-core-ead21w5c.js";
44
44
  import {
45
45
  globalHookManager,
46
46
  init_global_hook_manager
47
- } from "./roy-agent-core-a236mps6.js";
47
+ } from "./roy-agent-core-3j4by8rj.js";
48
48
  import {
49
49
  getEnvContextOrEmpty,
50
50
  init_env_context
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isValidSessionId
3
- } from "./roy-agent-core-c95tpapc.js";
3
+ } from "./roy-agent-core-gy1zfe0d.js";
4
4
  import {
5
5
  TAG_MAX_COUNT,
6
6
  TAG_MIN_COUNT