@openwop/openwop 1.8.0 → 2.0.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.
Files changed (60) hide show
  1. package/README.md +64 -117
  2. package/dist/client.d.ts +131 -245
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +233 -440
  5. package/dist/client.js.map +1 -1
  6. package/dist/cost-attribution.d.ts +2 -2
  7. package/dist/cost-attribution.js +2 -2
  8. package/dist/envelope-directive.d.ts +1 -1
  9. package/dist/envelope-directive.js +1 -1
  10. package/dist/event-helpers.js +1 -1
  11. package/dist/event-helpers.js.map +1 -1
  12. package/dist/generated.d.ts +17 -0
  13. package/dist/generated.d.ts.map +1 -0
  14. package/dist/generated.js +311 -0
  15. package/dist/generated.js.map +1 -0
  16. package/dist/index.d.ts +16 -16
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +26 -53
  19. package/dist/index.js.map +1 -1
  20. package/dist/run-helpers.d.ts +20 -21
  21. package/dist/run-helpers.d.ts.map +1 -1
  22. package/dist/run-helpers.js +23 -72
  23. package/dist/run-helpers.js.map +1 -1
  24. package/dist/sse.d.ts +33 -15
  25. package/dist/sse.d.ts.map +1 -1
  26. package/dist/sse.js +28 -30
  27. package/dist/sse.js.map +1 -1
  28. package/dist/types.d.ts +253 -559
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/types.js.map +1 -1
  31. package/dist/webhook-header-families.d.ts +42 -0
  32. package/dist/webhook-header-families.d.ts.map +1 -0
  33. package/dist/webhook-header-families.js +58 -0
  34. package/dist/webhook-header-families.js.map +1 -0
  35. package/dist/webhook-helpers.browser.d.ts +15 -28
  36. package/dist/webhook-helpers.browser.d.ts.map +1 -1
  37. package/dist/webhook-helpers.browser.js +16 -27
  38. package/dist/webhook-helpers.browser.js.map +1 -1
  39. package/dist/webhook-helpers.d.ts +48 -32
  40. package/dist/webhook-helpers.d.ts.map +1 -1
  41. package/dist/webhook-helpers.js +52 -37
  42. package/dist/webhook-helpers.js.map +1 -1
  43. package/package.json +6 -4
  44. package/src/client.ts +255 -454
  45. package/src/cost-attribution.ts +2 -2
  46. package/src/envelope-directive.ts +1 -1
  47. package/src/event-helpers.ts +1 -1
  48. package/src/generated.ts +322 -0
  49. package/src/index.ts +78 -105
  50. package/src/run-helpers.ts +27 -85
  51. package/src/sse.ts +63 -42
  52. package/src/types.ts +268 -603
  53. package/src/webhook-header-families.ts +78 -0
  54. package/src/webhook-helpers.browser.ts +24 -28
  55. package/src/webhook-helpers.ts +87 -39
  56. package/dist/registry-helpers.d.ts +0 -118
  57. package/dist/registry-helpers.d.ts.map +0 -1
  58. package/dist/registry-helpers.js +0 -82
  59. package/dist/registry-helpers.js.map +0 -1
  60. package/src/registry-helpers.ts +0 -173
package/dist/index.js CHANGED
@@ -1,65 +1,38 @@
1
1
  /**
2
- * @openwop/openwop — TypeScript reference SDK for OpenWOP-compliant servers.
2
+ * @openwop/openwop 2.x — TypeScript reference SDK for OpenWOP v2 hosts.
3
3
  *
4
4
  * Public surface:
5
- * - OpenwopClient (auth + endpoint methods)
6
- * - WopError (typed error wrapping ErrorEnvelope)
7
- * - All request/response types mirroring the OpenAPI spec
8
- * - streamEvents helper for advanced SSE use cases
5
+ * - OpenwopClient (auth + one method per `spec/v2/path-manifest.json` operation)
6
+ * - WopError (typed error wrapping the v2 ErrorEnvelope)
7
+ * - Generated ERROR_CODES / ErrorCode + capability-key unions (`generated.ts`)
8
+ * - All request/response types mirroring `api/v2/openapi.yaml` + `schemas/v2/`
9
+ * - streamEvents / streamHostEvents SSE helpers
9
10
  *
10
11
  * See README.md for usage examples.
11
12
  */
