@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,79 +0,0 @@
1
- // agent-utils.ts — Shared utility functions for LLM provider agentic loops.
2
- const SYSTEM_PROMPT_BASE = 'You are an AI agent executing a step in a structured workflow.\n' +
3
- 'Your task is described below. Respond with a JSON object only — no markdown, no explanation.';
4
- /** Builds the system prompt for an agent step, optionally including the output schema. */
5
- export function buildSystemPrompt(inputSchema) {
6
- if (inputSchema === undefined)
7
- return SYSTEM_PROMPT_BASE;
8
- return `${SYSTEM_PROMPT_BASE}\nThe JSON must conform to this schema: ${JSON.stringify(inputSchema)}`;
9
- }
10
- /**
11
- * Converts an error value to a string and strips sensitive patterns:
12
- * Bearer tokens, query-string tokens, and any process.env value longer than 4 characters.
13
- */
14
- export function sanitizeError(err) {
15
- let text;
16
- if (err instanceof Error) {
17
- text = err.message;
18
- }
19
- else if (typeof err === 'string') {
20
- text = err;
21
- }
22
- else {
23
- text = String(err);
24
- }
25
- text = text.replace(/Bearer [A-Za-z0-9._-]+/g, 'Bearer [REDACTED]');
26
- text = text.replace(/token=[A-Za-z0-9._-]+/g, 'token=[REDACTED]');
27
- for (const val of Object.values(process.env)) {
28
- if (val !== undefined && val.length > 4) {
29
- text = text.split(val).join('[REDACTED]');
30
- }
31
- }
32
- return text;
33
- }
34
- /**
35
- * Serializes an MCP tool result to a string and applies the same sanitization pass
36
- * as sanitizeError to strip any tokens that upstream services may have echoed.
37
- */
38
- export function serializeToolResult(result) {
39
- const raw = typeof result === 'string' ? result : JSON.stringify(result);
40
- return sanitizeError(raw);
41
- }
42
- /** Splits "server_id:tool_name" into its components. Throws if the format is invalid. */
43
- export function parseNamespacedId(id) {
44
- const colonIdx = id.indexOf(':');
45
- if (colonIdx === -1) {
46
- throw new Error(`Invalid namespaced tool id '${id}' (expected format: 'serverId:toolName')`);
47
- }
48
- return { serverId: id.slice(0, colonIdx), toolName: id.slice(colonIdx + 1) };
49
- }
50
- /** Tries to parse JSON; returns a plain object or null if parsing fails or the result is not an object. */
51
- export function tryParseJson(text) {
52
- try {
53
- const parsed = JSON.parse(text);
54
- if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
55
- return parsed;
56
- }
57
- return null;
58
- }
59
- catch {
60
- return null;
61
- }
62
- }
63
- /**
64
- * Returns true if all required properties from the schema are present in the parsed object.
65
- * Returns true when no schema is provided.
66
- */
67
- export function validateSchema(parsed, schema) {
68
- if (!schema)
69
- return true;
70
- const required = schema['required'];
71
- if (!Array.isArray(required))
72
- return true;
73
- return required.every((key) => typeof key === 'string' && key in parsed);
74
- }
75
- /** Returns a Promise that rejects with a timeout error after `ms` milliseconds. */
76
- export function rejectAfter(ms) {
77
- return new Promise((_, reject) => setTimeout(() => reject(new Error(`tool call timed out after ${ms}ms`)), ms));
78
- }
79
- //# sourceMappingURL=agent-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-utils.js","sourceRoot":"","sources":["../../src/agent/agent-utils.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,MAAM,kBAAkB,GACtB,kEAAkE;IAClE,8FAA8F,CAAC;AAEjG,0FAA0F;AAC1F,MAAM,UAAU,iBAAiB,CAAC,WAAqC;IACrE,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,kBAAkB,CAAC;IACzD,OAAO,GAAG,kBAAkB,2CAA2C,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;AACvG,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,IAAY,CAAC;IACjB,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC;SAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,GAAG,GAA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G;AAC3G,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5E,OAAO,MAAiC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAA+B,EAC/B,MAAgC;IAEhC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAQ,QAAsB,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,MAAM,CAAC,CAAC;AAC1F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACtC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAC7E,CAAC;AACJ,CAAC"}
@@ -1,23 +0,0 @@
1
- import { ToolCapableLlmProvider } from './llm-provider.js';
2
- import type { ToolDefinition, ToolExecutor, StepWithToolsResult } from './mcp-types.js';
3
- /**
4
- * Anthropic LLM provider for realm agent.
5
- * Uses the Messages API and extracts JSON from the first text content block.
6
- * Retries once if the model returns non-JSON content.
7
- */
8
- export declare class AnthropicProvider extends ToolCapableLlmProvider {
9
- private readonly model;
10
- constructor(model: string);
11
- callStep(prompt: string, inputSchema?: Record<string, unknown>): Promise<Record<string, unknown>>;
12
- /**
13
- * Agentic loop for tool-capable steps. Executes tool calls serially (V1 constraint).
14
- * All tool results for one turn are accumulated into a single user message with an array
15
- * of tool_result blocks — the Anthropic API rejects interleaved assistant/user turns.
16
- */
17
- callStepWithTools(prompt: string, tools: ToolDefinition[], executor: ToolExecutor, options: {
18
- inputSchema?: Record<string, unknown>;
19
- maxToolCalls?: number;
20
- toolTimeoutMs?: number;
21
- }): Promise<StepWithToolsResult>;
22
- }
23
- //# sourceMappingURL=anthropic-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../../src/agent/anthropic-provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAEV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAWxB;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,sBAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,MAAM;IAIpC,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;IAoDnC;;;;OAIG;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;CAiNhC"}
@@ -1,245 +0,0 @@
1
- // anthropic-provider.ts — Anthropic LLM provider implementation for realm agent.
2
- // Requires @anthropic-ai/sdk >= 0.20.0 as an optional peer dependency (npm install @anthropic-ai/sdk).
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
- * Anthropic LLM provider for realm agent.
8
- * Uses the Messages API and extracts JSON from the first text content block.
9
- * Retries once if the model returns non-JSON content.
10
- */
11
- export class AnthropicProvider extends ToolCapableLlmProvider {
12
- model;
13
- constructor(model) {
14
- super();
15
- this.model = model;
16
- }
17
- async callStep(prompt, inputSchema) {
18
- // Dynamically import @anthropic-ai/sdk to keep it an optional peer dependency.
19
- // See openai-provider.ts for an explanation of the 'string' cast technique.
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- let mod;
22
- try {
23
- const moduleId = '@anthropic-ai/sdk';
24
- mod = await import(moduleId);
25
- }
26
- catch {
27
- console.error('realm agent requires the @anthropic-ai/sdk package. Run: npm install @anthropic-ai/sdk');
28
- process.exit(1);
29
- }
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- const client = new mod.default({
32
- apiKey: process.env['ANTHROPIC_API_KEY'],
33
- });
34
- const systemPrompt = buildSystemPrompt(inputSchema);
35
- const makeRequest = async (userContent) => {
36
- const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- client.messages.create({
38
- model: this.model,
39
- max_tokens: 4096,
40
- system: systemPrompt,
41
- messages: [{ role: 'user', content: userContent }],
42
- });
43
- const block = response.content.find(
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- (b) => b.type === 'text');
46
- return block?.text ?? '';
47
- };
48
- const content = await makeRequest(prompt);
49
- try {
50
- return JSON.parse(content);
51
- }
52
- catch {
53
- // Retry once with an explicit reminder to return JSON.
54
- const retryPrompt = `${prompt}\n\nYour previous response was not valid JSON. Respond with a JSON object only.`;
55
- const retry = await makeRequest(retryPrompt);
56
- try {
57
- return JSON.parse(retry);
58
- }
59
- catch {
60
- throw new Error(`Anthropic returned non-JSON content after retry: ${retry.slice(0, 200)}`);
61
- }
62
- }
63
- }
64
- /**
65
- * Agentic loop for tool-capable steps. Executes tool calls serially (V1 constraint).
66
- * All tool results for one turn are accumulated into a single user message with an array
67
- * of tool_result blocks — the Anthropic API rejects interleaved assistant/user turns.
68
- */
69
- async callStepWithTools(prompt, tools, executor, options) {
70
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- let mod;
72
- try {
73
- const moduleId = '@anthropic-ai/sdk';
74
- mod = await import(moduleId);
75
- }
76
- catch {
77
- console.error('realm agent requires the @anthropic-ai/sdk package. Run: npm install @anthropic-ai/sdk');
78
- process.exit(1);
79
- }
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- const client = new mod.default({
82
- apiKey: process.env['ANTHROPIC_API_KEY'],
83
- });
84
- // toolIdMap: bareName → namespaced id, used to recover routing key from LLM responses.
85
- // Collision guard: two MCP servers may not expose the same bare tool name in the same step.
86
- const toolIdMap = new Map();
87
- const anthropicTools = [];
88
- for (const tool of tools) {
89
- if (toolIdMap.has(tool.name)) {
90
- throw new Error(`invariant: duplicate bare tool name '${tool.name}' in toolIdMap — this should have been caught at toolDefs assembly in run-agent.ts`);
91
- }
92
- toolIdMap.set(tool.name, tool.id);
93
- anthropicTools.push({
94
- name: tool.name,
95
- description: tool.description,
96
- input_schema: tool.inputSchema, // note: input_schema, not parameters
97
- });
98
- }
99
- const maxCalls = options.maxToolCalls ?? 20;
100
- let tool_call_count = 0;
101
- const tool_call_records = [];
102
- const system = buildSystemPrompt(options.inputSchema);
103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
- const history = [{ role: 'user', content: prompt }];
105
- const buildMainCallOpts = () => {
106
- const opts = {
107
- model: this.model,
108
- max_tokens: 4096,
109
- system,
110
- messages: history,
111
- };
112
- if (anthropicTools.length > 0)
113
- opts['tools'] = anthropicTools;
114
- return opts;
115
- };
116
- // Calls the API with tool_choice: none and no tools array to force a plain text answer.
117
- // Does NOT push to history — callers must ensure history ends with a valid user turn.
118
- const performFinalExtraction = async () => {
119
- const final = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- client.messages.create({
121
- model: this.model,
122
- max_tokens: 4096,
123
- system,
124
- messages: history,
125
- tool_choice: { type: 'none' },
126
- // NO tools array — enforces text-only response
127
- // NO response_format — not a valid Anthropic parameter
128
- });
129
- const textBlock = final.content.find((b) => b.type === 'text');
130
- const text = textBlock?.text ?? '';
131
- const parsed = tryParseJson(text);
132
- if (parsed && validateSchema(parsed, options.inputSchema)) {
133
- return { output: parsed, toolCalls: tool_call_records };
134
- }
135
- throw new WorkflowError('max_tool_calls reached; final extraction failed', {
136
- code: 'ENGINE_STEP_FAILED',
137
- category: 'ENGINE',
138
- agentAction: 'stop',
139
- retryable: false,
140
- });
141
- };
142
- while (true) {
143
- const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
- client.messages.create(buildMainCallOpts());
145
- const toolUseBlocks = response.content.filter((b) => b.type === 'tool_use');
146
- if (toolUseBlocks.length > 0) {
147
- history.push({ role: 'assistant', content: response.content });
148
- const anthropic_result_blocks = [];
149
- let budget_exhausted_mid_batch = false;
150
- for (const block of toolUseBlocks) {
151
- const llmToolCallId = block.id; // captured verbatim — "toolu_01abc..."
152
- if (tool_call_count >= maxCalls) {
153
- // Budget exhausted — must still answer every id in the assistant message.
154
- anthropic_result_blocks.push({
155
- type: 'tool_result',
156
- tool_use_id: llmToolCallId,
157
- content: 'Error: tool call budget exhausted',
158
- });
159
- budget_exhausted_mid_batch = true;
160
- continue;
161
- }
162
- const originalId = toolIdMap.get(block.name);
163
- const { serverId, toolName } = parseNamespacedId(originalId);
164
- const args = (block.input ?? {});
165
- const start = Date.now();
166
- let resultContent;
167
- let record;
168
- try {
169
- const rawResult = await Promise.race([
170
- executor(originalId, args),
171
- rejectAfter(options.toolTimeoutMs ?? 30000),
172
- ]);
173
- const serialized = serializeToolResult(rawResult);
174
- record = {
175
- server_id: serverId,
176
- tool: toolName,
177
- args,
178
- result: serialized,
179
- duration_ms: Date.now() - start,
180
- };
181
- resultContent = serialized;
182
- }
183
- catch (err) {
184
- const sanitized = sanitizeError(err);
185
- const content = sanitized.length > 0 ? `Error: ${sanitized}` : 'Error: (redacted)';
186
- record = {
187
- server_id: serverId,
188
- tool: toolName,
189
- args,
190
- result: null,
191
- duration_ms: Date.now() - start,
192
- error: sanitized,
193
- };
194
- resultContent = content;
195
- }
196
- tool_call_records.push(record);
197
- tool_call_count++;
198
- anthropic_result_blocks.push({
199
- type: 'tool_result',
200
- tool_use_id: llmToolCallId,
201
- content: resultContent,
202
- });
203
- }
204
- const exhausted = budget_exhausted_mid_batch || tool_call_count >= maxCalls;
205
- if (exhausted) {
206
- // Merge tool results and extraction prompt into a single user message to avoid
207
- // consecutive user messages, which the Anthropic API rejects with 400.
208
- history.push({
209
- role: 'user',
210
- content: [
211
- ...anthropic_result_blocks,
212
- {
213
- type: 'text',
214
- text: '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.',
215
- },
216
- ],
217
- });
218
- return performFinalExtraction();
219
- }
220
- // Normal continuation — single user message with all tool_result blocks.
221
- history.push({ role: 'user', content: anthropic_result_blocks });
222
- }
223
- else {
224
- // No tool calls — attempt to parse the final answer.
225
- const textBlock = response.content.find((b) => b.type === 'text');
226
- const text = textBlock?.text ?? '';
227
- const parsed = tryParseJson(text);
228
- if (parsed && validateSchema(parsed, options.inputSchema)) {
229
- return { output: parsed, toolCalls: tool_call_records };
230
- }
231
- // Schema mismatch — append correction and keep looping.
232
- history.push({ role: 'assistant', content: response.content });
233
- history.push({
234
- role: 'user',
235
- content: 'Your response did not match the required JSON schema. Try again.',
236
- });
237
- tool_call_count++; // schema correction consumes a slot
238
- if (tool_call_count >= maxCalls) {
239
- return performFinalExtraction();
240
- }
241
- }
242
- }
243
- }
244
- }
245
- //# sourceMappingURL=anthropic-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anthropic-provider.js","sourceRoot":"","sources":["../../src/agent/anthropic-provider.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,uGAAuG;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAO3D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,sBAAsB;IAC9B;IAA7B,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,MAAc,EACd,WAAqC;QAErC,+EAA+E;QAC/E,4EAA4E;QAC5E,8DAA8D;QAC9D,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACH,MAAM,QAAQ,GAAW,mBAAmB,CAAC;YAC7C,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CACX,wFAAwF,CACzF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,8DAA8D;QAC9D,MAAM,MAAM,GAAG,IAAK,GAAG,CAAC,OAAsD,CAAC;YAC7E,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;SACzC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAEpD,MAAM,WAAW,GAAG,KAAK,EAAE,WAAmB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,EAAE,CAAC;oBAChC,OAAO,sBAAsB,EAAE,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -1,29 +0,0 @@
1
- import type { LlmProvider } from './llm-provider.js';
2
- /** Structured output from LLM interpretation of a gate reply. */
3
- export interface GateInterpretation {
4
- /** One of the allowed gate choices, or 'unclear' when intent cannot be determined. */
5
- choice: string | 'unclear';
6
- /** Confidence in the interpretation. */
7
- confidence: 'high' | 'medium' | 'low';
8
- /** Brief explanation of the interpretation reasoning. */
9
- reason: string;
10
- }
11
- export interface InterpretGateIntentOptions {
12
- /** Raw message text from the Slack thread. */
13
- userMessage: string;
14
- /** The gate's valid choices (e.g. ['send', 'reject']). */
15
- allowedChoices: string[];
16
- /** Name of the gate step for context. */
17
- gateStepName: string;
18
- /** Optional headline from the gate preview — provides brief context without overwhelming the prompt. */
19
- previewSummary?: string;
20
- /** LLM provider to use — same instance configured for the agent run. */
21
- llmClient: LlmProvider;
22
- }
23
- /**
24
- * Asks the LLM to interpret a human's Slack reply as one of the allowed gate choices.
25
- * Returns a structured interpretation with confidence level and reasoning.
26
- * The LLM is solely responsible for understanding intent — no hardcoded synonyms.
27
- */
28
- export declare function interpretGateIntent(options: InterpretGateIntentOptions): Promise<GateInterpretation>;
29
- //# sourceMappingURL=gate-intent-interpreter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate-intent-interpreter.d.ts","sourceRoot":"","sources":["../../src/agent/gate-intent-interpreter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,wCAAwC;IACxC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,wGAAwG;IACxG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,SAAS,EAAE,WAAW,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,kBAAkB,CAAC,CAiC7B"}
@@ -1,33 +0,0 @@
1
- /**
2
- * Asks the LLM to interpret a human's Slack reply as one of the allowed gate choices.
3
- * Returns a structured interpretation with confidence level and reasoning.
4
- * The LLM is solely responsible for understanding intent — no hardcoded synonyms.
5
- */
6
- export async function interpretGateIntent(options) {
7
- const { userMessage, allowedChoices, gateStepName, previewSummary, llmClient } = options;
8
- const contextLine = previewSummary !== undefined ? `\nGate context: ${previewSummary}` : '';
9
- const choiceList = allowedChoices.map((c) => `"${c}"`).join(', ');
10
- const prompt = `You are interpreting a Slack message from a human reviewer responding to a workflow gate.\n` +
11
- `Gate step: "${gateStepName}"${contextLine}\n` +
12
- `Allowed choices: ${allowedChoices.join(', ')}\n\n` +
13
- `Message: "${userMessage}"\n\n` +
14
- `Determine which choice the user intends. Return JSON with:\n` +
15
- `- "choice": one of [${choiceList}, "unclear"]\n` +
16
- `- "confidence": "high", "medium", or "low"\n` +
17
- `- "reason": brief explanation of your interpretation`;
18
- const schema = {
19
- type: 'object',
20
- required: ['choice', 'confidence', 'reason'],
21
- properties: {
22
- choice: { type: 'string' },
23
- confidence: { type: 'string', enum: ['high', 'medium', 'low'] },
24
- reason: { type: 'string' },
25
- },
26
- };
27
- const result = await llmClient.callStep(prompt, schema);
28
- const choice = result['choice'] ?? 'unclear';
29
- const confidence = result['confidence'] ?? 'low';
30
- const reason = result['reason'] ?? '';
31
- return { choice, confidence, reason };
32
- }
33
- //# sourceMappingURL=gate-intent-interpreter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate-intent-interpreter.js","sourceRoot":"","sources":["../../src/agent/gate-intent-interpreter.ts"],"names":[],"mappings":"AA0BA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAmC;IAEnC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEzF,MAAM,WAAW,GAAG,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,mBAAmB,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5F,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElE,MAAM,MAAM,GACV,6FAA6F;QAC7F,eAAe,YAAY,IAAI,WAAW,IAAI;QAC9C,oBAAoB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;QACnD,aAAa,WAAW,OAAO;QAC/B,8DAA8D;QAC9D,uBAAuB,UAAU,gBAAgB;QACjD,8CAA8C;QAC9C,sDAAsD,CAAC;IAEzD,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC;QAC5C,UAAU,EAAE;YACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE;YAC/D,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC3B;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,MAAM,MAAM,GAAI,MAAM,CAAC,QAAQ,CAAwB,IAAI,SAAS,CAAC;IACrE,MAAM,UAAU,GAAI,MAAM,CAAC,YAAY,CAA2C,IAAI,KAAK,CAAC;IAC5F,MAAM,MAAM,GAAI,MAAM,CAAC,QAAQ,CAAwB,IAAI,EAAE,CAAC;IAE9D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC"}
@@ -1,46 +0,0 @@
1
- import type { ToolDefinition, ToolExecutor, StepWithToolsResult } from './mcp-types.js';
2
- /**
3
- * Describes the optional feature set that an LLM provider supports.
4
- * Custom providers can override {@link LlmProvider.capabilities} to declare
5
- * features beyond the universal baseline.
6
- */
7
- export interface ProviderCapabilities {
8
- /**
9
- * Whether this provider sends `response_format: { type: 'json_object' }` in API requests.
10
- * When false, JSON compliance is enforced through system prompt instruction and retry only.
11
- * This is the universal baseline — all providers work without json_object mode.
12
- */
13
- jsonMode: boolean;
14
- }
15
- /**
16
- * Abstract base class for LLM providers used by realm agent.
17
- * Extend this class to implement a custom provider.
18
- */
19
- export declare abstract class LlmProvider {
20
- /** Call the LLM with a step prompt and return a JSON object. */
21
- abstract callStep(prompt: string, inputSchema?: Record<string, unknown>): Promise<Record<string, unknown>>;
22
- /** Returns the capability set for this provider instance. */
23
- capabilities(): ProviderCapabilities;
24
- }
25
- /**
26
- * Extended abstract class for providers that support the agentic tool-calling loop.
27
- * Extend this class if your provider can drive tool-enabled workflow steps.
28
- */
29
- export declare abstract class ToolCapableLlmProvider extends LlmProvider {
30
- abstract callStepWithTools(prompt: string, tools: ToolDefinition[], executor: ToolExecutor, options: {
31
- inputSchema?: Record<string, unknown>;
32
- maxToolCalls?: number;
33
- toolTimeoutMs?: number;
34
- }): Promise<StepWithToolsResult>;
35
- }
36
- /**
37
- * Returns true if the provider supports the agentic tool-calling loop.
38
- */
39
- export declare function isToolCapable(provider: LlmProvider): provider is ToolCapableLlmProvider;
40
- export type ProviderName = 'openai' | 'anthropic';
41
- /**
42
- * Resolves the correct LLM provider from environment and CLI flags.
43
- * Throws if no API key is found or the specified package is not installed.
44
- */
45
- export declare function resolveProvider(providerFlag: ProviderName | undefined, modelFlag: string | undefined, baseUrlFlag?: string): Promise<LlmProvider>;
46
- //# sourceMappingURL=llm-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"llm-provider.d.ts","sourceRoot":"","sources":["../../src/agent/llm-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,8BAAsB,WAAW;IAC/B,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,CACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,6DAA6D;IAC7D,YAAY,IAAI,oBAAoB;CAGrC;AAED;;;GAGG;AACH,8BAAsB,sBAAuB,SAAQ,WAAW;IAC9D,QAAQ,CAAC,iBAAiB,CACxB,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;CAChC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,QAAQ,IAAI,sBAAsB,CAEvF;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,CAAC;AAElD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,CAAC,CAkCtB"}
@@ -1,55 +0,0 @@
1
- /**
2
- * Abstract base class for LLM providers used by realm agent.
3
- * Extend this class to implement a custom provider.
4
- */
5
- export class LlmProvider {
6
- /** Returns the capability set for this provider instance. */
7
- capabilities() {
8
- return { jsonMode: false };
9
- }
10
- }
11
- /**
12
- * Extended abstract class for providers that support the agentic tool-calling loop.
13
- * Extend this class if your provider can drive tool-enabled workflow steps.
14
- */
15
- export class ToolCapableLlmProvider extends LlmProvider {
16
- }
17
- /**
18
- * Returns true if the provider supports the agentic tool-calling loop.
19
- */
20
- export function isToolCapable(provider) {
21
- return provider instanceof ToolCapableLlmProvider;
22
- }
23
- /**
24
- * Resolves the correct LLM provider from environment and CLI flags.
25
- * Throws if no API key is found or the specified package is not installed.
26
- */
27
- export async function resolveProvider(providerFlag, modelFlag, baseUrlFlag) {
28
- const hasOpenAI = process.env['OPENAI_API_KEY'] !== undefined;
29
- const hasAnthropic = process.env['ANTHROPIC_API_KEY'] !== undefined;
30
- if (!hasOpenAI && !hasAnthropic) {
31
- throw new Error('realm agent requires an LLM API key. Set OPENAI_API_KEY or ANTHROPIC_API_KEY.');
32
- }
33
- const provider = providerFlag ?? (hasOpenAI ? 'openai' : 'anthropic');
34
- if (baseUrlFlag !== undefined && provider === 'anthropic') {
35
- throw new Error('--base-url is only supported with --provider openai (or OpenAI-compatible endpoints). ' +
36
- 'For Anthropic, configure the endpoint via the ANTHROPIC_BASE_URL environment variable.');
37
- }
38
- if (provider === 'openai') {
39
- // Match o1, o1-mini, o1-preview, o3, o3-mini, o4-mini, etc. The user has
40
- // explicitly declared the model name, so matching on name is the correct
41
- // signal here — not an internal allowlist.
42
- const REASONING_MODELS = /^o[1-4](-|$)/i;
43
- if (modelFlag !== undefined && REASONING_MODELS.test(modelFlag)) {
44
- const { OpenAIReasoningProvider } = await import('./openai-reasoning-provider.js');
45
- return new OpenAIReasoningProvider(modelFlag);
46
- }
47
- const { OpenAIProvider } = await import('./openai-provider.js');
48
- return new OpenAIProvider(modelFlag ?? 'gpt-4o', baseUrlFlag);
49
- }
50
- else {
51
- const { AnthropicProvider } = await import('./anthropic-provider.js');
52
- return new AnthropicProvider(modelFlag ?? 'claude-sonnet-4-5');
53
- }
54
- }
55
- //# sourceMappingURL=llm-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"llm-provider.js","sourceRoot":"","sources":["../../src/agent/llm-provider.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,OAAgB,WAAW;IAO/B,6DAA6D;IAC7D,YAAY;QACV,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,WAAW;CAW/D;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAqB;IACjD,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC;AAID;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,YAAsC,EACtC,SAA6B,EAC7B,WAAoB;IAEpB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,SAAS,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,KAAK,SAAS,CAAC;IAEpE,IAAI,CAAC,SAAS,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAEtE,IAAI,WAAW,KAAK,SAAS,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,wFAAwF;YACtF,wFAAwF,CAC3F,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,yEAAyE;QACzE,yEAAyE;QACzE,2CAA2C;QAC3C,MAAM,gBAAgB,GAAG,eAAe,CAAC;QACzC,IAAI,SAAS,KAAK,SAAS,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChE,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;YACnF,OAAO,IAAI,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAChE,OAAO,IAAI,cAAc,CAAC,SAAS,IAAI,QAAQ,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC;QACtE,OAAO,IAAI,iBAAiB,CAAC,SAAS,IAAI,mBAAmB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
@@ -1,18 +0,0 @@
1
- import { Client } from '@modelcontextprotocol/sdk/client';
2
- import type { McpClient as IMcpClient, McpServerConfig, McpTool } from './mcp-types.js';
3
- export declare class McpClient implements IMcpClient {
4
- private readonly _servers;
5
- private readonly _clients;
6
- constructor(servers: McpServerConfig[], signal?: AbortSignal);
7
- /**
8
- * Creates and connects an SDK Client for the given config.
9
- * Override in tests to inject an in-process transport and avoid spawning real subprocesses.
10
- */
11
- protected _createClient(config: McpServerConfig, expandedEnv: Record<string, string>): Promise<Client>;
12
- connect(serverId: string): Promise<void>;
13
- getTools(serverId: string, allowList: string[]): Promise<McpTool[]>;
14
- call(serverId: string, toolName: string, args: Record<string, unknown>): Promise<unknown>;
15
- disconnect(): Promise<void>;
16
- private _expandEnv;
17
- }
18
- //# sourceMappingURL=mcp-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/agent/mcp-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG1D,OAAO,KAAK,EAAE,SAAS,IAAI,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAExF,qBAAa,SAAU,YAAW,UAAU;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;gBAE/C,OAAO,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW;IAc5D;;;OAGG;cACa,aAAa,CAC3B,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,MAAM,CAAC;IAqBZ,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAanE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAMzF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,OAAO,CAAC,UAAU;CAmBnB"}