@recombine-ai/engine 1.0.0-beta-2 → 1.0.0-beta-4

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 (62) hide show
  1. package/.github/workflows/linting.yml +2 -2
  2. package/.github/workflows/publish.yml +1 -2
  3. package/build/index.d.ts +2 -2
  4. package/build/index.d.ts.map +1 -1
  5. package/build/index.js +3 -2
  6. package/build/lib/bosun/action.d.ts.map +1 -1
  7. package/build/lib/bosun/action.js +1 -0
  8. package/build/lib/bosun/agent.d.ts +1 -4
  9. package/build/lib/bosun/agent.d.ts.map +1 -1
  10. package/build/lib/engine.d.ts +31 -0
  11. package/build/lib/engine.d.ts.map +1 -0
  12. package/build/lib/interfaces/adapter.d.ts +13 -0
  13. package/build/lib/interfaces/adapter.d.ts.map +1 -0
  14. package/build/lib/interfaces/conversation.d.ts +63 -0
  15. package/build/lib/interfaces/conversation.d.ts.map +1 -0
  16. package/build/lib/interfaces/engine.d.ts +65 -0
  17. package/build/lib/interfaces/engine.d.ts.map +1 -0
  18. package/build/lib/interfaces/engine.js +2 -0
  19. package/build/lib/interfaces/index.d.ts +8 -0
  20. package/build/lib/interfaces/index.d.ts.map +1 -0
  21. package/build/lib/interfaces/index.js +23 -0
  22. package/build/lib/{interfaces.d.ts → interfaces/other.d.ts} +1 -1
  23. package/build/lib/interfaces/other.d.ts.map +1 -0
  24. package/build/lib/interfaces/other.js +2 -0
  25. package/build/lib/interfaces/steps.d.ts +84 -0
  26. package/build/lib/interfaces/steps.d.ts.map +1 -0
  27. package/build/lib/interfaces/steps.js +2 -0
  28. package/build/lib/{stream/interfaces.d.ts → interfaces/stream.d.ts} +8 -22
  29. package/build/lib/interfaces/stream.d.ts.map +1 -0
  30. package/build/lib/interfaces/stream.js +2 -0
  31. package/build/lib/interfaces/workflow.d.ts +44 -0
  32. package/build/lib/interfaces/workflow.d.ts.map +1 -0
  33. package/build/lib/interfaces/workflow.js +2 -0
  34. package/build/lib/llm-adapters/mock.d.ts +1 -1
  35. package/build/lib/llm-adapters/mock.d.ts.map +1 -1
  36. package/build/lib/llm-adapters/openai-stream.d.ts +1 -1
  37. package/build/lib/llm-adapters/openai.d.ts +1 -1
  38. package/build/lib/llm-adapters/openai.d.ts.map +1 -1
  39. package/build/lib/stream/engine.d.ts +3 -0
  40. package/build/lib/stream/engine.d.ts.map +1 -0
  41. package/build/lib/stream/engine.js +174 -0
  42. package/build/lib/stream/index.d.ts +2 -2
  43. package/build/lib/stream/index.d.ts.map +1 -1
  44. package/build/lib/stream/index.js +2 -2
  45. package/build/lib/stream/token-transformers.d.ts +6 -0
  46. package/build/lib/stream/token-transformers.d.ts.map +1 -0
  47. package/build/lib/stream/token-transformers.js +62 -0
  48. package/changelog.md +1 -0
  49. package/package.json +1 -1
  50. package/build/lib/ai.d.ts +0 -286
  51. package/build/lib/ai.d.ts.map +0 -1
  52. package/build/lib/interfaces.d.ts.map +0 -1
  53. package/build/lib/stream/ai.d.ts +0 -3
  54. package/build/lib/stream/ai.d.ts.map +0 -1
  55. package/build/lib/stream/ai.js +0 -224
  56. package/build/lib/stream/filter.d.ts +0 -6
  57. package/build/lib/stream/filter.d.ts.map +0 -1
  58. package/build/lib/stream/filter.js +0 -20
  59. package/build/lib/stream/interfaces.d.ts.map +0 -1
  60. /package/build/lib/{ai.js → engine.js} +0 -0
  61. /package/build/lib/{interfaces.js → interfaces/adapter.js} +0 -0
  62. /package/build/lib/{stream/interfaces.js → interfaces/conversation.js} +0 -0