12
- export { OpenwopClient } from './client.js';
13
+ export { OpenwopClient, SDK_PROTOCOL_MAJOR, protocolVersionHeader } from './client.js';
13
14
  export { WopError } from './types.js';
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.
15
+ export { streamEvents, streamHostEvents } from './sse.js';
16
+ // Generated from spec/v2/errors.json + schemas/v2/capabilities.schema.json.
17
+ export { ERROR_CODES, ERROR_CODE_HTTP_STATUS, RETRIABLE_ERROR_CODES, VENDOR_ERROR_CODE_PATTERN, CAPABILITY_FAMILY_KEYS, CAPABILITY_METADATA_KEYS, } from './generated.js';
18
+ // Typed event helpers — type guards over `RunEventDoc` plus a high-level
19
+ // streaming-reasoning subscription helper.
17
20
  export { isAgentReasoned, isAgentReasoningDelta, isAgentToolCalled, isAgentToolReturned, isAgentHandoff, isAgentDecided, isMemoryWritten, isOutputChunk, isVoiceSpeechStart, isVoiceTranscript, isVoiceEndpointCandidate, isVoiceTurnCommit, isVoiceSynthesisChunk, isVoiceBargeIn, isVoiceCancelled, isChannelPresence, isDispatchFanOut, isDispatchJoin, isContextSummarized, subscribeToAgentReasoning, } from './event-helpers.js';
18
- // Run-status + run-error helpers (added in 1). Forward-compat predicates
19
- // over the wire-format unions declared above; full design + rationale in
20
- // `run-helpers.ts`.
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.
21
+ // Run-status + error-code helpers. `HTTP_ERROR_CODES` is the generated
22
+ // registry; `isErrorCode` narrows to it, `isRetriableErrorCode` to the
23
+ // `retriable: true` rows.
24
+ export { ACTIVE_RUN_STATUSES, TERMINAL_RUN_STATUSES, isTerminalRunStatus, HTTP_ERROR_CODES, isHttpErrorCode, isErrorCode, isRetriableErrorCode, isVendorErrorCode, RUN_ERROR_CODES, isRunErrorCode, } from './run-helpers.js';
25
+ // Cost-attribution allowlist + sanitizer helpers.
26
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
- //
32
- // DEPRECATED ON THE BARREL (openwop-sdks#30). These re-exports are why a
33
- // browser consumer importing anything at all from `@openwop/openwop` dragged
34
- // in `node:crypto` and failed the build. Import them from
35
- // `@openwop/openwop/webhooks` instead; the barrel re-export is retained for
36
- // compatibility and will be removed in the next major.
37
- //
38
- // Until then the `browser` field in package.json substitutes a stub that
39
- // throws with an explanatory message, so a browser build succeeds and only a
40
- // browser CALL fails — which is the correct outcome either way, since the
41
- // subscription secret must never reach a browser.
42
- /** @deprecated Import from `@openwop/openwop/webhooks` — server-only; removed from the barrel in the next major. */
43
- export { DEFAULT_WEBHOOK_FRESHNESS_WINDOW_SECONDS, verifyWebhookSignature, signWebhookDelivery, } from './webhook-helpers.js';
44
- // Public-registry read helpers (SDK-5 close-out 2026-05-15). Read-only
45
- // typed client for the public node-pack registry at packs.openwop.dev
46
- // per spec/v1/registry-operations.md.
47
- export { RegistryClient } from './registry-helpers.js';
48
- // RFC 0030 §A `reasoning` field prompt-directive helper. Hosts that
49
- // advertise `capabilities.envelopes.reasoning.supported: true` use this
50
- // to synthesize the system-prompt fragment that instructs the model to
51
- // populate the OPTIONAL `reasoning` field. See `envelope-directive.ts`
52
- // for the operational note on `"mandatory"` strength (provider-side
53
- // refusal risk per the 2026-05-21 RFC 0030 amendment).
27
+ // Webhook verification is server-only (`node:crypto`) and lives on the
28
+ // `@openwop/openwop/webhooks` subpath it is no longer re-exported from the
29
+ // barrel (the 1.x deprecation, removed in this major). The browser-safe
30
+ // header-family readers stay here.
31
+ export { WEBHOOK_HEADER_FAMILIES, WEBHOOK_SIGNATURE_ALGORITHMS, parseSignatureValue, readWebhookHeaders, } from './webhook-header-families.js';
32
+ // RFC 0030 §A `reasoning` field prompt-directive helper.
54
33
  export { buildReasoningDirective } from './envelope-directive.js';
55
- // RFC 0032 §B.3 + RFC 0033 §D refusal detection helper. Normalizes
56
- // per-provider safety-stop signals (Anthropic `stop_reason: "refusal"`,
57
- // OpenAI `message.refusal` + `finish_reason: "content_filter"`, Gemini
58
- // `finishReason: "SAFETY"` + `promptFeedback.blockReason: "SAFETY"`)
59
- // to a canonical `{ refusalText, safetyCategory?, provider }` shape.
60
- // Hosts route the non-null return through `envelope.refusal` emission
61
- // + the `envelope_refusal` terminal error code (RFC 0033 §F).
62
- // **SECURITY:** Pass `refusalText` through the BYOK redaction harness
63
- // BEFORE persistence — this helper does NOT redact.
34
+ // RFC 0032 §B.3 + RFC 0033 §D refusal detection helper. **SECURITY:** pass
35
+ // `refusalText` through the BYOK redaction harness BEFORE persistence — this
36
+ // helper does NOT redact.
64
37
  export { parseRefusal } from './parse-refusal.js';
