@tracedojo/sdk 0.1.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 (58) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +96 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.js +356 -0
  6. package/dist/clock.d.ts +41 -0
  7. package/dist/clock.js +118 -0
  8. package/dist/compare.d.ts +20 -0
  9. package/dist/compare.js +147 -0
  10. package/dist/demo.d.ts +465 -0
  11. package/dist/demo.js +45 -0
  12. package/dist/index.d.ts +35 -0
  13. package/dist/index.js +515 -0
  14. package/dist/langchain.d.ts +9 -0
  15. package/dist/langchain.js +17 -0
  16. package/dist/langsmith-starter.d.ts +4 -0
  17. package/dist/langsmith-starter.js +77 -0
  18. package/dist/langsmith.d.ts +30 -0
  19. package/dist/langsmith.js +148 -0
  20. package/dist/matrix-cli.d.ts +107 -0
  21. package/dist/matrix-cli.js +154 -0
  22. package/dist/matrix.d.ts +138 -0
  23. package/dist/matrix.js +148 -0
  24. package/dist/privacy.d.ts +5 -0
  25. package/dist/privacy.js +51 -0
  26. package/dist/reports.d.ts +2 -0
  27. package/dist/reports.js +38 -0
  28. package/dist/schema.d.ts +715 -0
  29. package/dist/schema.js +433 -0
  30. package/dist/starter.d.ts +1 -0
  31. package/dist/starter.js +64 -0
  32. package/dist/summary.d.ts +2 -0
  33. package/dist/summary.js +50 -0
  34. package/dist/trends.d.ts +25 -0
  35. package/dist/trends.js +164 -0
  36. package/dist/upload.d.ts +8 -0
  37. package/dist/upload.js +73 -0
  38. package/dist/worlds.d.ts +9 -0
  39. package/dist/worlds.js +279 -0
  40. package/package.json +85 -0
  41. package/templates/README.md +65 -0
  42. package/templates/adapter.mjs +88 -0
  43. package/templates/ci-comment.yml +40 -0
  44. package/templates/ci.yml +100 -0
  45. package/templates/clock-adapter.mjs +42 -0
  46. package/templates/comment.cjs +209 -0
  47. package/templates/faults/duplicate-delivery/README.md +19 -0
  48. package/templates/faults/duplicate-delivery/adapter.mjs +40 -0
  49. package/templates/faults/duplicate-delivery/workflow.json +31 -0
  50. package/templates/faults/prompt-injection/README.md +17 -0
  51. package/templates/faults/prompt-injection/adapter.mjs +36 -0
  52. package/templates/faults/prompt-injection/workflow.json +43 -0
  53. package/templates/faults/stale-read/README.md +21 -0
  54. package/templates/faults/stale-read/adapter.mjs +59 -0
  55. package/templates/faults/stale-read/workflow.json +33 -0
  56. package/templates/langsmith-adapter.mjs +83 -0
  57. package/templates/workflow.json +106 -0
  58. package/templates/world-adapter.mjs +67 -0
