@recombine-ai/engine 0.8.3 → 0.8.6
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.
- package/build/lib/ai.d.ts +27 -9
- package/build/lib/ai.d.ts.map +1 -1
- package/build/lib/ai.js +23 -25
- package/build/lib/bosun/agent.d.ts +3 -1
- package/build/lib/bosun/agent.d.ts.map +1 -1
- package/build/lib/bosun/index.d.ts +1 -1
- package/build/lib/bosun/index.d.ts.map +1 -1
- package/build/lib/bosun/stepTracer.d.ts +29 -3
- package/build/lib/bosun/stepTracer.d.ts.map +1 -1
- package/build/lib/bosun/stepTracer.js +33 -0
- package/build/lib/bosun/tracer.d.ts +19 -4
- package/build/lib/bosun/tracer.d.ts.map +1 -1
- package/build/lib/bosun/tracer.js +11 -3
- package/build/lib/llm-adapters/openai.d.ts.map +1 -1
- package/build/lib/llm-adapters/openai.js +19 -5
- package/build/lib/prompt-fs.js +1 -1
- package/changelog.md +15 -1
- package/package.json +3 -3
package/build/lib/ai.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZodTypeAny } from 'zod';
|
|
2
2
|
import { Logger } from './interfaces';
|
|
3
3
|
import { SendAction } from './bosun/action';
|
|
4
4
|
import { PromptFile } from './prompt-fs';
|
|
5
5
|
import { StepTracer } from './bosun/stepTracer';
|
|
6
|
-
import { Tracer } from './bosun';
|
|
6
|
+
import { StepRegistry, Tracer } from './bosun/tracer';
|
|
7
7
|
/**
|
|
8
8
|
* Represents a basic model name for LLMs.
|
|
9
9
|
*/
|
|
10
10
|
export type BasicModel = 'o3-mini-2025-01-31' | 'o1-preview-2024-09-12' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4.1-2025-04-14' | 'o1-2024-12-17' | (string & {});
|
|
11
11
|
export interface LlmAdapter {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @param systemPrompt – rendered system prompt
|
|
14
|
+
* @param messages – stringified {@link Conversation}
|
|
15
|
+
* @param schema - optional Zod schema to pass to the model. Will overwrite any schema set in adapter options.
|
|
16
|
+
* @returns LLM Response
|
|
17
|
+
*/
|
|
18
|
+
generateResponse: (systemPrompt: string, messages: string, schema?: ZodTypeAny) => Promise<string>;
|
|
13
19
|
/** Returns adapter's configuration/options for tracing */
|
|
14
20
|
getOptions: () => unknown;
|
|
15
21
|
}
|
|
@@ -123,6 +129,7 @@ type WorkflowStep<CTX> = StringLLMStep<CTX> | JsonLLMStep<CTX, any> | Programmat
|
|
|
123
129
|
export interface WorkflowConfig<CTX> {
|
|
124
130
|
onError: (error: string, ctx: CTX) => Promise<unknown>;
|
|
125
131
|
steps?: WorkflowStep<CTX>[];
|
|
132
|
+
name?: string;
|
|
126
133
|
beforeEachCallback?: () => Promise<unknown>;
|
|
127
134
|
}
|
|
128
135
|
interface StepBuilder<CTX> {
|
|
@@ -209,7 +216,8 @@ export interface AIEngine {
|
|
|
209
216
|
}
|
|
210
217
|
/**
|
|
211
218
|
* Represents a conversation between a user and an AI agent.
|
|
212
|
-
* Provides methods to manage the conversation flow, format messages, and convert the conversation
|
|
219
|
+
* Provides methods to manage the conversation flow, format messages, and convert the conversation
|
|
220
|
+
* to a string representation.
|
|
213
221
|
*
|
|
214
222
|
* @example
|
|
215
223
|
* ```typescript
|
|
@@ -279,8 +287,9 @@ export interface Conversation {
|
|
|
279
287
|
*/
|
|
280
288
|
getProposedReply: () => string | null;
|
|
281
289
|
/**
|
|
282
|
-
* Gets the history of all messages in the conversation.
|
|
283
|
-
*
|
|
290
|
+
* Gets the history of all messages in the conversation. Returns {@link Message} rather than
|
|
291
|
+
* {@link ConversationMessage} because none of the {@link ConversationMessage} properties should
|
|
292
|
+
* be accessed outside of the {@link Conversation} context.
|
|
284
293
|
* @returns An array of Message objects representing the conversation history.
|
|
285
294
|
*/
|
|
286
295
|
getHistory: () => Message[];
|
|
@@ -304,8 +313,10 @@ export interface EngineConfig {
|
|
|
304
313
|
/**
|
|
305
314
|
* Optional token storage object that provides access to authentication tokens.
|
|
306
315
|
* @property {object} tokenStorage - Object containing method to retrieve token.
|
|
307
|
-
* @property {() => Promise<string | null>} tokenStorage.getToken - Function that returns a
|
|
308
|
-
*
|
|
316
|
+
* @property {() => Promise<string | null>} tokenStorage.getToken - Function that returns a
|
|
317
|
+
* promise resolving to an authentication token or null.
|
|
318
|
+
*
|
|
319
|
+
* @deprecated use {@link LlmAdapter} (which has its onw storage) in `model` field instead
|
|
309
320
|
*/
|
|
310
321
|
tokenStorage?: {
|
|
311
322
|
getToken: () => Promise<string | null>;
|
|
@@ -320,8 +331,15 @@ export interface EngineConfig {
|
|
|
320
331
|
sendAction?: SendAction;
|
|
321
332
|
/** traces received prompt, rendered prompt, context and other useful info about LLM execution */
|
|
322
333
|
stepTracer?: StepTracer;
|
|
323
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* registers steps in workflow
|
|
336
|
+
* @deprecated use `stepRegistry` instead
|
|
337
|
+
**/
|
|
324
338
|
tracer?: Tracer;
|
|
339
|
+
/**
|
|
340
|
+
* registers steps in workflow
|
|
341
|
+
*/
|
|
342
|
+
stepRegistry?: StepRegistry;
|
|
325
343
|
}
|
|
326
344
|
/**
|
|
327
345
|
* Creates an AI Engine with the given configuration.
|
package/build/lib/ai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/lib/ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/lib/ai.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAc,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAmC,UAAU,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ports.createAIEngine = createAIEngine;
|
|
7
7
|
exports.createConversation = createConversation;
|
|
8
8
|
exports.getStepBuilder = getStepBuilder;
|
|
9
|
+
// cspell:words lstripBlocks
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
9
11
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
10
12
|
const zod_1 = require("zod");
|
|
11
13
|
const action_1 = require("./bosun/action");
|
|
14
|
+
const stepTracer_1 = require("./bosun/stepTracer");
|
|
12
15
|
const tracer_1 = require("./bosun/tracer");
|
|
13
16
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
14
17
|
const openai_1 = require("./llm-adapters/openai");
|
|
@@ -38,11 +41,11 @@ const openai_1 = require("./llm-adapters/openai");
|
|
|
38
41
|
* ```
|
|
39
42
|
*/
|
|
40
43
|
function createAIEngine(cfg = {}) {
|
|
41
|
-
const stepTracer = cfg.stepTracer || undefined;
|
|
42
44
|
const logger = cfg.logger || globalThis.console;
|
|
43
|
-
const
|
|
45
|
+
const stepTracer = cfg.stepTracer || (0, stepTracer_1.createStubStepTracer)(logger);
|
|
46
|
+
const registry = cfg.stepRegistry || cfg.tracer || (0, tracer_1.createStubRegistry)(logger);
|
|
44
47
|
// tokenStorage is used by the default adapter to fetch API keys (backwards compatible)
|
|
45
|
-
function createWorkflow({ onError, steps = [], }) {
|
|
48
|
+
function createWorkflow({ onError, steps = [], name = 'workflow', }) {
|
|
46
49
|
steps.forEach(addStepToTracer);
|
|
47
50
|
return {
|
|
48
51
|
run: async (messages, ctx, beforeEach) => {
|
|
@@ -51,13 +54,12 @@ function createAIEngine(cfg = {}) {
|
|
|
51
54
|
await beforeEach?.(messages, ctx, state);
|
|
52
55
|
const step = state.getStep();
|
|
53
56
|
if (state.isTerminated()) {
|
|
54
|
-
logger.
|
|
57
|
+
logger.log('AI Engine, run terminated');
|
|
55
58
|
break;
|
|
56
59
|
}
|
|
57
60
|
if (!step.runIf || (await step.runIf(messages, ctx))) {
|
|
58
61
|
const action = (0, action_1.makeAction)(cfg.sendAction, 'AI', step.name);
|
|
59
62
|
await action('started');
|
|
60
|
-
logger.debug(`AI Engine: Step: ${step.name}`);
|
|
61
63
|
if ('prompt' in step) {
|
|
62
64
|
await runStep(step, messages, ctx, state);
|
|
63
65
|
}
|
|
@@ -67,6 +69,7 @@ function createAIEngine(cfg = {}) {
|
|
|
67
69
|
await action('completed');
|
|
68
70
|
}
|
|
69
71
|
} while (state.next());
|
|
72
|
+
await stepTracer.flush();
|
|
70
73
|
return state.isTerminated() ? null : messages.getProposedReply();
|
|
71
74
|
},
|
|
72
75
|
addStep(step) {
|
|
@@ -76,7 +79,7 @@ function createAIEngine(cfg = {}) {
|
|
|
76
79
|
};
|
|
77
80
|
function addStepToTracer(step) {
|
|
78
81
|
if ('prompt' in step) {
|
|
79
|
-
|
|
82
|
+
registry.addStep({
|
|
80
83
|
name: step.name,
|
|
81
84
|
prompt: (0, tracer_1.stdPrompt)(step.prompt),
|
|
82
85
|
type: 'text',
|
|
@@ -87,6 +90,8 @@ function createAIEngine(cfg = {}) {
|
|
|
87
90
|
async function runStep(step, conversation, ctx, state) {
|
|
88
91
|
const stepTrace = {
|
|
89
92
|
name: step.name,
|
|
93
|
+
workflowId: name,
|
|
94
|
+
workflowRunId: state.runId,
|
|
90
95
|
model: typeof step.model === 'string'
|
|
91
96
|
? step.model
|
|
92
97
|
: step.model
|
|
@@ -103,16 +108,13 @@ function createAIEngine(cfg = {}) {
|
|
|
103
108
|
let response = null;
|
|
104
109
|
let prompt = typeof step.prompt === 'string' ? step.prompt : await step.prompt.content();
|
|
105
110
|
stepTrace.receivedPrompt = prompt;
|
|
106
|
-
logger.debug('AI Engine: context', ctx);
|
|
107
|
-
logger.debug('AI Engine: messages', conversation.toString({ ignoreAddedMessages: step.ignoreAddedMessages }));
|
|
108
111
|
prompt = renderPrompt(prompt, ctx);
|
|
109
112
|
stepTrace.renderedPrompt = prompt;
|
|
110
113
|
const stringifiedMessages = conversation.toString({
|
|
111
114
|
ignoreAddedMessages: step.ignoreAddedMessages,
|
|
112
115
|
});
|
|
113
|
-
logger.debug('AI Engine stringified: ' + stringifiedMessages);
|
|
114
116
|
stepTrace.stringifiedConversation = stringifiedMessages;
|
|
115
|
-
stepTracer
|
|
117
|
+
stepTracer.addStepTrace(stepTrace);
|
|
116
118
|
if ('schema' in step) {
|
|
117
119
|
response = await runLLM(step.model, prompt, stringifiedMessages, step.schema);
|
|
118
120
|
response = step.schema.parse(JSON.parse(response));
|
|
@@ -123,14 +125,14 @@ function createAIEngine(cfg = {}) {
|
|
|
123
125
|
if (!response) {
|
|
124
126
|
throw new Error('No response from OpenAI');
|
|
125
127
|
}
|
|
126
|
-
logger.
|
|
128
|
+
logger.log(`AI Engine, executing ${step.name}`);
|
|
127
129
|
await step.execute(response, conversation, ctx, state);
|
|
128
130
|
}
|
|
129
131
|
catch (error) {
|
|
130
132
|
await (step.onError
|
|
131
133
|
? step.onError(error.message, ctx)
|
|
132
134
|
: onError(error.message, ctx));
|
|
133
|
-
stepTracer
|
|
135
|
+
stepTracer.addStepTrace(stepTrace);
|
|
134
136
|
state.terminate();
|
|
135
137
|
}
|
|
136
138
|
}
|
|
@@ -141,7 +143,7 @@ function createAIEngine(cfg = {}) {
|
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
catch (error) {
|
|
144
|
-
logger.error(`AI Engine
|
|
146
|
+
logger.error(`AI Engine, error in dumb step ${step.name}: ${error.message}`);
|
|
145
147
|
await (step.onError
|
|
146
148
|
? step.onError(error.message, ctx)
|
|
147
149
|
: onError(error.message, ctx));
|
|
@@ -150,20 +152,9 @@ function createAIEngine(cfg = {}) {
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
async function runLLM(model, systemPrompt, messages, schema) {
|
|
153
|
-
logger.debug('AI Engine: model:', typeof model === 'string' || model === undefined
|
|
154
|
-
? model || 'gpt-4o-2024-08-06'
|
|
155
|
-
: '[adapter]');
|
|
156
|
-
logger.debug('----------- RENDERED PROMPT ---------------');
|
|
157
|
-
logger.debug(systemPrompt);
|
|
158
|
-
logger.debug('-------------------------------------------');
|
|
159
155
|
const adapter = typeof model === 'string' || model === undefined
|
|
160
156
|
? (0, openai_1.createOpenAIAdapter)(getOpenAiOptions(model || 'gpt-4o-2024-08-06', schema), {
|
|
161
|
-
tokenStorage: cfg.tokenStorage ||
|
|
162
|
-
{
|
|
163
|
-
async getToken() {
|
|
164
|
-
return process.env.OPENAI_API_KEY ?? null;
|
|
165
|
-
},
|
|
166
|
-
},
|
|
157
|
+
tokenStorage: cfg.tokenStorage || fallBackTokenStorage,
|
|
167
158
|
})
|
|
168
159
|
: model;
|
|
169
160
|
return adapter.generateResponse(systemPrompt, messages, schema);
|
|
@@ -177,6 +168,11 @@ function createAIEngine(cfg = {}) {
|
|
|
177
168
|
},
|
|
178
169
|
};
|
|
179
170
|
}
|
|
171
|
+
const fallBackTokenStorage = {
|
|
172
|
+
async getToken() {
|
|
173
|
+
return process.env.OPENAI_API_KEY ?? null;
|
|
174
|
+
},
|
|
175
|
+
};
|
|
180
176
|
class WorkflowState {
|
|
181
177
|
logger;
|
|
182
178
|
steps;
|
|
@@ -186,9 +182,11 @@ class WorkflowState {
|
|
|
186
182
|
attempts = new Map();
|
|
187
183
|
rewinder = 0;
|
|
188
184
|
lastRewindTo = 0;
|
|
185
|
+
runId;
|
|
189
186
|
constructor(logger, steps) {
|
|
190
187
|
this.logger = logger;
|
|
191
188
|
this.steps = steps;
|
|
189
|
+
this.runId = (0, crypto_1.randomUUID)();
|
|
192
190
|
}
|
|
193
191
|
terminate() {
|
|
194
192
|
this.logger.debug('AI Engine: Terminating conversation...');
|
|
@@ -2,7 +2,7 @@ import { Message } from '../ai';
|
|
|
2
2
|
import { Logger, Scheduler } from '../interfaces';
|
|
3
3
|
import { SendAction } from './action';
|
|
4
4
|
import { Context } from './context';
|
|
5
|
-
import { Tracer } from './tracer';
|
|
5
|
+
import { StepRegistry, Tracer } from './tracer';
|
|
6
6
|
import { StepTracer } from './stepTracer';
|
|
7
7
|
/**
|
|
8
8
|
* Bosun is a UI for testing Recombine AI agents. It enables testing complex agent interactions with
|
|
@@ -26,7 +26,9 @@ import { StepTracer } from './stepTracer';
|
|
|
26
26
|
*/
|
|
27
27
|
type DefaultContext = Record<string, any>;
|
|
28
28
|
export interface TestAgentFactoryProps<CTX extends DefaultContext = DefaultContext> {
|
|
29
|
+
/** @deprecated */
|
|
29
30
|
tracer: Tracer;
|
|
31
|
+
stepRegistry: StepRegistry;
|
|
30
32
|
stepTracer: StepTracer;
|
|
31
33
|
logger: Logger;
|
|
32
34
|
scheduler: Scheduler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/agent.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AACzC,MAAM,WAAW,qBAAqB,CAAC,GAAG,SAAS,cAAc,GAAG,cAAc;IAC9E,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CA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* from './context';
|
|
3
3
|
export * from './agent';
|
|
4
4
|
export * from './mock';
|
|
5
|
-
export { PromptString, StepTraceDef, Tracer } from './tracer';
|
|
5
|
+
export { PromptString, StepTraceDef, StepDef, Tracer, StepRegistry } from './tracer';
|
|
6
6
|
export * from './stepTracer';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACpF,cAAc,cAAc,CAAA"}
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
import { ZodSchema } from 'zod';
|
|
2
2
|
import { PromptFile } from '../prompt-fs';
|
|
3
|
+
import { Logger } from '../interfaces';
|
|
3
4
|
export type StepTrace = {
|
|
5
|
+
/** Unique ID for the trace */
|
|
6
|
+
traceId?: string;
|
|
7
|
+
callId?: string;
|
|
8
|
+
/** Optional, to group traces within a broader context */
|
|
9
|
+
scopeId?: string;
|
|
10
|
+
/** Just unique name */
|
|
11
|
+
workflowId: string;
|
|
12
|
+
/** Unique ID for the workflow run */
|
|
13
|
+
workflowRunId: string;
|
|
4
14
|
name: string;
|
|
5
15
|
renderedPrompt?: string;
|
|
6
|
-
receivedContext?: unknown;
|
|
7
|
-
receivedPrompt?: string | PromptFile;
|
|
16
|
+
receivedContext?: Record<string, unknown> | unknown;
|
|
17
|
+
receivedPrompt?: string | PromptFile | File;
|
|
8
18
|
stringifiedConversation?: string;
|
|
9
19
|
schema?: ZodSchema;
|
|
10
20
|
model?: string;
|
|
21
|
+
/** Raw response from LLM or function call result */
|
|
22
|
+
response?: string;
|
|
23
|
+
/** Timestamp in milliseconds */
|
|
24
|
+
createdAt?: number;
|
|
11
25
|
};
|
|
12
26
|
export interface StepTracer {
|
|
13
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Add a step trace
|
|
29
|
+
* @param trace The step trace to add
|
|
30
|
+
*/
|
|
31
|
+
addStepTrace(trace: StepTrace): void;
|
|
32
|
+
/**
|
|
33
|
+
* Flush any buffered traces to storage
|
|
34
|
+
*/
|
|
35
|
+
flush(): Promise<void>;
|
|
14
36
|
}
|
|
37
|
+
export declare function createStubStepTracer(logger: Logger): {
|
|
38
|
+
addStepTrace(trace: StepTrace): void;
|
|
39
|
+
flush(): Promise<void>;
|
|
40
|
+
};
|
|
15
41
|
//# sourceMappingURL=stepTracer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stepTracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/stepTracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"stepTracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/stepTracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAGtC,MAAM,MAAM,SAAS,GAAG;IACpB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAA;IAErB,IAAI,EAAE,MAAM,CAAA;IAEZ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAA;IACnD,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAAA;IAE3C,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,WAAW,UAAU;IACvB;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAEpC;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM;wBAEvB,SAAS;;EA2BpC"}
|
|
@@ -1,2 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createStubStepTracer = createStubStepTracer;
|
|
7
|
+
const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
|
|
8
|
+
function createStubStepTracer(logger) {
|
|
9
|
+
return {
|
|
10
|
+
addStepTrace(trace) {
|
|
11
|
+
logger.log(`StepTrace: ${trace.name}, in workflow (${trace.workflowId})`);
|
|
12
|
+
if (trace.model) {
|
|
13
|
+
logger.log(`StepTrace, model: ${trace.model}`);
|
|
14
|
+
}
|
|
15
|
+
if (trace.schema) {
|
|
16
|
+
logger.log('StepTrace, schema:', (0, zod_to_json_schema_1.default)(trace.schema));
|
|
17
|
+
}
|
|
18
|
+
if (trace.receivedContext) {
|
|
19
|
+
logger.log('StepTrace, context:', trace.receivedContext);
|
|
20
|
+
}
|
|
21
|
+
if (trace.stringifiedConversation) {
|
|
22
|
+
logger.log(`StepTrace, messages: \n${trace.stringifiedConversation}`);
|
|
23
|
+
}
|
|
24
|
+
if (trace.renderedPrompt) {
|
|
25
|
+
logger.log('------------ RENDERED PROMPT ----------\n' +
|
|
26
|
+
trace.renderedPrompt +
|
|
27
|
+
'\n---------------------------------------');
|
|
28
|
+
}
|
|
29
|
+
if (trace.response) {
|
|
30
|
+
logger.log(`StepTrace, LLM response:\n${trace.response}`);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async flush() { },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -5,15 +5,30 @@ export interface PromptString {
|
|
|
5
5
|
type: 'string';
|
|
6
6
|
content: () => Promise<string>;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
8
|
+
export interface StepDef {
|
|
9
9
|
name: string;
|
|
10
10
|
type: 'streaming-response' | 'streaming-detect' | 'text';
|
|
11
11
|
prompt: PromptFile | PromptString;
|
|
12
12
|
schema?: ZodSchema;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated use `StepDef` instead
|
|
16
|
+
*/
|
|
17
|
+
export type StepTraceDef = StepDef;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use `StepRegistry` instead
|
|
20
|
+
*/
|
|
21
|
+
export type Tracer = StepRegistry;
|
|
22
|
+
export interface StepRegistry {
|
|
23
|
+
addStep(def: StepDef): void;
|
|
16
24
|
}
|
|
17
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated use `createStubRegistry` instead
|
|
27
|
+
*/
|
|
28
|
+
export declare const createConsoleTracer: typeof createStubRegistry;
|
|
29
|
+
/**
|
|
30
|
+
* a stub registry, that just prints step in logs
|
|
31
|
+
*/
|
|
32
|
+
export declare function createStubRegistry(logger: Logger): Tracer;
|
|
18
33
|
export declare function stdPrompt(prompt: PromptFile | string): PromptFile | PromptString;
|
|
19
34
|
//# sourceMappingURL=tracer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,OAAO;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,MAAM,CAAA;IACxD,MAAM,EAAE,UAAU,GAAG,YAAY,CAAA;IACjC,MAAM,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAAA;AAElC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,YAAY,CAAA;AAEjC,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAC9B;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,2BAAqB,CAAA;AAErD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,6BAQpD"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConsoleTracer =
|
|
3
|
+
exports.createConsoleTracer = void 0;
|
|
4
|
+
exports.createStubRegistry = createStubRegistry;
|
|
4
5
|
exports.stdPrompt = stdPrompt;
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use `createStubRegistry` instead
|
|
8
|
+
*/
|
|
9
|
+
exports.createConsoleTracer = createStubRegistry;
|
|
10
|
+
/**
|
|
11
|
+
* a stub registry, that just prints step in logs
|
|
12
|
+
*/
|
|
13
|
+
function createStubRegistry(logger) {
|
|
6
14
|
return {
|
|
7
15
|
addStep(def) {
|
|
8
|
-
logger.debug('
|
|
16
|
+
logger.debug('Step registry, step added:', def);
|
|
9
17
|
},
|
|
10
18
|
};
|
|
11
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/openai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/openai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAIvC,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,8BAA8B,EAAE,UAAU,GAAG,QAAQ,CAAC,CAAA;AAE3F,MAAM,MAAM,iBAAiB,GAAG;IAC5B,YAAY,EAAE;QAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;KAAE,CAAA;CAC3D,CAAA;AAID,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,iBAAiB,GACxB,UAAU,CA8CZ"}
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createOpenAIAdapter = createOpenAIAdapter;
|
|
4
7
|
const openai_1 = require("openai");
|
|
8
|
+
const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
|
|
5
9
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
10
|
function createOpenAIAdapter(options, auth) {
|
|
7
11
|
return {
|
|
8
12
|
getOptions: () => options,
|
|
9
|
-
async generateResponse(systemPrompt, messages,
|
|
13
|
+
async generateResponse(systemPrompt, messages, schema) {
|
|
14
|
+
const finalOptions = { ...options };
|
|
15
|
+
if (schema) {
|
|
16
|
+
finalOptions.response_format = {
|
|
17
|
+
type: 'json_schema',
|
|
18
|
+
json_schema: {
|
|
19
|
+
name: 'detector_response',
|
|
20
|
+
schema: (0, zod_to_json_schema_1.default)(schema),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
10
24
|
const apiKey = await auth.tokenStorage.getToken();
|
|
11
25
|
if (!apiKey) {
|
|
12
26
|
throw new Error('OpenAI API key is not set');
|
|
13
27
|
}
|
|
14
28
|
if (apiKey === '__TESTING__') {
|
|
15
29
|
await delay(100);
|
|
16
|
-
if (
|
|
17
|
-
return 'canned response';
|
|
30
|
+
if (options.response_format && 'json_schema' in options.response_format) {
|
|
31
|
+
return JSON.stringify({ message: 'canned response', reasons: [] });
|
|
18
32
|
}
|
|
19
|
-
return
|
|
33
|
+
return 'canned response';
|
|
20
34
|
}
|
|
21
35
|
const client = new openai_1.OpenAI({ apiKey });
|
|
22
36
|
const response = await client.chat.completions.create({
|
|
@@ -24,7 +38,7 @@ function createOpenAIAdapter(options, auth) {
|
|
|
24
38
|
{ role: 'system', content: systemPrompt },
|
|
25
39
|
{ role: 'user', content: messages },
|
|
26
40
|
],
|
|
27
|
-
...
|
|
41
|
+
...finalOptions,
|
|
28
42
|
});
|
|
29
43
|
const content = response.choices[0]?.message?.content;
|
|
30
44
|
if (!content) {
|
package/build/lib/prompt-fs.js
CHANGED
|
@@ -13,7 +13,7 @@ function createLocalFS(cfg) {
|
|
|
13
13
|
return {
|
|
14
14
|
type: 'file',
|
|
15
15
|
content: async () => {
|
|
16
|
-
logger.
|
|
16
|
+
logger.log('Local FS, loading prompt:', path);
|
|
17
17
|
return fs_1.default.promises.readFile((0, path_1.join)(cfg.basePath, path), 'utf-8');
|
|
18
18
|
},
|
|
19
19
|
path,
|
package/changelog.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
### 0.8.
|
|
3
|
+
### 0.8.5 → 0.8.6 (unstable)
|
|
4
|
+
|
|
5
|
+
- FIX: Added "schema" option to LlmAdapter.generateResponse()
|
|
6
|
+
|
|
7
|
+
### 0.8.4 → 0.8.5 (unstable)
|
|
8
|
+
|
|
9
|
+
- Clean up logging in favor of StepTracer, which logs everything by default,
|
|
10
|
+
- Deprecated `Tracer` in favor of `StepRegistry` – just renaming.
|
|
11
|
+
|
|
12
|
+
### 0.8.3 → 0.8.4 (unstable)
|
|
13
|
+
|
|
14
|
+
- Enhanced `StepTrace` type with `workflowId` and `workflowRunId` for better trace context.
|
|
15
|
+
- Updated `WorkflowConfig` to include an optional `name` of workflow.
|
|
16
|
+
|
|
17
|
+
### 0.8.2 → 0.8.3 (unstable)
|
|
4
18
|
|
|
5
19
|
- Fixed missing tokenStorage in `LlmAdapter`.
|
|
6
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recombine-ai/engine",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "Recombine AI engine for creating conversational AI agents",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"lint-staged": {
|
|
46
46
|
"*.{ts,tsx,js,jsx,json,md}": [
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"npm run format",
|
|
48
|
+
"npm run lint:fix"
|
|
49
49
|
]
|
|
50
50
|
}
|
|
51
51
|
}
|