65
38
  //# 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;AA8GtC,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,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAM5B,yEAAyE;AACzE,yEAAyE;AACzE,oB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Y,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG1D,4EAA4E;AAC5E,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAGxB,yEAAyE;AACzE,2CAA2C;AAC3C,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAM5B,uEAAuE;AACvE,uEAAuE;AACvE,0BAA0B;AAC1B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,kBAAkB,CAAC;AAS1B,kDAAkD;AAClD,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,uEAAuE;AACvE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAkCtC,yDAAyD;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,2EAA2E;AAC3E,6EAA6E;AAC7E,0BAA0B;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * declared in `types.ts`.
5
5
  *
6
6
  * **Why these live here.** `types.ts` declares the canonical wire shapes
7
- * (mirroring `api/openapi.yaml` + `schemas/run-snapshot.schema.json`).
7
+ * (mirroring `api/v2/openapi.yaml` + `schemas/v2/run-snapshot.schema.json`).
8
8
  * This module adds the constants + predicates SDK consumers need to act
9
9
  * on those shapes without redefining them locally. Pulling them into the
10
10
  * SDK makes the protocol vocabulary single-sourced for application,
@@ -27,7 +27,8 @@
27
27
  *
28
28
  * @module @openwop/openwop/run-helpers
29
29
  */
30
- import type { RunStatus } from './types.js';
30
+ import type { RunStatus, VendorErrorCode } from './types.js';
31
+ import { RETRIABLE_ERROR_CODES, type ErrorCode } from './generated.js';
31
32
  /**
32
33
  * Run statuses considered active — the run MAY still transition. A reader
33
34
  * who does not recognize a status string MUST treat it as terminal-unknown
@@ -59,22 +60,21 @@ export type TerminalRunStatus = (typeof TERMINAL_RUN_STATUSES)[number];
59
60
  */
60
61
  export declare function isTerminalRunStatus(status: RunStatus | string): boolean;
61
62
  /**
62
- * Canonical REST/MCP error-envelope codes from `auth.md`,
63
- * `rest-endpoints.md`, and adjacent v1 specs. The HTTP envelope's `error`
64
- * field remains string-typed for forward compatibility, but this list
65
- * gives SDK consumers a stable set for common branching.
66
- *
67
- * Codes here describe request/transport failures. Run execution failures
68
- * live in `RUN_ERROR_CODES` below as `RunSnapshot.error.code`.
69
- */
70
- export declare const HTTP_ERROR_CODES: readonly ["unauthenticated", "forbidden", "key_expired", "key_revoked", "validation_error", "not_found", "rate_limited", "run_already_active", "idempotency_in_flight", "idempotency_key_mismatch", "unsupported_stream_mode", "force_engine_version_forbidden", "mock_provider_forbidden", "capability_not_provided", "capability_required", "credential_required", "credential_forbidden", "credential_unavailable", "pack_integrity_mismatch", "pack_signature_invalid", "pack_peer_dependency_missing", "pack_lockfile_incomplete", "pack_version_not_found", "interrupt_not_found", "approval_token_invalid", "approval_token_expired", "approval_token_consumed", "provider_policy_denied", "mcp_server_not_configured", "mcp_timeout", "mcp_network_error", "mcp_server_error", "mcp_protocol_error", "mcp_tool_error", "http_url_rejected", "http_timeout", "http_network_error", "http_unexpected_status", "webhook_url_rejected", "subscription_not_found", "internal_error"];
71
- export type HttpErrorCode = (typeof HTTP_ERROR_CODES)[number];
72
- /**
73
- * Type guard that narrows a string to a known canonical HTTP error code.
74
- * Returns false for host extensions and future spec additions; callers
75
- * should still render a fallback from the envelope's `message`.
63
+ * The v2 error registry (`spec/v2/errors.json`, errors.md): every code a v2
64
+ * host may return in `ErrorEnvelope.error`, generated into `generated.ts`.
65
+ * Kept under the 1.x name for call-site parity; `ERROR_CODES` is the same
66
+ * array.
76
67
  */
