@llm4ts/flow 2.54.1 → 3.2.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 (95) hide show
  1. package/dist/Activity.d.ts +1 -1
  2. package/dist/Activity.d.ts.map +1 -1
  3. package/dist/Activity.js +20 -0
  4. package/dist/Activity.js.map +1 -1
  5. package/dist/EstimatedUsage.d.ts.map +1 -1
  6. package/dist/EstimatedUsage.js +0 -1
  7. package/dist/EstimatedUsage.js.map +1 -1
  8. package/dist/Pack.d.ts +11 -0
  9. package/dist/Pack.d.ts.map +1 -1
  10. package/dist/Pack.js +2 -0
  11. package/dist/Pack.js.map +1 -1
  12. package/dist/Replay.d.ts.map +1 -1
  13. package/dist/Replay.js +1 -4
  14. package/dist/Replay.js.map +1 -1
  15. package/dist/RosterSeats.d.ts.map +1 -1
  16. package/dist/RosterSeats.js +0 -1
  17. package/dist/RosterSeats.js.map +1 -1
  18. package/dist/Timing.d.ts.map +1 -1
  19. package/dist/Timing.js +0 -1
  20. package/dist/Timing.js.map +1 -1
  21. package/dist/Transcript.d.ts.map +1 -1
  22. package/dist/Transcript.js +0 -1
  23. package/dist/Transcript.js.map +1 -1
  24. package/dist/TransientRetry.d.ts.map +1 -1
  25. package/dist/TransientRetry.js +0 -1
  26. package/dist/TransientRetry.js.map +1 -1
  27. package/dist/endpoint/Auth.d.ts +194 -0
  28. package/dist/endpoint/Auth.d.ts.map +1 -0
  29. package/dist/endpoint/Auth.js +302 -0
  30. package/dist/endpoint/Auth.js.map +1 -0
  31. package/dist/endpoint/Endpoints.d.ts +21 -0
  32. package/dist/endpoint/Endpoints.d.ts.map +1 -0
  33. package/dist/endpoint/Endpoints.js +34 -0
  34. package/dist/endpoint/Endpoints.js.map +1 -0
  35. package/dist/endpoint/Transport.d.ts +90 -0
  36. package/dist/endpoint/Transport.d.ts.map +1 -0
  37. package/dist/endpoint/Transport.js +306 -0
  38. package/dist/endpoint/Transport.js.map +1 -0
  39. package/dist/tools/Builtin.d.ts +5 -0
  40. package/dist/tools/Builtin.d.ts.map +1 -0
  41. package/dist/tools/Builtin.js +7 -0
  42. package/dist/tools/Builtin.js.map +1 -0
  43. package/dist/tools/Diff.d.ts +8 -0
  44. package/dist/tools/Diff.d.ts.map +1 -0
  45. package/dist/tools/Diff.js +45 -0
  46. package/dist/tools/Diff.js.map +1 -0
  47. package/dist/tools/HttpCall.d.ts +14 -0
  48. package/dist/tools/HttpCall.d.ts.map +1 -0
  49. package/dist/tools/HttpCall.js +101 -0
  50. package/dist/tools/HttpCall.js.map +1 -0
  51. package/dist/tools/JsonSchemaCheck.d.ts +36 -0
  52. package/dist/tools/JsonSchemaCheck.d.ts.map +1 -0
  53. package/dist/tools/JsonSchemaCheck.js +342 -0
  54. package/dist/tools/JsonSchemaCheck.js.map +1 -0
  55. package/dist/tools/JsonValidate.d.ts +11 -0
  56. package/dist/tools/JsonValidate.d.ts.map +1 -0
  57. package/dist/tools/JsonValidate.js +84 -0
  58. package/dist/tools/JsonValidate.js.map +1 -0
  59. package/dist/tools/Tool.d.ts +126 -0
  60. package/dist/tools/Tool.d.ts.map +1 -0
  61. package/dist/tools/Tool.js +218 -0
  62. package/dist/tools/Tool.js.map +1 -0
  63. package/dist/tools/TreeDiff.d.ts +42 -0
  64. package/dist/tools/TreeDiff.d.ts.map +1 -0
  65. package/dist/tools/TreeDiff.js +276 -0
  66. package/dist/tools/TreeDiff.js.map +1 -0
  67. package/package.json +12 -4
  68. package/src/Activity.ts +22 -0
  69. package/src/EstimatedUsage.ts +0 -1
  70. package/src/Pack.ts +16 -0
  71. package/src/Replay.ts +1 -7
  72. package/src/RosterSeats.ts +0 -2
  73. package/src/Timing.ts +0 -10
  74. package/src/Transcript.ts +0 -1
  75. package/src/TransientRetry.ts +0 -2
  76. package/src/endpoint/Auth.ts +446 -0
  77. package/src/endpoint/Endpoints.ts +54 -0
  78. package/src/endpoint/Transport.ts +456 -0
  79. package/src/tools/Builtin.ts +10 -0
  80. package/src/tools/Diff.ts +61 -0
  81. package/src/tools/HttpCall.ts +124 -0
  82. package/src/tools/JsonSchemaCheck.ts +457 -0
  83. package/src/tools/JsonValidate.ts +106 -0
  84. package/src/tools/Tool.ts +351 -0
  85. package/src/tools/TreeDiff.ts +386 -0
  86. package/dist/WorkspaceLayout.d.ts +0 -3
  87. package/dist/WorkspaceLayout.d.ts.map +0 -1
  88. package/dist/WorkspaceLayout.js +0 -19
  89. package/dist/WorkspaceLayout.js.map +0 -1
  90. package/dist/WorkspaceTools.d.ts +0 -4
  91. package/dist/WorkspaceTools.d.ts.map +0 -1
  92. package/dist/WorkspaceTools.js +0 -130
  93. package/dist/WorkspaceTools.js.map +0 -1
  94. package/src/WorkspaceLayout.ts +0 -22
  95. package/src/WorkspaceTools.ts +0 -188
