@simulacra-ai/core 0.0.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/README.md +232 -0
- package/dist/checkpoints/default-summarization-strategy.d.ts +13 -0
- package/dist/checkpoints/default-summarization-strategy.d.ts.map +1 -0
- package/dist/checkpoints/default-summarization-strategy.js +63 -0
- package/dist/checkpoints/default-summarization-strategy.js.map +1 -0
- package/dist/checkpoints/index.d.ts +3 -0
- package/dist/checkpoints/index.d.ts.map +1 -0
- package/dist/checkpoints/index.js +3 -0
- package/dist/checkpoints/index.js.map +1 -0
- package/dist/checkpoints/types.d.ts +32 -0
- package/dist/checkpoints/types.d.ts.map +1 -0
- package/dist/checkpoints/types.js +2 -0
- package/dist/checkpoints/types.js.map +1 -0
- package/dist/context-transformers/checkpoint-context-transformer.d.ts +13 -0
- package/dist/context-transformers/checkpoint-context-transformer.d.ts.map +1 -0
- package/dist/context-transformers/checkpoint-context-transformer.js +32 -0
- package/dist/context-transformers/checkpoint-context-transformer.js.map +1 -0
- package/dist/context-transformers/composite-context-transformer.d.ts +31 -0
- package/dist/context-transformers/composite-context-transformer.d.ts.map +1 -0
- package/dist/context-transformers/composite-context-transformer.js +41 -0
- package/dist/context-transformers/composite-context-transformer.js.map +1 -0
- package/dist/context-transformers/index.d.ts +6 -0
- package/dist/context-transformers/index.d.ts.map +1 -0
- package/dist/context-transformers/index.js +6 -0
- package/dist/context-transformers/index.js.map +1 -0
- package/dist/context-transformers/noop-context-transformer.d.ts +24 -0
- package/dist/context-transformers/noop-context-transformer.d.ts.map +1 -0
- package/dist/context-transformers/noop-context-transformer.js +26 -0
- package/dist/context-transformers/noop-context-transformer.js.map +1 -0
- package/dist/context-transformers/tool-context-transformer.d.ts +26 -0
- package/dist/context-transformers/tool-context-transformer.d.ts.map +1 -0
- package/dist/context-transformers/tool-context-transformer.js +52 -0
- package/dist/context-transformers/tool-context-transformer.js.map +1 -0
- package/dist/context-transformers/types.d.ts +65 -0
- package/dist/context-transformers/types.d.ts.map +1 -0
- package/dist/context-transformers/types.js +2 -0
- package/dist/context-transformers/types.js.map +1 -0
- package/dist/conversations/conversation.d.ts +146 -0
- package/dist/conversations/conversation.d.ts.map +1 -0
- package/dist/conversations/conversation.js +642 -0
- package/dist/conversations/conversation.js.map +1 -0
- package/dist/conversations/index.d.ts +5 -0
- package/dist/conversations/index.d.ts.map +1 -0
- package/dist/conversations/index.js +5 -0
- package/dist/conversations/index.js.map +1 -0
- package/dist/conversations/stream-listener.d.ts +37 -0
- package/dist/conversations/stream-listener.d.ts.map +1 -0
- package/dist/conversations/stream-listener.js +68 -0
- package/dist/conversations/stream-listener.js.map +1 -0
- package/dist/conversations/token-tracker.d.ts +59 -0
- package/dist/conversations/token-tracker.d.ts.map +1 -0
- package/dist/conversations/token-tracker.js +98 -0
- package/dist/conversations/token-tracker.js.map +1 -0
- package/dist/conversations/types.d.ts +346 -0
- package/dist/conversations/types.d.ts.map +1 -0
- package/dist/conversations/types.js +2 -0
- package/dist/conversations/types.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/policies/composite-policy.d.ts +29 -0
- package/dist/policies/composite-policy.d.ts.map +1 -0
- package/dist/policies/composite-policy.js +77 -0
- package/dist/policies/composite-policy.js.map +1 -0
- package/dist/policies/default-policy.d.ts +7 -0
- package/dist/policies/default-policy.d.ts.map +1 -0
- package/dist/policies/default-policy.js +14 -0
- package/dist/policies/default-policy.js.map +1 -0
- package/dist/policies/index.d.ts +8 -0
- package/dist/policies/index.d.ts.map +1 -0
- package/dist/policies/index.js +8 -0
- package/dist/policies/index.js.map +1 -0
- package/dist/policies/noop-policy.d.ts +21 -0
- package/dist/policies/noop-policy.d.ts.map +1 -0
- package/dist/policies/noop-policy.js +36 -0
- package/dist/policies/noop-policy.js.map +1 -0
- package/dist/policies/rate-limit-policy.d.ts +44 -0
- package/dist/policies/rate-limit-policy.d.ts.map +1 -0
- package/dist/policies/rate-limit-policy.js +98 -0
- package/dist/policies/rate-limit-policy.js.map +1 -0
- package/dist/policies/retry-policy.d.ts +42 -0
- package/dist/policies/retry-policy.d.ts.map +1 -0
- package/dist/policies/retry-policy.js +114 -0
- package/dist/policies/retry-policy.js.map +1 -0
- package/dist/policies/token-limit-policy.d.ts +76 -0
- package/dist/policies/token-limit-policy.d.ts.map +1 -0
- package/dist/policies/token-limit-policy.js +134 -0
- package/dist/policies/token-limit-policy.js.map +1 -0
- package/dist/policies/types.d.ts +49 -0
- package/dist/policies/types.d.ts.map +1 -0
- package/dist/policies/types.js +9 -0
- package/dist/policies/types.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/types.d.ts +180 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/utils/async.d.ts +125 -0
- package/dist/utils/async.d.ts.map +1 -0
- package/dist/utils/async.js +217 -0
- package/dist/utils/async.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object.d.ts +80 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +189 -0
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/types.d.ts +17 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/workflows/index.d.ts +4 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +4 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/types.d.ts +70 -0
- package/dist/workflows/types.d.ts.map +1 -0
- package/dist/workflows/types.js +2 -0
- package/dist/workflows/types.js.map +1 -0
- package/dist/workflows/workflow-manager.d.ts +74 -0
- package/dist/workflows/workflow-manager.d.ts.map +1 -0
- package/dist/workflows/workflow-manager.js +165 -0
- package/dist/workflows/workflow-manager.js.map +1 -0
- package/dist/workflows/workflow.d.ts +116 -0
- package/dist/workflows/workflow.d.ts.map +1 -0
- package/dist/workflows/workflow.js +351 -0
- package/dist/workflows/workflow.js.map +1 -0
- package/package.json +20 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Conversation } from "../conversations/index.ts";
|
|
2
|
+
import { WorkflowManagerEvents, WorkflowState } from "./types.ts";
|
|
3
|
+
import { Workflow } from "./workflow.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically manages workflow lifecycle for a conversation.
|
|
6
|
+
*
|
|
7
|
+
* The WorkflowManager creates a new Workflow instance whenever a message is sent
|
|
8
|
+
* to its associated conversation, eliminating the need for manual workflow management.
|
|
9
|
+
*/
|
|
10
|
+
export declare class WorkflowManager {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new workflow manager instance.
|
|
14
|
+
*
|
|
15
|
+
* @param conversation - The conversation to manage workflows for.
|
|
16
|
+
* @param options - Optional configuration.
|
|
17
|
+
* @param options.context_data - Custom data to pass to tools via ToolContext.
|
|
18
|
+
*/
|
|
19
|
+
constructor(conversation: Conversation, options?: {
|
|
20
|
+
context_data?: Record<string, unknown>;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* The current state of the workflow manager.
|
|
24
|
+
*/
|
|
25
|
+
get state(): WorkflowState;
|
|
26
|
+
/**
|
|
27
|
+
* The conversation being managed.
|
|
28
|
+
*/
|
|
29
|
+
get conversation(): Conversation;
|
|
30
|
+
/**
|
|
31
|
+
* The currently active workflow, if any.
|
|
32
|
+
*/
|
|
33
|
+
get current_workflow(): Workflow | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Disposes the workflow manager and releases all resources.
|
|
36
|
+
*
|
|
37
|
+
* This method is called automatically when using the `using` keyword.
|
|
38
|
+
*/
|
|
39
|
+
[Symbol.dispose](): void;
|
|
40
|
+
/**
|
|
41
|
+
* Registers a one-time event listener.
|
|
42
|
+
*
|
|
43
|
+
* @template E - The event name type.
|
|
44
|
+
* @param event - The name of the event to listen for.
|
|
45
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
46
|
+
* @returns This workflow manager instance for chaining.
|
|
47
|
+
*/
|
|
48
|
+
once<E extends keyof WorkflowManagerEvents>(event: E, listener: E extends keyof WorkflowManagerEvents ? (...args: WorkflowManagerEvents[E]) => void : never): this;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a persistent event listener.
|
|
51
|
+
*
|
|
52
|
+
* @template E - The event name type.
|
|
53
|
+
* @param event - The name of the event to listen for.
|
|
54
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
55
|
+
* @returns This workflow manager instance for chaining.
|
|
56
|
+
*/
|
|
57
|
+
on<E extends keyof WorkflowManagerEvents>(event: E, listener: E extends keyof WorkflowManagerEvents ? (...args: WorkflowManagerEvents[E]) => void : never): this;
|
|
58
|
+
/**
|
|
59
|
+
* Removes an event listener.
|
|
60
|
+
*
|
|
61
|
+
* @template E - The event name type.
|
|
62
|
+
* @param event - The name of the event.
|
|
63
|
+
* @param listener - The callback function to remove.
|
|
64
|
+
* @returns This workflow manager instance for chaining.
|
|
65
|
+
*/
|
|
66
|
+
off<E extends keyof WorkflowManagerEvents>(event: E, listener: E extends keyof WorkflowManagerEvents ? (...args: WorkflowManagerEvents[E]) => void : never): this;
|
|
67
|
+
/**
|
|
68
|
+
* Manually starts a workflow.
|
|
69
|
+
*
|
|
70
|
+
* This is typically not needed as workflows are started automatically when messages are sent.
|
|
71
|
+
*/
|
|
72
|
+
start_workflow(): void;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=workflow-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-manager.d.ts","sourceRoot":"","sources":["../../src/workflows/workflow-manager.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IG;IACH,cAAc;CAmEf"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { setImmediate } from "node:timers/promises";
|
|
3
|
+
import { Workflow } from "./workflow.js";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically manages workflow lifecycle for a conversation.
|
|
6
|
+
*
|
|
7
|
+
* The WorkflowManager creates a new Workflow instance whenever a message is sent
|
|
8
|
+
* to its associated conversation, eliminating the need for manual workflow management.
|
|
9
|
+
*/
|
|
10
|
+
export class WorkflowManager {
|
|
11
|
+
#event_emitter = new EventEmitter();
|
|
12
|
+
#conversation;
|
|
13
|
+
#context_data;
|
|
14
|
+
#state = "idle";
|
|
15
|
+
#current_workflow;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new workflow manager instance.
|
|
18
|
+
*
|
|
19
|
+
* @param conversation - The conversation to manage workflows for.
|
|
20
|
+
* @param options - Optional configuration.
|
|
21
|
+
* @param options.context_data - Custom data to pass to tools via ToolContext.
|
|
22
|
+
*/
|
|
23
|
+
constructor(conversation, options) {
|
|
24
|
+
this.#conversation = conversation;
|
|
25
|
+
this.#context_data = options?.context_data ?? {};
|
|
26
|
+
this.#conversation.on("prompt_send", this.#on_prompt_send);
|
|
27
|
+
this.#conversation.on("checkpoint_begin", this.#on_checkpoint_begin);
|
|
28
|
+
this.#conversation.once("dispose", this.#on_conversation_dispose);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The current state of the workflow manager.
|
|
32
|
+
*/
|
|
33
|
+
get state() {
|
|
34
|
+
return this.#state;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The conversation being managed.
|
|
38
|
+
*/
|
|
39
|
+
get conversation() {
|
|
40
|
+
return this.#conversation;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The currently active workflow, if any.
|
|
44
|
+
*/
|
|
45
|
+
get current_workflow() {
|
|
46
|
+
return this.#current_workflow;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Disposes the workflow manager and releases all resources.
|
|
50
|
+
*
|
|
51
|
+
* This method is called automatically when using the `using` keyword.
|
|
52
|
+
*/
|
|
53
|
+
[Symbol.dispose]() {
|
|
54
|
+
this.#conversation.off("prompt_send", this.#on_prompt_send);
|
|
55
|
+
this.#conversation.off("checkpoint_begin", this.#on_checkpoint_begin);
|
|
56
|
+
this.#conversation.off("dispose", this.#on_conversation_dispose);
|
|
57
|
+
this.#event_emitter.emit("dispose", this);
|
|
58
|
+
this.#set_state("disposed");
|
|
59
|
+
this.#event_emitter.removeAllListeners();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Registers a one-time event listener.
|
|
63
|
+
*
|
|
64
|
+
* @template E - The event name type.
|
|
65
|
+
* @param event - The name of the event to listen for.
|
|
66
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
67
|
+
* @returns This workflow manager instance for chaining.
|
|
68
|
+
*/
|
|
69
|
+
once(event, listener) {
|
|
70
|
+
if (this.#state === "disposed") {
|
|
71
|
+
throw new Error("invalid state");
|
|
72
|
+
}
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
+
this.#event_emitter.once(event, listener);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers a persistent event listener.
|
|
79
|
+
*
|
|
80
|
+
* @template E - The event name type.
|
|
81
|
+
* @param event - The name of the event to listen for.
|
|
82
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
83
|
+
* @returns This workflow manager instance for chaining.
|
|
84
|
+
*/
|
|
85
|
+
on(event, listener) {
|
|
86
|
+
if (this.#state === "disposed") {
|
|
87
|
+
throw new Error("invalid state");
|
|
88
|
+
}
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
+
this.#event_emitter.on(event, listener);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes an event listener.
|
|
95
|
+
*
|
|
96
|
+
* @template E - The event name type.
|
|
97
|
+
* @param event - The name of the event.
|
|
98
|
+
* @param listener - The callback function to remove.
|
|
99
|
+
* @returns This workflow manager instance for chaining.
|
|
100
|
+
*/
|
|
101
|
+
off(event, listener) {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
this.#event_emitter.off(event, listener);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Manually starts a workflow.
|
|
108
|
+
*
|
|
109
|
+
* This is typically not needed as workflows are started automatically when messages are sent.
|
|
110
|
+
*/
|
|
111
|
+
start_workflow() {
|
|
112
|
+
if (this.#state !== "idle") {
|
|
113
|
+
throw new Error("invalid state");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
#on_prompt_send = ({ message }) => {
|
|
117
|
+
if (this.#current_workflow) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.#current_workflow = new Workflow(this.#conversation, { context_data: this.#context_data });
|
|
121
|
+
this.#attach_workflow_event(this.#current_workflow, "state_change");
|
|
122
|
+
this.#attach_workflow_event(this.#current_workflow, "workflow_update");
|
|
123
|
+
this.#attach_workflow_event(this.#current_workflow, "workflow_end");
|
|
124
|
+
this.#attach_workflow_event(this.#current_workflow, "child_workflow_begin");
|
|
125
|
+
this.#attach_workflow_event(this.#current_workflow, "child_workflow_event");
|
|
126
|
+
this.#attach_workflow_event(this.#current_workflow, "message_queued");
|
|
127
|
+
this.#attach_workflow_event(this.#current_workflow, "message_dequeued");
|
|
128
|
+
this.#attach_workflow_event(this.#current_workflow, "queue_cleared");
|
|
129
|
+
this.#attach_workflow_event(this.#current_workflow, "lifecycle_error");
|
|
130
|
+
this.#attach_workflow_event(this.#current_workflow, "dispose");
|
|
131
|
+
this.#current_workflow.once("dispose", () => {
|
|
132
|
+
this.#current_workflow = undefined;
|
|
133
|
+
this.#set_state("idle");
|
|
134
|
+
});
|
|
135
|
+
this.#set_state("busy");
|
|
136
|
+
this.#event_emitter.emit("workflow_begin", this.#current_workflow, this);
|
|
137
|
+
this.#current_workflow.start(message);
|
|
138
|
+
};
|
|
139
|
+
#set_state(state) {
|
|
140
|
+
if (this.#state === state) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const previous = this.state;
|
|
144
|
+
this.#state = state;
|
|
145
|
+
this.#event_emitter.emit("state_change", { previous, current: this.#state }, this);
|
|
146
|
+
}
|
|
147
|
+
#attach_workflow_event(workflow, event_name) {
|
|
148
|
+
const handler = (...args) => {
|
|
149
|
+
this.#event_emitter.emit("workflow_event", {
|
|
150
|
+
event_name,
|
|
151
|
+
event_args: args,
|
|
152
|
+
}, this);
|
|
153
|
+
};
|
|
154
|
+
workflow.on(event_name, handler);
|
|
155
|
+
workflow.once("dispose", () => setImmediate(() => workflow.off(event_name, handler)));
|
|
156
|
+
}
|
|
157
|
+
#on_checkpoint_begin = (child) => {
|
|
158
|
+
this.#set_state("busy");
|
|
159
|
+
child.once("dispose", () => {
|
|
160
|
+
this.#set_state("idle");
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
#on_conversation_dispose = () => this[Symbol.dispose]();
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=workflow-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-manager.js","sourceRoot":"","sources":["../../src/workflows/workflow-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACjB,cAAc,GAAG,IAAI,YAAY,EAAyB,CAAC;IAC3D,aAAa,CAAe;IAC5B,aAAa,CAA0B;IAEhD,MAAM,GAAkB,MAAM,CAAC;IAC/B,iB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E5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACrF,CAAC;IAED,sBAAsB,CAAC,QAAkB,EAAE,UAAgC;QACzE,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,gBAAgB,EAChB;gBACE,UAAU;gBACV,UAAU,EAAE,IAAI;aAC6B,EAC/C,IAAI,CACL,CAAC;QACJ,CAAC,CAAC;QACF,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,oBAAoB,GAAG,CAAC,KAAmB,EAAE,EAAE;QAC7C,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YACzB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,wBAAwB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Conversation, Message } from "../conversations/index.ts";
|
|
2
|
+
import { WorkflowEvents } from "./types.ts";
|
|
3
|
+
import { WorkflowState } from "./index.ts";
|
|
4
|
+
import { UserMessage } from "../conversations/types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Manages an agentic workflow with automatic tool execution.
|
|
7
|
+
*
|
|
8
|
+
* A Workflow wraps a Conversation and automatically executes tools requested
|
|
9
|
+
* by the model, continuing the conversation until completion or error.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Workflow {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new workflow instance.
|
|
15
|
+
*
|
|
16
|
+
* @param conversation - The conversation to manage.
|
|
17
|
+
* @param options - Optional configuration.
|
|
18
|
+
* @param options.context_data - Custom data to pass to tools via ToolContext.
|
|
19
|
+
* @param options.parent - Parent workflow if this is a child workflow.
|
|
20
|
+
*/
|
|
21
|
+
constructor(conversation: Conversation, options?: {
|
|
22
|
+
context_data?: Record<string, unknown>;
|
|
23
|
+
parent?: Workflow;
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* The unique identifier for this workflow.
|
|
27
|
+
*/
|
|
28
|
+
get id(): string;
|
|
29
|
+
set id(value: string);
|
|
30
|
+
/**
|
|
31
|
+
* The current state of the workflow.
|
|
32
|
+
*/
|
|
33
|
+
get state(): WorkflowState;
|
|
34
|
+
/**
|
|
35
|
+
* The conversation being managed by this workflow.
|
|
36
|
+
*/
|
|
37
|
+
get conversation(): Conversation;
|
|
38
|
+
/**
|
|
39
|
+
* The parent workflow, if this is a child workflow.
|
|
40
|
+
*/
|
|
41
|
+
get parent(): Workflow | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The message history tracked by this workflow.
|
|
44
|
+
*/
|
|
45
|
+
get messages(): readonly Readonly<Message>[];
|
|
46
|
+
/**
|
|
47
|
+
* Messages queued for sending after the current response completes.
|
|
48
|
+
*/
|
|
49
|
+
get queued_messages(): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Disposes the workflow and releases all resources.
|
|
52
|
+
*
|
|
53
|
+
* This method is called automatically when using the `using` keyword.
|
|
54
|
+
*/
|
|
55
|
+
[Symbol.dispose](): void;
|
|
56
|
+
/**
|
|
57
|
+
* Registers a one-time event listener.
|
|
58
|
+
*
|
|
59
|
+
* @template E - The event name type.
|
|
60
|
+
* @param event - The name of the event to listen for.
|
|
61
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
62
|
+
* @returns This workflow instance for chaining.
|
|
63
|
+
*/
|
|
64
|
+
once<E extends keyof WorkflowEvents>(event: E, listener: E extends keyof WorkflowEvents ? (...args: WorkflowEvents[E]) => void : never): this;
|
|
65
|
+
/**
|
|
66
|
+
* Registers a persistent event listener.
|
|
67
|
+
*
|
|
68
|
+
* @template E - The event name type.
|
|
69
|
+
* @param event - The name of the event to listen for.
|
|
70
|
+
* @param listener - The callback function to invoke when the event occurs.
|
|
71
|
+
* @returns This workflow instance for chaining.
|
|
72
|
+
*/
|
|
73
|
+
on<E extends keyof WorkflowEvents>(event: E, listener: E extends keyof WorkflowEvents ? (...args: WorkflowEvents[E]) => void : never): this;
|
|
74
|
+
/**
|
|
75
|
+
* Removes an event listener.
|
|
76
|
+
*
|
|
77
|
+
* @template E - The event name type.
|
|
78
|
+
* @param event - The name of the event.
|
|
79
|
+
* @param listener - The callback function to remove.
|
|
80
|
+
* @returns This workflow instance for chaining.
|
|
81
|
+
*/
|
|
82
|
+
off<E extends keyof WorkflowEvents>(event: E, listener: E extends keyof WorkflowEvents ? (...args: WorkflowEvents[E]) => void : never): this;
|
|
83
|
+
/**
|
|
84
|
+
* Starts the workflow execution.
|
|
85
|
+
*
|
|
86
|
+
* @param message - Optional initial user message to begin the workflow.
|
|
87
|
+
*/
|
|
88
|
+
start(message?: UserMessage): void;
|
|
89
|
+
/**
|
|
90
|
+
* Cancels the workflow execution.
|
|
91
|
+
*
|
|
92
|
+
* This will cancel any in-progress model response and emit a workflow_end event.
|
|
93
|
+
*/
|
|
94
|
+
cancel(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a child workflow with a different conversation.
|
|
97
|
+
*
|
|
98
|
+
* Child events are propagated to the parent as "child_workflow_event" events.
|
|
99
|
+
*
|
|
100
|
+
* @param conversation - The conversation for the child workflow.
|
|
101
|
+
* @param id - Optional custom ID for the child workflow.
|
|
102
|
+
* @returns The newly created child workflow.
|
|
103
|
+
*/
|
|
104
|
+
spawn_child(conversation: Conversation, id?: string): Workflow;
|
|
105
|
+
/**
|
|
106
|
+
* Adds a message to the queue for sending after the current response completes.
|
|
107
|
+
*
|
|
108
|
+
* @param message - The text message to queue.
|
|
109
|
+
*/
|
|
110
|
+
queue_message(message: string): void;
|
|
111
|
+
/**
|
|
112
|
+
* Clears all queued messages.
|
|
113
|
+
*/
|
|
114
|
+
clear_queue(): void;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/workflow.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,YAAY,EAEZ,OAAO,EAGR,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAoB,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,QAAQ;;IAYnB;;;;;;;OAOG;gBAED,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,QAAQ,CAAA;KAAE;IAgBzE;;OAEG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IACD,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAEnB;IAED;;OAEG;IACH,IAAI,KAAK,kBAER;IAED;;OAEG;IACH,IAAI,YAAY,iBAEf;IAED;;OAEG;IACH,IAAI,MAAM,yBAET;IAED;;OAEG;IACH,IAAI,QAAQ,iCAEX;IAED;;OAEG;IACH,IAAI,eAAe,aAElB;IAED;;;;OAIG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;IAYhB;;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