@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.
Files changed (134) hide show
  1. package/README.md +232 -0
  2. package/dist/checkpoints/default-summarization-strategy.d.ts +13 -0
  3. package/dist/checkpoints/default-summarization-strategy.d.ts.map +1 -0
  4. package/dist/checkpoints/default-summarization-strategy.js +63 -0
  5. package/dist/checkpoints/default-summarization-strategy.js.map +1 -0
  6. package/dist/checkpoints/index.d.ts +3 -0
  7. package/dist/checkpoints/index.d.ts.map +1 -0
  8. package/dist/checkpoints/index.js +3 -0
  9. package/dist/checkpoints/index.js.map +1 -0
  10. package/dist/checkpoints/types.d.ts +32 -0
  11. package/dist/checkpoints/types.d.ts.map +1 -0
  12. package/dist/checkpoints/types.js +2 -0
  13. package/dist/checkpoints/types.js.map +1 -0
  14. package/dist/context-transformers/checkpoint-context-transformer.d.ts +13 -0
  15. package/dist/context-transformers/checkpoint-context-transformer.d.ts.map +1 -0
  16. package/dist/context-transformers/checkpoint-context-transformer.js +32 -0
  17. package/dist/context-transformers/checkpoint-context-transformer.js.map +1 -0
  18. package/dist/context-transformers/composite-context-transformer.d.ts +31 -0
  19. package/dist/context-transformers/composite-context-transformer.d.ts.map +1 -0
  20. package/dist/context-transformers/composite-context-transformer.js +41 -0
  21. package/dist/context-transformers/composite-context-transformer.js.map +1 -0
  22. package/dist/context-transformers/index.d.ts +6 -0
  23. package/dist/context-transformers/index.d.ts.map +1 -0
  24. package/dist/context-transformers/index.js +6 -0
  25. package/dist/context-transformers/index.js.map +1 -0
  26. package/dist/context-transformers/noop-context-transformer.d.ts +24 -0
  27. package/dist/context-transformers/noop-context-transformer.d.ts.map +1 -0
  28. package/dist/context-transformers/noop-context-transformer.js +26 -0
  29. package/dist/context-transformers/noop-context-transformer.js.map +1 -0
  30. package/dist/context-transformers/tool-context-transformer.d.ts +26 -0
  31. package/dist/context-transformers/tool-context-transformer.d.ts.map +1 -0
  32. package/dist/context-transformers/tool-context-transformer.js +52 -0
  33. package/dist/context-transformers/tool-context-transformer.js.map +1 -0
  34. package/dist/context-transformers/types.d.ts +65 -0
  35. package/dist/context-transformers/types.d.ts.map +1 -0
  36. package/dist/context-transformers/types.js +2 -0
  37. package/dist/context-transformers/types.js.map +1 -0
  38. package/dist/conversations/conversation.d.ts +146 -0
  39. package/dist/conversations/conversation.d.ts.map +1 -0
  40. package/dist/conversations/conversation.js +642 -0
  41. package/dist/conversations/conversation.js.map +1 -0
  42. package/dist/conversations/index.d.ts +5 -0
  43. package/dist/conversations/index.d.ts.map +1 -0
  44. package/dist/conversations/index.js +5 -0
  45. package/dist/conversations/index.js.map +1 -0
  46. package/dist/conversations/stream-listener.d.ts +37 -0
  47. package/dist/conversations/stream-listener.d.ts.map +1 -0
  48. package/dist/conversations/stream-listener.js +68 -0
  49. package/dist/conversations/stream-listener.js.map +1 -0
  50. package/dist/conversations/token-tracker.d.ts +59 -0
  51. package/dist/conversations/token-tracker.d.ts.map +1 -0
  52. package/dist/conversations/token-tracker.js +98 -0
  53. package/dist/conversations/token-tracker.js.map +1 -0
  54. package/dist/conversations/types.d.ts +346 -0
  55. package/dist/conversations/types.d.ts.map +1 -0
  56. package/dist/conversations/types.js +2 -0
  57. package/dist/conversations/types.js.map +1 -0
  58. package/dist/index.d.ts +10 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +9 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/policies/composite-policy.d.ts +29 -0
  63. package/dist/policies/composite-policy.d.ts.map +1 -0
  64. package/dist/policies/composite-policy.js +77 -0
  65. package/dist/policies/composite-policy.js.map +1 -0
  66. package/dist/policies/default-policy.d.ts +7 -0
  67. package/dist/policies/default-policy.d.ts.map +1 -0
  68. package/dist/policies/default-policy.js +14 -0
  69. package/dist/policies/default-policy.js.map +1 -0
  70. package/dist/policies/index.d.ts +8 -0
  71. package/dist/policies/index.d.ts.map +1 -0
  72. package/dist/policies/index.js +8 -0
  73. package/dist/policies/index.js.map +1 -0
  74. package/dist/policies/noop-policy.d.ts +21 -0
  75. package/dist/policies/noop-policy.d.ts.map +1 -0
  76. package/dist/policies/noop-policy.js +36 -0
  77. package/dist/policies/noop-policy.js.map +1 -0
  78. package/dist/policies/rate-limit-policy.d.ts +44 -0
  79. package/dist/policies/rate-limit-policy.d.ts.map +1 -0
  80. package/dist/policies/rate-limit-policy.js +98 -0
  81. package/dist/policies/rate-limit-policy.js.map +1 -0
  82. package/dist/policies/retry-policy.d.ts +42 -0
  83. package/dist/policies/retry-policy.d.ts.map +1 -0
  84. package/dist/policies/retry-policy.js +114 -0
  85. package/dist/policies/retry-policy.js.map +1 -0
  86. package/dist/policies/token-limit-policy.d.ts +76 -0
  87. package/dist/policies/token-limit-policy.d.ts.map +1 -0
  88. package/dist/policies/token-limit-policy.js +134 -0
  89. package/dist/policies/token-limit-policy.js.map +1 -0
  90. package/dist/policies/types.d.ts +49 -0
  91. package/dist/policies/types.d.ts.map +1 -0
  92. package/dist/policies/types.js +9 -0
  93. package/dist/policies/types.js.map +1 -0
  94. package/dist/tools/index.d.ts +2 -0
  95. package/dist/tools/index.d.ts.map +1 -0
  96. package/dist/tools/index.js +2 -0
  97. package/dist/tools/index.js.map +1 -0
  98. package/dist/tools/types.d.ts +180 -0
  99. package/dist/tools/types.d.ts.map +1 -0
  100. package/dist/tools/types.js +2 -0
  101. package/dist/tools/types.js.map +1 -0
  102. package/dist/utils/async.d.ts +125 -0
  103. package/dist/utils/async.d.ts.map +1 -0
  104. package/dist/utils/async.js +217 -0
  105. package/dist/utils/async.js.map +1 -0
  106. package/dist/utils/index.d.ts +4 -0
  107. package/dist/utils/index.d.ts.map +1 -0
  108. package/dist/utils/index.js +4 -0
  109. package/dist/utils/index.js.map +1 -0
  110. package/dist/utils/object.d.ts +80 -0
  111. package/dist/utils/object.d.ts.map +1 -0
  112. package/dist/utils/object.js +189 -0
  113. package/dist/utils/object.js.map +1 -0
  114. package/dist/utils/types.d.ts +17 -0
  115. package/dist/utils/types.d.ts.map +1 -0
  116. package/dist/utils/types.js +2 -0
  117. package/dist/utils/types.js.map +1 -0
  118. package/dist/workflows/index.d.ts +4 -0
  119. package/dist/workflows/index.d.ts.map +1 -0
  120. package/dist/workflows/index.js +4 -0
  121. package/dist/workflows/index.js.map +1 -0
  122. package/dist/workflows/types.d.ts +70 -0
  123. package/dist/workflows/types.d.ts.map +1 -0
  124. package/dist/workflows/types.js +2 -0
  125. package/dist/workflows/types.js.map +1 -0
  126. package/dist/workflows/workflow-manager.d.ts +74 -0
  127. package/dist/workflows/workflow-manager.d.ts.map +1 -0
  128. package/dist/workflows/workflow-manager.js +165 -0
  129. package/dist/workflows/workflow-manager.js.map +1 -0
  130. package/dist/workflows/workflow.d.ts +116 -0
  131. package/dist/workflows/workflow.d.ts.map +1 -0
  132. package/dist/workflows/workflow.js +351 -0
  133. package/dist/workflows/workflow.js.map +1 -0
  134. package/package.json +20 -0
