@warpmetrics/warp 0.0.10 → 0.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warpmetrics/warp",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Measure your agents, not your LLM calls.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -7,5 +7,8 @@ export const runRegistry = new Map();
7
7
  /** @type {Map<string, object>} group id → group data */
8
8
  export const groupRegistry = new Map();
9
9
 
10
+ /** @type {Map<string, object>} act id → act data */
11
+ export const actRegistry = new Map();
12
+
10
13
  /** @type {WeakMap<object, string>} LLM response object → call id */
11
14
  export const responseRegistry = new WeakMap();
@@ -159,6 +159,7 @@ export function logRun(data) {
159
159
  label: data.label,
160
160
  link: data.link,
161
161
  name: data.name,
162
+ refId: data.refId || null,
162
163
  timestamp: new Date().toISOString(),
163
164
  });
164
165
  }
@@ -188,7 +189,7 @@ export function logLink(data) {
188
189
  export function logOutcome(data) {
189
190
  enqueue('outcomes', {
190
191
  id: data.id,
191
- targetId: data.targetId,
192
+ refId: data.refId,
192
193
  name: data.name,
193
194
  reason: data.reason,
194
195
  source: data.source,
@@ -200,7 +201,8 @@ export function logOutcome(data) {
200
201
 
201
202
  export function logAct(data) {
202
203
  enqueue('acts', {
203
- targetId: data.targetId,
204
+ id: data.id,
205
+ refId: data.refId,
204
206
  name: data.name,
205
207
  metadata: data.metadata,
206
208
  timestamp: new Date().toISOString(),
package/src/core/utils.js CHANGED
@@ -6,7 +6,7 @@ const ulid = monotonicFactory();
6
6
 
7
7
  /**
8
8
  * Generate a prefixed ULID-based unique ID (lowercase).
9
- * @param {'run' | 'grp' | 'call' | 'oc'} prefix
9
+ * @param {'run' | 'grp' | 'call' | 'oc' | 'act'} prefix
10
10
  * @returns {string} e.g. "wm_run_01jkx3ndek0gh4r5tmqp9a3bcv"
11
11
  */
12
12
  export function generateId(prefix) {
package/src/index.d.ts CHANGED
@@ -47,6 +47,11 @@ export interface OutcomeOptions {
47
47
  metadata?: Record<string, any>;
48
48
  }
49
49
 
50
+ export interface Act {
51
+ readonly id: string;
52
+ readonly _type: 'act';
53
+ }
54
+
50
55
 
51
56
  /**
52
57
  * Wrap an LLM client to automatically track every API call.
@@ -56,6 +61,8 @@ export function warp<T>(client: T, options?: WarpOptions): T;
56
61
 
57
62
  /** Create a run — the top-level unit that tracks one agent execution. */
58
63
  export function run(label: string, options?: RunOptions): Run;
64
+ /** Create a follow-up run from an act. */
65
+ export function run(act: Act | string, label: string, options?: RunOptions): Run;
59
66
 
60
67
  /** Create a group — a logical phase or step inside a run. */
61
68
  export function group(label: string, options?: GroupOptions): Group;
@@ -70,15 +77,15 @@ export function outcome(
70
77
  options?: OutcomeOptions,
71
78
  ): Outcome | undefined;
72
79
 
73
- /** Record an action taken on an outcome (e.g. acting on feedback). */
80
+ /** Record an action taken on an outcome. Returns an Act handle for use with run(). */
74
81
  export function act(
75
82
  target: Outcome | string,
76
83
  name: string,
77
84
  metadata?: Record<string, any>,
78
- ): void;
85
+ ): Act | undefined;
79
86
 
80
87
  /** Resolve any trackable target to its string ID. */
81
- export function ref(target: Run | Group | Outcome | object | string): string | undefined;
88
+ export function ref(target: Run | Group | Act | Outcome | object | string): string | undefined;
82
89
 
83
90
  /** Manually flush pending events to the API. */
84
91
  export function flush(): Promise<void>;
package/src/index.js CHANGED
@@ -3,10 +3,11 @@
3
3
  //
4
4
  // warp(client, options?) — wrap an LLM client
5
5
  // run(label, options?) — create a run
6
+ // run(act, label, options?) — create a follow-up run from an act
6
7
  // group(label, options?) — create a group
7
8
  // add(target, ...items) — add groups / calls to a run or group
8
9
  // outcome(target, name, options?) — record a result
9
- // act(target, name, options?) — record an action taken on a result
10
+ // act(target, name, metadata?) — record an action, returns act ref
10
11
  // ref(target) — get tracking ID
11
12
  export { warp } from './core/warp.js';
12
13
  export { run } from './trace/run.js';
package/src/trace/act.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Warpmetrics SDK — act()
2
2
 
3
3
  import { ref as getRef } from './ref.js';
4
+ import { generateId } from '../core/utils.js';
5
+ import { actRegistry } from '../core/registry.js';
4
6
  import { logAct, getConfig } from '../core/transport.js';
5
7
 
6
8
  /**
@@ -9,23 +11,25 @@ import { logAct, getConfig } from '../core/transport.js';
9
11
  * @param {{ id: string, _type: 'outcome' } | string} target — Outcome handle from outcome(), or outcome ref string (wm_oc_*)
10
12
  * @param {string} name — action name ("improve-section", "refine-prompt")
11
13
  * @param {Record<string, any>} [metadata] — arbitrary extra data
14
+ * @returns {{ readonly id: string, readonly _type: 'act' } | undefined}
12
15
  */
13
16
  export function act(target, name, metadata) {
14
- const targetId = getRef(target);
17
+ const refId = getRef(target);
15
18
 
16
- if (!targetId) {
19
+ if (!refId) {
17
20
  if (getConfig().debug) console.warn('[warpmetrics] act() — target not tracked.');
18
- return;
21
+ return undefined;
19
22
  }
20
23
 
21
- if (!targetId.startsWith('wm_oc_')) {
24
+ if (!refId.startsWith('wm_oc_')) {
22
25
  if (getConfig().debug) console.warn('[warpmetrics] act() — target must be an outcome (wm_oc_*).');
23
- return;
26
+ return undefined;
24
27
  }
25
28
 
26
- logAct({
27
- targetId,
28
- name,
29
- metadata: metadata || null,
30
- });
29
+ const id = generateId('act');
30
+ actRegistry.set(id, { id, refId });
31
+
32
+ logAct({ id, refId, name, metadata: metadata || null });
33
+
34
+ return Object.freeze({ id, _type: 'act' });
31
35
  }
@@ -19,9 +19,9 @@ import { logOutcome, getConfig } from '../core/transport.js';
19
19
  * @returns {{ id: string, _type: 'outcome' } | undefined}
20
20
  */
21
21
  export function outcome(target, name, options = {}) {
22
- const targetId = getRef(target);
22
+ const refId = getRef(target);
23
23
 
24
- if (!targetId) {
24
+ if (!refId) {
25
25
  if (getConfig().debug) console.warn('[warpmetrics] outcome() — target not tracked.');
26
26
  return undefined;
27
27
  }
@@ -30,7 +30,7 @@ export function outcome(target, name, options = {}) {
30
30
 
31
31
  logOutcome({
32
32
  id,
33
- targetId,
33
+ refId,
34
34
  name,
35
35
  reason: options.reason || null,
36
36
  source: options.source || null,
package/src/trace/run.js CHANGED
@@ -1,19 +1,37 @@
1
1
  // Warpmetrics SDK — run()
2
2
 
3
+ import { ref as getRef } from './ref.js';
3
4
  import { generateId } from '../core/utils.js';
4
5
  import { runRegistry } from '../core/registry.js';
5
- import { logRun } from '../core/transport.js';
6
+ import { logRun, getConfig } from '../core/transport.js';
6
7
 
7
8
  /**
8
9
  * Create a run — the top-level unit that tracks one agent execution.
9
10
  *
10
- * @param {string} label — run type used for aggregation ("code-review", "bug-fix")
11
- * @param {object} [options]
12
- * @param {string} [options.link] — external reference ("ticket:PROJ-101", PR URL, etc.)
13
- * @param {string} [options.name] — human-readable name
11
+ * @param {string | { id: string, _type: 'act' }} labelOrRef — run label, or act ref for follow-up runs
12
+ * @param {string | object} [labelOrOpts] — label (if first arg is act ref) or options
13
+ * @param {object} [maybeOpts]
14
+ * @param {string} [maybeOpts.link] — external reference ("ticket:PROJ-101", PR URL, etc.)
15
+ * @param {string} [maybeOpts.name] — human-readable name
14
16
  * @returns {{ readonly id: string, readonly _type: 'run' }}
15
17
  */
16
- export function run(label, options = {}) {
18
+ export function run(labelOrRef, labelOrOpts, maybeOpts) {
19
+ let refId = null;
20
+ let label, options;
21
+
22
+ if (typeof labelOrRef === 'string' && !labelOrRef.startsWith('wm_act_')) {
23
+ label = labelOrRef;
24
+ options = labelOrOpts || {};
25
+ } else {
26
+ refId = getRef(labelOrRef);
27
+ if (refId && !refId.startsWith('wm_act_')) {
28
+ if (getConfig().debug) console.warn('[warpmetrics] run() ref must be an act (wm_act_*).');
29
+ refId = null;
30
+ }
31
+ label = labelOrOpts;
32
+ options = maybeOpts || {};
33
+ }
34
+
17
35
  const id = generateId('run');
18
36
 
19
37
  const data = {
@@ -21,6 +39,7 @@ export function run(label, options = {}) {
21
39
  label,
22
40
  link: options.link || null,
23
41
  name: options.name || null,
42
+ refId,
24
43
  groups: [],
25
44
  calls: [],
26
45
  };