@ai-setting/roy-agent-core 1.4.13 → 1.4.15

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 (102) hide show
  1. package/dist/config/index.js +32 -0
  2. package/dist/env/agent/index.js +24 -0
  3. package/dist/env/commands/index.js +14 -0
  4. package/dist/env/debug/formatters/index.js +11 -0
  5. package/dist/env/debug/index.js +26 -0
  6. package/dist/env/hook/index.js +29 -0
  7. package/dist/env/index.js +81 -0
  8. package/dist/env/llm/index.js +40 -0
  9. package/dist/env/log-trace/index.js +83 -0
  10. package/dist/env/mcp/index.js +39 -0
  11. package/dist/env/mcp/tool/index.js +14 -0
  12. package/dist/env/memory/built-in/index.js +11 -0
  13. package/dist/env/memory/index.js +56 -0
  14. package/dist/env/memory/plugin/index.js +36 -0
  15. package/dist/env/prompt/index.js +20 -0
  16. package/dist/env/session/index.js +25 -0
  17. package/dist/env/session/storage/index.js +18 -0
  18. package/dist/env/skill/index.js +34 -0
  19. package/dist/env/skill/tool/index.js +9 -0
  20. package/dist/env/task/delegate/index.js +18 -0
  21. package/dist/env/task/hooks/index.js +7 -0
  22. package/dist/env/task/index.js +30 -0
  23. package/dist/env/task/plugins/index.js +23 -0
  24. package/dist/env/task/storage/index.js +14 -0
  25. package/dist/env/task/tools/index.js +17 -0
  26. package/dist/env/task/tools/operation/index.js +15 -0
  27. package/dist/{shared/chunk-1d4rwms4.js → env/tool/built-in/index.js} +4 -4
  28. package/dist/env/tool/index.js +39 -0
  29. package/dist/env/workflow/decorators/index.js +27 -0
  30. package/dist/env/workflow/engine/index.js +28 -0
  31. package/dist/env/workflow/index.js +132 -0
  32. package/dist/env/workflow/nodes/index.js +19 -0
  33. package/dist/env/workflow/service/index.js +13 -0
  34. package/dist/env/workflow/storage/index.js +27 -0
  35. package/dist/env/workflow/tools/index.js +159 -0
  36. package/dist/env/workflow/types/index.js +94 -0
  37. package/dist/env/workflow/utils/index.js +637 -0
  38. package/dist/index.js +233 -16386
  39. package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-0rtxwr28.js} +6 -114
  40. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-12zkpda2.js +393 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-2kg2wma8.js +620 -0
  45. package/dist/shared/@ai-setting/roy-agent-core-2x0m2p66.js +851 -0
  46. package/dist/shared/@ai-setting/roy-agent-core-35x0wrtt.js +172 -0
  47. package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-37e4tep3.js} +2 -2
  48. package/dist/shared/@ai-setting/roy-agent-core-3agad0d9.js +603 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-4arba14a.js +419 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-4rqmfr7t.js +266 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-561b1c4p.js +377 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-5xf65pz6.js +1305 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-6a72jfdy.js +303 -0
  55. package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-7f303ffd.js} +3 -3
  56. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
  57. package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-7n436rb4.js} +7 -12
  58. package/dist/shared/@ai-setting/roy-agent-core-7r85t0qn.js +492 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7rewcey6.js +862 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
  61. package/dist/shared/@ai-setting/roy-agent-core-9qwp5qkz.js +1387 -0
  62. package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-9yxb3ty9.js} +3 -2
  63. package/dist/shared/@ai-setting/roy-agent-core-anwsxdds.js +1205 -0
  64. package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-bncgx3gb.js} +1 -1
  65. package/dist/shared/@ai-setting/roy-agent-core-cd00w5mb.js +762 -0
  66. package/dist/shared/@ai-setting/roy-agent-core-cgs0j60t.js +442 -0
  67. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
  68. package/dist/shared/@ai-setting/roy-agent-core-dbsk841j.js +286 -0
  69. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
  70. package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-e5jcp24a.js} +2 -2
  71. package/dist/shared/@ai-setting/roy-agent-core-e62e2a5a.js +204 -0
  72. package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-ewrj1c4k.js} +2 -2
  73. package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-fdb6m4e4.js} +119 -1113
  74. package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-fv32jaa8.js} +3 -3
  75. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-gmnkza34.js +202 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-hz7rr4yx.js +513 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-j3bbr2n0.js +378 -0
  79. package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-j3wc4465.js} +6 -3
  80. package/dist/shared/@ai-setting/roy-agent-core-jj79gszx.js +1130 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-mwwk6req.js +913 -0
  82. package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-pc9g3962.js} +6 -50
  83. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-pzsg9pvf.js +393 -0
  85. package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-q779wnwm.js} +5 -5
  86. package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-qw0ebh1d.js} +1 -1
  87. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-qya7seh6.js +408 -0
  90. package/dist/shared/@ai-setting/roy-agent-core-rbetrphj.js +97 -0
  91. package/dist/shared/@ai-setting/roy-agent-core-re1wjfw7.js +587 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-rft3fmp0.js +14 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
  94. package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-rvxg1wps.js} +1 -1
  95. package/dist/shared/@ai-setting/roy-agent-core-rzp9kxne.js +341 -0
  96. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-w78syn7w.js +788 -0
  98. package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-z2t8hse8.js} +3 -2
  99. package/package.json +8 -7
  100. package/dist/index.d.ts +0 -7825
  101. package/dist/shared/chunk-hs7tbmje.js +0 -24
  102. /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
