@sensigo/realm-cli 0.1.0 → 0.2.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 (72) hide show
  1. package/dist/agent/providers/agent-utils.d.ts +2 -2
  2. package/dist/agent/providers/agent-utils.d.ts.map +1 -1
  3. package/dist/agent/providers/agent-utils.js +7 -4
  4. package/dist/agent/providers/agent-utils.js.map +1 -1
  5. package/dist/agent/providers/anthropic-provider.d.ts +3 -1
  6. package/dist/agent/providers/anthropic-provider.d.ts.map +1 -1
  7. package/dist/agent/providers/anthropic-provider.js +15 -4
  8. package/dist/agent/providers/anthropic-provider.js.map +1 -1
  9. package/dist/agent/providers/llm-provider.d.ts +3 -1
  10. package/dist/agent/providers/llm-provider.d.ts.map +1 -1
  11. package/dist/agent/providers/llm-provider.js.map +1 -1
  12. package/dist/agent/providers/openai-provider.d.ts +3 -1
  13. package/dist/agent/providers/openai-provider.d.ts.map +1 -1
  14. package/dist/agent/providers/openai-provider.js +18 -4
  15. package/dist/agent/providers/openai-provider.js.map +1 -1
  16. package/dist/agent/providers/openai-reasoning-provider.d.ts +1 -1
  17. package/dist/agent/providers/openai-reasoning-provider.d.ts.map +1 -1
  18. package/dist/agent/providers/openai-reasoning-provider.js +2 -2
  19. package/dist/agent/providers/openai-reasoning-provider.js.map +1 -1
  20. package/dist/agent/run-agent.d.ts.map +1 -1
  21. package/dist/agent/run-agent.js +29 -2
  22. package/dist/agent/run-agent.js.map +1 -1
  23. package/dist/index.js +1 -1
  24. package/package.json +4 -4
  25. package/dist/agent/agent-utils.d.ts +0 -27
  26. package/dist/agent/agent-utils.d.ts.map +0 -1
  27. package/dist/agent/agent-utils.js +0 -79
  28. package/dist/agent/agent-utils.js.map +0 -1
  29. package/dist/agent/anthropic-provider.d.ts +0 -23
  30. package/dist/agent/anthropic-provider.d.ts.map +0 -1
  31. package/dist/agent/anthropic-provider.js +0 -245
  32. package/dist/agent/anthropic-provider.js.map +0 -1
  33. package/dist/agent/gate-intent-interpreter.d.ts +0 -29
  34. package/dist/agent/gate-intent-interpreter.d.ts.map +0 -1
  35. package/dist/agent/gate-intent-interpreter.js +0 -33
  36. package/dist/agent/gate-intent-interpreter.js.map +0 -1
  37. package/dist/agent/llm-provider.d.ts +0 -46
  38. package/dist/agent/llm-provider.d.ts.map +0 -1
  39. package/dist/agent/llm-provider.js +0 -55
  40. package/dist/agent/llm-provider.js.map +0 -1
  41. package/dist/agent/mcp-client.d.ts +0 -18
  42. package/dist/agent/mcp-client.d.ts.map +0 -1
  43. package/dist/agent/mcp-client.js +0 -108
  44. package/dist/agent/mcp-client.js.map +0 -1
  45. package/dist/agent/mcp-types.d.ts +0 -40
  46. package/dist/agent/mcp-types.d.ts.map +0 -1
  47. package/dist/agent/mcp-types.js +0 -2
  48. package/dist/agent/mcp-types.js.map +0 -1
  49. package/dist/agent/openai-provider.d.ts +0 -30
  50. package/dist/agent/openai-provider.d.ts.map +0 -1
  51. package/dist/agent/openai-provider.js +0 -253
  52. package/dist/agent/openai-provider.js.map +0 -1
  53. package/dist/agent/openai-reasoning-provider.d.ts +0 -18
  54. package/dist/agent/openai-reasoning-provider.d.ts.map +0 -1
  55. package/dist/agent/openai-reasoning-provider.js +0 -76
  56. package/dist/agent/openai-reasoning-provider.js.map +0 -1
  57. package/dist/agent/slack-gate-notifier.d.ts +0 -80
  58. package/dist/agent/slack-gate-notifier.d.ts.map +0 -1
  59. package/dist/agent/slack-gate-notifier.js +0 -315
  60. package/dist/agent/slack-gate-notifier.js.map +0 -1
  61. package/dist/agent/slack-gate-poller.d.ts +0 -28
  62. package/dist/agent/slack-gate-poller.d.ts.map +0 -1
  63. package/dist/agent/slack-gate-poller.js +0 -66
  64. package/dist/agent/slack-gate-poller.js.map +0 -1
  65. package/dist/agent/slack-gate-server.d.ts +0 -30
  66. package/dist/agent/slack-gate-server.d.ts.map +0 -1
  67. package/dist/agent/slack-gate-server.js +0 -99
  68. package/dist/agent/slack-gate-server.js.map +0 -1
  69. package/dist/agent/slack-socket-client.d.ts +0 -20
  70. package/dist/agent/slack-socket-client.d.ts.map +0 -1
  71. package/dist/agent/slack-socket-client.js +0 -141
  72. package/dist/agent/slack-socket-client.js.map +0 -1