@@ -0,0 +1,386 @@
1
+ /**
2
+ * A deep structural compare of two JSON values that reports every difference
3
+ * with a JSONPath-style location, for tools that check an actual payload
4
+ * against an expected one.
5
+ *
6
+ * Arrays compare under one of three orderings: by position (`ordered`), by an
7
+ * identity field of their object elements (`per-key`), or as a multiset of
8
+ * canonical JSON (`unordered`). Paths named in `ignore` are skipped on both
9
+ * sides, so neither a missing nor an unexpected nor a changed value is
10
+ * reported for them.
11
+ */
12
+
13
+ export type DiffOrdering = "ordered" | "per-key" | "unordered"
14
+
15
+ export type DiffKind = "missing" | "unexpected" | "changed" | "type"
16
+
17
+ export interface DiffIssue {
18
+ readonly path: string
19
+ readonly kind: DiffKind
20
+ readonly detail: string
21
+ }
22
+
23
+ export interface TreeDiffOptions {
24
+ readonly ordering: DiffOrdering
25
+ /**
26
+ * Dot paths to skip, with `*` matching any one segment: `meta.requestId`,
27
+ * `items.*.updatedAt`. An array index is a segment (`items.2`); under
28
+ * `per-key` an element's segment is its identity (`items.42` or
29
+ * `items.id=42`).
30
+ */
31
+ readonly ignore: ReadonlyArray<string>
32
+ /**
33
+ * For `per-key`: the first of these fields present in an array element
34
+ * names its identity. Defaults to `["id", "key", "name", "code"]`.
35
+ */
36
+ readonly keyFields?: ReadonlyArray<string>
37
+ }
38
+
39
+ const defaultKeyFields: ReadonlyArray<string> = ["id", "key", "name", "code"]
40
+
41
+ type JsonRecord = Record<string, unknown>
42
+
43
+ const isRecord = (value: unknown): value is JsonRecord =>
44
+ typeof value === "object" && value !== null && !Array.isArray(value)
45
+
46
+ const jsonTypeOf = (value: unknown): string => {
47
+ if (value === null) return "null"
48
+ if (Array.isArray(value)) return "array"
49
+ return typeof value
50
+ }
51
+
52
+ /** Serialises a value as compact JSON with object keys sorted. */
53
+ export const canonicalJson = (value: unknown): string => {
54
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`
55
+ if (isRecord(value)) {
56
+ const entries = Object.keys(value)
57
+ .filter((key) => value[key] !== undefined)
58
+ .sort()
59
+ .map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`)
60
+ return `{${entries.join(",")}}`
61
+ }
62
+ const text = JSON.stringify(value)
63
+ return text === undefined ? "null" : text
64
+ }
65
+
66
+ const renderLimit = 80
67
+
68
+ const render = (value: unknown): string => {
69
+ const text = canonicalJson(value)
70
+ return text.length > renderLimit ? `${text.slice(0, renderLimit - 1)}…` : text
71
+ }
72
+
73
+ type Segment =
74
+ | { readonly kind: "key"; readonly name: string }
75
+ | { readonly kind: "index"; readonly index: number }
76
+ | { readonly kind: "identity"; readonly field: string; readonly value: unknown }
77
+
78
+ const identifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/
79
+
80
+ const plainKeyValue = /^[A-Za-z0-9_.:-]+$/
81
+
82
+ const renderKeyValue = (value: unknown): string =>
83
+ typeof value === "number" || (typeof value === "string" && plainKeyValue.test(value))
84
+ ? String(value)
85
+ : canonicalJson(value)
86
+
87
+ const renderPath = (segments: ReadonlyArray<Segment>): string =>
88
+ segments.reduce((path, segment) => {
89
+ switch (segment.kind) {
90
+ case "key":
91
+ return identifier.test(segment.name)
92
+ ? `${path}.${segment.name}`
93
+ : `${path}[${JSON.stringify(segment.name)}]`
94
+ case "index":
95
+ return `${path}[${segment.index}]`
96
+ case "identity":
97
+ return `${path}[${segment.field}=${renderKeyValue(segment.value)}]`
98
+ }
99
+ }, "$")
100
+
101
+ const segmentMatches = (pattern: string, segment: Segment): boolean => {
102
+ if (pattern === "*") return true
103
+ switch (segment.kind) {
104
+ case "key":
105
+ return pattern === segment.name
106
+ case "index":
107
+ return pattern === String(segment.index)
108
+ case "identity": {
109
+ const value = renderKeyValue(segment.value)
110
+ return pattern === value || pattern === `${segment.field}=${value}`
111
+ }
112
+ }
113
+ }
114
+
115
+ const pathMatches = (pattern: ReadonlyArray<string>, segments: ReadonlyArray<Segment>): boolean =>
116
+ pattern.length === segments.length &&
117
+ pattern.every((part, index) => segmentMatches(part, segments[index]))
118
+
119
+ interface Differ {
120
+ readonly ordering: DiffOrdering
121
+ readonly ignore: ReadonlyArray<ReadonlyArray<string>>
122
+ readonly keyFields: ReadonlyArray<string>
123
+ readonly issues: Array<DiffIssue>
124
+ }
125
+
126
+ const ignored = (differ: Differ, segments: ReadonlyArray<Segment>): boolean =>
127
+ differ.ignore.some((pattern) => pathMatches(pattern, segments))
128
+
129
+ const report = (
130
+ differ: Differ,
131
+ segments: ReadonlyArray<Segment>,
132
+ kind: DiffKind,
133
+ detail: string
134
+ ): void => {
135
+ differ.issues.push({ path: renderPath(segments), kind, detail })
136
+ }
137
+
138
+ /** Removes the ignored paths below `segments` from a value, for canonical matching. */
139
+ const strip = (differ: Differ, value: unknown, segments: ReadonlyArray<Segment>): unknown => {
140
+ if (Array.isArray(value)) {
141
+ return value.flatMap((item, index) => {
142
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "index", index }]
143
+ return ignored(differ, child) ? [] : [strip(differ, item, child)]
144
+ })
145
+ }
146
+ if (isRecord(value)) {
147
+ const out: JsonRecord = {}
148
+ for (const name of Object.keys(value)) {
149
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "key", name }]
150
+ if (!ignored(differ, child)) out[name] = strip(differ, value[name], child)
151
+ }
152
+ return out
153
+ }
154
+ return value
155
+ }
156
+
157
+ const identityOf = (
158
+ differ: Differ,
159
+ element: unknown
160
+ ): { readonly field: string; readonly value: unknown; readonly token: string } | undefined => {
161
+ if (!isRecord(element)) return undefined
162
+ for (const field of differ.keyFields) {
163
+ if (element[field] !== undefined) {
164
+ const value = element[field]
165
+ return { field, value, token: `${field}=${canonicalJson(value)}` }
166
+ }
167
+ }
168
+ return undefined
169
+ }
170
+
171
+ const diffOrdered = (
172
+ differ: Differ,
173
+ expected: ReadonlyArray<unknown>,
174
+ actual: ReadonlyArray<unknown>,
175
+ segments: ReadonlyArray<Segment>
176
+ ): void => {
177
+ const shared = Math.min(expected.length, actual.length)
178
+ for (let index = 0; index < shared; index++) {
179
+ diffAt(differ, expected[index], actual[index], [...segments, { kind: "index", index }])
180
+ }
181
+ for (let index = shared; index < expected.length; index++) {
182
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "index", index }]
183
+ if (ignored(differ, child)) continue
184
+ report(differ, child, "missing", `missing item ${render(expected[index])} at index ${index}`)
185
+ }
186
+ for (let index = shared; index < actual.length; index++) {
187
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "index", index }]
188
+ if (ignored(differ, child)) continue
189
+ report(
190
+ differ,
191
+ child,
192
+ "unexpected",
193
+ `unexpected item ${render(actual[index])} at index ${index}`
194
+ )
195
+ }
196
+ }
197
+
198
+ const diffPerKey = (
199
+ differ: Differ,
200
+ expected: ReadonlyArray<unknown>,
201
+ actual: ReadonlyArray<unknown>,
202
+ segments: ReadonlyArray<Segment>
203
+ ): void => {
204
+ const byIdentity = new Map<string, Array<number>>()
205
+ actual.forEach((element, index) => {
206
+ const identity = identityOf(differ, element)
207
+ if (identity === undefined) return
208
+ const queue = byIdentity.get(identity.token)
209
+ if (queue === undefined) byIdentity.set(identity.token, [index])
210
+ else queue.push(index)
211
+ })
212
+ const used = new Set<number>()
213
+
214
+ expected.forEach((element, index) => {
215
+ const identity = identityOf(differ, element)
216
+ if (identity === undefined) {
217
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "index", index }]
218
+ const counterpart = actual[index]
219
+ if (
220
+ index < actual.length &&
221
+ !used.has(index) &&
222
+ identityOf(differ, counterpart) === undefined
223
+ ) {
224
+ used.add(index)
225
+ diffAt(differ, element, counterpart, child)
226
+ } else if (!ignored(differ, child)) {
227
+ report(differ, child, "missing", `missing item ${render(element)} at index ${index}`)
228
+ }
229
+ return
230
+ }
231
+ const child: ReadonlyArray<Segment> = [
232
+ ...segments,
233
+ { kind: "identity", field: identity.field, value: identity.value }
234
+ ]
235
+ const match = byIdentity.get(identity.token)?.shift()
236
+ if (match === undefined) {
237
+ if (!ignored(differ, child)) {
238
+ report(
239
+ differ,
240
+ child,
241
+ "missing",
242
+ `missing item with ${identity.field}=${renderKeyValue(identity.value)}`
243
+ )
244
+ }
245
+ return
246
+ }
247
+ used.add(match)
248
+ diffAt(differ, element, actual[match], child)
249
+ })
250
+
251
+ actual.forEach((element, index) => {
252
+ if (used.has(index)) return
253
+ const identity = identityOf(differ, element)
254
+ const child: ReadonlyArray<Segment> =
255
+ identity === undefined
256
+ ? [...segments, { kind: "index", index }]
257
+ : [...segments, { kind: "identity", field: identity.field, value: identity.value }]
258
+ if (ignored(differ, child)) return
259
+ const detail =
260
+ identity === undefined
261
+ ? `unexpected item ${render(element)} at index ${index}`
262
+ : `unexpected item with ${identity.field}=${renderKeyValue(identity.value)}`
263
+ report(differ, child, "unexpected", detail)
264
+ })
265
+ }
266
+
267
+ const diffUnordered = (
268
+ differ: Differ,
269
+ expected: ReadonlyArray<unknown>,
270
+ actual: ReadonlyArray<unknown>,
271
+ segments: ReadonlyArray<Segment>
272
+ ): void => {
273
+ const keyOf = (element: unknown, index: number): string | undefined => {
274
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "index", index }]
275
+ return ignored(differ, child) ? undefined : canonicalJson(strip(differ, element, child))
276
+ }
277
+ const expectedKeys = expected.map(keyOf)
278
+ const actualKeys = actual.map(keyOf)
279
+ const count = (keys: ReadonlyArray<string | undefined>): Map<string, number> => {
280
+ const counts = new Map<string, number>()
281
+ for (const key of keys) {
282
+ if (key !== undefined) counts.set(key, (counts.get(key) ?? 0) + 1)
283
+ }
284
+ return counts
285
+ }
286
+ const leftover = (
287
+ keys: ReadonlyArray<string | undefined>,
288
+ available: Map<string, number>
289
+ ): ReadonlyArray<number> =>
290
+ keys.flatMap((key, index) => {
291
+ if (key === undefined) return []
292
+ const left = available.get(key) ?? 0
293
+ if (left === 0) return [index]
294
+ available.set(key, left - 1)
295
+ return []
296
+ })
297
+
298
+ for (const index of leftover(expectedKeys, count(actualKeys))) {
299
+ report(
300
+ differ,
301
+ [...segments, { kind: "index", index }],
302
+ "missing",
303
+ `missing item ${render(expected[index])}`
304
+ )
305
+ }
306
+ for (const index of leftover(actualKeys, count(expectedKeys))) {
307
+ report(
308
+ differ,
309
+ [...segments, { kind: "index", index }],
310
+ "unexpected",
311
+ `unexpected item ${render(actual[index])}`
312
+ )
313
+ }
314
+ }
315
+
316
+ const diffObjects = (
317
+ differ: Differ,
318
+ expected: JsonRecord,
319
+ actual: JsonRecord,
320
+ segments: ReadonlyArray<Segment>
321
+ ): void => {
322
+ const present = (record: JsonRecord, name: string): boolean =>
323
+ Object.prototype.hasOwnProperty.call(record, name) && record[name] !== undefined
324
+ for (const name of Object.keys(expected)) {
325
+ if (!present(expected, name)) continue
326
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "key", name }]
327
+ if (ignored(differ, child)) continue
328
+ if (present(actual, name)) diffAt(differ, expected[name], actual[name], child)
329
+ else report(differ, child, "missing", `missing property ${JSON.stringify(name)}`)
330
+ }
331
+ for (const name of Object.keys(actual)) {
332
+ if (!present(actual, name) || present(expected, name)) continue
333
+ const child: ReadonlyArray<Segment> = [...segments, { kind: "key", name }]
334
+ if (ignored(differ, child)) continue
335
+ report(differ, child, "unexpected", `unexpected property ${JSON.stringify(name)}`)
336
+ }
337
+ }
338
+
339
+ const diffAt = (
340
+ differ: Differ,
341
+ expected: unknown,
342
+ actual: unknown,
343
+ segments: ReadonlyArray<Segment>
344
+ ): void => {
345
+ if (ignored(differ, segments)) return
346
+ const expectedType = jsonTypeOf(expected)
347
+ const actualType = jsonTypeOf(actual)
348
+ if (expectedType !== actualType) {
349
+ report(differ, segments, "type", `expected ${expectedType}, found ${actualType}`)
350
+ return
351
+ }
352
+ if (Array.isArray(expected) && Array.isArray(actual)) {
353
+ switch (differ.ordering) {
354
+ case "ordered":
355
+ return diffOrdered(differ, expected, actual, segments)
356
+ case "per-key":
357
+ return diffPerKey(differ, expected, actual, segments)
358
+ case "unordered":
359
+ return diffUnordered(differ, expected, actual, segments)
360
+ }
361
+ }
362
+ if (isRecord(expected) && isRecord(actual)) return diffObjects(differ, expected, actual, segments)
363
+ if (expected !== actual) {
364
+ report(differ, segments, "changed", `expected ${render(expected)}, found ${render(actual)}`)
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Compares `actual` against `expected` and returns every difference found,
370
+ * in document order: for objects the expected keys first, then the extra
371
+ * keys of `actual`; for arrays as the ordering dictates.
372
+ */
373
+ export const diffJson = (
374
+ expected: unknown,
375
+ actual: unknown,
376
+ options: TreeDiffOptions
377
+ ): ReadonlyArray<DiffIssue> => {
378
+ const differ: Differ = {
379
+ ordering: options.ordering,
380
+ ignore: options.ignore.map((pattern) => pattern.split(".")),
381
+ keyFields: options.keyFields ?? defaultKeyFields,
382
+ issues: []
383
+ }
384
+ diffAt(differ, expected, actual, [])
385
+ return differ.issues
386
+ }
@@ -1,3 +0,0 @@
1
- export declare const repoId: (workspace: string, repository: string) => string | undefined;
2
- export declare const llm4tsDirectory: (workspace: string, repository: string) => string;
3
- //# sourceMappingURL=WorkspaceLayout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkspaceLayout.d.ts","sourceRoot":"","sources":["../src/WorkspaceLayout.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,GAAI,WAAW,MAAM,EAAE,YAAY,MAAM,KAAG,MAAM,GAAG,SAMvE,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,EAAE,YAAY,MAAM,KAAG,MAIvE,CAAA"}
@@ -1,19 +0,0 @@
1
- import { stableHash } from "./Plan.js";
2
- const normalize = (path) => path.replaceAll("\\", "/").replace(/\/+$/, "");
3
- const basename = (path) => {
4
- const parts = normalize(path).split("/");
5
- return parts.at(-1) || "repo";
6
- };
7
- export const repoId = (workspace, repository) => {
8
- const normalizedWorkspace = normalize(workspace);
9
- const normalizedRepository = normalize(repository);
10
- return normalizedWorkspace === normalizedRepository
11
- ? undefined
12
- : `${basename(normalizedRepository)}-${stableHash(normalizedRepository)}`;
13
- };
14
- export const llm4tsDirectory = (workspace, repository) => {
15
- const root = `${normalize(workspace)}/.llm4ts`;
16
- const id = repoId(workspace, repository);
17
- return id === undefined ? root : `${root}/${id}`;
18
- };
19
- //# sourceMappingURL=WorkspaceLayout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkspaceLayout.js","sourceRoot":"","sources":["../src/WorkspaceLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAE1F,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE;IACxC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAA;AAC/B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,SAAiB,EAAE,UAAkB,EAAsB,EAAE;IAClF,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAA;IAChD,MAAM,oBAAoB,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;IAClD,OAAO,mBAAmB,KAAK,oBAAoB;QACjD,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,QAAQ,CAAC,oBAAoB,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAA;AAC7E,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,UAAkB,EAAU,EAAE;IAC/E,MAAM,IAAI,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,UAAU,CAAA;IAC9C,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IACxC,OAAO,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,EAAE,CAAA;AAClD,CAAC,CAAA"}
@@ -1,4 +0,0 @@
1
- import { type Tool } from "@llm4ts/core/tools/Tool";
2
- import type { WorkspaceShape } from "./Workspace.ts";
3
- export declare const workspaceTools: (workspace: WorkspaceShape) => ReadonlyArray<Tool>;
4
- //# sourceMappingURL=WorkspaceTools.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkspaceTools.d.ts","sourceRoot":"","sources":["../src/WorkspaceTools.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAGlF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAmEpD,eAAO,MAAM,cAAc,GAAI,WAAW,cAAc,KAAG,aAAa,CAAC,IAAI,CAoH5E,CAAA"}
@@ -1,130 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import { ToolExecutionFailed, makeTool } from "@llm4ts/core/tools/Tool";
3
- import { isJsonRecord } from "@llm4ts/core/providers/CliSupport";
4
- const parameter = (parameters, name) => {
5
- if (!isJsonRecord(parameters)) {
6
- return Effect.fail(ToolExecutionFailed.make({
7
- message: "tool parameters must be an object"
8
- }));
9
- }
10
- const value = parameters[name];
11
- return typeof value === "string"
12
- ? Effect.succeed(value)
13
- : Effect.fail(ToolExecutionFailed.make({
14
- message: `parameter '${name}' must be a string`
15
- }));
16
- };
17
- const optionalParameter = (parameters, name) => {
18
- if (!isJsonRecord(parameters)) {
19
- return Effect.fail(ToolExecutionFailed.make({
20
- message: "tool parameters must be an object"
21
- }));
22
- }
23
- const value = parameters[name];
24
- return value === undefined || typeof value === "string"
25
- ? Effect.succeed(value)
26
- : Effect.fail(ToolExecutionFailed.make({
27
- message: `parameter '${name}' must be a string when supplied`
28
- }));
29
- };
30
- const mapWorkspaceError = Effect.mapError((error) => ToolExecutionFailed.make({ message: error.message }));
31
- const pathSchema = {
32
- type: "object",
33
- properties: {
34
- path: { type: "string" }
35
- },
36
- required: ["path"],
37
- additionalProperties: false
38
- };
39
- const contentSchema = {
40
- type: "object",
41
- properties: {
42
- path: { type: "string" },
43
- contents: { type: "string" }
44
- },
45
- required: ["path", "contents"],
46
- additionalProperties: false
47
- };
48
- export const workspaceTools = (workspace) => [
49
- makeTool({
50
- name: "workspace_read",
51
- description: "Read a bounded UTF-8 file under the workspace root",
52
- parameters: pathSchema,
53
- tags: ["file", "read", "workspace"],
54
- sandbox: "WorkspaceReadOnly",
55
- execute: (parameters) => Effect.all({
56
- path: parameter(parameters, "path")
57
- }).pipe(Effect.flatMap(({ path }) => workspace.read(path)), mapWorkspaceError)
58
- }),
59
- makeTool({
60
- name: "workspace_write",
61
- description: "Write bounded UTF-8 content under the workspace root",
62
- parameters: contentSchema,
63
- tags: ["file", "write", "workspace"],
64
- execute: (parameters) => Effect.all({
65
- path: parameter(parameters, "path"),
66
- contents: parameter(parameters, "contents")
67
- }).pipe(Effect.flatMap(({ path, contents }) => workspace.write(path, contents)), mapWorkspaceError, Effect.as({ written: true }))
68
- }),
69
- makeTool({
70
- name: "workspace_append",
71
- description: "Append bounded UTF-8 content under the workspace root",
72
- parameters: contentSchema,
73
- tags: ["file", "append", "workspace"],
74
- execute: (parameters) => Effect.all({
75
- path: parameter(parameters, "path"),
76
- contents: parameter(parameters, "contents")
77
- }).pipe(Effect.flatMap(({ path, contents }) => workspace.append(path, contents)), mapWorkspaceError, Effect.as({ appended: true }))
78
- }),
79
- makeTool({
80
- name: "workspace_discover",
81
- description: "Discover files under the workspace root using a bounded glob",
82
- parameters: {
83
- type: "object",
84
- properties: {
85
- pattern: { type: "string" }
86
- },
87
- additionalProperties: false
88
- },
89
- tags: ["file", "glob", "discover", "workspace"],
90
- sandbox: "WorkspaceReadOnly",
91
- execute: (parameters) => optionalParameter(parameters, "pattern").pipe(Effect.flatMap((pattern) => workspace.discover(pattern)), mapWorkspaceError, Effect.map((paths) => [...paths]))
92
- }),
93
- makeTool({
94
- name: "workspace_search",
95
- description: "Search bounded workspace files for literal text",
96
- parameters: {
97
- type: "object",
98
- properties: {
99
- query: { type: "string" },
100
- pattern: { type: "string" }
101
- },
102
- required: ["query"],
103
- additionalProperties: false
104
- },
105
- tags: ["file", "search", "workspace"],
106
- sandbox: "WorkspaceReadOnly",
107
- execute: (parameters) => Effect.all({
108
- query: parameter(parameters, "query"),
109
- pattern: optionalParameter(parameters, "pattern")
110
- }).pipe(Effect.flatMap(({ pattern, query }) => workspace.search(query, pattern)), mapWorkspaceError, Effect.map((matches) => matches.map((match) => ({
111
- path: match.path,
112
- line: match.line,
113
- text: match.text
114
- }))))
115
- }),
116
- makeTool({
117
- name: "workspace_validate_json",
118
- description: "Validate that a bounded workspace file contains JSON",
119
- parameters: pathSchema,
120
- tags: ["file", "validate", "json", "workspace"],
121
- sandbox: "WorkspaceReadOnly",
122
- execute: (parameters) => parameter(parameters, "path").pipe(Effect.flatMap((path) => workspace.read(path)), mapWorkspaceError, Effect.flatMap((contents) => Effect.try({
123
- try: () => JSON.parse(contents),
124
- catch: (error) => ToolExecutionFailed.make({
125
- message: `invalid JSON: ${String(error)}`
126
- })
127
- })), Effect.as({ valid: true }))
128
- })
129
- ];
130
- //# sourceMappingURL=WorkspaceTools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkspaceTools.js","sourceRoot":"","sources":["../src/WorkspaceTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAa,MAAM,yBAAyB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAIhE,MAAM,SAAS,GAAG,CAChB,UAAqB,EACrB,IAAY,EACgC,EAAE;IAC9C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,IAAI,CAChB,mBAAmB,CAAC,IAAI,CAAC;YACvB,OAAO,EAAE,mCAAmC;SAC7C,CAAC,CACH,CAAA;IACH,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC9B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,CAAC,CAAC,MAAM,CAAC,IAAI,CACT,mBAAmB,CAAC,IAAI,CAAC;YACvB,OAAO,EAAE,cAAc,IAAI,oBAAoB;SAChD,CAAC,CACH,CAAA;AACP,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,CACxB,UAAqB,EACrB,IAAY,EAC4C,EAAE;IAC1D,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,IAAI,CAChB,mBAAmB,CAAC,IAAI,CAAC;YACvB,OAAO,EAAE,mCAAmC;SAC7C,CAAC,CACH,CAAA;IACH,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9B,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ;QACrD,CAAC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aAC1C,CAAC;SACL,CAAC,CACH,EACD,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAC3B;KACJ,CAAC;CACH,CAAA"}
@@ -1,22 +0,0 @@
1
- import { stableHash } from "./Plan.ts"
2
-
3
- const normalize = (path: string): string => path.replaceAll("\\", "/").replace(/\/+$/, "")
4
-
5
- const basename = (path: string): string => {
6
- const parts = normalize(path).split("/")
7
- return parts.at(-1) || "repo"
8
- }
9
-
10
- export const repoId = (workspace: string, repository: string): string | undefined => {
11
- const normalizedWorkspace = normalize(workspace)
12
- const normalizedRepository = normalize(repository)
13
- return normalizedWorkspace === normalizedRepository
14
- ? undefined
15
- : `${basename(normalizedRepository)}-${stableHash(normalizedRepository)}`
16
- }
17
-
18
- export const llm4tsDirectory = (workspace: string, repository: string): string => {
19
- const root = `${normalize(workspace)}/.llm4ts`
20
- const id = repoId(workspace, repository)
21
- return id === undefined ? root : `${root}/${id}`
22
- }