@@ -1,4 +1,4 @@
1
- name: lint & typecheck
1
+ name: lint & test
2
2
 
3
3
  on:
4
4
  push:
@@ -20,7 +20,7 @@ jobs:
20
20
  cache: 'npm'
21
21
 
22
22
  - name: Install dependencies
23
- run: npm ci --legacy-peer-deps
23
+ run: npm ci
24
24
 
25
25
  - name: Run lint
26
26
  run: npm run lint --silent
@@ -33,8 +33,7 @@ jobs:
33
33
  run: npm install -g npm@latest
34
34
 
35
35
  - name: 'Install dependencies'
36
- # TODO rm --legacy-peer-deps as soon as zod stuff fixed
37
- run: npm ci --legacy-peer-deps
36
+ run: npm ci
38
37
 
39
38
  - name: 'Build'
40
39
  run: npm run build
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './lib/ai';
1
+ export * from './lib/interfaces/index';
2
+ export * from './lib/engine';
2
3
  export * from './lib/stream';
3
4
  export * from './lib/schedule';
4
- export * from './lib/interfaces';
5
5
  export * from './lib/bosun';
6
6
  export * from './lib/prompt-fs';
7
7
  export * from './lib/llm-adapters';
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAA;AAEtC,cAAc,cAAc,CAAA;AAE5B,cAAc,cAAc,CAAA;AAE5B,cAAc,gBAAgB,CAAA;AAE9B,cAAc,aAAa,CAAA;AAE3B,cAAc,iBAAiB,CAAA;AAE/B,cAAc,oBAAoB,CAAA"}
package/build/index.js CHANGED
@@ -14,10 +14,11 @@ 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
- __exportStar(require("./lib/ai"), exports);
17
+ // Hmm.. why it should be /index explicitly?
18
+ __exportStar(require("./lib/interfaces/index"), exports);
19
+ __exportStar(require("./lib/engine"), exports);
18
20
  __exportStar(require("./lib/stream"), exports);
19
21
  __exportStar(require("./lib/schedule"), exports);
20
- __exportStar(require("./lib/interfaces"), exports);
21
22
  __exportStar(require("./lib/bosun"), exports);
22
23
  __exportStar(require("./lib/prompt-fs"), exports);