@@ -0,0 +1,286 @@
1
+ // src/env/task/tools/task-types.ts
2
+ import { z } from "zod";
3
+ var CreateTaskToolSchema = z.object({
4
+ title: z.string().describe("Task title"),
5
+ description: z.string().optional().describe("Task description"),
6
+ priority: z.enum(["low", "medium", "high"]).optional().describe("Task priority"),
7
+ goals_and_expected_deliverables: z.string().optional().describe("Goals and expected deliverables"),
8
+ due_date: z.string().optional().describe("Due date (ISO format)"),
9
+ tags: z.array(z.string()).optional().describe("Task tags (for search, stored in task.tags JSON field)")
10
+ });
11
+ var GetTaskToolSchema = z.object({
12
+ task_id: z.number().describe("Task ID"),
13
+ include_operations: z.boolean().optional().default(false).describe("Include operation records")
14
+ });
15
+ var ListTasksToolSchema = z.object({
16
+ status: z.enum(["todo", "active", "completed", "paused", "cancelled"]).optional(),
17
+ priority: z.enum(["low", "medium", "high"]).optional(),
18
+ limit: z.number().optional().default(20),
19
+ offset: z.number().optional().default(0)
20
+ });
21
+ var UpdateTaskToolSchema = z.object({
22
+ task_id: z.number().describe("Task ID"),
23
+ title: z.string().optional(),
24
+ description: z.string().optional(),
25
+ status: z.enum(["todo", "active", "completed", "paused", "cancelled"]).optional(),
26
+ priority: z.enum(["low", "medium", "high"]).optional(),
27
+ progress: z.number().min(0).max(100).optional(),
28
+ current_status: z.string().optional(),
29
+ goals_and_expected_deliverables: z.string().optional(),
30
+ due_date: z.string().optional(),
31
+ tags: z.array(z.string()).optional()
32
+ });
33
+ var DeleteTaskToolSchema = z.object({
34
+ task_id: z.number().describe("Task ID")
35
+ });
36
+
37
+ // src/env/task/tools/create-tool.ts
38
+ function createTaskTool(taskComponent) {
39
+ return {
40
+ name: "task_create",
41
+ description: "Create a new task. The task will be associated with the current session.",
42
+ parameters: CreateTaskToolSchema,
43
+ execute: async (args, ctx) => {
44
+ const params = CreateTaskToolSchema.parse(args);
45
+ const sessionId = ctx.session_id || "unknown";
46
+ try {
47
+ const task = await taskComponent.createTask({
48
+ title: params.title,
49
+ description: params.description,
50
+ priority: params.priority,
51
+ goals_and_expected_deliverables: params.goals_and_expected_deliverables,
52
+ due_date: params.due_date,
53
+ tags: params.tags,
54
+ sessionId
55
+ });
56
+ return {
57
+ success: true,
58
+ output: `Task created successfully: #${task.id} - ${task.title}`,
59
+ metadata: {
60
+ execution_time_ms: 0,
61
+ task_id: task.id,
62
+ status: task.status,
63
+ createdAt: task.createdAt
64
+ }
65
+ };
66
+ } catch (error) {
67
+ return {
68
+ success: false,
69
+ output: "",
70
+ error: error instanceof Error ? error.message : String(error),
71
+ metadata: { execution_time_ms: 0 }
72
+ };
73
+ }
74
+ }
75
+ };
76
+ }
77
+ // src/env/task/tools/get-tool.ts
78
+ function getTaskTool(taskComponent) {
79
+ return {
80
+ name: "task_get",
81
+ description: "Get task details by ID. Optionally include operation records.",
82
+ parameters: GetTaskToolSchema,
83
+ execute: async (args, ctx) => {
84
+ const params = GetTaskToolSchema.parse(args);
85
+ try {
86
+ if (params.include_operations) {
87
+ const result = await taskComponent.getTaskWithOperations(params.task_id);
88
+ if (!result) {
89
+ return {
90
+ success: false,
91
+ output: "",
92
+ error: `Task not found: ${params.task_id}`,
93
+ metadata: { execution_time_ms: 0 }
94
+ };
95
+ }
96
+ return {
97
+ success: true,
98
+ output: JSON.stringify(result, null, 2),
99
+ metadata: { execution_time_ms: 0 }
100
+ };
101
+ } else {
102
+ const task = await taskComponent.getTask(params.task_id);
103
+ if (!task) {
104
+ return {
105
+ success: false,
106
+ output: "",
107
+ error: `Task not found: ${params.task_id}`,
108
+ metadata: { execution_time_ms: 0 }
109
+ };
110
+ }
111
+ return {
112
+ success: true,
113
+ output: JSON.stringify(task, null, 2),
114
+ metadata: { execution_time_ms: 0 }
115
+ };
116
+ }
117
+ } catch (error) {
118
+ return {
119
+ success: false,
120
+ output: "",
121
+ error: error instanceof Error ? error.message : String(error),
122
+ metadata: { execution_time_ms: 0 }
123
+ };
124
+ }
125
+ }
126
+ };
127
+ }
128
+ // src/env/task/tools/list-tool.ts
129
+ function listTasksTool(taskComponent) {
130
+ return {
131
+ name: "task_list",
132
+ description: "List tasks with optional filters for status and priority.",
133
+ parameters: ListTasksToolSchema,
134
+ execute: async (args, ctx) => {
135
+ const params = ListTasksToolSchema.parse(args);
136
+ try {
137
+ const tasks = await taskComponent.listTasks({
138
+ status: params.status,
139
+ priority: params.priority,
140
+ limit: params.limit,
141
+ offset: params.offset
142
+ });
143
+ return {
144
+ success: true,
145
+ output: JSON.stringify({ tasks, count: tasks.length }),
146
+ metadata: { execution_time_ms: 0 }
147
+ };
148
+ } catch (error) {
149
+ return {
150
+ success: false,
151
+ output: "",
152
+ error: error instanceof Error ? error.message : String(error),
153
+ metadata: { execution_time_ms: 0 }
154
+ };
155
+ }
156
+ }
157
+ };
158
+ }
159
+ // src/env/task/tools/update-tool.ts
160
+ function updateTaskTool(taskComponent) {
161
+ return {
162
+ name: "task_update",
163
+ description: "Update an existing task's properties. Status and progress changes will create operation records.",
164
+ parameters: UpdateTaskToolSchema,
165
+ execute: async (args, ctx) => {
166
+ const params = UpdateTaskToolSchema.parse(args);
167
+ const sessionId = ctx.session_id || "unknown";
168
+ try {
169
+ const task = await taskComponent.updateTask(params.task_id, {
170
+ title: params.title,
171
+ description: params.description,
172
+ status: params.status,
173
+ priority: params.priority,
174
+ progress: params.progress,
175
+ current_status: params.current_status,
176
+ goals_and_expected_deliverables: params.goals_and_expected_deliverables,
177
+ due_date: params.due_date,
178
+ tags: params.tags
179
+ });
180
+ if (!task) {
181
+ return {
182
+ success: false,
183
+ output: "",
184
+ error: `Task not found: ${params.task_id}`,
185
+ metadata: { execution_time_ms: 0 }
186
+ };
187
+ }
188
+ if (params.status || params.progress !== undefined || params.current_status) {
189
+ await taskComponent.createOperation({
190
+ taskId: params.task_id,
191
+ sessionId,
192
+ actionType: "progress",
193
+ actionTitle: params.current_status || `Updated: ${params.status || `${params.progress}%`}`,
194
+ actionDescription: JSON.stringify({
195
+ status: params.status,
196
+ progress: params.progress,
197
+ current_status: params.current_status
198
+ })
199
+ });
200
+ }
201
+ return {
202
+ success: true,
203
+ output: `Task updated: #${task.id} - ${task.title}`,
204
+ metadata: { execution_time_ms: 0, task }
205
+ };
206
+ } catch (error) {
207
+ return {
208
+ success: false,
209
+ output: "",
210
+ error: error instanceof Error ? error.message : String(error),
211
+ metadata: { execution_time_ms: 0 }
212
+ };
213
+ }
214
+ }
215
+ };
216
+ }
217
+ // src/env/task/tools/delete-tool.ts
218
+ function deleteTaskTool(taskComponent) {
219
+ return {
220
+ name: "task_delete",
221
+ description: "Delete a task and all its operation records.",
222
+ parameters: DeleteTaskToolSchema,
223
+ execute: async (args, ctx) => {
224
+ const params = DeleteTaskToolSchema.parse(args);
225
+ try {
226
+ const deleted = await taskComponent.deleteTask(params.task_id);
227
+ if (!deleted) {
228
+ return {
229
+ success: false,
230
+ output: "",
231
+ error: `Task not found: ${params.task_id}`,
232
+ metadata: { execution_time_ms: 0 }
233
+ };
234
+ }
235
+ return {
236
+ success: true,
237
+ output: `Task deleted: #${params.task_id}`,
238
+ metadata: { execution_time_ms: 0 }
239
+ };
240
+ } catch (error) {
241
+ return {
242
+ success: false,
243
+ output: "",
244
+ error: error instanceof Error ? error.message : String(error),
245
+ metadata: { execution_time_ms: 0 }
246
+ };
247
+ }
248
+ }
249
+ };
250
+ }
251
+ // src/env/task/tools/complete-tool.ts
252
+ function completeTaskTool(taskComponent) {
253
+ return {
254
+ name: "task_complete",
255
+ description: "Mark a task as completed (progress=100, status=completed). Creates an operation record.",
256
+ parameters: DeleteTaskToolSchema,
257
+ execute: async (args, ctx) => {
258
+ const params = DeleteTaskToolSchema.parse(args);
259
+ const sessionId = ctx.session_id || "unknown";
260
+ try {
261
+ const task = await taskComponent.completeTask(params.task_id, sessionId);
262
+ if (!task) {
263
+ return {
264
+ success: false,
265
+ output: "",
266
+ error: `Task not found: ${params.task_id}`,
267
+ metadata: { execution_time_ms: 0 }
268
+ };
269
+ }
270
+ return {
271
+ success: true,
272
+ output: `Task completed: #${task.id} - ${task.title}`,
273
+ metadata: { execution_time_ms: 0, task }
274
+ };
275
+ } catch (error) {
276
+ return {
277
+ success: false,
278
+ output: "",
279
+ error: error instanceof Error ? error.message : String(error),
280
+ metadata: { execution_time_ms: 0 }
281
+ };
282
+ }
283
+ }
284
+ };
285
+ }
286
+ export { createTaskTool, getTaskTool, listTasksTool, updateTaskTool, deleteTaskTool, completeTaskTool };
@@ -0,0 +1,64 @@
1
+ import {
2
+ __esm
3
+ } from "./roy-agent-core-fs0mn2jk.js";
4
+
5
+ // src/env/workflow/types/workflow-hil.ts
6
+ function createNodeInterruptEvent(runId, nodeId, nodeType, query, agentSessionId) {
7
+ return {
8
+ type: "node.interrupt",
9
+ run_id: runId,
10
+ timestamp: Date.now(),
11
+ node_id: nodeId,
12
+ node_type: nodeType,
13
+ query,
14
+ ...agentSessionId ? { agent_session_id: agentSessionId } : {}
15
+ };
16
+ }
17
+ function createWorkflowAskUserEvent(runId, sessionId, nodeId, nodeType, query) {
18
+ return {
19
+ type: "workflow.ask-user",
20
+ run_id: runId,
21
+ timestamp: Date.now(),
22
+ session_id: sessionId,
23
+ node_id: nodeId,
24
+ node_type: nodeType,
25
+ query
26
+ };
27
+ }
28
+ var AskUserError;
29
+ var init_workflow_hil = __esm(() => {
30
+ AskUserError = class AskUserError extends Error {
31
+ runId;
32
+ sessionId;
33
+ nodeId;
34
+ nodeType;
35
+ query;
36
+ agentSessionId;
37
+ timestamp;
38
+ type = "ask-user";
39
+ name = "AskUserError";
40
+ constructor(runId, sessionId, nodeId, nodeType, query, agentSessionId, timestamp = Date.now()) {
41
+ super(`[${nodeType}:${nodeId}] Ask user: ${query}`);
42
+ this.runId = runId;
43
+ this.sessionId = sessionId;
44
+ this.nodeId = nodeId;
45
+ this.nodeType = nodeType;
46
+ this.query = query;
47
+ this.agentSessionId = agentSessionId;
48
+ this.timestamp = timestamp;
49
+ }
50
+ toEvent() {
51
+ return {
52
+ type: "workflow.ask-user",
53
+ run_id: this.runId,
54
+ timestamp: this.timestamp,
55
+ session_id: this.sessionId,
56
+ node_id: this.nodeId,
57
+ node_type: this.nodeType,
58
+ query: this.query
59
+ };
60
+ }
61
+ };
62
+ });
63
+
64
+ export { createNodeInterruptEvent, createWorkflowAskUserEvent, AskUserError, init_workflow_hil };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  SQLiteSpanStorage,
3
3
  init_span_storage
