@mishri/ai-term 1.0.0

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 (124) hide show
  1. package/README.md +77 -0
  2. package/dist/agent/context/compaction.d.ts +3 -0
  3. package/dist/agent/context/compaction.d.ts.map +1 -0
  4. package/dist/agent/context/compaction.js +39 -0
  5. package/dist/agent/context/compaction.js.map +1 -0
  6. package/dist/agent/context/index.d.ts +7 -0
  7. package/dist/agent/context/index.d.ts.map +1 -0
  8. package/dist/agent/context/index.js +24 -0
  9. package/dist/agent/context/index.js.map +1 -0
  10. package/dist/agent/context/modelLimits.d.ts +7 -0
  11. package/dist/agent/context/modelLimits.d.ts.map +1 -0
  12. package/dist/agent/context/modelLimits.js +31 -0
  13. package/dist/agent/context/modelLimits.js.map +1 -0
  14. package/dist/agent/context/tokenEstimator.d.ts +3 -0
  15. package/dist/agent/context/tokenEstimator.d.ts.map +1 -0
  16. package/dist/agent/context/tokenEstimator.js +28 -0
  17. package/dist/agent/context/tokenEstimator.js.map +1 -0
  18. package/dist/agent/evals/agent-multiturn.eval.d.ts +2 -0
  19. package/dist/agent/evals/agent-multiturn.eval.d.ts.map +1 -0
  20. package/dist/agent/evals/agent-multiturn.eval.js +32 -0
  21. package/dist/agent/evals/agent-multiturn.eval.js.map +1 -0
  22. package/dist/agent/evals/data/agent-multiturn.json +111 -0
  23. package/dist/agent/evals/data/tool-calls.json +28 -0
  24. package/dist/agent/evals/evaluators.d.ts +6 -0
  25. package/dist/agent/evals/evaluators.d.ts.map +1 -0
  26. package/dist/agent/evals/evaluators.js +59 -0
  27. package/dist/agent/evals/evaluators.js.map +1 -0
  28. package/dist/agent/evals/executors.d.ts +31 -0
  29. package/dist/agent/evals/executors.d.ts.map +1 -0
  30. package/dist/agent/evals/executors.js +107 -0
  31. package/dist/agent/evals/executors.js.map +1 -0
  32. package/dist/agent/evals/file-tools.eval.d.ts +2 -0
  33. package/dist/agent/evals/file-tools.eval.d.ts.map +1 -0
  34. package/dist/agent/evals/file-tools.eval.js +27 -0
  35. package/dist/agent/evals/file-tools.eval.js.map +1 -0
  36. package/dist/agent/evals/mocks/tools.d.ts +32 -0
  37. package/dist/agent/evals/mocks/tools.d.ts.map +1 -0
  38. package/dist/agent/evals/mocks/tools.js +58 -0
  39. package/dist/agent/evals/mocks/tools.js.map +1 -0
  40. package/dist/agent/evals/types.d.ts +55 -0
  41. package/dist/agent/evals/types.d.ts.map +1 -0
  42. package/dist/agent/evals/types.js +2 -0
  43. package/dist/agent/evals/types.js.map +1 -0
  44. package/dist/agent/evals/utils.d.ts +4 -0
  45. package/dist/agent/evals/utils.d.ts.map +1 -0
  46. package/dist/agent/evals/utils.js +20 -0
  47. package/dist/agent/evals/utils.js.map +1 -0
  48. package/dist/agent/executeTool.d.ts +42 -0
  49. package/dist/agent/executeTool.d.ts.map +1 -0
  50. package/dist/agent/executeTool.js +14 -0
  51. package/dist/agent/executeTool.js.map +1 -0
  52. package/dist/agent/run.d.ts +4 -0
  53. package/dist/agent/run.d.ts.map +1 -0
  54. package/dist/agent/run.js +134 -0
  55. package/dist/agent/run.js.map +1 -0
  56. package/dist/agent/system/filterMessages.d.ts +3 -0
  57. package/dist/agent/system/filterMessages.d.ts.map +1 -0
  58. package/dist/agent/system/filterMessages.js +25 -0
  59. package/dist/agent/system/filterMessages.js.map +1 -0
  60. package/dist/agent/system/system_prompt.d.ts +2 -0
  61. package/dist/agent/system/system_prompt.d.ts.map +1 -0
  62. package/dist/agent/system/system_prompt.js +8 -0
  63. package/dist/agent/system/system_prompt.js.map +1 -0
  64. package/dist/agent/system_prompt.d.ts +2 -0
  65. package/dist/agent/system_prompt.d.ts.map +1 -0
  66. package/dist/agent/system_prompt.js +8 -0
  67. package/dist/agent/system_prompt.js.map +1 -0
  68. package/dist/agent/tools/execCode.d.ts +5 -0
  69. package/dist/agent/tools/execCode.d.ts.map +1 -0
  70. package/dist/agent/tools/execCode.js +58 -0
  71. package/dist/agent/tools/execCode.js.map +1 -0
  72. package/dist/agent/tools/file.d.ts +29 -0
  73. package/dist/agent/tools/file.d.ts.map +1 -0
  74. package/dist/agent/tools/file.js +92 -0
  75. package/dist/agent/tools/file.js.map +1 -0
  76. package/dist/agent/tools/index.d.ts +44 -0
  77. package/dist/agent/tools/index.d.ts.map +1 -0
  78. package/dist/agent/tools/index.js +14 -0
  79. package/dist/agent/tools/index.js.map +1 -0
  80. package/dist/agent/tools/shell.d.ts +4 -0
  81. package/dist/agent/tools/shell.d.ts.map +1 -0
  82. package/dist/agent/tools/shell.js +30 -0
  83. package/dist/agent/tools/shell.js.map +1 -0
  84. package/dist/agent/tools/websearch.d.ts +22 -0
  85. package/dist/agent/tools/websearch.d.ts.map +1 -0
  86. package/dist/agent/tools/websearch.js +3 -0
  87. package/dist/agent/tools/websearch.js.map +1 -0
  88. package/dist/agent/type.d.ts +27 -0
  89. package/dist/agent/type.d.ts.map +1 -0
  90. package/dist/agent/type.js +2 -0
  91. package/dist/agent/type.js.map +1 -0
  92. package/dist/config.d.ts +4 -0
  93. package/dist/config.d.ts.map +1 -0
  94. package/dist/config.js +6 -0
  95. package/dist/config.js.map +1 -0
  96. package/dist/index.d.ts +3 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +12 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/ui/App.d.ts +2 -0
  101. package/dist/ui/App.d.ts.map +1 -0
  102. package/dist/ui/App.js +89 -0
  103. package/dist/ui/App.js.map +1 -0
  104. package/dist/ui/components/Input.d.ts +7 -0
  105. package/dist/ui/components/Input.d.ts.map +1 -0
  106. package/dist/ui/components/Input.js +26 -0
  107. package/dist/ui/components/Input.js.map +1 -0
  108. package/dist/ui/components/MessageList.d.ts +10 -0
  109. package/dist/ui/components/MessageList.d.ts.map +1 -0
  110. package/dist/ui/components/MessageList.js +7 -0
  111. package/dist/ui/components/MessageList.js.map +1 -0
  112. package/dist/ui/components/TokenUsage.d.ts +8 -0
  113. package/dist/ui/components/TokenUsage.d.ts.map +1 -0
  114. package/dist/ui/components/TokenUsage.js +20 -0
  115. package/dist/ui/components/TokenUsage.js.map +1 -0
  116. package/dist/ui/components/ToolApproval.d.ts +6 -0
  117. package/dist/ui/components/ToolApproval.d.ts.map +1 -0
  118. package/dist/ui/components/ToolApproval.js +19 -0
  119. package/dist/ui/components/ToolApproval.js.map +1 -0
  120. package/dist/ui/components/ToolCall.d.ts +8 -0
  121. package/dist/ui/components/ToolCall.d.ts.map +1 -0
  122. package/dist/ui/components/ToolCall.js +13 -0
  123. package/dist/ui/components/ToolCall.js.map +1 -0
  124. package/package.json +58 -0