23
24
  __exportStar(require("./lib/llm-adapters"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/action.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,IAEhD,SAAS,MAAM,EACf,MAAM,MAAM,EACZ,QAAQ,MAAM,OAAO,CAAC,OAAO,CAAC,mBAiBrC;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAM1D,MAAM,CAAC,OAAO,CAAC,mBAQhD"}
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/lib/bosun/action.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,IAEhD,SAAS,MAAM,EACf,MAAM,MAAM,EACZ,QAAQ,MAAM,OAAO,CAAC,OAAO,CAAC,mBAiBrC;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAM1D,MAAM,CAAC,OAAO,CAAC,mBAQhD"}
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // TODO drop this!
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.makeActionWrapper = makeActionWrapper;
4
5
  exports.makeAction = makeAction;
@@ -1,6 +1,4 @@
1
- import { Message } from '../ai';
2
- import { Logger, Scheduler } from '../interfaces';
3
- import { SendAction } from './action';
1
+ import { Logger, Message, Scheduler } from '../interfaces';
4
2
  import { Context } from './context';
5
3
  import { StepRegistry } from './step-registry';
6
4
  import { StepTracer } from './step-tracer';
@@ -46,7 +44,6 @@ export interface TestAgentFactoryProps<CTX extends DefaultContext = DefaultConte
46
44
  scheduler: Scheduler;
47
45
  getMessages: () => Message[];
48
46
  sendMessage: (message: string | Message) => Promise<void>;
49
- sendAction: SendAction;
50
47
  ctx: Context<CTX>;
51
48
  }
52
49
  export interface TestTextAgent {
@@ -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,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,KAAK,cAAc,GAAG,M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AAO,CAAC,GAAG,CAAC,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACtC,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACxC,UAAU,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAClC,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACnD;AACD,MAAM,WAAW,cAAc;IAC3B,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACtC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACjC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACnC,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEhD,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACvC;AAED,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,cAAc,CAAA;AAEtD,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI,CACtE,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAC9B,OAAO,CAAC,SAAS,CAAC,CAAA;AAEvB,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,uBAE5F"}
@@ -0,0 +1,31 @@
1
+ import { Conversation, Message, StepBuilder } from './interfaces';
2
+ import { AIEngine, EngineConfig } from './interfaces/engine';
3
+ /**
4
+ * Creates an AI Engine with the given configuration.
5
+ *
6
+ * The AI Engine provides utilities for creating and running conversational workflows
7
+ * with large language models, specifically OpenAI GPT models.
8
+ *
9
+ * @returns An AIEngine instance.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const engine = createAIEngine({
14
+ * logger: customLogger,
15
+ * });
16
+ *
17
+ * const workflow = await engine.createWorkflow(
18
+ * engine.createStep({
19
+ * name: 'generate-response',
20
+ * prompt: engine.loadFile('prompts/response.txt'),
21
+ * execute: (response) => conversation.setProposedReply(response)
22
+ * })
23
+ * );
24
+ *
25
+ * const reply = await workflow.run(conversation);
26
+ * ```
27
+ */
28
+ export declare function createAIEngine<CTX extends object>(cfg?: EngineConfig): AIEngine<CTX>;
29
+ export declare function createConversation(initialMessages?: Message[]): Conversation;
30
+ export declare function getStepBuilder<CTX = unknown>(): StepBuilder<CTX>;
31
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/lib/engine.ts"],"names":[],"mappings":"AAIA,OAAO,EAEH,YAAY,EAGZ,OAAO,EAEP,WAAW,EAKd,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,GAAE,YAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC,CA+NxF;AAuDD,wBAAgB,kBAAkB,CAAC,eAAe,GAAE,OAAO,EAAO,GAAG,YAAY,CA2ChF;AAED,wBAAgB,cAAc,CAAC,GAAG,GAAG,OAAO,KAAK,WAAW,CAAC,GAAG,CAAC,CAEhE"}
@@ -0,0 +1,13 @@
1
+ import * as Zod from 'zod';
2
+ export interface LlmAdapter {
3
+ /**
4
+ * @param systemPrompt - rendered system prompt
5
+ * @param messages - stringified {@link Conversation}
6
+ * @param schema - optional Zod schema to pass to the model. Will overwrite any schema set in adapter options.
7
+ * @returns LLM Response
8
+ */
9
+ generateResponse: (systemPrompt: string, messages: string, schema?: Zod.ZodType) => Promise<string>;
10
+ /** Returns adapter's configuration/options for tracing */
11
+ getOptions: () => unknown;
12
+ }
13
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAE1B,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"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Represents a conversation between a user and an AI agent.
3
+ * Provides methods to manage the conversation flow, format messages, and convert the conversation
4
+ * to a string representation.
5
+ */
6
+ export interface Conversation {
7
+ /**
8
+ * Sets the default formatter to stringify messages when toString is called.
9
+ * @param formatter - A function that takes a message and returns a formatted string.
10
+ */
11
+ setDefaultFormatter: (formatter: (message: Message) => string) => void;
12
+ /**
13
+ * Converts the conversation to a string representation to be fed to an LLM.
14
+ * @param filter - A function that filters messages based on certain criteria.
15
+ * @example
16
+ * @returns The string representation of the conversation.
17
+ */
18
+ toString: (options?: {
19
+ ignoreAddedMessages?: boolean;
20
+ }) => string;
21
+ /**
22
+ * Adds a message from a specified sender to the conversation.
23
+ * @param message - The message to add to the conversation.
24
+ */
25
+ addMessage: (message: Message, opts?: {
26
+ formatter?: (message: Message) => string;
27
+ }) => void;
28
+ /**
29
+ * Sets a custom formatter for proposed messages.
30
+ * @param formatter - A function that takes a message string and returns a formatted string.
31
+ */
32
+ setProposedMessageFormatter: (formatter: (message: string) => string) => void;
33
+ /**
34
+ * Sets a proposed reply message.
35
+ * @param message - The proposed reply message.
36
+ */
37
+ setProposedReply: (message: string) => void;
38
+ /**
39
+ * Gets the current proposed reply message.
40
+ * @returns The proposed reply message, or null if none exists.
41
+ */
42
+ getProposedReply: () => string | null;
43
+ /**
44
+ * Gets the history of all messages in the conversation. Returns {@link Message} rather than
45
+ * {@link ConversationMessage} because none of the {@link ConversationMessage} properties should
46
+ * be accessed outside of the {@link Conversation} context.
47
+ * @returns An array of Message objects representing the conversation history.
48
+ */
49
+ getHistory: () => Message[];
50
+ }
51
+ /**
52
+ * Represents a message in a conversation between a user and an agent, or a system message.
53
+ * Messages can contain text and optionally an image URL. To be used in the {@link Conversation} interface.
54
+ */
55
+ export interface Message {
56
+ /** The sender of the message, which can be one of the following: 'user', 'agent', or 'system' */
57
+ sender: 'user' | 'agent' | 'system';
58
+ /** The text content of the message */
59
+ text: string;
60
+ /** Optional URL of an image associated with the message */
61
+ imageUrl?: string;
62
+ }
63
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/conversation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,mBAAmB,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,KAAK,IAAI,CAAA;IAEtE;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,MAAM,CAAA;IAEjE;;;OAGG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAE3F;;;OAGG;IACH,2BAA2B,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,KAAK,IAAI,CAAA;IAE7E;;;OAGG;IACH,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAE3C;;;OAGG;IACH,gBAAgB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IAErC;;;;;OAKG;IACH,UAAU,EAAE,MAAM,OAAO,EAAE,CAAA;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACpB,iGAAiG;IACjG,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;IACnC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB"}
@@ -0,0 +1,65 @@
1
+ import { Environment } from 'nunjucks';
2
+ import { StepRegistry, StepTracer } from '../bosun';
3
+ import { Conversation, Message } from './conversation';
4
+ import { Logger } from './other';
5
+ import { StepBuilder } from './steps';
6
+ import { Workflow, WorkflowConfig } from './workflow';
7
+ /**
8
+ * The main interface for the AI Engine.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { createAIEngine } from '@recombine-ai/engine'
13
+ *
14
+ * Create a new AI engine instance
15
+ * const ai = createAIEngine({
16
+ * // engine configuration, see EngineConfig
17
+ * })
18
+ *
19
+ * // create a conversation to be used in workflow.run(), see Conversation
20
+ * const conversation = ai.createConversation(messages)
21
+ * // create a workflow, see WorkflowConfig
22
+ * const workflow = ai.createWorkflow({steps})
23
+ * workflow.run(conversation)
24
+ * ```
25
+ */
26
+ export interface AIEngine<CTX extends object> {
27
+ /**
28
+ * Creates a workflow from a sequence of steps.
29
+ * @param config - common parameters for a workflow
30
+ * @returns AI workflow Workflow.
31
+ */
32
+ createWorkflow: (config: WorkflowConfig<CTX>) => Workflow<CTX>;
33
+ /**
34
+ * Creates a new conversation instance.
35
+ * @param messages - Optional initial messages for the conversation.
36
+ * @returns A new Conversation object.
37
+ */
38
+ createConversation: (messages?: Message[]) => Conversation;
39
+ /**
40
+ * Get the function to create steps to use with {@link WorkflowConfig#steps}
41
+ * if you want to define steps outside of workflow.
42
+ */
43
+ getStepBuilder(): StepBuilder<CTX>;
44
+ /**
45
+ * Renders a prompt string using Nunjucks templating engine.
46
+ * @param prompt - The prompt string to render.
47
+ * @param context - Optional context object to use for rendering the prompt.
48
+ * @returns The rendered prompt string.
49
+ */
50
+ renderPrompt: (prompt: string, context?: object) => string;
51
+ }
52
+ /**
53
+ * Configuration options for the Engine.
54
+ */
55
+ export interface EngineConfig {
56
+ /** Optional logger instance for handling log messages. */
57
+ logger?: Logger;
58
+ /** traces received prompt, rendered prompt, context and other useful info about LLM execution */
59
+ stepTracer?: StepTracer;
60
+ /** registers steps in workflow to be available in Bosun IDE */
61
+ stepRegistry?: StepRegistry;
62
+ /** Optional nunjucks Environment to customize prompt rendering. */
63
+ nunjucksEnv?: Environment;
64
+ }
65
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAErD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,QAAQ,CAAC,GAAG,SAAS,MAAM;IACxC;;;;OAIG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAA;IAE9D;;;;OAIG;IACH,kBAAkB,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,YAAY,CAAA;IAE1D;;;OAGG;IACH,cAAc,IAAI,WAAW,CAAC,GAAG,CAAC,CAAA;IAElC;;;;;OAKG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iGAAiG;IACjG,UAAU,CAAC,EAAE,UAAU,CAAA;IAEvB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B,oEAAoE;IACpE,WAAW,CAAC,EAAE,WAAW,CAAA;CAC5B"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export * from './other';
2
+ export * from './conversation';
3
+ export * from './steps';
4
+ export * from './stream';
5
+ export * from './workflow';
6
+ export * from './adapter';
7
+ export * from './engine';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./other"), exports);
18
+ __exportStar(require("./conversation"), exports);
19
+ __exportStar(require("./steps"), exports);
20
+ __exportStar(require("./stream"), exports);
21
+ __exportStar(require("./workflow"), exports);
22
+ __exportStar(require("./adapter"), exports);
23
+ __exportStar(require("./engine"), exports);
@@ -23,4 +23,4 @@ export interface Scheduler {
23
23
  */
24
24
  clearAllPendingActions: (phone: string) => Promise<unknown>;
25
25
  }
26
- //# sourceMappingURL=interfaces.d.ts.map
26
+ //# sourceMappingURL=other.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"other.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/other.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACnB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC7B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAClC;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1E,MAAM,WAAW,SAAS;IACtB;;;;;OAKG;IACH,cAAc,EAAE,CACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,KAC1C,cAAc,CAAA;IAEnB;;OAEG;IACH,sBAAsB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9D"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,84 @@
1
+ import * as Zod from 'zod';
2
+ import { PromptFile } from '../prompt-fs';
3
+ import { LlmAdapter } from './adapter';
4
+ import { Conversation } from './conversation';
5
+ import { WorkflowControls } from './workflow';
6
+ export interface BasicStep<CTX> {
7
+ /** Step name */
8
+ name: string;
9
+ /** Determines if the step should be run or not */
10
+ runIf?: (messages: Conversation, ctx: CTX) => boolean | Promise<boolean>;
11
+ /**
12
+ * When provided, throws an error if the step is invoked more times than `maxAttempts`.
13
+ * Number of attempts taken is reset when the flow passed the step that was rewinding.
14
+ */
15
+ maxAttempts?: number;
16
+ /** Error handler called if an error occurred during in `execute` function */
17
+ onError?: (error: string, ctx: CTX) => Promise<unknown>;
18
+ }
19
+ export interface ProgrammaticStep<CTX> extends BasicStep<CTX> {
20
+ /** Content of the step */
21
+ execute: (messages: Conversation, ctx: CTX, workflow: WorkflowControls) => Promise<unknown>;
22
+ }
23
+ export interface LLMStep<CTX> extends BasicStep<CTX> {
24
+ /** LLM adapter to use */
25
+ model: LlmAdapter;
26
+ /**
27
+ * Prompt can be a simple string or a link to a file, loaded with `loadFile` function which
28
+ * takes a path to the file relative to `src/use-cases` directory. Should be Nunjucks-compatible.
29
+ */
30
+ prompt: string | PromptFile;
31
+ /**
32
+ * Do not put messages that were added via {@link Conversation.addMessage} into the prompt.
33
+ */
34
+ ignoreAddedMessages?: boolean;
35
+ }
36
+ export interface JsonLLMStep<CTX, Schema extends Zod.ZodType> extends LLMStep<CTX> {
37
+ /**
38
+ * Defines the expected structure of the LLM's output. Accepts ZodSchema. When provided, the
39
+ * LLM's response is validated and parsed according to this schema ensuring reliable structured
40
+ * output.
41
+ */
42
+ schema: Schema;
43
+ /**
44
+ * Function to execute with the LLM's response. Use {@link setProposedReply} to use the LLM's output as the proposed reply.
45
+ * Or use combination of {@link getProposedReply} and {@link setProposedReply} to substitute parts of the string.
46
+ * @example
47
+ * ```
48
+ * // Use LLM output directly as reply
49
+ * execute: (reply) => messages.setProposedReply(reply)
50
+ *
51
+ * // Substitute tokens in LLM output
52
+ * execute: (reply) => {
53
+ * const withLink = reply.replace('<PAYMENT_LINK>', 'https://payment.example.com/123')
54
+ * messages.setProposedReply(withLink)
55
+ * }
56
+ * ```
57
+ */
58
+ execute: (reply: Zod.infer<Schema>, conversation: Conversation, ctx: CTX, workflowControls: WorkflowControls) => Promise<unknown>;
59
+ }
60
+ export interface StringLLMStep<CTX> extends LLMStep<CTX> {
61
+ /**
62
+ * Function to execute with the LLM's response. Use {@link setProposedReply} to use the LLM's output as the proposed reply.
63
+ * Or use combination of {@link getProposedReply} and {@link setProposedReply} to substitute parts of the string.
64
+ * @example
65
+ * ```
66
+ * // Use LLM output directly as reply
67
+ * execute: (reply) => messages.setProposedReply(reply)
68
+ *
69
+ * // Substitute tokens in LLM output
70
+ * execute: (reply) => {
71
+ * const withLink = reply.replace('<PAYMENT_LINK>', 'https://payment.example.com/123')
72
+ * messages.setProposedReply(withLink)
73
+ * }
74
+ * ```
75
+ */
76
+ execute: (reply: string, conversation: Conversation, ctx: CTX, workflowControls?: WorkflowControls) => Promise<unknown>;
77
+ }
78
+ export type WorkflowStep<CTX> = StringLLMStep<CTX> | JsonLLMStep<CTX, any> | ProgrammaticStep<CTX>;
79
+ export interface StepBuilder<CTX> {
80
+ <Schema extends Zod.ZodType>(step: JsonLLMStep<CTX, Schema>): JsonLLMStep<CTX, Schema>;
81
+ (step: StringLLMStep<CTX>): StringLLMStep<CTX>;
82
+ (step: ProgrammaticStep<CTX>): ProgrammaticStep<CTX>;
83
+ }
84
+ //# sourceMappingURL=steps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/steps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA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,CAAC,KAAK,CAAC,MAAM,CAAC,EACxB,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,gBAAgB,EAAE,gBAAgB,KACjC,OAAO,CAAC,OAAO,CAAC,CAAA;CACxB;AAED,MAAM,WAAW,aAAa,CAAC,GAAG,CAAE,SAAQ,OAAO,CAAC,GAAG,CAAC;IACpD;;;;;;;;;;;;;;OAcG;IACH,OAAO,EAAE,CACL,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,gBAAgB,CAAC,EAAE,gBAAgB,KAClC,OAAO,CAAC,OAAO,CAAC,CAAA;CACxB;AAED,MAAM,MAAM,YAAY,CAAC,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;AAElG,MAAM,WAAW,WAAW,CAAC,GAAG;IAC5B,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACtF,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;IAC9C,CAAC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;CACvD"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,10 @@
1
- import { Message } from '../ai';
2
- import { Logger } from '../interfaces';
1
+ import { Message } from './conversation';
3
2
  import { StepRegistry, StepTracer } from '../bosun';
4
3
  import { PromptFile } from '../prompt-fs';
5
- export interface AIStreamEngine {
4
+ import { Logger } from './other';
5
+ export interface AIStreamEngine<CTX extends {}> {
6
6
  /** creates streaming workflow */
7
- createWorkflow: <CTX extends {}>(config: WorkflowConfig<CTX>) => {
7
+ createWorkflow: (config: StreamWorkflowConfig<CTX>) => {
8
8
  /**
9
9
  * Runs streaming workflow (starts stream)
10
10
  * @param messages
@@ -22,7 +22,7 @@ export interface StreamingEngineConfig {
22
22
  /** traces received prompt, rendered prompt, context and other useful info about LLM execution */
23
23
  stepTracer?: StepTracer;
24
24
  }
25
- export interface WorkflowConfig<CTX> {
25
+ export interface StreamWorkflowConfig<CTX> {
26
26
  /** name of the workflow and its only step to appear in Bosun and in traces */
27
27
  name: string;
28
28
  /** system prompt */
@@ -30,15 +30,13 @@ export interface WorkflowConfig<CTX> {
30
30
  /** LLM model with streaming support */
31
31
  model: LlmStreamAdapter;
32
32
  onError: (error: Error | string, ctx: CTX) => Promise<void>;
33
- /** filter out some tokens on the fly */
34
- filter?: ProgrammaticFilter;
33
+ /** transform LLM-tokens on the fly */
34
+ tokenTransformers?: (() => TransformStream<string, string>)[];
35
35
  }
36
36
  export interface Transcript {
37
37
  responseChunks: ResponseChunk[];
38
38
  messages: Message[];
39
39
  readonly currentResponse: string;
40
- readonly mainResponseFinished: boolean;
41
- markMainResponseFinished(): void;
42
40
  toString(ignoreDirectives?: boolean): string;
43
41
  getConversation(): Message[];
44
42
  }
@@ -52,20 +50,8 @@ export interface LlmStreamAdapter {
52
50
  /** Returns adapter's configuration/options for tracing */
53
51
  getOptions: () => unknown;
54
52
  }
55
- export interface ProgrammaticFilter {
56
- shouldStartFiltering: (state: Transcript, newToken: string) => boolean;
57
- onNewToken: (state: Transcript, filteredTokens: string[]) => {
58
- action: 'CONTINUE_FILTERING';
59
- } | {
60
- action: 'RELEASE_TOKENS';
61
- tokens: string[];
62
- };
63
- onStreamEnd: (state: Transcript, filteredTokens: string[]) => {
64
- tokensToRelease: string[];
65
- };
66
- }
67
53
  export interface ResponseChunk {
68
54
  role: 'agent' | 'system';
69
55
  delta: string;
70
56
  }
71
- //# sourceMappingURL=interfaces.d.ts.map
57
+ //# sourceMappingURL=stream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;IACvB,cAAc,EAAE,aAAa,EAAE,CAAA;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5C,eAAe,IAAI,OAAO,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC7B;;;;OAIG;IACH,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;IAC3F,0DAA0D;IAC1D,UAAU,EAAE,MAAM,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;CAChB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,44 @@
1
+ import { Conversation } from './conversation';
2
+ import { WorkflowStep } from './steps';
3
+ export interface WorkflowControls {
4
+ /**
5
+ * Terminates the workflow, preventing further steps from being executed.
6
+ */
7
+ terminate: () => void;
8
+ /**
9
+ * Rewinds the workflow execution to a specific step.
10
+ * @param step - The name of the step to rewind to
11
+ */
12
+ rewindTo: (step: string) => void;
13
+ }
14
+ export type BeforeEachStep<CTX> = (conversation: Conversation, ctx: CTX, workflowControls?: WorkflowControls) => Promise<void>;
15
+ /**
16
+ * An AI workflow composed of steps.
17
+ */
18
+ export interface Workflow<CTX> {
19
+ /**
20
+ * Runs the workflow with a given conversation context.
21
+ * Executes steps sequentially until completion or termination.
22
+ * @param conversation - The conversation context for the workflow
23
+ * @param contextProvider - A provider function for the context that will be passed to all steps and to all prompts in those steps
24
+ * @param beforeEach - A callback, that runs before each step
25
+ * @returns The proposed reply if workflow completes, or null if terminated
26
+ */
27
+ run: (conversation: Conversation, contextProvider: (() => CTX) | (() => Promise<CTX>), beforeEach?: BeforeEachStep<CTX>) => Promise<string | null>;
28
+ }
29
+ /**
30
+ * Config object to be used in {@link AIEngine#createWorkflow}
31
+ */
32
+ export interface WorkflowConfig<CTX> {
33
+ /** workflow name, to use in traces, defaults to 'workflow' */
34
+ name?: string;
35
+ /** a function that will run once, if any of the steps going to be executed */
36
+ beforeExecute?: (ctx: CTX) => Promise<void>;
37
+ /** a function that will run once, if any of the steps was executed */
38
+ afterExecute?: (ctx: CTX) => Promise<void>;
39
+ /** common error handler for workflow */
40
+ onError: (error: string, ctx: CTX) => Promise<unknown>;
41
+ /** workflow steps {@link ProgrammaticStep}, {@link StringLLMStep} or {@link JsonLLMStep} */
42
+ steps?: WorkflowStep<CTX>[];
43
+ }
44
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,SAAS,EAAE,MAAM,IAAI,CAAA;IAErB;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAED,MAAM,MAAM,cAAc,CAAC,GAAG,IAAI,CAC9B,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,gBAAgB,CAAC,EAAE,gBAAgB,KAClC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,GAAG;IACzB;;;;;;;OAOG;IACH,GAAG,EAAE,CACD,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EACnD,UAAU,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,KAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,GAAG;IAC/B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,8EAA8E;IAC9E,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1C,wCAAwC;IACxC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACtD,4FAA4F;IAC5F,KAAK,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,EAAE,CAAA;CAC9B"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
- import type { LlmAdapter } from '../ai';
1
+ import { LlmAdapter } from '../interfaces';
2
2
  export declare function createMockAdapter(): LlmAdapter;
3
3
  //# sourceMappingURL=mock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,wBAAgB,iBAAiB,IAAI,UAAU,CAU9C"}
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,wBAAgB,iBAAiB,IAAI,UAAU,CAU9C"}
@@ -1,6 +1,6 @@
1
1
  import { OpenAI } from 'openai';
2
2
  import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
3
- import { LlmStreamAdapter } from '../stream/interfaces';
3
+ import { LlmStreamAdapter } from '../interfaces/stream';
4
4
  export type OpenAIChatOptions = Omit<ChatCompletionCreateParamsBase, 'messages' | 'response_format' | 'stream'>;
5
5
  export declare function createOpenAIStreamAdapter(options: OpenAIChatOptions, client?: OpenAI): LlmStreamAdapter;
6
6
  //# sourceMappingURL=openai-stream.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { OpenAI } from 'openai';
2
2
  import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
3
- import type { LlmAdapter } from '../ai';
3
+ import { LlmAdapter } from '../interfaces';
4
4
  type OpenaiOptionsToSend = Omit<ChatCompletionCreateParamsBase, 'messages' | 'stream'>;
5
5
  export type OpenAIChatOptions = Omit<OpenaiOptionsToSend, 'response_format'>;
6
6
  export declare function createOpenAIAdapter(options: OpenAIChatOptions, client?: OpenAI): LlmAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,KAAK,mBAAmB,GAAG,IAAI,CAAC,8BAA8B,EAAE,UAAU,GAAG,QAAQ,CAAC,CAAA;AACtF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;AAE5E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAe,GAAG,UAAU,CAmCjG"}
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-adapters/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAA;AAElF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,KAAK,mBAAmB,GAAG,IAAI,CAAC,8BAA8B,EAAE,UAAU,GAAG,QAAQ,CAAC,CAAA;AACtF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;AAE5E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAe,GAAG,UAAU,CAmCjG"}
@@ -0,0 +1,3 @@
1
+ import { AIStreamEngine, StreamingEngineConfig } from '../interfaces';
2
+ export declare function createAIStreamEngine<CTX extends {}>(cfg: StreamingEngineConfig): AIStreamEngine<CTX>;
3
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/lib/stream/engine.ts"],"names":[],"mappings":"AAKA,OAAO,EAGH,cAAc,EAEd,qBAAqB,EAGxB,MAAM,eAAe,CAAA;AAItB,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,EAAE,EAC/C,GAAG,EAAE,qBAAqB,GAC3B,cAAc,CAAC,GAAG,CAAC,CAgJrB"}