openpond-sdk 0.12.10 → 0.12.12

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 (91) hide show
  1. package/LEARNING.md +11 -0
  2. package/README.md +2 -0
  3. package/dist/advanced-refiner-evaluations.js +8 -8
  4. package/dist/candidate-evaluations.js +7 -7
  5. package/dist/{chunk-QQ444G6A.js → chunk-2LVR24GU.js} +2 -2
  6. package/dist/{chunk-5QMREXMU.js → chunk-7BYLH47N.js} +3 -3
  7. package/dist/{chunk-RYDUAY52.js → chunk-C3TS766N.js} +21 -74
  8. package/dist/chunk-C3TS766N.js.map +1 -0
  9. package/dist/{chunk-HDKP6KE2.js → chunk-C4W2MEFP.js} +2 -2
  10. package/dist/{chunk-XJKGCU2K.js → chunk-CNREFTAV.js} +2 -2
  11. package/dist/{chunk-UAYXORU5.js → chunk-GHPCQXG5.js} +2 -2
  12. package/dist/{chunk-WOD72SFI.js → chunk-GJRXJL6G.js} +3 -3
  13. package/dist/{chunk-GRQWKATA.js → chunk-HAQPGTQ4.js} +2 -2
  14. package/dist/{chunk-7WKCQ4V5.js → chunk-IFBCLRBM.js} +2 -2
  15. package/dist/chunk-IZ26ZCGU.js +65 -0
  16. package/dist/chunk-IZ26ZCGU.js.map +1 -0
  17. package/dist/{chunk-ICFFZ4WC.js → chunk-JBYFD3QS.js} +3 -3
  18. package/dist/{chunk-4L556MYM.js → chunk-JDQVAG3R.js} +3 -3
  19. package/dist/{chunk-7FYPFHCQ.js → chunk-K54BDIKL.js} +3 -3
  20. package/dist/{chunk-ESW25WSD.js → chunk-KOJC3TH4.js} +6 -6
  21. package/dist/{chunk-GIEST52U.js → chunk-LHHHJIDR.js} +2 -2
  22. package/dist/{chunk-FC56EMHT.js → chunk-NKF5NIML.js} +6 -6
  23. package/dist/{chunk-LKKKTBLL.js → chunk-O3NOGKMT.js} +2 -2
  24. package/dist/{chunk-XNRM3QGR.js → chunk-ORYA2G7S.js} +3 -3
  25. package/dist/{chunk-PT72OARU.js → chunk-RIN6Z56W.js} +5 -5
  26. package/dist/{chunk-LT2YQCZI.js → chunk-RLW4Y5ZV.js} +2 -2
  27. package/dist/{chunk-PKW3II5M.js → chunk-TLSP5JKG.js} +2 -2
  28. package/dist/{chunk-BQ2C2Y54.js → chunk-UOV2LEXS.js} +4 -4
  29. package/dist/{chunk-ZZZU6XER.js → chunk-UWY5PUHR.js} +2 -2
  30. package/dist/{chunk-DMN6EF3R.js → chunk-XMVSQIK4.js} +2 -2
  31. package/dist/{chunk-WEL535AI.js → chunk-XRBM6PBD.js} +4 -4
  32. package/dist/{chunk-2DK7UBAG.js → chunk-YIGFQWZV.js} +3 -3
  33. package/dist/{chunk-IIQENUOK.js → chunk-ZYDDHHZZ.js} +3 -3
  34. package/dist/connected-evidence.js +14 -14
  35. package/dist/dataset-workspaces.js +14 -14
  36. package/dist/experiment-evaluation-schedules.js +18 -18
  37. package/dist/experiment-improvements.js +8 -8
  38. package/dist/experiments.js +17 -17
  39. package/dist/index.js +26 -25
  40. package/dist/index.js.map +1 -1
  41. package/dist/learning.js +9 -7
  42. package/dist/learning.js.map +1 -1
  43. package/dist/model-projects.js +4 -4
  44. package/dist/model-starter-attempts.js +3 -3
  45. package/dist/model-starter-catalog.js +10 -10
  46. package/dist/model-starters.js +10 -10
  47. package/dist/model-taskset-runs.js +4 -4
  48. package/dist/post-training.js +7 -7
  49. package/dist/taskset-drafts.js +13 -13
  50. package/dist/taskset-packages.js +15 -15
  51. package/dist/tool-learning-local-store.js +160 -7
  52. package/dist/tool-learning-local-store.js.map +1 -1
  53. package/dist/tool-learning.js +519 -0
  54. package/dist/tool-learning.js.map +1 -1
  55. package/dist/training-bundle.js +11 -11
  56. package/dist/training.js +8 -8
  57. package/dist/types/packages/sdk/src/tool-learning-client.d.ts +1236 -0
  58. package/dist/types/packages/sdk/src/tool-learning-client.d.ts.map +1 -0
  59. package/dist/types/packages/sdk/src/tool-learning-episodes.d.ts +58 -0
  60. package/dist/types/packages/sdk/src/tool-learning-episodes.d.ts.map +1 -0
  61. package/dist/types/packages/sdk/src/tool-learning-local-store.d.ts +70 -2
  62. package/dist/types/packages/sdk/src/tool-learning-local-store.d.ts.map +1 -1
  63. package/dist/types/packages/sdk/src/tool-learning.d.ts +2 -0
  64. package/dist/types/packages/sdk/src/tool-learning.d.ts.map +1 -1
  65. package/package.json +1 -1
  66. package/dist/chunk-RYDUAY52.js.map +0 -1
  67. /package/dist/{chunk-QQ444G6A.js.map → chunk-2LVR24GU.js.map} +0 -0
  68. /package/dist/{chunk-5QMREXMU.js.map → chunk-7BYLH47N.js.map} +0 -0
  69. /package/dist/{chunk-HDKP6KE2.js.map → chunk-C4W2MEFP.js.map} +0 -0
  70. /package/dist/{chunk-XJKGCU2K.js.map → chunk-CNREFTAV.js.map} +0 -0
  71. /package/dist/{chunk-UAYXORU5.js.map → chunk-GHPCQXG5.js.map} +0 -0
  72. /package/dist/{chunk-WOD72SFI.js.map → chunk-GJRXJL6G.js.map} +0 -0
  73. /package/dist/{chunk-GRQWKATA.js.map → chunk-HAQPGTQ4.js.map} +0 -0
  74. /package/dist/{chunk-7WKCQ4V5.js.map → chunk-IFBCLRBM.js.map} +0 -0
  75. /package/dist/{chunk-ICFFZ4WC.js.map → chunk-JBYFD3QS.js.map} +0 -0
  76. /package/dist/{chunk-4L556MYM.js.map → chunk-JDQVAG3R.js.map} +0 -0
  77. /package/dist/{chunk-7FYPFHCQ.js.map → chunk-K54BDIKL.js.map} +0 -0
  78. /package/dist/{chunk-ESW25WSD.js.map → chunk-KOJC3TH4.js.map} +0 -0
  79. /package/dist/{chunk-GIEST52U.js.map → chunk-LHHHJIDR.js.map} +0 -0
  80. /package/dist/{chunk-FC56EMHT.js.map → chunk-NKF5NIML.js.map} +0 -0
  81. /package/dist/{chunk-LKKKTBLL.js.map → chunk-O3NOGKMT.js.map} +0 -0
  82. /package/dist/{chunk-XNRM3QGR.js.map → chunk-ORYA2G7S.js.map} +0 -0
  83. /package/dist/{chunk-PT72OARU.js.map → chunk-RIN6Z56W.js.map} +0 -0
  84. /package/dist/{chunk-LT2YQCZI.js.map → chunk-RLW4Y5ZV.js.map} +0 -0
  85. /package/dist/{chunk-PKW3II5M.js.map → chunk-TLSP5JKG.js.map} +0 -0
  86. /package/dist/{chunk-BQ2C2Y54.js.map → chunk-UOV2LEXS.js.map} +0 -0
  87. /package/dist/{chunk-ZZZU6XER.js.map → chunk-UWY5PUHR.js.map} +0 -0
  88. /package/dist/{chunk-DMN6EF3R.js.map → chunk-XMVSQIK4.js.map} +0 -0
  89. /package/dist/{chunk-WEL535AI.js.map → chunk-XRBM6PBD.js.map} +0 -0
  90. /package/dist/{chunk-2DK7UBAG.js.map → chunk-YIGFQWZV.js.map} +0 -0
  91. /package/dist/{chunk-IIQENUOK.js.map → chunk-ZYDDHHZZ.js.map} +0 -0
