llmz 0.0.13 → 0.0.15
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/CLAUDE.md +363 -0
- package/README.md +61 -34
- package/dist/abort-signal.d.ts +40 -0
- package/dist/chat.d.ts +325 -0
- package/dist/{chunk-KH6JQYQA.js → chunk-2D2DE7CD.js} +2 -2
- package/dist/chunk-3G3BS5IA.cjs +256 -0
- package/dist/{chunk-SNDVQU5A.js → chunk-3JYCCI4S.js} +1 -1
- package/dist/chunk-A7QHWVD7.js +493 -0
- package/dist/{chunk-IH2WQFO5.js → chunk-EE6NVDID.js} +1 -1
- package/dist/{chunk-4L6D2A6O.cjs → chunk-FZJHYLM2.cjs} +14 -14
- package/dist/{chunk-JGVAZO4X.cjs → chunk-GZPN7RGH.cjs} +2 -2
- package/dist/{chunk-SHJDRZF5.cjs → chunk-PIDLNYIP.cjs} +25 -25
- package/dist/{chunk-PRVFVXT4.js → chunk-RBRTK37G.js} +383 -4
- package/dist/{chunk-HJKOSEH2.cjs → chunk-TCRRSS44.cjs} +397 -18
- package/dist/chunk-VPTFUOIK.js +256 -0
- package/dist/{chunk-276Q6EWP.cjs → chunk-WHNOR4ZU.cjs} +3 -0
- package/dist/chunk-XGJOEQMW.cjs +493 -0
- package/dist/{chunk-4MNIJGK6.js → chunk-ZORRILUV.js} +3 -0
- package/dist/context.d.ts +412 -4
- package/dist/{dual-modes-T53P72CH.js → dual-modes-7FI4T35O.js} +3 -3
- package/dist/{dual-modes-VLIGPIHX.cjs → dual-modes-OFHV2C3X.cjs} +4 -4
- package/dist/exit-XAYKJ6TR.cjs +8 -0
- package/dist/{exit-YORW76T3.js → exit-YLO7BY7Z.js} +2 -2
- package/dist/exit.d.ts +369 -2
- package/dist/index.cjs +253 -28
- package/dist/index.d.ts +71 -1
- package/dist/index.js +242 -17
- package/dist/{llmz-ROOX7RYI.js → llmz-67EZPJ4E.js} +113 -39
- package/dist/{llmz-QLZBDG2Z.cjs → llmz-WVNKAMCP.cjs} +123 -49
- package/dist/llmz.d.ts +142 -5
- package/dist/objects.d.ts +350 -1
- package/dist/result.d.ts +809 -6
- package/dist/snapshots.d.ts +181 -1
- package/dist/{tool-QP4MVRWI.cjs → tool-O4SFRIE4.cjs} +4 -4
- package/dist/{tool-N6ODRRGH.js → tool-PCOYOCRH.js} +3 -3
- package/dist/tool.d.ts +470 -2
- package/dist/{truncator-IY2MXOMC.js → truncator-BSP6PQPC.js} +2 -2
- package/dist/truncator-W3NXBLYJ.cjs +10 -0
- package/dist/types.d.ts +3 -0
- package/dist/{typings-GDMY6VY2.js → typings-WYHEFCYB.js} +2 -2
- package/dist/{typings-2CPHOFDN.cjs → typings-Y45GMPZT.cjs} +3 -3
- package/dist/utils-L5QAQXV2.cjs +39 -0
- package/dist/{utils-N24IHDFA.js → utils-RQHQ2KOG.js} +1 -1
- package/docs/TODO.md +919 -0
- package/package.json +3 -3
- package/dist/chunk-C6WNNTEV.cjs +0 -212
- package/dist/chunk-GWFYZDUR.cjs +0 -105
- package/dist/chunk-JAGB2AOU.js +0 -212
- package/dist/chunk-JMSZKB4T.js +0 -105
- package/dist/exit-TRXEU4OU.cjs +0 -8
- package/dist/truncator-DUMWEGQO.cjs +0 -10
- package/dist/utils-A7WNEFTA.cjs +0 -39
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isJsonSchema,
|
|
3
|
+
isValidIdentifier,
|
|
4
|
+
isZuiSchema
|
|
5
|
+
} from "./chunk-ZORRILUV.js";
|
|
6
|
+
import {
|
|
7
|
+
uniq_default
|
|
8
|
+
} from "./chunk-7WRN4E42.js";
|
|
9
|
+
|
|
10
|
+
// src/exit.ts
|
|
11
|
+
import { transforms } from "@bpinternal/zui";
|
|
12
|
+
var Exit = class _Exit {
|
|
13
|
+
/** The primary name of the exit (used in return statements) */
|
|
14
|
+
name;
|
|
15
|
+
/** Alternative names that can be used to reference this exit */
|
|
16
|
+
aliases = [];
|
|
17
|
+
/** Human-readable description of when this exit should be used */
|
|
18
|
+
description;
|
|
19
|
+
/** Additional metadata for orchestration and custom logic */
|
|
20
|
+
metadata;
|
|
21
|
+
/** JSON Schema for validating exit result data */
|
|
22
|
+
schema;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the Zod schema equivalent of the JSON schema (if available).
|
|
25
|
+
* Used internally for validation and type inference.
|
|
26
|
+
*/
|
|
27
|
+
get zSchema() {
|
|
28
|
+
return this.schema ? transforms.fromJSONSchemaLegacy(this.schema) : void 0;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Renames the exit and updates aliases accordingly.
|
|
32
|
+
*
|
|
33
|
+
* @param name - The new name for the exit (must be a valid identifier)
|
|
34
|
+
* @returns This exit instance for chaining
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const exit = new Exit({ name: 'old_name', description: 'Test exit' })
|
|
39
|
+
* exit.rename('new_name')
|
|
40
|
+
* console.log(exit.name) // 'new_name'
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
rename(name) {
|
|
44
|
+
const before = this.name;
|
|
45
|
+
if (!isValidIdentifier(name)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Invalid name for exit ${name}. An exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
this.name = name;
|
|
51
|
+
this.aliases = uniq_default([name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a deep copy of this exit.
|
|
56
|
+
*
|
|
57
|
+
* The clone is completely independent and can be modified without affecting
|
|
58
|
+
* the original exit. This is useful for creating variations of existing exits.
|
|
59
|
+
*
|
|
60
|
+
* @returns A new Exit instance with the same configuration
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const originalExit = new Exit({
|
|
65
|
+
* name: 'base',
|
|
66
|
+
* description: 'Base exit',
|
|
67
|
+
* schema: z.object({ status: z.string() }),
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* const customExit = originalExit.clone().rename('custom')
|
|
71
|
+
* // customExit is independent of originalExit
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
clone() {
|
|
75
|
+
return new _Exit({
|
|
76
|
+
name: this.name,
|
|
77
|
+
aliases: [...this.aliases],
|
|
78
|
+
description: this.description,
|
|
79
|
+
metadata: JSON.parse(JSON.stringify(this.metadata)),
|
|
80
|
+
schema: this.zSchema
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Type guard to check if this exit matches another exit by name.
|
|
85
|
+
*
|
|
86
|
+
* Used internally for type narrowing and exit comparison.
|
|
87
|
+
*
|
|
88
|
+
* @param exit - The exit to compare against
|
|
89
|
+
* @returns True if the exits have the same name
|
|
90
|
+
*/
|
|
91
|
+
is(exit) {
|
|
92
|
+
return this.name === exit.name;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Type guard to check if an ExitResult matches this exit.
|
|
96
|
+
*
|
|
97
|
+
* @param result - The exit result to check
|
|
98
|
+
* @returns True if the result was created by this exit
|
|
99
|
+
*/
|
|
100
|
+
match(result) {
|
|
101
|
+
return result.exit instanceof _Exit && this.name === result.exit.name;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Serializes this exit to a JSON-compatible object.
|
|
105
|
+
*
|
|
106
|
+
* @returns JSON representation of the exit
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const exit = new Exit({
|
|
111
|
+
* name: 'complete',
|
|
112
|
+
* description: 'Task completed successfully',
|
|
113
|
+
* })
|
|
114
|
+
*
|
|
115
|
+
* console.log(exit.toJSON())
|
|
116
|
+
* // { name: 'complete', aliases: [], description: 'Task completed successfully', metadata: {}, schema: undefined }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
toJSON() {
|
|
120
|
+
return {
|
|
121
|
+
name: this.name,
|
|
122
|
+
aliases: [...this.aliases],
|
|
123
|
+
description: this.description,
|
|
124
|
+
metadata: { ...this.metadata },
|
|
125
|
+
schema: this.schema
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new Exit instance.
|
|
130
|
+
*
|
|
131
|
+
* @param props - Exit configuration
|
|
132
|
+
* @param props.name - Primary name for the exit (must be valid identifier)
|
|
133
|
+
* @param props.description - Human-readable description of the exit's purpose
|
|
134
|
+
* @param props.aliases - Alternative names that can be used to reference this exit
|
|
135
|
+
* @param props.metadata - Additional data for orchestration and custom logic
|
|
136
|
+
* @param props.schema - Zod schema for validating exit result data
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Simple exit without data validation
|
|
141
|
+
* const exit = new Exit({
|
|
142
|
+
* name: 'complete',
|
|
143
|
+
* description: 'Task completed successfully',
|
|
144
|
+
* })
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Exit with typed result data
|
|
150
|
+
* const approval = new Exit({
|
|
151
|
+
* name: 'approved',
|
|
152
|
+
* description: 'Request approved by system',
|
|
153
|
+
* schema: z.object({
|
|
154
|
+
* amount: z.number().positive(),
|
|
155
|
+
* reference: z.string().min(1),
|
|
156
|
+
* timestamp: z.date().default(() => new Date()),
|
|
157
|
+
* }),
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* // Exit with aliases and metadata
|
|
164
|
+
* const handoff = new Exit({
|
|
165
|
+
* name: 'handoff_support',
|
|
166
|
+
* aliases: ['escalate', 'transfer'],
|
|
167
|
+
* description: 'Transfer to human support agent',
|
|
168
|
+
* metadata: {
|
|
169
|
+
* department: 'customer_service',
|
|
170
|
+
* priority: 'high',
|
|
171
|
+
* },
|
|
172
|
+
* schema: z.object({
|
|
173
|
+
* reason: z.string(),
|
|
174
|
+
* customerData: z.record(z.any()),
|
|
175
|
+
* }),
|
|
176
|
+
* })
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
constructor(props) {
|
|
180
|
+
if (!isValidIdentifier(props.name)) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`Invalid name for exit ${props.name}. A exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (typeof props.description !== "string" || props.description.trim().length === 0) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Invalid description for exit ${props.name}. Expected a non-empty string, but got type "${typeof props.description}"`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (props.metadata !== void 0 && typeof props.metadata !== "object") {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Invalid metadata for exit ${props.name}. Expected an object, but got type "${typeof props.metadata}"`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`Invalid aliases for exit ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (props.aliases && props.aliases.some((alias) => !isValidIdentifier(alias))) {
|
|
201
|
+
throw new Error(`Invalid aliases for exit ${props.name}. Expected an array of valid identifiers.`);
|
|
202
|
+
}
|
|
203
|
+
if (typeof props.schema !== "undefined") {
|
|
204
|
+
if (isZuiSchema(props.schema)) {
|
|
205
|
+
this.schema = transforms.toJSONSchemaLegacy(props.schema);
|
|
206
|
+
} else if (isJsonSchema(props.schema)) {
|
|
207
|
+
this.schema = props.schema;
|
|
208
|
+
} else {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`Invalid input schema for exit ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.schema}"`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
this.name = props.name;
|
|
215
|
+
this.aliases = uniq_default([props.name, ...props.aliases ?? []]);
|
|
216
|
+
this.description = props.description;
|
|
217
|
+
this.metadata = props.metadata ?? {};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Ensures all exits in an array have unique names by renaming duplicates.
|
|
221
|
+
*
|
|
222
|
+
* When multiple exits have the same name, this method appends numbers to
|
|
223
|
+
* create unique names (e.g., 'exit1', 'exit2'). This prevents naming conflicts
|
|
224
|
+
* in execution contexts with multiple exits.
|
|
225
|
+
*
|
|
226
|
+
* @param exits - Array of exits that may have duplicate names
|
|
227
|
+
* @returns Array of exits with guaranteed unique names
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const exit1 = new Exit({ name: 'done', description: 'First done' })
|
|
232
|
+
* const exit2 = new Exit({ name: 'done', description: 'Second done' })
|
|
233
|
+
*
|
|
234
|
+
* const uniqueExits = Exit.withUniqueNames([exit1, exit2])
|
|
235
|
+
* // Result: [{ name: 'done' }, { name: 'done1' }]
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
static withUniqueNames = (exits) => {
|
|
239
|
+
const names = /* @__PURE__ */ new Set();
|
|
240
|
+
return exits.map((exit) => {
|
|
241
|
+
if (exits.filter((t) => t.name === exit.name).length === 1) {
|
|
242
|
+
return exit;
|
|
243
|
+
}
|
|
244
|
+
let counter = 1;
|
|
245
|
+
let exitName = exit.name + counter;
|
|
246
|
+
while (names.has(exitName)) {
|
|
247
|
+
exitName = `${exit.name}${++counter}`;
|
|
248
|
+
}
|
|
249
|
+
return exit.rename(exitName);
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export {
|
|
255
|
+
Exit
|
|
256
|
+
};
|
|
@@ -166,6 +166,9 @@ var convertObjectToZuiLiterals = (obj, nested = false) => {
|
|
|
166
166
|
if (nested) {
|
|
167
167
|
return _zui.z.object(shape).catch(() => shape);
|
|
168
168
|
}
|
|
169
|
+
if (Object.keys(shape).length === 0) {
|
|
170
|
+
return _zui.z.object({}).catch(() => shape);
|
|
171
|
+
}
|
|
169
172
|
return shape;
|
|
170
173
|
}
|
|
171
174
|
if (obj === void 0) {
|