@recombine-ai/engine 0.11.3 → 1.0.0-beta-1
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/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/lib/ai.d.ts +14 -60
- package/build/lib/ai.d.ts.map +1 -1
- package/build/lib/ai.js +21 -76
- package/build/lib/bosun/agent.d.ts +4 -6
- package/build/lib/bosun/agent.d.ts.map +1 -1
- package/build/lib/bosun/{apiCallTracer.d.ts → api-call-tracer.d.ts} +1 -1
- package/build/lib/bosun/api-call-tracer.d.ts.map +1 -0
- package/build/lib/bosun/context.d.ts.map +1 -1
- package/build/lib/bosun/context.js +0 -2
- package/build/lib/bosun/{conversationalTracer.d.ts → conversational-tracer.d.ts} +4 -2
- package/build/lib/bosun/conversational-tracer.d.ts.map +1 -0
- package/build/lib/bosun/index.d.ts +4 -4
- package/build/lib/bosun/index.d.ts.map +1 -1
- package/build/lib/bosun/index.js +3 -3
- package/build/lib/bosun/{tracer.d.ts → step-registry.d.ts} +4 -16
- package/build/lib/bosun/step-registry.d.ts.map +1 -0
- package/build/lib/bosun/{tracer.js → step-registry.js} +0 -5
- package/build/lib/bosun/{stepTracer.d.ts → step-tracer.d.ts} +3 -3
- package/build/lib/bosun/step-tracer.d.ts.map +1 -0
- package/build/lib/bosun/{stepTracer.js → step-tracer.js} +2 -5
- package/build/lib/llm-adapters/index.d.ts +2 -0
- package/build/lib/llm-adapters/index.d.ts.map +1 -1
- package/build/lib/llm-adapters/index.js +4 -0
- package/build/lib/llm-adapters/mock.d.ts +3 -0
- package/build/lib/llm-adapters/mock.d.ts.map +1 -0
- package/build/lib/llm-adapters/mock.js +14 -0
- package/build/lib/llm-adapters/openai-stream.d.ts +6 -0
- package/build/lib/llm-adapters/openai-stream.d.ts.map +1 -0
- package/build/lib/llm-adapters/openai-stream.js +30 -0
- package/build/lib/llm-adapters/openai.d.ts +5 -7
- package/build/lib/llm-adapters/openai.d.ts.map +1 -1
- package/build/lib/llm-adapters/openai.js +3 -19
- package/build/lib/stream/ai.d.ts +3 -0
- package/build/lib/stream/ai.d.ts.map +1 -0
- package/build/lib/stream/ai.js +245 -0
- package/build/lib/stream/filter.d.ts +6 -0
- package/build/lib/stream/filter.d.ts.map +1 -0
- package/build/lib/stream/filter.js +20 -0
- package/build/lib/stream/get-client.d.ts +15 -0
- package/build/lib/stream/get-client.d.ts.map +1 -0
- package/build/lib/stream/get-client.js +166 -0
- package/build/lib/stream/index.d.ts +4 -0
- package/build/lib/stream/index.d.ts.map +1 -0
- package/build/lib/stream/index.js +8 -0
- package/build/lib/stream/interfaces.d.ts +73 -0
- package/build/lib/stream/interfaces.d.ts.map +1 -0
- package/build/lib/stream/interfaces.js +2 -0
- package/changelog.md +17 -0
- package/package.json +3 -3
- package/build/lib/bosun/apiCallTracer.d.ts.map +0 -1
- package/build/lib/bosun/conversationalTracer.d.ts.map +0 -1
- package/build/lib/bosun/stepTracer.d.ts.map +0 -1
- package/build/lib/bosun/tracer.d.ts.map +0 -1
- /package/build/lib/bosun/{apiCallTracer.js → api-call-tracer.js} +0 -0
- /package/build/lib/bosun/{conversationalTracer.js → conversational-tracer.js} +0 -0
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AAExB,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,aAAa,CAAA;AAE3B,cAAc,iBAAiB,CAAA;AAE/B,cAAc,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AAExB,cAAc,cAAc,CAAA;AAE5B,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,aAAa,CAAA;AAE3B,cAAc,iBAAiB,CAAA;AAE/B,cAAc,oBAAoB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./lib/ai"), exports);
|
|
18
|
+
__exportStar(require("./lib/stream"), exports);
|
|
18
19
|
__exportStar(require("./lib/schedule"), exports);
|
|
19
20
|
__exportStar(require("./lib/interfaces"), exports);
|
|
20
21
|
__exportStar(require("./lib/bosun"), exports);
|
package/build/lib/ai.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import nunjucks from 'nunjucks';
|
|
1
2
|
import * as Zod from 'zod';
|
|
2
3
|
import { Logger } from './interfaces';
|
|
3
|
-
import { SendAction } from './bosun/action';
|
|
4
4
|
import { PromptFile } from './prompt-fs';
|
|
5
|
-
import { StepTracer } from './bosun/
|
|
6
|
-
import { StepRegistry
|
|
7
|
-
/**
|
|
8
|
-
* Represents a basic model name for LLMs.
|
|
9
|
-
*/
|
|
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 & {});
|
|
5
|
+
import { StepTracer } from './bosun/step-tracer';
|
|
6
|
+
import { StepRegistry } from './bosun/step-registry';
|
|
11
7
|
export interface LlmAdapter {
|
|
12
8
|
/**
|
|
13
9
|
* @param systemPrompt - rendered system prompt
|
|
@@ -15,7 +11,7 @@ export interface LlmAdapter {
|
|
|
15
11
|
* @param schema - optional Zod schema to pass to the model. Will overwrite any schema set in adapter options.
|
|
16
12
|
* @returns LLM Response
|
|
17
13
|
*/
|
|
18
|
-
generateResponse: (systemPrompt: string, messages: string, schema?: Zod.
|
|
14
|
+
generateResponse: (systemPrompt: string, messages: string, schema?: Zod.ZodType) => Promise<string>;
|
|
19
15
|
/** Returns adapter's configuration/options for tracing */
|
|
20
16
|
getOptions: () => unknown;
|
|
21
17
|
}
|
|
@@ -37,8 +33,8 @@ export interface ProgrammaticStep<CTX> extends BasicStep<CTX> {
|
|
|
37
33
|
execute: (messages: Conversation, ctx: CTX, workflow: WorkflowControls) => Promise<unknown>;
|
|
38
34
|
}
|
|
39
35
|
export interface LLMStep<CTX> extends BasicStep<CTX> {
|
|
40
|
-
/** LLM
|
|
41
|
-
model
|
|
36
|
+
/** LLM adapter to use */
|
|
37
|
+
model: LlmAdapter;
|
|
42
38
|
/**
|
|
43
39
|
* Prompt can be a simple string or a link to a file, loaded with `loadFile` function which
|
|
44
40
|
* takes a path to the file relative to `src/use-cases` directory. Should be Nunjucks-compatible.
|
|
@@ -60,7 +56,7 @@ export interface WorkflowControls {
|
|
|
60
56
|
*/
|
|
61
57
|
rewindTo: (step: string) => void;
|
|
62
58
|
}
|
|
63
|
-
export interface JsonLLMStep<CTX, Schema extends Zod.
|
|
59
|
+
export interface JsonLLMStep<CTX, Schema extends Zod.ZodType> extends LLMStep<CTX> {
|
|
64
60
|
/**
|
|
65
61
|
* Defines the expected structure of the LLM's output. Accepts ZodSchema. When provided, the
|
|
66
62
|
* LLM's response is validated and parsed according to this schema ensuring reliable structured
|
|
@@ -116,13 +112,6 @@ export interface Workflow<CTX> {
|
|
|
116
112
|
* @returns The proposed reply if workflow completes, or null if terminated
|
|
117
113
|
*/
|
|
118
114
|
run: (conversation: Conversation, contextProvider: (() => CTX) | (() => Promise<CTX>), beforeEach?: BeforeEachStep<CTX>) => Promise<string | null>;
|
|
119
|
-
/**
|
|
120
|
-
* Add a step to workflow
|
|
121
|
-
* @deprecated use {@link WorkflowConfig#steps} instead
|
|
122
|
-
*/
|
|
123
|
-
addStep<Schema extends Zod.ZodTypeAny>(step: JsonLLMStep<CTX, Schema>): void;
|
|
124
|
-
addStep(step: StringLLMStep<CTX>): void;
|
|
125
|
-
addStep(step: ProgrammaticStep<CTX>): void;
|
|
126
115
|
}
|
|
127
116
|
type WorkflowStep<CTX> = StringLLMStep<CTX> | JsonLLMStep<CTX, any> | ProgrammaticStep<CTX>;
|
|
128
117
|
/**
|
|
@@ -141,7 +130,7 @@ export interface WorkflowConfig<CTX> {
|
|
|
141
130
|
steps?: WorkflowStep<CTX>[];
|
|
142
131
|
}
|
|
143
132
|
interface StepBuilder<CTX> {
|
|
144
|
-
<Schema extends Zod.
|
|
133
|
+
<Schema extends Zod.ZodType>(step: JsonLLMStep<CTX, Schema>): JsonLLMStep<CTX, Schema>;
|
|
145
134
|
(step: StringLLMStep<CTX>): StringLLMStep<CTX>;
|
|
146
135
|
(step: ProgrammaticStep<CTX>): ProgrammaticStep<CTX>;
|
|
147
136
|
}
|
|
@@ -178,7 +167,7 @@ export interface AIEngine {
|
|
|
178
167
|
*/
|
|
179
168
|
createConversation: (messages?: Message[]) => Conversation;
|
|
180
169
|
/**
|
|
181
|
-
* Get the function to create steps to use with
|
|
170
|
+
* Get the function to create steps to use with {@link WorkflowConfig#steps}
|
|
182
171
|
* if you want to define steps outside of workflow.
|
|
183
172
|
*/
|
|
184
173
|
getStepBuilder<CTX>(): StepBuilder<CTX>;
|
|
@@ -188,7 +177,7 @@ export interface AIEngine {
|
|
|
188
177
|
* @param context - Optional context object to use for rendering the prompt.
|
|
189
178
|
* @returns The rendered prompt string.
|
|
190
179
|
*/
|
|
191
|
-
renderPrompt:
|
|
180
|
+
renderPrompt: (prompt: string, context?: object) => string;
|
|
192
181
|
}
|
|
193
182
|
/**
|
|
194
183
|
* Represents a conversation between a user and an AI agent.
|
|
@@ -196,18 +185,6 @@ export interface AIEngine {
|
|
|
196
185
|
* to a string representation.
|
|
197
186
|
*/
|
|
198
187
|
export interface Conversation {
|
|
199
|
-
/**
|
|
200
|
-
* Sets the name of the user in the conversation to be used in {@link toString}.
|
|
201
|
-
* @param name - The name to set for the user.
|
|
202
|
-
* @deprecated
|
|
203
|
-
*/
|
|
204
|
-
setUserName(name: string): void;
|
|
205
|
-
/**
|
|
206
|
-
* Sets the name of the AI agent in the conversation to be used in {@link toString}.
|
|
207
|
-
* @param name - The name to set for the agent.
|
|
208
|
-
* @deprecated
|
|
209
|
-
*/
|
|
210
|
-
setAgentName(name: string): void;
|
|
211
188
|
/**
|
|
212
189
|
* Sets the default formatter to stringify messages when toString is called.
|
|
213
190
|
* @param formatter - A function that takes a message and returns a formatted string.
|
|
@@ -268,36 +245,14 @@ export interface Message {
|
|
|
268
245
|
* Configuration options for the Engine.
|
|
269
246
|
*/
|
|
270
247
|
export interface EngineConfig {
|
|
271
|
-
/**
|
|
272
|
-
* Optional token storage object that provides access to authentication tokens.
|
|
273
|
-
* @property {object} tokenStorage - Object containing method to retrieve token.
|
|
274
|
-
* @property {() => Promise<string | null>} tokenStorage.getToken - Function that returns a
|
|
275
|
-
* promise resolving to an authentication token or null.
|
|
276
|
-
*
|
|
277
|
-
* @deprecated use {@link LlmAdapter} (which has its onw storage) in `model` field instead
|
|
278
|
-
*/
|
|
279
|
-
tokenStorage?: {
|
|
280
|
-
getToken: () => Promise<string | null>;
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Optional logger instance for handling log messages.
|
|
284
|
-
*/
|
|
248
|
+
/** Optional logger instance for handling log messages. */
|
|
285
249
|
logger?: Logger;
|
|
286
|
-
/**
|
|
287
|
-
* Optional function for sending actions.
|
|
288
|
-
*/
|
|
289
|
-
sendAction?: SendAction;
|
|
290
250
|
/** traces received prompt, rendered prompt, context and other useful info about LLM execution */
|
|
291
251
|
stepTracer?: StepTracer;
|
|
292
|
-
/**
|
|
293
|
-
* registers steps in workflow
|
|
294
|
-
* @deprecated use `stepRegistry` instead
|
|
295
|
-
**/
|
|
296
|
-
tracer?: Tracer;
|
|
297
|
-
/**
|
|
298
|
-
* registers steps in workflow
|
|
299
|
-
*/
|
|
252
|
+
/** registers steps in workflow to be available in Bosun IDE */
|
|
300
253
|
stepRegistry?: StepRegistry;
|
|
254
|
+
/** Optional nunjucks Environment to customize prompt rendering. */
|
|
255
|
+
nunjucksEnv?: nunjucks.Environment;
|
|
301
256
|
}
|
|
302
257
|
/**
|
|
303
258
|
* Creates an AI Engine with the given configuration.
|
|
@@ -325,7 +280,6 @@ export interface EngineConfig {
|
|
|
325
280
|
* ```
|
|
326
281
|
*/
|
|
327
282
|
export declare function createAIEngine(cfg?: EngineConfig): AIEngine;
|
|
328
|
-
declare function renderPrompt(prompt: string, context?: object): string;
|
|
329
283
|
export declare function createConversation(initialMessages?: Message[]): Conversation;
|
|
330
284
|
export declare function getStepBuilder<CTX = unknown>(): StepBuilder<CTX>;
|
|
331
285
|
export {};
|
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":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAmC,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,EAAiC,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEnF,MAAM,WAAW,UAAU;IACvB;;;;;OAKG;IACH,gBAAgB,EAAE,CACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,KACnB,OAAO,CAAC,MAAM,CAAC,CAAA;IACpB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,SAAS,CAAC,GAAG;IAC1B,iBAAiB;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BAAgB,cAAc,CAAC,GAAG,GAAG,OAAO,KAAK,WAAW,CAAC,GAAG,CAAC,CAEhE"}
|
package/build/lib/ai.js
CHANGED
|
@@ -43,11 +43,8 @@ exports.getStepBuilder = getStepBuilder;
|
|
|
43
43
|
const crypto_1 = require("crypto");
|
|
44
44
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
45
45
|
const Zod = __importStar(require("zod"));
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const tracer_1 = require("./bosun/tracer");
|
|
49
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
50
|
-
const openai_1 = require("./llm-adapters/openai");
|
|
46
|
+
const step_tracer_1 = require("./bosun/step-tracer");
|
|
47
|
+
const step_registry_1 = require("./bosun/step-registry");
|
|
51
48
|
/**
|
|
52
49
|
* Creates an AI Engine with the given configuration.
|
|
53
50
|
*
|
|
@@ -75,9 +72,8 @@ const openai_1 = require("./llm-adapters/openai");
|
|
|
75
72
|
*/
|
|
76
73
|
function createAIEngine(cfg = {}) {
|
|
77
74
|
const logger = cfg.logger || globalThis.console;
|
|
78
|
-
const stepTracer = cfg.stepTracer || (0,
|
|
79
|
-
const registry = cfg.stepRegistry ||
|
|
80
|
-
// tokenStorage is used by the default adapter to fetch API keys (backwards compatible)
|
|
75
|
+
const stepTracer = cfg.stepTracer || (0, step_tracer_1.createStubStepTracer)(logger);
|
|
76
|
+
const registry = cfg.stepRegistry || (0, step_registry_1.createStubRegistry)(logger);
|
|
81
77
|
function createWorkflow({ onError, beforeExecute, afterExecute, steps = [], name = 'workflow', }) {
|
|
82
78
|
steps.forEach(addStepToTracer);
|
|
83
79
|
return {
|
|
@@ -95,8 +91,6 @@ function createAIEngine(cfg = {}) {
|
|
|
95
91
|
}
|
|
96
92
|
if (!step.runIf || (await step.runIf(messages, ctx))) {
|
|
97
93
|
// TODO: drop actions, they are replaced by traces
|
|
98
|
-
const action = (0, action_1.makeAction)(cfg.sendAction, 'AI', step.name);
|
|
99
|
-
await action('started');
|
|
100
94
|
didExecute = true;
|
|
101
95
|
if (beforeExecute && !beforeHookExecuted) {
|
|
102
96
|
await beforeExecute(ctx);
|
|
@@ -108,7 +102,6 @@ function createAIEngine(cfg = {}) {
|
|
|
108
102
|
else {
|
|
109
103
|
await runProgrammaticStep(step, messages, ctx, state);
|
|
110
104
|
}
|
|
111
|
-
await action('completed');
|
|
112
105
|
}
|
|
113
106
|
} while (state.next());
|
|
114
107
|
if (afterExecute && didExecute) {
|
|
@@ -117,16 +110,12 @@ function createAIEngine(cfg = {}) {
|
|
|
117
110
|
await stepTracer.flush();
|
|
118
111
|
return state.isTerminated() ? null : messages.getProposedReply();
|
|
119
112
|
},
|
|
120
|
-
addStep(step) {
|
|
121
|
-
addStepToTracer(step);
|
|
122
|
-
steps.push(step);
|
|
123
|
-
},
|
|
124
113
|
};
|
|
125
114
|
function addStepToTracer(step) {
|
|
126
115
|
if ('prompt' in step) {
|
|
127
116
|
registry.addStep({
|
|
128
117
|
name: step.name,
|
|
129
|
-
prompt: (0,
|
|
118
|
+
prompt: (0, step_registry_1.stdPrompt)(step.prompt),
|
|
130
119
|
type: 'text',
|
|
131
120
|
schema: 'schema' in step ? step.schema : undefined,
|
|
132
121
|
});
|
|
@@ -138,13 +127,9 @@ function createAIEngine(cfg = {}) {
|
|
|
138
127
|
workflowId: name,
|
|
139
128
|
workflowRunId: state.runId,
|
|
140
129
|
createdAt: Date.now(),
|
|
141
|
-
model:
|
|
142
|
-
? step.model
|
|
143
|
-
: step.model
|
|
144
|
-
? JSON.stringify(step.model.getOptions())
|
|
145
|
-
: 'default',
|
|
130
|
+
model: JSON.stringify(step.model.getOptions()),
|
|
146
131
|
schema: 'schema' in step
|
|
147
|
-
? step.schema instanceof Zod.
|
|
132
|
+
? step.schema instanceof Zod.ZodType
|
|
148
133
|
? step.schema
|
|
149
134
|
: undefined
|
|
150
135
|
: undefined,
|
|
@@ -172,14 +157,14 @@ function createAIEngine(cfg = {}) {
|
|
|
172
157
|
if (err instanceof SyntaxError) {
|
|
173
158
|
logger.error(`AI-generated response is not valid JSON in step ${step.name}`, {
|
|
174
159
|
response: stringResponse,
|
|
175
|
-
schema:
|
|
160
|
+
schema: Zod.toJSONSchema(step.schema),
|
|
176
161
|
});
|
|
177
162
|
throw new Error(`Response is not valid JSON for step ${step.name}`);
|
|
178
163
|
}
|
|
179
164
|
else {
|
|
180
165
|
logger.error(`AI-generated response in step ${step.name} violates schema`, {
|
|
181
166
|
response: stringResponse,
|
|
182
|
-
schema:
|
|
167
|
+
schema: Zod.toJSONSchema(step.schema),
|
|
183
168
|
errors: step.schema.safeParse(parsedJsonResponse).error,
|
|
184
169
|
});
|
|
185
170
|
throw new Error(`Response validation failed for step ${step.name}`);
|
|
@@ -241,12 +226,18 @@ function createAIEngine(cfg = {}) {
|
|
|
241
226
|
}
|
|
242
227
|
}
|
|
243
228
|
async function runLLM(model, systemPrompt, messages, schema) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
229
|
+
return model.generateResponse(systemPrompt, messages, schema);
|
|
230
|
+
}
|
|
231
|
+
function renderPrompt(prompt, context) {
|
|
232
|
+
if (cfg.nunjucksEnv) {
|
|
233
|
+
return cfg.nunjucksEnv.renderString(prompt, context ?? {});
|
|
234
|
+
}
|
|
235
|
+
nunjucks_1.default.configure({
|
|
236
|
+
autoescape: false,
|
|
237
|
+
trimBlocks: true,
|
|
238
|
+
lstripBlocks: true,
|
|
239
|
+
});
|
|
240
|
+
return nunjucks_1.default.renderString(prompt, context ?? {});
|
|
250
241
|
}
|
|
251
242
|
return {
|
|
252
243
|
createWorkflow,
|
|
@@ -257,11 +248,6 @@ function createAIEngine(cfg = {}) {
|
|
|
257
248
|
},
|
|
258
249
|
};
|
|
259
250
|
}
|
|
260
|
-
const fallBackTokenStorage = {
|
|
261
|
-
async getToken() {
|
|
262
|
-
return process.env.OPENAI_API_KEY ?? null;
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
251
|
class WorkflowState {
|
|
266
252
|
logger;
|
|
267
253
|
steps;
|
|
@@ -312,41 +298,6 @@ class WorkflowState {
|
|
|
312
298
|
this.attempts.set(this.currentStep, attempt + 1);
|
|
313
299
|
}
|
|
314
300
|
}
|
|
315
|
-
function getOpenAiOptions(model, schema) {
|
|
316
|
-
const options = {
|
|
317
|
-
model,
|
|
318
|
-
};
|
|
319
|
-
const isReasoningModel = ['o3-', 'o1-', 'o1-preview-'].some((m) => model.startsWith(m));
|
|
320
|
-
if (isReasoningModel) {
|
|
321
|
-
if (!model.startsWith('o1-preview-')) {
|
|
322
|
-
options.reasoning_effort = 'high';
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
options.temperature = 0.1;
|
|
327
|
-
}
|
|
328
|
-
if (schema) {
|
|
329
|
-
options.response_format = {
|
|
330
|
-
type: 'json_schema',
|
|
331
|
-
json_schema: {
|
|
332
|
-
name: 'detector_response',
|
|
333
|
-
schema: (0, zod_to_json_schema_1.zodToJsonSchema)(schema),
|
|
334
|
-
},
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
options.response_format = { type: 'text' };
|
|
339
|
-
}
|
|
340
|
-
return options;
|
|
341
|
-
}
|
|
342
|
-
function renderPrompt(prompt, context) {
|
|
343
|
-
nunjucks_1.default.configure({
|
|
344
|
-
autoescape: false,
|
|
345
|
-
trimBlocks: true,
|
|
346
|
-
lstripBlocks: true,
|
|
347
|
-
});
|
|
348
|
-
return nunjucks_1.default.renderString(prompt, context || {});
|
|
349
|
-
}
|
|
350
301
|
function createConversation(initialMessages = []) {
|
|
351
302
|
const messages = initialMessages.map((msg) => ({
|
|
352
303
|
...msg,
|
|
@@ -387,12 +338,6 @@ function createConversation(initialMessages = []) {
|
|
|
387
338
|
setProposedReply: (message) => (proposedReply = message),
|
|
388
339
|
getProposedReply: () => proposedReply,
|
|
389
340
|
getHistory: () => messages,
|
|
390
|
-
setUserName: (name) => {
|
|
391
|
-
names.user = name;
|
|
392
|
-
},
|
|
393
|
-
setAgentName: (name) => {
|
|
394
|
-
names.agent = name;
|
|
395
|
-
},
|
|
396
341
|
};
|
|
397
342
|
}
|
|
398
343
|
function getStepBuilder() {
|
|
@@ -2,10 +2,10 @@ 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 { StepRegistry
|
|
6
|
-
import { StepTracer } from './
|
|
7
|
-
import { ApiCallTracer } from './
|
|
8
|
-
import { ConversationalTracer } from './
|
|
5
|
+
import { StepRegistry } from './step-registry';
|
|
6
|
+
import { StepTracer } from './step-tracer';
|
|
7
|
+
import { ApiCallTracer } from './api-call-tracer';
|
|
8
|
+
import { ConversationalTracer } from './conversational-tracer';
|
|
9
9
|
/**
|
|
10
10
|
* Bosun is a UI for testing Recombine AI agents. It enables testing complex agent interactions with
|
|
11
11
|
* multiple steps, error handling, and state management.
|
|
@@ -28,8 +28,6 @@ import { ConversationalTracer } from './conversationalTracer';
|
|
|
28
28
|
*/
|
|
29
29
|
type DefaultContext = Record<string, any>;
|
|
30
30
|
export interface TestAgentFactoryProps<CTX extends DefaultContext = DefaultContext> {
|
|
31
|
-
/** @deprecated */
|
|
32
|
-
tracer: Tracer;
|
|
33
31
|
stepRegistry: StepRegistry;
|
|
34
32
|
/**
|
|
35
33
|
* Optional tracer for recording API calls (e.g. generated OpenAPI SDK operations).
|
|
@@ -1 +1 @@
|
|
|
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,OAA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AAS,MAAM,CAAC,GACjB,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GACpB,CAAC,CAAC,KAAK,CAAC,GACR,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,GAC7B,KAAK,GACT,KAAK,CAAA;AAEX,cAAM,OAAO,CAAC,CAAC,SAAS,GAAG;;gBAIX,OAAO,EAAE,CAAC;IAItB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IACxF,GAAG,CAAC,UAAU,EAAE,CAAC,GAAG,IAAI;IAgBxB,GAAG;IAIH,gCAAgC;IAChC,IAAI,CAAC,UAAU,EAAE,CAAC;IAIlB,SAAS,GAAI,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,mBAG1C;IAED,sBAAsB,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM;IAIvD,sBAAsB,UAxCD,CAAC,KAAK,MAAM;CA2CpC;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,CAAC,cAEtD;AAED,KAAK,MAAM,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAEzC,KAAK,aAAa,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtD,YAAY,EAAE,aAAa,IAAI,OAAO,EAAE,CAAA"}
|
|
@@ -35,11 +35,9 @@ class Context {
|
|
|
35
35
|
return () => this.#listeners.delete(listener);
|
|
36
36
|
};
|
|
37
37
|
setPromptContextMapper(promptMapper) {
|
|
38
|
-
console.log('--- setPromptContextMapper ---');
|
|
39
38
|
this.#promptMapper = promptMapper;
|
|
40
39
|
}
|
|
41
40
|
getPromptContextMapper() {
|
|
42
|
-
console.log('--- getPromptContextMapper ---');
|
|
43
41
|
return this.#promptMapper;
|
|
44
42
|
}
|
|
45
43
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Logger } from '../interfaces';
|
|
2
2
|
/**
|
|
3
|
-
* Generic conversational event tracing. Represents “something happened in the conversation” (e.g.
|
|
3
|
+
* Generic conversational event tracing. Represents “something happened in the conversation” (e.g.
|
|
4
|
+
* message received/sent, streaming finished, handler invoked) that UIs may want to show on the same
|
|
5
|
+
* per-conversation timeline.
|
|
4
6
|
*/
|
|
5
7
|
export type ConversationalTrace = {
|
|
6
8
|
/** Unique ID for the trace */
|
|
@@ -29,4 +31,4 @@ export declare function createStubConversationalTracer(logger: Logger): {
|
|
|
29
31
|
addConversationalTrace(trace: ConversationalTrace): void;
|
|
30
32
|
flush(): Promise<void>;
|
|
31
33
|
};
|
|
32
|
-
//# sourceMappingURL=
|
|
34
|
+
//# sourceMappingURL=conversational-tracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversational-tracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/conversational-tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,wCAAwC;IACxC,SAAS,EACH,8BAA8B,GAC9B,8BAA8B,GAC9B,kBAAkB,GAClB,cAAc,GACd,oBAAoB,GACpB,kBAAkB,CAAA;IAExB,sDAAsD;IACtD,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IAEjD,qDAAqD;IACrD,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IAE5C,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAA;IAEf,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAA;IAEjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,WAAW,oBAAoB;IACjC,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAA;IACxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM;kCAEvB,mBAAmB;;EAKxD"}
|
|
@@ -2,8 +2,8 @@ export * from './action';
|
|
|
2
2
|
export * from './context';
|
|
3
3
|
export * from './agent';
|
|
4
4
|
export * from './mock';
|
|
5
|
-
export { PromptString,
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
5
|
+
export { PromptString, StepDef, StepRegistry } from './step-registry';
|
|
6
|
+
export * from './step-tracer';
|
|
7
|
+
export * from './api-call-tracer';
|
|
8
|
+
export * from './conversational-tracer';
|
|
9
9
|
//# 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,
|
|
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,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACrE,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA"}
|
package/build/lib/bosun/index.js
CHANGED
|
@@ -18,6 +18,6 @@ __exportStar(require("./action"), exports);
|
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
19
|
__exportStar(require("./agent"), exports);
|
|
20
20
|
__exportStar(require("./mock"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./step-tracer"), exports);
|
|
22
|
+
__exportStar(require("./api-call-tracer"), exports);
|
|
23
|
+
__exportStar(require("./conversational-tracer"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ZodType } from 'zod';
|
|
2
2
|
import { PromptFile } from '../prompt-fs';
|
|
3
3
|
import { Logger } from '../interfaces';
|
|
4
4
|
export interface PromptString {
|
|
@@ -9,26 +9,14 @@ export interface StepDef {
|
|
|
9
9
|
name: string;
|
|
10
10
|
type: 'streaming-response' | 'streaming-detect' | 'text';
|
|
11
11
|
prompt: PromptFile | PromptString;
|
|
12
|
-
schema?:
|
|
12
|
+
schema?: ZodType;
|
|
13
13
|
}
|
|
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
14
|
export interface StepRegistry {
|
|
23
15
|
addStep(def: StepDef): void;
|
|
24
16
|
}
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use `createStubRegistry` instead
|
|
27
|
-
*/
|
|
28
|
-
export declare const createConsoleTracer: typeof createStubRegistry;
|
|
29
17
|
/**
|
|
30
18
|
* a stub registry, that just prints step in logs
|
|
31
19
|
*/
|
|
32
|
-
export declare function createStubRegistry(logger: Logger):
|
|
20
|
+
export declare function createStubRegistry(logger: Logger): StepRegistry;
|
|
33
21
|
export declare function stdPrompt(prompt: PromptFile | string): PromptFile | PromptString;
|
|
34
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=step-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-registry.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/step-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,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,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAC9B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAM/D;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,6BAQpD"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConsoleTracer = void 0;
|
|
4
3
|
exports.createStubRegistry = createStubRegistry;
|
|
5
4
|
exports.stdPrompt = stdPrompt;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated use `createStubRegistry` instead
|
|
8
|
-
*/
|
|
9
|
-
exports.createConsoleTracer = createStubRegistry;
|
|
10
5
|
/**
|
|
11
6
|
* a stub registry, that just prints step in logs
|
|
12
7
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ZodType } from 'zod';
|
|
2
2
|
import { PromptFile } from '../prompt-fs';
|
|
3
3
|
import { Logger } from '../interfaces';
|
|
4
4
|
export type LlmUsage = {
|
|
@@ -22,7 +22,7 @@ export type StepTrace = {
|
|
|
22
22
|
receivedContext?: Record<string, unknown> | unknown;
|
|
23
23
|
receivedPrompt?: string | PromptFile | File;
|
|
24
24
|
stringifiedConversation?: string;
|
|
25
|
-
schema?:
|
|
25
|
+
schema?: ZodType;
|
|
26
26
|
model?: string;
|
|
27
27
|
llmUsage?: LlmUsage;
|
|
28
28
|
/** Raw response from LLM or function call result */
|
|
@@ -46,4 +46,4 @@ export declare function createStubStepTracer(logger: Logger): {
|
|
|
46
46
|
addStepTrace(trace: StepTrace): void;
|
|
47
47
|
flush(): Promise<void>;
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=step-tracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-tracer.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/step-tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAgB,MAAM,KAAK,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,MAAM,MAAM,QAAQ,GAAG;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACpB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,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,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAA;IAEjB,KAAK,CAAC,EAAE,KAAK,CAAA;CAChB,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,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createStubStepTracer = createStubStepTracer;
|
|
7
|
-
const
|
|
4
|
+
const zod_1 = require("zod");
|
|
8
5
|
function createStubStepTracer(logger) {
|
|
9
6
|
return {
|
|
10
7
|
addStepTrace(trace) {
|
|
@@ -13,7 +10,7 @@ function createStubStepTracer(logger) {
|
|
|
13
10
|
logger.log(`StepTrace, model: ${trace.model}`);
|
|
14
11
|
}
|
|
15
12
|
if (trace.schema) {
|
|
16
|
-
logger.log('StepTrace, schema:', (0,
|
|
13
|
+
logger.log('StepTrace, schema:', (0, zod_1.toJSONSchema)(trace.schema));
|
|
17
14
|
}
|
|
18
15
|
if (trace.receivedContext) {
|
|
19
16
|
logger.log('StepTrace, context:', trace.receivedContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,cAAc,QAAQ,CAAA"}
|
|
@@ -14,4 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createOpenAIStreamAdapter = void 0;
|
|
17
18
|
__exportStar(require("./openai"), exports);
|
|
19
|
+
var openai_stream_1 = require("./openai-stream");
|
|
20
|
+
Object.defineProperty(exports, "createOpenAIStreamAdapter", { enumerable: true, get: function () { return openai_stream_1.createOpenAIStreamAdapter; } });
|
|
21
|
+
__exportStar(require("./mock"), exports);
|