@zarel-ai/sdk 0.6.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/LICENSE +21 -0
- package/README.md +412 -0
- package/dist/_internal/auth-headers.d.ts +19 -0
- package/dist/_internal/auth-headers.d.ts.map +1 -0
- package/dist/_internal/auth-headers.js +30 -0
- package/dist/_internal/auth-headers.js.map +1 -0
- package/dist/_internal/confirmation.d.ts +24 -0
- package/dist/_internal/confirmation.d.ts.map +1 -0
- package/dist/_internal/confirmation.js +54 -0
- package/dist/_internal/confirmation.js.map +1 -0
- package/dist/_internal/event-iterator.d.ts +18 -0
- package/dist/_internal/event-iterator.d.ts.map +1 -0
- package/dist/_internal/event-iterator.js +151 -0
- package/dist/_internal/event-iterator.js.map +1 -0
- package/dist/_internal/fetch-client.d.ts +141 -0
- package/dist/_internal/fetch-client.d.ts.map +1 -0
- package/dist/_internal/fetch-client.js +471 -0
- package/dist/_internal/fetch-client.js.map +1 -0
- package/dist/_internal/interceptors.d.ts +40 -0
- package/dist/_internal/interceptors.d.ts.map +1 -0
- package/dist/_internal/interceptors.js +28 -0
- package/dist/_internal/interceptors.js.map +1 -0
- package/dist/_internal/mcp.d.ts +11 -0
- package/dist/_internal/mcp.d.ts.map +1 -0
- package/dist/_internal/mcp.js +79 -0
- package/dist/_internal/mcp.js.map +1 -0
- package/dist/_internal/pagination.d.ts +71 -0
- package/dist/_internal/pagination.d.ts.map +1 -0
- package/dist/_internal/pagination.js +130 -0
- package/dist/_internal/pagination.js.map +1 -0
- package/dist/_internal/require-token.d.ts +17 -0
- package/dist/_internal/require-token.d.ts.map +1 -0
- package/dist/_internal/require-token.js +25 -0
- package/dist/_internal/require-token.js.map +1 -0
- package/dist/_internal/retry-after.d.ts +2 -0
- package/dist/_internal/retry-after.d.ts.map +1 -0
- package/dist/_internal/retry-after.js +34 -0
- package/dist/_internal/retry-after.js.map +1 -0
- package/dist/_internal/sse-client.d.ts +43 -0
- package/dist/_internal/sse-client.d.ts.map +1 -0
- package/dist/_internal/sse-client.js +250 -0
- package/dist/_internal/sse-client.js.map +1 -0
- package/dist/_internal/version.d.ts +5 -0
- package/dist/_internal/version.d.ts.map +1 -0
- package/dist/_internal/version.js +12 -0
- package/dist/_internal/version.js.map +1 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +86 -0
- package/dist/client.js.map +1 -0
- package/dist/contract/_singleton.d.ts +18 -0
- package/dist/contract/_singleton.d.ts.map +1 -0
- package/dist/contract/_singleton.js +27 -0
- package/dist/contract/_singleton.js.map +1 -0
- package/dist/contract/actions.d.ts +18 -0
- package/dist/contract/actions.d.ts.map +1 -0
- package/dist/contract/actions.js +36 -0
- package/dist/contract/actions.js.map +1 -0
- package/dist/contract/assistant.d.ts +65 -0
- package/dist/contract/assistant.d.ts.map +1 -0
- package/dist/contract/assistant.js +44 -0
- package/dist/contract/assistant.js.map +1 -0
- package/dist/contract/batch.d.ts +27 -0
- package/dist/contract/batch.d.ts.map +1 -0
- package/dist/contract/batch.js +20 -0
- package/dist/contract/batch.js.map +1 -0
- package/dist/contract/capabilities.d.ts +21 -0
- package/dist/contract/capabilities.d.ts.map +1 -0
- package/dist/contract/capabilities.js +31 -0
- package/dist/contract/capabilities.js.map +1 -0
- package/dist/contract/constraints.d.ts +21 -0
- package/dist/contract/constraints.d.ts.map +1 -0
- package/dist/contract/constraints.js +31 -0
- package/dist/contract/constraints.js.map +1 -0
- package/dist/contract/events.d.ts +33 -0
- package/dist/contract/events.d.ts.map +1 -0
- package/dist/contract/events.js +56 -0
- package/dist/contract/events.js.map +1 -0
- package/dist/contract/flows.d.ts +44 -0
- package/dist/contract/flows.d.ts.map +1 -0
- package/dist/contract/flows.js +109 -0
- package/dist/contract/flows.js.map +1 -0
- package/dist/contract/governance.d.ts +6 -0
- package/dist/contract/governance.d.ts.map +1 -0
- package/dist/contract/governance.js +17 -0
- package/dist/contract/governance.js.map +1 -0
- package/dist/contract/index.d.ts +137 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +177 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/metadata.d.ts +26 -0
- package/dist/contract/metadata.d.ts.map +1 -0
- package/dist/contract/metadata.js +25 -0
- package/dist/contract/metadata.js.map +1 -0
- package/dist/contract/process-model.d.ts +31 -0
- package/dist/contract/process-model.d.ts.map +1 -0
- package/dist/contract/process-model.js +51 -0
- package/dist/contract/process-model.js.map +1 -0
- package/dist/contract/roots/channels.d.ts +27 -0
- package/dist/contract/roots/channels.d.ts.map +1 -0
- package/dist/contract/roots/channels.js +53 -0
- package/dist/contract/roots/channels.js.map +1 -0
- package/dist/contract/roots/events.d.ts +7 -0
- package/dist/contract/roots/events.d.ts.map +1 -0
- package/dist/contract/roots/events.js +19 -0
- package/dist/contract/roots/events.js.map +1 -0
- package/dist/contract/roots/index.d.ts +15 -0
- package/dist/contract/roots/index.d.ts.map +1 -0
- package/dist/contract/roots/index.js +38 -0
- package/dist/contract/roots/index.js.map +1 -0
- package/dist/contract/roots/mcp-servers.d.ts +46 -0
- package/dist/contract/roots/mcp-servers.d.ts.map +1 -0
- package/dist/contract/roots/mcp-servers.js +68 -0
- package/dist/contract/roots/mcp-servers.js.map +1 -0
- package/dist/contract/roots/profiles.d.ts +18 -0
- package/dist/contract/roots/profiles.d.ts.map +1 -0
- package/dist/contract/roots/profiles.js +31 -0
- package/dist/contract/roots/profiles.js.map +1 -0
- package/dist/contract/roots/timezone.d.ts +10 -0
- package/dist/contract/roots/timezone.d.ts.map +1 -0
- package/dist/contract/roots/timezone.js +19 -0
- package/dist/contract/roots/timezone.js.map +1 -0
- package/dist/contract/roots/treatment.d.ts +11 -0
- package/dist/contract/roots/treatment.d.ts.map +1 -0
- package/dist/contract/roots/treatment.js +37 -0
- package/dist/contract/roots/treatment.js.map +1 -0
- package/dist/contract/roots/vocabulary.d.ts +18 -0
- package/dist/contract/roots/vocabulary.d.ts.map +1 -0
- package/dist/contract/roots/vocabulary.js +31 -0
- package/dist/contract/roots/vocabulary.js.map +1 -0
- package/dist/contract/schemas.d.ts +18 -0
- package/dist/contract/schemas.d.ts.map +1 -0
- package/dist/contract/schemas.js +31 -0
- package/dist/contract/schemas.js.map +1 -0
- package/dist/contract/skills.d.ts +20 -0
- package/dist/contract/skills.d.ts.map +1 -0
- package/dist/contract/skills.js +36 -0
- package/dist/contract/skills.js.map +1 -0
- package/dist/errors.d.ts +65 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +80 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/contract.d.ts +7688 -0
- package/dist/generated/contract.d.ts.map +1 -0
- package/dist/generated/contract.js +7 -0
- package/dist/generated/contract.js.map +1 -0
- package/dist/generated/index.d.ts +41 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +3 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/runtime.d.ts +4020 -0
- package/dist/generated/runtime.d.ts.map +1 -0
- package/dist/generated/runtime.js +7 -0
- package/dist/generated/runtime.js.map +1 -0
- package/dist/generated/unwrap-map.d.ts +989 -0
- package/dist/generated/unwrap-map.d.ts.map +1 -0
- package/dist/generated/unwrap-map.js +344 -0
- package/dist/generated/unwrap-map.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/actions.d.ts +33 -0
- package/dist/resources/actions.d.ts.map +1 -0
- package/dist/resources/actions.js +52 -0
- package/dist/resources/actions.js.map +1 -0
- package/dist/resources/audit.d.ts +52 -0
- package/dist/resources/audit.d.ts.map +1 -0
- package/dist/resources/audit.js +86 -0
- package/dist/resources/audit.js.map +1 -0
- package/dist/resources/authorization-ceiling.d.ts +25 -0
- package/dist/resources/authorization-ceiling.d.ts.map +1 -0
- package/dist/resources/authorization-ceiling.js +26 -0
- package/dist/resources/authorization-ceiling.js.map +1 -0
- package/dist/resources/authorization-operation-ids.d.ts +15 -0
- package/dist/resources/authorization-operation-ids.d.ts.map +1 -0
- package/dist/resources/authorization-operation-ids.js +31 -0
- package/dist/resources/authorization-operation-ids.js.map +1 -0
- package/dist/resources/authorization.d.ts +60 -0
- package/dist/resources/authorization.d.ts.map +1 -0
- package/dist/resources/authorization.js +51 -0
- package/dist/resources/authorization.js.map +1 -0
- package/dist/resources/authorizations.d.ts +38 -0
- package/dist/resources/authorizations.d.ts.map +1 -0
- package/dist/resources/authorizations.js +19 -0
- package/dist/resources/authorizations.js.map +1 -0
- package/dist/resources/channels.d.ts +36 -0
- package/dist/resources/channels.d.ts.map +1 -0
- package/dist/resources/channels.js +61 -0
- package/dist/resources/channels.js.map +1 -0
- package/dist/resources/contracts.d.ts +46 -0
- package/dist/resources/contracts.d.ts.map +1 -0
- package/dist/resources/contracts.js +86 -0
- package/dist/resources/contracts.js.map +1 -0
- package/dist/resources/conversation-sessions.d.ts +62 -0
- package/dist/resources/conversation-sessions.d.ts.map +1 -0
- package/dist/resources/conversation-sessions.js +48 -0
- package/dist/resources/conversation-sessions.js.map +1 -0
- package/dist/resources/conversation.d.ts +48 -0
- package/dist/resources/conversation.d.ts.map +1 -0
- package/dist/resources/conversation.js +104 -0
- package/dist/resources/conversation.js.map +1 -0
- package/dist/resources/embedding-credentials.d.ts +60 -0
- package/dist/resources/embedding-credentials.d.ts.map +1 -0
- package/dist/resources/embedding-credentials.js +53 -0
- package/dist/resources/embedding-credentials.js.map +1 -0
- package/dist/resources/entities.d.ts +66 -0
- package/dist/resources/entities.d.ts.map +1 -0
- package/dist/resources/entities.js +106 -0
- package/dist/resources/entities.js.map +1 -0
- package/dist/resources/events.d.ts +45 -0
- package/dist/resources/events.d.ts.map +1 -0
- package/dist/resources/events.js +71 -0
- package/dist/resources/events.js.map +1 -0
- package/dist/resources/flows.d.ts +45 -0
- package/dist/resources/flows.d.ts.map +1 -0
- package/dist/resources/flows.js +82 -0
- package/dist/resources/flows.js.map +1 -0
- package/dist/resources/imports.d.ts +8 -0
- package/dist/resources/imports.d.ts.map +1 -0
- package/dist/resources/imports.js +14 -0
- package/dist/resources/imports.js.map +1 -0
- package/dist/resources/index.d.ts +24 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +41 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/llm-credentials.d.ts +47 -0
- package/dist/resources/llm-credentials.d.ts.map +1 -0
- package/dist/resources/llm-credentials.js +46 -0
- package/dist/resources/llm-credentials.js.map +1 -0
- package/dist/resources/llm-services.d.ts +46 -0
- package/dist/resources/llm-services.d.ts.map +1 -0
- package/dist/resources/llm-services.js +41 -0
- package/dist/resources/llm-services.js.map +1 -0
- package/dist/resources/mcp.d.ts +8 -0
- package/dist/resources/mcp.d.ts.map +1 -0
- package/dist/resources/mcp.js +25 -0
- package/dist/resources/mcp.js.map +1 -0
- package/dist/resources/receipts.d.ts +25 -0
- package/dist/resources/receipts.d.ts.map +1 -0
- package/dist/resources/receipts.js +54 -0
- package/dist/resources/receipts.js.map +1 -0
- package/dist/resources/records.d.ts +51 -0
- package/dist/resources/records.d.ts.map +1 -0
- package/dist/resources/records.js +103 -0
- package/dist/resources/records.js.map +1 -0
- package/dist/resources/role-assignments.d.ts +27 -0
- package/dist/resources/role-assignments.d.ts.map +1 -0
- package/dist/resources/role-assignments.js +40 -0
- package/dist/resources/role-assignments.js.map +1 -0
- package/dist/resources/roles.d.ts +39 -0
- package/dist/resources/roles.d.ts.map +1 -0
- package/dist/resources/roles.js +42 -0
- package/dist/resources/roles.js.map +1 -0
- package/dist/resources/runtime-entities.d.ts +23 -0
- package/dist/resources/runtime-entities.d.ts.map +1 -0
- package/dist/resources/runtime-entities.js +29 -0
- package/dist/resources/runtime-entities.js.map +1 -0
- package/dist/resources/state-machine.d.ts +45 -0
- package/dist/resources/state-machine.d.ts.map +1 -0
- package/dist/resources/state-machine.js +86 -0
- package/dist/resources/state-machine.js.map +1 -0
- package/dist/resources/system.d.ts +12 -0
- package/dist/resources/system.d.ts.map +1 -0
- package/dist/resources/system.js +26 -0
- package/dist/resources/system.js.map +1 -0
- package/dist/resources/tools.d.ts +22 -0
- package/dist/resources/tools.d.ts.map +1 -0
- package/dist/resources/tools.js +33 -0
- package/dist/resources/tools.js.map +1 -0
- package/dist/resources/traces.d.ts +65 -0
- package/dist/resources/traces.d.ts.map +1 -0
- package/dist/resources/traces.js +97 -0
- package/dist/resources/traces.js.map +1 -0
- package/dist/runtime/index.d.ts +128 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +210 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/types/actions.d.ts +32 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +9 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/audit.d.ts +65 -0
- package/dist/types/audit.d.ts.map +1 -0
- package/dist/types/audit.js +14 -0
- package/dist/types/audit.js.map +1 -0
- package/dist/types/channels.d.ts +37 -0
- package/dist/types/channels.d.ts.map +1 -0
- package/dist/types/channels.js +6 -0
- package/dist/types/channels.js.map +1 -0
- package/dist/types/confirmation.d.ts +53 -0
- package/dist/types/confirmation.d.ts.map +1 -0
- package/dist/types/confirmation.js +17 -0
- package/dist/types/confirmation.js.map +1 -0
- package/dist/types/contracts.d.ts +194 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +10 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/conversation-sessions.d.ts +58 -0
- package/dist/types/conversation-sessions.d.ts.map +1 -0
- package/dist/types/conversation-sessions.js +6 -0
- package/dist/types/conversation-sessions.js.map +1 -0
- package/dist/types/conversation.d.ts +96 -0
- package/dist/types/conversation.d.ts.map +1 -0
- package/dist/types/conversation.js +3 -0
- package/dist/types/conversation.js.map +1 -0
- package/dist/types/entities.d.ts +22 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +4 -0
- package/dist/types/entities.js.map +1 -0
- package/dist/types/events-stream.d.ts +82 -0
- package/dist/types/events-stream.d.ts.map +1 -0
- package/dist/types/events-stream.js +65 -0
- package/dist/types/events-stream.js.map +1 -0
- package/dist/types/flows-contract.d.ts +8 -0
- package/dist/types/flows-contract.d.ts.map +1 -0
- package/dist/types/flows-contract.js +7 -0
- package/dist/types/flows-contract.js.map +1 -0
- package/dist/types/flows.d.ts +66 -0
- package/dist/types/flows.d.ts.map +1 -0
- package/dist/types/flows.js +25 -0
- package/dist/types/flows.js.map +1 -0
- package/dist/types/imports.d.ts +57 -0
- package/dist/types/imports.d.ts.map +1 -0
- package/dist/types/imports.js +3 -0
- package/dist/types/imports.js.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/locale.d.ts +24 -0
- package/dist/types/locale.d.ts.map +1 -0
- package/dist/types/locale.js +17 -0
- package/dist/types/locale.js.map +1 -0
- package/dist/types/mcp.d.ts +28 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +12 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/platform.d.ts +51 -0
- package/dist/types/platform.d.ts.map +1 -0
- package/dist/types/platform.js +4 -0
- package/dist/types/platform.js.map +1 -0
- package/dist/types/receipt.d.ts +79 -0
- package/dist/types/receipt.d.ts.map +1 -0
- package/dist/types/receipt.js +15 -0
- package/dist/types/receipt.js.map +1 -0
- package/dist/types/records.d.ts +45 -0
- package/dist/types/records.d.ts.map +1 -0
- package/dist/types/records.js +4 -0
- package/dist/types/records.js.map +1 -0
- package/dist/types/spec.d.ts +6 -0
- package/dist/types/spec.d.ts.map +1 -0
- package/dist/types/spec.js +3 -0
- package/dist/types/spec.js.map +1 -0
- package/dist/types/state-machine.d.ts +100 -0
- package/dist/types/state-machine.d.ts.map +1 -0
- package/dist/types/state-machine.js +9 -0
- package/dist/types/state-machine.js.map +1 -0
- package/dist/types/system.d.ts +28 -0
- package/dist/types/system.d.ts.map +1 -0
- package/dist/types/system.js +3 -0
- package/dist/types/system.js.map +1 -0
- package/dist/types/tools.d.ts +188 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +22 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/traces.d.ts +77 -0
- package/dist/types/traces.d.ts.map +1 -0
- package/dist/types/traces.js +11 -0
- package/dist/types/traces.js.map +1 -0
- package/dist/types/workflows.d.ts +42 -0
- package/dist/types/workflows.d.ts.map +1 -0
- package/dist/types/workflows.js +11 -0
- package/dist/types/workflows.js.map +1 -0
- package/package.json +103 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Spec 2 — pure extraction of an MCP JSON-RPC response from the dual
|
|
3
|
+
// content-type body (application/json OR a single text/event-stream frame).
|
|
4
|
+
// Zero runtime deps: reuses the pure SSE frame parser; validates the JSON-RPC
|
|
5
|
+
// shape with a hand-written type-guard (no Zod, no `as` beyond the
|
|
6
|
+
// unknown→record narrowing the transport's envelope-shape guard already uses).
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.extractMcpResponse = extractMcpResponse;
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const sse_client_1 = require("./sse-client");
|
|
11
|
+
function isValidError(value) {
|
|
12
|
+
if (typeof value !== 'object' || value === null)
|
|
13
|
+
return false;
|
|
14
|
+
const obj = value;
|
|
15
|
+
return typeof obj.code === 'number' && typeof obj.message === 'string';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A parsed body is a JSON-RPC response iff it is an object with a present `id`
|
|
19
|
+
* (string | number | null) and EXACTLY ONE of a present `result` (any value) or
|
|
20
|
+
* a well-formed `error` member. Keying on id + (result xor error) — rather than
|
|
21
|
+
* on `jsonrpc` — tolerates a server that omits the version field while rejecting
|
|
22
|
+
* a non-JSON-RPC body (e.g. a stray `{success,data}` envelope or an HTML page).
|
|
23
|
+
*/
|
|
24
|
+
function isMcpJsonRpcResponse(value) {
|
|
25
|
+
if (typeof value !== 'object' || value === null)
|
|
26
|
+
return false;
|
|
27
|
+
const obj = value;
|
|
28
|
+
if (!('id' in obj))
|
|
29
|
+
return false;
|
|
30
|
+
const id = obj.id;
|
|
31
|
+
if (!(typeof id === 'string' || typeof id === 'number' || id === null))
|
|
32
|
+
return false;
|
|
33
|
+
const hasResult = 'result' in obj;
|
|
34
|
+
const hasError = 'error' in obj && isValidError(obj.error);
|
|
35
|
+
return hasResult !== hasError;
|
|
36
|
+
}
|
|
37
|
+
/** Pull the first non-empty `data` payload out of an SSE body. */
|
|
38
|
+
function extractSseData(body) {
|
|
39
|
+
// Whole-body (non-streaming) parse: `parseSseFrames` only emits blocks closed
|
|
40
|
+
// by a blank line, leaving any unterminated trailing block in `carry`. A
|
|
41
|
+
// single final `data:` frame sent without the closing `\n\n` would otherwise
|
|
42
|
+
// be dropped — flush it by re-feeding `carry` with a terminator.
|
|
43
|
+
const { frames, carry } = (0, sse_client_1.parseSseFrames)(body, '');
|
|
44
|
+
const allFrames = carry.trim() === ''
|
|
45
|
+
? frames
|
|
46
|
+
: [...frames, ...(0, sse_client_1.parseSseFrames)('\n\n', carry).frames];
|
|
47
|
+
for (const frame of allFrames) {
|
|
48
|
+
if (frame.data !== '')
|
|
49
|
+
return frame.data;
|
|
50
|
+
}
|
|
51
|
+
throw new errors_1.ZarelError('MCP SSE response contained no data frame');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extract the typed JSON-RPC response from an MCP transport reply. The server
|
|
55
|
+
* frames `text/event-stream` as a single `message` data frame; everything else
|
|
56
|
+
* (application/json, or a JSON body with no/odd content-type) is parsed
|
|
57
|
+
* directly. A protocol-level JSON-RPC error is RETURNED in the union (the caller
|
|
58
|
+
* discriminates with `'error' in res`); a body that is not a valid JSON-RPC
|
|
59
|
+
* response throws `ZarelError`.
|
|
60
|
+
*/
|
|
61
|
+
function extractMcpResponse(contentType, bodyText) {
|
|
62
|
+
const isSse = contentType !== null && contentType.includes('text/event-stream');
|
|
63
|
+
const jsonText = isSse ? extractSseData(bodyText) : bodyText;
|
|
64
|
+
if (jsonText.trim() === '') {
|
|
65
|
+
throw new errors_1.ZarelError('MCP response body is empty');
|
|
66
|
+
}
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(jsonText);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new errors_1.ZarelError('MCP response body is not valid JSON');
|
|
73
|
+
}
|
|
74
|
+
if (!isMcpJsonRpcResponse(parsed)) {
|
|
75
|
+
throw new errors_1.ZarelError('MCP response is not a valid JSON-RPC response');
|
|
76
|
+
}
|
|
77
|
+
return parsed;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/_internal/mcp.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,4EAA4E;AAC5E,8EAA8E;AAC9E,mEAAmE;AACnE,+EAA+E;;AAsD/E,gDAgBC;AApED,sCAAuC;AAEvC,6CAA8C;AAE9C,SAAS,YAAY,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;QAAE,OAA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,CAAC,CAAC,QAAQ,CAAC;IAC7D,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,mBAAU,CAAC,4BAA4B,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACD,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACL,MAAM,IAAI,mBAAU,CAAC,qCAAqC,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,mBAAU,CAAC,+CAA+C,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-pagination (Track G2). Pure TS, zero runtime deps.
|
|
3
|
+
*
|
|
4
|
+
* `PagePromise<Page, Item>` is the value returned by the SDK's paginated `list`
|
|
5
|
+
* calls. It is simultaneously:
|
|
6
|
+
* - a `Promise<Page>` — `await list(...)` resolves to today's single-page shape
|
|
7
|
+
* (backward-compatible: the class implements the full `Promise<Page>`
|
|
8
|
+
* interface, so it stays assignable to the pre-G2 return type); and
|
|
9
|
+
* - an `AsyncIterable<Item>` — `for await (const item of list(...))` paginates
|
|
10
|
+
* over every item across all pages.
|
|
11
|
+
*
|
|
12
|
+
* A `PaginationStrategy` knows how to extract items from a page and how to
|
|
13
|
+
* advance to the next page (or signal exhaustion) for one of the three wire
|
|
14
|
+
* models (offset+total, cursor, bare-array-offset). Strategies use typed
|
|
15
|
+
* accessor functions — never `as` or a schema library (QI-004).
|
|
16
|
+
*
|
|
17
|
+
* No default page size is injected into the request: the first page is fetched
|
|
18
|
+
* with the caller's params verbatim (so `await list(...)` is byte-identical to
|
|
19
|
+
* pre-G2 — QI-001). Page size, where a strategy needs it, is the caller's
|
|
20
|
+
* `limit` or the size of the first page returned by the server.
|
|
21
|
+
*/
|
|
22
|
+
/** Per-page request parameters the iterator advances between pages. */
|
|
23
|
+
export interface PageParams {
|
|
24
|
+
limit?: number;
|
|
25
|
+
offset?: number;
|
|
26
|
+
cursor?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/** How to read items from a page and compute the next page's params. */
|
|
30
|
+
export interface PaginationStrategy<Page, Item> {
|
|
31
|
+
items(page: Page): readonly Item[];
|
|
32
|
+
/** Next page's params, or `null` when the result set is exhausted. */
|
|
33
|
+
nextParams(page: Page, current: PageParams, lastCount: number): PageParams | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Offset pagination with an authoritative `total` (e.g. records). Advances the
|
|
37
|
+
* offset by the number of items actually returned and stops once `total` is
|
|
38
|
+
* consumed — robust to a server page size that differs from any caller `limit`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function offsetWithTotal<Page, Item>(getItems: (page: Page) => readonly Item[], getTotal: (page: Page) => number): PaginationStrategy<Page, Item>;
|
|
41
|
+
/** Cursor pagination (e.g. traces). Follows the next cursor until it is null/absent. */
|
|
42
|
+
export declare function cursorBased<Page, Item>(getItems: (page: Page) => readonly Item[], getCursor: (page: Page) => string | null | undefined): PaginationStrategy<Page, Item>;
|
|
43
|
+
/**
|
|
44
|
+
* Offset pagination over a bare array with no `total`/cursor (e.g. conversation
|
|
45
|
+
* sessions). End-of-data is inferred from `lastCount < pageSize`, where the
|
|
46
|
+
* page size is the **server's actual first-page length** — never the caller's
|
|
47
|
+
* requested `limit`. Trusting the requested `limit` would silently drop data if
|
|
48
|
+
* the server capped a page below it (a full first page shorter than the
|
|
49
|
+
* requested `limit` would be misread as the final page). Consequences: (a) one
|
|
50
|
+
* extra request returns an empty page and iteration stops when the row count is
|
|
51
|
+
* an exact multiple of the page size; (b) one extra empty request when the
|
|
52
|
+
* whole result fits within the first page — both bounded, no item missed or
|
|
53
|
+
* duplicated. The requested `limit` is still sent as the per-request page size
|
|
54
|
+
* by the resource; this strategy governs only termination.
|
|
55
|
+
*/
|
|
56
|
+
export declare function bareArrayOffset<Item>(): PaginationStrategy<Item[], Item>;
|
|
57
|
+
/** A promise of the first page that can also be async-iterated over all items. */
|
|
58
|
+
export declare class PagePromise<Page, Item> implements Promise<Page>, AsyncIterable<Item> {
|
|
59
|
+
private readonly fetchPage;
|
|
60
|
+
private readonly strategy;
|
|
61
|
+
private readonly initialParams;
|
|
62
|
+
private firstPage?;
|
|
63
|
+
constructor(fetchPage: (params: PageParams) => Promise<Page>, strategy: PaginationStrategy<Page, Item>, initialParams: PageParams);
|
|
64
|
+
private getFirstPage;
|
|
65
|
+
then<TResult1 = Page, TResult2 = never>(onfulfilled?: ((value: Page) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
66
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<Page | TResult>;
|
|
67
|
+
finally(onfinally?: (() => void) | null): Promise<Page>;
|
|
68
|
+
get [Symbol.toStringTag](): string;
|
|
69
|
+
[Symbol.asyncIterator](): AsyncIterator<Item>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/_internal/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB,CAAC,IAAI,EAAE,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,UAAU;IAG9C,OAAO,CAAC,YAAY;IAOb,IAAI,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,GAAG,KAAK,EACzC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EACxE,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAC5E,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAIxB,KAAK,CAAC,OAAO,GAAG,KAAK,EACxB,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAC1E,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC;IAInB,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAExC;IAIa,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC;CAY9D"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auto-pagination (Track G2). Pure TS, zero runtime deps.
|
|
4
|
+
*
|
|
5
|
+
* `PagePromise<Page, Item>` is the value returned by the SDK's paginated `list`
|
|
6
|
+
* calls. It is simultaneously:
|
|
7
|
+
* - a `Promise<Page>` — `await list(...)` resolves to today's single-page shape
|
|
8
|
+
* (backward-compatible: the class implements the full `Promise<Page>`
|
|
9
|
+
* interface, so it stays assignable to the pre-G2 return type); and
|
|
10
|
+
* - an `AsyncIterable<Item>` — `for await (const item of list(...))` paginates
|
|
11
|
+
* over every item across all pages.
|
|
12
|
+
*
|
|
13
|
+
* A `PaginationStrategy` knows how to extract items from a page and how to
|
|
14
|
+
* advance to the next page (or signal exhaustion) for one of the three wire
|
|
15
|
+
* models (offset+total, cursor, bare-array-offset). Strategies use typed
|
|
16
|
+
* accessor functions — never `as` or a schema library (QI-004).
|
|
17
|
+
*
|
|
18
|
+
* No default page size is injected into the request: the first page is fetched
|
|
19
|
+
* with the caller's params verbatim (so `await list(...)` is byte-identical to
|
|
20
|
+
* pre-G2 — QI-001). Page size, where a strategy needs it, is the caller's
|
|
21
|
+
* `limit` or the size of the first page returned by the server.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.PagePromise = void 0;
|
|
25
|
+
exports.offsetWithTotal = offsetWithTotal;
|
|
26
|
+
exports.cursorBased = cursorBased;
|
|
27
|
+
exports.bareArrayOffset = bareArrayOffset;
|
|
28
|
+
/**
|
|
29
|
+
* Offset pagination with an authoritative `total` (e.g. records). Advances the
|
|
30
|
+
* offset by the number of items actually returned and stops once `total` is
|
|
31
|
+
* consumed — robust to a server page size that differs from any caller `limit`.
|
|
32
|
+
*/
|
|
33
|
+
function offsetWithTotal(getItems, getTotal) {
|
|
34
|
+
return {
|
|
35
|
+
items: getItems,
|
|
36
|
+
nextParams(page, current, lastCount) {
|
|
37
|
+
const total = getTotal(page);
|
|
38
|
+
const consumed = (current.offset ?? 0) + lastCount;
|
|
39
|
+
if (lastCount === 0 || consumed >= total)
|
|
40
|
+
return null;
|
|
41
|
+
return { ...current, offset: consumed };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Cursor pagination (e.g. traces). Follows the next cursor until it is null/absent. */
|
|
46
|
+
function cursorBased(getItems, getCursor) {
|
|
47
|
+
return {
|
|
48
|
+
items: getItems,
|
|
49
|
+
nextParams(page, current) {
|
|
50
|
+
const cursor = getCursor(page);
|
|
51
|
+
// Deliberate loose `==` — treats both null and undefined as terminal.
|
|
52
|
+
if (cursor == null)
|
|
53
|
+
return null;
|
|
54
|
+
return { ...current, cursor };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Offset pagination over a bare array with no `total`/cursor (e.g. conversation
|
|
60
|
+
* sessions). End-of-data is inferred from `lastCount < pageSize`, where the
|
|
61
|
+
* page size is the **server's actual first-page length** — never the caller's
|
|
62
|
+
* requested `limit`. Trusting the requested `limit` would silently drop data if
|
|
63
|
+
* the server capped a page below it (a full first page shorter than the
|
|
64
|
+
* requested `limit` would be misread as the final page). Consequences: (a) one
|
|
65
|
+
* extra request returns an empty page and iteration stops when the row count is
|
|
66
|
+
* an exact multiple of the page size; (b) one extra empty request when the
|
|
67
|
+
* whole result fits within the first page — both bounded, no item missed or
|
|
68
|
+
* duplicated. The requested `limit` is still sent as the per-request page size
|
|
69
|
+
* by the resource; this strategy governs only termination.
|
|
70
|
+
*/
|
|
71
|
+
function bareArrayOffset() {
|
|
72
|
+
let pageSize;
|
|
73
|
+
return {
|
|
74
|
+
items: (page) => page,
|
|
75
|
+
nextParams(_page, current, lastCount) {
|
|
76
|
+
if (pageSize === undefined)
|
|
77
|
+
pageSize = lastCount;
|
|
78
|
+
if (pageSize === 0 || lastCount < pageSize)
|
|
79
|
+
return null;
|
|
80
|
+
return { ...current, offset: (current.offset ?? 0) + lastCount };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** A promise of the first page that can also be async-iterated over all items. */
|
|
85
|
+
class PagePromise {
|
|
86
|
+
fetchPage;
|
|
87
|
+
strategy;
|
|
88
|
+
initialParams;
|
|
89
|
+
firstPage;
|
|
90
|
+
constructor(fetchPage, strategy, initialParams) {
|
|
91
|
+
this.fetchPage = fetchPage;
|
|
92
|
+
this.strategy = strategy;
|
|
93
|
+
this.initialParams = initialParams;
|
|
94
|
+
}
|
|
95
|
+
getFirstPage() {
|
|
96
|
+
if (!this.firstPage)
|
|
97
|
+
this.firstPage = this.fetchPage(this.initialParams);
|
|
98
|
+
return this.firstPage;
|
|
99
|
+
}
|
|
100
|
+
// ── Promise<Page> face (delegates to the lazy, memoized first page) ──
|
|
101
|
+
then(onfulfilled, onrejected) {
|
|
102
|
+
return this.getFirstPage().then(onfulfilled, onrejected);
|
|
103
|
+
}
|
|
104
|
+
catch(onrejected) {
|
|
105
|
+
return this.getFirstPage().catch(onrejected);
|
|
106
|
+
}
|
|
107
|
+
finally(onfinally) {
|
|
108
|
+
return this.getFirstPage().finally(onfinally);
|
|
109
|
+
}
|
|
110
|
+
get [Symbol.toStringTag]() {
|
|
111
|
+
return 'PagePromise';
|
|
112
|
+
}
|
|
113
|
+
// ── AsyncIterable<Item> face ──
|
|
114
|
+
async *[Symbol.asyncIterator]() {
|
|
115
|
+
let params = this.initialParams;
|
|
116
|
+
let page = await this.getFirstPage(); // reuse the memoized first page
|
|
117
|
+
for (;;) {
|
|
118
|
+
const items = this.strategy.items(page);
|
|
119
|
+
for (const item of items)
|
|
120
|
+
yield item;
|
|
121
|
+
const next = this.strategy.nextParams(page, params, items.length);
|
|
122
|
+
if (next === null)
|
|
123
|
+
return;
|
|
124
|
+
params = next;
|
|
125
|
+
page = await this.fetchPage(next);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.PagePromise = PagePromise;
|
|
130
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/_internal/pagination.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAsBH,0CAaC;AAGD,kCAaC;AAeD,0CAUC;AA3DD;;;;GAIG;AACH,SAAgB,eAAe,CAC3B,QAAyC,EACzC,QAAgC;IAEhC,OAAO;QACH,KAAK,EAAE,QAAQ;QACf,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS;YAC/B,MAAM,KAAK,GAAG,QAAQ,CAA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E,OAAO;YAC1B,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;IACL,CAAC;CACJ;AAnDD,kCAmDC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ZarelAuthErrorCode } from '../errors';
|
|
2
|
+
/**
|
|
3
|
+
* Spec 050 / FR-007 / FR-008 — guard that a plane's token is configured
|
|
4
|
+
* before any network I/O is attempted.
|
|
5
|
+
*
|
|
6
|
+
* Called at the entry of every resource method in `client.runtime.*` and
|
|
7
|
+
* `client.contract.*`. The check is pure and deterministic — no side
|
|
8
|
+
* effects beyond the throw. The thrown `ZarelAuthError.code` is one of
|
|
9
|
+
* `'runtime_token_missing'` or `'contract_token_missing'`; server-issued
|
|
10
|
+
* 401s use `'unauthorized'` and are raised by FetchClient instead.
|
|
11
|
+
*
|
|
12
|
+
* Per ADR-0098, JWT-class and API-key-prefix validation is the server's
|
|
13
|
+
* responsibility (runtime-api / contract-api sentinel middleware); this
|
|
14
|
+
* helper does NOT inspect token contents — only presence.
|
|
15
|
+
*/
|
|
16
|
+
export declare function requireToken(token: string | undefined, code: Extract<ZarelAuthErrorCode, 'runtime_token_missing' | 'contract_token_missing'>): void;
|
|
17
|
+
//# sourceMappingURL=require-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-token.d.ts","sourceRoot":"","sources":["../../src/_internal/require-token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,EAAE,OAAO,CAAC,kBAAkB,EAAE,uBAAuB,GAAG,wBAAwB,CAAC,GACtF,IAAI,CAON"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireToken = requireToken;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
/**
|
|
6
|
+
* Spec 050 / FR-007 / FR-008 — guard that a plane's token is configured
|
|
7
|
+
* before any network I/O is attempted.
|
|
8
|
+
*
|
|
9
|
+
* Called at the entry of every resource method in `client.runtime.*` and
|
|
10
|
+
* `client.contract.*`. The check is pure and deterministic — no side
|
|
11
|
+
* effects beyond the throw. The thrown `ZarelAuthError.code` is one of
|
|
12
|
+
* `'runtime_token_missing'` or `'contract_token_missing'`; server-issued
|
|
13
|
+
* 401s use `'unauthorized'` and are raised by FetchClient instead.
|
|
14
|
+
*
|
|
15
|
+
* Per ADR-0098, JWT-class and API-key-prefix validation is the server's
|
|
16
|
+
* responsibility (runtime-api / contract-api sentinel middleware); this
|
|
17
|
+
* helper does NOT inspect token contents — only presence.
|
|
18
|
+
*/
|
|
19
|
+
function requireToken(token, code) {
|
|
20
|
+
if (token && token.length > 0)
|
|
21
|
+
return;
|
|
22
|
+
const plane = code === 'runtime_token_missing' ? 'runtime' : 'contract';
|
|
23
|
+
throw new errors_1.ZarelAuthError(`${plane} token not configured — pass ${plane}Token to Zarel constructor`, code);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=require-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-token.js","sourceRoot":"","sources":["../../src/_internal/require-token.ts"],"names":[],"mappings":";;AAiBA,oCAUC;AA3BD,sCAA2C;AAG3C;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CACxB,KAAyB,EACzB,IAAqF;IAErF,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO;IACtC,MAAM,KAAK,GAAG,IAAI,KAAK,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACxE,MAAM,IAAI,uBAAc,CACpB,GAAG,KAAK,gCAAgC,KAAK,4BAA4B,EACzE,IAAI,CACP,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/_internal/retry-after.ts"],"names":[],"mappings":"AASA,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBvF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRetryAfter = parseRetryAfter;
|
|
4
|
+
// Pure parser for the HTTP `Retry-After` response header (RFC 7231 §7.1.3).
|
|
5
|
+
// Two forms are accepted: an integer count of seconds (delta-seconds) and an
|
|
6
|
+
// HTTP-date. Returns a NON-NEGATIVE millisecond delay, or `undefined` when the
|
|
7
|
+
// header is absent/unparseable. The caller injects `nowMs` (so the HTTP-date
|
|
8
|
+
// arithmetic is deterministic and testable) and is responsible for clamping the
|
|
9
|
+
// result to a ceiling — this module is parsing only, no policy.
|
|
10
|
+
//
|
|
11
|
+
// No `as` cast, no schema library — hand-written narrowing (the SDK's zero-dep,
|
|
12
|
+
// no-Zod boundary convention).
|
|
13
|
+
function parseRetryAfter(value, nowMs) {
|
|
14
|
+
if (value === null)
|
|
15
|
+
return undefined;
|
|
16
|
+
const trimmed = value.trim();
|
|
17
|
+
if (trimmed === '')
|
|
18
|
+
return undefined;
|
|
19
|
+
// delta-seconds: an integer number of seconds (RFC 7231 requires an integer).
|
|
20
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
21
|
+
const seconds = Number(trimmed);
|
|
22
|
+
return Math.max(0, seconds * 1000);
|
|
23
|
+
}
|
|
24
|
+
// HTTP-date: must contain letters (month/day names + "GMT") — this rejects
|
|
25
|
+
// bare numerics like "1.5"/"1e3" that `Date.parse` would otherwise coerce
|
|
26
|
+
// into a year. A real HTTP-date → delta from now, floored at 0.
|
|
27
|
+
if (!/[a-zA-Z]/.test(trimmed))
|
|
28
|
+
return undefined;
|
|
29
|
+
const parsed = Date.parse(trimmed);
|
|
30
|
+
if (Number.isNaN(parsed))
|
|
31
|
+
return undefined;
|
|
32
|
+
return Math.max(0, parsed - nowMs);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=retry-after.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-after.js","sourceRoot":"","sources":["../../src/_internal/retry-after.ts"],"names":[],"mappings":";;AASA,0CAkBC;AA3BD,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAChE,EAAE;AACF,gFAAgF;AAChF,+BAA+B;AAC/B,SAAgB,eAAe,CAAC,KAAoB,EAAE,KAAa;IAC/D,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAErC,8EAA8E;IAC9E,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,2EAA2E;IAC3E,0EAA0E;IAC1E,gEAAgE;IAChE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { EventStreamHandle, EventStreamHandlers, EventStreamOptions } from '../types/events-stream';
|
|
2
|
+
export interface RawSseFrame {
|
|
3
|
+
event?: string;
|
|
4
|
+
data: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
retry?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Incrementally parse SSE text. Pure over `(chunk, carry)`: returns the complete
|
|
10
|
+
* frames found and the leftover `carry` (an unterminated trailing block) to feed
|
|
11
|
+
* into the next call. Frames are delimited by a blank line (`\n\n`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseSseFrames(chunk: string, carry: string): {
|
|
14
|
+
frames: RawSseFrame[];
|
|
15
|
+
carry: string;
|
|
16
|
+
};
|
|
17
|
+
/** The outcome of one connect attempt, classified by the transport. */
|
|
18
|
+
export type ConnectOutcome = {
|
|
19
|
+
kind: 'open';
|
|
20
|
+
body: ReadableStream<Uint8Array>;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'terminal';
|
|
23
|
+
error: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'transient';
|
|
26
|
+
error?: unknown;
|
|
27
|
+
};
|
|
28
|
+
export interface StreamLoopDeps {
|
|
29
|
+
/** One connect attempt. Resolves an open body, or a terminal/transient disposition. */
|
|
30
|
+
connect: (lastEventId: string | undefined, signal: AbortSignal) => Promise<ConnectOutcome>;
|
|
31
|
+
handlers: EventStreamHandlers;
|
|
32
|
+
options: EventStreamOptions;
|
|
33
|
+
baseDelayMs?: number;
|
|
34
|
+
maxDelayMs?: number;
|
|
35
|
+
sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Drive a self-reconnecting SSE consumption loop. Returns an `EventStreamHandle`
|
|
39
|
+
* synchronously; the first connect happens asynchronously. Reconnect attempts are
|
|
40
|
+
* UNBOUNDED (until `close()`/abort/terminal); only the per-attempt delay is capped.
|
|
41
|
+
*/
|
|
42
|
+
export declare function runEventStream(deps: StreamLoopDeps): EventStreamHandle;
|
|
43
|
+
//# sourceMappingURL=sse-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-client.d.ts","sourceRoot":"","sources":["../../src/_internal/sse-client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EACrB,MAAM,wBAAwB,CAAC;AAUhC,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAoDD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAcrG;AAID,uEAAuE;AACvE,MAAM,MAAM,cAAc,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC3B,uFAAuF;IACvF,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3F,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,EAAE,kBAAkB,CAAC;IAE5B,WAAW,CAAC,EAAE,MAAM,CAAC;I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