4
- } from "./chunk-1qwabsm0.js";
5
- import"./chunk-wbkh7wat.js";
4
+ } from "./roy-agent-core-bncgx3gb.js";
5
+ import"./roy-agent-core-fs0mn2jk.js";
6
6
  init_span_storage();
7
7
 
8
8
  export {
@@ -0,0 +1,204 @@
1
+ import {
2
+ TracedAs,
3
+ init_decorator
4
+ } from "./roy-agent-core-35x0wrtt.js";
5
+ import {
6
+ __legacyDecorateClassTS
7
+ } from "./roy-agent-core-fs0mn2jk.js";
8
+
9
+ // src/env/session/session-message-converter.ts
10
+ init_decorator();
11
+ import { randomUUID } from "crypto";
12
+ var DEFAULT_REASONING_BUDGET_TOKENS = 1e4;
13
+
14
+ class SessionMessageConverter {
15
+ toModelMessage(msg) {
16
+ if (msg.role === "assistant") {
17
+ const content = [];
18
+ for (const part of msg.parts || []) {
19
+ if (part.type === "text") {
20
+ const textPart = part;
21
+ content.push({
22
+ type: "text",
23
+ text: textPart.content,
24
+ ...textPart.synthetic !== undefined && { synthetic: textPart.synthetic }
25
+ });
26
+ } else if (part.type === "reasoning") {
27
+ const reasoningPart = part;
28
+ content.push({
29
+ type: "reasoning",
30
+ text: reasoningPart.content,
31
+ reasoningType: reasoningPart.reasoningType
32
+ });
33
+ } else if (part.type === "tool-call") {
34
+ const toolPart = part;
35
+ let parsedArgs = {};
36
+ if (typeof toolPart.arguments === "string") {
37
+ try {
38
+ parsedArgs = JSON.parse(toolPart.arguments);
39
+ } catch {
40
+ parsedArgs = { _raw: toolPart.arguments };
41
+ }
42
+ } else {
43
+ parsedArgs = toolPart.arguments;
44
+ }
45
+ content.push({
46
+ type: "tool-call",
47
+ toolCallId: toolPart.toolCallId,
48
+ toolName: toolPart.toolName,
49
+ input: parsedArgs
50
+ });
51
+ } else if (part.type === "file") {
52
+ const filePart = part;
53
+ content.push({
54
+ type: "file",
55
+ url: filePart.url,
56
+ mimeType: filePart.mime,
57
+ filename: filePart.filename
58
+ });
59
+ } else if (part.type === "tool-result" || part.type === "checkpoint") {} else {
60
+ console.debug(`[session-message-converter] Skipping unsupported part type in assistant: ${part.type}`);
61
+ }
62
+ }
63
+ if (content.length === 0 && msg.content) {
64
+ return { role: "assistant", content: msg.content };
65
+ }
66
+ return { role: "assistant", content };
67
+ }
68
+ if (msg.role === "tool") {
69
+ const toolPart = msg.parts?.find((p) => p.type === "tool-result");
70
+ return {
71
+ role: "tool",
72
+ content: [{
73
+ type: "tool-result",
74
+ toolCallId: toolPart?.toolCallId || "",
75
+ toolName: toolPart?.toolName || "",
76
+ output: toolPart?.output || msg.content || ""
77
+ }]
78
+ };
79
+ }
80
+ return {
81
+ role: msg.role,
82
+ content: msg.content || ""
83
+ };
84
+ }
85
+ fromModelMessage(aiMsg, options) {
86
+ const parts = [];
87
+ const content = typeof aiMsg.content === "string" || Array.isArray(aiMsg.content) ? aiMsg.content : "";
88
+ let hasToolCallPart = false;
89
+ let hasToolResultPart = false;
90
+ if (typeof content === "string") {
91
+ parts.push({ type: "text", content });
92
+ } else if (Array.isArray(content)) {
93
+ for (const part of content) {
94
+ const p = part;
95
+ if (p.type === "text") {
96
+ parts.push({ type: "text", content: p.text || "" });
97
+ } else if (p.type === "reasoning") {
98
+ parts.push({
99
+ type: "reasoning",
100
+ content: p.text || "",
101
+ reasoningType: p.reasoningType,
102
+ state: "completed"
103
+ });
104
+ } else if (p.type === "tool-call") {
105
+ hasToolCallPart = true;
106
+ parts.push({
107
+ type: "tool-call",
108
+ toolCallId: p.toolCallId,
109
+ toolName: p.toolName,
110
+ arguments: p.input,
111
+ state: "pending"
112
+ });
113
+ } else if (p.type === "tool-result") {
114
+ hasToolResultPart = true;
115
+ parts.push({
116
+ type: "tool-result",
117
+ toolCallId: p.toolCallId,
118
+ toolName: p.toolName,
119
+ output: typeof p.output === "string" ? p.output : JSON.stringify(p.output),
120
+ state: "completed"
121
+ });
122
+ } else if (p.type === "file") {
123
+ parts.push({
124
+ type: "file",
125
+ mime: p.mimeType || "application/octet-stream",
126
+ url: p.url,
127
+ filename: p.filename
128
+ });
129
+ } else {
130
+ console.debug(`[session-message-converter] Unknown part type: ${p.type}`);
131
+ }
132
+ }
133
+ }
134
+ let metadataType;
135
+ if (aiMsg.role === "assistant" && hasToolCallPart) {
136
+ metadataType = "tool_call";
137
+ } else if (aiMsg.role === "tool") {
138
+ metadataType = "tool_result";
139
+ }
140
+ const result = {
141
+ id: options?.messageID || `msg_${randomUUID()}`,
142
+ sessionID: options?.sessionID || "",
143
+ role: aiMsg.role,
144
+ timestamp: Date.now(),
145
+ parts,
146
+ content: typeof content === "string" ? content : ""
147
+ };
148
+ if (metadataType) {
149
+ result.metadata = { type: metadataType };
150
+ }
151
+ return result;
152
+ }
153
+ sessionToHistory(messages) {
154
+ return messages.filter((msg) => !msg.metadata?.isArchived && !msg.isArchived).map((msg) => this.toModelMessage(msg));
155
+ }
156
+ extractProviderOptions(msg) {
157
+ const options = {};
158
+ const reasoningParts = msg.parts?.filter((p) => p.type === "reasoning");
159
+ if (reasoningParts && reasoningParts.length > 0) {
160
+ const firstReasoning = reasoningParts[0];
161
+ if (firstReasoning.reasoningType) {
162
+ options.openai = {
163
+ thinking: {
164
+ type: firstReasoning.reasoningType === "effort" ? "extended" : "core"
165
+ }
166
+ };
167
+ if (firstReasoning.reasoningType === "effort") {
168
+ const budgetTokens = firstReasoning.metadata?.tokenCount || DEFAULT_REASONING_BUDGET_TOKENS;
169
+ options.anthropic = {
170
+ thinking: {
171
+ type: "enabled",
172
+ budgetTokens
173
+ }
174
+ };
175
+ }
176
+ }
177
+ }
178
+ return options;
179
+ }
180
+ migrateMessage(oldMsg) {
181
+ if (oldMsg.parts && oldMsg.parts.length > 0) {
182
+ const firstPart = oldMsg.parts[0];
183
+ if (firstPart && typeof firstPart.type === "string" && firstPart.type.length > 0) {
184
+ return {
185
+ ...oldMsg,
186
+ content: oldMsg.content || ""
187
+ };
188
+ }
189
+ }
190
+ return {
191
+ ...oldMsg,
192
+ content: oldMsg.content || "",
193
+ parts: oldMsg.content ? [{ type: "text", content: oldMsg.content }] : []
194
+ };
195
+ }
196
+ }
197
+ __legacyDecorateClassTS([
198
+ TracedAs("session-message-converter.toModelMessage", { recordParams: true, recordResult: true, log: true })
199
+ ], SessionMessageConverter.prototype, "toModelMessage", null);
200
+ __legacyDecorateClassTS([
201
+ TracedAs("session-message-converter.fromModelMessage", { recordParams: true, recordResult: true, log: true })
202
+ ], SessionMessageConverter.prototype, "fromModelMessage", null);
203
+
204
+ export { SessionMessageConverter };
@@ -3,10 +3,10 @@ import {
3
3
  init_propagation,
4
4
  init_tracer_provider,
5
5
  propagation
6
- } from "./chunk-q9j99fsm.js";
6
+ } from "./roy-agent-core-fv32jaa8.js";
7
7
  import {
8
8
  __toCommonJS
9
- } from "./chunk-wbkh7wat.js";
9
+ } from "./roy-agent-core-fs0mn2jk.js";
10
10
 
11
11
  // src/env/tool/built-in/bash.ts
12
12
  init_propagation();