77
- export declare function isHttpErrorCode(value: unknown): value is HttpErrorCode;
68
+ export declare const HTTP_ERROR_CODES: readonly ["audience_mismatch", "capability_not_provided", "capability_required", "client_version_unsupported", "connection_provider_conflict", "connection_provider_unresolved", "connector_action_unresolved", "connector_auth_expired", "credential_forbidden", "credential_not_found", "credential_required", "credential_revoked", "credential_scope_unsupported", "credential_unavailable", "delegation_chain_cyclic", "delegation_chain_too_long", "delegation_expired", "delegation_scope_amplified", "envelope_correlation_conflict", "envelope_invalid", "envelope_refusal", "envelope_truncation_unrecoverable", "event_type_unmapped", "forbidden", "force_engine_version_forbidden", "fork_point_invalid", "id_tenant_mismatch", "idempotency_in_flight", "idempotency_key_invalid", "idempotency_key_mismatch", "identity_unresolvable", "identity_unverified", "internal_error", "interop_version_unsupported", "interrupt_already_resolved", "interrupt_cancelled", "interrupt_expired", "interrupt_not_found", "interrupt_token_invalid", "key_revoked", "loop_limit_exceeded", "mcp_mrtr_rounds_exceeded", "mock_provider_forbidden", "not_found", "oauth_provider_unsupported", "oauth_scope_unsupported", "pack_dependency_conflict", "pack_dependency_cycle", "pack_engine_unsupported", "pack_integrity_failure", "pack_integrity_mismatch", "pack_kind_invalid", "pack_load_failure", "pack_lockfile_incomplete", "pack_namespace_unauthorized", "pack_peer_dependency_missing", "pack_peer_dependency_undefined", "pack_registry_unreachable", "pack_runtime_requirement_unmet", "pack_signature_invalid", "pack_validation_failed", "pack_version_not_found", "payload_too_large", "protocol_version_mismatch", "protocol_version_unsupported", "rate_limited", "recursion_limit_exceeded", "replay_diverged_at_refusal", "replay_memory_snapshot_unavailable", "replay_source_missing", "residency_unavailable", "run_already_active", "run_forbidden", "run_state_conflict", "run_terminal", "run_timeout", "runner_unavailable", "sandbox_capability_denied", "sandbox_escape_attempt", "sandbox_memory_exceeded", "sandbox_timeout", "schedule_horizon_exceeded", "sender_constraint_missing", "signature_not_available", "sub_chain_cycle", "sub_chain_depth_exceeded", "token_budget_exceeded", "unauthenticated", "unsupported_media_type", "unsupported_stream_mode", "until_in_past", "validation_error", "version_conflict", "webhook_url_rejected", "workspace_conflict", "workspace_membership_required", "workspace_too_large"];
69
+ export type HttpErrorCode = ErrorCode;
70
+ /** Type guard that narrows a string to a registered protocol {@link ErrorCode}. */
71
+ export declare function isErrorCode(value: unknown): value is ErrorCode;
72
+ /** 1.x name for {@link isErrorCode}. */
73
+ export declare const isHttpErrorCode: typeof isErrorCode;
74
+ /** True for the registry rows marked `retriable: true`; retry timing lives in `Retry-After` only (RFC 0171 §B.2). */
75
+ export declare function isRetriableErrorCode(value: unknown): value is (typeof RETRIABLE_ERROR_CODES)[number];
76
+ /** True for a well-formed vendor code (`<org>.<name>`, `openwop.` reserved); does not check org registration. */
77
+ export declare function isVendorErrorCode(value: unknown): value is VendorErrorCode;
78
78
  /**
79
79
  * Run-document error codes — stable identifiers used in
80
80
  * `RunSnapshot.error.code` when a run reaches `failed`. These are distinct
@@ -92,7 +92,7 @@ export declare function isHttpErrorCode(value: unknown): value is HttpErrorCode;
92
92
  * unrecognized values. Until that lands, drift between this list + the
93
93
  * engine's actual emission set is detectable only by manual review.
94
94
  */
95
- export declare const RUN_ERROR_CODES: readonly ["auth_required", "forbidden", "workspace_not_found", "run_already_active", "run_not_found", "run_terminal", "engine_version_mismatch", "invalid_workflow_definition", "invalid_trigger_input", "node_type_not_found", "config_validation_failed", "token_budget_exceeded", "concurrent_run_limit_reached", "rate_limited", "node_timeout", "global_timeout", "node_execution_failed", "external_call_failed", "recursion_limit_exceeded", "capability_not_provided", "approval_timeout", "approval_token_invalid", "approval_token_expired", "approval_token_consumed", "persistence_failed", "doc_budget_exceeded"];
95
+ export declare const RUN_ERROR_CODES: readonly ["auth_required", "forbidden", "workspace_not_found", "run_already_active", "run_not_found", "run_terminal", "engine_version_mismatch", "invalid_workflow_definition", "invalid_trigger_input", "node_type_not_found", "config_validation_failed", "token_budget_exceeded", "concurrent_run_limit_reached", "rate_limited", "node_timeout", "global_timeout", "node_execution_failed", "external_call_failed", "recursion_limit_exceeded", "run_timeout", "loop_limit_exceeded", "envelope_refusal", "capability_not_provided", "approval_timeout", "approval_token_invalid", "approval_token_expired", "approval_token_consumed", "persistence_failed", "doc_budget_exceeded"];
96
96
  export type RunErrorCode = (typeof RUN_ERROR_CODES)[number];
