@liquidmetal-ai/precip 1.0.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 (78) hide show
  1. package/.prettierrc +9 -0
  2. package/CHANGELOG.md +8 -0
  3. package/eslint.config.mjs +28 -0
  4. package/package.json +53 -0
  5. package/src/engine/agent.ts +478 -0
  6. package/src/engine/llm-provider.test.ts +275 -0
  7. package/src/engine/llm-provider.ts +330 -0
  8. package/src/engine/stream-parser.ts +170 -0
  9. package/src/index.ts +142 -0
  10. package/src/mounts/mount-manager.test.ts +516 -0
  11. package/src/mounts/mount-manager.ts +327 -0
  12. package/src/mounts/mount-registry.ts +196 -0
  13. package/src/mounts/zod-to-string.test.ts +154 -0
  14. package/src/mounts/zod-to-string.ts +213 -0
  15. package/src/presets/agent-tools.ts +57 -0
  16. package/src/presets/index.ts +5 -0
  17. package/src/sandbox/README.md +1321 -0
  18. package/src/sandbox/bridges/README.md +571 -0
  19. package/src/sandbox/bridges/actor.test.ts +229 -0
  20. package/src/sandbox/bridges/actor.ts +195 -0
  21. package/src/sandbox/bridges/bridge-fixes.test.ts +614 -0
  22. package/src/sandbox/bridges/bucket.test.ts +300 -0
  23. package/src/sandbox/bridges/cleanup-reproduction.test.ts +225 -0
  24. package/src/sandbox/bridges/console-multiple.test.ts +187 -0
  25. package/src/sandbox/bridges/console.test.ts +157 -0
  26. package/src/sandbox/bridges/console.ts +122 -0
  27. package/src/sandbox/bridges/fetch.ts +93 -0
  28. package/src/sandbox/bridges/index.ts +78 -0
  29. package/src/sandbox/bridges/readable-stream.ts +323 -0
  30. package/src/sandbox/bridges/response.test.ts +154 -0
  31. package/src/sandbox/bridges/response.ts +123 -0
  32. package/src/sandbox/bridges/review-fixes.test.ts +331 -0
  33. package/src/sandbox/bridges/search.test.ts +475 -0
  34. package/src/sandbox/bridges/search.ts +264 -0
  35. package/src/sandbox/bridges/shared/body-methods.ts +93 -0
  36. package/src/sandbox/bridges/shared/cleanup.ts +112 -0
  37. package/src/sandbox/bridges/shared/convert.ts +76 -0
  38. package/src/sandbox/bridges/shared/headers.ts +181 -0
  39. package/src/sandbox/bridges/shared/index.ts +36 -0
  40. package/src/sandbox/bridges/shared/json-helpers.ts +77 -0
  41. package/src/sandbox/bridges/shared/path-parser.ts +109 -0
  42. package/src/sandbox/bridges/shared/promise-helper.ts +108 -0
  43. package/src/sandbox/bridges/shared/registry-setup.ts +84 -0
  44. package/src/sandbox/bridges/shared/response-object.ts +280 -0
  45. package/src/sandbox/bridges/shared/result-builder.ts +130 -0
  46. package/src/sandbox/bridges/shared/scope-helpers.ts +44 -0
  47. package/src/sandbox/bridges/shared/stream-reader.ts +90 -0
  48. package/src/sandbox/bridges/storage-bridge.test.ts +893 -0
  49. package/src/sandbox/bridges/storage.ts +421 -0
  50. package/src/sandbox/bridges/text-decoder.ts +190 -0
  51. package/src/sandbox/bridges/text-encoder.ts +102 -0
  52. package/src/sandbox/bridges/types.ts +39 -0
  53. package/src/sandbox/bridges/utils.ts +123 -0
  54. package/src/sandbox/index.ts +6 -0
  55. package/src/sandbox/quickjs-wasm.d.ts +9 -0
  56. package/src/sandbox/sandbox.test.ts +191 -0
  57. package/src/sandbox/sandbox.ts +831 -0
  58. package/src/sandbox/test-helper.ts +43 -0
  59. package/src/sandbox/test-mocks.ts +154 -0
  60. package/src/sandbox/user-stream.test.ts +77 -0
  61. package/src/skills/frontmatter.test.ts +305 -0
  62. package/src/skills/frontmatter.ts +200 -0
  63. package/src/skills/index.ts +9 -0
  64. package/src/skills/skills-loader.test.ts +237 -0
  65. package/src/skills/skills-loader.ts +200 -0
  66. package/src/tools/actor-storage-tools.ts +250 -0
  67. package/src/tools/code-tools.test.ts +199 -0
  68. package/src/tools/code-tools.ts +444 -0
  69. package/src/tools/file-tools.ts +206 -0
  70. package/src/tools/registry.ts +125 -0
  71. package/src/tools/script-tools.ts +145 -0
  72. package/src/tools/smartbucket-tools.ts +203 -0
  73. package/src/tools/sql-tools.ts +213 -0
  74. package/src/tools/tool-factory.ts +119 -0
  75. package/src/types.ts +512 -0
  76. package/tsconfig.eslint.json +5 -0
  77. package/tsconfig.json +15 -0
  78. package/vitest.config.ts +33 -0
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Zod Schema to Human-Readable Type String
3
+ *
4
+ * Converts Zod schemas to concise type strings for prompt documentation.
5
+ * Designed to give LLMs enough information to understand the API without overwhelming detail.
6
+ */
7
+
8
+ import { z } from 'zod';
9
+
10
+ /**
11
+ * Convert a Zod schema to a human-readable type string.
12
+ *
13
+ * Examples:
14
+ * - z.string() → "string"
15
+ * - z.object({ name: z.string() }) → "{ name: string }"
16
+ * - z.array(z.number()) → "Array<number>"
17
+ * - z.object({ name: z.string().optional() }) → "{ name?: string }"
18
+ * - z.enum(['a', 'b']) → "'a' | 'b'"
19
+ */
20
+ export function zodToTypeString(schema: z.ZodType, depth: number = 0): string {
21
+ // Prevent infinite recursion for deeply nested types
22
+ if (depth > 5) {
23
+ return '...';
24
+ }
25
+
26
+ // Handle ZodOptional - unwrap and mark
27
+ if (schema instanceof z.ZodOptional) {
28
+ return zodToTypeString(schema.unwrap(), depth);
29
+ }
30
+
31
+ // Handle ZodNullable
32
+ if (schema instanceof z.ZodNullable) {
33
+ return `${zodToTypeString(schema.unwrap(), depth)} | null`;
34
+ }
35
+
36
+ // Handle ZodDefault - unwrap
37
+ if (schema instanceof z.ZodDefault) {
38
+ return zodToTypeString(schema._def.innerType, depth);
39
+ }
40
+
41
+ // Primitives
42
+ if (schema instanceof z.ZodString) {
43
+ return 'string';
44
+ }
45
+ if (schema instanceof z.ZodNumber) {
46
+ return 'number';
47
+ }
48
+ if (schema instanceof z.ZodBoolean) {
49
+ return 'boolean';
50
+ }
51
+ if (schema instanceof z.ZodNull) {
52
+ return 'null';
53
+ }
54
+ if (schema instanceof z.ZodUndefined) {
55
+ return 'undefined';
56
+ }
57
+ if (schema instanceof z.ZodVoid) {
58
+ return 'void';
59
+ }
60
+ if (schema instanceof z.ZodAny) {
61
+ return 'any';
62
+ }
63
+ if (schema instanceof z.ZodUnknown) {
64
+ return 'unknown';
65
+ }
66
+ if (schema instanceof z.ZodNever) {
67
+ return 'never';
68
+ }
69
+
70
+ // Literal
71
+ if (schema instanceof z.ZodLiteral) {
72
+ const val = schema._def.value;
73
+ if (typeof val === 'string') {
74
+ return `'${val}'`;
75
+ }
76
+ return String(val);
77
+ }
78
+
79
+ // Enum
80
+ if (schema instanceof z.ZodEnum) {
81
+ const values = schema._def.values as string[];
82
+ return values.map(v => `'${v}'`).join(' | ');
83
+ }
84
+
85
+ // Native Enum
86
+ if (schema instanceof z.ZodNativeEnum) {
87
+ return 'enum';
88
+ }
89
+
90
+ // Array
91
+ if (schema instanceof z.ZodArray) {
92
+ const itemType = zodToTypeString(schema._def.type, depth + 1);
93
+ return `Array<${itemType}>`;
94
+ }
95
+
96
+ // Object
97
+ if (schema instanceof z.ZodObject) {
98
+ const shape = schema._def.shape();
99
+ const entries = Object.entries(shape);
100
+
101
+ // Empty object
102
+ if (entries.length === 0) {
103
+ return '{}';
104
+ }
105
+
106
+ // For shallow depth or few properties, show inline
107
+ if (depth < 2 && entries.length <= 4) {
108
+ const props = entries.map(([key, value]) => {
109
+ const isOptional = value instanceof z.ZodOptional;
110
+ const typeStr = zodToTypeString(value as z.ZodType, depth + 1);
111
+ return `${key}${isOptional ? '?' : ''}: ${typeStr}`;
112
+ });
113
+ return `{ ${props.join(', ')} }`;
114
+ }
115
+
116
+ // For deeper nesting or many properties, abbreviate
117
+ const propNames = entries.map(([key, value]) => {
118
+ const isOptional = value instanceof z.ZodOptional;
119
+ return `${key}${isOptional ? '?' : ''}`;
120
+ });
121
+ return `{ ${propNames.join(', ')} }`;
122
+ }
123
+
124
+ // Record
125
+ if (schema instanceof z.ZodRecord) {
126
+ const valueType = zodToTypeString(schema._def.valueType, depth + 1);
127
+ return `Record<string, ${valueType}>`;
128
+ }
129
+
130
+ // Map
131
+ if (schema instanceof z.ZodMap) {
132
+ const keyType = zodToTypeString(schema._def.keyType, depth + 1);
133
+ const valueType = zodToTypeString(schema._def.valueType, depth + 1);
134
+ return `Map<${keyType}, ${valueType}>`;
135
+ }
136
+
137
+ // Set
138
+ if (schema instanceof z.ZodSet) {
139
+ const valueType = zodToTypeString(schema._def.valueType, depth + 1);
140
+ return `Set<${valueType}>`;
141
+ }
142
+
143
+ // Tuple
144
+ if (schema instanceof z.ZodTuple) {
145
+ const items = schema._def.items as z.ZodType[];
146
+ const itemTypes = items.map(item => zodToTypeString(item, depth + 1));
147
+ return `[${itemTypes.join(', ')}]`;
148
+ }
149
+
150
+ // Union
151
+ if (schema instanceof z.ZodUnion) {
152
+ const options = schema._def.options as z.ZodType[];
153
+ const types = options.map(opt => zodToTypeString(opt, depth + 1));
154
+ return types.join(' | ');
155
+ }
156
+
157
+ // Discriminated Union
158
+ if (schema instanceof z.ZodDiscriminatedUnion) {
159
+ const options = schema._def.options as z.ZodType[];
160
+ const types = options.map(opt => zodToTypeString(opt, depth + 1));
161
+ return types.join(' | ');
162
+ }
163
+
164
+ // Intersection
165
+ if (schema instanceof z.ZodIntersection) {
166
+ const left = zodToTypeString(schema._def.left, depth + 1);
167
+ const right = zodToTypeString(schema._def.right, depth + 1);
168
+ return `${left} & ${right}`;
169
+ }
170
+
171
+ // Promise
172
+ if (schema instanceof z.ZodPromise) {
173
+ const inner = zodToTypeString(schema._def.type, depth + 1);
174
+ return `Promise<${inner}>`;
175
+ }
176
+
177
+ // Function
178
+ if (schema instanceof z.ZodFunction) {
179
+ return 'Function';
180
+ }
181
+
182
+ // Date
183
+ if (schema instanceof z.ZodDate) {
184
+ return 'Date';
185
+ }
186
+
187
+ // Effects (refinements, transforms, etc.) - unwrap
188
+ if (schema instanceof z.ZodEffects) {
189
+ return zodToTypeString(schema._def.schema, depth);
190
+ }
191
+
192
+ // Branded - unwrap
193
+ if (schema instanceof z.ZodBranded) {
194
+ return zodToTypeString(schema._def.type, depth);
195
+ }
196
+
197
+ // Lazy - try to resolve
198
+ if (schema instanceof z.ZodLazy) {
199
+ try {
200
+ return zodToTypeString(schema._def.getter(), depth + 1);
201
+ } catch {
202
+ return 'lazy';
203
+ }
204
+ }
205
+
206
+ // Pipeline - show output type
207
+ if (schema instanceof z.ZodPipeline) {
208
+ return zodToTypeString(schema._def.out, depth);
209
+ }
210
+
211
+ // Fallback
212
+ return 'unknown';
213
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Prebuilt Agent Tool Sets
3
+ *
4
+ * Two opinionated tool configurations for common agent patterns:
5
+ *
6
+ * **ScriptAgentTools** — Code-first agent. Scripts and ad-hoc code handle all data access
7
+ * through sandbox bridges (read, write, query, search, etc.). Lean prompt, maximum flexibility.
8
+ * - run_script: Execute scripts from skill mounts with args
9
+ * - run_code: Ad-hoc JavaScript for anything a script doesn't cover
10
+ * - read_file: Read files directly (SKILL.md, configs, quick lookups)
11
+ *
12
+ * **ToolAgentTools** — Tool-first agent. Each operation is a discrete, auditable tool call.
13
+ * Every action is visible in the conversation. More constrained, more transparent.
14
+ * - File CRUD: read_file, write_file, list_files, delete_file
15
+ * - SQL: sql_query, sql_execute, sql_batch
16
+ * - Search: semantic_search, chunk_search, get_search_page
17
+ * - Actor state: read_state, write_state, list_state, delete_state
18
+ *
19
+ * Mix and match, or build your own:
20
+ * tools: [...ScriptAgentTools, SqlQueryTool]
21
+ */
22
+
23
+ import type { Tool } from '../types.js';
24
+ import { ScriptExecutionTool } from '../tools/script-tools.js';
25
+ import { CodeExecutionTool } from '../tools/code-tools.js';
26
+ import { ReadFileTool, FileTools } from '../tools/file-tools.js';
27
+ import { SqlTools } from '../tools/sql-tools.js';
28
+ import { SmartBucketTools } from '../tools/smartbucket-tools.js';
29
+ import { ActorStorageTools } from '../tools/actor-storage-tools.js';
30
+
31
+ /**
32
+ * Code-first agent tools.
33
+ *
34
+ * Scripts and ad-hoc code handle data access through sandbox bridges.
35
+ * Lean prompt (~1,200 tokens for tool descriptions). Maximum flexibility.
36
+ *
37
+ * Tools: run_script, run_code, read_file
38
+ */
39
+ export const ScriptAgentTools: Tool[] = [ScriptExecutionTool, CodeExecutionTool, ReadFileTool];
40
+
41
+ /**
42
+ * Tool-first agent tools.
43
+ *
44
+ * Each operation is a discrete, auditable tool call. Every action visible
45
+ * in the conversation history. More constrained, more transparent.
46
+ *
47
+ * Tools: read_file, write_file, list_files, delete_file,
48
+ * sql_query, sql_execute, sql_batch,
49
+ * semantic_search, chunk_search, get_search_page,
50
+ * read_state, write_state, list_state, delete_state
51
+ */
52
+ export const ToolAgentTools: Tool[] = [
53
+ ...FileTools,
54
+ ...SqlTools,
55
+ ...SmartBucketTools,
56
+ ...ActorStorageTools
57
+ ];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Prebuilt agent presets
3
+ */
4
+
5
+ export { ScriptAgentTools, ToolAgentTools } from './agent-tools.js';