@wytness/sdk 0.3.0 → 0.3.1

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.
package/dist/index.cjs CHANGED
@@ -309,7 +309,7 @@ function sanitise(params) {
309
309
  function hashValue(value) {
310
310
  return (0, import_crypto4.createHash)("sha256").update(JSON.stringify(value, null, 0)).digest("hex");
311
311
  }
312
- function recordEvent(client, toolName, taskId, args, start, status, errorCode, result) {
312
+ function recordEvent(client, toolName, taskId, prompt, args, start, status, errorCode, result) {
313
313
  const params = {};
314
314
  args.forEach((arg, i) => {
315
315
  params[`arg${i}`] = arg;
@@ -322,6 +322,7 @@ function recordEvent(client, toolName, taskId, args, start, status, errorCode, r
322
322
  session_id: client.sessionId,
323
323
  tool_name: toolName,
324
324
  tool_parameters: sanitise(params),
325
+ prompt,
325
326
  inputs_hash: hashValue(args),
326
327
  outputs_hash: result != null ? hashValue(result) : "",
327
328
  status,
@@ -330,26 +331,26 @@ function recordEvent(client, toolName, taskId, args, start, status, errorCode, r
330
331
  });
331
332
  client.record(event);
332
333
  }
333
- function wrapFn(client, fn, toolName, taskId) {
334
+ function wrapFn(client, fn, toolName, taskId, prompt) {
334
335
  const wrapped = function(...args) {
335
336
  const start = performance.now();
336
337
  let result;
337
338
  try {
338
339
  result = fn.apply(this, args);
339
340
  } catch (e) {
340
- recordEvent(client, toolName, taskId, args, start, "failure", e.constructor.name, null);
341
+ recordEvent(client, toolName, taskId, prompt, args, start, "failure", e.constructor.name, null);
341
342
  throw e;
342
343
  }
343
344
  if (result && typeof result.then === "function") {
344
345
  return result.then((resolved) => {
345
- recordEvent(client, toolName, taskId, args, start, "success", null, resolved);
346
+ recordEvent(client, toolName, taskId, prompt, args, start, "success", null, resolved);
346
347
  return resolved;
347
348
  }).catch((e) => {
348
- recordEvent(client, toolName, taskId, args, start, "failure", e.constructor.name, null);
349
+ recordEvent(client, toolName, taskId, prompt, args, start, "failure", e.constructor.name, null);
349
350
  throw e;
350
351
  });
351
352
  }
352
- recordEvent(client, toolName, taskId, args, start, "success", null, result);
353
+ recordEvent(client, toolName, taskId, prompt, args, start, "success", null, result);
353
354
  return result;
354
355
  };
355
356
  Object.defineProperty(wrapped, "name", { value: toolName });
@@ -361,12 +362,13 @@ function auditTool(client, fnOrTaskId, options) {
361
362
  const opts = typeof options === "object" ? options : {};
362
363
  const toolName = opts.toolName ?? fn.name ?? "anonymous";
363
364
  const taskId2 = opts.taskId ?? "default";
364
- return wrapFn(client, fn, toolName, taskId2);
365
+ const prompt = opts.prompt ?? "";
366
+ return wrapFn(client, fn, toolName, taskId2, prompt);
365
367
  }
366
368
  const taskId = typeof fnOrTaskId === "string" ? fnOrTaskId : "default";
367
369
  return function(fn, fnName) {
368
370
  const toolName = fnName ?? fn.name ?? "anonymous";
369
- return wrapFn(client, fn, toolName, taskId);
371
+ return wrapFn(client, fn, toolName, taskId, "");
370
372
  };
371
373
  }
372
374
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -137,6 +137,7 @@ declare function hashValue(value: unknown): string;
137
137
  interface AuditToolOptions {
138
138
  toolName?: string;
139
139
  taskId?: string;
140
+ prompt?: string;
140
141
  }
141
142
  /**
142
143
  * Wrap a function with audit logging. Works with both sync and async functions.
package/dist/index.d.ts CHANGED
@@ -137,6 +137,7 @@ declare function hashValue(value: unknown): string;
137
137
  interface AuditToolOptions {
138
138
  toolName?: string;
139
139
  taskId?: string;
140
+ prompt?: string;
140
141
  }
141
142
  /**
142
143
  * Wrap a function with audit logging. Works with both sync and async functions.
package/dist/index.js CHANGED
@@ -263,7 +263,7 @@ function sanitise(params) {
263
263
  function hashValue(value) {
264
264
  return createHash2("sha256").update(JSON.stringify(value, null, 0)).digest("hex");
265
265
  }
266
- function recordEvent(client, toolName, taskId, args, start, status, errorCode, result) {
266
+ function recordEvent(client, toolName, taskId, prompt, args, start, status, errorCode, result) {
267
267
  const params = {};
268
268
  args.forEach((arg, i) => {
269
269
  params[`arg${i}`] = arg;
@@ -276,6 +276,7 @@ function recordEvent(client, toolName, taskId, args, start, status, errorCode, r
276
276
  session_id: client.sessionId,
277
277
  tool_name: toolName,
278
278
  tool_parameters: sanitise(params),
279
+ prompt,
279
280
  inputs_hash: hashValue(args),
280
281
  outputs_hash: result != null ? hashValue(result) : "",
281
282
  status,
@@ -284,26 +285,26 @@ function recordEvent(client, toolName, taskId, args, start, status, errorCode, r
284
285
  });
285
286
  client.record(event);
286
287
  }
287
- function wrapFn(client, fn, toolName, taskId) {
288
+ function wrapFn(client, fn, toolName, taskId, prompt) {
288
289
  const wrapped = function(...args) {
289
290
  const start = performance.now();
290
291
  let result;
291
292
  try {
292
293
  result = fn.apply(this, args);
293
294
  } catch (e) {
294
- recordEvent(client, toolName, taskId, args, start, "failure", e.constructor.name, null);
295
+ recordEvent(client, toolName, taskId, prompt, args, start, "failure", e.constructor.name, null);
295
296
  throw e;
296
297
  }
297
298
  if (result && typeof result.then === "function") {
298
299
  return result.then((resolved) => {
299
- recordEvent(client, toolName, taskId, args, start, "success", null, resolved);
300
+ recordEvent(client, toolName, taskId, prompt, args, start, "success", null, resolved);
300
301
  return resolved;
301
302
  }).catch((e) => {
302
- recordEvent(client, toolName, taskId, args, start, "failure", e.constructor.name, null);
303
+ recordEvent(client, toolName, taskId, prompt, args, start, "failure", e.constructor.name, null);
303
304
  throw e;
304
305
  });
305
306
  }
306
- recordEvent(client, toolName, taskId, args, start, "success", null, result);
307
+ recordEvent(client, toolName, taskId, prompt, args, start, "success", null, result);
307
308
  return result;
308
309
  };
309
310
  Object.defineProperty(wrapped, "name", { value: toolName });
@@ -315,12 +316,13 @@ function auditTool(client, fnOrTaskId, options) {
315
316
  const opts = typeof options === "object" ? options : {};
316
317
  const toolName = opts.toolName ?? fn.name ?? "anonymous";
317
318
  const taskId2 = opts.taskId ?? "default";
318
- return wrapFn(client, fn, toolName, taskId2);
319
+ const prompt = opts.prompt ?? "";
320
+ return wrapFn(client, fn, toolName, taskId2, prompt);
319
321
  }
320
322
  const taskId = typeof fnOrTaskId === "string" ? fnOrTaskId : "default";
321
323
  return function(fn, fnName) {
322
324
  const toolName = fnName ?? fn.name ?? "anonymous";
323
- return wrapFn(client, fn, toolName, taskId);
325
+ return wrapFn(client, fn, toolName, taskId, "");
324
326
  };
325
327
  }
326
328
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wytness/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "TypeScript SDK for Wytness — audit logging for AI agents with cryptographic signing and chain integrity",
5
5
  "license": "MIT",
6
6
  "author": "Wytness <hello@wytness.dev>",