@graphorin/core 0.5.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.
- package/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/channels/channels.d.ts +156 -0
- package/dist/channels/channels.d.ts.map +1 -0
- package/dist/channels/channels.js +90 -0
- package/dist/channels/channels.js.map +1 -0
- package/dist/channels/directive.d.ts +34 -0
- package/dist/channels/directive.d.ts.map +1 -0
- package/dist/channels/directive.js +29 -0
- package/dist/channels/directive.js.map +1 -0
- package/dist/channels/dispatch.d.ts +26 -0
- package/dist/channels/dispatch.d.ts.map +1 -0
- package/dist/channels/dispatch.js +32 -0
- package/dist/channels/dispatch.js.map +1 -0
- package/dist/channels/index.d.ts +5 -0
- package/dist/channels/index.js +6 -0
- package/dist/channels/pause.d.ts +84 -0
- package/dist/channels/pause.d.ts.map +1 -0
- package/dist/channels/pause.js +90 -0
- package/dist/channels/pause.js.map +1 -0
- package/dist/contracts/auth-token-store.d.ts +45 -0
- package/dist/contracts/auth-token-store.d.ts.map +1 -0
- package/dist/contracts/checkpoint-store.d.ts +90 -0
- package/dist/contracts/checkpoint-store.d.ts.map +1 -0
- package/dist/contracts/embedder.d.ts +45 -0
- package/dist/contracts/embedder.d.ts.map +1 -0
- package/dist/contracts/eval-scorer.d.ts +46 -0
- package/dist/contracts/eval-scorer.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +22 -0
- package/dist/contracts/index.js +6 -0
- package/dist/contracts/local-provider-trust.d.ts +36 -0
- package/dist/contracts/local-provider-trust.d.ts.map +1 -0
- package/dist/contracts/logger.d.ts +53 -0
- package/dist/contracts/logger.d.ts.map +1 -0
- package/dist/contracts/logger.js +21 -0
- package/dist/contracts/logger.js.map +1 -0
- package/dist/contracts/memory-store.d.ts +106 -0
- package/dist/contracts/memory-store.d.ts.map +1 -0
- package/dist/contracts/oauth-server-store.d.ts +81 -0
- package/dist/contracts/oauth-server-store.d.ts.map +1 -0
- package/dist/contracts/preferred-model.d.ts +60 -0
- package/dist/contracts/preferred-model.d.ts.map +1 -0
- package/dist/contracts/preferred-model.js +15 -0
- package/dist/contracts/preferred-model.js.map +1 -0
- package/dist/contracts/provider.d.ts +272 -0
- package/dist/contracts/provider.d.ts.map +1 -0
- package/dist/contracts/reasoning-retention.d.ts +53 -0
- package/dist/contracts/reasoning-retention.d.ts.map +1 -0
- package/dist/contracts/redaction-validator.d.ts +59 -0
- package/dist/contracts/redaction-validator.d.ts.map +1 -0
- package/dist/contracts/sandbox.d.ts +73 -0
- package/dist/contracts/sandbox.d.ts.map +1 -0
- package/dist/contracts/secret-ref.d.ts +26 -0
- package/dist/contracts/secret-ref.d.ts.map +1 -0
- package/dist/contracts/secret-value.d.ts +112 -0
- package/dist/contracts/secret-value.d.ts.map +1 -0
- package/dist/contracts/secret-value.js +24 -0
- package/dist/contracts/secret-value.js.map +1 -0
- package/dist/contracts/secrets-store.d.ts +87 -0
- package/dist/contracts/secrets-store.d.ts.map +1 -0
- package/dist/contracts/session-store.d.ts +142 -0
- package/dist/contracts/session-store.d.ts.map +1 -0
- package/dist/contracts/token-counter.d.ts +28 -0
- package/dist/contracts/token-counter.d.ts.map +1 -0
- package/dist/contracts/tool.d.ts +264 -0
- package/dist/contracts/tool.d.ts.map +1 -0
- package/dist/contracts/tracer.d.ts +84 -0
- package/dist/contracts/tracer.d.ts.map +1 -0
- package/dist/contracts/tracer.js +34 -0
- package/dist/contracts/tracer.js.map +1 -0
- package/dist/contracts/trigger-store.d.ts +43 -0
- package/dist/contracts/trigger-store.d.ts.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/types/agent-event.d.ts +449 -0
- package/dist/types/agent-event.d.ts.map +1 -0
- package/dist/types/handoff.d.ts +112 -0
- package/dist/types/handoff.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +6 -0
- package/dist/types/memory.d.ts +354 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/message.d.ts +162 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/run.d.ts +155 -0
- package/dist/types/run.d.ts.map +1 -0
- package/dist/types/run.js +31 -0
- package/dist/types/run.js.map +1 -0
- package/dist/types/sensitivity.d.ts +35 -0
- package/dist/types/sensitivity.d.ts.map +1 -0
- package/dist/types/sensitivity.js +29 -0
- package/dist/types/sensitivity.js.map +1 -0
- package/dist/types/session-scope.d.ts +22 -0
- package/dist/types/session-scope.d.ts.map +1 -0
- package/dist/types/stop-condition.d.ts +62 -0
- package/dist/types/stop-condition.d.ts.map +1 -0
- package/dist/types/stop-condition.js +81 -0
- package/dist/types/stop-condition.js.map +1 -0
- package/dist/types/tool-call.d.ts +27 -0
- package/dist/types/tool-call.d.ts.map +1 -0
- package/dist/types/tool.d.ts +260 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/usage.d.ts +82 -0
- package/dist/types/usage.d.ts.map +1 -0
- package/dist/types/usage.js +17 -0
- package/dist/types/usage.js.map +1 -0
- package/dist/types/workflow-event.d.ts +108 -0
- package/dist/types/workflow-event.d.ts.map +1 -0
- package/dist/utils/assert-never.d.ts +26 -0
- package/dist/utils/assert-never.d.ts.map +1 -0
- package/dist/utils/assert-never.js +29 -0
- package/dist/utils/assert-never.js.map +1 -0
- package/dist/utils/async-context.d.ts +37 -0
- package/dist/utils/async-context.d.ts.map +1 -0
- package/dist/utils/async-context.js +33 -0
- package/dist/utils/async-context.js.map +1 -0
- package/dist/utils/hash.d.ts +30 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +102 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/streams.d.ts +59 -0
- package/dist/utils/streams.d.ts.map +1 -0
- package/dist/utils/streams.js +169 -0
- package/dist/utils/streams.js.map +1 -0
- package/dist/utils/validation.d.ts +67 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +36 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/types/usage.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Token / cost metrics for a single LLM call.
|
|
4
|
+
*
|
|
5
|
+
* `cost` is optional because the framework cannot compute it without a
|
|
6
|
+
* pricing snapshot — providers/middleware fill it in (e.g. through the
|
|
7
|
+
* separate `@graphorin/pricing` package) when the snapshot is available.
|
|
8
|
+
*
|
|
9
|
+
* @stable
|
|
10
|
+
*/
|
|
11
|
+
interface Usage {
|
|
12
|
+
promptTokens: number;
|
|
13
|
+
completionTokens: number;
|
|
14
|
+
reasoningTokens?: number;
|
|
15
|
+
totalTokens: number;
|
|
16
|
+
cost?: Cost;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Money figure attached to a `Usage`. Always carries a 3-letter currency
|
|
20
|
+
* code so that consumers can perform aggregation safely.
|
|
21
|
+
*
|
|
22
|
+
* @stable
|
|
23
|
+
*/
|
|
24
|
+
interface Cost {
|
|
25
|
+
/** Amount in the smallest fractional unit of the declared currency. */
|
|
26
|
+
amount: number;
|
|
27
|
+
/** ISO-4217 currency code; default `'USD'`. */
|
|
28
|
+
currency: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Per-model breakdown used by aggregators (e.g. `CostTracker` in
|
|
32
|
+
* `@graphorin/observability`).
|
|
33
|
+
*
|
|
34
|
+
* @stable
|
|
35
|
+
*/
|
|
36
|
+
interface ModelUsage {
|
|
37
|
+
modelId: string;
|
|
38
|
+
promptTokens: number;
|
|
39
|
+
completionTokens: number;
|
|
40
|
+
reasoningTokens?: number;
|
|
41
|
+
totalTokens: number;
|
|
42
|
+
cost?: Cost;
|
|
43
|
+
callCount: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A live accumulator of token / cost figures. Implementations live in
|
|
47
|
+
* `@graphorin/observability`. The contract sits here so every package
|
|
48
|
+
* (agent, workflow, server, …) can type a parameter as `UsageAccumulator`
|
|
49
|
+
* without taking an observability dependency.
|
|
50
|
+
*
|
|
51
|
+
* @stable
|
|
52
|
+
*/
|
|
53
|
+
interface UsageAccumulator {
|
|
54
|
+
/** Current rolled-up totals across every model that has been added. */
|
|
55
|
+
readonly total: Usage;
|
|
56
|
+
/** Per-model breakdown; preserves call counts for observability. */
|
|
57
|
+
readonly byModel: ReadonlyMap<string, ModelUsage>;
|
|
58
|
+
/** Add a single LLM-call usage record under the given model id. */
|
|
59
|
+
add(modelId: string, usage: Usage): void;
|
|
60
|
+
/** Reset the accumulator to a zeroed state. */
|
|
61
|
+
reset(): void;
|
|
62
|
+
/** Render an immutable snapshot suitable for serialization / span attrs. */
|
|
63
|
+
snapshot(): UsageSnapshot;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Immutable, JSON-serializable snapshot of a `UsageAccumulator`.
|
|
67
|
+
*
|
|
68
|
+
* @stable
|
|
69
|
+
*/
|
|
70
|
+
interface UsageSnapshot {
|
|
71
|
+
readonly total: Usage;
|
|
72
|
+
readonly byModel: readonly ModelUsage[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns a fresh, zeroed `Usage` value.
|
|
76
|
+
*
|
|
77
|
+
* @stable
|
|
78
|
+
*/
|
|
79
|
+
declare function zeroUsage(): Usage;
|
|
80
|
+
//#endregion
|
|
81
|
+
export { Cost, ModelUsage, Usage, UsageAccumulator, UsageSnapshot, zeroUsage };
|
|
82
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","names":[],"sources":["../../src/types/usage.ts"],"sourcesContent":[],"mappings":";;AASA;AAcA;AAaA;AAkBA;;;;;AAWc,UAxDG,KAAA,CAwDH;EAAa,YAAA,EAAA,MAAA;EAQV,gBAAa,EAAA,MAAA;EAUd,eAAS,CAAA,EAAA,MAAA;;SArEhB;;;;;;;;UASQ,IAAA;;;;;;;;;;;;UAaA,UAAA;;;;;;SAMR;;;;;;;;;;;UAYQ,gBAAA;;kBAEC;;oBAEE,oBAAoB;;8BAGV;;;;cAIhB;;;;;;;UAQG,aAAA;kBACC;6BACW;;;;;;;iBAQb,SAAA,CAAA,GAAa"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/types/usage.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns a fresh, zeroed `Usage` value.
|
|
4
|
+
*
|
|
5
|
+
* @stable
|
|
6
|
+
*/
|
|
7
|
+
function zeroUsage() {
|
|
8
|
+
return {
|
|
9
|
+
promptTokens: 0,
|
|
10
|
+
completionTokens: 0,
|
|
11
|
+
totalTokens: 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { zeroUsage };
|
|
17
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","names":[],"sources":["../../src/types/usage.ts"],"sourcesContent":["/**\n * Token / cost metrics for a single LLM call.\n *\n * `cost` is optional because the framework cannot compute it without a\n * pricing snapshot — providers/middleware fill it in (e.g. through the\n * separate `@graphorin/pricing` package) when the snapshot is available.\n *\n * @stable\n */\nexport interface Usage {\n promptTokens: number;\n completionTokens: number;\n reasoningTokens?: number;\n totalTokens: number;\n cost?: Cost;\n}\n\n/**\n * Money figure attached to a `Usage`. Always carries a 3-letter currency\n * code so that consumers can perform aggregation safely.\n *\n * @stable\n */\nexport interface Cost {\n /** Amount in the smallest fractional unit of the declared currency. */\n amount: number;\n /** ISO-4217 currency code; default `'USD'`. */\n currency: string;\n}\n\n/**\n * Per-model breakdown used by aggregators (e.g. `CostTracker` in\n * `@graphorin/observability`).\n *\n * @stable\n */\nexport interface ModelUsage {\n modelId: string;\n promptTokens: number;\n completionTokens: number;\n reasoningTokens?: number;\n totalTokens: number;\n cost?: Cost;\n callCount: number;\n}\n\n/**\n * A live accumulator of token / cost figures. Implementations live in\n * `@graphorin/observability`. The contract sits here so every package\n * (agent, workflow, server, …) can type a parameter as `UsageAccumulator`\n * without taking an observability dependency.\n *\n * @stable\n */\nexport interface UsageAccumulator {\n /** Current rolled-up totals across every model that has been added. */\n readonly total: Usage;\n /** Per-model breakdown; preserves call counts for observability. */\n readonly byModel: ReadonlyMap<string, ModelUsage>;\n\n /** Add a single LLM-call usage record under the given model id. */\n add(modelId: string, usage: Usage): void;\n /** Reset the accumulator to a zeroed state. */\n reset(): void;\n /** Render an immutable snapshot suitable for serialization / span attrs. */\n snapshot(): UsageSnapshot;\n}\n\n/**\n * Immutable, JSON-serializable snapshot of a `UsageAccumulator`.\n *\n * @stable\n */\nexport interface UsageSnapshot {\n readonly total: Usage;\n readonly byModel: readonly ModelUsage[];\n}\n\n/**\n * Returns a fresh, zeroed `Usage` value.\n *\n * @stable\n */\nexport function zeroUsage(): Usage {\n return { promptTokens: 0, completionTokens: 0, totalTokens: 0 };\n}\n"],"mappings":";;;;;;AAmFA,SAAgB,YAAmB;AACjC,QAAO;EAAE,cAAc;EAAG,kBAAkB;EAAG,aAAa;EAAG"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/types/workflow-event.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Discriminated union of every event produced by `Workflow.execute(...)`
|
|
4
|
+
* and `Workflow.resume(...)`.
|
|
5
|
+
*
|
|
6
|
+
* Generic over `TState` so that downstream consumers can discriminate on
|
|
7
|
+
* the workflow's typed state shape.
|
|
8
|
+
*
|
|
9
|
+
* @stable
|
|
10
|
+
*/
|
|
11
|
+
type WorkflowEvent<TState = unknown> = WorkflowStartEvent | WorkflowStepStartEvent<TState> | WorkflowStepEndEvent<TState> | WorkflowTaskStartEvent | WorkflowTaskEndEvent | WorkflowChannelUpdateEvent<TState> | WorkflowCheckpointWrittenEvent | WorkflowSuspendedEvent<TState> | WorkflowResumedEvent<TState> | WorkflowEndEvent<TState> | WorkflowErrorEvent | WorkflowCustomEvent;
|
|
12
|
+
/** @stable */
|
|
13
|
+
interface WorkflowStartEvent {
|
|
14
|
+
readonly type: 'workflow.start';
|
|
15
|
+
readonly threadId: string;
|
|
16
|
+
readonly workflowId: string;
|
|
17
|
+
}
|
|
18
|
+
/** @stable */
|
|
19
|
+
interface WorkflowStepStartEvent<TState = unknown> {
|
|
20
|
+
readonly type: 'workflow.step.start';
|
|
21
|
+
readonly stepNumber: number;
|
|
22
|
+
readonly state: TState;
|
|
23
|
+
}
|
|
24
|
+
/** @stable */
|
|
25
|
+
interface WorkflowStepEndEvent<TState = unknown> {
|
|
26
|
+
readonly type: 'workflow.step.end';
|
|
27
|
+
readonly stepNumber: number;
|
|
28
|
+
readonly state: TState;
|
|
29
|
+
}
|
|
30
|
+
/** @stable */
|
|
31
|
+
interface WorkflowTaskStartEvent {
|
|
32
|
+
readonly type: 'workflow.task.start';
|
|
33
|
+
readonly stepNumber: number;
|
|
34
|
+
readonly taskId: string;
|
|
35
|
+
readonly nodeName: string;
|
|
36
|
+
}
|
|
37
|
+
/** @stable */
|
|
38
|
+
interface WorkflowTaskEndEvent {
|
|
39
|
+
readonly type: 'workflow.task.end';
|
|
40
|
+
readonly stepNumber: number;
|
|
41
|
+
readonly taskId: string;
|
|
42
|
+
readonly nodeName: string;
|
|
43
|
+
readonly status: 'completed' | 'failed' | 'paused';
|
|
44
|
+
readonly durationMs: number;
|
|
45
|
+
}
|
|
46
|
+
/** @stable */
|
|
47
|
+
interface WorkflowChannelUpdateEvent<TState = unknown> {
|
|
48
|
+
readonly type: 'workflow.channel.update';
|
|
49
|
+
readonly stepNumber: number;
|
|
50
|
+
readonly channel: keyof TState & string;
|
|
51
|
+
readonly version: number;
|
|
52
|
+
}
|
|
53
|
+
/** @stable */
|
|
54
|
+
interface WorkflowCheckpointWrittenEvent {
|
|
55
|
+
readonly type: 'workflow.checkpoint.written';
|
|
56
|
+
readonly checkpointId: string;
|
|
57
|
+
readonly stepNumber: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Workflow paused — for HITL approvals or programmatic `pause(value)`
|
|
61
|
+
* calls. Carries the value passed to `pause(...)` so the caller can
|
|
62
|
+
* choose how to surface the prompt to the user.
|
|
63
|
+
*
|
|
64
|
+
* @stable
|
|
65
|
+
*/
|
|
66
|
+
interface WorkflowSuspendedEvent<TState = unknown> {
|
|
67
|
+
readonly type: 'workflow.suspended';
|
|
68
|
+
readonly threadId: string;
|
|
69
|
+
readonly stepNumber: number;
|
|
70
|
+
readonly state: TState;
|
|
71
|
+
readonly value: unknown;
|
|
72
|
+
}
|
|
73
|
+
/** @stable */
|
|
74
|
+
interface WorkflowResumedEvent<TState = unknown> {
|
|
75
|
+
readonly type: 'workflow.resumed';
|
|
76
|
+
readonly threadId: string;
|
|
77
|
+
readonly stepNumber: number;
|
|
78
|
+
readonly state: TState;
|
|
79
|
+
}
|
|
80
|
+
/** @stable */
|
|
81
|
+
interface WorkflowEndEvent<TState = unknown> {
|
|
82
|
+
readonly type: 'workflow.end';
|
|
83
|
+
readonly threadId: string;
|
|
84
|
+
readonly state: TState;
|
|
85
|
+
}
|
|
86
|
+
/** @stable */
|
|
87
|
+
interface WorkflowErrorEvent {
|
|
88
|
+
readonly type: 'workflow.error';
|
|
89
|
+
readonly threadId: string;
|
|
90
|
+
readonly error: {
|
|
91
|
+
readonly message: string;
|
|
92
|
+
readonly code: string;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Application-defined event emitted from inside a workflow node via
|
|
97
|
+
* `ctx.emit(name, payload)`. The runtime never produces these on its own.
|
|
98
|
+
*
|
|
99
|
+
* @stable
|
|
100
|
+
*/
|
|
101
|
+
interface WorkflowCustomEvent {
|
|
102
|
+
readonly type: 'workflow.custom';
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly payload: unknown;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { WorkflowChannelUpdateEvent, WorkflowCheckpointWrittenEvent, WorkflowCustomEvent, WorkflowEndEvent, WorkflowErrorEvent, WorkflowEvent, WorkflowResumedEvent, WorkflowStartEvent, WorkflowStepEndEvent, WorkflowStepStartEvent, WorkflowSuspendedEvent, WorkflowTaskEndEvent, WorkflowTaskStartEvent };
|
|
108
|
+
//# sourceMappingURL=workflow-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-event.d.ts","names":[],"sources":["../../src/types/workflow-event.ts"],"sourcesContent":[],"mappings":";;AASA;;;;;;;;AAM+B,KANnB,aAMmB,CAAA,SAAA,OAAA,CAAA,GAL3B,kBAK2B,GAJ3B,sBAI2B,CAJJ,MAII,CAAA,GAH3B,oBAG2B,CAHN,MAGM,CAAA,GAF3B,sBAE2B,GAD3B,oBAC2B,GAA3B,0BAA2B,CAAA,MAAA,CAAA,GAC3B,8BAD2B,GAE3B,sBAF2B,CAEJ,MAFI,CAAA,GAG3B,oBAH2B,CAGN,MAHM,CAAA,GAI3B,gBAJ2B,CAIV,MAJU,CAAA,GAK3B,kBAL2B,GAM3B,mBAN2B;;AAC3B,UAQa,kBAAA,CARb;EACuB,SAAA,IAAA,EAAA,gBAAA;EAAvB,SAAA,QAAA,EAAA,MAAA;EACqB,SAAA,UAAA,EAAA,MAAA;;;AACrB,UAYa,sBAZb,CAAA,SAAA,OAAA,CAAA,CAAA;EACA,SAAA,IAAA,EAAA,qBAAA;EACA,SAAA,UAAA,EAAA,MAAA;EAAmB,SAAA,KAAA,EAaL,MAbK;AAGvB;AAOA;AAOiB,UAAA,oBAAoB,CAAA,SAGnB,OAAM,CAAA,CAAA;EAIP,SAAA,IAAA,EAAA,mBAAsB;EAQtB,SAAA,UAAA,EAAA,MAAoB;EAUpB,SAAA,KAAA,EAtBC,MAsBD;AAQjB;AAaA;AASiB,UAhDA,sBAAA,CAgDoB;EAQpB,SAAA,IAAA,EAAA,qBAAgB;EAOhB,SAAA,UAAA,EAAkB,MAAA;EAYlB,SAAA,MAAA,EAAA,MAAmB;;;;UAnEnB,oBAAA;;;;;;;;;UAUA;;;0BAGS;;;;UAKT,8BAAA;;;;;;;;;;;;UAaA;;;;kBAIC;;;;UAKD;;;;kBAIC;;;UAID;;;kBAGC;;;UAID,kBAAA;;;;;;;;;;;;;;UAYA,mBAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/utils/assert-never.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Exhaustiveness helper. Place at the end of a `switch (...)` over a
|
|
4
|
+
* discriminated union: TypeScript narrows the operand to `never` if
|
|
5
|
+
* every variant is handled. Adding a new variant later turns the call
|
|
6
|
+
* site into a compile error — the regression net for our event unions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* function describe(event: AgentEvent): string {
|
|
11
|
+
* switch (event.type) {
|
|
12
|
+
* case 'agent.start': return 'started';
|
|
13
|
+
* case 'agent.end': return 'ended';
|
|
14
|
+
* // ... every other variant ...
|
|
15
|
+
* default:
|
|
16
|
+
* return assertNever(event, 'Unhandled AgentEvent variant');
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @stable
|
|
22
|
+
*/
|
|
23
|
+
declare function assertNever(value: never, message?: string): never;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { assertNever };
|
|
26
|
+
//# sourceMappingURL=assert-never.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-never.d.ts","names":[],"sources":["../../src/utils/assert-never.ts"],"sourcesContent":[],"mappings":";;AAqBA;;;;;;;;;;;;;;;;;;;;iBAAgB,WAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/utils/assert-never.ts
|
|
2
|
+
/**
|
|
3
|
+
* Exhaustiveness helper. Place at the end of a `switch (...)` over a
|
|
4
|
+
* discriminated union: TypeScript narrows the operand to `never` if
|
|
5
|
+
* every variant is handled. Adding a new variant later turns the call
|
|
6
|
+
* site into a compile error — the regression net for our event unions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* function describe(event: AgentEvent): string {
|
|
11
|
+
* switch (event.type) {
|
|
12
|
+
* case 'agent.start': return 'started';
|
|
13
|
+
* case 'agent.end': return 'ended';
|
|
14
|
+
* // ... every other variant ...
|
|
15
|
+
* default:
|
|
16
|
+
* return assertNever(event, 'Unhandled AgentEvent variant');
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @stable
|
|
22
|
+
*/
|
|
23
|
+
function assertNever(value, message) {
|
|
24
|
+
throw new Error(message ?? `graphorin: unhandled discriminated-union variant: ${String(value)}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { assertNever };
|
|
29
|
+
//# sourceMappingURL=assert-never.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-never.js","names":[],"sources":["../../src/utils/assert-never.ts"],"sourcesContent":["/**\n * Exhaustiveness helper. Place at the end of a `switch (...)` over a\n * discriminated union: TypeScript narrows the operand to `never` if\n * every variant is handled. Adding a new variant later turns the call\n * site into a compile error — the regression net for our event unions.\n *\n * @example\n * ```ts\n * function describe(event: AgentEvent): string {\n * switch (event.type) {\n * case 'agent.start': return 'started';\n * case 'agent.end': return 'ended';\n * // ... every other variant ...\n * default:\n * return assertNever(event, 'Unhandled AgentEvent variant');\n * }\n * }\n * ```\n *\n * @stable\n */\nexport function assertNever(value: never, message?: string): never {\n throw new Error(message ?? `graphorin: unhandled discriminated-union variant: ${String(value)}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,YAAY,OAAc,SAAyB;AACjE,OAAM,IAAI,MAAM,WAAW,qDAAqD,OAAO,MAAM,GAAG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/utils/async-context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Thin typed wrapper around Node's `AsyncLocalStorage`. Used to thread a
|
|
4
|
+
* tool-execution / request-scoped context through the async stack
|
|
5
|
+
* without explicit parameter passing.
|
|
6
|
+
*
|
|
7
|
+
* The wrapper exists because:
|
|
8
|
+
* - The Node API requires a fresh `AsyncLocalStorage<T>` per scope; this
|
|
9
|
+
* helper centralizes the construction with consistent typing.
|
|
10
|
+
* - Downstream packages (security, tools) want a single canonical
|
|
11
|
+
* constructor so that their `getStore()` code paths share the same
|
|
12
|
+
* identity (matters for HMR / multi-realm setups).
|
|
13
|
+
*
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
interface AsyncContext<T> {
|
|
17
|
+
/** Run `fn` inside a fresh scope carrying `value`. */
|
|
18
|
+
run<R>(value: T, fn: () => R): R;
|
|
19
|
+
/** Run `fn` inside a fresh scope carrying `value` (async-friendly). */
|
|
20
|
+
runAsync<R>(value: T, fn: () => Promise<R>): Promise<R>;
|
|
21
|
+
/** Get the value of the current scope, or `undefined` outside one. */
|
|
22
|
+
get(): T | undefined;
|
|
23
|
+
/** Replace the value of the current scope (advanced; rarely needed). */
|
|
24
|
+
enterWith(value: T): void;
|
|
25
|
+
/** Exit any in-flight scope (advanced; rarely needed). */
|
|
26
|
+
disable(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Construct a typed `AsyncContext`. The optional `name` is surfaced in
|
|
30
|
+
* the diagnostics channel of `AsyncLocalStorage` (debugging only).
|
|
31
|
+
*
|
|
32
|
+
* @stable
|
|
33
|
+
*/
|
|
34
|
+
declare function createAsyncContext<T>(_name?: string): AsyncContext<T>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { AsyncContext, createAsyncContext };
|
|
37
|
+
//# sourceMappingURL=async-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.d.ts","names":[],"sources":["../../src/utils/async-context.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;AAmBA;UAnBiB;;gBAED,aAAa,IAAI;;qBAEZ,aAAa,QAAQ,KAAK,QAAQ;;SAE9C;;mBAEU;;;;;;;;;;iBAWH,uCAAuC,aAAa"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/async-context.ts
|
|
4
|
+
/**
|
|
5
|
+
* Construct a typed `AsyncContext`. The optional `name` is surfaced in
|
|
6
|
+
* the diagnostics channel of `AsyncLocalStorage` (debugging only).
|
|
7
|
+
*
|
|
8
|
+
* @stable
|
|
9
|
+
*/
|
|
10
|
+
function createAsyncContext(_name) {
|
|
11
|
+
const als = new AsyncLocalStorage();
|
|
12
|
+
return {
|
|
13
|
+
run(value, fn) {
|
|
14
|
+
return als.run(value, fn);
|
|
15
|
+
},
|
|
16
|
+
runAsync(value, fn) {
|
|
17
|
+
return als.run(value, fn);
|
|
18
|
+
},
|
|
19
|
+
get() {
|
|
20
|
+
return als.getStore();
|
|
21
|
+
},
|
|
22
|
+
enterWith(value) {
|
|
23
|
+
als.enterWith(value);
|
|
24
|
+
},
|
|
25
|
+
disable() {
|
|
26
|
+
als.disable();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createAsyncContext };
|
|
33
|
+
//# sourceMappingURL=async-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.js","names":[],"sources":["../../src/utils/async-context.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\n/**\n * Thin typed wrapper around Node's `AsyncLocalStorage`. Used to thread a\n * tool-execution / request-scoped context through the async stack\n * without explicit parameter passing.\n *\n * The wrapper exists because:\n * - The Node API requires a fresh `AsyncLocalStorage<T>` per scope; this\n * helper centralizes the construction with consistent typing.\n * - Downstream packages (security, tools) want a single canonical\n * constructor so that their `getStore()` code paths share the same\n * identity (matters for HMR / multi-realm setups).\n *\n * @stable\n */\nexport interface AsyncContext<T> {\n /** Run `fn` inside a fresh scope carrying `value`. */\n run<R>(value: T, fn: () => R): R;\n /** Run `fn` inside a fresh scope carrying `value` (async-friendly). */\n runAsync<R>(value: T, fn: () => Promise<R>): Promise<R>;\n /** Get the value of the current scope, or `undefined` outside one. */\n get(): T | undefined;\n /** Replace the value of the current scope (advanced; rarely needed). */\n enterWith(value: T): void;\n /** Exit any in-flight scope (advanced; rarely needed). */\n disable(): void;\n}\n\n/**\n * Construct a typed `AsyncContext`. The optional `name` is surfaced in\n * the diagnostics channel of `AsyncLocalStorage` (debugging only).\n *\n * @stable\n */\nexport function createAsyncContext<T>(_name?: string): AsyncContext<T> {\n const als = new AsyncLocalStorage<T>();\n return {\n run<R>(value: T, fn: () => R): R {\n return als.run(value, fn);\n },\n runAsync<R>(value: T, fn: () => Promise<R>): Promise<R> {\n return als.run(value, fn);\n },\n get(): T | undefined {\n return als.getStore();\n },\n enterWith(value: T): void {\n als.enterWith(value);\n },\n disable(): void {\n als.disable();\n },\n };\n}\n"],"mappings":";;;;;;;;;AAmCA,SAAgB,mBAAsB,OAAiC;CACrE,MAAM,MAAM,IAAI,mBAAsB;AACtC,QAAO;EACL,IAAO,OAAU,IAAgB;AAC/B,UAAO,IAAI,IAAI,OAAO,GAAG;;EAE3B,SAAY,OAAU,IAAkC;AACtD,UAAO,IAAI,IAAI,OAAO,GAAG;;EAE3B,MAAqB;AACnB,UAAO,IAAI,UAAU;;EAEvB,UAAU,OAAgB;AACxB,OAAI,UAAU,MAAM;;EAEtB,UAAgB;AACd,OAAI,SAAS;;EAEhB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/utils/hash.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* MD5 hex digest. Used by the memory layer for content deduplication
|
|
4
|
+
* (`MD5(content)` is the dedup key for incoming facts / messages).
|
|
5
|
+
*
|
|
6
|
+
* MD5 is **not** a cryptographic primitive in this codebase — it's used
|
|
7
|
+
* exclusively for collision-resistant content addressing where
|
|
8
|
+
* collision-resistance is the desired property, not pre-image resistance.
|
|
9
|
+
* Do not use this helper for password hashing, MAC, or any other
|
|
10
|
+
* security-sensitive use case (use `@graphorin/security` for those).
|
|
11
|
+
*
|
|
12
|
+
* @stable
|
|
13
|
+
*/
|
|
14
|
+
declare function md5(content: string | Uint8Array): string;
|
|
15
|
+
/**
|
|
16
|
+
* Pure-JS XXH32 implementation. Used by the memory-modification guard
|
|
17
|
+
* — fast, non-cryptographic content fingerprinting (`xxhash(content)`
|
|
18
|
+
* tracks whether a tool's view of memory has shifted while the LLM was
|
|
19
|
+
* thinking).
|
|
20
|
+
*
|
|
21
|
+
* Not security-sensitive — never use for tampering detection of an
|
|
22
|
+
* untrusted attacker; for that the audit log uses SHA-256 (in
|
|
23
|
+
* `@graphorin/security`).
|
|
24
|
+
*
|
|
25
|
+
* @stable
|
|
26
|
+
*/
|
|
27
|
+
declare function xxhash(input: string | Uint8Array, seed?: number): string;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { md5, xxhash };
|
|
30
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","names":[],"sources":["../../src/utils/hash.ts"],"sourcesContent":[],"mappings":";;AAcA;AAsBA;;;;;;;;;;iBAtBgB,GAAA,mBAAsB;;;;;;;;;;;;;iBAsBtB,MAAA,iBAAuB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hash.ts
|
|
4
|
+
/**
|
|
5
|
+
* MD5 hex digest. Used by the memory layer for content deduplication
|
|
6
|
+
* (`MD5(content)` is the dedup key for incoming facts / messages).
|
|
7
|
+
*
|
|
8
|
+
* MD5 is **not** a cryptographic primitive in this codebase — it's used
|
|
9
|
+
* exclusively for collision-resistant content addressing where
|
|
10
|
+
* collision-resistance is the desired property, not pre-image resistance.
|
|
11
|
+
* Do not use this helper for password hashing, MAC, or any other
|
|
12
|
+
* security-sensitive use case (use `@graphorin/security` for those).
|
|
13
|
+
*
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
function md5(content) {
|
|
17
|
+
const h = createHash("md5");
|
|
18
|
+
if (typeof content === "string") h.update(content, "utf8");
|
|
19
|
+
else h.update(content);
|
|
20
|
+
return h.digest("hex");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Pure-JS XXH32 implementation. Used by the memory-modification guard
|
|
24
|
+
* — fast, non-cryptographic content fingerprinting (`xxhash(content)`
|
|
25
|
+
* tracks whether a tool's view of memory has shifted while the LLM was
|
|
26
|
+
* thinking).
|
|
27
|
+
*
|
|
28
|
+
* Not security-sensitive — never use for tampering detection of an
|
|
29
|
+
* untrusted attacker; for that the audit log uses SHA-256 (in
|
|
30
|
+
* `@graphorin/security`).
|
|
31
|
+
*
|
|
32
|
+
* @stable
|
|
33
|
+
*/
|
|
34
|
+
function xxhash(input, seed = 0) {
|
|
35
|
+
return xxh32(typeof input === "string" ? utf8Encode(input) : input, seed >>> 0).toString(16).padStart(8, "0");
|
|
36
|
+
}
|
|
37
|
+
const PRIME32_1 = 2654435761;
|
|
38
|
+
const PRIME32_2 = 2246822519;
|
|
39
|
+
const PRIME32_3 = 3266489917;
|
|
40
|
+
const PRIME32_4 = 668265263;
|
|
41
|
+
const PRIME32_5 = 374761393;
|
|
42
|
+
const utf8 = new TextEncoder();
|
|
43
|
+
function utf8Encode(s) {
|
|
44
|
+
return utf8.encode(s);
|
|
45
|
+
}
|
|
46
|
+
function rotl32(x, r) {
|
|
47
|
+
return (x << r | x >>> 32 - r) >>> 0;
|
|
48
|
+
}
|
|
49
|
+
function mul32(a, b) {
|
|
50
|
+
const aLo = a & 65535;
|
|
51
|
+
const aHi = a >>> 16;
|
|
52
|
+
const bLo = b & 65535;
|
|
53
|
+
const bHi = b >>> 16;
|
|
54
|
+
return aLo * bLo + (aLo * bHi + aHi * bLo << 16 >>> 0) >>> 0;
|
|
55
|
+
}
|
|
56
|
+
function read32LE(buf, offset) {
|
|
57
|
+
const b0 = buf[offset] ?? 0;
|
|
58
|
+
const b1 = buf[offset + 1] ?? 0;
|
|
59
|
+
const b2 = buf[offset + 2] ?? 0;
|
|
60
|
+
const b3 = buf[offset + 3] ?? 0;
|
|
61
|
+
return (b0 | b1 << 8 | b2 << 16 | b3 << 24) >>> 0;
|
|
62
|
+
}
|
|
63
|
+
function xxh32(input, seed) {
|
|
64
|
+
const len = input.length;
|
|
65
|
+
let h32;
|
|
66
|
+
let i = 0;
|
|
67
|
+
if (len >= 16) {
|
|
68
|
+
let v1 = seed + PRIME32_1 + PRIME32_2 >>> 0;
|
|
69
|
+
let v2 = seed + PRIME32_2 >>> 0;
|
|
70
|
+
let v3 = seed >>> 0;
|
|
71
|
+
let v4 = seed - PRIME32_1 >>> 0;
|
|
72
|
+
while (i + 16 <= len) {
|
|
73
|
+
v1 = mul32(rotl32(v1 + mul32(read32LE(input, i), PRIME32_2) >>> 0, 13), PRIME32_1);
|
|
74
|
+
i += 4;
|
|
75
|
+
v2 = mul32(rotl32(v2 + mul32(read32LE(input, i), PRIME32_2) >>> 0, 13), PRIME32_1);
|
|
76
|
+
i += 4;
|
|
77
|
+
v3 = mul32(rotl32(v3 + mul32(read32LE(input, i), PRIME32_2) >>> 0, 13), PRIME32_1);
|
|
78
|
+
i += 4;
|
|
79
|
+
v4 = mul32(rotl32(v4 + mul32(read32LE(input, i), PRIME32_2) >>> 0, 13), PRIME32_1);
|
|
80
|
+
i += 4;
|
|
81
|
+
}
|
|
82
|
+
h32 = rotl32(v1, 1) + rotl32(v2, 7) + rotl32(v3, 12) + rotl32(v4, 18) >>> 0;
|
|
83
|
+
} else h32 = seed + PRIME32_5 >>> 0;
|
|
84
|
+
h32 = h32 + len >>> 0;
|
|
85
|
+
while (i + 4 <= len) {
|
|
86
|
+
h32 = mul32(rotl32(h32 + mul32(read32LE(input, i), PRIME32_3) >>> 0, 17), PRIME32_4);
|
|
87
|
+
i += 4;
|
|
88
|
+
}
|
|
89
|
+
while (i < len) {
|
|
90
|
+
const byte = input[i] ?? 0;
|
|
91
|
+
h32 = mul32(rotl32(h32 + mul32(byte >>> 0, PRIME32_5) >>> 0, 11), PRIME32_1);
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
h32 = mul32(h32 ^ h32 >>> 15, PRIME32_2);
|
|
95
|
+
h32 = mul32(h32 ^ h32 >>> 13, PRIME32_3);
|
|
96
|
+
h32 = (h32 ^ h32 >>> 16) >>> 0;
|
|
97
|
+
return h32;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { md5, xxhash };
|
|
102
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","names":["h32: number"],"sources":["../../src/utils/hash.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\n/**\n * MD5 hex digest. Used by the memory layer for content deduplication\n * (`MD5(content)` is the dedup key for incoming facts / messages).\n *\n * MD5 is **not** a cryptographic primitive in this codebase — it's used\n * exclusively for collision-resistant content addressing where\n * collision-resistance is the desired property, not pre-image resistance.\n * Do not use this helper for password hashing, MAC, or any other\n * security-sensitive use case (use `@graphorin/security` for those).\n *\n * @stable\n */\nexport function md5(content: string | Uint8Array): string {\n const h = createHash('md5');\n if (typeof content === 'string') {\n h.update(content, 'utf8');\n } else {\n h.update(content);\n }\n return h.digest('hex');\n}\n\n/**\n * Pure-JS XXH32 implementation. Used by the memory-modification guard\n * — fast, non-cryptographic content fingerprinting (`xxhash(content)`\n * tracks whether a tool's view of memory has shifted while the LLM was\n * thinking).\n *\n * Not security-sensitive — never use for tampering detection of an\n * untrusted attacker; for that the audit log uses SHA-256 (in\n * `@graphorin/security`).\n *\n * @stable\n */\nexport function xxhash(input: string | Uint8Array, seed = 0): string {\n const bytes = typeof input === 'string' ? utf8Encode(input) : input;\n const h = xxh32(bytes, seed >>> 0);\n return h.toString(16).padStart(8, '0');\n}\n\nconst PRIME32_1 = 0x9e3779b1 >>> 0;\nconst PRIME32_2 = 0x85ebca77 >>> 0;\nconst PRIME32_3 = 0xc2b2ae3d >>> 0;\nconst PRIME32_4 = 0x27d4eb2f >>> 0;\nconst PRIME32_5 = 0x165667b1 >>> 0;\n\nconst utf8 = new TextEncoder();\nfunction utf8Encode(s: string): Uint8Array {\n return utf8.encode(s);\n}\n\nfunction rotl32(x: number, r: number): number {\n return ((x << r) | (x >>> (32 - r))) >>> 0;\n}\n\nfunction mul32(a: number, b: number): number {\n // Multiply two 32-bit unsigned ints with overflow truncation.\n const aLo = a & 0xffff;\n const aHi = a >>> 16;\n const bLo = b & 0xffff;\n const bHi = b >>> 16;\n return (aLo * bLo + (((aLo * bHi + aHi * bLo) << 16) >>> 0)) >>> 0;\n}\n\nfunction read32LE(buf: Uint8Array, offset: number): number {\n const b0 = buf[offset] ?? 0;\n const b1 = buf[offset + 1] ?? 0;\n const b2 = buf[offset + 2] ?? 0;\n const b3 = buf[offset + 3] ?? 0;\n return (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24)) >>> 0;\n}\n\nfunction xxh32(input: Uint8Array, seed: number): number {\n const len = input.length;\n let h32: number;\n let i = 0;\n\n if (len >= 16) {\n let v1 = (seed + PRIME32_1 + PRIME32_2) >>> 0;\n let v2 = (seed + PRIME32_2) >>> 0;\n let v3 = seed >>> 0;\n let v4 = (seed - PRIME32_1) >>> 0;\n\n while (i + 16 <= len) {\n v1 = mul32(rotl32((v1 + mul32(read32LE(input, i), PRIME32_2)) >>> 0, 13), PRIME32_1);\n i += 4;\n v2 = mul32(rotl32((v2 + mul32(read32LE(input, i), PRIME32_2)) >>> 0, 13), PRIME32_1);\n i += 4;\n v3 = mul32(rotl32((v3 + mul32(read32LE(input, i), PRIME32_2)) >>> 0, 13), PRIME32_1);\n i += 4;\n v4 = mul32(rotl32((v4 + mul32(read32LE(input, i), PRIME32_2)) >>> 0, 13), PRIME32_1);\n i += 4;\n }\n\n h32 = (rotl32(v1, 1) + rotl32(v2, 7) + rotl32(v3, 12) + rotl32(v4, 18)) >>> 0;\n } else {\n h32 = (seed + PRIME32_5) >>> 0;\n }\n\n h32 = (h32 + len) >>> 0;\n\n while (i + 4 <= len) {\n h32 = mul32(rotl32((h32 + mul32(read32LE(input, i), PRIME32_3)) >>> 0, 17), PRIME32_4);\n i += 4;\n }\n\n while (i < len) {\n const byte = input[i] ?? 0;\n h32 = mul32(rotl32((h32 + mul32(byte >>> 0, PRIME32_5)) >>> 0, 11), PRIME32_1);\n i++;\n }\n\n h32 = mul32(h32 ^ (h32 >>> 15), PRIME32_2);\n h32 = mul32(h32 ^ (h32 >>> 13), PRIME32_3);\n h32 = (h32 ^ (h32 >>> 16)) >>> 0;\n\n return h32;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,IAAI,SAAsC;CACxD,MAAM,IAAI,WAAW,MAAM;AAC3B,KAAI,OAAO,YAAY,SACrB,GAAE,OAAO,SAAS,OAAO;KAEzB,GAAE,OAAO,QAAQ;AAEnB,QAAO,EAAE,OAAO,MAAM;;;;;;;;;;;;;;AAexB,SAAgB,OAAO,OAA4B,OAAO,GAAW;AAGnE,QADU,MADI,OAAO,UAAU,WAAW,WAAW,MAAM,GAAG,OACvC,SAAS,EAAE,CACzB,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI;;AAGxC,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AAElB,MAAM,OAAO,IAAI,aAAa;AAC9B,SAAS,WAAW,GAAuB;AACzC,QAAO,KAAK,OAAO,EAAE;;AAGvB,SAAS,OAAO,GAAW,GAAmB;AAC5C,SAAS,KAAK,IAAM,MAAO,KAAK,OAAS;;AAG3C,SAAS,MAAM,GAAW,GAAmB;CAE3C,MAAM,MAAM,IAAI;CAChB,MAAM,MAAM,MAAM;CAClB,MAAM,MAAM,IAAI;CAChB,MAAM,MAAM,MAAM;AAClB,QAAQ,MAAM,OAAS,MAAM,MAAM,MAAM,OAAQ,OAAQ,OAAQ;;AAGnE,SAAS,SAAS,KAAiB,QAAwB;CACzD,MAAM,KAAK,IAAI,WAAW;CAC1B,MAAM,KAAK,IAAI,SAAS,MAAM;CAC9B,MAAM,KAAK,IAAI,SAAS,MAAM;CAC9B,MAAM,KAAK,IAAI,SAAS,MAAM;AAC9B,SAAQ,KAAM,MAAM,IAAM,MAAM,KAAO,MAAM,QAAS;;AAGxD,SAAS,MAAM,OAAmB,MAAsB;CACtD,MAAM,MAAM,MAAM;CAClB,IAAIA;CACJ,IAAI,IAAI;AAER,KAAI,OAAO,IAAI;EACb,IAAI,KAAM,OAAO,YAAY,cAAe;EAC5C,IAAI,KAAM,OAAO,cAAe;EAChC,IAAI,KAAK,SAAS;EAClB,IAAI,KAAM,OAAO,cAAe;AAEhC,SAAO,IAAI,MAAM,KAAK;AACpB,QAAK,MAAM,OAAQ,KAAK,MAAM,SAAS,OAAO,EAAE,EAAE,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AACpF,QAAK;AACL,QAAK,MAAM,OAAQ,KAAK,MAAM,SAAS,OAAO,EAAE,EAAE,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AACpF,QAAK;AACL,QAAK,MAAM,OAAQ,KAAK,MAAM,SAAS,OAAO,EAAE,EAAE,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AACpF,QAAK;AACL,QAAK,MAAM,OAAQ,KAAK,MAAM,SAAS,OAAO,EAAE,EAAE,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AACpF,QAAK;;AAGP,QAAO,OAAO,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,GAAG,OAAO,IAAI,GAAG,GAAG,OAAO,IAAI,GAAG,KAAM;OAE5E,OAAO,OAAO,cAAe;AAG/B,OAAO,MAAM,QAAS;AAEtB,QAAO,IAAI,KAAK,KAAK;AACnB,QAAM,MAAM,OAAQ,MAAM,MAAM,SAAS,OAAO,EAAE,EAAE,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AACtF,OAAK;;AAGP,QAAO,IAAI,KAAK;EACd,MAAM,OAAO,MAAM,MAAM;AACzB,QAAM,MAAM,OAAQ,MAAM,MAAM,SAAS,GAAG,UAAU,KAAM,GAAG,GAAG,EAAE,UAAU;AAC9E;;AAGF,OAAM,MAAM,MAAO,QAAQ,IAAK,UAAU;AAC1C,OAAM,MAAM,MAAO,QAAQ,IAAK,UAAU;AAC1C,QAAO,MAAO,QAAQ,QAAS;AAE/B,QAAO"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ValidationResult, ZodLikeError, ZodLikeSafeParseResult, ZodLikeSchema, validate, validateOrThrow } from "./validation.js";
|
|
2
|
+
import { assertNever } from "./assert-never.js";
|
|
3
|
+
import { AsyncContext, createAsyncContext } from "./async-context.js";
|
|
4
|
+
import { md5, xxhash } from "./hash.js";
|
|
5
|
+
import { collect, filter, mapStream, merge, take, takeWhile, withSignal } from "./streams.js";
|
|
6
|
+
export { type AsyncContext, type ValidationResult, type ZodLikeError, type ZodLikeSafeParseResult, type ZodLikeSchema, assertNever, collect, createAsyncContext, filter, mapStream, md5, merge, take, takeWhile, validate, validateOrThrow, withSignal, xxhash };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { assertNever } from "./assert-never.js";
|
|
2
|
+
import { createAsyncContext } from "./async-context.js";
|
|
3
|
+
import { md5, xxhash } from "./hash.js";
|
|
4
|
+
import { collect, filter, mapStream, merge, take, takeWhile, withSignal } from "./streams.js";
|
|
5
|
+
import { validate, validateOrThrow } from "./validation.js";
|
|
6
|
+
|
|
7
|
+
export { assertNever, collect, createAsyncContext, filter, mapStream, md5, merge, take, takeWhile, validate, validateOrThrow, withSignal, xxhash };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/utils/streams.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Stream / async-iterable helpers. All helpers honor `AbortSignal`
|
|
4
|
+
* propagation: when the supplied signal aborts, the underlying
|
|
5
|
+
* iterator's `return()` method is invoked so that resources held by the
|
|
6
|
+
* upstream generator are released cleanly.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Drain an `AsyncIterable` into an array.
|
|
12
|
+
*
|
|
13
|
+
* @stable
|
|
14
|
+
*/
|
|
15
|
+
declare function collect<T>(source: AsyncIterable<T>, signal?: AbortSignal): Promise<T[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Map every value of an async iterable. The mapper may be async.
|
|
18
|
+
* Cancellation via `signal` is honored.
|
|
19
|
+
*
|
|
20
|
+
* @stable
|
|
21
|
+
*/
|
|
22
|
+
declare function mapStream<T, U>(source: AsyncIterable<T>, fn: (value: T, index: number) => U | Promise<U>, signal?: AbortSignal): AsyncIterable<U>;
|
|
23
|
+
/**
|
|
24
|
+
* Filter values produced by `source`. The predicate may be async.
|
|
25
|
+
*
|
|
26
|
+
* @stable
|
|
27
|
+
*/
|
|
28
|
+
declare function filter<T>(source: AsyncIterable<T>, pred: (value: T, index: number) => boolean | Promise<boolean>, signal?: AbortSignal): AsyncIterable<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Take the first `n` items.
|
|
31
|
+
*
|
|
32
|
+
* @stable
|
|
33
|
+
*/
|
|
34
|
+
declare function take<T>(source: AsyncIterable<T>, n: number, signal?: AbortSignal): AsyncIterable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Take items as long as `pred` returns truthy. The first item for which
|
|
37
|
+
* `pred` returns falsy ends the stream.
|
|
38
|
+
*
|
|
39
|
+
* @stable
|
|
40
|
+
*/
|
|
41
|
+
declare function takeWhile<T>(source: AsyncIterable<T>, pred: (value: T, index: number) => boolean | Promise<boolean>, signal?: AbortSignal): AsyncIterable<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Merge multiple async iterables into a single output iterable. Items
|
|
44
|
+
* are yielded in the order they arrive (interleaved), not in source
|
|
45
|
+
* order. Cancellation propagates to every upstream iterator.
|
|
46
|
+
*
|
|
47
|
+
* @stable
|
|
48
|
+
*/
|
|
49
|
+
declare function merge<T>(sources: ReadonlyArray<AsyncIterable<T>>, signal?: AbortSignal): AsyncIterable<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Wrap `source` with abort-signal propagation: when `signal` aborts the
|
|
52
|
+
* underlying iterator's `return()` is called and the loop exits cleanly.
|
|
53
|
+
*
|
|
54
|
+
* @stable
|
|
55
|
+
*/
|
|
56
|
+
declare function withSignal<T>(source: AsyncIterable<T>, signal?: AbortSignal): AsyncIterable<T>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { collect, filter, mapStream, merge, take, takeWhile, withSignal };
|
|
59
|
+
//# sourceMappingURL=streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.d.ts","names":[],"sources":["../../src/utils/streams.ts"],"sourcesContent":[],"mappings":";;AAwBA;;;;;;;AAcA;;;;;AAE+C,iBAhBzB,OAgByB,CAAA,CAAA,CAAA,CAAA,MAAA,EAhBN,aAgBM,CAhBQ,CAgBR,CAAA,EAAA,MAAA,CAAA,EAhBqB,WAgBrB,CAAA,EAhBmC,OAgBnC,CAhB2C,CAgB3C,EAAA,CAAA;;;;;;AAc/C;AACwB,iBAjBD,SAiBC,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,MAAA,EAhBd,aAgBc,CAhBA,CAgBA,CAAA,EAAA,EAAA,EAAA,CAAA,KAAA,EAfV,CAeU,EAAA,KAAA,EAAA,MAAA,EAAA,GAfW,CAeX,GAfe,OAef,CAfuB,CAevB,CAAA,EAAA,MAAA,CAAA,EAdb,WAca,CAAA,EAbrB,aAaqB,CAbP,CAaO,CAAA;;;;;;AAGrB,iBAJoB,MAIpB,CAAA,CAAA,CAAA,CAAA,MAAA,EAHO,aAGP,CAHqB,CAGrB,CAAA,EAAA,IAAA,EAAA,CAAA,KAAA,EAFa,CAEb,EAAA,KAAA,EAAA,MAAA,EAAA,GAAA,OAAA,GAF4C,OAE5C,CAAA,OAAA,CAAA,EAAA,MAAA,CAAA,EADQ,WACR,CAAA,EAAA,aAAA,CAAc,CAAd,CAAA;;AAYH;;;;AAIiB,iBAJM,IAIN,CAAA,CAAA,CAAA,CAAA,MAAA,EAHP,aAGO,CAHO,CAGP,CAAA,EAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EADN,WACM,CAAA,EAAd,aAAc,CAAA,CAAA,CAAA;;;AAejB;;;;AAE+C,iBAFxB,SAEwB,CAAA,CAAA,CAAA,CAAA,MAAA,EADrC,aACqC,CADvB,CACuB,CAAA,EAAA,IAAA,EAAA,CAAA,KAAA,EAA/B,CAA+B,EAAA,KAAA,EAAA,MAAA,EAAA,GAAA,OAAA,GAAA,OAAA,CAAA,OAAA,CAAA,EAAA,MAAA,CAAA,EACpC,WADoC,CAAA,EAE5C,aAF4C,CAE9B,CAF8B,CAAA;;;;;AAiB/C;;;AACW,iBADY,KACZ,CAAA,CAAA,CAAA,CAAA,OAAA,EAAA,aAAA,CAAc,aAAd,CAA4B,CAA5B,CAAA,CAAA,EAAA,MAAA,CAAA,EACA,WADA,CAAA,EAER,aAFQ,CAEM,CAFN,CAAA;;;;;AAiFX;;AACU,iBADa,UACb,CAAA,CAAA,CAAA,CAAA,MAAA,EAAA,aAAA,CAAc,CAAd,CAAA,EAAA,MAAA,CAAA,EACC,WADD,CAAA,EAEP,aAFO,CAEO,CAFP,CAAA"}
|