@@ -1,3 +1,522 @@
1
+ import {
2
+ LearningSourceCredentialSecretSchema,
3
+ createSourceCredentialRequest
4
+ } from "./chunk-IZ26ZCGU.js";
5
+ import {
6
+ readBoundedJsonResponse
7
+ } from "./chunk-B3ZHJ2KK.js";
8
+ import {
9
+ contentHash
10
+ } from "./chunk-H3JZ3P5T.js";
11
+ import "./chunk-YLJ4XMA6.js";
12
+
1
13
  // src/tool-learning.ts
2
14
  export * from "@openpond/evals/tool-learning";
15
+
16
+ // src/tool-learning-client.ts
17
+ import { z as z2 } from "zod";
18
+ import { LearningRevisionRefSchema } from "@openpond/evals/learning";
19
+ import {
20
+ TOOL_LEARNING_LIMITS as TOOL_LEARNING_LIMITS2,
21
+ ToolLearningRegistrationSchema,
22
+ ToolLearningInstallationSchema,
23
+ ToolLearningIdSchema,
24
+ ToolEpisodeEventSchema as ToolEpisodeEventSchema2,
25
+ ToolLearningRefSchema as ToolLearningRefSchema2,
26
+ ToolLearningDecisionSchema,
27
+ boundedToolLearningSchema,
28
+ ToolLearningInstallationUpdateSchema,
29
+ ToolEpisodeAppendSchema,
30
+ ToolEpisodeAppendReceiptSchema,
31
+ ToolLearningManifestSchema,
32
+ ToolLearningCapabilitySchema,
33
+ ToolLearningConsultationRequestSchema,
34
+ assertToolLearningConsultationResponse
35
+ } from "@openpond/evals/tool-learning";
36
+ import { assertBoundedTaskJson } from "@openpond/evals/task-schema";
37
+
38
+ // src/tool-learning-episodes.ts
39
+ import { z } from "zod";
40
+ import {
41
+ TOOL_LEARNING_LIMITS,
42
+ ToolEpisodeEventSchema,
43
+ ToolLearningHashSchema,
44
+ ToolLearningRefSchema
45
+ } from "@openpond/evals/tool-learning";
46
+ var ToolLearningEpisodeAssemblySchema = z.object({
47
+ state: z.enum(["incomplete", "ambiguous", "awaiting_owner_review"]),
48
+ issues: z.array(z.enum([
49
+ "missing_attempt",
50
+ "missing_observation",
51
+ "completion_not_observed",
52
+ "conflicting_observations",
53
+ "reference_mismatch",
54
+ "lineage_mismatch",
55
+ "mixed_scope",
56
+ "conflicting_event"
57
+ ])).max(8),
58
+ groups: z.array(z.object({
59
+ key: ToolLearningHashSchema,
60
+ application: z.string().min(1).max(200),
61
+ applicationVersion: z.string().min(1).max(200),
62
+ tool: z.object({
63
+ name: z.string().min(1).max(200),
64
+ version: z.string().max(200).nullable(),
65
+ server: z.string().max(200).nullable()
66
+ }).strict(),
67
+ environmentFingerprints: z.array(ToolLearningHashSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode),
68
+ attempts: z.array(ToolLearningRefSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode)
69
+ }).strict()).max(TOOL_LEARNING_LIMITS.eventsPerEpisode)
70
+ }).strict();
71
+ function assembleToolLearningEpisode(raw) {
72
+ const events = z.array(ToolEpisodeEventSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode).parse(raw);
73
+ const incomplete = /* @__PURE__ */ new Set(), ambiguous = /* @__PURE__ */ new Set();
74
+ const byId = /* @__PURE__ */ new Map();
75
+ const first = events[0];
76
+ for (const event of events) {
77
+ if (first && (event.installationId !== first.installationId || event.episodeId !== first.episodeId))
78
+ ambiguous.add("mixed_scope");
79
+ if (event.parentSessionId === event.sessionId) ambiguous.add("lineage_mismatch");
80
+ const previous = byId.get(event.eventId);
81
+ if (previous && previous.contentHash !== event.contentHash) ambiguous.add("conflicting_event");
82
+ else byId.set(event.eventId, event);
83
+ }
84
+ const attempts = [...byId.values()].filter((event) => event.eventKind === "attempt");
85
+ const observations = /* @__PURE__ */ new Map();
86
+ const callOwners = /* @__PURE__ */ new Map();
87
+ if (!attempts.length) incomplete.add("missing_attempt");
88
+ for (const event of byId.values()) {
89
+ if (event.eventKind !== "observation") continue;
90
+ const attempt = byId.get(event.payload.attempt.id);
91
+ if (!attempt) incomplete.add("missing_attempt");
92
+ else if (attempt.eventKind !== "attempt" || attempt.contentHash !== event.payload.attempt.contentHash || attempt.payload.actionHash !== event.payload.actionHash) ambiguous.add("reference_mismatch");
93
+ else if (attempt.sessionId !== event.sessionId || attempt.callId !== event.callId || attempt.parentSessionId && event.parentSessionId && attempt.parentSessionId !== event.parentSessionId || attempt.turnId && event.turnId && attempt.turnId !== event.turnId) ambiguous.add("lineage_mismatch");
94
+ const values = observations.get(event.payload.attempt.id) ?? [];
95
+ values.push(event);
96
+ observations.set(event.payload.attempt.id, values);
97
+ }
98
+ const grouped = /* @__PURE__ */ new Map();
99
+ for (const attempt of attempts) {
100
+ const callKey = JSON.stringify([attempt.sessionId, attempt.callId]);
101
+ const previousCall = callOwners.get(callKey);
102
+ if (previousCall && previousCall !== attempt.contentHash) ambiguous.add("lineage_mismatch");
103
+ callOwners.set(callKey, attempt.contentHash);
104
+ const values = observations.get(attempt.eventId) ?? [];
105
+ if (!values.length) incomplete.add("missing_observation");
106
+ else {
107
+ const terminal = values.filter((event) => event.payload.outcome !== "incomplete");
108
+ if (!terminal.length) incomplete.add("completion_not_observed");
109
+ if (new Set(terminal.map((event) => contentHash(event.payload))).size > 1)
110
+ ambiguous.add("conflicting_observations");
111
+ }
112
+ const { environment, tool } = attempt.payload;
113
+ const key = contentHash([environment.application, environment.version, tool.name, tool.version, tool.server]);
114
+ const group = grouped.get(key) ?? {
115
+ application: environment.application,
116
+ applicationVersion: environment.version,
117
+ tool,
118
+ fingerprints: /* @__PURE__ */ new Set(),
119
+ attempts: []
120
+ };
121
+ group.fingerprints.add(environment.fingerprint);
122
+ group.attempts.push({ id: attempt.eventId, contentHash: attempt.contentHash });
123
+ grouped.set(key, group);
124
+ }
125
+ return ToolLearningEpisodeAssemblySchema.parse({
126
+ state: ambiguous.size ? "ambiguous" : incomplete.size ? "incomplete" : "awaiting_owner_review",
127
+ issues: [.../* @__PURE__ */ new Set([...ambiguous, ...incomplete])].sort(),
128
+ groups: [...grouped].sort(([a], [b]) => a.localeCompare(b)).map(([key, group]) => ({
129
+ key,
130
+ application: group.application,
131
+ applicationVersion: group.applicationVersion,
132
+ tool: group.tool,
133
+ environmentFingerprints: [...group.fingerprints].sort(),
134
+ attempts: group.attempts.sort((a, b) => a.id.localeCompare(b.id))
135
+ }))
136
+ });
137
+ }
138
+
139
+ // src/tool-learning-client.ts
140
+ var ToolLearningRegistrationRequestSchema = boundedToolLearningSchema(
141
+ z2.object({
142
+ registration: ToolLearningRegistrationSchema,
143
+ credential: z2.object({ apiKey: LearningSourceCredentialSecretSchema, expiresAt: z2.iso.datetime() }).strict()
144
+ }).strict(),
145
+ TOOL_LEARNING_LIMITS2.eventBytes
146
+ );
147
+ var ToolLearningProjectionRequestSchema = boundedToolLearningSchema(
148
+ z2.object({
149
+ operationId: ToolLearningIdSchema,
150
+ expectedRevision: z2.number().int().positive(),
151
+ episodeId: ToolLearningIdSchema,
152
+ failure: ToolLearningRefSchema2,
153
+ recovery: ToolLearningRefSchema2,
154
+ taskDefinition: LearningRevisionRefSchema,
155
+ familyKey: ToolLearningIdSchema,
156
+ split: z2.literal("train"),
157
+ proposedTarget: ToolLearningDecisionSchema,
158
+ saveToPrivateDataset: z2.literal(true),
159
+ targetApproval: z2.literal("pending_owner_review")
160
+ }).strict(),
161
+ TOOL_LEARNING_LIMITS2.eventBytes
162
+ );
163
+ var ToolLearningProjectionReceiptSchema = boundedToolLearningSchema(
164
+ z2.object({
165
+ installationId: ToolLearningIdSchema,
166
+ projectId: ToolLearningIdSchema,
167
+ operationId: ToolLearningIdSchema,
168
+ source: LearningRevisionRefSchema,
169
+ evidence: LearningRevisionRefSchema,
170
+ originHash: z2.string().regex(/^[a-f0-9]{64}$/),
171
+ requestHash: z2.string().regex(/^[a-f0-9]{64}$/),
172
+ projectedAt: z2.iso.datetime(),
173
+ targetApproval: z2.literal("pending_owner_review"),
174
+ learningEnrollment: z2.literal(false)
175
+ }).strict(),
176
+ TOOL_LEARNING_LIMITS2.eventBytes
177
+ );
178
+ var ToolLearningRoutingRequestSchema = boundedToolLearningSchema(
179
+ z2.object({
180
+ operationId: ToolLearningIdSchema,
181
+ expectedRevision: z2.number().int().nonnegative(),
182
+ state: z2.enum(["enabled", "disabled"]),
183
+ modelId: ToolLearningIdSchema,
184
+ qualification: z2.discriminatedUnion("kind", [
185
+ z2.object({ kind: z2.literal("integration"), evaluationRunId: ToolLearningIdSchema }).strict(),
186
+ z2.object({
187
+ kind: z2.literal("learned"),
188
+ evaluationRunId: ToolLearningIdSchema,
189
+ baselineRunId: ToolLearningIdSchema,
190
+ trainingRunId: ToolLearningIdSchema
191
+ }).strict()
192
+ ]),
193
+ capabilities: z2.array(ToolLearningCapabilitySchema.omit({ qualification: true })).min(1).max(16),
194
+ limits: z2.object({
195
+ maxOutputTokens: z2.number().int().min(128).max(2048),
196
+ maximumCallUsd: z2.number().positive().max(1),
197
+ maximumDayUsd: z2.number().positive().max(10),
198
+ maximumSessionCalls: z2.number().int().min(1).max(20),
199
+ maximumDayCalls: z2.number().int().min(1).max(200)
200
+ }).strict()
201
+ }).strict(),
202
+ TOOL_LEARNING_LIMITS2.eventBytes
203
+ );
204
+ var ToolLearningRoutingSchema = boundedToolLearningSchema(
205
+ z2.object({
206
+ installationId: ToolLearningIdSchema,
207
+ scope: z2.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),
208
+ revision: z2.number().int().positive(),
209
+ operationId: ToolLearningIdSchema,
210
+ requestHash: z2.string().regex(/^[a-f0-9]{64}$/),
211
+ configuration: ToolLearningRoutingRequestSchema,
212
+ modelRelease: ToolLearningRefSchema2,
213
+ policySystemPrompt: z2.string().min(1).max(16384),
214
+ capabilities: z2.array(ToolLearningCapabilitySchema).max(16),
215
+ updatedAt: z2.iso.datetime()
216
+ }).strict(),
217
+ TOOL_LEARNING_LIMITS2.eventBytes
218
+ );
219
+ function prepareToolLearningRegistration(registration, expiresAt) {
220
+ const prepared = createSourceCredentialRequest({
221
+ sourceId: registration.installationId,
222
+ name: "Tool learning installation",
223
+ expiresAt
224
+ });
225
+ return ToolLearningRegistrationRequestSchema.parse({
226
+ registration,
227
+ credential: { apiKey: prepared.apiKey, expiresAt }
228
+ });
229
+ }
230
+ var OpenPondToolLearningError = class extends Error {
231
+ constructor(status, code) {
232
+ super(`Tool learning request failed (${status}): ${code}`);
233
+ this.status = status;
234
+ this.code = code;
235
+ this.name = "OpenPondToolLearningError";
236
+ }
237
+ status;
238
+ code;
239
+ };
240
+ var OpenPondToolLearningClient = class {
241
+ #baseUrl;
242
+ #options;
243
+ constructor(options) {
244
+ this.#options = { ...options };
245
+ const url = new URL(options.baseUrl);
246
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || !options.apiKey.trim() || !options.teamId.trim() || !options.projectId.trim())
247
+ throw new Error("tool_learning_client_scope_required");
248
+ this.#baseUrl = url.toString().replace(/\/+$/, "");
249
+ }
250
+ async register(value, signal) {
251
+ const input = ToolLearningRegistrationRequestSchema.parse(value);
252
+ if (input.registration.projectId !== this.#options.projectId)
253
+ throw new Error("tool_learning_project_mismatch");
254
+ const result = z2.object({
255
+ installation: ToolLearningInstallationSchema,
256
+ apiKey: LearningSourceCredentialSecretSchema
257
+ }).strict().parse(await this.#request("installations", "POST", input, signal));
258
+ this.#installation(result.installation, input.registration.installationId);
259
+ if (result.apiKey !== input.credential.apiKey)
260
+ throw new Error("tool_learning_credential_mismatch");
261
+ const installation = result.installation;
262
+ if (installation.client !== input.registration.client || installation.clientVersion !== input.registration.clientVersion || installation.machineSourceId !== input.registration.machineSourceId || contentHash(installation.adapterRelease) !== contentHash(input.registration.adapterRelease) || contentHash(installation.collectionPolicy) !== contentHash(input.registration.collectionPolicy) || installation.collectionPolicyHash !== contentHash(input.registration.collectionPolicy) || installation.credential?.expiresAt !== input.credential.expiresAt)
263
+ throw new Error("tool_learning_registration_receipt_mismatch");
264
+ return result;
265
+ }
266
+ async installation(id, signal) {
267
+ const result = ToolLearningInstallationSchema.parse(
268
+ await this.#request(`installations/${encodeURIComponent(id)}`, "GET", void 0, signal)
269
+ );
270
+ this.#installation(result, id);
271
+ return result;
272
+ }
273
+ async installations(after, signal) {
274
+ const result = z2.object({
275
+ items: z2.array(ToolLearningInstallationSchema).max(30),
276
+ nextCursor: ToolLearningIdSchema.nullable()
277
+ }).strict().parse(
278
+ await this.#request(
279
+ `installations?projectId=${encodeURIComponent(this.#options.projectId)}${after ? `&after=${encodeURIComponent(after)}` : ""}`,
280
+ "GET",
281
+ void 0,
282
+ signal
283
+ )
284
+ );
285
+ for (const installation of result.items) this.#installation(installation, installation.id);
286
+ if (result.nextCursor !== null && result.nextCursor !== result.items.at(-1)?.id)
287
+ throw new Error("tool_learning_installation_cursor_mismatch");
288
+ return result;
289
+ }
290
+ async episodes(installationId, after, signal) {
291
+ const result = z2.object({
292
+ installationId: ToolLearningIdSchema,
293
+ scope: z2.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),
294
+ items: z2.array(
295
+ z2.object({
296
+ episodeId: ToolLearningIdSchema,
297
+ eventCount: z2.number().int().positive(),
298
+ lastReceivedAt: z2.iso.datetime()
299
+ }).strict()
300
+ ).max(30),
301
+ nextCursor: ToolLearningIdSchema.nullable(),
302
+ learningEnrollment: z2.literal(false)
303
+ }).strict().parse(
304
+ await this.#request(
305
+ `installations/${encodeURIComponent(installationId)}/episodes${after ? `?after=${encodeURIComponent(after)}` : ""}`,
306
+ "GET",
307
+ void 0,
308
+ signal
309
+ )
310
+ );
311
+ if (result.installationId !== installationId || result.scope.teamId !== this.#options.teamId || result.scope.projectId !== this.#options.projectId || result.nextCursor !== null && result.nextCursor !== result.items.at(-1)?.episodeId)
312
+ throw new Error("tool_learning_episode_page_mismatch");
313
+ return result;
314
+ }
315
+ async episode(installationId, episodeId, signal) {
316
+ const result = z2.object({
317
+ installationId: ToolLearningIdSchema,
318
+ episodeId: ToolLearningIdSchema,
319
+ scope: z2.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),
320
+ events: z2.array(ToolEpisodeEventSchema2).max(TOOL_LEARNING_LIMITS2.eventsPerEpisode),
321
+ state: ToolLearningEpisodeAssemblySchema.shape.state,
322
+ assembly: ToolLearningEpisodeAssemblySchema,
323
+ verificationAuthority: z2.literal("not_granted"),
324
+ learningEnrollment: z2.literal(false)
325
+ }).strict().parse(
326
+ await this.#request(
327
+ `installations/${encodeURIComponent(installationId)}/episodes/${encodeURIComponent(episodeId)}`,
328
+ "GET",
329
+ void 0,
330
+ signal
331
+ )
332
+ );
333
+ if (result.installationId !== installationId || result.episodeId !== episodeId || result.scope.teamId !== this.#options.teamId || result.scope.projectId !== this.#options.projectId || result.events.some(
334
+ (event) => event.installationId !== installationId || event.episodeId !== episodeId
335
+ ))
336
+ throw new Error("tool_learning_episode_scope_mismatch");
337
+ if (result.state !== result.assembly.state || contentHash(assembleToolLearningEpisode(result.events)) !== contentHash(result.assembly))
338
+ throw new Error("tool_learning_episode_assembly_mismatch");
339
+ return result;
340
+ }
341
+ async purge(installationId, input, signal) {
342
+ const request = z2.object({ operationId: ToolLearningIdSchema, expectedRevision: z2.number().int().positive() }).strict().parse(input);
343
+ const result = z2.object({
344
+ installationId: ToolLearningIdSchema,
345
+ operationId: ToolLearningIdSchema,
346
+ purgedEvents: z2.number().int().nonnegative(),
347
+ learningEnrollment: z2.literal(false)
348
+ }).strict().parse(
349
+ await this.#request(
350
+ `installations/${encodeURIComponent(installationId)}/purge`,
351
+ "POST",
352
+ request,
353
+ signal
354
+ )
355
+ );
356
+ if (result.installationId !== installationId || result.operationId !== request.operationId)
357
+ throw new Error("tool_learning_purge_scope_mismatch");
358
+ return result;
359
+ }
360
+ async project(installationId, value, signal) {
361
+ const input = ToolLearningProjectionRequestSchema.parse(value);
362
+ const result = ToolLearningProjectionReceiptSchema.parse(
363
+ await this.#request(
364
+ `installations/${encodeURIComponent(installationId)}/project`,
365
+ "POST",
366
+ input,
367
+ signal
368
+ )
369
+ );
370
+ if (result.installationId !== installationId || result.projectId !== this.#options.projectId || result.operationId !== input.operationId || result.requestHash !== contentHash(input))
371
+ throw new Error("tool_learning_projection_scope_mismatch");
372
+ return result;
373
+ }
374
+ async setState(id, value, signal) {
375
+ const input = ToolLearningInstallationUpdateSchema.parse(value);
376
+ const result = ToolLearningInstallationSchema.parse(
377
+ await this.#request(`installations/${encodeURIComponent(id)}`, "PATCH", input, signal)
378
+ );
379
+ this.#installation(result, id);
380
+ if (result.state !== input.state) throw new Error("tool_learning_state_mismatch");
381
+ return result;
382
+ }
383
+ async append(value, signal) {
384
+ const input = ToolEpisodeAppendSchema.parse(value);
385
+ const result = ToolEpisodeAppendReceiptSchema.parse(
386
+ await this.#request("episodes", "POST", input, signal)
387
+ );
388
+ if (result.operationId !== input.operationId || result.installationId !== input.installationId || result.teamId !== this.#options.teamId || result.projectId !== this.#options.projectId || result.requestHash !== contentHash(input) || result.events.length !== input.events.length || new Set(result.events.map((event) => event.eventId)).size !== result.events.length)
389
+ throw new Error("tool_learning_append_receipt_mismatch");
390
+ for (const event of result.events) {
391
+ const submitted = input.events.find((value2) => value2.eventId === event.eventId);
392
+ if (!submitted || submitted.contentHash !== event.contentHash)
393
+ throw new Error("tool_learning_append_event_mismatch");
394
+ }
395
+ return result;
396
+ }
397
+ async routing(installationId, signal) {
398
+ return this.#routing(
399
+ installationId,
400
+ await this.#request(
401
+ `installations/${encodeURIComponent(installationId)}/routing`,
402
+ "GET",
403
+ void 0,
404
+ signal
405
+ )
406
+ );
407
+ }
408
+ async configureRouting(installationId, value, signal) {
409
+ const input = ToolLearningRoutingRequestSchema.parse(value);
410
+ const result = this.#routing(
411
+ installationId,
412
+ await this.#request(
413
+ `installations/${encodeURIComponent(installationId)}/routing`,
414
+ "POST",
415
+ input,
416
+ signal
417
+ )
418
+ );
419
+ if (result.operationId !== input.operationId || result.requestHash !== contentHash(input) || contentHash(result.configuration) !== contentHash(input))
420
+ throw new Error("tool_learning_routing_receipt_mismatch");
421
+ return result;
422
+ }
423
+ #routing(installationId, value) {
424
+ const result = ToolLearningRoutingSchema.parse(value);
425
+ if (result.installationId !== installationId || result.scope.teamId !== this.#options.teamId || result.scope.projectId !== this.#options.projectId)
426
+ throw new Error("tool_learning_routing_scope_mismatch");
427
+ return result;
428
+ }
429
+ async manifest(installationId, signal) {
430
+ const result = ToolLearningManifestSchema.parse(
431
+ await this.#request(
432
+ `installations/${encodeURIComponent(installationId)}/manifest`,
433
+ "GET",
434
+ void 0,
435
+ signal
436
+ )
437
+ );
438
+ if (result.installationId !== installationId || result.scope.teamId !== this.#options.teamId || result.scope.projectId !== this.#options.projectId)
439
+ throw new Error("tool_learning_manifest_scope_mismatch");
440
+ if (Date.parse(result.expiresAt) <= Date.now() || Date.parse(result.issuedAt) > Date.now() + 3e4)
441
+ throw new Error("tool_learning_manifest_expired");
442
+ return result;
443
+ }
444
+ async consult(value, signal) {
445
+ const input = ToolLearningConsultationRequestSchema.parse(value);
446
+ if (input.scope.teamId !== this.#options.teamId || input.scope.projectId !== this.#options.projectId)
447
+ throw new Error("tool_learning_consultation_scope_mismatch");
448
+ return assertToolLearningConsultationResponse(
449
+ input,
450
+ await this.#request("consultations", "POST", input, signal)
451
+ );
452
+ }
453
+ async consultation(value, signal) {
454
+ const input = ToolLearningConsultationRequestSchema.parse(value);
455
+ if (input.scope.teamId !== this.#options.teamId || input.scope.projectId !== this.#options.projectId)
456
+ throw new Error("tool_learning_consultation_scope_mismatch");
457
+ return assertToolLearningConsultationResponse(
458
+ input,
459
+ await this.#request(
460
+ `installations/${encodeURIComponent(input.installationId)}/consultations/${encodeURIComponent(input.operationId)}`,
461
+ "GET",
462
+ void 0,
463
+ signal
464
+ )
465
+ );
466
+ }
467
+ #installation(value, id) {
468
+ if (value.id !== id || value.scope.teamId !== this.#options.teamId || value.scope.projectId !== this.#options.projectId)
469
+ throw new Error("tool_learning_installation_scope_mismatch");
470
+ }
471
+ async #request(path, method, body, signal) {
472
+ if (body !== void 0)
473
+ assertBoundedTaskJson(
474
+ body,
475
+ TOOL_LEARNING_LIMITS2.eventBytes * TOOL_LEARNING_LIMITS2.eventsPerAppend
476
+ );
477
+ const timeout = AbortSignal.timeout(3e4);
478
+ const response = await (this.#options.fetch ?? globalThis.fetch)(
479
+ `${this.#baseUrl}/v1/tool-learning/${path}`,
480
+ {
481
+ method,
482
+ redirect: "error",
483
+ signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
484
+ headers: {
485
+ Authorization: `Bearer ${this.#options.apiKey}`,
486
+ "X-OpenPond-Team-Id": this.#options.teamId,
487
+ Accept: "application/json",
488
+ ...body === void 0 ? {} : { "Content-Type": "application/json" }
489
+ },
490
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
491
+ }
492
+ );
493
+ const value = await readBoundedJsonResponse(
494
+ response,
495
+ TOOL_LEARNING_LIMITS2.eventBytes * TOOL_LEARNING_LIMITS2.eventsPerAppend,
496
+ "Tool learning response"
497
+ );
498
+ if (!response.ok) {
499
+ const error = z2.object({
500
+ code: z2.string().regex(/^[a-z0-9_]+$/).max(200)
501
+ }).passthrough().safeParse(value);
502
+ throw new OpenPondToolLearningError(
503
+ response.status,
504
+ error.success ? error.data.code : "tool_learning_request_failed"
505
+ );
506
+ }
507
+ return value;
508
+ }
509
+ };
510
+ export {
511
+ OpenPondToolLearningClient,
512
+ OpenPondToolLearningError,
513
+ ToolLearningEpisodeAssemblySchema,
514
+ ToolLearningProjectionReceiptSchema,
515
+ ToolLearningProjectionRequestSchema,
516
+ ToolLearningRegistrationRequestSchema,
517
+ ToolLearningRoutingRequestSchema,
518
+ ToolLearningRoutingSchema,
519
+ assembleToolLearningEpisode,
520
+ prepareToolLearningRegistration
521
+ };
3
522
  //# sourceMappingURL=tool-learning.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tool-learning.ts"],"sourcesContent":["/** Portable episode and recovery-consultation protocol; no installation side effects. */\nexport * from \"@openpond/evals/tool-learning\";\n"],"mappings":";AACA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/tool-learning.ts","../src/tool-learning-client.ts","../src/tool-learning-episodes.ts"],"sourcesContent":["/** Portable episode and recovery-consultation protocol; no installation side effects. */\nexport * from \"@openpond/evals/tool-learning\";\nexport * from \"./tool-learning-client.js\";\nexport * from \"./tool-learning-episodes.js\";\n","import { z } from \"zod\";\nimport { contentHash } from \"@openpond/harness\";\nimport { LearningRevisionRefSchema } from \"@openpond/evals/learning\";\nimport {\n TOOL_LEARNING_LIMITS,\n ToolLearningRegistrationSchema,\n ToolLearningInstallationSchema,\n ToolLearningIdSchema,\n ToolEpisodeEventSchema,\n ToolLearningRefSchema,\n ToolLearningDecisionSchema,\n boundedToolLearningSchema,\n ToolLearningInstallationUpdateSchema,\n ToolEpisodeAppendSchema,\n ToolEpisodeAppendReceiptSchema,\n ToolLearningManifestSchema,\n ToolLearningCapabilitySchema,\n ToolLearningConsultationRequestSchema,\n assertToolLearningConsultationResponse,\n type ToolLearningRegistration,\n type ToolEpisodeAppend,\n type ToolLearningConsultationRequest,\n} from \"@openpond/evals/tool-learning\";\nimport {\n LearningSourceCredentialSecretSchema,\n createSourceCredentialRequest,\n} from \"./learning-credentials.js\";\nimport { assertBoundedTaskJson } from \"@openpond/evals/task-schema\";\nimport { readBoundedJsonResponse } from \"./protocol.js\";\nimport { assembleToolLearningEpisode, ToolLearningEpisodeAssemblySchema } from \"./tool-learning-episodes.js\";\n\n/** Prepare and retain this request privately before registration. Retrying the\n * same bytes recovers issuance without storing plaintext on the host. */\nexport const ToolLearningRegistrationRequestSchema = boundedToolLearningSchema(\n z\n .object({\n registration: ToolLearningRegistrationSchema,\n credential: z\n .object({ apiKey: LearningSourceCredentialSecretSchema, expiresAt: z.iso.datetime() })\n .strict(),\n })\n .strict(),\n TOOL_LEARNING_LIMITS.eventBytes,\n);\n\nexport const ToolLearningProjectionRequestSchema = boundedToolLearningSchema(\n z\n .object({\n operationId: ToolLearningIdSchema,\n expectedRevision: z.number().int().positive(),\n episodeId: ToolLearningIdSchema,\n failure: ToolLearningRefSchema,\n recovery: ToolLearningRefSchema,\n taskDefinition: LearningRevisionRefSchema,\n familyKey: ToolLearningIdSchema,\n split: z.literal(\"train\"),\n proposedTarget: ToolLearningDecisionSchema,\n saveToPrivateDataset: z.literal(true),\n targetApproval: z.literal(\"pending_owner_review\"),\n })\n .strict(),\n TOOL_LEARNING_LIMITS.eventBytes,\n);\nexport const ToolLearningProjectionReceiptSchema = boundedToolLearningSchema(\n z\n .object({\n installationId: ToolLearningIdSchema,\n projectId: ToolLearningIdSchema,\n operationId: ToolLearningIdSchema,\n source: LearningRevisionRefSchema,\n evidence: LearningRevisionRefSchema,\n originHash: z.string().regex(/^[a-f0-9]{64}$/),\n requestHash: z.string().regex(/^[a-f0-9]{64}$/),\n projectedAt: z.iso.datetime(),\n targetApproval: z.literal(\"pending_owner_review\"),\n learningEnrollment: z.literal(false),\n })\n .strict(),\n TOOL_LEARNING_LIMITS.eventBytes,\n);\n\n/** Explicit owner selection. Capturing events never authorizes inference spend. */\nexport const ToolLearningRoutingRequestSchema = boundedToolLearningSchema(\n z\n .object({\n operationId: ToolLearningIdSchema,\n expectedRevision: z.number().int().nonnegative(),\n state: z.enum([\"enabled\", \"disabled\"]),\n modelId: ToolLearningIdSchema,\n qualification: z.discriminatedUnion(\"kind\", [\n z\n .object({ kind: z.literal(\"integration\"), evaluationRunId: ToolLearningIdSchema })\n .strict(),\n z\n .object({\n kind: z.literal(\"learned\"),\n evaluationRunId: ToolLearningIdSchema,\n baselineRunId: ToolLearningIdSchema,\n trainingRunId: ToolLearningIdSchema,\n })\n .strict(),\n ]),\n capabilities: z\n .array(ToolLearningCapabilitySchema.omit({ qualification: true }))\n .min(1)\n .max(16),\n limits: z\n .object({\n maxOutputTokens: z.number().int().min(128).max(2048),\n maximumCallUsd: z.number().positive().max(1),\n maximumDayUsd: z.number().positive().max(10),\n maximumSessionCalls: z.number().int().min(1).max(20),\n maximumDayCalls: z.number().int().min(1).max(200),\n })\n .strict(),\n })\n .strict(),\n TOOL_LEARNING_LIMITS.eventBytes,\n);\nexport const ToolLearningRoutingSchema = boundedToolLearningSchema(\n z\n .object({\n installationId: ToolLearningIdSchema,\n scope: z.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),\n revision: z.number().int().positive(),\n operationId: ToolLearningIdSchema,\n requestHash: z.string().regex(/^[a-f0-9]{64}$/),\n configuration: ToolLearningRoutingRequestSchema,\n modelRelease: ToolLearningRefSchema,\n policySystemPrompt: z.string().min(1).max(16384),\n capabilities: z.array(ToolLearningCapabilitySchema).max(16),\n updatedAt: z.iso.datetime(),\n })\n .strict(),\n TOOL_LEARNING_LIMITS.eventBytes,\n);\n\nexport function prepareToolLearningRegistration(\n registration: ToolLearningRegistration,\n expiresAt: string,\n) {\n const prepared = createSourceCredentialRequest({\n sourceId: registration.installationId,\n name: \"Tool learning installation\",\n expiresAt,\n });\n return ToolLearningRegistrationRequestSchema.parse({\n registration,\n credential: { apiKey: prepared.apiKey, expiresAt },\n });\n}\n\nexport class OpenPondToolLearningError extends Error {\n constructor(\n readonly status: number,\n readonly code: string,\n ) {\n super(`Tool learning request failed (${status}): ${code}`);\n this.name = \"OpenPondToolLearningError\";\n }\n}\n\n/** Owner credentials register/control installations. External hooks and MCP\n * use only the separate installation credential returned by registration. */\ntype ToolLearningClientOptions = {\n baseUrl: string;\n apiKey: string;\n teamId: string;\n projectId: string;\n fetch?: typeof globalThis.fetch;\n};\n\nexport class OpenPondToolLearningClient {\n readonly #baseUrl: string;\n readonly #options: ToolLearningClientOptions;\n constructor(options: ToolLearningClientOptions) {\n this.#options = { ...options };\n\n const url = new URL(options.baseUrl);\n if (\n ![\"https:\", \"http:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash ||\n !options.apiKey.trim() ||\n !options.teamId.trim() ||\n !options.projectId.trim()\n )\n throw new Error(\"tool_learning_client_scope_required\");\n this.#baseUrl = url.toString().replace(/\\/+$/, \"\");\n }\n\n async register(\n value: z.input<typeof ToolLearningRegistrationRequestSchema>,\n signal?: AbortSignal,\n ) {\n const input = ToolLearningRegistrationRequestSchema.parse(value);\n if (input.registration.projectId !== this.#options.projectId)\n throw new Error(\"tool_learning_project_mismatch\");\n const result = z\n .object({\n installation: ToolLearningInstallationSchema,\n apiKey: LearningSourceCredentialSecretSchema,\n })\n .strict()\n .parse(await this.#request(\"installations\", \"POST\", input, signal));\n this.#installation(result.installation, input.registration.installationId);\n if (result.apiKey !== input.credential.apiKey)\n throw new Error(\"tool_learning_credential_mismatch\");\n const installation = result.installation;\n if (\n installation.client !== input.registration.client ||\n installation.clientVersion !== input.registration.clientVersion ||\n installation.machineSourceId !== input.registration.machineSourceId ||\n contentHash(installation.adapterRelease) !== contentHash(input.registration.adapterRelease) ||\n contentHash(installation.collectionPolicy) !==\n contentHash(input.registration.collectionPolicy) ||\n installation.collectionPolicyHash !== contentHash(input.registration.collectionPolicy) ||\n installation.credential?.expiresAt !== input.credential.expiresAt\n )\n throw new Error(\"tool_learning_registration_receipt_mismatch\");\n return result;\n }\n\n async installation(id: string, signal?: AbortSignal) {\n const result = ToolLearningInstallationSchema.parse(\n await this.#request(`installations/${encodeURIComponent(id)}`, \"GET\", undefined, signal),\n );\n this.#installation(result, id);\n return result;\n }\n\n async installations(after?: string, signal?: AbortSignal) {\n const result = z\n .object({\n items: z.array(ToolLearningInstallationSchema).max(30),\n nextCursor: ToolLearningIdSchema.nullable(),\n })\n .strict()\n .parse(\n await this.#request(\n `installations?projectId=${encodeURIComponent(this.#options.projectId)}${after ? `&after=${encodeURIComponent(after)}` : \"\"}`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n for (const installation of result.items) this.#installation(installation, installation.id);\n if (result.nextCursor !== null && result.nextCursor !== result.items.at(-1)?.id)\n throw new Error(\"tool_learning_installation_cursor_mismatch\");\n return result;\n }\n\n async episodes(installationId: string, after?: string, signal?: AbortSignal) {\n const result = z\n .object({\n installationId: ToolLearningIdSchema,\n scope: z.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),\n items: z\n .array(\n z\n .object({\n episodeId: ToolLearningIdSchema,\n eventCount: z.number().int().positive(),\n lastReceivedAt: z.iso.datetime(),\n })\n .strict(),\n )\n .max(30),\n nextCursor: ToolLearningIdSchema.nullable(),\n learningEnrollment: z.literal(false),\n })\n .strict()\n .parse(\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/episodes${after ? `?after=${encodeURIComponent(after)}` : \"\"}`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n if (\n result.installationId !== installationId ||\n result.scope.teamId !== this.#options.teamId ||\n result.scope.projectId !== this.#options.projectId ||\n (result.nextCursor !== null && result.nextCursor !== result.items.at(-1)?.episodeId)\n )\n throw new Error(\"tool_learning_episode_page_mismatch\");\n return result;\n }\n\n async episode(installationId: string, episodeId: string, signal?: AbortSignal) {\n const result = z\n .object({\n installationId: ToolLearningIdSchema,\n episodeId: ToolLearningIdSchema,\n scope: z.object({ teamId: ToolLearningIdSchema, projectId: ToolLearningIdSchema }).strict(),\n events: z.array(ToolEpisodeEventSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode),\n state: ToolLearningEpisodeAssemblySchema.shape.state,\n assembly: ToolLearningEpisodeAssemblySchema,\n verificationAuthority: z.literal(\"not_granted\"),\n learningEnrollment: z.literal(false),\n })\n .strict()\n .parse(\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/episodes/${encodeURIComponent(episodeId)}`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n if (\n result.installationId !== installationId ||\n result.episodeId !== episodeId ||\n result.scope.teamId !== this.#options.teamId ||\n result.scope.projectId !== this.#options.projectId ||\n result.events.some(\n (event) => event.installationId !== installationId || event.episodeId !== episodeId,\n )\n )\n throw new Error(\"tool_learning_episode_scope_mismatch\");\n if (result.state !== result.assembly.state ||\n contentHash(assembleToolLearningEpisode(result.events)) !== contentHash(result.assembly))\n throw new Error(\"tool_learning_episode_assembly_mismatch\");\n return result;\n }\n\n async purge(\n installationId: string,\n input: { operationId: string; expectedRevision: number },\n signal?: AbortSignal,\n ) {\n const request = z\n .object({ operationId: ToolLearningIdSchema, expectedRevision: z.number().int().positive() })\n .strict()\n .parse(input);\n const result = z\n .object({\n installationId: ToolLearningIdSchema,\n operationId: ToolLearningIdSchema,\n purgedEvents: z.number().int().nonnegative(),\n learningEnrollment: z.literal(false),\n })\n .strict()\n .parse(\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/purge`,\n \"POST\",\n request,\n signal,\n ),\n );\n if (result.installationId !== installationId || result.operationId !== request.operationId)\n throw new Error(\"tool_learning_purge_scope_mismatch\");\n return result;\n }\n\n async project(\n installationId: string,\n value: z.input<typeof ToolLearningProjectionRequestSchema>,\n signal?: AbortSignal,\n ) {\n const input = ToolLearningProjectionRequestSchema.parse(value);\n const result = ToolLearningProjectionReceiptSchema.parse(\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/project`,\n \"POST\",\n input,\n signal,\n ),\n );\n if (\n result.installationId !== installationId ||\n result.projectId !== this.#options.projectId ||\n result.operationId !== input.operationId ||\n result.requestHash !== contentHash(input)\n )\n throw new Error(\"tool_learning_projection_scope_mismatch\");\n return result;\n }\n\n async setState(\n id: string,\n value: z.input<typeof ToolLearningInstallationUpdateSchema>,\n signal?: AbortSignal,\n ) {\n const input = ToolLearningInstallationUpdateSchema.parse(value);\n const result = ToolLearningInstallationSchema.parse(\n await this.#request(`installations/${encodeURIComponent(id)}`, \"PATCH\", input, signal),\n );\n this.#installation(result, id);\n if (result.state !== input.state) throw new Error(\"tool_learning_state_mismatch\");\n return result;\n }\n\n async append(value: ToolEpisodeAppend, signal?: AbortSignal) {\n const input = ToolEpisodeAppendSchema.parse(value);\n const result = ToolEpisodeAppendReceiptSchema.parse(\n await this.#request(\"episodes\", \"POST\", input, signal),\n );\n if (\n result.operationId !== input.operationId ||\n result.installationId !== input.installationId ||\n result.teamId !== this.#options.teamId ||\n result.projectId !== this.#options.projectId ||\n result.requestHash !== contentHash(input) ||\n result.events.length !== input.events.length ||\n new Set(result.events.map((event) => event.eventId)).size !== result.events.length\n )\n throw new Error(\"tool_learning_append_receipt_mismatch\");\n for (const event of result.events) {\n const submitted = input.events.find((value) => value.eventId === event.eventId);\n if (!submitted || submitted.contentHash !== event.contentHash)\n throw new Error(\"tool_learning_append_event_mismatch\");\n }\n return result;\n }\n\n async routing(installationId: string, signal?: AbortSignal) {\n return this.#routing(\n installationId,\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/routing`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n }\n\n async configureRouting(\n installationId: string,\n value: z.input<typeof ToolLearningRoutingRequestSchema>,\n signal?: AbortSignal,\n ) {\n const input = ToolLearningRoutingRequestSchema.parse(value);\n const result = this.#routing(\n installationId,\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/routing`,\n \"POST\",\n input,\n signal,\n ),\n );\n if (\n result.operationId !== input.operationId ||\n result.requestHash !== contentHash(input) ||\n contentHash(result.configuration) !== contentHash(input)\n )\n throw new Error(\"tool_learning_routing_receipt_mismatch\");\n return result;\n }\n\n #routing(installationId: string, value: unknown) {\n const result = ToolLearningRoutingSchema.parse(value);\n if (\n result.installationId !== installationId ||\n result.scope.teamId !== this.#options.teamId ||\n result.scope.projectId !== this.#options.projectId\n )\n throw new Error(\"tool_learning_routing_scope_mismatch\");\n return result;\n }\n\n async manifest(installationId: string, signal?: AbortSignal) {\n const result = ToolLearningManifestSchema.parse(\n await this.#request(\n `installations/${encodeURIComponent(installationId)}/manifest`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n if (\n result.installationId !== installationId ||\n result.scope.teamId !== this.#options.teamId ||\n result.scope.projectId !== this.#options.projectId\n )\n throw new Error(\"tool_learning_manifest_scope_mismatch\");\n if (\n Date.parse(result.expiresAt) <= Date.now() ||\n Date.parse(result.issuedAt) > Date.now() + 30000\n )\n throw new Error(\"tool_learning_manifest_expired\");\n return result;\n }\n\n async consult(value: ToolLearningConsultationRequest, signal?: AbortSignal) {\n const input = ToolLearningConsultationRequestSchema.parse(value);\n if (\n input.scope.teamId !== this.#options.teamId ||\n input.scope.projectId !== this.#options.projectId\n )\n throw new Error(\"tool_learning_consultation_scope_mismatch\");\n return assertToolLearningConsultationResponse(\n input,\n await this.#request(\"consultations\", \"POST\", input, signal),\n );\n }\n\n async consultation(value: ToolLearningConsultationRequest, signal?: AbortSignal) {\n const input = ToolLearningConsultationRequestSchema.parse(value);\n if (\n input.scope.teamId !== this.#options.teamId ||\n input.scope.projectId !== this.#options.projectId\n )\n throw new Error(\"tool_learning_consultation_scope_mismatch\");\n return assertToolLearningConsultationResponse(\n input,\n await this.#request(\n `installations/${encodeURIComponent(input.installationId)}/consultations/${encodeURIComponent(input.operationId)}`,\n \"GET\",\n undefined,\n signal,\n ),\n );\n }\n\n #installation(value: z.infer<typeof ToolLearningInstallationSchema>, id: string) {\n if (\n value.id !== id ||\n value.scope.teamId !== this.#options.teamId ||\n value.scope.projectId !== this.#options.projectId\n )\n throw new Error(\"tool_learning_installation_scope_mismatch\");\n }\n\n async #request(\n path: string,\n method: string,\n body: unknown,\n signal?: AbortSignal,\n ): Promise<unknown> {\n if (body !== undefined)\n assertBoundedTaskJson(\n body,\n TOOL_LEARNING_LIMITS.eventBytes * TOOL_LEARNING_LIMITS.eventsPerAppend,\n );\n const timeout = AbortSignal.timeout(30000);\n const response = await (this.#options.fetch ?? globalThis.fetch)(\n `${this.#baseUrl}/v1/tool-learning/${path}`,\n {\n method,\n redirect: \"error\",\n signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n headers: {\n Authorization: `Bearer ${this.#options.apiKey}`,\n \"X-OpenPond-Team-Id\": this.#options.teamId,\n Accept: \"application/json\",\n ...(body === undefined ? {} : { \"Content-Type\": \"application/json\" }),\n },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n },\n );\n const value = await readBoundedJsonResponse(\n response,\n TOOL_LEARNING_LIMITS.eventBytes * TOOL_LEARNING_LIMITS.eventsPerAppend,\n \"Tool learning response\",\n );\n if (!response.ok) {\n const error = z\n .object({\n code: z\n .string()\n .regex(/^[a-z0-9_]+$/)\n .max(200),\n })\n .passthrough()\n .safeParse(value);\n throw new OpenPondToolLearningError(\n response.status,\n error.success ? error.data.code : \"tool_learning_request_failed\",\n );\n }\n return value;\n }\n}\n","import { z } from \"zod\";\nimport { contentHash } from \"@openpond/harness\";\nimport {\n TOOL_LEARNING_LIMITS,\n ToolEpisodeEventSchema,\n ToolLearningHashSchema,\n ToolLearningRefSchema,\n type ToolEpisodeEvent,\n} from \"@openpond/evals/tool-learning\";\n\nexport const ToolLearningEpisodeAssemblySchema = z.object({\n state: z.enum([\"incomplete\", \"ambiguous\", \"awaiting_owner_review\"]),\n issues: z.array(z.enum([\n \"missing_attempt\", \"missing_observation\", \"completion_not_observed\",\n \"conflicting_observations\", \"reference_mismatch\", \"lineage_mismatch\",\n \"mixed_scope\", \"conflicting_event\",\n ])).max(8),\n groups: z.array(z.object({\n key: ToolLearningHashSchema,\n application: z.string().min(1).max(200),\n applicationVersion: z.string().min(1).max(200),\n tool: z.object({\n name: z.string().min(1).max(200),\n version: z.string().max(200).nullable(),\n server: z.string().max(200).nullable(),\n }).strict(),\n environmentFingerprints: z.array(ToolLearningHashSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode),\n attempts: z.array(ToolLearningRefSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode),\n }).strict()).max(TOOL_LEARNING_LIMITS.eventsPerEpisode),\n}).strict();\n\ntype Issue = z.infer<typeof ToolLearningEpisodeAssemblySchema>[\"issues\"][number];\ntype Attempt = Extract<ToolEpisodeEvent, { eventKind: \"attempt\" }>;\ntype Observation = Extract<ToolEpisodeEvent, { eventKind: \"observation\" }>;\n\n/** Structural assembly of retained calls, never recovery verification or label\n * approval. Conflicting observations remain visible instead of selecting the\n * most recently received answer. Recovery/verifier claims retain their separate\n * owner authority and are not promoted by this read projection. */\nexport function assembleToolLearningEpisode(raw: readonly ToolEpisodeEvent[]) {\n const events = z.array(ToolEpisodeEventSchema).max(TOOL_LEARNING_LIMITS.eventsPerEpisode).parse(raw);\n const incomplete = new Set<Issue>(), ambiguous = new Set<Issue>();\n const byId = new Map<string, ToolEpisodeEvent>();\n const first = events[0];\n for (const event of events) {\n if (first && (event.installationId !== first.installationId || event.episodeId !== first.episodeId))\n ambiguous.add(\"mixed_scope\");\n if (event.parentSessionId === event.sessionId) ambiguous.add(\"lineage_mismatch\");\n const previous = byId.get(event.eventId);\n if (previous && previous.contentHash !== event.contentHash) ambiguous.add(\"conflicting_event\");\n else byId.set(event.eventId, event);\n }\n const attempts = [...byId.values()].filter((event): event is Attempt => event.eventKind === \"attempt\");\n const observations = new Map<string, Observation[]>();\n const callOwners = new Map<string, string>();\n if (!attempts.length) incomplete.add(\"missing_attempt\");\n for (const event of byId.values()) {\n if (event.eventKind !== \"observation\") continue;\n const attempt = byId.get(event.payload.attempt.id);\n if (!attempt) incomplete.add(\"missing_attempt\");\n else if (attempt.eventKind !== \"attempt\" ||\n attempt.contentHash !== event.payload.attempt.contentHash ||\n attempt.payload.actionHash !== event.payload.actionHash) ambiguous.add(\"reference_mismatch\");\n else if (attempt.sessionId !== event.sessionId || attempt.callId !== event.callId ||\n (attempt.parentSessionId && event.parentSessionId && attempt.parentSessionId !== event.parentSessionId) ||\n (attempt.turnId && event.turnId && attempt.turnId !== event.turnId)) ambiguous.add(\"lineage_mismatch\");\n const values = observations.get(event.payload.attempt.id) ?? [];\n values.push(event);\n observations.set(event.payload.attempt.id, values);\n }\n const grouped = new Map<string, {\n application: string; applicationVersion: string; tool: Attempt[\"payload\"][\"tool\"];\n fingerprints: Set<string>; attempts: Array<{ id: string; contentHash: string }>;\n }>();\n for (const attempt of attempts) {\n const callKey = JSON.stringify([attempt.sessionId, attempt.callId]);\n const previousCall = callOwners.get(callKey);\n if (previousCall && previousCall !== attempt.contentHash) ambiguous.add(\"lineage_mismatch\");\n callOwners.set(callKey, attempt.contentHash);\n const values = observations.get(attempt.eventId) ?? [];\n if (!values.length) incomplete.add(\"missing_observation\");\n else {\n const terminal = values.filter((event) => event.payload.outcome !== \"incomplete\");\n if (!terminal.length) incomplete.add(\"completion_not_observed\");\n if (new Set(terminal.map((event) => contentHash(event.payload))).size > 1)\n ambiguous.add(\"conflicting_observations\");\n }\n const { environment, tool } = attempt.payload;\n const key = contentHash([environment.application, environment.version, tool.name, tool.version, tool.server]);\n const group = grouped.get(key) ?? {\n application: environment.application, applicationVersion: environment.version,\n tool, fingerprints: new Set<string>(), attempts: [],\n };\n group.fingerprints.add(environment.fingerprint);\n group.attempts.push({ id: attempt.eventId, contentHash: attempt.contentHash });\n grouped.set(key, group);\n }\n return ToolLearningEpisodeAssemblySchema.parse({\n state: ambiguous.size ? \"ambiguous\" : incomplete.size ? \"incomplete\" : \"awaiting_owner_review\",\n issues: [...new Set([...ambiguous, ...incomplete])].sort(),\n groups: [...grouped].sort(([a], [b]) => a.localeCompare(b)).map(([key, group]) => ({\n key, application: group.application, applicationVersion: group.applicationVersion, tool: group.tool,\n environmentFingerprints: [...group.fingerprints].sort(),\n attempts: group.attempts.sort((a, b) => a.id.localeCompare(b.id)),\n })),\n });\n}\n"],"mappings":";;;;;;;;;;;;;AACA,cAAc;;;ACDd,SAAS,KAAAA,UAAS;AAElB,SAAS,iCAAi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M;AAAA,UAC7C,sBAAsB,KAAK,SAAS;AAAA,UACpC,QAAQ;AAAA,UACR,GAAI,SAAS,SAAY,CAAC,IAAI,EAAE,gBAAgB,mBAAmB;AAAA,QACrE;AAAA,QACA,GAAI,SAAS,SAAY,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,IAAI,EAAE;AAAA,MAC7D;AAAA,IACF;AACA,UAAM,QAAQ,MAAM;AAAA,MAClB;AAAA,MACAA,sBAAqB,aAAaA,sBAAqB;AAAA,MACvD;AAAA,IACF;AACA,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,QAAQD,GACX,OAAO;AAAA,QACN,MAAMA,GACH,OAAO,EACP,MAAM,cAAc,EACpB,IAAI,GAAG;AAAA,MACZ,CAAC,EACA,YAAY,EACZ,UAAU,KAAK;AAClB,YAAM,IAAI;AAAA,QACR,SAAS;AAAA,QACT,MAAM,UAAU,MAAM,KAAK,OAAO;AAAA,MACpC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["z","TOOL_LEARNING_LIMITS","ToolEpisodeEventSchema","ToolLearningRefSchema","z","TOOL_LEARNING_LIMITS","ToolLearningRefSchema","ToolEpisodeEventSchema","value"]}