@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.0

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 (199) hide show
  1. package/dist/agent-init/agent-project-generator.d.ts +5 -1
  2. package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
  3. package/dist/agent-project/agent-project.d.ts +3 -3
  4. package/dist/agent-project/agent-project.d.ts.map +1 -1
  5. package/dist/agent-project/agent-resolver.d.ts.map +1 -1
  6. package/dist/agent-project/config-writer.d.ts +1 -1
  7. package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
  8. package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
  9. package/dist/agent-project/types.d.ts +9 -4
  10. package/dist/agent-project/types.d.ts.map +1 -1
  11. package/dist/agent0/capabilities/commands/adk-build.md +6 -5
  12. package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
  13. package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
  14. package/dist/agent0/capabilities/commands/adk-document.md +10 -2
  15. package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
  16. package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
  17. package/dist/agent0/capabilities/commands/adk-init.md +2 -2
  18. package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
  19. package/dist/agent0/capabilities/commands/adk-test.md +3 -3
  20. package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
  21. package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
  22. package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
  23. package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
  24. package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
  25. package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
  26. package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
  27. package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
  28. package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
  29. package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
  30. package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
  31. package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
  32. package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
  33. package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
  34. package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
  35. package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
  36. package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
  37. package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
  38. package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
  39. package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
  40. package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
  41. package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
  42. package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
  43. package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
  44. package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
  45. package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
  46. package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
  47. package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
  48. package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
  49. package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
  50. package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
  51. package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
  52. package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
  53. package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
  54. package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
  55. package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
  56. package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
  57. package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
  58. package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
  59. package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
  60. package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
  61. package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
  62. package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
  63. package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
  64. package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
  65. package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
  66. package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
  67. package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
  68. package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
  69. package/dist/agent0/index.js +41 -19
  70. package/dist/agent0/index.js.map +7 -7
  71. package/dist/agent0/runtime/client.d.ts +2 -0
  72. package/dist/agent0/runtime/client.d.ts.map +1 -1
  73. package/dist/agent0/runtime/engine.d.ts +2 -1
  74. package/dist/agent0/runtime/engine.d.ts.map +1 -1
  75. package/dist/agent0/runtime/process.d.ts +1 -0
  76. package/dist/agent0/runtime/process.d.ts.map +1 -1
  77. package/dist/assets/manager.d.ts +3 -0
  78. package/dist/assets/manager.d.ts.map +1 -1
  79. package/dist/auth/credentials.d.ts +1 -1
  80. package/dist/bot-generator/generator.d.ts +22 -0
  81. package/dist/bot-generator/generator.d.ts.map +1 -1
  82. package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
  83. package/dist/commands/base-command.d.ts +1 -0
  84. package/dist/commands/base-command.d.ts.map +1 -1
  85. package/dist/commands/bp-dev-command.d.ts +1 -1
  86. package/dist/commands/bp-dev-command.d.ts.map +1 -1
  87. package/dist/commands/bp-dev-stderr.d.ts +9 -0
  88. package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
  89. package/dist/commands/index.d.ts +1 -0
  90. package/dist/commands/index.d.ts.map +1 -1
  91. package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
  92. package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
  93. package/dist/dependencies/catalog/client-factory.d.ts +33 -0
  94. package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
  95. package/dist/dependencies/catalog/integration-source.d.ts +34 -0
  96. package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
  97. package/dist/dependencies/catalog/interface-source.d.ts +23 -0
  98. package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
  99. package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
  100. package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
  101. package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
  102. package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
  103. package/dist/dependencies/dependency-manager.d.ts +31 -16
  104. package/dist/dependencies/dependency-manager.d.ts.map +1 -1
  105. package/dist/dependencies/errors.d.ts +2 -2
  106. package/dist/dependencies/errors.d.ts.map +1 -1
  107. package/dist/dependencies/index.d.ts +5 -4
  108. package/dist/dependencies/index.d.ts.map +1 -1
  109. package/dist/dependencies/index.js +2089 -1670
  110. package/dist/dependencies/index.js.map +37 -30
  111. package/dist/dependencies/legacy-lock-file.d.ts +15 -0
  112. package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
  113. package/dist/dependencies/migration.d.ts +19 -0
  114. package/dist/dependencies/migration.d.ts.map +1 -1
  115. package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
  116. package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
  117. package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
  118. package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
  119. package/dist/dependencies/snapshot-store.d.ts +59 -0
  120. package/dist/dependencies/snapshot-store.d.ts.map +1 -0
  121. package/dist/dependencies/status-resolver.d.ts +36 -0
  122. package/dist/dependencies/status-resolver.d.ts.map +1 -0
  123. package/dist/dependencies/status.d.ts +214 -0
  124. package/dist/dependencies/status.d.ts.map +1 -0
  125. package/dist/dependencies/types.d.ts +380 -29
  126. package/dist/dependencies/types.d.ts.map +1 -1
  127. package/dist/file-watcher/watcher.d.ts +21 -5
  128. package/dist/file-watcher/watcher.d.ts.map +1 -1
  129. package/dist/generators/action-types.d.ts.map +1 -1
  130. package/dist/generators/client-wrapper.d.ts.map +1 -1
  131. package/dist/index.d.ts +4 -5
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +3134 -2226
  134. package/dist/index.js.map +55 -48
  135. package/dist/integrations/config-utils.d.ts +11 -7
  136. package/dist/integrations/config-utils.d.ts.map +1 -1
  137. package/dist/integrations/hub-cache.d.ts +0 -58
  138. package/dist/integrations/hub-cache.d.ts.map +1 -1
  139. package/dist/integrations/index.d.ts +1 -3
  140. package/dist/integrations/index.d.ts.map +1 -1
  141. package/dist/integrations/manager.d.ts +19 -53
  142. package/dist/integrations/manager.d.ts.map +1 -1
  143. package/dist/interfaces/enhanced-cache.d.ts +7 -7
  144. package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
  145. package/dist/interfaces/manager.d.ts +11 -17
  146. package/dist/interfaces/manager.d.ts.map +1 -1
  147. package/dist/knowledge/manager.d.ts +3 -0
  148. package/dist/knowledge/manager.d.ts.map +1 -1
  149. package/dist/plugins/index.d.ts +0 -1
  150. package/dist/plugins/index.d.ts.map +1 -1
  151. package/dist/plugins/manager.d.ts +16 -48
  152. package/dist/plugins/manager.d.ts.map +1 -1
  153. package/dist/preflight/checker.d.ts +6 -1
  154. package/dist/preflight/checker.d.ts.map +1 -1
  155. package/dist/preflight/dependency-gate.d.ts +37 -0
  156. package/dist/preflight/dependency-gate.d.ts.map +1 -0
  157. package/dist/preflight/index.d.ts +2 -1
  158. package/dist/preflight/index.d.ts.map +1 -1
  159. package/dist/preflight/types.d.ts +18 -0
  160. package/dist/preflight/types.d.ts.map +1 -1
  161. package/dist/runner/script-runner.d.ts.map +1 -1
  162. package/dist/tables/table-manager.d.ts +3 -0
  163. package/dist/tables/table-manager.d.ts.map +1 -1
  164. package/dist/templates/README.md +23 -13
  165. package/dist/templates/blank/agent.config.ts +3 -3
  166. package/dist/templates/blank/src/triggers/index.ts +1 -1
  167. package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
  168. package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
  169. package/dist/templates/crm-enrichment/README.md +3 -3
  170. package/dist/templates/crm-enrichment/agent.config.ts +2 -2
  171. package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
  172. package/dist/templates/hello-world/agent.config.ts +3 -3
  173. package/dist/templates/hello-world/src/triggers/index.ts +1 -1
  174. package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
  175. package/dist/templates/template.config.json +3 -3
  176. package/dist/utils/ids.d.ts +10 -0
  177. package/dist/utils/ids.d.ts.map +1 -1
  178. package/dist/workspace/workspace-cache.d.ts +2 -1
  179. package/dist/workspace/workspace-cache.d.ts.map +1 -1
  180. package/package.json +3 -3
  181. package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
  182. package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
  183. package/dist/dependencies/lock-file.d.ts +0 -15
  184. package/dist/dependencies/lock-file.d.ts.map +0 -1
  185. package/dist/integrations/enhanced-cache.d.ts +0 -53
  186. package/dist/integrations/enhanced-cache.d.ts.map +0 -1
  187. package/dist/plugins/enhanced-cache.d.ts +0 -53
  188. package/dist/plugins/enhanced-cache.d.ts.map +0 -1
  189. package/dist/templates/blank/package.json +0 -17
  190. package/dist/templates/blank/tsconfig.json +0 -25
  191. package/dist/templates/botpress-desk/package.json +0 -17
  192. package/dist/templates/crm-enrichment/package.json +0 -18
  193. package/dist/templates/crm-enrichment/tsconfig.json +0 -25
  194. package/dist/templates/hello-world/package.json +0 -18
  195. package/dist/templates/hello-world/tsconfig.json +0 -25
  196. package/dist/templates/knowledge-assistant/package.json +0 -18
  197. package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
  198. package/dist/templates/slack-triage/package.json +0 -18
  199. package/dist/templates/slack-triage/tsconfig.json +0 -25