97
97
  /**
98
98
  * Type guard that narrows a string to a known {@link RunErrorCode}.
@@ -108,9 +108,8 @@ export declare function isRunErrorCode(value: unknown): value is RunErrorCode;
108
108
  * - `RunError` lives on the run document; describes WHY the run failed.
109
109
  * `code` is from the typed {@link RunErrorCode} vocabulary.
110
110
  * - `ErrorEnvelope` lives on HTTP error responses; describes WHY the
111
- * request failed. `error` is a free string code (often from
112
- * {@link HTTP_ERROR_CODES}, but not type-pinned, to permit host
113
- * extensions and future protocol additions).
111
+ * request failed. `error` is a registered {@link ErrorCode} or a vendor
112
+ * code (`<org>.<name>`).
114
113
  *
115
114
  * The shapes share `message` and `details` but diverge on the code field
116
115
  * name (`code` vs `error`) by design — they represent different layers.
@@ -1 +1 @@
1
- {"version":3,"file":"run-helpers.d.ts","sourceRoot":"","sources":["../src/run-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,kHAUtB,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,qBAAqB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B,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
@@ -4,7 +4,7 @@
4
4
  * declared in `types.ts`.
5
5
  *
6
6
  * **Why these live here.** `types.ts` declares the canonical wire shapes
7
- * (mirroring `api/openapi.yaml` + `schemas/run-snapshot.schema.json`).
7
+ * (mirroring `api/v2/openapi.yaml` + `schemas/v2/run-snapshot.schema.json`).
8
8
  * This module adds the constants + predicates SDK consumers need to act
9
9
  * on those shapes without redefining them locally. Pulling them into the
10
10
  * SDK makes the protocol vocabulary single-sourced for application,
@@ -27,6 +27,7 @@
27
27
  *
28
28
  * @module @openwop/openwop/run-helpers
29
29
  */
30
+ import { ERROR_CODES, RETRIABLE_ERROR_CODES, VENDOR_ERROR_CODE_PATTERN } from './generated.js';
30
31
  // ─── Run statuses ────────────────────────────────────────────────────────
31
32
  /**
32
33
  * Run statuses considered active — the run MAY still transition. A reader
@@ -74,78 +75,25 @@ export function isTerminalRunStatus(status) {
74
75
  }
75
76
  // ─── HTTP error-envelope codes ───────────────────────────────────────────
76
77
  /**
77
- * Canonical REST/MCP error-envelope codes from `auth.md`,
78
- * `rest-endpoints.md`, and adjacent v1 specs. The HTTP envelope's `error`
79
- * field remains string-typed for forward compatibility, but this list
80
- * gives SDK consumers a stable set for common branching.
81
- *
82
- * Codes here describe request/transport failures. Run execution failures
83
- * live in `RUN_ERROR_CODES` below as `RunSnapshot.error.code`.
78
+ * The v2 error registry (`spec/v2/errors.json`, errors.md): every code a v2
79
+ * host may return in `ErrorEnvelope.error`, generated into `generated.ts`.
80
+ * Kept under the 1.x name for call-site parity; `ERROR_CODES` is the same
81
+ * array.
84
82
  */