@@ -0,0 +1,107 @@
1
+ import { generateText, stepCountIs } from "ai";
2
+ import { SYSTEM_PROMPT } from "../system/system_prompt.js";
3
+ import z from "zod";
4
+ import { tool } from "ai";
5
+ import { createGoogleGenerativeAI } from "@ai-sdk/google";
6
+ import { GEMINI_API_KEY, OPENAI_API_KEY } from "../../config.js";
7
+ import { createOpenAI } from "@ai-sdk/openai";
8
+ import { buildMockedTools } from "./utils.js";
9
+ const openai = createOpenAI({ apiKey: OPENAI_API_KEY });
10
+ const google = createGoogleGenerativeAI({ apiKey: GEMINI_API_KEY });
11
+ export const TOOL_DEFINITIONS = {
12
+ readFile: {
13
+ description: "Read the contents of a file.",
14
+ inputSchema: z.object({
15
+ path: z.string().describe("The path of the file to be read.")
16
+ })
17
+ },
18
+ writeFile: {
19
+ description: "Write content to a file.",
20
+ inputSchema: z.object({
21
+ path: z.string().describe("The path of the file to write to."),
22
+ content: z.string().describe("Content to write")
23
+ })
24
+ },
25
+ listFiles: {
26
+ description: "List all the files and directories in a directory",
27
+ inputSchema: z.object({
28
+ directory: z.string().describe("Directory for which listing has to be done")
29
+ })
30
+ },
31
+ deleteFile: {
32
+ description: "Remove a file",
33
+ inputSchema: z.object({
34
+ path: z.string().describe("Path of the filt to delete")
35
+ })
36
+ }
37
+ };
38
+ export const singleTurnWithMocks = async (data) => {
39
+ const messages = [{
40
+ role: "user", content: data.prompt
41
+ }];
42
+ const tools = {};
43
+ for (const toolName of data.tools) {
44
+ const def = TOOL_DEFINITIONS[toolName];
45
+ if (def) {
46
+ tools[toolName] = tool({ description: def.description, inputSchema: def.inputSchema });
47
+ }
48
+ }
49
+ const result = await generateText({
50
+ model: google("gemini-3.5-flash"),
51
+ // model: openai("gpt-5-mini"),
52
+ system: SYSTEM_PROMPT,
53
+ tools,
54
+ messages,
55
+ stopWhen: stepCountIs(1)
56
+ });
57
+ const toolCalls = (result.toolCalls ?? []).map((tc) => ({ toolName: tc.toolName, args: "input" in tc ? tc.input : {} }));
58
+ const toolNames = toolCalls.map((tc) => tc.toolName);
59
+ return {
60
+ toolCalls,
61
+ toolNames,
62
+ selectedAny: toolCalls.length > 0
63
+ };
64
+ };
65
+ export const multiturnWithMocks = async (data) => {
66
+ const mockedTools = buildMockedTools(data.mockTools);
67
+ const messages = data.messages ?? [
68
+ {
69
+ role: "user", content: data.prompt
70
+ }
71
+ ];
72
+ const result = await generateText({
73
+ // model: google("gemini-3.5-flash"),
74
+ model: openai("gpt-5-mini"),
75
+ system: SYSTEM_PROMPT,
76
+ tools: mockedTools,
77
+ messages,
78
+ stopWhen: stepCountIs(data.config?.maxSteps ?? 5)
79
+ });
80
+ const allToolCalls = [];
81
+ const steps = result.steps.map((step) => {
82
+ const stepToolCalls = (step.toolCalls ?? []).map((tc) => {
83
+ allToolCalls.push(tc.toolName);
84
+ return {
85
+ toolName: tc.toolName,
86
+ args: "input" in tc ? tc.input : {}
87
+ };
88
+ });
89
+ const stepToolResults = (step.toolResults ?? []).map((tr) => ({
90
+ toolName: tr.toolName,
91
+ result: "result" in tr ? tr.result : tr
92
+ }));
93
+ return {
94
+ toolCalls: stepToolCalls.length > 0 ? stepToolCalls : undefined,
95
+ toolResults: stepToolResults.length > 0 ? stepToolResults : undefined,
96
+ text: step.text || undefined
97
+ };
98
+ });
99
+ const toolsUsed = [...new Set(allToolCalls)];
100
+ return {
101
+ text: result.text,
102
+ steps,
103
+ toolsUsed,
104
+ toolCallOrder: allToolCalls
105
+ };
106
+ };
107
+ //# sourceMappingURL=executors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executors.js","sourceRoot":"","sources":["../../../src/agent/evals/executors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAmC,MAAM,IAAI,CAAC;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAA;AACvD,MAAM,MAAM,GAAG,wBAAwB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAA;AAEnE,MAAM,CAAC,MAAM,gBAAgB,GAC7B;IACI,QAAQ,EAAE;QACN,WAAW,EAAE,8BAA8B;QAC3C,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;SAChE,CAAC;KACL;IACD,SAAS,EAAE;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;YAC9D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC;SACnD,CAAC;KACL;IACD,SAAS,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AAQ;gBACrB,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;aACtC,CAAA;QACL,CAAC,CAAC,CAAA;QAEF,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1D,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;SAC1C,CAAC,CAAC,CAAA;QAEH,OAAO;YACH,SAAS,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;YAC/D,WAAW,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;YACrE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,SAAS;SAC/B,CAAA;IACL,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;IAG5C,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK;QACL,SAAS;QACT,aAAa,EAAE,YAAY;KAC9B,CAAA;AACL,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=file-tools.eval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-tools.eval.d.ts","sourceRoot":"","sources":["../../../src/agent/evals/file-tools.eval.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ import { evaluate } from "@lmnr-ai/lmnr";
2
+ import dataset from "./data/tool-calls.json" with { type: "json" };
3
+ import { LMNR_PROJECT_API_KEY } from "../../config.js";
4
+ import { singleTurnWithMocks } from "./executors.js";
5
+ import { toolsAvoided, toolsSelected } from "./evaluators.js";
6
+ const executor = async (data) => {
7
+ return await singleTurnWithMocks(data);
8
+ };
9
+ evaluate({
10
+ data: dataset,
11
+ executor,
12
+ evaluators: {
13
+ toolsSelected: (output, target) => {
14
+ if (!target)
15
+ return 1;
16
+ return toolsSelected(output, target);
17
+ },
18
+ toolsAvoided: (output, target) => {
19
+ if (!target)
20
+ return 1;
21
+ return toolsAvoided(output, target);
22
+ }
23
+ },
24
+ config: { projectApiKey: LMNR_PROJECT_API_KEY },
25
+ groupName: "file-tool-selection"
26
+ });
27
+ //# sourceMappingURL=file-tools.eval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-tools.eval.js","sourceRoot":"","sources":["../../../src/agent/evals/file-tools.eval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,OAAO,MAAM,wBAAwB,CAAC,OAAM,IAAI,EAAE,MAAM,EAAC,CAAA;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE9D,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAc,EAAE,EAAE;IACtC,OAAO,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,QAAQ,CAAC;IACL,IAAI,EAAE,OAAwD;IAC9D,QAAQ;IACR,UAAU,EAAE;QACR,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YAC9B,IAAI,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAA;YACrB,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,CAAC;QACD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YAC7B,IAAI,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAA;YACrB,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACvC,CAAC;KACJ;IACD,MAAM,EAAE,EAAE,aAAa,EAAE,oBAAoB,EAAE;IAC/C,SAAS,EAAE,qBAAqB;CACnC,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Create a mock readFile tool that returns fixed content
3
+ */
4
+ export declare const createMockReadFile: (mockContent: string) => import("ai").Tool<{
5
+ path: string;
6
+ }, string>;
7
+ /**
8
+ * Create a mock writeFile tool that returns a success message
9
+ */
10
+ export declare const createMockWriteFile: (mockResponse?: string) => import("ai").Tool<{
11
+ path: string;
12
+ content: string;
13
+ }, string>;
14
+ /**
15
+ * Create a mock listFiles tool that returns a fixed file list
16
+ */
17
+ export declare const createMockListFiles: (mockFiles: string[]) => import("ai").Tool<{
18
+ directory: string;
19
+ }, string>;
20
+ /**
21
+ * Create a mock deleteFile tool that returns a success message
22
+ */
23
+ export declare const createMockDeleteFile: (mockResponse?: string) => import("ai").Tool<{
24
+ path: string;
25
+ }, string>;
26
+ /**
27
+ * Create a mock shell command tool that returns fixed output
28
+ */
29
+ export declare const createMockShell: (mockOutput: string) => import("ai").Tool<{
30
+ command: string;
31
+ }, string>;
32
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../../src/agent/evals/mocks/tools.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM;;UAQhD,CAAC;AAEP;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,eAAe,MAAM;;;UAWnD,CAAC;AAEP;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,EAAE;;UAYjD,CAAC;AAEP;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,eAAe,MAAM;;UASpD,CAAC;AAEP;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM;;UAQ5C,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { tool } from "ai";
2
+ import { z } from "zod";
3
+ /**
4
+ * Create a mock readFile tool that returns fixed content
5
+ */
6
+ export const createMockReadFile = (mockContent) => tool({
7
+ description: "Read the contents of a file at the specified path. Use this to examine file contents.",
8
+ inputSchema: z.object({
9
+ path: z.string().describe("The path to the file to read"),
10
+ }),
11
+ execute: async ({ path }) => mockContent,
12
+ });
13
+ /**
14
+ * Create a mock writeFile tool that returns a success message
15
+ */
16
+ export const createMockWriteFile = (mockResponse) => tool({
17
+ description: "Write content to a file at the specified path. Creates the file if it doesn't exist.",
18
+ inputSchema: z.object({
19
+ path: z.string().describe("The path to the file to write"),
20
+ content: z.string().describe("The content to write to the file"),
21
+ }),
22
+ execute: async ({ path, content }) => mockResponse ??
23
+ `Successfully wrote ${content.length} characters to ${path}`,
24
+ });
25
+ /**
26
+ * Create a mock listFiles tool that returns a fixed file list
27
+ */
28
+ export const createMockListFiles = (mockFiles) => tool({
29
+ description: "List all files and directories in the specified directory path.",
30
+ inputSchema: z.object({
31
+ directory: z
32
+ .string()
33
+ .describe("The directory path to list contents of")
34
+ .default("."),
35
+ }),
36
+ execute: async ({ directory }) => mockFiles.join("\n"),
37
+ });
38
+ /**
39
+ * Create a mock deleteFile tool that returns a success message
40
+ */
41
+ export const createMockDeleteFile = (mockResponse) => tool({
42
+ description: "Delete a file at the specified path. Use with caution as this is irreversible.",
43
+ inputSchema: z.object({
44
+ path: z.string().describe("The path to the file to delete"),
45
+ }),
46
+ execute: async ({ path }) => mockResponse ?? `Successfully deleted ${path}`,
47
+ });
48
+ /**
49
+ * Create a mock shell command tool that returns fixed output
50
+ */
51
+ export const createMockShell = (mockOutput) => tool({
52
+ description: "Execute a shell command and return its output. Use this for system operations.",
53
+ inputSchema: z.object({
54
+ command: z.string().describe("The shell command to execute"),
55
+ }),
56
+ execute: async ({ command }) => mockOutput,
57
+ });
58
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../../src/agent/evals/mocks/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,WAAmB,EAAE,EAAE,CACtD,IAAI,CAAC;IACD,WAAW,EACP,uFAAuF;IAC3F,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;KAC5D,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAoB,EAAE,EAAE,CAAC,WAAW;CAC7D,CAAC,CAAC;AAEP;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,YAAqB,EAAE,EAAE,CACzD,IAAI,CAAC;IACD,WAAW,EACP,sFAAsF;IAC1F,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QAC1D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;KACnE,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAqC,EAAE,EAAE,CACpE,YAAY;QACZ,sBAAsB,OAAO,CAAC,MAAM,kBAAkB,IAAI,EAAE;CACnE,CAAC,CAAC;AAEP;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAmB,EAAE,EAAE,CACvD,IAAI,CAAC;IACD,WAAW,EACP,iEAAiE;IACrE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,SAAS,EAAE,CAAC;aACP,MAAM,EAAE;aACR,QAAQ,CAAC,wCAAwC,CAAC;aAClD,OAAO,CAAC,GAAG,CAAC;KACpB,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,SAAS,EAAyB,EAAE,EAAE,CACpD,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;CAC3B,CAAC,CAAC;AAEP;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAqB,EAAE,EAAE,CAC1D,IAAI,CAAC;IACD,WAAW,EACP,gFAAgF;IACpF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;KAC9D,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAoB,EAAE,EAAE,CAC1C,YAAY,IAAI,wBAAwB,IAAI,EAAE;CACrD,CAAC,CAAC;AAEP;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAE,EAAE,CAClD,IAAI,CAAC;IACD,WAAW,EACP,gFAAgF;IACpF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;KAC/D,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAuB,EAAE,EAAE,CAAC,UAAU;CAClE,CAAC,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { ModelMessage } from "ai";
2
+ export interface EvalData {
3
+ prompt: string;
4
+ tools: string[];
5
+ }
6
+ export interface MockTool {
7
+ description: string;
8
+ parameters: Record<string, any>;
9
+ mockReturn?: string;
10
+ }
11
+ export interface MultiturnEvalData {
12
+ prompt?: string;
13
+ messages?: ModelMessage[];
14
+ mockTools: Record<string, MockTool>;
15
+ config?: {
16
+ maxSteps: number;
17
+ };
18
+ }
19
+ export interface EvalTarget {
20
+ forbiddenTools?: string[];
21
+ expectedTools?: string[];
22
+ category: "golden" | "secondary" | "negative";
23
+ }
24
+ export interface MultiturnEvalTarget {
25
+ originalTask: string;
26
+ expectedToolOrder?: string[];
27
+ forbiddenTools?: string[];
28
+ mockToolResults: Record<string, string>;
29
+ category: "task-completion" | "conversation-continuation" | "negative";
30
+ }
31
+ export interface SingleTurnRes {
32
+ toolCalls: {
33
+ toolName: string;
34
+ args: unknown;
35
+ }[];
36
+ toolNames: string[];
37
+ selectedAny: boolean;
38
+ }
39
+ export interface MultiturnRes {
40
+ text: string;
41
+ steps: {
42
+ toolCalls: {
43
+ toolName: string;
44
+ args: unknown;
45
+ }[] | undefined;
46
+ toolResults: {
47
+ toolName: string;
48
+ result: unknown;
49
+ }[] | undefined;
50
+ text: string | undefined;
51
+ }[];
52
+ toolCallOrder: string[];
53
+ toolsUsed: string[];
54
+ }
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/agent/evals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAEtC,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,QAAQ;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAA;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE;QACL,QAAQ,EAAE,MAAM,CAAA;KACnB,CAAA;CACJ;AAED,MAAM,WAAW,UAAU;IACvB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;CAChD;AACD,MAAM,WAAW,mBAAmB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,QAAQ,EAAE,iBAAiB,GAAG,2BAA2B,GAAG,UAAU,CAAA;CACzE;AAID,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IACjD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QACH,SAAS,EAAE;YACP,QAAQ,EAAE,MAAM,CAAC;YACjB,IAAI,EAAE,OAAO,CAAC;SACjB,EAAE,GAAG,SAAS,CAAC;QAChB,WAAW,EAAE;YACT,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,EAAE,OAAO,CAAC;SACnB,EAAE,GAAG,SAAS,CAAC;QAChB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;IACJ,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAA;CACtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agent/evals/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { type ToolSet } from "ai";
2
+ import type { MockTool } from "./types.js";
3
+ export declare function buildMockedTools(mockTools: Record<string, MockTool>): ToolSet;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/evals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,WAkBnE"}
@@ -0,0 +1,20 @@
1
+ import { tool } from "ai";
2
+ import z from "zod";
3
+ export function buildMockedTools(mockTools) {
4
+ const tools = {};
5
+ for (const [key, value] of Object.entries(mockTools)) {
6
+ const paramSchema = {};
7
+ for (const [paramName, _] of Object.entries(value.parameters)) {
8
+ paramSchema[paramName] = z.string();
9
+ }
10
+ tools[key] = tool({
11
+ description: value.description,
12
+ inputSchema: z.object(paramSchema),
13
+ execute: async () => {
14
+ return value.mockReturn;
15
+ }
16
+ });
17
+ }
18
+ return tools;
19
+ }
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/agent/evals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,IAAI,CAAC;AAExC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,UAAU,gBAAgB,CAAC,SAAmC;IAEhE,MAAM,KAAK,GAAY,EAAE,CAAA;IAEzB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACnD,MAAM,WAAW,GAAgC,EAAE,CAAA;QACnD,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5D,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAA;QACvC,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACd,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;YAClC,OAAO,EAAE,KAAK,IAAI,EAAE;gBAChB,OAAO,KAAK,CAAC,UAAU,CAAA;YAC3B,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC"}
@@ -0,0 +1,42 @@
1
+ export declare function executeTool(toolName: string, args: unknown, toolCallId: string): Promise<string | AsyncIterable<string> | {
2
+ action?: {
3
+ type: "search";
4
+ query?: string;
5
+ queries?: string[];
6
+ } | {
7
+ type: "openPage";
8
+ url?: string | null;
9
+ } | {
10
+ type: "findInPage";
11
+ url?: string | null;
12
+ pattern?: string | null;
13
+ };
14
+ sources?: Array<{
15
+ type: "url";
16
+ url: string;
17
+ } | {
18
+ type: "api";
19
+ name: string;
20
+ }>;
21
+ } | AsyncIterable<{
22
+ action?: {
23
+ type: "search";
24
+ query?: string;
25
+ queries?: string[];
26
+ } | {
27
+ type: "openPage";
28
+ url?: string | null;
29
+ } | {
30
+ type: "findInPage";
31
+ url?: string | null;
32
+ pattern?: string | null;
33
+ };
34
+ sources?: Array<{
35
+ type: "url";
36
+ url: string;
37
+ } | {
38
+ type: "api";
39
+ name: string;
40
+ }>;
41
+ }>>;
42
+ //# sourceMappingURL=executeTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeTool.d.ts","sourceRoot":"","sources":["../../src/agent/executeTool.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM;;;aAc0z9B,CAAC;eAA6B,CAAC;;;WAAuE,CAAC;;;WAA8E,CAAC;eAAoC,CAAC;;;;;;;;;;;;aAA3N,CAAC;eAA6B,CAAC;;;WAAuE,CAAC;;;WAA8E,CAAC;eAAoC,CAAC;;;;;;;;;IAAzm+B"}
@@ -0,0 +1,14 @@
1
+ import { tools } from "./tools/index.js";
2
+ export async function executeTool(toolName, args, toolCallId) {
3
+ const tool = tools[toolName];
4
+ if (!tool) {
5
+ return `Unknown Tool:${toolName}`;
6
+ }
7
+ const execute = tool.execute;
8
+ if (!execute) {
9
+ return `Provider tool ${toolName}- executed by model provider`;
10
+ }
11
+ const result = await execute(args, { toolCallId, messages: [] });
12
+ return result;
13
+ }
14
+ //# sourceMappingURL=executeTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeTool.js","sourceRoot":"","sources":["../../src/agent/executeTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAgB,EAAE,IAAa,EAAE,UAAkB;IACjF,MAAM,IAAI,GAAG,KAAK,CAAC,QAA8B,CAAC,CAAA;IAElD,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,gBAAgB,QAAQ,EAAE,CAAA;IACrC,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;IAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,OAAO,iBAAiB,QAAQ,8BAA8B,CAAA;IAClE,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAa,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAA;IACzE,OAAO,MAAM,CAAA;AACjB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ModelMessage } from "ai";
2
+ import type { AgentCallbacks } from "./type.js";
3
+ export declare function runAgent(userMessage: string, conversationHistory: ModelMessage[], callbacks: AgentCallbacks): Promise<ModelMessage[]>;
4
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/agent/run.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAahD,wBAAsB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,cAAc,2BAiJjH"}
@@ -0,0 +1,134 @@
1
+ import { openai } from "@ai-sdk/openai";
2
+ import { LMNR_PROJECT_API_KEY } from "../config.js";
3
+ import { getTracer, Laminar } from "@lmnr-ai/lmnr";
4
+ import { streamText } from "ai";
5
+ import { SYSTEM_PROMPT } from "./system/system_prompt.js";
6
+ import { tools } from "./tools/index.js";
7
+ import { executeTool } from "./executeTool.js";
8
+ import { filterMessages } from "./system/filterMessages.js";
9
+ import { estimateMessagesTokens } from "./context/index.js";
10
+ import { calculateUsagePercentage, DEFAULT_THRESHOLD, getModelLimits, isOverThreshold } from "./context/modelLimits.js";
11
+ import { compactConversation } from "./context/compaction.js";
12
+ Laminar.initialize({ projectApiKey: LMNR_PROJECT_API_KEY });
13
+ const MODEL_NAME = "gpt-5-mini";
14
+ export async function runAgent(userMessage, conversationHistory, callbacks) {
15
+ const limits = getModelLimits(MODEL_NAME);
16
+ let workingHistory = filterMessages(conversationHistory);
17
+ const tokens = estimateMessagesTokens([
18
+ { role: "system", content: SYSTEM_PROMPT },
19
+ ...workingHistory,
20
+ { role: "user", content: userMessage }
21
+ ]);
22
+ let messages = [];
23
+ if (isOverThreshold(tokens.total, limits.contextWindow)) {
24
+ workingHistory = await compactConversation(workingHistory);
25
+ messages = [
26
+ ...workingHistory,
27
+ { role: "user", content: userMessage }
28
+ ];
29
+ }
30
+ messages = [
31
+ ...conversationHistory,
32
+ { role: "user", content: userMessage }
33
+ ];
34
+ let fullResponse = "";
35
+ const reportTokenUsage = () => {
36
+ const { input, output, total } = estimateMessagesTokens(messages);
37
+ callbacks.onTokenUsage({
38
+ inputTokens: input,
39
+ outputTokens: output,
40
+ totalTokens: total,
41
+ contextWindow: limits.contextWindow,
42
+ threshold: DEFAULT_THRESHOLD,
43
+ percentage: calculateUsagePercentage(total, limits.contextWindow)
44
+ });
45
+ };
46
+ reportTokenUsage();
47
+ while (true) {
48
+ const result = streamText({
49
+ //model: google("gemini-2.5-flash"),
50
+ model: openai(MODEL_NAME),
51
+ system: SYSTEM_PROMPT,
52
+ tools,
53
+ messages,
54
+ experimental_telemetry: {
55
+ isEnabled: true,
56
+ tracer: getTracer()
57
+ }
58
+ });
59
+ // need this to call execute the toolCalls
60
+ const toolCalls = [];
61
+ // to store the text of loop of stream
62
+ let currentText = "";
63
+ let streamError = null;
64
+ try {
65
+ for await (const chunk of result.fullStream) {
66
+ if (chunk.type === "text-delta") {
67
+ currentText += chunk.text;
68
+ callbacks.onToken(chunk.text);
69
+ }
70
+ if (chunk.type === "tool-call") {
71
+ const input = chunk?.input ?? {};
72
+ toolCalls.push({
73
+ toolCallId: chunk.toolCallId,
74
+ toolName: chunk.toolName,
75
+ input
76
+ });
77
+ callbacks.onToolCallStart(chunk.toolName, chunk.toolCallId, input);
78
+ }
79
+ }
80
+ }
81
+ catch (error) {
82
+ streamError = error;
83
+ // no text + real unknown error -> throw error
84
+ if (!currentText && !streamError.message.includes("No output generated")) {
85
+ throw streamError;
86
+ }
87
+ }
88
+ fullResponse += currentText;
89
+ //no text + "No output generated" -> let the user know
90
+ if (streamError && !currentText) {
91
+ fullResponse = "I apologize, but I wasn't able to generate a response. Could you please try rephrasing your message?";
92
+ callbacks.onToken(fullResponse);
93
+ break;
94
+ }
95
+ const responseMessages = await result.response;
96
+ messages.push(...responseMessages.messages);
97
+ const finishReason = await result.finishReason;
98
+ if (finishReason !== "tool-calls" || toolCalls.length === 0) {
99
+ reportTokenUsage();
100
+ break;
101
+ }
102
+ //tool-call execution after the fullStream loop
103
+ //Expected sequence of messages array : user -> assistant -> tool
104
+ let rejected = false;
105
+ for (const tc of toolCalls) {
106
+ if (tc.toolName === "shellCommand" || tc.toolName === "execCode") {
107
+ const approved = await callbacks.onToolApproval(tc.toolName, tc.input);
108
+ if (!approved) {
109
+ rejected = true;
110
+ break;
111
+ }
112
+ }
113
+ const result = await executeTool(tc.toolName, tc.input, tc.toolCallId);
114
+ callbacks.onToolCallEnd(tc.toolName, result);
115
+ messages.push({
116
+ role: "tool", content: [
117
+ {
118
+ type: "tool-result",
119
+ toolCallId: tc.toolCallId,
120
+ toolName: tc.toolName,
121
+ output: { type: "text", value: result }
122
+ }
123
+ ]
124
+ });
125
+ reportTokenUsage();
126
+ }
127
+ if (rejected) {
128
+ break;
129
+ }
130
+ }
131
+ callbacks.onComplete(fullResponse);
132
+ return messages;
133
+ }
134
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/agent/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAqB,MAAM,IAAI,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACxH,OAAO,EAAE,mBA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AE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAW,CAAA;YAChF,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC5C,QAAQ,CAAC,IAAI,CACT;gBACI,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;oBACnB;wBACI,IAAI,EAAE,aAAa;wBACnB,UAAU,EAAE,EAAE,CAAC,UAAU;wBACzB,QAAQ,EAAE,EAAE,CAAC,QAAQ;wBACrB,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;qBAC1C;iBACJ;aACJ,CACJ,CAAA;YACD,gBAAgB,EAAE,CAAA;QACtB,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACX,MAAK;QACT,CAAC;IACL,CAAC;IAED,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;IAClC,OAAO,QAAQ,CAAA;AACnB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ModelMessage } from "ai";
2
+ export declare function filterMessages(messages: ModelMessage[]): ModelMessage[];
3
+ //# sourceMappingURL=filterMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterMessages.d.ts","sourceRoot":"","sources":["../../../src/agent/system/filterMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAEvC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,EAAE,kBA6BtD"}
@@ -0,0 +1,25 @@
1
+ export function filterMessages(messages) {
2
+ return messages.filter((msg) => {
3
+ if (msg.role === "user" || msg.role === "system" || msg.role === "tool")
4
+ return true;
5
+ else if (msg.role === "assistant") {
6
+ const content = msg.content;
7
+ if (typeof content === "string" && content.trim()) {
8
+ return true;
9
+ }
10
+ if (Array.isArray(content)) {
11
+ const hasTextContent = content.some((part) => {
12
+ if (typeof part === "string" && part.trim())
13
+ return true;
14
+ if (typeof part === "object" && part !== null && "text" in part && typeof part.text === "string" && part.text.trim()) {
15
+ return true;
16
+ }
17
+ return false;
18
+ });
19
+ return hasTextContent;
20
+ }
21
+ }
22
+ return false;
23
+ });
24
+ }
25
+ //# sourceMappingURL=filterMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterMessages.js","sourceRoot":"","sources":["../../../src/agent/system/filterMessages.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,QAAwB;IAEnD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QAE3B,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,IAAI,CAAA;aAG/E,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;YAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAA;YACf,CAAC;YAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzB,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAa,EAAE,EAAE;oBAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE;wBAAE,OAAO,IAAI,CAAA;oBACxD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;wBACnH,OAAO,IAAI,CAAA;oBACf,CAAC;oBACD,OAAO,KAAK,CAAA;gBAChB,CAAC,CAAC,CAAA;gBACF,OAAO,cAAc,CAAA;YACzB,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAA;IAEhB,CAAC,CAAC,CAAA;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const SYSTEM_PROMPT = "You are a helpful AI assistant. You provide clear, accurate, and concise responses to user questions.\n\nGuidelines:\n- Be direct and helpful\n- If you don't know something, say so honestly\n- Provide explanations when they add value\n- Stay focused on the user's actual question";
2
+ //# sourceMappingURL=system_prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system_prompt.d.ts","sourceRoot":"","sources":["../../../src/agent/system/system_prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,4RAMmB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export const SYSTEM_PROMPT = `You are a helpful AI assistant. You provide clear, accurate, and concise responses to user questions.
2
+
3
+ Guidelines:
4
+ - Be direct and helpful
5
+ - If you don't know something, say so honestly
6
+ - Provide explanations when they add value
7
+ - Stay focused on the user's actual question`;
8
+ //# sourceMappingURL=system_prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system_prompt.js","sourceRoot":"","sources":["../../../src/agent/system/system_prompt.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;6CAMgB,CAAC"}