@openwop/openwop 1.1.0 → 1.1.2
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/README.md +4 -0
- package/dist/client.d.ts +80 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +186 -0
- package/dist/client.js.map +1 -1
- package/dist/cost-attribution.d.ts +49 -0
- package/dist/cost-attribution.d.ts.map +1 -0
- package/dist/cost-attribution.js +65 -0
- package/dist/cost-attribution.js.map +1 -0
- package/dist/event-helpers.d.ts +95 -0
- package/dist/event-helpers.d.ts.map +1 -0
- package/dist/event-helpers.js +160 -0
- package/dist/event-helpers.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/registry-helpers.d.ts +118 -0
- package/dist/registry-helpers.d.ts.map +1 -0
- package/dist/registry-helpers.js +82 -0
- package/dist/registry-helpers.js.map +1 -0
- package/dist/types.d.ts +376 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/webhook-helpers.d.ts +73 -0
- package/dist/webhook-helpers.d.ts.map +1 -0
- package/dist/webhook-helpers.js +97 -0
- package/dist/webhook-helpers.js.map +1 -0
- package/package.json +1 -1
- package/src/client.ts +218 -0
- package/src/cost-attribution.ts +72 -0
- package/src/event-helpers.ts +238 -0
- package/src/index.ts +96 -0
- package/src/registry-helpers.ts +173 -0
- package/src/types.ts +424 -0
- package/src/webhook-helpers.ts +131 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed helpers for the `agent.*` event family (RFC 0002 §B + RFC 0024).
|
|
3
|
+
*
|
|
4
|
+
* Two layers:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Type guards** (`isAgentReasoned`, `isAgentReasoningDelta`, etc.)
|
|
7
|
+
* — discriminator-based predicates that narrow `RunEventDoc` to a
|
|
8
|
+
* `TypedRunEvent<TPayload>` inside the guarded branch. Use these
|
|
9
|
+
* when you're iterating events yourself (e.g., inside a
|
|
10
|
+
* `for await (const ev of streamEvents(...))` loop) and want
|
|
11
|
+
* compile-time-narrowed access to the payload.
|
|
12
|
+
*
|
|
13
|
+
* 2. **High-level subscription helper** (`subscribeToAgentReasoning`)
|
|
14
|
+
* — fan-outs the `streamEvents()` generator into typed callbacks
|
|
15
|
+
* (`onDelta`, `onClosed`). Composes with the existing
|
|
16
|
+
* `streamEvents` SSE consumer; cleanup via the returned
|
|
17
|
+
* `Unsubscribe` function aborts the underlying fetch.
|
|
18
|
+
*
|
|
19
|
+
* Forward-compat: `RunEventDoc.type` is intentionally `string`-typed
|
|
20
|
+
* (not a closed union) per `COMPATIBILITY.md §2.1` — consumers MUST
|
|
21
|
+
* tolerate unknown event types. The type guards here only narrow when
|
|
22
|
+
* the discriminator AND the required payload fields are present; they
|
|
23
|
+
* return `false` for malformed or unknown events.
|
|
24
|
+
*
|
|
25
|
+
* @see schemas/run-event-payloads.schema.json
|
|
26
|
+
* @see RFCS/0002-agent-identity-and-reasoning-events.md
|
|
27
|
+
* @see RFCS/0024-agent-reasoning-streaming.md
|
|
28
|
+
*/
|
|
29
|
+
import { streamEvents } from './sse.js';
|
|
30
|
+
// ─── Type guards ────────────────────────────────────────────────────────
|
|
31
|
+
function hasStringField(payload, field) {
|
|
32
|
+
return (payload !== null &&
|
|
33
|
+
typeof payload === 'object' &&
|
|
34
|
+
typeof payload[field] === 'string');
|
|
35
|
+
}
|
|
36
|
+
/** `agent.reasoned` (RFC 0002 §B). Narrows when `type` matches AND
|
|
37
|
+
* payload carries the required `agentId` + `reasoning` strings. */
|
|
38
|
+
export function isAgentReasoned(ev) {
|
|
39
|
+
return (ev.type === 'agent.reasoned' &&
|
|
40
|
+
hasStringField(ev.payload, 'agentId') &&
|
|
41
|
+
hasStringField(ev.payload, 'reasoning'));
|
|
42
|
+
}
|
|
43
|
+
/** `agent.reasoning.delta` (RFC 0024). Narrows when `type` matches AND
|
|
44
|
+
* payload carries the required `agentId` + `delta` strings + numeric
|
|
45
|
+
* `sequence`. */
|
|
46
|
+
export function isAgentReasoningDelta(ev) {
|
|
47
|
+
if (ev.type !== 'agent.reasoning.delta')
|
|
48
|
+
return false;
|
|
49
|
+
if (!hasStringField(ev.payload, 'agentId'))
|
|
50
|
+
return false;
|
|
51
|
+
if (!hasStringField(ev.payload, 'delta'))
|
|
52
|
+
return false;
|
|
53
|
+
const seq = ev.payload.sequence;
|
|
54
|
+
return typeof seq === 'number' && Number.isInteger(seq) && seq >= 0;
|
|
55
|
+
}
|
|
56
|
+
/** `agent.toolCalled` (RFC 0002 §B). */
|
|
57
|
+
export function isAgentToolCalled(ev) {
|
|
58
|
+
return (ev.type === 'agent.toolCalled' &&
|
|
59
|
+
hasStringField(ev.payload, 'agentId') &&
|
|
60
|
+
hasStringField(ev.payload, 'toolName') &&
|
|
61
|
+
hasStringField(ev.payload, 'callId'));
|
|
62
|
+
}
|
|
63
|
+
/** `agent.toolReturned` (RFC 0002 §B). Pairs with `agent.toolCalled`
|
|
64
|
+
* via `callId`; `outcome` and `error` are mutually exclusive but the
|
|
65
|
+
* guard doesn't enforce that (callers inspect after narrowing). */
|
|
66
|
+
export function isAgentToolReturned(ev) {
|
|
67
|
+
return (ev.type === 'agent.toolReturned' &&
|
|
68
|
+
hasStringField(ev.payload, 'agentId') &&
|
|
69
|
+
hasStringField(ev.payload, 'toolName') &&
|
|
70
|
+
hasStringField(ev.payload, 'callId'));
|
|
71
|
+
}
|
|
72
|
+
/** `agent.handoff` (RFC 0002 §B). Note the distinct field names —
|
|
73
|
+
* `fromAgentId` / `toAgentId`, NOT a single `agentId`. */
|
|
74
|
+
export function isAgentHandoff(ev) {
|
|
75
|
+
return (ev.type === 'agent.handoff' &&
|
|
76
|
+
hasStringField(ev.payload, 'fromAgentId') &&
|
|
77
|
+
hasStringField(ev.payload, 'toAgentId'));
|
|
78
|
+
}
|
|
79
|
+
/** `agent.decided` (RFC 0002 §B). `decision` is `unknown` per the
|
|
80
|
+
* schema (host-specific shape); guard only validates `agentId` +
|
|
81
|
+
* the presence of a `decision` key. */
|
|
82
|
+
export function isAgentDecided(ev) {
|
|
83
|
+
return (ev.type === 'agent.decided' &&
|
|
84
|
+
hasStringField(ev.payload, 'agentId') &&
|
|
85
|
+
ev.payload !== null &&
|
|
86
|
+
typeof ev.payload === 'object' &&
|
|
87
|
+
'decision' in ev.payload);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Subscribe to the reasoning event sub-stream for a single run.
|
|
91
|
+
* Convenience wrapper over `streamEvents()` that dispatches the two
|
|
92
|
+
* RFC 0024 event types into typed callbacks.
|
|
93
|
+
*
|
|
94
|
+
* Returns immediately; the SSE consumption runs as a detached async
|
|
95
|
+
* task in the background. Call the returned `Unsubscribe` to cancel.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const stop = subscribeToAgentReasoning(ctx, runId, {
|
|
100
|
+
* onDelta: ({ delta, sequence }) => process.stdout.write(delta),
|
|
101
|
+
* onClosed: ({ reasoning }) => console.log('\nfinal:', reasoning),
|
|
102
|
+
* });
|
|
103
|
+
* // ...later
|
|
104
|
+
* stop();
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function subscribeToAgentReasoning(ctx, runId, callbacks, options = {}) {
|
|
108
|
+
const abort = new AbortController();
|
|
109
|
+
let stopped = false;
|
|
110
|
+
const stop = () => {
|
|
111
|
+
if (stopped)
|
|
112
|
+
return;
|
|
113
|
+
stopped = true;
|
|
114
|
+
abort.abort();
|
|
115
|
+
};
|
|
116
|
+
void (async () => {
|
|
117
|
+
try {
|
|
118
|
+
// streamModes default to 'updates' — agent.* events flow there
|
|
119
|
+
// per `spec/v1/stream-modes.md`.
|
|
120
|
+
const events = streamEvents(ctx, runId, {
|
|
121
|
+
...options,
|
|
122
|
+
streamMode: options.streamMode ?? 'updates',
|
|
123
|
+
signal: abort.signal,
|
|
124
|
+
});
|
|
125
|
+
for await (const ev of events) {
|
|
126
|
+
if (stopped)
|
|
127
|
+
break;
|
|
128
|
+
try {
|
|
129
|
+
if (isAgentReasoningDelta(ev)) {
|
|
130
|
+
await callbacks.onDelta?.(ev.payload, ev);
|
|
131
|
+
}
|
|
132
|
+
else if (isAgentReasoned(ev)) {
|
|
133
|
+
await callbacks.onClosed?.(ev.payload, ev);
|
|
134
|
+
}
|
|
135
|
+
// Other event types ignored — forward-compat per
|
|
136
|
+
// COMPATIBILITY.md §2.1. Consumers that want them iterate
|
|
137
|
+
// streamEvents() directly.
|
|
138
|
+
}
|
|
139
|
+
catch (handlerErr) {
|
|
140
|
+
// Handler exceptions: surface via onError but DO NOT tear
|
|
141
|
+
// down the stream. One bad handler shouldn't kill the rest.
|
|
142
|
+
callbacks.onError?.(handlerErr instanceof Error
|
|
143
|
+
? handlerErr
|
|
144
|
+
: new Error(String(handlerErr)));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!stopped)
|
|
148
|
+
callbacks.onEnd?.();
|
|
149
|
+
}
|
|
150
|
+
catch (streamErr) {
|
|
151
|
+
if (stopped)
|
|
152
|
+
return; // intentional cancellation
|
|
153
|
+
callbacks.onError?.(streamErr instanceof Error
|
|
154
|
+
? streamErr
|
|
155
|
+
: new Error(String(streamErr)));
|
|
156
|
+
}
|
|
157
|
+
})();
|
|
158
|
+
return stop;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=event-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-helpers.js","sourceRoot":"","sources":["../src/event-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,YAAY,EAAsD,MAAM,UAAU,CAAC;AAY5F,2EAA2E;AAE3E,SAAS,cAAc,CACrB,OAAgB,EAChB,KAAa;IAEb,OAAO,CACL,OAAO,KAAK,IAAI;QAChB,OAAO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9 +12,18 @@
|
|
|
12
12
|
export { OpenwopClient } from './client.js';
|
|
13
13
|
export type { OpenwopClientOptions, MutationOptions } from './client.js';
|
|
14
14
|
export { WopError } from './types.js';
|
|
15
|
-
export type { AuditVerifyAnomaly, AuditVerifyCheckpoint, AuditVerifyResult, BulkCancelRunResult, BulkCancelRunsRequest, BulkCancelRunsResponse, Capabilities, CancelRunRequest, CancelRunResponse, CreateRunRequest, CreateRunResponse, ErrorEnvelope, ForkRunRequest, ForkRunResponse, InterruptByTokenInspection, PollEventsResponse, ResolveInterruptByTokenResponse, ResolveInterruptRequest, ResolveInterruptResponse, RunConfigurable, RunEventDoc, RunSnapshot, RunStatus, StreamMode, } from './types.js';
|
|
15
|
+
export type { AuditVerifyAnomaly, AuditVerifyCheckpoint, AuditVerifyResult, BulkCancelRunResult, BulkCancelRunsRequest, BulkCancelRunsResponse, Capabilities, CancelRunRequest, CancelRunResponse, CreateRunRequest, CreateRunResponse, ErrorEnvelope, ForkRunRequest, ForkRunResponse, DebugBundle, DebugBundleOptions, RegisterWebhookRequest, RegisterWebhookResponse, InterruptByTokenInspection, PauseRunRequest, PauseRunResponse, PollEventsResponse, ResolveInterruptByTokenResponse, ResolveInterruptRequest, ResolveInterruptResponse, ResumeRunRequest, ResumeRunResponse, RunConfigurable, RunEventDoc, RunSnapshot, RunStatus, StreamMode, TypedRunEvent, AgentReasonedPayload, AgentReasoningDeltaPayload, AgentToolCalledPayload, AgentToolReturnedPayload, AgentHandoffPayload, AgentDecidedPayload, GetPromptRequest, ListPromptsRequest, ListPromptsResponse, PromptKind, PromptRef, PromptTemplate, PromptVariable, RenderPromptRequest, RenderPromptResponse, } from './types.js';
|
|
16
16
|
export { streamEvents } from './sse.js';
|
|
17
17
|
export type { EventsStreamContext, EventsStreamOptions } from './sse.js';
|
|
18
|
+
export { isAgentReasoned, isAgentReasoningDelta, isAgentToolCalled, isAgentToolReturned, isAgentHandoff, isAgentDecided, subscribeToAgentReasoning, } from './event-helpers.js';
|
|
19
|
+
export type { AgentReasoningCallbacks, Unsubscribe, } from './event-helpers.js';
|
|
18
20
|
export { ACTIVE_RUN_STATUSES, TERMINAL_RUN_STATUSES, isTerminalRunStatus, HTTP_ERROR_CODES, isHttpErrorCode, RUN_ERROR_CODES, isRunErrorCode, } from './run-helpers.js';
|
|
19
21
|
export type { ActiveRunStatus, TerminalRunStatus, HttpErrorCode, RunErrorCode, RunError, } from './run-helpers.js';
|
|
22
|
+
export { OPENWOP_COST_ATTRIBUTE_NAMES, sanitizeCostAttributes, } from './cost-attribution.js';
|
|
23
|
+
export type { OpenwopCostAttributeName } from './cost-attribution.js';
|
|
24
|
+
export { DEFAULT_WEBHOOK_FRESHNESS_WINDOW_SECONDS, verifyWebhookSignature, signWebhookDelivery, } from './webhook-helpers.js';
|
|
25
|
+
export type { VerifyWebhookSignatureOptions, VerifyWebhookOutcome, } from './webhook-helpers.js';
|
|
26
|
+
export { RegistryClient } from './registry-helpers.js';
|
|
27
|
+
export type { RegistryClientOptions, RegistryDiscovery, RegistryIndex, RegistryIndexEntry, RegistryPackMetadata, RegistryVersionManifest, } from './registry-helpers.js';
|
|
28
|
+
export type { AIEnvelope, AIEnvelopeErrorPayload, ClarificationRequestPayload, EnvelopeContract, EnvelopeContractRefusal, EnvelopeContractsCapability, EnvelopeMeta, EnvelopeOutcome, EnvelopeStrictness, PartialInfo, SchemaRequestPayload, SchemaResponsePayload, ValidationDetail, } from './types.js';
|
|
20
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EACf,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EAEnB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,oBA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/index.js
CHANGED
|
@@ -12,8 +12,25 @@
|
|
|
12
12
|
export { OpenwopClient } from './client.js';
|
|
13
13
|
export { WopError } from './types.js';
|
|
14
14
|
export { streamEvents } from './sse.js';
|
|
15
|
+
// RFC 0002 + RFC 0024 typed event helpers — type guards over `RunEventDoc`
|
|
16
|
+
// plus a high-level streaming-reasoning subscription helper.
|
|
17
|
+
export { isAgentReasoned, isAgentReasoningDelta, isAgentToolCalled, isAgentToolReturned, isAgentHandoff, isAgentDecided, subscribeToAgentReasoning, } from './event-helpers.js';
|
|
15
18
|
// Run-status + run-error helpers (added in 1). Forward-compat predicates
|
|
16
19
|
// over the wire-format unions declared above; full design + rationale in
|
|
17
20
|
// `run-helpers.ts`.
|
|
18
21
|
export { ACTIVE_RUN_STATUSES, TERMINAL_RUN_STATUSES, isTerminalRunStatus, HTTP_ERROR_CODES, isHttpErrorCode, RUN_ERROR_CODES, isRunErrorCode, } from './run-helpers.js';
|
|
22
|
+
// Cost-attribution allowlist + sanitizer helpers
|
|
23
|
+
// (`spec/v1/observability.md §"Cost attribution attributes"`). Single
|
|
24
|
+
// source of truth for the canonical attribute names so independent
|
|
25
|
+
// hosts share one list instead of each re-deriving it.
|
|
26
|
+
export { OPENWOP_COST_ATTRIBUTE_NAMES, sanitizeCostAttributes, } from './cost-attribution.js';
|
|
27
|
+
// Webhook-delivery verification helpers (SDK-3 close-out 2026-05-15).
|
|
28
|
+
// HMAC-SHA256 + timestamp freshness window verification per
|
|
29
|
+
// spec/v1/webhooks.md §"Signature recipe". Receivers MUST verify both
|
|
30
|
+
// the HMAC AND the timestamp to defeat replay attacks.
|
|
31
|
+
export { DEFAULT_WEBHOOK_FRESHNESS_WINDOW_SECONDS, verifyWebhookSignature, signWebhookDelivery, } from './webhook-helpers.js';
|
|
32
|
+
// Public-registry read helpers (SDK-5 close-out 2026-05-15). Read-only
|
|
33
|
+
// typed client for the public node-pack registry at packs.openwop.dev
|
|
34
|
+
// per spec/v1/registry-operations.md.
|
|
35
|
+
export { RegistryClient } from './registry-helpers.js';
|
|
19
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAoDtC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,2EAA2E;AAC3E,6DAA6D;AAC7D,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAM5B,yEAAyE;AACzE,yEAAyE;AACzE,oBAAoB;AACpB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,GACf,MAAM,kBAAkB,CAAC;AAS1B,iDAAiD;AACjD,sEAAsE;AACtE,mEAAmE;AACnE,uDAAuD;AACvD,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,sEAAsE;AACtE,4DAA4D;AAC5D,sEAAsE;AACtE,uDAAuD;AACvD,OAAO,EACL,wCAAwC,EACxC,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAM9B,uEAAuE;AACvE,sEAAsE;AACtE,sCAAsC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public-registry read helpers per
|
|
3
|
+
* `spec/v1/registry-operations.md`.
|
|
4
|
+
*
|
|
5
|
+
* The OpenWOP host SDK targets the host wire surface
|
|
6
|
+
* (`/.well-known/openwop` + `/v1/runs/*` + `/v1/interrupts/*` etc).
|
|
7
|
+
* The **public node-pack registry** at `packs.openwop.dev` is a
|
|
8
|
+
* separate wire surface with its own discovery payload and pack-
|
|
9
|
+
* versioned read endpoints. This module exposes a thin typed client
|
|
10
|
+
* for that surface so adopters fetching pack manifests, indices, or
|
|
11
|
+
* signature material don't roll their own HTTP plumbing.
|
|
12
|
+
*
|
|
13
|
+
* Read-only by design — the public registry uses pull-request-driven
|
|
14
|
+
* publishing per `spec/v1/registry-operations.md` §"Submission flow"
|
|
15
|
+
* + the `registry-publish.yml` GitHub workflow. There is no write API.
|
|
16
|
+
*
|
|
17
|
+
* No auth required for public reads.
|
|
18
|
+
*
|
|
19
|
+
* @module @openwop/openwop/registry-helpers
|
|
20
|
+
*/
|
|
21
|
+
/** Public registry discovery payload per `registry-operations.md` §"Discovery". */
|
|
22
|
+
export interface RegistryDiscovery {
|
|
23
|
+
registryVersion: string;
|
|
24
|
+
protocolVersion: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
operator?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
supportedNamespaces: readonly string[];
|
|
29
|
+
supportedSigningMethods: readonly string[];
|
|
30
|
+
supportedTrustModes?: readonly string[];
|
|
31
|
+
endpoints: {
|
|
32
|
+
registryIndex: string;
|
|
33
|
+
packMetadata: string;
|
|
34
|
+
versionManifest: string;
|
|
35
|
+
versionTarball: string;
|
|
36
|
+
versionSignature: string;
|
|
37
|
+
publicKey: string;
|
|
38
|
+
};
|
|
39
|
+
signingKeys?: ReadonlyArray<{
|
|
40
|
+
keyId: string;
|
|
41
|
+
algorithm: string;
|
|
42
|
+
publicKeyUrl?: string;
|
|
43
|
+
permittedNamespaces?: readonly string[];
|
|
44
|
+
operator?: string;
|
|
45
|
+
status?: string;
|
|
46
|
+
}>;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** Registry-wide index entry per `/v1/index.json` rows. */
|
|
50
|
+
export interface RegistryIndexEntry {
|
|
51
|
+
name: string;
|
|
52
|
+
latestVersion: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
scope?: string;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface RegistryIndex {
|
|
58
|
+
packs: ReadonlyArray<RegistryIndexEntry>;
|
|
59
|
+
generated?: string;
|
|
60
|
+
packCount?: number;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/** Per-pack metadata document at `/v1/packs/{name}/index.json`. */
|
|
64
|
+
export interface RegistryPackMetadata {
|
|
65
|
+
name: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
versions: ReadonlyArray<string>;
|
|
68
|
+
latestVersion?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
/** Version manifest at `/v1/packs/{name}/-/{version}.json`. */
|
|
72
|
+
export interface RegistryVersionManifest {
|
|
73
|
+
name: string;
|
|
74
|
+
version: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
/** SRI hash: `sha256-<43-char-b64>=`. */
|
|
77
|
+
integrity?: string;
|
|
78
|
+
signing?: {
|
|
79
|
+
method: 'ed25519' | 'manual' | string;
|
|
80
|
+
keyId: string;
|
|
81
|
+
publicKeyUrl?: string;
|
|
82
|
+
};
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface RegistryClientOptions {
|
|
86
|
+
/** Base URL for the registry. Defaults to `https://packs.openwop.dev`. */
|
|
87
|
+
baseUrl?: string;
|
|
88
|
+
/** Custom fetch implementation; defaults to `globalThis.fetch`. */
|
|
89
|
+
fetch?: typeof fetch;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Typed client for the public OpenWOP node-pack registry. Read-only;
|
|
93
|
+
* no auth required for the canonical public read surface.
|
|
94
|
+
*
|
|
95
|
+
* For host-side install-time verification (SRI + Ed25519 + lockfile),
|
|
96
|
+
* see `examples/hosts/postgres/src/pack-consumer.ts` — the registry
|
|
97
|
+
* client is the fetch surface; the consumer is the security surface.
|
|
98
|
+
*/
|
|
99
|
+
export declare class RegistryClient {
|
|
100
|
+
#private;
|
|
101
|
+
readonly baseUrl: string;
|
|
102
|
+
constructor(options?: RegistryClientOptions);
|
|
103
|
+
/** `GET /.well-known/openwop-registry` — discovery + endpoint catalog. */
|
|
104
|
+
discovery(): Promise<RegistryDiscovery>;
|
|
105
|
+
/** `GET /v1/index.json` — registry-wide pack index. */
|
|
106
|
+
index(): Promise<RegistryIndex>;
|
|
107
|
+
/** `GET /v1/packs/{name}/index.json` — per-pack metadata. */
|
|
108
|
+
pack(name: string): Promise<RegistryPackMetadata>;
|
|
109
|
+
/** `GET /v1/packs/{name}/-/{version}.json` — version manifest. */
|
|
110
|
+
version(name: string, version: string): Promise<RegistryVersionManifest>;
|
|
111
|
+
/** Fetch raw tarball bytes. Caller MUST verify SRI + signature before trust. */
|
|
112
|
+
tarball(name: string, version: string): Promise<Buffer>;
|
|
113
|
+
/** Fetch raw 64-byte Ed25519 signature bytes. */
|
|
114
|
+
signature(name: string, version: string): Promise<Buffer>;
|
|
115
|
+
/** Fetch a publisher's public key as PEM text. */
|
|
116
|
+
publicKey(keyId: string): Promise<string>;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=registry-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-helpers.d.ts","sourceRoot":"","sources":["../src/registry-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MA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E,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM7D,iDAAiD;IAC3C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM/D,kDAAkD;IAC5C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAmBhD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public-registry read helpers per
|
|
3
|
+
* `spec/v1/registry-operations.md`.
|
|
4
|
+
*
|
|
5
|
+
* The OpenWOP host SDK targets the host wire surface
|
|
6
|
+
* (`/.well-known/openwop` + `/v1/runs/*` + `/v1/interrupts/*` etc).
|
|
7
|
+
* The **public node-pack registry** at `packs.openwop.dev` is a
|
|
8
|
+
* separate wire surface with its own discovery payload and pack-
|
|
9
|
+
* versioned read endpoints. This module exposes a thin typed client
|
|
10
|
+
* for that surface so adopters fetching pack manifests, indices, or
|
|
11
|
+
* signature material don't roll their own HTTP plumbing.
|
|
12
|
+
*
|
|
13
|
+
* Read-only by design — the public registry uses pull-request-driven
|
|
14
|
+
* publishing per `spec/v1/registry-operations.md` §"Submission flow"
|
|
15
|
+
* + the `registry-publish.yml` GitHub workflow. There is no write API.
|
|
16
|
+
*
|
|
17
|
+
* No auth required for public reads.
|
|
18
|
+
*
|
|
19
|
+
* @module @openwop/openwop/registry-helpers
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Typed client for the public OpenWOP node-pack registry. Read-only;
|
|
23
|
+
* no auth required for the canonical public read surface.
|
|
24
|
+
*
|
|
25
|
+
* For host-side install-time verification (SRI + Ed25519 + lockfile),
|
|
26
|
+
* see `examples/hosts/postgres/src/pack-consumer.ts` — the registry
|
|
27
|
+
* client is the fetch surface; the consumer is the security surface.
|
|
28
|
+
*/
|
|
29
|
+
export class RegistryClient {
|
|
30
|
+
baseUrl;
|
|
31
|
+
#fetch;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
this.baseUrl = (options.baseUrl ?? 'https://packs.openwop.dev').replace(/\/$/, '');
|
|
34
|
+
this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
35
|
+
}
|
|
36
|
+
/** `GET /.well-known/openwop-registry` — discovery + endpoint catalog. */
|
|
37
|
+
async discovery() {
|
|
38
|
+
return this.#getJson('/.well-known/openwop-registry');
|
|
39
|
+
}
|
|
40
|
+
/** `GET /v1/index.json` — registry-wide pack index. */
|
|
41
|
+
async index() {
|
|
42
|
+
return this.#getJson('/v1/index.json');
|
|
43
|
+
}
|
|
44
|
+
/** `GET /v1/packs/{name}/index.json` — per-pack metadata. */
|
|
45
|
+
async pack(name) {
|
|
46
|
+
return this.#getJson(`/v1/packs/${encodeURIComponent(name)}/index.json`);
|
|
47
|
+
}
|
|
48
|
+
/** `GET /v1/packs/{name}/-/{version}.json` — version manifest. */
|
|
49
|
+
async version(name, version) {
|
|
50
|
+
return this.#getJson(`/v1/packs/${encodeURIComponent(name)}/-/${encodeURIComponent(version)}.json`);
|
|
51
|
+
}
|
|
52
|
+
/** Fetch raw tarball bytes. Caller MUST verify SRI + signature before trust. */
|
|
53
|
+
async tarball(name, version) {
|
|
54
|
+
return this.#getBinary(`/v1/packs/${encodeURIComponent(name)}/-/${encodeURIComponent(version)}.tgz`);
|
|
55
|
+
}
|
|
56
|
+
/** Fetch raw 64-byte Ed25519 signature bytes. */
|
|
57
|
+
async signature(name, version) {
|
|
58
|
+
return this.#getBinary(`/v1/packs/${encodeURIComponent(name)}/-/${encodeURIComponent(version)}.sig`);
|
|
59
|
+
}
|
|
60
|
+
/** Fetch a publisher's public key as PEM text. */
|
|
61
|
+
async publicKey(keyId) {
|
|
62
|
+
const res = await this.#fetch(`${this.baseUrl}/keys/${encodeURIComponent(keyId)}.pub`);
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
throw new Error(`registry: GET /keys/${keyId}.pub returned ${res.status}`);
|
|
65
|
+
return res.text();
|
|
66
|
+
}
|
|
67
|
+
async #getJson(path) {
|
|
68
|
+
const res = await this.#fetch(`${this.baseUrl}${path}`, {
|
|
69
|
+
headers: { Accept: 'application/json' },
|
|
70
|
+
});
|
|
71
|
+
if (!res.ok)
|
|
72
|
+
throw new Error(`registry: GET ${path} returned ${res.status}`);
|
|
73
|
+
return (await res.json());
|
|
74
|
+
}
|
|
75
|
+
async #getBinary(path) {
|
|
76
|
+
const res = await this.#fetch(`${this.baseUrl}${path}`);
|
|
77
|
+
if (!res.ok)
|
|
78
|
+
throw new Error(`registry: GET ${path} returned ${res.status}`);
|
|
79
|
+
return Buffer.from(await res.arrayBuffer());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=registry-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-helpers.js","sourceRoot":"","sources":["../src/registry-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA8EH;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IAChB,OAAO,CAAS;IAChB,MAAM,CAAe;IAE9B,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnE,CAAC;IAED,0EAA0E;IAC1E,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,QAAQ,CAAoB,+BAA+B,CAAC,CAAC;IAC3E,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,QAAQ,CAAgB,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAA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