@@ -0,0 +1,217 @@
1
+ import EventEmitter from "node:events";
2
+ /**
3
+ * Token for monitoring and responding to cancellation requests.
4
+ *
5
+ * Provides a way to check if an operation has been cancelled and to
6
+ * register callbacks for when cancellation occurs.
7
+ */
8
+ export class CancellationToken {
9
+ #source;
10
+ /**
11
+ * Creates a new cancellation token.
12
+ *
13
+ * @param source - Optional source that controls this token.
14
+ */
15
+ constructor(source) {
16
+ this.#source = source;
17
+ }
18
+ /**
19
+ * Whether cancellation has been requested.
20
+ */
21
+ get is_cancellation_requested() {
22
+ return !!this.#source?.is_cancelled;
23
+ }
24
+ /**
25
+ * Registers a one-time handler for cancellation.
26
+ *
27
+ * @param event - The event name (always "cancel").
28
+ * @param handler - The callback to invoke when cancelled.
29
+ */
30
+ once(event, handler) {
31
+ this.#source?.once(event, handler);
32
+ }
33
+ /**
34
+ * Removes a cancellation handler.
35
+ *
36
+ * @param event - The event name (always "cancel").
37
+ * @param handler - The callback to remove.
38
+ */
39
+ off(event, handler) {
40
+ this.#source?.off(event, handler);
41
+ }
42
+ /**
43
+ * Throws an error if cancellation has been requested.
44
+ */
45
+ throw_if_cancellation_requested() {
46
+ if (this.is_cancellation_requested) {
47
+ throw new OperationCanceledError(this);
48
+ }
49
+ }
50
+ /**
51
+ * Creates a promise that rejects when cancellation is requested.
52
+ *
53
+ * @returns A promise that never resolves but rejects on cancellation.
54
+ */
55
+ await_cancellation() {
56
+ return new Promise((_, reject) => this.once("cancel", () => reject(new OperationCanceledError(this))));
57
+ }
58
+ /**
59
+ * Creates an empty cancellation token that can never be cancelled.
60
+ *
61
+ * @returns A new cancellation token with no source.
62
+ */
63
+ static empty() {
64
+ return new CancellationToken();
65
+ }
66
+ }
67
+ /**
68
+ * Source for creating and controlling cancellation tokens.
69
+ *
70
+ * Allows triggering cancellation for associated tokens.
71
+ */
72
+ export class CancellationTokenSource {
73
+ #event_emitter = new EventEmitter();
74
+ #is_cancelled = false;
75
+ #is_disposed = false;
76
+ #token;
77
+ /**
78
+ * Disposes the cancellation token source.
79
+ *
80
+ * This method is called automatically when using the `using` keyword.
81
+ */
82
+ [Symbol.dispose]() {
83
+ if (this.#is_disposed) {
84
+ throw new Error("invalid state");
85
+ }
86
+ this.#is_disposed = true;
87
+ this.#event_emitter.removeAllListeners();
88
+ }
89
+ /**
90
+ * Gets a cancellation token associated with this source.
91
+ */
92
+ get token() {
93
+ if (!this.#token) {
94
+ this.#token = new CancellationToken(this);
95
+ }
96
+ return this.#token;
97
+ }
98
+ /**
99
+ * Whether cancellation has been triggered.
100
+ */
101
+ get is_cancelled() {
102
+ return this.#is_cancelled;
103
+ }
104
+ /**
105
+ * Registers a one-time handler for cancellation.
106
+ *
107
+ * @param event - The event name (always "cancel").
108
+ * @param handler - The callback to invoke when cancelled.
109
+ */
110
+ once(event, handler) {
111
+ if (this.#is_cancelled) {
112
+ throw new OperationCanceledError(new CancellationToken(this));
113
+ }
114
+ if (this.#is_disposed) {
115
+ throw new Error("invalid state");
116
+ }
117
+ this.#event_emitter.once(event, handler);
118
+ }
119
+ /**
120
+ * Removes a cancellation handler.
121
+ *
122
+ * @param event - The event name (always "cancel").
123
+ * @param handler - The callback to remove.
124
+ */
125
+ off(event, handler) {
126
+ this.#event_emitter.off(event, handler);
127
+ }
128
+ /**
129
+ * Triggers cancellation for all associated tokens.
130
+ */
131
+ cancel() {
132
+ if (this.#is_cancelled) {
133
+ throw new OperationCanceledError(new CancellationToken(this));
134
+ }
135
+ this.#is_cancelled = true;
136
+ this.#event_emitter.emit("cancel");
137
+ }
138
+ }
139
+ /**
140
+ * Error thrown when an operation is cancelled.
141
+ */
142
+ export class OperationCanceledError extends Error {
143
+ #token;
144
+ /**
145
+ * Creates a new operation cancelled error.
146
+ *
147
+ * @param token - The cancellation token associated with this error.
148
+ */
149
+ constructor(token) {
150
+ super("The operation was cancelled", { cause: "cancelled" });
151
+ this.#token = token;
152
+ }
153
+ /**
154
+ * The cancellation token associated with this error.
155
+ */
156
+ get token() {
157
+ return this.#token;
158
+ }
159
+ }
160
+ /**
161
+ * Delays execution for a specified time period with cancellation support.
162
+ *
163
+ * @param ms - The number of milliseconds to sleep.
164
+ * @param cancellation_token - Optional token for cancelling the sleep.
165
+ * @returns A promise that resolves after the delay or rejects if cancelled.
166
+ */
167
+ export function sleep(ms, cancellation_token) {
168
+ return new Promise((resolve, reject) => {
169
+ if (cancellation_token) {
170
+ const token = cancellation_token;
171
+ const on_cancel = () => {
172
+ clearTimeout(timeout);
173
+ reject(new OperationCanceledError(token));
174
+ };
175
+ const on_timeout = () => {
176
+ token.off("cancel", on_cancel);
177
+ resolve();
178
+ };
179
+ const timeout = setTimeout(on_timeout, ms);
180
+ if (token.is_cancellation_requested) {
181
+ clearTimeout(timeout);
182
+ reject(new OperationCanceledError(token));
183
+ }
184
+ else {
185
+ token.once("cancel", on_cancel);
186
+ }
187
+ }
188
+ else {
189
+ setTimeout(resolve, ms);
190
+ }
191
+ });
192
+ }
193
+ /**
194
+ * Peeks at the first value from an async generator without consuming it.
195
+ *
196
+ * @template T - The type of values yielded by the generator.
197
+ * @param generator - The async generator to peek.
198
+ * @returns An object containing the peeked value and a new generator that includes it.
199
+ */
200
+ export async function peek_generator(generator) {
201
+ const iterator = generator[Symbol.asyncIterator]();
202
+ let result = await iterator.next();
203
+ const wrapper = (async function* () {
204
+ while (true) {
205
+ if (result.done) {
206
+ break;
207
+ }
208
+ yield result.value;
209
+ result = await iterator.next();
210
+ }
211
+ })();
212
+ return {
213
+ peeked_value: result.value,
214
+ generator: wrapper,
215
+ };
216
+ }
217
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/utils/async.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAA2B;IAE3C;;;;OAIG;IACH,YAAY,MAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,yBAAyB;QAC3B,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,KAAe,EAAE,OAAmB;QACvC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,KAAe,EAAE,OAAmB;QACtC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,+BAA+B;QAC7B,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACnC,MAAM,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,kBAAkB;QAChB,OAAO,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACtC,I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AS,CAAC,CAAC;gBAC/B,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAC3C,IAAI,KAAK,CAAC,yBAAyB,EAAE,CAAC;gBACpC,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,MAAM,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,SAA4B;IAClE,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAEnD,IAAI,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,MAAM,OAAO,GAAG,CAAC,KAAK,SAAS,CAAC;QAC9B,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAChB,MAAM;YACR,CAAC;YACD,MAAM,MAAM,CAAC,KAAK,CAAC;YACnB,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,KAAU;QAC/B,SAAS,EAAE,OAAO;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./async.ts";
2
+ export * from "./object.ts";
3
+ export * from "./types.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./async.js";
2
+ export * from "./object.js";
3
+ export * from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Gets all keys from an object where the value is not undefined.
3
+ *
4
+ * @param obj - The object to examine.
5
+ * @returns An array of keys with defined values.
6
+ */
7
+ export declare function defined_keys(obj: Record<string, unknown>): string[];
8
+ /**
9
+ * Checks whether an object has any defined properties.
10
+ *
11
+ * @param obj - The object to examine.
12
+ * @returns True if the object has at least one defined property.
13
+ */
14
+ export declare function has_data(obj: Record<string, unknown>): boolean;
15
+ /**
16
+ * Returns undefined if the value is empty (empty array or object with no defined keys).
17
+ *
18
+ * @template T - The type of the value.
19
+ * @param obj - The value to check.
20
+ * @returns The value if non-empty, otherwise undefined.
21
+ */
22
+ export declare function undefined_if_empty<T = unknown>(obj: T): T | undefined;
23
+ /**
24
+ * Recursively merges two values together.
25
+ *
26
+ * For objects, properties are merged recursively. For arrays, elements are concatenated.
27
+ * For primitives, the supplemental value replaces the original.
28
+ *
29
+ * @template T - The type of values being merged.
30
+ * @param original - The original value.
31
+ * @param supplemental - The value to merge in.
32
+ * @returns The merged result.
33
+ */
34
+ export declare function deep_merge<T = unknown>(original: T, supplemental: T): T;
35
+ /**
36
+ * Copies a property from source to destination only if it is defined.
37
+ *
38
+ * @template TKey - The key type.
39
+ * @template TSource - The source object type.
40
+ * @param key - The property key to copy.
41
+ * @param source - The source object.
42
+ * @param destination - The destination object.
43
+ */
44
+ export declare function copy_if_defined<TKey extends keyof TSource, TSource extends object>(key: TKey, source: TSource, destination: Partial<Pick<TSource, TKey>>): void;
45
+ /**
46
+ * Type guard that checks if an object contains a specific key.
47
+ *
48
+ * @template T - The object type.
49
+ * @template K - The key type.
50
+ * @param obj - The object to check.
51
+ * @param key - The key to look for.
52
+ * @returns True if the object contains the key.
53
+ */
54
+ export declare function contains_key<T extends object, K extends string | number>(obj: T, key: K): obj is T & Record<K, unknown>;
55
+ /**
56
+ * Gets a value from a nested object path.
57
+ *
58
+ * @param node - The object to traverse.
59
+ * @param key_path - The path to the value (dot-separated string or array of keys).
60
+ * @returns The value at the path, or undefined if not found.
61
+ */
62
+ export declare function get_nested_value(node: unknown, key_path: string | (string | number)[]): unknown;
63
+ /**
64
+ * Sets a value at a nested object path.
65
+ *
66
+ * Creates intermediate objects/arrays as needed.
67
+ *
68
+ * @param node - The object to modify.
69
+ * @param key_path - The path to set (dot-separated string or array of keys).
70
+ * @param value - The value to set.
71
+ */
72
+ export declare function set_nested_value(node: unknown, key_path: string | (string | number)[], value: unknown): void;
73
+ /**
74
+ * Deletes a value at a nested object path.
75
+ *
76
+ * @param node - The object to modify.
77
+ * @param key_path - The path to delete (dot-separated string or array of keys).
78
+ */
79
+ export declare function delete_nested_value(node: unknown, key_path: string | (string | number)[]): void;
80
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAExD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,iBAWrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAmCvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,SAAS,MAAM,OAAO,EAAE,OAAO,SAAS,MAAM,EAChF,GAAG,EAAE,IAAI,EACT,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,QAK1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EACtE,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,GACL,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAa/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACtC,KAAK,EAAE,OAAO,QAwBf;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,QAwBxF"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Gets all keys from an object where the value is not undefined.
3
+ *
4
+ * @param obj - The object to examine.
5
+ * @returns An array of keys with defined values.
6
+ */
7
+ export function defined_keys(obj) {
8
+ return Object.keys(obj).filter((key) => obj[key] !== undefined);
9
+ }
10
+ /**
11
+ * Checks whether an object has any defined properties.
12
+ *
13
+ * @param obj - The object to examine.
14
+ * @returns True if the object has at least one defined property.
15
+ */
16
+ export function has_data(obj) {
17
+ return defined_keys(obj).length > 0;
18
+ }
19
+ /**
20
+ * Returns undefined if the value is empty (empty array or object with no defined keys).
21
+ *
22
+ * @template T - The type of the value.
23
+ * @param obj - The value to check.
24
+ * @returns The value if non-empty, otherwise undefined.
25
+ */
26
+ export function undefined_if_empty(obj) {
27
+ if (!obj) {
28
+ return obj;
29
+ }
30
+ if (Array.isArray(obj)) {
31
+ return obj.length === 0 ? undefined : obj;
32
+ }
33
+ if (typeof obj === "object") {
34
+ return defined_keys(obj).length === 0 ? undefined : obj;
35
+ }
36
+ return obj;
37
+ }
38
+ /**
39
+ * Recursively merges two values together.
40
+ *
41
+ * For objects, properties are merged recursively. For arrays, elements are concatenated.
42
+ * For primitives, the supplemental value replaces the original.
43
+ *
44
+ * @template T - The type of values being merged.
45
+ * @param original - The original value.
46
+ * @param supplemental - The value to merge in.
47
+ * @returns The merged result.
48
+ */
49
+ export function deep_merge(original, supplemental) {
50
+ if (supplemental === undefined || supplemental === null) {
51
+ return original;
52
+ }
53
+ if (original === undefined || original === null) {
54
+ return supplemental;
55
+ }
56
+ if (typeof original === "object" && typeof supplemental === "object") {
57
+ if (Array.isArray(original)) {
58
+ if (!Array.isArray(supplemental)) {
59
+ throw new Error("type mismatch");
60
+ }
61
+ return [...original, ...supplemental];
62
+ }
63
+ else {
64
+ if (Array.isArray(supplemental)) {
65
+ throw new Error("type mismatch");
66
+ }
67
+ const result = { ...original };
68
+ for (const [key, value] of Object.entries(supplemental)) {
69
+ result[key] = deep_merge(result[key], value);
70
+ }
71
+ return result;
72
+ }
73
+ }
74
+ if (typeof supplemental !== typeof original) {
75
+ throw new Error("type mismatch");
76
+ }
77
+ if (typeof supplemental === "string" ||
78
+ typeof supplemental === "number" ||
79
+ typeof supplemental === "boolean") {
80
+ return supplemental;
81
+ }
82
+ throw new Error("unsupported type");
83
+ }
84
+ /**
85
+ * Copies a property from source to destination only if it is defined.
86
+ *
87
+ * @template TKey - The key type.
88
+ * @template TSource - The source object type.
89
+ * @param key - The property key to copy.
90
+ * @param source - The source object.
91
+ * @param destination - The destination object.
92
+ */
93
+ export function copy_if_defined(key, source, destination) {
94
+ if (source[key] !== undefined) {
95
+ destination[key] = source[key];
96
+ }
97
+ }
98
+ /**
99
+ * Type guard that checks if an object contains a specific key.
100
+ *
101
+ * @template T - The object type.
102
+ * @template K - The key type.
103
+ * @param obj - The object to check.
104
+ * @param key - The key to look for.
105
+ * @returns True if the object contains the key.
106
+ */
107
+ export function contains_key(obj, key) {
108
+ return key in obj;
109
+ }
110
+ /**
111
+ * Gets a value from a nested object path.
112
+ *
113
+ * @param node - The object to traverse.
114
+ * @param key_path - The path to the value (dot-separated string or array of keys).
115
+ * @returns The value at the path, or undefined if not found.
116
+ */
117
+ export function get_nested_value(node, key_path) {
118
+ if (typeof key_path === "string") {
119
+ return get_nested_value(node, key_path.split("."));
120
+ }
121
+ const [key, ...rest] = key_path;
122
+ if (typeof node !== "object" || node === null || key === undefined) {
123
+ return node;
124
+ }
125
+ if (!contains_key(node, key)) {
126
+ return undefined;
127
+ }
128
+ return get_nested_value(node[key], rest);
129
+ }
130
+ /**
131
+ * Sets a value at a nested object path.
132
+ *
133
+ * Creates intermediate objects/arrays as needed.
134
+ *
135
+ * @param node - The object to modify.
136
+ * @param key_path - The path to set (dot-separated string or array of keys).
137
+ * @param value - The value to set.
138
+ */
139
+ export function set_nested_value(node, key_path, value) {
140
+ if (typeof key_path === "string") {
141
+ set_nested_value(node, key_path.split("."), value);
142
+ return;
143
+ }
144
+ const [key, next_key, ...rest] = key_path;
145
+ if (key === undefined) {
146
+ throw new Error("invalid object key");
147
+ }
148
+ if (typeof node !== "object" || node === null) {
149
+ throw new Error("invalid object value");
150
+ }
151
+ const obj = node;
152
+ if (next_key === undefined || next_key === null) {
153
+ obj[key] = value;
154
+ return;
155
+ }
156
+ if (obj[key] === undefined || obj[key] === null) {
157
+ obj[key] = typeof next_key === "number" || /^\d+$/.test(String(next_key)) ? [] : {};
158
+ }
159
+ set_nested_value(obj[key], [next_key, ...rest], value);
160
+ }
161
+ /**
162
+ * Deletes a value at a nested object path.
163
+ *
164
+ * @param node - The object to modify.
165
+ * @param key_path - The path to delete (dot-separated string or array of keys).
166
+ */
167
+ export function delete_nested_value(node, key_path) {
168
+ if (typeof key_path === "string") {
169
+ delete_nested_value(node, key_path.split("."));
170
+ return;
171
+ }
172
+ const [key, next_key, ...rest] = key_path;
173
+ if (key === undefined) {
174
+ return;
175
+ }
176
+ if (typeof node !== "object" || node === null) {
177
+ return;
178
+ }
179
+ const obj = node;
180
+ if (!contains_key(obj, key)) {
181
+ return;
182
+ }
183
+ if (next_key === undefined) {
184
+ delete obj[key];
185
+ return;
186
+ }
187
+ delete_nested_value(obj[key], [next_key, ...rest]);
188
+ }
189
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAA4B;IACvD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAA4B;IACnD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAc,GAAM;IACpD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5C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AAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,QAAsC;IACvF,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/C,OAAO;IACT,CAAC;IACD,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC;IAE1C,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,IAAwC,CAAC;IAErD,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO;IACT,CAAC;IACD,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Makes all properties of an object and their nested properties optional.
3
+ *
4
+ * @template T - The object type to make deeply partial.
5
+ */
6
+ export type DeepPartial<T> = Partial<{
7
+ [K in keyof T]: Partial<T[K]>;
8
+ }>;
9
+ /**
10
+ * Flattens intersection types for better IDE display.
11
+ *
12
+ * @template T - The type to prettify.
13
+ */
14
+ export type Prettify<T> = {
15
+ [K in keyof T]: T[K];
16
+ } & {};
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,OAAO,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from "./types.ts";
2
+ export * from "./workflow.ts";
3
+ export * from "./workflow-manager.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./types.js";
2
+ export * from "./workflow.js";
3
+ export * from "./workflow-manager.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { ChangeEvent, type LifecycleErrorEvent } from "../conversations/index.ts";
2
+ import { WorkflowManager } from "./workflow-manager.ts";
3
+ import { Workflow } from "./workflow.ts";
4
+ /**
5
+ * Possible states of a workflow.
6
+ */
7
+ export type WorkflowState = "idle" | "busy" | "disposed";
8
+ /**
9
+ * Event data describing why a workflow ended.
10
+ */
11
+ export type WorkflowEndEvent = {
12
+ reason: "complete" | "cancel" | "error";
13
+ };
14
+ /**
15
+ * Events emitted by a Workflow instance.
16
+ */
17
+ export interface WorkflowEvents {
18
+ /** Emitted when the workflow state changes. */
19
+ state_change: [ChangeEvent<WorkflowState>, Workflow];
20
+ /** Emitted when the workflow is updated with new messages. */
21
+ workflow_update: [Workflow];
22
+ /** Emitted when the workflow ends. */
23
+ workflow_end: [WorkflowEndEvent, Workflow];
24
+ /** Emitted when a child workflow is created. */
25
+ child_workflow_begin: [Workflow, Workflow];
26
+ /** Emitted when a child workflow emits an event. */
27
+ child_workflow_event: [
28
+ {
29
+ [E in keyof WorkflowEvents]: {
30
+ event_name: E;
31
+ event_args: WorkflowEvents[E];
32
+ };
33
+ }[keyof WorkflowEvents],
34
+ Workflow
35
+ ];
36
+ /** Emitted when a message is added to the queue. */
37
+ message_queued: [string, Workflow];
38
+ /** Emitted when a message is removed from the queue for sending. */
39
+ message_dequeued: [string, Workflow];
40
+ /** Emitted when the message queue is cleared. */
41
+ queue_cleared: [Workflow];
42
+ /** Emitted when an infrastructure or lifecycle operation fails. */
43
+ lifecycle_error: [LifecycleErrorEvent, Workflow];
44
+ /** Emitted when the workflow is disposed. */
45
+ dispose: [Workflow];
46
+ }
47
+ /**
48
+ * Events emitted by a WorkflowManager instance.
49
+ */
50
+ export interface WorkflowManagerEvents {
51
+ /** Emitted when the workflow manager state changes. */
52
+ state_change: [ChangeEvent<WorkflowState>, WorkflowManager];
53
+ /** Emitted when a new workflow begins. */
54
+ workflow_begin: [Workflow, WorkflowManager];
55
+ /** Emitted when a managed workflow emits an event. */
56
+ workflow_event: [
57
+ {
58
+ [E in keyof WorkflowEvents]: {
59
+ event_name: E;
60
+ event_args: WorkflowEvents[E];
61
+ };
62
+ }[keyof WorkflowEvents],
63
+ WorkflowManager
64
+ ];
65
+ /** Emitted when an infrastructure or lifecycle operation fails. */
66
+ lifecycle_error: [LifecycleErrorEvent, WorkflowManager];
67
+ /** Emitted when the workflow manager is disposed. */
68
+ dispose: [WorkflowManager];
69
+ }
70
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workflows/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAA;CAAE,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,YAAY,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,CAAC;IACrD,8DAA8D;IAC9D,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC;IAC5B,sCAAsC;IACtC,YAAY,EAAE,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IAC3C,gDAAgD;IAChD,oBAAoB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC3C,oDAAoD;IACpD,oBAAoB,EAAE;QACpB;aACG,CAAC,IAAI,MAAM,cAAc,GAAG;gBAC3B,UAAU,EAAE,CAAC,CAAC;gBACd,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;aAC/B;SACF,CAAC,MAAM,cAAc,CAAC;QACvB,QAAQ;KACT,CAAC;IACF,oDAAoD;IACpD,cAAc,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnC,oEAAoE;IACpE,gBAAgB,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,iDAAiD;IACjD,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC;IAC1B,mEAAmE;IACnE,eAAe,EAAE,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACjD,6CAA6C;IAC7C,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,uDAAuD;IACvD,YAAY,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,eAAe,CAAC,CAAC;IAC5D,0CAA0C;IAC1C,cAAc,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC5C,sDAAsD;IACtD,cAAc,EAAE;QACd;aACG,CAAC,IAAI,MAAM,cAAc,GAAG;gBAC3B,UAAU,EAAE,CAAC,CAAC;gBACd,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;aAC/B;SACF,CAAC,MAAM,cAAc,CAAC;QACvB,eAAe;KAChB,CAAC;IACF,mEAAmE;IACnE,eAAe,EAAE,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;IACxD,qDAAqD;IACrD,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/workflows/types.ts"],"names":[],"mappings":""}