@warpmetrics/warp 0.0.13 → 0.0.16
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 +1 -1
- package/src/core/registry.js +3 -0
- package/src/trace/call.js +1 -5
- package/src/trace/group.js +1 -5
- package/src/trace/outcome.js +3 -0
- package/src/trace/ref.js +29 -4
package/package.json
CHANGED
package/src/core/registry.js
CHANGED
|
@@ -7,6 +7,9 @@ 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>} outcome id → outcome data */
|
|
11
|
+
export const outcomeRegistry = new Map();
|
|
12
|
+
|
|
10
13
|
/** @type {Map<string, object>} act id → act data */
|
|
11
14
|
export const actRegistry = new Map();
|
|
12
15
|
|
package/src/trace/call.js
CHANGED
|
@@ -19,10 +19,6 @@ export function call(target, response, opts) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const parentData = runRegistry.get(targetId) || groupRegistry.get(targetId);
|
|
22
|
-
if (!parentData) {
|
|
23
|
-
if (getConfig().debug) console.warn(`[warpmetrics] call() — target not in registry: ${targetId}`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
22
|
|
|
27
23
|
// Auto-extract _warpResponse if present (error case)
|
|
28
24
|
const actualResponse = response?._warpResponse || response;
|
|
@@ -38,7 +34,7 @@ export function call(target, response, opts) {
|
|
|
38
34
|
|
|
39
35
|
logCall(data);
|
|
40
36
|
logLink({ parentId: targetId, childId: id, type: 'call' });
|
|
41
|
-
parentData.calls.push(id);
|
|
37
|
+
if (parentData) parentData.calls.push(id);
|
|
42
38
|
|
|
43
39
|
responseRegistry.delete(actualResponse);
|
|
44
40
|
}
|
package/src/trace/group.js
CHANGED
|
@@ -21,10 +21,6 @@ export function group(target, label, opts) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const parentData = runRegistry.get(targetId) || groupRegistry.get(targetId);
|
|
24
|
-
if (!parentData) {
|
|
25
|
-
if (getConfig().debug) console.warn(`[warpmetrics] group() — target not in registry: ${targetId}`);
|
|
26
|
-
return Object.freeze({ id: generateId('grp'), _type: 'group' });
|
|
27
|
-
}
|
|
28
24
|
|
|
29
25
|
const id = generateId('grp');
|
|
30
26
|
|
|
@@ -38,7 +34,7 @@ export function group(target, label, opts) {
|
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
groupRegistry.set(id, data);
|
|
41
|
-
parentData.groups.push(id);
|
|
37
|
+
if (parentData) parentData.groups.push(id);
|
|
42
38
|
|
|
43
39
|
logGroup(data);
|
|
44
40
|
logLink({ parentId: targetId, childId: id, type: 'group' });
|
package/src/trace/outcome.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { ref as getRef } from './ref.js';
|
|
4
4
|
import { generateId } from '../core/utils.js';
|
|
5
|
+
import { outcomeRegistry } from '../core/registry.js';
|
|
5
6
|
import { logOutcome, getConfig } from '../core/transport.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -24,6 +25,8 @@ export function outcome(target, name, opts) {
|
|
|
24
25
|
|
|
25
26
|
const id = generateId('oc');
|
|
26
27
|
|
|
28
|
+
outcomeRegistry.set(id, { id, refId, name, opts: opts || null });
|
|
29
|
+
|
|
27
30
|
logOutcome({
|
|
28
31
|
id,
|
|
29
32
|
refId,
|
package/src/trace/ref.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
// Warpmetrics SDK — ref()
|
|
2
2
|
|
|
3
|
-
import { responseRegistry } from '../core/registry.js';
|
|
3
|
+
import { runRegistry, groupRegistry, outcomeRegistry, actRegistry, responseRegistry } from '../core/registry.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve any trackable target to its string ID.
|
|
7
7
|
*
|
|
8
|
+
* When a raw ID string is passed (e.g. loaded from a database or fetched
|
|
9
|
+
* from the API), it is adopted into the local registry so that downstream
|
|
10
|
+
* calls like group(), call(), outcome(), and act() can reference it.
|
|
11
|
+
*
|
|
8
12
|
* Accepts:
|
|
9
|
-
* - A string ref (
|
|
10
|
-
* - A Run or
|
|
13
|
+
* - A string ref (e.g. "wm_run_...", "wm_grp_...", "wm_oc_...", "wm_act_...")
|
|
14
|
+
* - A Run, Group, Outcome, or Act object ({ id, _type })
|
|
11
15
|
* - An LLM response object (looked up in the response registry)
|
|
12
16
|
*
|
|
13
17
|
* @param {object | string} target
|
|
14
18
|
* @returns {string | undefined}
|
|
15
19
|
*/
|
|
16
20
|
export function ref(target) {
|
|
17
|
-
if (typeof target === 'string')
|
|
21
|
+
if (typeof target === 'string') {
|
|
22
|
+
ensureRegistered(target);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
if (target && target._type && target.id) return target.id;
|
|
20
27
|
|
|
@@ -25,3 +32,21 @@ export function ref(target) {
|
|
|
25
32
|
|
|
26
33
|
return undefined;
|
|
27
34
|
}
|
|
35
|
+
|
|
36
|
+
const REGISTRIES = [
|
|
37
|
+
['wm_run_', runRegistry],
|
|
38
|
+
['wm_grp_', groupRegistry],
|
|
39
|
+
['wm_oc_', outcomeRegistry],
|
|
40
|
+
['wm_act_', actRegistry],
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
function ensureRegistered(id) {
|
|
44
|
+
for (const [prefix, registry] of REGISTRIES) {
|
|
45
|
+
if (id.startsWith(prefix)) {
|
|
46
|
+
if (!registry.has(id)) {
|
|
47
|
+
registry.set(id, { id, label: null, opts: null, groups: [], calls: [], stub: true });
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|