@@ -9,16 +9,10 @@ ZAI is pre-configured in your ADK environment. Use `adk.zai.*` to access LLM ope
9
9
  Extract structured data from any input using Zod schema. Auto-handles large documents via chunking.
10
10
 
11
11
  ```typescript
12
- await zai.extract(
13
- "John is 30",
14
- z.object({ name: z.string(), age: z.number() }),
15
- );
12
+ await zai.extract('John is 30', z.object({ name: z.string(), age: z.number() }))
16
13
  // → { name: 'John', age: 30 }
17
14
 
18
- await zai.extract(
19
- emails,
20
- z.array(z.object({ from: z.string(), subject: z.string() })),
21
- );
15
+ await zai.extract(emails, z.array(z.object({ from: z.string(), subject: z.string() })))
22
16
  // → [{ from: 'alice@example.com', subject: 'Meeting' }, ...]
23
17
  ```
24
18
 
@@ -27,8 +21,8 @@ await zai.extract(
27
21
  Boolean verification using natural language.
28
22
 
29
23
  ```typescript
30
- await zai.check("Buy cheap pills!", "is spam"); // → true
31
- await zai.check(code, "contains SQL injection vulnerability"); // → boolean
24
+ await zai.check('Buy cheap pills!', 'is spam') // → true
25
+ await zai.check(code, 'contains SQL injection vulnerability') // → boolean
32
26
  ```
33
27
 
34
28
  ### `zai.label(input, criteria)`
@@ -37,10 +31,10 @@ Apply multiple boolean labels simultaneously.
37
31
 
38
32
  ```typescript
39
33
  await zai.label(customerEmail, {
40
- spam: "is spam",
41
- urgent: "requires immediate response",
42
- complaint: "expresses dissatisfaction",
43
- });
34
+ spam: 'is spam',
35
+ urgent: 'requires immediate response',
36
+ complaint: 'expresses dissatisfaction',
37
+ })
44
38
  // → { spam: false, urgent: true, complaint: true }
45
39
  ```
46
40
 
@@ -49,9 +43,9 @@ await zai.label(customerEmail, {
49
43
  Transform text per instruction.
50
44
 
51
45
  ```typescript
52
- await zai.rewrite("hey wassup", "make professional"); // → 'Hello, how are you?'
53
- await zai.rewrite(html, "convert to markdown");
54
- await zai.rewrite(text, "translate to French");
46
+ await zai.rewrite('hey wassup', 'make professional') // → 'Hello, how are you?'
47
+ await zai.rewrite(html, 'convert to markdown')
48
+ await zai.rewrite(text, 'translate to French')
55
49
  ```
56
50
 
57
51
  ### `zai.filter(array, condition)`
@@ -59,8 +53,8 @@ await zai.rewrite(text, "translate to French");
59
53
  Filter arrays with natural language.
60
54
 
61
55
  ```typescript
62
- await zai.filter(users, "have purchased in last 30 days");
63
- await zai.filter([1, 2, 3, 4, 5], "are prime numbers"); // → [2,3,5]
56
+ await zai.filter(users, 'have purchased in last 30 days')
57
+ await zai.filter([1, 2, 3, 4, 5], 'are prime numbers') // → [2,3,5]
64
58
  ```
65
59
 
66
60
  ### `zai.text(prompt)`
@@ -68,8 +62,8 @@ await zai.filter([1, 2, 3, 4, 5], "are prime numbers"); // → [2,3,5]
68
62
  Generate text from prompt.
69
63
 
70
64
  ```typescript
71
- await zai.text("Write a regex for email validation");
72
- await zai.text("SQL query to find duplicate records");
65
+ await zai.text('Write a regex for email validation')
66
+ await zai.text('SQL query to find duplicate records')
73
67
  ```
74
68
 
75
69
  ### `zai.summarize(input)`
@@ -77,11 +71,11 @@ await zai.text("SQL query to find duplicate records");
77
71
  Create intelligent summary. Handles any size via auto-chunking.
78
72
 
79
73
  ```typescript
80
- await zai.summarize(longDocument);
74
+ await zai.summarize(longDocument)
81
75
  await zai.summarize(chatHistory, {
82
76
  length: 200,
83
- prompt: "focus on decisions made",
84
- });
77
+ prompt: 'focus on decisions made',
78
+ })
85
79
  ```
86
80
 
87
81
  ### `zai.answer(documents, question)`
@@ -90,24 +84,24 @@ Answer questions from documents with citations and intelligent edge case handlin
90
84
 
91
85
  ```typescript
92
86
  const docs = [
93
- "Botpress was founded in 2016.",
94
- "The company is based in Quebec, Canada.",
95
- "Botpress provides an AI agent platform.",
96
- ];
97
-
98
- const result = await zai.answer(docs, "When was Botpress founded?");
99
- if (result.type === "answer") {
100
- console.log(result.answer); // "Botpress was founded in 2016."
101
- console.log(result.citations); // [{ offset: 30, item: docs[0], snippet: '...' }]
87
+ 'Botpress was founded in 2016.',
88
+ 'The company is based in Quebec, Canada.',
89
+ 'Botpress provides an AI agent platform.',
90
+ ]
91
+
92
+ const result = await zai.answer(docs, 'When was Botpress founded?')
93
+ if (result.type === 'answer') {
94
+ console.log(result.answer) // "Botpress was founded in 2016."
95
+ console.log(result.citations) // [{ offset: 30, item: docs[0], snippet: '...' }]
102
96
  }
103
97
 
104
98
  // Handle different response types
105
99
  switch (result.type) {
106
- case "answer": // Has answer and citations
107
- case "ambiguous": // Multiple interpretations, has follow_up question
108
- case "out_of_topic": // Question unrelated to documents
109
- case "invalid_question": // Malformed or unclear question
110
- case "missing_knowledge": // Insufficient information
100
+ case 'answer': // Has answer and citations
101
+ case 'ambiguous': // Multiple interpretations, has follow_up question
102
+ case 'out_of_topic': // Question unrelated to documents
103
+ case 'invalid_question': // Malformed or unclear question
104
+ case 'missing_knowledge': // Insufficient information
111
105
  }
112
106
  ```
113
107
 
@@ -117,15 +111,15 @@ Rate array items on a 1-5 scale. Returns single score or multiple criteria score
117
111
 
118
112
  ```typescript
119
113
  // Single criterion (returns number 1-5)
120
- await zai.rate(customerEmails, "urgency level");
114
+ await zai.rate(customerEmails, 'urgency level')
121
115
  // → [4, 2, 5, 1, 3]
122
116
 
123
117
  // Multiple criteria (returns scores object)
124
118
  await zai.rate(products, {
125
- quality: "product build quality",
126
- value: "price to performance ratio",
127
- design: "aesthetic appeal",
128
- });
119
+ quality: 'product build quality',
120
+ value: 'price to performance ratio',
121
+ design: 'aesthetic appeal',
122
+ })
129
123
  // → [{ quality: 5, value: 4, design: 5, total: 14 }, ...]
130
124
  ```
131
125
 
@@ -134,9 +128,9 @@ await zai.rate(products, {
134
128
  Sort array based on natural language instructions.
135
129
 
136
130
  ```typescript
137
- await zai.sort(tickets, "from least urgent to most urgent");
138
- await zai.sort(products, "by price, cheapest first");
139
- await zai.sort(emails, "prioritize: open old items highest");
131
+ await zai.sort(tickets, 'from least urgent to most urgent')
132
+ await zai.sort(products, 'by price, cheapest first')
133
+ await zai.sort(emails, 'prioritize: open old items highest')
140
134
  // Returns sorted array directly
141
135
  ```
142
136
 
@@ -146,8 +140,8 @@ Group array elements based on natural language criteria.
146
140
 
147
141
  ```typescript
148
142
  await zai.group(tickets, {
149
- instructions: "group by issue type and priority",
150
- });
143
+ instructions: 'group by issue type and priority',
144
+ })
151
145
  // → [
152
146
  // { id: 'bugs', label: 'Bug Reports', elements: [...] },
153
147
  // { id: 'features', label: 'Feature Requests', elements: [...] }
@@ -155,12 +149,12 @@ await zai.group(tickets, {
155
149
 
156
150
  // With initial groups
157
151
  await zai.group(emails, {
158
- instructions: "categorize emails",
152
+ instructions: 'categorize emails',
159
153
  initialGroups: [
160
- { id: "urgent", label: "Urgent" },
161
- { id: "spam", label: "Spam" },
154
+ { id: 'urgent', label: 'Urgent' },
155
+ { id: 'spam', label: 'Spam' },
162
156
  ],
163
- });
157
+ })
164
158
  ```
165
159
 
166
160
  ### `zai.patch(files, instructions)`
@@ -170,19 +164,19 @@ Patch code files using natural language instructions. Uses efficient micropatch
170
164
  ```typescript
171
165
  const files = [
172
166
  {
173
- path: "src/hello.ts",
174
- name: "hello.ts",
167
+ path: 'src/hello.ts',
168
+ name: 'hello.ts',
175
169
  content: 'console.log("Hello World")',
176
170
  },
177
- ];
171
+ ]
178
172
 
179
- const patched = await zai.patch(files, 'change message to "Hi World"');
173
+ const patched = await zai.patch(files, 'change message to "Hi World"')
180
174
  // → [{ path: 'src/hello.ts', content: 'console.log("Hi World")', patch: '...' }]
181
175
 
182
176
  // Works with multiple files
183
- await zai.patch(files, "add JSDoc comments to all functions");
184
- await zai.patch(files, "remove all debug code");
185
- await zai.patch(files, "update version to 2.0.0 in all config files");
177
+ await zai.patch(files, 'add JSDoc comments to all functions')
178
+ await zai.patch(files, 'remove all debug code')
179
+ await zai.patch(files, 'update version to 2.0.0 in all config files')
186
180
  ```
187
181
 
188
182
  ## Advanced Usage
@@ -192,9 +186,9 @@ await zai.patch(files, "update version to 2.0.0 in all config files");
192
186
  Create a new instance with modified configuration.
193
187
 
194
188
  ```typescript
195
- const creativeZai = zai.with({ temperature: 0.9 });
196
- const fastZai = zai.with({ modelId: "fast" });
197
- const preciseZai = zai.with({ modelId: "best" }).learn("extraction-task");
189
+ const creativeZai = zai.with({ temperature: 0.9 })
190
+ const fastZai = zai.with({ modelId: 'fast' })
191
+ const preciseZai = zai.with({ modelId: 'best' }).learn('extraction-task')
198
192
  ```
199
193
 
200
194
  ### `zai.learn(taskId)`
@@ -202,8 +196,8 @@ const preciseZai = zai.with({ modelId: "best" }).learn("extraction-task");
202
196
  Enable learning for repetitive tasks. Caches exact matches, uses approved examples.
203
197
 
204
198
  ```typescript
205
- const smartZai = zai.learn("invoice-parsing");
206
- await smartZai.extract(invoice, invoiceSchema); // Learns patterns over time
199
+ const smartZai = zai.learn('invoice-parsing')
200
+ await smartZai.extract(invoice, invoiceSchema) // Learns patterns over time
207
201
  ```
208
202
 
209
203
  ### Response Methods
@@ -211,63 +205,60 @@ await smartZai.extract(invoice, invoiceSchema); // Learns patterns over time
211
205
  All operations return a Response object:
212
206
 
213
207
  ```typescript
214
- const result = await zai.check(text, "is positive"); // Simple boolean
215
- const { value, explanation } = await result.full(); // Detailed result
216
- const { tokens, cost } = await result.usage(); // Usage metrics
208
+ const result = await zai.check(text, 'is positive') // Simple boolean
209
+ const { value, explanation } = await result.full() // Detailed result
210
+ const { tokens, cost } = await result.usage() // Usage metrics
217
211
  ```
218
212
 
219
213
  ### Options (all operations)
220
214
 
221
215
  ```typescript
222
216
  await zai.extract(input, schema, {
223
- instructions: "Focus on financial data only",
217
+ instructions: 'Focus on financial data only',
224
218
  strict: false, // Allow partial matches
225
219
  chunkLength: 8000, // For large docs
226
- });
220
+ })
227
221
  ```
228
222
 
229
223
  ## Quick Patterns
230
224
 
231
225
  ```typescript
232
226
  // Validate and extract
233
- if (await zai.check(input, "is valid JSON")) {
234
- const data = await zai.extract(input, schema);
227
+ if (await zai.check(input, 'is valid JSON')) {
228
+ const data = await zai.extract(input, schema)
235
229
  }
236
230
 
237
231
  // Multi-step processing
238
- const clean = await zai.rewrite(userInput, "remove profanity");
239
- const translated = await zai.rewrite(clean, "translate to Spanish");
232
+ const clean = await zai.rewrite(userInput, 'remove profanity')
233
+ const translated = await zai.rewrite(clean, 'translate to Spanish')
240
234
 
241
235
  // Conditional filtering
242
- const urgentTickets = await zai.filter(
243
- tickets,
244
- "require response within 1 hour",
245
- );
236
+ const urgentTickets = await zai.filter(tickets, 'require response within 1 hour')
246
237
 
247
238
  // Smart extraction with learning
248
- const parser = zai.learn("resume-parser");
249
- const candidate = await parser.extract(resume, candidateSchema);
239
+ const parser = zai.learn('resume-parser')
240
+ const candidate = await parser.extract(resume, candidateSchema)
250
241
 
251
242
  // Question answering with citations
252
- const result = await zai.answer(knowledgeBase, userQuestion);
253
- if (result.type === "answer") {
254
- return { answer: result.answer, sources: result.citations };
243
+ const result = await zai.answer(knowledgeBase, userQuestion)
244
+ if (result.type === 'answer') {
245
+ return { answer: result.answer, sources: result.citations }
255
246
  }
256
247
 
257
248
  // Rate and sort workflow
258
- const rated = await zai.rate(items, "quality score");
259
- const sorted = await zai.sort(items, "by quality, best first");
249
+ const rated = await zai.rate(items, 'quality score')
250
+ const sorted = await zai.sort(items, 'by quality, best first')
260
251
 
261
252
  // Group and process
262
253
  const groups = await zai.group(tickets, {
263
- instructions: "by priority and category",
264
- });
254
+ instructions: 'by priority and category',
255
+ })
265
256
  for (const group of groups) {
266
- await processGroup(group.label, group.elements);
257
+ await processGroup(group.label, group.elements)
267
258
  }
268
259
 
269
260
  // Automated code modifications
270
- const updatedFiles = await zai.patch(sourceFiles, "add TypeScript types");
261
+ const updatedFiles = await zai.patch(sourceFiles, 'add TypeScript types')
271
262
  ```
272
263
 
273
264
  ## Everyday Problems Zai Solves
@@ -277,12 +268,15 @@ const updatedFiles = await zai.patch(sourceFiles, "add TypeScript types");
277
268
  A user sends "I'm Jane, I work at Acme Corp, my email is jane@acme.com and I need help with billing". Instead of regex or manual parsing:
278
269
 
279
270
  ```typescript
280
- const contact = await zai.extract(message, z.object({
281
- name: z.string(),
282
- company: z.string(),
283
- email: z.string(),
284
- topic: z.string(),
285
- }));
271
+ const contact = await zai.extract(
272
+ message,
273
+ z.object({
274
+ name: z.string(),
275
+ company: z.string(),
276
+ email: z.string(),
277
+ topic: z.string(),
278
+ })
279
+ )
286
280
  // → { name: 'Jane', company: 'Acme Corp', email: 'jane@acme.com', topic: 'billing' }
287
281
  ```
288
282
 
@@ -292,11 +286,11 @@ Incoming messages need routing to the right team without building a classifier f
292
286
 
293
287
  ```typescript
294
288
  const triage = await zai.label(message, {
295
- urgent: "needs response within 1 hour",
296
- billing: "related to payments or invoices",
297
- technical: "related to bugs or technical issues",
298
- churn_risk: "user is frustrated or threatening to leave",
299
- });
289
+ urgent: 'needs response within 1 hour',
290
+ billing: 'related to payments or invoices',
291
+ technical: 'related to bugs or technical issues',
292
+ churn_risk: 'user is frustrated or threatening to leave',
293
+ })
300
294
  // → { urgent: true, billing: true, technical: false, churn_risk: true }
301
295
  ```
302
296
 
@@ -305,8 +299,8 @@ const triage = await zai.label(message, {
305
299
  User-generated text needs to go into a report or external system:
306
300
 
307
301
  ```typescript
308
- const cleaned = await zai.rewrite(userMessage, "fix grammar and spelling, keep the meaning");
309
- const translated = await zai.rewrite(userMessage, "translate to French, keep a professional tone");
302
+ const cleaned = await zai.rewrite(userMessage, 'fix grammar and spelling, keep the meaning')
303
+ const translated = await zai.rewrite(userMessage, 'translate to French, keep a professional tone')
310
304
  ```
311
305
 
312
306
  ### Answering Questions from a Knowledge Base
@@ -314,11 +308,11 @@ const translated = await zai.rewrite(userMessage, "translate to French, keep a p
314
308
  A user asks a question and you have docs to search through — but you need citations and graceful handling when the answer isn't there:
315
309
 
316
310
  ```typescript
317
- const result = await zai.answer(kbDocuments, userQuestion);
318
- if (result.type === "answer") {
319
- return `${result.answer}\n\nSources: ${result.citations.map(c => c.snippet).join(", ")}`;
320
- } else if (result.type === "missing_knowledge") {
321
- return "I don't have enough information to answer that. Let me connect you with a human.";
311
+ const result = await zai.answer(kbDocuments, userQuestion)
312
+ if (result.type === 'answer') {
313
+ return `${result.answer}\n\nSources: ${result.citations.map((c) => c.snippet).join(', ')}`
314
+ } else if (result.type === 'missing_knowledge') {
315
+ return "I don't have enough information to answer that. Let me connect you with a human."
322
316
  }
323
317
  ```
324
318
 
@@ -328,11 +322,11 @@ A support queue has 50 tickets and the agent needs to work the most urgent ones
328
322
 
329
323
  ```typescript
330
324
  // Score tickets, then sort by those scores
331
- const scored = await zai.rate(tickets, "customer impact and time sensitivity");
325
+ const scored = await zai.rate(tickets, 'customer impact and time sensitivity')
332
326
  // scored: [4, 2, 5, 1, 3] — one score per ticket
333
327
 
334
328
  // Or sort directly when you only need ordering
335
- const sorted = await zai.sort(tickets, "most urgent and highest impact first");
329
+ const sorted = await zai.sort(tickets, 'most urgent and highest impact first')
336
330
  ```
337
331
 
338
332
  ### Pre-screening Before Human Review
@@ -340,7 +334,7 @@ const sorted = await zai.sort(tickets, "most urgent and highest impact first");
340
334
  Filter out irrelevant items before a human sees them:
341
335
 
342
336
  ```typescript
343
- const relevant = await zai.filter(applications, "meet minimum requirements: 3+ years experience, relevant degree");
337
+ const relevant = await zai.filter(applications, 'meet minimum requirements: 3+ years experience, relevant degree')
344
338
  ```
345
339
 
346
340
  ### Summarizing Long Conversations for Handoff
@@ -351,7 +345,7 @@ A conversation has been going for 30 messages and needs to be handed to a human
351
345
  const summary = await zai.summarize(conversationHistory, {
352
346
  prompt: "focus on the customer's problem, what has been tried, and current status",
353
347
  length: 200,
354
- });
348
+ })
355
349
  ```
356
350
 
357
351
  ### Grouping Feedback for Product Review
@@ -360,8 +354,8 @@ Hundreds of user feedback messages need to be organized into themes:
360
354
 
361
355
  ```typescript
362
356
  const themes = await zai.group(feedbackMessages, {
363
- instructions: "group by product area and sentiment",
364
- });
357
+ instructions: 'group by product area and sentiment',
358
+ })
365
359
  // → [{ id: 'onboarding', label: 'Onboarding Issues', elements: [...] }, ...]
366
360
  ```
367
361
 
@@ -372,12 +366,12 @@ const themes = await zai.group(feedbackMessages, {
372
366
  When `check()` gives inconsistent results on borderline inputs, add examples to guide it:
373
367
 
374
368
  ```typescript
375
- await zai.check(text, "is a complaint", {
369
+ await zai.check(text, 'is a complaint', {
376
370
  examples: [
377
- { input: "This is taking too long", check: true, reason: "Expresses frustration with wait time" },
378
- { input: "How long does shipping take?", check: false, reason: "Neutral question, not a complaint" },
371
+ { input: 'This is taking too long', check: true, reason: 'Expresses frustration with wait time' },
372
+ { input: 'How long does shipping take?', check: false, reason: 'Neutral question, not a complaint' },
379
373
  ],
380
- });
374
+ })
381
375
  ```
382
376
 
383
377
  ### Very Large Documents
@@ -388,7 +382,7 @@ Zai auto-chunks, but default `chunkLength` (16000 tokens) may lose context acros
388
382
  await zai.extract(contract, schema, {
389
383
  chunkLength: 32000, // Larger chunks to keep definitions in context
390
384
  instructions: "Definitions from the 'Definitions' section apply throughout",
391
- });
385
+ })
392
386
  ```
393
387
 
394
388
  ### extract() Returns Hallucinated Fields
@@ -396,10 +390,14 @@ await zai.extract(contract, schema, {
396
390
  When the input doesn't contain the requested data, the LLM may invent values. Use `.describe()` on schema fields and strict mode:
397
391
 
398
392
  ```typescript
399
- const data = await zai.extract(text, z.object({
400
- revenue: z.number().describe("Annual revenue in USD. Use -1 if not mentioned."),
401
- founded: z.number().describe("Year founded. Use 0 if not mentioned."),
402
- }), { strict: true });
393
+ const data = await zai.extract(
394
+ text,
395
+ z.object({
396
+ revenue: z.number().describe('Annual revenue in USD. Use -1 if not mentioned.'),
397
+ founded: z.number().describe('Year founded. Use 0 if not mentioned.'),
398
+ }),
399
+ { strict: true }
400
+ )
403
401
  ```
404
402
 
405
403
  ### answer() Returns "missing_knowledge" Despite Relevant Docs
@@ -409,8 +407,8 @@ This usually means the docs are too long and the relevant passage fell outside t
409
407
  ```typescript
410
408
  await zai.answer(docs, question, {
411
409
  chunkLength: 4000,
412
- instructions: "The documents use technical terminology. Match concepts, not exact wording.",
413
- });
410
+ instructions: 'The documents use technical terminology. Match concepts, not exact wording.',
411
+ })
414
412
  ```
415
413
 
416
414
  ### Mixed-Language Content
@@ -419,8 +417,8 @@ Zai handles multilingual input natively — no special config needed. But be exp
419
417
 
420
418
  ```typescript
421
419
  await zai.extract(mixedLanguageText, schema, {
422
- instructions: "Input may be in any language. Always return field values in English.",
423
- });
420
+ instructions: 'Input may be in any language. Always return field values in English.',
421
+ })
424
422
  ```
425
423
 
426
424
  ### Empty or Minimal Input
@@ -429,7 +427,7 @@ Zai doesn't error on empty strings but results will be empty/default. Guard at t
429
427
 
430
428
  ```typescript
431
429
  if (input.trim().length > 0) {
432
- const result = await zai.extract(input, schema);
430
+ const result = await zai.extract(input, schema)
433
431
  }
434
432
  ```
435
433
 
@@ -438,10 +436,10 @@ if (input.trim().length > 0) {
438
436
  When processing batches, stagger requests to avoid hitting API limits:
439
437
 
440
438
  ```typescript
441
- const results = [];
439
+ const results = []
442
440
  for (const [i, item] of items.entries()) {
443
- if (i > 0) await new Promise((r) => setTimeout(r, 200));
444
- results.push(await zai.extract(item, schema));
441
+ if (i > 0) await new Promise((r) => setTimeout(r, 200))
442
+ results.push(await zai.extract(item, schema))
445
443
  }
446
444
  ```
447
445