85
- export const HTTP_ERROR_CODES = [
86
- // Auth / access
87
- 'unauthenticated',
88
- 'forbidden',
89
- 'key_expired',
90
- 'key_revoked',
91
- // Request / routing
92
- 'validation_error',
93
- 'not_found',
94
- 'rate_limited',
95
- // Idempotency / run creation conflicts
96
- 'run_already_active',
97
- 'idempotency_in_flight',
98
- 'idempotency_key_mismatch',
99
- // Streaming / protocol negotiation
100
- 'unsupported_stream_mode',
101
- 'force_engine_version_forbidden',
102
- 'mock_provider_forbidden',
103
- // Capability / credential negotiation
104
- 'capability_not_provided',
105
- 'capability_required',
106
- 'credential_required',
107
- 'credential_forbidden',
108
- 'credential_unavailable',
109
- // Node-pack lifecycle (registry + lockfile) per node-packs.md §"Dependency resolution + lockfile"
110
- 'pack_integrity_mismatch',
111
- 'pack_signature_invalid',
112
- 'pack_peer_dependency_missing',
113
- 'pack_lockfile_incomplete',
114
- 'pack_version_not_found',
115
- // HITL / interrupt callbacks
116
- 'interrupt_not_found',
117
- 'approval_token_invalid',
118
- 'approval_token_expired',
119
- 'approval_token_consumed',
120
- // Phase H.1″ — AI provider policy enforcement per
121
- // capabilities.md §"aiProviders.policies".
122
- 'provider_policy_denied',
123
- // Phase H.2 — MCP client error codes.
124
- 'mcp_server_not_configured',
125
- 'mcp_timeout',
126
- 'mcp_network_error',
127
- 'mcp_server_error',
128
- 'mcp_protocol_error',
129
- 'mcp_tool_error',
130
- // Phase H.3 — HTTP client error codes.
131
- 'http_url_rejected',
132
- 'http_timeout',
133
- 'http_network_error',
134
- 'http_unexpected_status',
135
- // Phase H webhook codes (restored to spec-de-facto per Python host
136
- // close-out and conformance webhook-negative.test.ts).
137
- 'webhook_url_rejected',
138
- 'subscription_not_found',
139
- // Generic server failure
140
- 'internal_error',
141
- ];
142
- /**
143
- * Type guard that narrows a string to a known canonical HTTP error code.
144
- * Returns false for host extensions and future spec additions; callers
145
- * should still render a fallback from the envelope's `message`.
146
- */
147
- export function isHttpErrorCode(value) {
148
- return typeof value === 'string' && HTTP_ERROR_CODES.includes(value);
83
+ export const HTTP_ERROR_CODES = ERROR_CODES;
84
+ /** Type guard that narrows a string to a registered protocol {@link ErrorCode}. */
85
+ export function isErrorCode(value) {
86
+ return typeof value === 'string' && ERROR_CODES.includes(value);
87
+ }
88
+ /** 1.x name for {@link isErrorCode}. */
89
+ export const isHttpErrorCode = isErrorCode;
90
+ /** True for the registry rows marked `retriable: true`; retry timing lives in `Retry-After` only (RFC 0171 §B.2). */
91
+ export function isRetriableErrorCode(value) {
92
+ return typeof value === 'string' && RETRIABLE_ERROR_CODES.includes(value);
93
+ }
94
+ /** True for a well-formed vendor code (`<org>.<name>`, `openwop.` reserved); does not check org registration. */
95
+ export function isVendorErrorCode(value) {
96
+ return typeof value === 'string' && VENDOR_ERROR_CODE_PATTERN.test(value);
149
97
  }
150
98
  // ─── Run error codes ─────────────────────────────────────────────────────
151
99
  /**
@@ -190,6 +138,9 @@ export const RUN_ERROR_CODES = [
190
138
  'node_execution_failed',
191
139
  'external_call_failed',
192
140
  'recursion_limit_exceeded',
141
+ 'run_timeout',
142
+ 'loop_limit_exceeded',
143
+ 'envelope_refusal',
193
144
  'capability_not_provided',
194
145
  // Approval
195
146
  'approval_timeout',
@@ -1 +1 @@
1
- {"version":3,"file":"run-helpers.js","sourceRoot":"","sources":["../src/run-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,4EAA4E;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS;IACT,SAAS;IACT,QAAQ;IACR,kBAAkB;IAClB,eAAe;IACf,kBAAkB;IAClB,sEAAsE;IACtE,oEAAoE;IACpE,YAAY;CACJ,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW;IACX,QAAQ;IACR,WAAW;CACH,CAAC;AAKX;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA0B;IAC5D,OAAO,CAAE,mBAAyC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACtE,CAAC;AAED,4EAA4E;AAE5E;;;;;;;;GAQG;AACH,MAAM,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1
  /**
2
- * SSE consumer for `GET /v1/runs/{runId}/events`. Async-iterable shape so
3
- * consumers can write `for await (const event of client.runs.events(...))`.
2
+ * SSE consumers for `GET /runs/{runId}/events` (the `runEvents` channel) and
3
+ * `GET /host/events` (the `hostEvents` channel) events.md §SSE frames.
4
+ * Async-iterable shape so consumers can write
5
+ * `for await (const event of client.runs.events(...))`.
4
6
  *
5
- * Implementation parses event:/data:/id: lines per RFC 8895. Native fetch +
6
- * ReadableStream — zero third-party deps.
7
+ * Parses `event:` / `data:` / `id:` lines per the WHATWG EventSource
8
+ * grammar. Native fetch + ReadableStream — zero third-party deps.
7
9
  *
8
- * Designed to be cancellable: pass an AbortSignal via options, or break out
9
- * of the for-await loop and the underlying connection is torn down on the
10
- * next tick.
10
+ * Cancellable: pass an AbortSignal via options, or break out of the
11
+ * for-await loop and the underlying connection is torn down.
11
12
  */
12
- import type { RunEventDoc, StreamMode } from './types.js';
13
+ import type { HostEventDoc, RunEventDoc, StreamMode } from './types.js';
13
14
  export interface EventsStreamOptions {
14
15
  /**
15
- * Single mode (e.g., 'updates') OR array of modes (S4 mixed-mode,
16
- * e.g., ['updates', 'messages']). Arrays serialize to a comma-
17
- * separated `?streamMode=updates,messages` query.
16
+ * Single mode (e.g., 'updates') OR array of modes (mixed mode, e.g.,
17
+ * ['updates', 'messages']). Arrays serialize to a comma-separated
18
+ * `?streamMode=updates,messages` query (events.md §The events channel).
18
19
  */
19
20
  readonly streamMode?: StreamMode | readonly StreamMode[];
21
+ /** `Last-Event-ID` — the host resumes at the next sequence and never re-emits the resumption point. */
20
22
  readonly lastEventId?: string;
21
23
  readonly signal?: AbortSignal;
22
24
  /**
23
- * S3 batching hint. When set, server batches events for up to N ms;
24
- * the SDK transparently flattens batched arrays back into individual
25
- * RunEventDoc yields, so consumers see the same per-event surface as
26
- * unbuffered streams. Range 0..5000.
25
+ * Batching hint (0..5000). The host accumulates events into one
26
+ * `event: batch` frame whose `data:` is an array of `RunEventDoc`; the SDK
27
+ * flattens the batch back into individual yields.
27
28
  */
28
29
  readonly bufferMs?: number;
29
30
  }
31
+ export interface HostEventsStreamOptions {
32
+ /** `Last-Event-ID` for resumption. */
33
+ readonly lastEventId?: string;
34
+ readonly signal?: AbortSignal;
35
+ /**
36
+ * The channel address. Default `/host/events`; a host MAY declare another
37
+ * under `heartbeat.deliveryChannel` (capabilities.md).
38
+ */
39
+ readonly path?: string;
40
+ }
30
41
  export interface EventsStreamContext {
31
42
  readonly baseUrl: string;
32
43
  readonly apiKey: string;
44
+ /** The `OpenWOP-Version` value sent on the subscribe request (RFC 0172 §A.3). */
45
+ readonly protocolVersion: string;
46
+ /** Optional fetch implementation override. Defaults to global `fetch`. */
47
+ readonly fetch?: typeof fetch;
33
48
  }
49
+ /** Subscribe to a run's event stream. Yields each `RunEventDoc` until the host closes after the terminal event. */
34
50
  export declare function streamEvents(ctx: EventsStreamContext, runId: string, opts?: EventsStreamOptions): AsyncGenerator<RunEventDoc, void, void>;
51
+ /** Subscribe to the host events channel (heartbeat messages; content-free of run data). */
52
+ export declare function streamHostEvents(ctx: EventsStreamContext, opts?: HostEventsStreamOptions): AsyncGenerator<HostEventDoc, void, void>;
35
53
  //# sourceMappingURL=sse.d.ts.map
package/dist/sse.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,UAAU,EAAE,CAAC;IACzD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAA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ACnH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,mBAAmB,EACxB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,mBAAwB,GAC7B,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAazC;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,mBAAmB,EACxB,IAAI,GAAE,uBAA4B,GACjC,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAE1C"}
package/dist/sse.js CHANGED
@@ -1,15 +1,17 @@
1
1
  /**
2
- * SSE consumer for `GET /v1/runs/{runId}/events`. Async-iterable shape so
3
- * consumers can write `for await (const event of client.runs.events(...))`.
2
+ * SSE consumers for `GET /runs/{runId}/events` (the `runEvents` channel) and
3
+ * `GET /host/events` (the `hostEvents` channel) events.md §SSE frames.
4
+ * Async-iterable shape so consumers can write
5
+ * `for await (const event of client.runs.events(...))`.
4
6
  *
5
- * Implementation parses event:/data:/id: lines per RFC 8895. Native fetch +
6
- * ReadableStream — zero third-party deps.
7
+ * Parses `event:` / `data:` / `id:` lines per the WHATWG EventSource
8
+ * grammar. Native fetch + ReadableStream — zero third-party deps.
7
9
  *
8
- * Designed to be cancellable: pass an AbortSignal via options, or break out
9
- * of the for-await loop and the underlying connection is torn down on the
10
- * next tick.
10
+ * Cancellable: pass an AbortSignal via options, or break out of the
11
+ * for-await loop and the underlying connection is torn down.
11
12
  */
12
- export async function* streamEvents(ctx, runId, opts = {}) {
13
+ /** Subscribe to a run's event stream. Yields each `RunEventDoc` until the host closes after the terminal event. */
14
+ export function streamEvents(ctx, runId, opts = {}) {
13
15
  const params = new URLSearchParams();
14
16
  if (opts.streamMode) {
15
17
  const modeParam = typeof opts.streamMode === 'string' ? opts.streamMode : opts.streamMode.join(',');
@@ -19,11 +21,20 @@ export async function* streamEvents(ctx, runId, opts = {}) {
19
21
  params.set('bufferMs', String(opts.bufferMs));
20
22
  }
21
23
  const qs = params.toString();
22
- const url = `${ctx.baseUrl}/v1/runs/${encodeURIComponent(runId)}/events${qs ? `?${qs}` : ''}`;
24
+ const path = `/runs/${encodeURIComponent(runId)}/events${qs ? `?${qs}` : ''}`;
25
+ return streamSse(ctx, path, opts);
26
+ }
27
+ /** Subscribe to the host events channel (heartbeat messages; content-free of run data). */
28
+ export function streamHostEvents(ctx, opts = {}) {
29
+ return streamSse(ctx, opts.path ?? '/host/events', opts);
30
+ }
31
+ async function* streamSse(ctx, path, opts) {
32
+ const url = `${ctx.baseUrl}${path}`;
23
33
  const headers = {
24
34
  Accept: 'text/event-stream',
25
35
  Authorization: `Bearer ${ctx.apiKey}`,
26
36
  'Cache-Control': 'no-cache',
37
+ 'OpenWOP-Version': ctx.protocolVersion,
27
38
  };
28
39
  if (opts.lastEventId) {
29
40
  headers['Last-Event-ID'] = opts.lastEventId;
@@ -36,7 +47,8 @@ export async function* streamEvents(ctx, runId, opts = {}) {
36
47
  else
37
48
  externalSignal.addEventListener('abort', () => internalAbort.abort(), { once: true });
38
49
  }
39
- const res = await fetch(url, { method: 'GET', headers, signal: internalAbort.signal });
50
+ const doFetch = ctx.fetch ?? fetch;
51
+ const res = await doFetch(url, { method: 'GET', headers, signal: internalAbort.signal });
40
52
  if (!res.ok || res.body === null) {
41
53
  throw new Error(`SSE subscribe failed: HTTP ${res.status}`);
42
54
  }
@@ -45,36 +57,29 @@ export async function* streamEvents(ctx, runId, opts = {}) {
45
57
  let buffer = '';
46
58
  let pendingEvent = 'message';
47
59
  let pendingData = [];
48
- let pendingId = null;
49
60
  /**
50
- * Flush the buffered event. Returns an array of RunEventDoc:
51
- * - 0 elements when the buffer is empty or non-JSON (skip).
52
- * - 1 element for a normal `event: <type>` event.
53
- * - N elements when the server batched per S3 — `event: batch` with
54
- * `data:` as a JSON array of RunEventDoc.
61
+ * Flush the buffered frame. Returns 0 elements when the buffer is empty or
62
+ * non-JSON (skip), 1 element for a normal `event: <type>` frame, N for an
63
+ * `event: batch` frame whose `data:` is a JSON array.
55
64
  */
56
65
  const flushAndYield = () => {
57
66
  if (pendingData.length === 0) {
58
67
  pendingEvent = 'message';
59
- pendingId = null;
60
68
  return [];
61
69
  }
62
70
  const dataStr = pendingData.join('\n');
63
71
  const eventType = pendingEvent;
64
72
  pendingEvent = 'message';
65
73
  pendingData = [];
66
- pendingId = null;
67
74
  try {
68
75
  const parsed = JSON.parse(dataStr);
69
- // S3 batched envelope — `event: batch` carries an array of events.
70
76
  if (eventType === 'batch' && Array.isArray(parsed)) {
71
77
  return parsed;
72
78
  }
73
- // Normal single-event payload.
74
79
  return [parsed];
75
80
  }
76
81
  catch {
77
- // Skip non-JSON events (keep-alive payloads, vendor extensions).
82
+ // Skip non-JSON frames (keep-alive payloads, vendor extensions).
78
83
  return [];
79
84
  }
80
85
  };
@@ -106,15 +111,13 @@ export async function* streamEvents(ctx, runId, opts = {}) {
106
111
  case 'data':
107
112
  pendingData.push(fieldValue);
108
113
  break;
109
- case 'id':
110
- pendingId = fieldValue;
111
- break;
112
114
  default:
115
+ // `id:` is the sequence; the consumer reads it from the document itself.
113
116
  break;
114
117
  }
115
118
  }
116
119
  }
117
- // Flush any final unterminated event.
120
+ // Flush any final unterminated frame.
118
121
  for (const final of flushAndYield())
119
122
  yield final;
120
123
  }
@@ -128,10 +131,5 @@ export async function* streamEvents(ctx, runId, opts = {}) {
128
131
  if (!internalAbort.signal.aborted)
129
132
  internalAbort.abort();
130
133
  }
131
- // Reference pendingEvent/pendingId so the linter doesn't flag them as
132
- // unused; they're consumed via flushAndYield's closure but TS can't see
133
- // that across a generator boundary.
134
- void pendingEvent;
135
- void pendingId;
136
134
  }
137
135
  //# sourceMappingURL=sse.js.map
package/dist/sse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sse.js","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CACjC,GAAwB,EACxB,KAAa,EAC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