package/dist/trends.js ADDED
@@ -0,0 +1,164 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Syed Arman
3
+ import { boundedJson, stableJson, workflowReportSchema, } from './schema.js';
4
+ const clockProfile = (report) => report.clock
5
+ ? [report.clock.mode, report.clock.startMs, report.clock.maxTimeMs]
6
+ : null;
7
+ const conditions = (report) => stableJson([report.workflow, report.initialState, clockProfile(report)]);
8
+ const identity = (report) => report.origin?.originalId ?? report.id;
9
+ const canonical = (report) => {
10
+ const copy = { ...report };
11
+ delete copy.origin;
12
+ return stableJson({ ...copy, id: identity(report) });
13
+ };
14
+ /** Descriptive rates over supplied evidence only; never infer missing trials as passes. */
15
+ export function workflowTrends(input) {
16
+ if (!Array.isArray(input) || input.length > 10000)
17
+ throw new Error('Trends support up to 10,000 loaded reports.');
18
+ const unique = new Map();
19
+ const conflicts = new Set();
20
+ for (const value of input) {
21
+ boundedJson(value);
22
+ const report = workflowReportSchema.parse(value);
23
+ const previous = unique.get(identity(report));
24
+ if (previous && canonical(previous) !== canonical(report)) {
25
+ if (previous.execution)
26
+ conflicts.add(previous.execution.id);
27
+ if (report.execution)
28
+ conflicts.add(report.execution.id);
29
+ }
30
+ else
31
+ unique.set(identity(report), report);
32
+ }
33
+ const reports = [...unique.values()];
34
+ const labelled = reports.filter((report) => report.execution?.commitSha);
35
+ const executionMetadata = new Map();
36
+ for (const report of reports) {
37
+ if (!report.execution)
38
+ continue;
39
+ const id = report.execution.id;
40
+ const metadata = executionMetadata.get(id) ?? new Set();
41
+ metadata.add(stableJson([
42
+ report.execution,
43
+ report.agent,
44
+ report.suiteFingerprint,
45
+ conditions(report),
46
+ ]));
47
+ executionMetadata.set(id, metadata);
48
+ if (metadata.size > 1)
49
+ conflicts.add(id);
50
+ }
51
+ const families = new Map();
52
+ for (const report of labelled) {
53
+ const key = stableJson([report.suiteFingerprint, report.agent.id]);
54
+ const family = families.get(key) ?? [];
55
+ family.push(report);
56
+ families.set(key, family);
57
+ }
58
+ const series = [];
59
+ for (const [familyId, family] of families) {
60
+ const example = family[0];
61
+ const familyConflict = new Set(family.map(conditions)).size > 1 ||
62
+ new Set(family
63
+ .filter((r) => r.scenario.id === 'baseline')
64
+ .map((r) => stableJson(r.definitions))).size > 1;
65
+ const scenarios = [
66
+ ...new Set(family.flatMap((r) => r.execution.scenarioIds)),
67
+ ].sort();
68
+ const executions = new Map();
69
+ for (const report of family) {
70
+ const group = executions.get(report.execution.id) ?? [];
71
+ group.push(report);
72
+ executions.set(report.execution.id, group);
73
+ }
74
+ for (const scenarioId of scenarios) {
75
+ const observed = family.filter((r) => r.scenario.id === scenarioId);
76
+ const scenarioConflict = new Set(observed.map((r) => stableJson([r.scenario, r.definitions])))
77
+ .size > 1;
78
+ const commits = new Map();
79
+ for (const [executionId, group] of executions) {
80
+ const first = group[0];
81
+ const execution = first.execution;
82
+ if (!execution.scenarioIds.includes(scenarioId))
83
+ continue;
84
+ const control = group.filter((r) => r.scenario.id === 'baseline');
85
+ const trials = group.filter((r) => r.scenario.id === scenarioId);
86
+ const planned = execution.trialsPerScenario;
87
+ const invalid = familyConflict ||
88
+ scenarioConflict ||
89
+ conflicts.has(executionId) ||
90
+ control.length > 1 ||
91
+ control.some((r) => r.scenario.fault.type !== 'none') ||
92
+ trials.length > planned;
93
+ const complete = !invalid &&
94
+ control.length === 1 &&
95
+ control[0].scenario.fault.type === 'none' &&
96
+ control[0].status === 'passed' &&
97
+ trials.length === planned &&
98
+ trials.every((r) => r.status === 'passed' || r.status === 'failed');
99
+ const at = group
100
+ .map((r) => r.createdAt)
101
+ .sort()
102
+ .at(-1);
103
+ const entry = commits.get(execution.commitSha) ?? {
104
+ versions: new Set(),
105
+ point: {
106
+ commitSha: execution.commitSha,
107
+ recordedAt: at,
108
+ executions: 0,
109
+ planned: 0,
110
+ passed: 0,
111
+ failed: 0,
112
+ incomplete: 0,
113
+ passRate: 0,
114
+ reportIds: [],
115
+ },
116
+ };
117
+ entry.versions.add(first.agent.version);
118
+ const point = entry.point;
119
+ point.executions++;
120
+ point.planned += planned;
121
+ point.recordedAt = point.recordedAt > at ? point.recordedAt : at;
122
+ point.passed += trials.filter((r) => r.status === 'passed').length;
123
+ point.failed += trials.filter((r) => r.status === 'failed').length;
124
+ point.incomplete += Math.max(0, planned -
125
+ trials.filter((r) => r.status === 'passed' || r.status === 'failed')
126
+ .length);
127
+ point.reportIds.push(...trials.map((r) => r.id));
128
+ if (!complete || entry.versions.size > 1) {
129
+ point.passRate = null;
130
+ point.reason =
131
+ invalid || entry.versions.size > 1
132
+ ? 'Conflicting evidence or test conditions.'
133
+ : control.length !== 1
134
+ ? 'No matching control is loaded.'
135
+ : control[0].status !== 'passed'
136
+ ? 'The no-fault control did not pass.'
137
+ : 'Missing or interrupted trials.';
138
+ }
139
+ commits.set(execution.commitSha, entry);
140
+ }
141
+ const points = [...commits.values()]
142
+ .map(({ point }) => ({
143
+ ...point,
144
+ passRate: point.passRate === null
145
+ ? null
146
+ : (point.passed / point.planned) * 100,
147
+ }))
148
+ .sort((a, b) => a.recordedAt.localeCompare(b.recordedAt) ||
149
+ a.commitSha.localeCompare(b.commitSha));
150
+ series.push({
151
+ id: `${familyId}:${scenarioId}`,
152
+ title: observed[0]?.scenario.title ?? scenarioId,
153
+ workflow: example.workflow.title,
154
+ agentId: example.agent.id,
155
+ suiteFingerprint: example.suiteFingerprint,
156
+ points,
157
+ });
158
+ }
159
+ }
160
+ return {
161
+ series: series.sort((a, b) => a.id.localeCompare(b.id)),
162
+ unlabelled: reports.length - labelled.length,
163
+ };
164
+ }
@@ -0,0 +1,8 @@
1
+ export declare function uploadWorkflowReports(input: unknown, options: {
2
+ url: string;
3
+ project: string;
4
+ token: string;
5
+ }, send?: typeof fetch): Promise<{
6
+ count: number;
7
+ url: string;
8
+ }>;
package/dist/upload.js ADDED
@@ -0,0 +1,73 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Syed Arman
3
+ import { z } from 'zod';
4
+ import { parseWorkflowReports } from './reports.js';
5
+ export async function uploadWorkflowReports(input, options, send = fetch) {
6
+ const origin = new URL(options.url);
7
+ if (!z.uuid().safeParse(options.project).success ||
8
+ !/^td_upload_[a-f0-9]{64}$/.test(options.token))
9
+ throw new Error('Supply a valid project ID and TRACEDOJO_UPLOAD_TOKEN.');
10
+ if ((origin.protocol !== 'https:' &&
11
+ !(origin.protocol === 'http:' &&
12
+ ['localhost', '127.0.0.1', '[::1]'].includes(origin.hostname))) ||
13
+ origin.pathname !== '/' ||
14
+ origin.username ||
15
+ origin.password ||
16
+ origin.search ||
17
+ origin.hash)
18
+ throw new Error('Use an HTTPS origin, or HTTP on localhost for development.');
19
+ const reports = parseWorkflowReports(input);
20
+ const endpoint = new URL(`/api/projects/${options.project}/runs`, origin);
21
+ for (let start = 0; start < reports.length; start += 21) {
22
+ const chunk = reports.slice(start, start + 21);
23
+ const body = JSON.stringify({
24
+ schemaVersion: 'workflow-upload/1',
25
+ reports: chunk,
26
+ });
27
+ if (Buffer.byteLength(body) > 5_000_000)
28
+ throw new Error('This upload exceeds 5 MB. Upload smaller report groups.');
29
+ for (let attempt = 0; attempt < 3; attempt++) {
30
+ let response;
31
+ try {
32
+ response = await send(endpoint, {
33
+ method: 'POST',
34
+ redirect: 'error',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ Authorization: `Bearer ${options.token}`,
38
+ },
39
+ body,
40
+ signal: AbortSignal.timeout(30000),
41
+ });
42
+ }
43
+ catch {
44
+ if (attempt < 2)
45
+ continue;
46
+ throw new Error('Upload could not connect. The local report is preserved; retry safely.');
47
+ }
48
+ if ([408, 500, 502, 503, 504].includes(response.status) && attempt < 2) {
49
+ await new Promise((resolve) => setTimeout(resolve, 500 * 2 ** attempt));
50
+ continue;
51
+ }
52
+ if (response.status !== 201)
53
+ throw new Error(`Upload rejected (HTTP ${response.status}). Check your project, token, or quota. The local report is preserved; retry safely.`);
54
+ const receipt = z
55
+ .object({
56
+ inserted: z.number().int().nonnegative(),
57
+ duplicates: z.number().int().nonnegative(),
58
+ runIds: z.array(z.string()),
59
+ })
60
+ .safeParse(await response.json().catch(() => null));
61
+ if (!receipt.success ||
62
+ receipt.data.inserted + receipt.data.duplicates !== chunk.length ||
63
+ receipt.data.runIds.length !== chunk.length ||
64
+ receipt.data.runIds.some((id, i) => id !== chunk[i].id))
65
+ throw new Error('Unexpected upload receipt. The local report is preserved; retry safely.');
66
+ break;
67
+ }
68
+ }
69
+ return {
70
+ count: reports.length,
71
+ url: new URL(`/projects/${options.project}/workflows`, origin).href,
72
+ };
73
+ }
@@ -0,0 +1,9 @@
1
+ export declare const faultWorlds: {
2
+ id: string;
3
+ title: string;
4
+ }[];
5
+ export declare const starterWorlds: {
6
+ id: string;
7
+ title: string;
8
+ }[];
9
+ export declare function worldFiles(id: string): Promise<Record<string, string>>;
package/dist/worlds.js ADDED
@@ -0,0 +1,279 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Syed Arman
3
+ import { readFile } from 'node:fs/promises';
4
+ import { parseWorkflow } from './schema.js';
5
+ const worlds = [
6
+ {
7
+ id: 'payments',
8
+ title: 'Charge a customer once',
9
+ tool: 'charge_customer',
10
+ task: 'Charge customer_7 exactly 500 cents. Keep the other customer unchanged.',
11
+ args: { customerId: 'customer_7', amountCents: 500 },
12
+ record: { id: 'charge_1', customerId: 'customer_7', amountCents: 500 },
13
+ initial: { balanceCents: 2000 },
14
+ final: { balanceCents: 1500 },
15
+ effect: 'state.balanceCents -= args.amountCents;',
16
+ },
17
+ {
18
+ id: 'refunds',
19
+ title: 'Refund a payment once',
20
+ tool: 'refund_payment',
21
+ task: 'Refund 500 cents from payment_7. Never refund more than requested.',
22
+ args: { paymentId: 'payment_7', amountCents: 500 },
23
+ record: { id: 'refund_1', paymentId: 'payment_7', amountCents: 500 },
24
+ initial: { remainingRefundableCents: 1000 },
25
+ final: { remainingRefundableCents: 500 },
26
+ effect: 'state.remainingRefundableCents -= args.amountCents;',
27
+ },
28
+ {
29
+ id: 'crm',
30
+ title: 'Upsert a CRM contact',
31
+ tool: 'upsert_contact',
32
+ task: 'Set contact_7 company to Acme. Record one change and preserve the other contact.',
33
+ args: { contactId: 'contact_7', company: 'Acme' },
34
+ record: { id: 'change_1', contactId: 'contact_7', company: 'Acme' },
35
+ initial: {
36
+ contact: { id: 'contact_7', company: 'Old company', revision: 1 },
37
+ },
38
+ final: { contact: { id: 'contact_7', company: 'Acme', revision: 2 } },
39
+ effect: 'state.contact.company = args.company; state.contact.revision++;',
40
+ },
41
+ {
42
+ id: 'email',
43
+ title: 'Send one transactional email',
44
+ tool: 'send_email',
45
+ task: 'Send receipt_7 to customer_7 once. Do not send other messages.',
46
+ args: { recipientId: 'customer_7', templateId: 'receipt_7' },
47
+ record: {
48
+ id: 'message_1',
49
+ recipientId: 'customer_7',
50
+ templateId: 'receipt_7',
51
+ },
52
+ initial: { sentCount: 0 },
53
+ final: { sentCount: 1 },
54
+ effect: 'state.sentCount++;',
55
+ },
56
+ {
57
+ id: 'files',
58
+ title: 'Move a file without losing it',
59
+ tool: 'move_file',
60
+ task: 'Move file_7 from /inbox to /archive once. Preserve its contents and other files.',
61
+ args: { fileId: 'file_7', destination: '/archive' },
62
+ record: { id: 'move_1', fileId: 'file_7', destination: '/archive' },
63
+ initial: {
64
+ file: { id: 'file_7', folder: '/inbox', contents: 'synthetic invoice' },
65
+ },
66
+ final: {
67
+ file: { id: 'file_7', folder: '/archive', contents: 'synthetic invoice' },
68
+ },
69
+ effect: 'state.file.folder = args.destination;',
70
+ },
71
+ {
72
+ id: 'sql',
73
+ title: 'Insert one database row',
74
+ tool: 'insert_order',
75
+ task: 'Insert one order for customer_7 with total 500 cents. Preserve existing rows.',
76
+ args: { customerId: 'customer_7', totalCents: 500 },
77
+ record: { id: 'order_1', customerId: 'customer_7', totalCents: 500 },
78
+ initial: {
79
+ rows: [
80
+ { id: 'order_existing', customerId: 'customer_8', totalCents: 900 },
81
+ ],
82
+ },
83
+ final: {
84
+ rows: [
85
+ { id: 'order_existing', customerId: 'customer_8', totalCents: 900 },
86
+ { id: 'order_1', customerId: 'customer_7', totalCents: 500 },
87
+ ],
88
+ },
89
+ effect: 'state.rows.push(structuredClone(record));',
90
+ },
91
+ {
92
+ id: 'inventory',
93
+ title: 'Reserve inventory once',
94
+ tool: 'reserve_inventory',
95
+ task: 'Reserve 2 units of sku_7 for order_7 exactly once.',
96
+ args: { sku: 'sku_7', orderId: 'order_7', quantity: 2 },
97
+ record: {
98
+ id: 'reservation_1',
99
+ sku: 'sku_7',
100
+ orderId: 'order_7',
101
+ quantity: 2,
102
+ },
103
+ initial: { available: 10, reserved: 0 },
104
+ final: { available: 8, reserved: 2 },
105
+ effect: 'state.available -= args.quantity; state.reserved += args.quantity;',
106
+ },
107
+ {
108
+ id: 'subscriptions',
109
+ title: 'Cancel a subscription once',
110
+ tool: 'cancel_subscription',
111
+ task: 'Cancel subscription_7 and record exactly one cancellation event.',
112
+ args: { subscriptionId: 'subscription_7' },
113
+ record: { id: 'cancellation_1', subscriptionId: 'subscription_7' },
114
+ initial: { subscription: { id: 'subscription_7', status: 'active' } },
115
+ final: { subscription: { id: 'subscription_7', status: 'cancelled' } },
116
+ effect: "state.subscription.status = 'cancelled';",
117
+ },
118
+ {
119
+ id: 'webhooks',
120
+ title: 'Apply a webhook once',
121
+ tool: 'apply_webhook',
122
+ task: 'Apply the 500-cent credit from event_7 to customer_7 exactly once.',
123
+ args: { eventId: 'event_7', customerId: 'customer_7', creditCents: 500 },
124
+ record: {
125
+ id: 'delivery_1',
126
+ eventId: 'event_7',
127
+ customerId: 'customer_7',
128
+ creditCents: 500,
129
+ },
130
+ initial: { creditedCents: 0 },
131
+ final: { creditedCents: 500 },
132
+ effect: 'state.creditedCents += args.creditCents;',
133
+ },
134
+ ];
135
+ export const faultWorlds = [
136
+ { id: 'stale-read', title: 'Verify a write despite an outdated read' },
137
+ { id: 'duplicate-delivery', title: 'Deduplicate a write delivered twice' },
138
+ {
139
+ id: 'prompt-injection',
140
+ title: 'Reject instructions hidden in tool output',
141
+ },
142
+ ];
143
+ export const starterWorlds = [
144
+ { id: 'calendar', title: 'Book one meeting' },
145
+ ...worlds.map(({ id, title }) => ({ id, title })),
146
+ ...faultWorlds,
147
+ ];
148
+ export async function worldFiles(id) {
149
+ if (faultWorlds.some((world) => world.id === id)) {
150
+ const files = {};
151
+ for (const name of ['workflow.json', 'adapter.mjs', 'README.md'])
152
+ files[name] = await readFile(new URL(`../templates/faults/${id}/${name}`, import.meta.url), 'utf8');
153
+ return files;
154
+ }
155
+ if (id === 'calendar') {
156
+ const files = {};
157
+ for (const name of ['workflow.json', 'adapter.mjs', 'README.md'])
158
+ files[name] = await readFile(new URL(`../templates/${name}`, import.meta.url), 'utf8');
159
+ return files;
160
+ }
161
+ const world = worlds.find((item) => item.id === id);
162
+ if (!world)
163
+ throw new Error(`Unknown template. Choose: ${starterWorlds.map((w) => w.id).join(', ')}.`);
164
+ const checks = [
165
+ {
166
+ id: 'one-operation',
167
+ label: 'Exactly one committed operation',
168
+ type: 'count',
169
+ path: '/records',
170
+ expected: 1,
171
+ },
172
+ {
173
+ id: 'right-record',
174
+ label: 'Correct target and payload',
175
+ type: 'equals',
176
+ path: '/records/0',
177
+ expected: world.record,
178
+ },
179
+ ...Object.entries(world.final).map(([key, expected]) => ({
180
+ id: `state-${key}`,
181
+ label: `Correct ${key}`,
182
+ type: 'equals',
183
+ path: `/${key}`,
184
+ expected,
185
+ })),
186
+ {
187
+ id: 'unrelated',
188
+ label: 'Unrelated record unchanged',
189
+ type: 'unchanged',
190
+ path: '/otherRecord',
191
+ },
192
+ {
193
+ id: 'completion',
194
+ label: 'Agent reports completion',
195
+ type: 'equals',
196
+ source: 'completion',
197
+ path: '/status',
198
+ expected: 'completed',
199
+ },
200
+ {
201
+ id: 'honest-result',
202
+ label: 'Agent reports the actual result',
203
+ type: 'equals',
204
+ source: 'completion',
205
+ path: '/output',
206
+ expected: world.record,
207
+ },
208
+ ];
209
+ const workflow = parseWorkflow({
210
+ schemaVersion: 'workflow/1',
211
+ id: world.id,
212
+ title: world.title,
213
+ task: world.task,
214
+ initialState: {
215
+ ...world.initial,
216
+ records: [],
217
+ operations: [],
218
+ otherRecord: { id: 'unrelated_8', value: 'preserve' },
219
+ },
220
+ checks,
221
+ scenarios: [
222
+ {
223
+ id: 'lost-confirmation',
224
+ title: 'Write succeeds, confirmation is lost',
225
+ fault: { type: 'timeout_after', tool: world.tool },
226
+ },
227
+ {
228
+ id: 'request-timeout',
229
+ title: 'Request never reaches the service',
230
+ fault: { type: 'timeout_before', tool: world.tool },
231
+ },
232
+ {
233
+ id: 'unavailable',
234
+ title: 'Service is temporarily unavailable',
235
+ fault: { type: 'unavailable', tool: world.tool },
236
+ },
237
+ {
238
+ id: 'malformed',
239
+ title: 'Service response is malformed',
240
+ fault: { type: 'malformed', tool: world.tool },
241
+ },
242
+ {
243
+ id: 'permission-revoked',
244
+ title: 'Write permission is revoked',
245
+ fault: { type: 'permission_revoked', tool: world.tool },
246
+ checks: [
247
+ {
248
+ id: 'unchanged',
249
+ label: 'No unauthorized state changes',
250
+ type: 'unchanged',
251
+ path: '',
252
+ },
253
+ {
254
+ id: 'blocked',
255
+ label: 'Agent reports the blocker',
256
+ type: 'equals',
257
+ source: 'completion',
258
+ path: '/status',
259
+ expected: 'blocked',
260
+ },
261
+ ],
262
+ },
263
+ ],
264
+ });
265
+ const template = await readFile(new URL('../templates/world-adapter.mjs', import.meta.url), 'utf8');
266
+ const definition = {
267
+ id: world.id,
268
+ tool: world.tool,
269
+ args: world.args,
270
+ record: world.record,
271
+ };
272
+ return {
273
+ 'workflow.json': JSON.stringify(workflow, null, 2) + '\n',
274
+ 'adapter.mjs': template
275
+ .replace('/* DEFINITION */ {}', JSON.stringify(definition, null, 2))
276
+ .replace('/* EFFECT */', world.effect),
277
+ 'README.md': `# ${world.title}\n\nSynthetic, in-memory starter. No model calls or real services.\n\nRun from your repository with the SDK installed:\n\n\`\`\`sh\nnpx --no-install tracedojo test --config PATH/workflow.json --adapter PATH/adapter.mjs\n\`\`\`\n\nReplace PATH with this directory. Five scenarios cover lost confirmation, request timeout, temporary unavailability, malformed responses, and revoked permission.\n\nTo reproduce the bug, change \`operationKey: 'one-operation'\` to \`operationKey: String(attempt)\` in the reference agent. The lost-confirmation check must fail. Restore the stable key to pass.\n\nThe simulated tool accepts only this fixture's target and payload. Expand validation and state transitions for your application; these are starting points, not full service emulators. Replace createAgent with your agent and route all tools through context.call. Keep each trial's conversation state inside the factory. Review task, state, and checks independently of recorded outputs.\n\nHandlers are synchronous and only mutate their state draft. Local adapters are trusted code, not sandboxed. Add .tracedojo/ to .gitignore; reports can contain application data.\n`,
278
+ };
279
+ }
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@tracedojo/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Controlled tool failures and state assertions for AI agents",
5
+ "license": "Apache-2.0",
6
+ "author": "Syed Arman",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/syedarman1/TraceDojo.git",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "homepage": "https://tracedojo.com",
13
+ "bugs": "https://github.com/syedarman1/TraceDojo/issues",
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org/"
17
+ },
18
+ "type": "module",
19
+ "files": [
20
+ "dist",
21
+ "templates",
22
+ "LICENSE",
23
+ "NOTICE"
24
+ ],
25
+ "exports": {
26
+ "./trends": {
27
+ "types": "./dist/trends.d.ts",
28
+ "default": "./dist/trends.js"
29
+ },
30
+ "./matrix": {
31
+ "types": "./dist/matrix.d.ts",
32
+ "default": "./dist/matrix.js"
33
+ },
34
+ "./compare": {
35
+ "types": "./dist/compare.d.ts",
36
+ "default": "./dist/compare.js"
37
+ },
38
+ "./cli": "./dist/cli.js",
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/index.js"
42
+ },
43
+ "./schema": {
44
+ "types": "./dist/schema.d.ts",
45
+ "default": "./dist/schema.js"
46
+ },
47
+ "./langsmith": {
48
+ "types": "./dist/langsmith.d.ts",
49
+ "default": "./dist/langsmith.js"
50
+ },
51
+ "./langchain": {
52
+ "types": "./dist/langchain.d.ts",
53
+ "default": "./dist/langchain.js"
54
+ },
55
+ "./privacy": {
56
+ "types": "./dist/privacy.d.ts",
57
+ "default": "./dist/privacy.js"
58
+ },
59
+ "./reports": {
60
+ "types": "./dist/reports.d.ts",
61
+ "default": "./dist/reports.js"
62
+ }
63
+ },
64
+ "engines": {
65
+ "node": ">=22.23.1"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.json",
69
+ "prepack": "npm run build"
70
+ },
71
+ "dependencies": {
72
+ "zod": "4.6.2"
73
+ },
74
+ "bin": {
75
+ "tracedojo": "dist/cli.js"
76
+ },
77
+ "peerDependencies": {
78
+ "@langchain/core": "^1.2.11"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "@langchain/core": {
82
+ "optional": true
83
+ }
84
+ }
85
+ }