@@ -1,108 +0,0 @@
1
- // mcp-client.ts — Manages stdio MCP server subprocess lifecycles.
2
- // This is the only file in the codebase that imports @modelcontextprotocol/sdk directly.
3
- import { Client } from '@modelcontextprotocol/sdk/client';
4
- import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
5
- import { WorkflowError } from '@sensigo/realm';
6
- export class McpClient {
7
- _servers;
8
- _clients = new Map();
9
- constructor(servers, signal) {
10
- this._servers = new Map(servers.map((s) => [s.id, s]));
11
- if (signal) {
12
- // Register unconditionally — a signal that fires before first connect must still trigger cleanup.
13
- signal.addEventListener('abort', () => {
14
- void this.disconnect();
15
- }, { once: true });
16
- }
17
- }
18
- /**
19
- * Creates and connects an SDK Client for the given config.
20
- * Override in tests to inject an in-process transport and avoid spawning real subprocesses.
21
- */
22
- async _createClient(config, expandedEnv) {
23
- const params = {
24
- command: config.command ?? '',
25
- ...(config.args !== undefined ? { args: config.args } : {}),
26
- ...(Object.keys(expandedEnv).length > 0 ? { env: expandedEnv } : {}),
27
- };
28
- const transport = new StdioClientTransport(params);
29
- const client = new Client({ name: 'realm-agent', version: '0.1.0' });
30
- try {
31
- await client.connect(transport);
32
- }
33
- catch (e) {
34
- throw new WorkflowError(`MCP server '${config.id}': connection failed: ${String(e)}`, {
35
- code: 'MCP_CONNECTION_FAILED',
36
- category: 'ENGINE',
37
- agentAction: 'stop',
38
- retryable: false,
39
- });
40
- }
41
- return client;
42
- }
43
- async connect(serverId) {
44
- if (this._clients.has(serverId))
45
- return;
46
- const config = this._servers.get(serverId);
47
- if (!config) {
48
- throw new WorkflowError(`MCP server '${serverId}' is not configured`, {
49
- code: 'MCP_CONNECTION_FAILED',
50
- category: 'ENGINE',
51
- agentAction: 'stop',
52
- retryable: false,
53
- });
54
- }
55
- const expandedEnv = this._expandEnv(serverId, config);
56
- const client = await this._createClient(config, expandedEnv);
57
- // Idempotency check after await — guards against concurrent connect() calls.
58
- if (!this._clients.has(serverId)) {
59
- this._clients.set(serverId, client);
60
- }
61
- else {
62
- void client.close();
63
- }
64
- }
65
- async getTools(serverId, allowList) {
66
- await this.connect(serverId);
67
- const client = this._clients.get(serverId);
68
- const result = await client.listTools();
69
- const tools = result.tools.map((t) => ({
70
- name: t.name,
71
- description: t.description ?? '',
72
- inputSchema: t.inputSchema,
73
- }));
74
- if (allowList.length === 0)
75
- return tools;
76
- return tools.filter((t) => allowList.includes(t.name));
77
- }
78
- async call(serverId, toolName, args) {
79
- await this.connect(serverId);
80
- const client = this._clients.get(serverId);
81
- return client.callTool({ name: toolName, arguments: args });
82
- }
83
- async disconnect() {
84
- const clients = [...this._clients.values()];
85
- this._clients.clear();
86
- await Promise.allSettled(clients.map((c) => c.close()));
87
- }
88
- _expandEnv(serverId, config) {
89
- const expanded = {};
90
- for (const [key, value] of Object.entries(config.env ?? {})) {
91
- const result = value.replace(/\$\{([^}]+)\}/g, (_match, varName) => {
92
- const v = process.env[varName];
93
- if (v === undefined) {
94
- throw new WorkflowError(`MCP server '${serverId}': env var ${varName} is not set`, {
95
- code: 'MCP_CONNECTION_FAILED',
96
- category: 'ENGINE',
97
- agentAction: 'stop',
98
- retryable: false,
99
- });
100
- }
101
- return v;
102
- });
103
- expanded[key] = result;
104
- }
105
- return expanded;
106
- }
107
- }
108
- //# sourceMappingURL=mcp-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-client.js","sourceRoot":"","sources":["../../src/agent/mcp-client.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,yFAAyF;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/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AE,MAAuB;QAC1D,MAAM,QAAQ,GAA2B,EAAE,CAAC;QAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,OAAe,EAAU,EAAE;gBACjF,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC/B,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;oBACpB,MAAM,IAAI,aAAa,CAAC,eAAe,QAAQ,cAAc,OAAO,aAAa,EAAE;wBACjF,IAAI,EAAE,uBAAuB;wBAC7B,QAAQ,EAAE,QAAQ;wBAClB,WAAW,EAAE,MAAM;wBACnB,SAAS,EAAE,KAAK;qBACjB,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,CAAC,CAAC;YACX,CAAC,CAAC,CAAC;YACH,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACzB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
@@ -1,40 +0,0 @@
1
- import type { ToolCallRecord, McpServerConfig } from '@sensigo/realm';
2
- export type { ToolCallRecord, McpServerConfig };
3
- export interface McpTool {
4
- name: string;
5
- description: string;
6
- inputSchema: Record<string, unknown>;
7
- }
8
- export interface ToolDefinition {
9
- id: string;
10
- serverId: string;
11
- name: string;
12
- description: string;
13
- inputSchema: Record<string, unknown>;
14
- }
15
- export type ToolExecutor = (toolName: string, args: Record<string, unknown>) => Promise<unknown>;
16
- export interface StepWithToolsResult {
17
- output: Record<string, unknown>;
18
- toolCalls: ToolCallRecord[];
19
- }
20
- export interface McpClient {
21
- /**
22
- * Lazily connects to a server on first call. Idempotent.
23
- * stdio failures throw WorkflowError(MCP_CONNECTION_FAILED, stop).
24
- */
25
- connect(serverId: string): Promise<void>;
26
- /**
27
- * Returns tools from the specified server, filtered to the allow-list.
28
- * Triggers lazy-connect on first call — the subprocess may spawn here.
29
- */
30
- getTools(serverId: string, allowList: string[]): Promise<McpTool[]>;
31
- /** Execute a tool on the specified server. */
32
- call(serverId: string, toolName: string, args: Record<string, unknown>): Promise<unknown>;
33
- /**
34
- * Shut down all server connections. Idempotent — safe to call multiple times.
35
- * Must be called in finally blocks.
36
- * If constructed with an AbortSignal, also called automatically on abort.
37
- */
38
- disconnect(): Promise<void>;
39
- }
40
- //# sourceMappingURL=mcp-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-types.d.ts","sourceRoot":"","sources":["../../src/agent/mcp-types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC;AAGhD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAGD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAGD,MAAM,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAGjG,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,SAAS,EAAE,cAAc,EAAE,CAAC;CAE7B;AAGD,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACpE,8CAA8C;IAC9C,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1F;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mcp-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-types.js","sourceRoot":"","sources":["../../src/agent/mcp-types.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
1
- import { ToolCapableLlmProvider, type ProviderCapabilities } from './llm-provider.js';
2
- import type { ToolDefinition, ToolExecutor, StepWithToolsResult } from './mcp-types.js';
3
- /**
4
- * OpenAI LLM provider for realm agent.
5
- * Uses the Chat Completions API. Sends `response_format: json_object` on native
6
- * OpenAI endpoints; falls back to prompt-only JSON enforcement on compat endpoints
7
- * behind `--base-url`. Retries once if the model returns non-JSON content.
8
- */
9
- export declare class OpenAIProvider extends ToolCapableLlmProvider {
10
- private readonly model;
11
- private readonly baseUrl;
12
- constructor(model: string, baseUrl?: string);
13
- /**
14
- * Native OpenAI endpoints have a well-defined, tested capability surface that includes
15
- * json_object mode. Custom compat endpoints behind --base-url do not guarantee this feature.
16
- * Default to prompt-only enforcement for any unknown endpoint.
17
- */
18
- capabilities(): ProviderCapabilities;
19
- callStep(prompt: string, inputSchema?: Record<string, unknown>): Promise<Record<string, unknown>>;
20
- /**
21
- * Agentic loop for tool-capable steps. Executes tool calls serially (V1 constraint)
22
- * until the model returns a final JSON answer or the tool call budget is exhausted.
23
- */
24
- callStepWithTools(prompt: string, tools: ToolDefinition[], executor: ToolExecutor, options: {
25
- inputSchema?: Record<string, unknown>;
26
- maxToolCalls?: number;
27
- toolTimeoutMs?: number;
28
- }): Promise<StepWithToolsResult>;
29
- }
30
- //# sourceMappingURL=openai-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../src/agent/openai-provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAEV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAWxB;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,sBAAsB;IACxD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAEjC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAM3C;;;;OAIG;IACH,YAAY,IAAI,oBAAoB;IAI9B,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA8DnC;;;OAGG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,cAAc,EAAE,EACvB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACtC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,OAAO,CAAC,mBAAmB,CAAC;CA0LhC"}
@@ -1,253 +0,0 @@
1
- // openai-provider.ts — OpenAI LLM provider implementation for realm agent.
2
- // Requires openai >= 4.0.0 as an optional peer dependency (npm install openai).
3
- import { WorkflowError } from '@sensigo/realm';
4
- import { ToolCapableLlmProvider } from './llm-provider.js';
5
- import { sanitizeError, serializeToolResult, parseNamespacedId, tryParseJson, validateSchema, rejectAfter, buildSystemPrompt, } from './agent-utils.js';
6
- /**
7
- * OpenAI LLM provider for realm agent.
8
- * Uses the Chat Completions API. Sends `response_format: json_object` on native
9
- * OpenAI endpoints; falls back to prompt-only JSON enforcement on compat endpoints
10
- * behind `--base-url`. Retries once if the model returns non-JSON content.
11
- */
12
- export class OpenAIProvider extends ToolCapableLlmProvider {
13
- model;
14
- baseUrl;
15
- constructor(model, baseUrl) {
16
- super();
17
- this.model = model;
18
- this.baseUrl = baseUrl;
19
- }
20
- /**
21
- * Native OpenAI endpoints have a well-defined, tested capability surface that includes
22
- * json_object mode. Custom compat endpoints behind --base-url do not guarantee this feature.
23
- * Default to prompt-only enforcement for any unknown endpoint.
24
- */
25
- capabilities() {
26
- return { jsonMode: this.baseUrl === undefined };
27
- }
28
- async callStep(prompt, inputSchema) {
29
- // Dynamically import openai to keep it an optional peer dependency.
30
- // Assigning the module specifier to a typed variable via 'string' makes TS
31
- // treat it as Promise<any>, bypassing static module resolution at build time.
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- let mod;
34
- try {
35
- const moduleId = 'openai';
36
- mod = await import(moduleId);
37
- }
38
- catch {
39
- console.error('realm agent requires the openai package. Run: npm install openai');
40
- process.exit(1);
41
- }
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const client = new mod.default({
44
- apiKey: process.env['OPENAI_API_KEY'],
45
- ...(this.baseUrl !== undefined ? { baseURL: this.baseUrl } : {}),
46
- });
47
- const systemPrompt = buildSystemPrompt(inputSchema);
48
- const messages = [
49
- { role: 'system', content: systemPrompt },
50
- { role: 'user', content: prompt },
51
- ];
52
- const makeRequest = async (msgs) => {
53
- const opts = {
54
- model: this.model,
55
- messages: msgs,
56
- };
57
- if (this.capabilities().jsonMode) {
58
- opts['response_format'] = { type: 'json_object' };
59
- }
60
- const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- client.chat.completions.create(opts);
62
- return response.choices[0]?.message?.content ?? '';
63
- };
64
- const content = await makeRequest(messages);
65
- try {
66
- return JSON.parse(content);
67
- }
68
- catch {
69
- // Retry once with an explicit reminder to return JSON.
70
- const retryMessages = [
71
- ...messages,
72
- { role: 'assistant', content },
73
- {
74
- role: 'user',
75
- content: 'Your previous response was not valid JSON. Respond with a JSON object only.',
76
- },
77
- ];
78
- const retry = await makeRequest(retryMessages);
79
- try {
80
- return JSON.parse(retry);
81
- }
82
- catch {
83
- throw new Error(`OpenAI returned non-JSON content after retry: ${retry.slice(0, 200)}`);
84
- }
85
- }
86
- }
87
- /**
88
- * Agentic loop for tool-capable steps. Executes tool calls serially (V1 constraint)
89
- * until the model returns a final JSON answer or the tool call budget is exhausted.
90
- */
91
- async callStepWithTools(prompt, tools, executor, options) {
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- let mod;
94
- try {
95
- const moduleId = 'openai';
96
- mod = await import(moduleId);
97
- }
98
- catch {
99
- console.error('realm agent requires the openai package. Run: npm install openai');
100
- process.exit(1);
101
- }
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- const client = new mod.default({
104
- apiKey: process.env['OPENAI_API_KEY'],
105
- ...(this.baseUrl !== undefined ? { baseURL: this.baseUrl } : {}),
106
- });
107
- const responseFormat = this.capabilities().jsonMode && options.inputSchema !== undefined
108
- ? { type: 'json_object' }
109
- : undefined;
110
- // toolIdMap: bareName → namespaced id, used to recover routing key from LLM responses.
111
- // Collision guard: two MCP servers may not expose the same bare tool name in the same step.
112
- const toolIdMap = new Map();
113
- const openaiTools = [];
114
- for (const tool of tools) {
115
- if (toolIdMap.has(tool.name)) {
116
- throw new Error(`invariant: duplicate bare tool name '${tool.name}' in toolIdMap — this should have been caught at toolDefs assembly in run-agent.ts`);
117
- }
118
- toolIdMap.set(tool.name, tool.id);
119
- openaiTools.push({
120
- type: 'function',
121
- function: {
122
- name: tool.name,
123
- description: tool.description,
124
- parameters: tool.inputSchema,
125
- },
126
- });
127
- }
128
- const maxCalls = options.maxToolCalls ?? 20;
129
- let tool_call_count = 0;
130
- const tool_call_records = [];
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- const history = [
133
- { role: 'system', content: buildSystemPrompt(options.inputSchema) },
134
- { role: 'user', content: prompt },
135
- ];
136
- const buildMainCallOpts = () => {
137
- const opts = { model: this.model, messages: history };
138
- if (openaiTools.length > 0)
139
- opts['tools'] = openaiTools;
140
- if (responseFormat !== undefined)
141
- opts['response_format'] = responseFormat;
142
- return opts;
143
- };
144
- const buildFinalCallOpts = () => {
145
- const opts = { model: this.model, messages: history };
146
- if (responseFormat !== undefined)
147
- opts['response_format'] = responseFormat;
148
- return opts;
149
- };
150
- // Injects the over-budget message and calls the API without tools to produce a final answer.
151
- const performFinalExtraction = async () => {
152
- history.push({
153
- role: 'user',
154
- content: 'You have reached the maximum number of tool calls. Produce your final JSON answer now using only what you have already gathered. No further tool calls will be executed.',
155
- });
156
- const final = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- client.chat.completions.create(buildFinalCallOpts());
158
- const text = final.choices[0].message.content ?? '';
159
- const parsed = tryParseJson(text);
160
- if (parsed && validateSchema(parsed, options.inputSchema)) {
161
- return { output: parsed, toolCalls: tool_call_records };
162
- }
163
- throw new WorkflowError('max_tool_calls reached; final extraction failed', {
164
- code: 'ENGINE_STEP_FAILED',
165
- category: 'ENGINE',
166
- agentAction: 'stop',
167
- retryable: false,
168
- });
169
- };
170
- while (true) {
171
- const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
172
- client.chat.completions.create(buildMainCallOpts());
173
- const message = response.choices[0].message;
174
- if (message.tool_calls?.length) {
175
- const batch = message.tool_calls;
176
- history.push(message);
177
- let budget_exhausted_mid_batch = false;
178
- for (const tool of batch) {
179
- const llmToolCallId = tool.id; // captured verbatim — API returns 400 if echoed incorrectly
180
- if (tool_call_count >= maxCalls) {
181
- // Budget exhausted — must still answer every id in the assistant message.
182
- history.push({
183
- role: 'tool',
184
- tool_call_id: llmToolCallId,
185
- content: 'Error: tool call budget exhausted',
186
- });
187
- budget_exhausted_mid_batch = true;
188
- continue;
189
- }
190
- const originalId = toolIdMap.get(tool.function.name);
191
- const { serverId, toolName } = parseNamespacedId(originalId);
192
- const args = JSON.parse(tool.function.arguments || '{}');
193
- const start = Date.now();
194
- let resultContent;
195
- let record;
196
- try {
197
- const rawResult = await Promise.race([
198
- executor(originalId, args),
199
- rejectAfter(options.toolTimeoutMs ?? 30000),
200
- ]);
201
- const serialized = serializeToolResult(rawResult);
202
- record = {
203
- server_id: serverId,
204
- tool: toolName,
205
- args,
206
- result: serialized,
207
- duration_ms: Date.now() - start,
208
- };
209
- resultContent = serialized;
210
- }
211
- catch (err) {
212
- const sanitized = sanitizeError(err);
213
- const content = sanitized.length > 0 ? `Error: ${sanitized}` : 'Error: (redacted)';
214
- record = {
215
- server_id: serverId,
216
- tool: toolName,
217
- args,
218
- result: null,
219
- duration_ms: Date.now() - start,
220
- error: sanitized,
221
- };
222
- resultContent = content;
223
- }
224
- tool_call_records.push(record);
225
- tool_call_count++;
226
- history.push({ role: 'tool', tool_call_id: llmToolCallId, content: resultContent });
227
- }
228
- if (budget_exhausted_mid_batch || tool_call_count >= maxCalls) {
229
- return performFinalExtraction();
230
- }
231
- }
232
- else {
233
- // No tool calls — attempt to parse the final answer.
234
- const text = message.content ?? '';
235
- const parsed = tryParseJson(text);
236
- if (parsed && validateSchema(parsed, options.inputSchema)) {
237
- return { output: parsed, toolCalls: tool_call_records };
238
- }
239
- // Schema mismatch — append correction message and continue the loop.
240
- history.push({ role: 'assistant', content: text });
241
- history.push({
242
- role: 'user',
243
- content: 'Your response did not match the required JSON schema. Try again.',
244
- });
245
- tool_call_count++; // schema correction consumes a slot
246
- if (tool_call_count >= maxCalls) {
247
- return performFinalExtraction();
248
- }
249
- }
250
- }
251
- }
252
- }
253
- //# sourceMappingURL=openai-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-provider.js","sourceRoot":"","sources":["../../src/agent/openai-provider.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAA6B,MAAM,mBAAmB,CAAC;AAOtF,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,sBAAsB;IACvC,KAAK,CAAS;IACd,OAAO,CAAqB;IAE7C,YAAY,KAAa,EAAE,OAAgB;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,MAAc,EACd,WAAqC;QAErC,oEAAoE;QACpE,2EAA2E;QAC3E,8EAA8E;QAC9E,8DAA8D;QAC9D,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACH,MAAM,QAAQ,GAAW,QAAQ,CAAC;YAClC,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;YAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,8DAA8D;QAC9D,MAAM,MAAM,GAAG,IAAK,GAAG,CAAC,OAAsD,CAAC;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M,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBAClC,IAAI,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;gBAC1D,CAAC;gBACD,qEAAqE;gBACrE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBACnD,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,kEAAkE;iBAC5E,CAAC,CAAC;gBACH,eAAe,EAAE,CAAC,CAAC,oCAAoC;gBACvD,IAAI,eAAe,IAAI,QAAQ,EAAE,CAAC;oBAChC,OAAO,sBAAsB,EAAE,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -1,18 +0,0 @@
1
- import { LlmProvider } from './llm-provider.js';
2
- /**
3
- * OpenAI reasoning model provider for realm agent.
4
- * Handles the o1/o3 model families, which differ from standard chat completions:
5
- * - No `response_format` parameter (JSON enforced via system prompt + retry).
6
- * - System prompt content is folded into the first user message — the safe
7
- * universal approach for the full o1/o3 lineage. (o1 originally rejected the
8
- * system role; later versions accept it as a developer role, but prepending
9
- * to the user message works uniformly across all revisions.)
10
- * - Tool calling is not supported — this class extends LlmProvider, not
11
- * ToolCapableLlmProvider, so `isToolCapable` returns false for these instances.
12
- */
13
- export declare class OpenAIReasoningProvider extends LlmProvider {
14
- private readonly model;
15
- constructor(model: string);
16
- callStep(prompt: string, inputSchema?: Record<string, unknown>): Promise<Record<string, unknown>>;
17
- }
18
- //# sourceMappingURL=openai-reasoning-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-reasoning-provider.d.ts","sourceRoot":"","sources":["../../src/agent/openai-reasoning-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,KAAK,EAAE,MAAM;IAKnB,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAwDpC"}
@@ -1,76 +0,0 @@
1
- // openai-reasoning-provider.ts — OpenAI reasoning model provider (o1/o3) for realm agent.
2
- // Extends LlmProvider (not ToolCapableLlmProvider) — reasoning models do not support the tools parameter.
3
- import { LlmProvider } from './llm-provider.js';
4
- import { buildSystemPrompt } from './agent-utils.js';
5
- /**
6
- * OpenAI reasoning model provider for realm agent.
7
- * Handles the o1/o3 model families, which differ from standard chat completions:
8
- * - No `response_format` parameter (JSON enforced via system prompt + retry).
9
- * - System prompt content is folded into the first user message — the safe
10
- * universal approach for the full o1/o3 lineage. (o1 originally rejected the
11
- * system role; later versions accept it as a developer role, but prepending
12
- * to the user message works uniformly across all revisions.)
13
- * - Tool calling is not supported — this class extends LlmProvider, not
14
- * ToolCapableLlmProvider, so `isToolCapable` returns false for these instances.
15
- */
16
- export class OpenAIReasoningProvider extends LlmProvider {
17
- model;
18
- constructor(model) {
19
- super();
20
- this.model = model;
21
- }
22
- async callStep(prompt, inputSchema) {
23
- // Dynamically import openai to keep it an optional peer dependency.
24
- // Assigning the module specifier to a typed variable via 'string' makes TS
25
- // treat it as Promise<any>, bypassing static module resolution at build time.
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- let mod;
28
- try {
29
- const moduleId = 'openai';
30
- mod = await import(moduleId);
31
- }
32
- catch {
33
- console.error('realm agent requires the openai package. Run: npm install openai');
34
- process.exit(1);
35
- }
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- const client = new mod.default({
38
- apiKey: process.env['OPENAI_API_KEY'],
39
- });
40
- // Fold system prompt into the user message — safe for all o1/o3 API revisions.
41
- const systemPrompt = buildSystemPrompt(inputSchema);
42
- const userContent = `${systemPrompt}\n\n${prompt}`;
43
- const messages = [{ role: 'user', content: userContent }];
44
- const makeRequest = async (msgs) => {
45
- const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- client.chat.completions.create({
47
- model: this.model,
48
- messages: msgs,
49
- });
50
- return response.choices[0]?.message?.content ?? '';
51
- };
52
- const content = await makeRequest(messages);
53
- try {
54
- return JSON.parse(content);
55
- }
56
- catch {
57
- // Retry once with an explicit reminder to return JSON.
58
- const retryMessages = [
59
- ...messages,
60
- { role: 'assistant', content },
61
- {
62
- role: 'user',
63
- content: 'Your previous response was not valid JSON. Respond with a JSON object only.',
64
- },
65
- ];
66
- const retry = await makeRequest(retryMessages);
67
- try {
68
- return JSON.parse(retry);
69
- }
70
- catch {
71
- throw new Error(`OpenAI returned non-JSON content after retry: ${retry.slice(0, 200)}`);
72
- }
73
- }
74
- }
75
- }
76
- //# sourceMappingURL=openai-reasoning-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-reasoning-provider.js","sourceRoot":"","sources":["../../src/agent/openai-reasoning-provider.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,0GAA0G;AAC1G,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACrC,KAAK,CAAS;IAE/B,YAAY,KAAa;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,MAAc,EACd,WAAqC;QAErC,oEAAoE;QACpE,2EAA2E;QAC3E,8EAA8E;QAC9E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