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
package/dist/objects.d.ts
CHANGED
|
@@ -1,18 +1,305 @@
|
|
|
1
1
|
import { z } from '@bpinternal/zui';
|
|
2
2
|
import { Tool } from './tool.js';
|
|
3
|
+
import { Serializable } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Defines a property within an ObjectInstance.
|
|
6
|
+
*
|
|
7
|
+
* Properties are stateful variables that can be accessed and optionally modified
|
|
8
|
+
* by the generated TypeScript code. They provide a way to maintain state across
|
|
9
|
+
* execution iterations and can include validation rules.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const userAgeProperty: ObjectProperty = {
|
|
14
|
+
* name: 'age',
|
|
15
|
+
* description: 'User age with validation constraints',
|
|
16
|
+
* value: 25,
|
|
17
|
+
* type: z.number().min(18).max(100),
|
|
18
|
+
* writable: true,
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
3
22
|
export type ObjectProperty = {
|
|
23
|
+
/** The name of the property (must be a valid TypeScript identifier) */
|
|
4
24
|
name: string;
|
|
25
|
+
/** The current value of the property */
|
|
5
26
|
value: any;
|
|
27
|
+
/** Optional Zod schema for validation when the property is modified */
|
|
6
28
|
type?: z.Schema;
|
|
29
|
+
/** Optional human-readable description of the property */
|
|
7
30
|
description?: string;
|
|
31
|
+
/** Whether the LLM can modify this property (default: false) */
|
|
8
32
|
writable?: boolean;
|
|
9
33
|
};
|
|
10
|
-
export declare
|
|
34
|
+
export declare namespace ObjectInstance {
|
|
35
|
+
type JSON = {
|
|
36
|
+
name: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
properties?: ObjectProperty[];
|
|
39
|
+
tools?: Tool.JSON[];
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* ObjectInstance creates stateful, namespace-scoped objects for LLMz agents.
|
|
45
|
+
*
|
|
46
|
+
* Objects combine properties (stateful variables) and tools (functions) into a
|
|
47
|
+
* single namespace that the LLM can interact with. This provides organized,
|
|
48
|
+
* type-safe interfaces for complex data and functionality.
|
|
49
|
+
*
|
|
50
|
+
* ## Key Features
|
|
51
|
+
* - **Stateful Properties**: Variables that persist across execution iterations
|
|
52
|
+
* - **Validation**: Zod schema validation for property changes
|
|
53
|
+
* - **Tool Grouping**: Organize related tools under a common namespace
|
|
54
|
+
* - **Type Safety**: Full TypeScript inference and validation
|
|
55
|
+
* - **Dynamic Updates**: Properties can reflect real-time state changes
|
|
56
|
+
*
|
|
57
|
+
* ## Use Cases
|
|
58
|
+
* - **User Profile Management**: Collect and validate user data over time
|
|
59
|
+
* - **API Namespacing**: Group related API calls under a common interface
|
|
60
|
+
* - **State Machines**: Track and modify execution state
|
|
61
|
+
* - **Configuration Objects**: Manage settings and preferences
|
|
62
|
+
* - **Multi-Agent Systems**: Per-agent state and capabilities
|
|
63
|
+
*
|
|
64
|
+
* ## Basic Usage
|
|
65
|
+
*
|
|
66
|
+
* ### Simple Property Object
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const userProfile = new ObjectInstance({
|
|
69
|
+
* name: 'user',
|
|
70
|
+
* description: 'User profile data',
|
|
71
|
+
* properties: [
|
|
72
|
+
* {
|
|
73
|
+
* name: 'name',
|
|
74
|
+
* value: 'John Doe',
|
|
75
|
+
* type: z.string().min(1),
|
|
76
|
+
* writable: true,
|
|
77
|
+
* },
|
|
78
|
+
* {
|
|
79
|
+
* name: 'email',
|
|
80
|
+
* value: null,
|
|
81
|
+
* type: z.string().email().nullable(),
|
|
82
|
+
* writable: true,
|
|
83
|
+
* },
|
|
84
|
+
* {
|
|
85
|
+
* name: 'id',
|
|
86
|
+
* value: 'user_123',
|
|
87
|
+
* writable: false, // Read-only
|
|
88
|
+
* },
|
|
89
|
+
* ],
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* // LLM can access and modify: user.name, user.email
|
|
93
|
+
* // LLM can read only: user.id
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* ### Tool Grouping
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const fileSystem = new ObjectInstance({
|
|
99
|
+
* name: 'fs',
|
|
100
|
+
* description: 'File system operations',
|
|
101
|
+
* tools: [
|
|
102
|
+
* new Tool({
|
|
103
|
+
* name: 'readFile',
|
|
104
|
+
* input: z.object({ path: z.string() }),
|
|
105
|
+
* output: z.string(),
|
|
106
|
+
* handler: async ({ path }) => readFileSync(path, 'utf8'),
|
|
107
|
+
* }),
|
|
108
|
+
* new Tool({
|
|
109
|
+
* name: 'writeFile',
|
|
110
|
+
* input: z.object({ path: z.string(), content: z.string() }),
|
|
111
|
+
* handler: async ({ path, content }) => writeFileSync(path, content),
|
|
112
|
+
* }),
|
|
113
|
+
* ],
|
|
114
|
+
* })
|
|
115
|
+
*
|
|
116
|
+
* // LLM can call: fs.readFile(), fs.writeFile()
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* ### Combined Properties and Tools
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const database = new ObjectInstance({
|
|
122
|
+
* name: 'db',
|
|
123
|
+
* description: 'Database connection with state',
|
|
124
|
+
* properties: [
|
|
125
|
+
* {
|
|
126
|
+
* name: 'connectionString',
|
|
127
|
+
* value: 'postgresql://localhost:5432/mydb',
|
|
128
|
+
* writable: false,
|
|
129
|
+
* },
|
|
130
|
+
* {
|
|
131
|
+
* name: 'lastQuery',
|
|
132
|
+
* value: null,
|
|
133
|
+
* type: z.string().nullable(),
|
|
134
|
+
* writable: true,
|
|
135
|
+
* },
|
|
136
|
+
* ],
|
|
137
|
+
* tools: [
|
|
138
|
+
* new Tool({
|
|
139
|
+
* name: 'query',
|
|
140
|
+
* input: z.object({ sql: z.string() }),
|
|
141
|
+
* output: z.array(z.record(z.any())),
|
|
142
|
+
* handler: async ({ sql }) => {
|
|
143
|
+
* // Execute query and update lastQuery property
|
|
144
|
+
* const results = await executeQuery(sql)
|
|
145
|
+
* return results
|
|
146
|
+
* },
|
|
147
|
+
* }),
|
|
148
|
+
* ],
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* ## Dynamic Objects
|
|
153
|
+
*
|
|
154
|
+
* Objects can be created dynamically to reflect current state:
|
|
155
|
+
*
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const memory: Record<string, any> = {}
|
|
158
|
+
*
|
|
159
|
+
* const getObjects = () => [
|
|
160
|
+
* new ObjectInstance({
|
|
161
|
+
* name: 'user',
|
|
162
|
+
* properties: [
|
|
163
|
+
* {
|
|
164
|
+
* name: 'name',
|
|
165
|
+
* value: memory.name ?? null,
|
|
166
|
+
* type: z.string().nullable(),
|
|
167
|
+
* writable: true,
|
|
168
|
+
* },
|
|
169
|
+
* {
|
|
170
|
+
* name: 'age',
|
|
171
|
+
* value: memory.age ?? null,
|
|
172
|
+
* type: z.number().min(18).max(100).nullable(),
|
|
173
|
+
* writable: true,
|
|
174
|
+
* },
|
|
175
|
+
* ],
|
|
176
|
+
* }),
|
|
177
|
+
* ]
|
|
178
|
+
*
|
|
179
|
+
* await execute({
|
|
180
|
+
* objects: getObjects, // Function returning current state
|
|
181
|
+
* onTrace: ({ trace }) => {
|
|
182
|
+
* if (trace.type === 'property') {
|
|
183
|
+
* // Persist property changes
|
|
184
|
+
* memory[trace.property] = trace.value
|
|
185
|
+
* }
|
|
186
|
+
* },
|
|
187
|
+
* // ...
|
|
188
|
+
* })
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* ## Property Validation
|
|
192
|
+
*
|
|
193
|
+
* Properties support comprehensive validation through Zod schemas:
|
|
194
|
+
*
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const userSettings = new ObjectInstance({
|
|
197
|
+
* name: 'settings',
|
|
198
|
+
* properties: [
|
|
199
|
+
* {
|
|
200
|
+
* name: 'theme',
|
|
201
|
+
* value: 'light',
|
|
202
|
+
* type: z.enum(['light', 'dark']),
|
|
203
|
+
* writable: true,
|
|
204
|
+
* },
|
|
205
|
+
* {
|
|
206
|
+
* name: 'maxRetries',
|
|
207
|
+
* value: 3,
|
|
208
|
+
* type: z.number().min(1).max(10),
|
|
209
|
+
* writable: true,
|
|
210
|
+
* },
|
|
211
|
+
* {
|
|
212
|
+
* name: 'email',
|
|
213
|
+
* value: null,
|
|
214
|
+
* type: z.string().email().nullable(),
|
|
215
|
+
* writable: true,
|
|
216
|
+
* },
|
|
217
|
+
* ],
|
|
218
|
+
* })
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* ## TypeScript Integration
|
|
222
|
+
*
|
|
223
|
+
* Objects generate TypeScript namespace declarations:
|
|
224
|
+
*
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Generated types for the LLM context:
|
|
227
|
+
* export namespace user {
|
|
228
|
+
* const name: Writable<string | null> = null
|
|
229
|
+
* const age: Writable<number | null> = null
|
|
230
|
+
* const id: Readonly<string> = "user_123"
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* export namespace fs {
|
|
234
|
+
* function readFile(args: { path: string }): Promise<string>
|
|
235
|
+
* function writeFile(args: { path: string, content: string }): Promise<void>
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @see {@link https://github.com/botpress/botpress/blob/master/packages/llmz/examples/09_chat_variables/index.ts} Example usage
|
|
240
|
+
*/
|
|
241
|
+
export declare class ObjectInstance implements Serializable<ObjectInstance.JSON> {
|
|
11
242
|
name: string;
|
|
12
243
|
description?: string;
|
|
13
244
|
properties?: ObjectProperty[];
|
|
14
245
|
tools?: Tool[];
|
|
15
246
|
metadata?: Record<string, unknown>;
|
|
247
|
+
/**
|
|
248
|
+
* Creates a new ObjectInstance.
|
|
249
|
+
*
|
|
250
|
+
* @param props - Object configuration
|
|
251
|
+
* @param props.name - Unique object name (must be valid TypeScript identifier)
|
|
252
|
+
* @param props.description - Human-readable description of the object
|
|
253
|
+
* @param props.tools - Array of tools to group under this object namespace
|
|
254
|
+
* @param props.properties - Array of stateful properties for this object
|
|
255
|
+
* @param props.metadata - Additional metadata for the object
|
|
256
|
+
*
|
|
257
|
+
* @throws Error if name is not a valid identifier
|
|
258
|
+
* @throws Error if description is not a string
|
|
259
|
+
* @throws Error if metadata is not an object
|
|
260
|
+
* @throws Error if properties/tools are not arrays
|
|
261
|
+
* @throws Error if properties exceed 100 limit
|
|
262
|
+
* @throws Error if property names are duplicated or invalid
|
|
263
|
+
* @throws Error if property descriptions exceed 5000 characters
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const userProfile = new ObjectInstance({
|
|
268
|
+
* name: 'user',
|
|
269
|
+
* description: 'User profile management',
|
|
270
|
+
* properties: [
|
|
271
|
+
* {
|
|
272
|
+
* name: 'name',
|
|
273
|
+
* value: 'John Doe',
|
|
274
|
+
* type: z.string().min(1),
|
|
275
|
+
* description: 'User full name',
|
|
276
|
+
* writable: true,
|
|
277
|
+
* },
|
|
278
|
+
* {
|
|
279
|
+
* name: 'email',
|
|
280
|
+
* value: null,
|
|
281
|
+
* type: z.string().email().nullable(),
|
|
282
|
+
* description: 'User email address',
|
|
283
|
+
* writable: true,
|
|
284
|
+
* },
|
|
285
|
+
* ],
|
|
286
|
+
* tools: [
|
|
287
|
+
* new Tool({
|
|
288
|
+
* name: 'updateProfile',
|
|
289
|
+
* input: z.object({ name: z.string(), email: z.string() }),
|
|
290
|
+
* handler: async ({ name, email }) => {
|
|
291
|
+
* // Update external system
|
|
292
|
+
* await updateUserInDatabase({ name, email })
|
|
293
|
+
* },
|
|
294
|
+
* }),
|
|
295
|
+
* ],
|
|
296
|
+
* metadata: {
|
|
297
|
+
* version: '1.0',
|
|
298
|
+
* category: 'user-management',
|
|
299
|
+
* },
|
|
300
|
+
* })
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
16
303
|
constructor(props: {
|
|
17
304
|
name: string;
|
|
18
305
|
description?: string;
|
|
@@ -20,5 +307,67 @@ export declare class ObjectInstance {
|
|
|
20
307
|
properties?: ObjectProperty[];
|
|
21
308
|
metadata?: Record<string, unknown>;
|
|
22
309
|
});
|
|
310
|
+
/**
|
|
311
|
+
* Generates TypeScript namespace declarations for this object.
|
|
312
|
+
*
|
|
313
|
+
* This method creates TypeScript definitions that are included in the LLM context
|
|
314
|
+
* to help it understand the available properties and tools. Properties become
|
|
315
|
+
* const declarations with appropriate Readonly/Writable types, and tools become
|
|
316
|
+
* function signatures.
|
|
317
|
+
*
|
|
318
|
+
* @returns Promise resolving to TypeScript namespace declaration
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const obj = new ObjectInstance({
|
|
323
|
+
* name: 'user',
|
|
324
|
+
* properties: [
|
|
325
|
+
* { name: 'name', value: 'John', writable: true },
|
|
326
|
+
* { name: 'id', value: 123, writable: false },
|
|
327
|
+
* ],
|
|
328
|
+
* tools: [
|
|
329
|
+
* new Tool({
|
|
330
|
+
* name: 'save',
|
|
331
|
+
* input: z.object({ data: z.string() }),
|
|
332
|
+
* handler: async ({ data }) => { /* ... *\/ },
|
|
333
|
+
* }),
|
|
334
|
+
* ],
|
|
335
|
+
* })
|
|
336
|
+
*
|
|
337
|
+
* const typings = await obj.getTypings()
|
|
338
|
+
* console.log(typings)
|
|
339
|
+
* // Output:
|
|
340
|
+
* // export namespace user {
|
|
341
|
+
* // const name: Writable<string> = "John"
|
|
342
|
+
* // const id: Readonly<number> = 123
|
|
343
|
+
* // function save(args: { data: string }): Promise<void>
|
|
344
|
+
* // }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
23
347
|
getTypings(): Promise<string>;
|
|
348
|
+
/**
|
|
349
|
+
* Converts this ObjectInstance to its JSON representation.
|
|
350
|
+
*
|
|
351
|
+
* This method serializes the object into a JSON format that includes its name,
|
|
352
|
+
* description, properties, tools, and metadata. It is used for serialization
|
|
353
|
+
* and transmission of the object state.
|
|
354
|
+
*
|
|
355
|
+
* @returns JSON representation of the ObjectInstance
|
|
356
|
+
*/
|
|
357
|
+
toJSON(): {
|
|
358
|
+
name: string;
|
|
359
|
+
description: string | undefined;
|
|
360
|
+
properties: ObjectProperty[] | undefined;
|
|
361
|
+
tools: {
|
|
362
|
+
name: string;
|
|
363
|
+
aliases: string[];
|
|
364
|
+
description: string | undefined;
|
|
365
|
+
metadata: Record<string, unknown>;
|
|
366
|
+
input: import("json-schema").JSONSchema7 | undefined;
|
|
367
|
+
output: import("json-schema").JSONSchema7 | undefined;
|
|
368
|
+
staticInputValues: unknown;
|
|
369
|
+
maxRetries: number;
|
|
370
|
+
}[];
|
|
371
|
+
metadata: Record<string, unknown> | undefined;
|
|
372
|
+
};
|
|
24
373
|
}
|