omnicell-router 0.7.0 → 0.8.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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CanonicalResponse, StreamEvent } from '../types.js';
|
|
2
|
+
export interface ResponsesEcho {
|
|
3
|
+
instructions: string | null;
|
|
4
|
+
metadata: Record<string, unknown> | null;
|
|
5
|
+
temperature: number | null;
|
|
6
|
+
top_p: number | null;
|
|
7
|
+
max_output_tokens: number | null;
|
|
8
|
+
tool_choice: unknown;
|
|
9
|
+
parallel_tool_calls: boolean;
|
|
10
|
+
previous_response_id: string | null;
|
|
11
|
+
service_tier: string | null;
|
|
12
|
+
tools: Record<string, unknown>[];
|
|
13
|
+
text?: unknown;
|
|
14
|
+
reasoning?: unknown;
|
|
15
|
+
truncation?: 'auto' | 'disabled';
|
|
16
|
+
background?: boolean;
|
|
17
|
+
include?: string[];
|
|
18
|
+
prompt?: unknown;
|
|
19
|
+
conversation?: unknown;
|
|
20
|
+
safety_identifier?: string | null;
|
|
21
|
+
}
|
|
22
|
+
export declare function defaultResponsesEcho(): ResponsesEcho;
|
|
23
|
+
export interface ResponsesStreamSequence {
|
|
24
|
+
value: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function newResponseStreamSequence(): ResponsesStreamSequence;
|
|
27
|
+
export declare function newResponseMessageId(): string;
|
|
28
|
+
export declare function canonicalToResponsesObject(response: CanonicalResponse, ids: {
|
|
29
|
+
respId: string;
|
|
30
|
+
messageId?: string;
|
|
31
|
+
}, model: string, store?: boolean, echo?: ResponsesEcho): Record<string, unknown>;
|
|
32
|
+
export declare function responsesEventFrame(payload: Record<string, unknown>): string;
|
|
33
|
+
/** One stateful encoder per Responses client stream. */
|
|
34
|
+
export declare class ResponsesEventEncoder {
|
|
35
|
+
private readonly respId;
|
|
36
|
+
private readonly messageId;
|
|
37
|
+
private readonly seq;
|
|
38
|
+
private readonly store;
|
|
39
|
+
private readonly echo;
|
|
40
|
+
private readonly itemIds;
|
|
41
|
+
private readonly customItems;
|
|
42
|
+
private terminal;
|
|
43
|
+
constructor(respId: string, messageId: string, seq: ResponsesStreamSequence, store: boolean, echo: ResponsesEcho);
|
|
44
|
+
encode(event: StreamEvent, model: string, finalResponse?: CanonicalResponse): Record<string, unknown>[];
|
|
45
|
+
private itemId;
|
|
46
|
+
private item;
|
|
47
|
+
private isCustom;
|
|
48
|
+
private responseObject;
|
|
49
|
+
private sequenced;
|
|
50
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { IrUnsupportedError } from '../errors.js';
|
|
3
|
+
import { assertCanonicalResponseSupported, assertCanonicalStreamEventSupported } from '../validate.js';
|
|
4
|
+
import { responsesPartToWire } from './responses.js';
|
|
5
|
+
const PROTOCOL = 'openai-responses';
|
|
6
|
+
function shortId(prefix) {
|
|
7
|
+
return prefix + crypto.randomBytes(12).toString('hex');
|
|
8
|
+
}
|
|
9
|
+
export function defaultResponsesEcho() {
|
|
10
|
+
return {
|
|
11
|
+
instructions: null,
|
|
12
|
+
metadata: null,
|
|
13
|
+
temperature: null,
|
|
14
|
+
top_p: null,
|
|
15
|
+
max_output_tokens: null,
|
|
16
|
+
tool_choice: 'auto',
|
|
17
|
+
parallel_tool_calls: true,
|
|
18
|
+
previous_response_id: null,
|
|
19
|
+
service_tier: null,
|
|
20
|
+
tools: [],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function newResponseStreamSequence() {
|
|
24
|
+
return { value: 0 };
|
|
25
|
+
}
|
|
26
|
+
export function newResponseMessageId() {
|
|
27
|
+
return shortId('msg_');
|
|
28
|
+
}
|
|
29
|
+
function responsesUsage(usage) {
|
|
30
|
+
return {
|
|
31
|
+
input_tokens: usage.inputTokens,
|
|
32
|
+
output_tokens: usage.outputTokens,
|
|
33
|
+
total_tokens: usage.totalTokens ?? usage.inputTokens + usage.outputTokens,
|
|
34
|
+
...((usage.cachedInputTokens !== undefined || usage.audioInputTokens !== undefined)
|
|
35
|
+
? {
|
|
36
|
+
input_tokens_details: {
|
|
37
|
+
...(usage.cachedInputTokens !== undefined ? { cached_tokens: usage.cachedInputTokens } : {}),
|
|
38
|
+
...(usage.audioInputTokens !== undefined ? { audio_tokens: usage.audioInputTokens } : {}),
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
...((usage.reasoningTokens !== undefined || usage.audioOutputTokens !== undefined ||
|
|
43
|
+
usage.acceptedPredictionTokens !== undefined || usage.rejectedPredictionTokens !== undefined)
|
|
44
|
+
? {
|
|
45
|
+
output_tokens_details: {
|
|
46
|
+
...(usage.reasoningTokens !== undefined ? { reasoning_tokens: usage.reasoningTokens } : {}),
|
|
47
|
+
...(usage.audioOutputTokens !== undefined ? { audio_tokens: usage.audioOutputTokens } : {}),
|
|
48
|
+
...(usage.acceptedPredictionTokens !== undefined
|
|
49
|
+
? { accepted_prediction_tokens: usage.acceptedPredictionTokens } : {}),
|
|
50
|
+
...(usage.rejectedPredictionTokens !== undefined
|
|
51
|
+
? { rejected_prediction_tokens: usage.rejectedPredictionTokens } : {}),
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
: {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function outputPartToWire(part) {
|
|
58
|
+
return responsesPartToWire(part, 'assistant');
|
|
59
|
+
}
|
|
60
|
+
function outputItemToWire(item, messageId) {
|
|
61
|
+
if (item.type === 'message') {
|
|
62
|
+
return {
|
|
63
|
+
type: 'message',
|
|
64
|
+
id: item.id ?? messageId ?? shortId('msg_'),
|
|
65
|
+
status: item.status ?? 'completed',
|
|
66
|
+
role: 'assistant',
|
|
67
|
+
content: item.content.map(outputPartToWire),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (item.type === 'tool_call') {
|
|
71
|
+
const custom = item.vendor?.[PROTOCOL]?.itemType === 'custom_tool_call';
|
|
72
|
+
return {
|
|
73
|
+
type: custom ? 'custom_tool_call' : 'function_call',
|
|
74
|
+
id: item.id || shortId(custom ? 'ctc_' : 'fc_'),
|
|
75
|
+
call_id: item.callId ?? item.id,
|
|
76
|
+
name: item.name,
|
|
77
|
+
...(custom ? { input: item.arguments } : { arguments: item.arguments }),
|
|
78
|
+
status: item.status ?? 'completed',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (item.type === 'reasoning') {
|
|
82
|
+
return {
|
|
83
|
+
type: 'reasoning',
|
|
84
|
+
id: item.id ?? shortId('rs_'),
|
|
85
|
+
status: item.status ?? 'completed',
|
|
86
|
+
summary: item.summary?.map((text) => ({ type: 'summary_text', text })) ?? [],
|
|
87
|
+
...(item.text ? { content: [{ type: 'reasoning_text', text: item.text }] } : {}),
|
|
88
|
+
...(item.signature ? { signature: item.signature } : {}),
|
|
89
|
+
...(item.encrypted ? { encrypted_content: item.encrypted } : {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (item.protocol !== PROTOCOL) {
|
|
93
|
+
throw new IrUnsupportedError('output_item', `Cannot convert ${item.protocol} output to Responses.`, PROTOCOL);
|
|
94
|
+
}
|
|
95
|
+
return item.payload;
|
|
96
|
+
}
|
|
97
|
+
export function canonicalToResponsesObject(response, ids, model, store = true, echo = defaultResponsesEcho()) {
|
|
98
|
+
assertCanonicalResponseSupported(response, PROTOCOL);
|
|
99
|
+
const incompleteReason = response.status === 'incomplete'
|
|
100
|
+
? response.reason === 'content_filter' ? 'content_filter' : 'max_output_tokens'
|
|
101
|
+
: null;
|
|
102
|
+
return {
|
|
103
|
+
id: ids.respId,
|
|
104
|
+
object: 'response',
|
|
105
|
+
created_at: response.createdAt ?? Math.floor(Date.now() / 1000),
|
|
106
|
+
status: response.status,
|
|
107
|
+
error: response.error ?? null,
|
|
108
|
+
incomplete_details: incompleteReason ? { reason: incompleteReason } : null,
|
|
109
|
+
instructions: echo.instructions,
|
|
110
|
+
metadata: echo.metadata,
|
|
111
|
+
model,
|
|
112
|
+
output: response.output.map((item, index) => outputItemToWire(item, index === 0 ? ids.messageId : undefined)),
|
|
113
|
+
parallel_tool_calls: echo.parallel_tool_calls,
|
|
114
|
+
temperature: echo.temperature,
|
|
115
|
+
tool_choice: echo.tool_choice,
|
|
116
|
+
tools: echo.tools,
|
|
117
|
+
top_p: echo.top_p,
|
|
118
|
+
max_output_tokens: echo.max_output_tokens,
|
|
119
|
+
previous_response_id: response.previousResponseId ?? echo.previous_response_id,
|
|
120
|
+
service_tier: response.serviceTier ?? echo.service_tier,
|
|
121
|
+
store,
|
|
122
|
+
text: echo.text ?? { format: { type: 'text' } },
|
|
123
|
+
reasoning: echo.reasoning ?? null,
|
|
124
|
+
truncation: echo.truncation ?? 'disabled',
|
|
125
|
+
background: echo.background ?? false,
|
|
126
|
+
include: echo.include ?? [],
|
|
127
|
+
prompt: echo.prompt ?? null,
|
|
128
|
+
conversation: echo.conversation ?? null,
|
|
129
|
+
safety_identifier: echo.safety_identifier ?? null,
|
|
130
|
+
usage: responsesUsage(response.usage),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function responsesEventFrame(payload) {
|
|
134
|
+
return `event: ${payload.type}\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
135
|
+
}
|
|
136
|
+
/** One stateful encoder per Responses client stream. */
|
|
137
|
+
export class ResponsesEventEncoder {
|
|
138
|
+
respId;
|
|
139
|
+
messageId;
|
|
140
|
+
seq;
|
|
141
|
+
store;
|
|
142
|
+
echo;
|
|
143
|
+
itemIds = new Map();
|
|
144
|
+
customItems = new Set();
|
|
145
|
+
terminal = false;
|
|
146
|
+
constructor(respId, messageId, seq, store, echo) {
|
|
147
|
+
this.respId = respId;
|
|
148
|
+
this.messageId = messageId;
|
|
149
|
+
this.seq = seq;
|
|
150
|
+
this.store = store;
|
|
151
|
+
this.echo = echo;
|
|
152
|
+
}
|
|
153
|
+
encode(event, model, finalResponse) {
|
|
154
|
+
assertCanonicalStreamEventSupported(event, PROTOCOL);
|
|
155
|
+
if ((event.candidateIndex ?? 0) !== 0)
|
|
156
|
+
return [];
|
|
157
|
+
if (event.type === 'response.created') {
|
|
158
|
+
const response = this.responseObject(finalResponse, model, 'in_progress', true);
|
|
159
|
+
return [this.sequenced({ type: 'response.created', response }), this.sequenced({ type: 'response.in_progress', response })];
|
|
160
|
+
}
|
|
161
|
+
if (event.type === 'response.output_item.added') {
|
|
162
|
+
const item = this.item(event.index, event.item, true);
|
|
163
|
+
return [this.sequenced({ type: 'response.output_item.added', output_index: event.index, item })];
|
|
164
|
+
}
|
|
165
|
+
if (event.type === 'response.content_part.added') {
|
|
166
|
+
return [this.sequenced({
|
|
167
|
+
type: 'response.content_part.added', item_id: this.itemId(event.index), output_index: event.index,
|
|
168
|
+
content_index: event.partIndex, part: outputPartToWire(event.part),
|
|
169
|
+
})];
|
|
170
|
+
}
|
|
171
|
+
if (event.type === 'response.output_text.delta') {
|
|
172
|
+
return [this.sequenced({
|
|
173
|
+
type: 'response.output_text.delta', item_id: this.itemId(event.index), output_index: event.index,
|
|
174
|
+
content_index: event.partIndex, delta: event.text,
|
|
175
|
+
})];
|
|
176
|
+
}
|
|
177
|
+
if (event.type === 'response.output_text.done') {
|
|
178
|
+
return [this.sequenced({
|
|
179
|
+
type: 'response.output_text.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
180
|
+
content_index: event.partIndex, text: event.text,
|
|
181
|
+
})];
|
|
182
|
+
}
|
|
183
|
+
if (event.type === 'response.output_text.annotation.added') {
|
|
184
|
+
const annotations = outputPartToWire({ type: 'text', text: '', annotations: [event.annotation] }).annotations;
|
|
185
|
+
return [this.sequenced({
|
|
186
|
+
type: 'response.output_text.annotation.added', item_id: this.itemId(event.index), output_index: event.index,
|
|
187
|
+
content_index: event.partIndex, annotation_index: event.annotationIndex,
|
|
188
|
+
annotation: Array.isArray(annotations) ? annotations[0] : annotations,
|
|
189
|
+
})];
|
|
190
|
+
}
|
|
191
|
+
if (event.type === 'response.refusal.delta') {
|
|
192
|
+
return [this.sequenced({
|
|
193
|
+
type: 'response.refusal.delta', item_id: this.itemId(event.index), output_index: event.index,
|
|
194
|
+
content_index: event.partIndex, delta: event.text,
|
|
195
|
+
})];
|
|
196
|
+
}
|
|
197
|
+
if (event.type === 'response.refusal.done') {
|
|
198
|
+
return [this.sequenced({
|
|
199
|
+
type: 'response.refusal.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
200
|
+
content_index: event.partIndex, refusal: event.text,
|
|
201
|
+
})];
|
|
202
|
+
}
|
|
203
|
+
if (event.type === 'response.reasoning.delta') {
|
|
204
|
+
return [this.sequenced({
|
|
205
|
+
type: 'response.reasoning_text.delta', item_id: this.itemId(event.index), output_index: event.index,
|
|
206
|
+
content_index: 0, delta: event.text,
|
|
207
|
+
})];
|
|
208
|
+
}
|
|
209
|
+
if (event.type === 'response.reasoning.done') {
|
|
210
|
+
return [this.sequenced({
|
|
211
|
+
type: 'response.reasoning_text.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
212
|
+
content_index: 0, text: event.text,
|
|
213
|
+
})];
|
|
214
|
+
}
|
|
215
|
+
if (event.type === 'response.reasoning_summary_part.added') {
|
|
216
|
+
return [this.sequenced({
|
|
217
|
+
type: 'response.reasoning_summary_part.added', item_id: this.itemId(event.index), output_index: event.index,
|
|
218
|
+
summary_index: event.summaryIndex, part: { type: 'summary_text', text: '' },
|
|
219
|
+
})];
|
|
220
|
+
}
|
|
221
|
+
if (event.type === 'response.reasoning_summary.delta') {
|
|
222
|
+
return [this.sequenced({
|
|
223
|
+
type: 'response.reasoning_summary_text.delta', item_id: this.itemId(event.index), output_index: event.index,
|
|
224
|
+
summary_index: event.summaryIndex, delta: event.text,
|
|
225
|
+
})];
|
|
226
|
+
}
|
|
227
|
+
if (event.type === 'response.reasoning_summary.done') {
|
|
228
|
+
return [
|
|
229
|
+
this.sequenced({
|
|
230
|
+
type: 'response.reasoning_summary_text.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
231
|
+
summary_index: event.summaryIndex, text: event.text,
|
|
232
|
+
}),
|
|
233
|
+
this.sequenced({
|
|
234
|
+
type: 'response.reasoning_summary_part.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
235
|
+
summary_index: event.summaryIndex, part: { type: 'summary_text', text: event.text },
|
|
236
|
+
}),
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
if (event.type === 'response.function_call.arguments.delta') {
|
|
240
|
+
const custom = this.isCustom(event.index);
|
|
241
|
+
return [this.sequenced({
|
|
242
|
+
type: custom ? 'response.custom_tool_call_input.delta' : 'response.function_call_arguments.delta',
|
|
243
|
+
item_id: this.itemId(event.index), output_index: event.index, delta: event.argumentsDelta,
|
|
244
|
+
})];
|
|
245
|
+
}
|
|
246
|
+
if (event.type === 'response.function_call.arguments.done') {
|
|
247
|
+
const custom = this.isCustom(event.index);
|
|
248
|
+
return [this.sequenced({
|
|
249
|
+
type: custom ? 'response.custom_tool_call_input.done' : 'response.function_call_arguments.done',
|
|
250
|
+
item_id: this.itemId(event.index), output_index: event.index,
|
|
251
|
+
...(custom ? { input: event.arguments } : { arguments: event.arguments }),
|
|
252
|
+
})];
|
|
253
|
+
}
|
|
254
|
+
if (event.type === 'response.content_part.done') {
|
|
255
|
+
return [this.sequenced({
|
|
256
|
+
type: 'response.content_part.done', item_id: this.itemId(event.index), output_index: event.index,
|
|
257
|
+
content_index: event.partIndex, part: outputPartToWire(event.part),
|
|
258
|
+
})];
|
|
259
|
+
}
|
|
260
|
+
if (event.type === 'response.output_item.done') {
|
|
261
|
+
return [this.sequenced({
|
|
262
|
+
type: 'response.output_item.done', output_index: event.index, item: this.item(event.index, event.item, false),
|
|
263
|
+
})];
|
|
264
|
+
}
|
|
265
|
+
if (event.type === 'response.completed' || event.type === 'response.incomplete' || event.type === 'response.failed') {
|
|
266
|
+
if (!finalResponse || this.terminal)
|
|
267
|
+
return [];
|
|
268
|
+
this.terminal = true;
|
|
269
|
+
return [this.sequenced({
|
|
270
|
+
type: event.type,
|
|
271
|
+
response: this.responseObject(finalResponse, model, finalResponse.status, false),
|
|
272
|
+
})];
|
|
273
|
+
}
|
|
274
|
+
if (event.type === 'error') {
|
|
275
|
+
if (this.terminal)
|
|
276
|
+
return [];
|
|
277
|
+
this.terminal = true;
|
|
278
|
+
const failed = {
|
|
279
|
+
status: 'failed', reason: 'error', output: [],
|
|
280
|
+
usage: { inputTokens: 0, outputTokens: 0 }, error: { code: event.code, message: event.message },
|
|
281
|
+
};
|
|
282
|
+
return [this.sequenced({ type: 'response.failed', response: this.responseObject(failed, model, 'failed', false) })];
|
|
283
|
+
}
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
itemId(index, item) {
|
|
287
|
+
const existing = this.itemIds.get(index);
|
|
288
|
+
if (existing)
|
|
289
|
+
return existing;
|
|
290
|
+
if (!item) {
|
|
291
|
+
throw new IrUnsupportedError('stream_lifecycle', `Responses stream references unopened output item ${index}.`, PROTOCOL);
|
|
292
|
+
}
|
|
293
|
+
const sourceId = 'id' in item && typeof item.id === 'string' ? item.id : undefined;
|
|
294
|
+
const id = sourceId ?? (item.type === 'message' && index === 0 ? this.messageId : undefined)
|
|
295
|
+
?? shortId(item.type === 'message' ? 'msg_' : item.type === 'reasoning' ? 'rs_'
|
|
296
|
+
: item.type === 'tool_call' && item.vendor?.[PROTOCOL]?.itemType === 'custom_tool_call' ? 'ctc_' : 'fc_');
|
|
297
|
+
this.itemIds.set(index, id);
|
|
298
|
+
return id;
|
|
299
|
+
}
|
|
300
|
+
item(index, source, opening) {
|
|
301
|
+
if (source.type === 'tool_call' && source.vendor?.[PROTOCOL]?.itemType === 'custom_tool_call') {
|
|
302
|
+
this.customItems.add(index);
|
|
303
|
+
}
|
|
304
|
+
const wire = outputItemToWire(source, this.itemId(index, source));
|
|
305
|
+
wire.id = this.itemId(index, source);
|
|
306
|
+
if (opening) {
|
|
307
|
+
wire.status = 'in_progress';
|
|
308
|
+
if (source.type === 'message')
|
|
309
|
+
wire.content = [];
|
|
310
|
+
if (source.type === 'tool_call') {
|
|
311
|
+
if (wire.type === 'custom_tool_call')
|
|
312
|
+
wire.input = '';
|
|
313
|
+
else
|
|
314
|
+
wire.arguments = '';
|
|
315
|
+
}
|
|
316
|
+
if (source.type === 'reasoning') {
|
|
317
|
+
wire.summary = [];
|
|
318
|
+
delete wire.content;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return wire;
|
|
322
|
+
}
|
|
323
|
+
isCustom(index) {
|
|
324
|
+
return this.customItems.has(index);
|
|
325
|
+
}
|
|
326
|
+
responseObject(response, model, status, opening) {
|
|
327
|
+
const base = response ?? {
|
|
328
|
+
status: 'completed', output: [], usage: { inputTokens: 0, outputTokens: 0 },
|
|
329
|
+
};
|
|
330
|
+
const object = canonicalToResponsesObject(base, {
|
|
331
|
+
respId: this.respId, messageId: this.messageId,
|
|
332
|
+
}, model, this.store, this.echo);
|
|
333
|
+
object.status = status;
|
|
334
|
+
if (opening)
|
|
335
|
+
object.output = [];
|
|
336
|
+
else if (Array.isArray(object.output)) {
|
|
337
|
+
object.output.forEach((item, index) => {
|
|
338
|
+
const id = this.itemIds.get(index);
|
|
339
|
+
if (id)
|
|
340
|
+
item.id = id;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return object;
|
|
344
|
+
}
|
|
345
|
+
sequenced(payload) {
|
|
346
|
+
return { sequence_number: this.seq.value++, ...payload };
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StreamEvent } from '../types.js';
|
|
2
|
+
/** Stateful OpenAI Responses SSE → canonical item lifecycle decoder. */
|
|
3
|
+
export declare class ResponsesStreamDecoder {
|
|
4
|
+
private nativeTerminal;
|
|
5
|
+
private terminalSent;
|
|
6
|
+
private createdSent;
|
|
7
|
+
private readonly annotations;
|
|
8
|
+
get terminated(): boolean;
|
|
9
|
+
push(raw: unknown): StreamEvent[];
|
|
10
|
+
finish(): StreamEvent[];
|
|
11
|
+
private key;
|
|
12
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { IrUpstreamError } from '../errors.js';
|
|
2
|
+
import { responsesAnnotationFromWire, responsesPartFromWire, responsesResponseToIR, responsesUsageFromWire, } from './responses.js';
|
|
3
|
+
function record(value) {
|
|
4
|
+
return value && typeof value === 'object' ? value : {};
|
|
5
|
+
}
|
|
6
|
+
function invalid(message) {
|
|
7
|
+
throw new IrUpstreamError(`Invalid Responses stream: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
function itemFromWire(raw) {
|
|
10
|
+
const item = responsesResponseToIR({ status: 'in_progress', output: [raw] }).output[0];
|
|
11
|
+
if (!item)
|
|
12
|
+
invalid('output_item did not contain an item.');
|
|
13
|
+
return item;
|
|
14
|
+
}
|
|
15
|
+
/** Stateful OpenAI Responses SSE → canonical item lifecycle decoder. */
|
|
16
|
+
export class ResponsesStreamDecoder {
|
|
17
|
+
nativeTerminal = false;
|
|
18
|
+
terminalSent = false;
|
|
19
|
+
createdSent = false;
|
|
20
|
+
annotations = new Map();
|
|
21
|
+
get terminated() {
|
|
22
|
+
return this.nativeTerminal;
|
|
23
|
+
}
|
|
24
|
+
push(raw) {
|
|
25
|
+
const frame = record(raw);
|
|
26
|
+
const type = String(frame.type ?? '');
|
|
27
|
+
const index = typeof frame.output_index === 'number' ? frame.output_index : 0;
|
|
28
|
+
const partIndex = typeof frame.content_index === 'number' ? frame.content_index : 0;
|
|
29
|
+
const summaryIndex = typeof frame.summary_index === 'number' ? frame.summary_index : 0;
|
|
30
|
+
if (type === 'response.created') {
|
|
31
|
+
this.createdSent = true;
|
|
32
|
+
const response = record(frame.response);
|
|
33
|
+
return [{
|
|
34
|
+
type: 'response.created',
|
|
35
|
+
...(typeof response.id === 'string' ? { id: response.id } : {}),
|
|
36
|
+
...(typeof response.model === 'string' ? { model: response.model } : {}),
|
|
37
|
+
...(typeof response.created_at === 'number' ? { createdAt: response.created_at } : {}),
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
if (type === 'response.output_item.added' || type === 'response.output_item.done') {
|
|
41
|
+
return [{
|
|
42
|
+
type: type === 'response.output_item.added' ? 'response.output_item.added' : 'response.output_item.done',
|
|
43
|
+
index,
|
|
44
|
+
item: itemFromWire(frame.item),
|
|
45
|
+
}];
|
|
46
|
+
}
|
|
47
|
+
if (type === 'response.content_part.added' || type === 'response.content_part.done') {
|
|
48
|
+
const part = responsesPartFromWire(frame.part);
|
|
49
|
+
if (part.type === 'text' && part.annotations)
|
|
50
|
+
this.annotations.set(this.key(index, partIndex), part.annotations);
|
|
51
|
+
return [{
|
|
52
|
+
type: type === 'response.content_part.added' ? 'response.content_part.added' : 'response.content_part.done',
|
|
53
|
+
index, partIndex, part,
|
|
54
|
+
}];
|
|
55
|
+
}
|
|
56
|
+
if (type === 'response.output_text.delta' || type === 'response.output_text.done') {
|
|
57
|
+
if (typeof frame.delta === 'string' && type.endsWith('.delta')) {
|
|
58
|
+
return [{ type: 'response.output_text.delta', index, partIndex, text: frame.delta }];
|
|
59
|
+
}
|
|
60
|
+
if (typeof frame.text === 'string') {
|
|
61
|
+
const annotations = this.annotations.get(this.key(index, partIndex));
|
|
62
|
+
return [{
|
|
63
|
+
type: 'response.output_text.done', index, partIndex, text: frame.text,
|
|
64
|
+
...(annotations ? { annotations } : {}),
|
|
65
|
+
}];
|
|
66
|
+
}
|
|
67
|
+
invalid(`${type} requires its text payload.`);
|
|
68
|
+
}
|
|
69
|
+
if (type === 'response.output_text.annotation.added') {
|
|
70
|
+
const annotation = responsesAnnotationFromWire(frame.annotation);
|
|
71
|
+
const key = this.key(index, partIndex);
|
|
72
|
+
const list = this.annotations.get(key) ?? [];
|
|
73
|
+
list.push(annotation);
|
|
74
|
+
this.annotations.set(key, list);
|
|
75
|
+
return [{
|
|
76
|
+
type: 'response.output_text.annotation.added', index, partIndex,
|
|
77
|
+
annotationIndex: typeof frame.annotation_index === 'number' ? frame.annotation_index : list.length - 1,
|
|
78
|
+
annotation,
|
|
79
|
+
}];
|
|
80
|
+
}
|
|
81
|
+
if (type === 'response.refusal.delta' || type === 'response.refusal.done') {
|
|
82
|
+
const text = type.endsWith('.delta') ? frame.delta : frame.refusal;
|
|
83
|
+
if (typeof text !== 'string')
|
|
84
|
+
invalid(`${type} requires its refusal payload.`);
|
|
85
|
+
return [{
|
|
86
|
+
type: type.endsWith('.delta') ? 'response.refusal.delta' : 'response.refusal.done',
|
|
87
|
+
index, partIndex, text,
|
|
88
|
+
}];
|
|
89
|
+
}
|
|
90
|
+
if (type === 'response.reasoning_text.delta' || type === 'response.reasoning_text.done' ||
|
|
91
|
+
type === 'response.reasoning.delta' || type === 'response.reasoning.done') {
|
|
92
|
+
const text = type.endsWith('.delta') ? frame.delta : frame.text;
|
|
93
|
+
if (typeof text !== 'string')
|
|
94
|
+
invalid(`${type} requires its reasoning payload.`);
|
|
95
|
+
return [{
|
|
96
|
+
type: type.endsWith('.delta') ? 'response.reasoning.delta' : 'response.reasoning.done',
|
|
97
|
+
index, text,
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
if (type === 'response.reasoning_summary_part.added') {
|
|
101
|
+
return [{ type: 'response.reasoning_summary_part.added', index, summaryIndex }];
|
|
102
|
+
}
|
|
103
|
+
if (type === 'response.reasoning_summary_text.delta' || type === 'response.reasoning_summary_text.done' ||
|
|
104
|
+
type === 'response.reasoning_summary.delta' || type === 'response.reasoning_summary.done') {
|
|
105
|
+
const text = type.endsWith('.delta') ? frame.delta : frame.text;
|
|
106
|
+
if (typeof text !== 'string')
|
|
107
|
+
invalid(`${type} requires its summary payload.`);
|
|
108
|
+
return [{
|
|
109
|
+
type: type.endsWith('.delta') ? 'response.reasoning_summary.delta' : 'response.reasoning_summary.done',
|
|
110
|
+
index, summaryIndex, text,
|
|
111
|
+
}];
|
|
112
|
+
}
|
|
113
|
+
if (type === 'response.function_call.arguments.delta' || type === 'response.function_call.arguments.done' ||
|
|
114
|
+
type === 'response.custom_tool_call_input.delta' || type === 'response.custom_tool_call_input.done' ||
|
|
115
|
+
type === 'response.custom_tool_call.input.delta' || type === 'response.custom_tool_call.input.done') {
|
|
116
|
+
const done = type.endsWith('.done');
|
|
117
|
+
const text = done
|
|
118
|
+
? (typeof frame.arguments === 'string' ? frame.arguments : frame.input)
|
|
119
|
+
: frame.delta;
|
|
120
|
+
if (typeof text !== 'string')
|
|
121
|
+
invalid(`${type} requires its tool input payload.`);
|
|
122
|
+
return [done
|
|
123
|
+
? { type: 'response.function_call.arguments.done', index, arguments: text }
|
|
124
|
+
: { type: 'response.function_call.arguments.delta', index, argumentsDelta: text }];
|
|
125
|
+
}
|
|
126
|
+
if (type === 'response.completed' || type === 'response.incomplete' || type === 'response.failed') {
|
|
127
|
+
this.nativeTerminal = true;
|
|
128
|
+
this.terminalSent = true;
|
|
129
|
+
const response = record(frame.response);
|
|
130
|
+
const events = [];
|
|
131
|
+
if (frame.response && typeof frame.response === 'object') {
|
|
132
|
+
if (!this.createdSent) {
|
|
133
|
+
this.createdSent = true;
|
|
134
|
+
events.push({
|
|
135
|
+
type: 'response.created',
|
|
136
|
+
...(typeof response.id === 'string' ? { id: response.id } : {}),
|
|
137
|
+
...(typeof response.model === 'string' ? { model: response.model } : {}),
|
|
138
|
+
...(typeof response.created_at === 'number' ? { createdAt: response.created_at } : {}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
events.push({ type: 'response.usage', usage: responsesUsageFromWire(response.usage) });
|
|
142
|
+
}
|
|
143
|
+
if (type === 'response.failed') {
|
|
144
|
+
const error = record(response.error);
|
|
145
|
+
events.push({ type: 'response.failed', reason: error.message ?? response.error?.message ?? 'error' });
|
|
146
|
+
}
|
|
147
|
+
else if (type === 'response.incomplete') {
|
|
148
|
+
const wireReason = record(response.incomplete_details).reason;
|
|
149
|
+
events.push({
|
|
150
|
+
type: 'response.incomplete',
|
|
151
|
+
reason: wireReason === 'content_filter' ? 'content_filter' : wireReason === 'max_output_tokens' ? 'length' : wireReason,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
events.push({ type: 'response.completed' });
|
|
156
|
+
}
|
|
157
|
+
return events;
|
|
158
|
+
}
|
|
159
|
+
if (type === 'response.error' || type === 'error') {
|
|
160
|
+
this.nativeTerminal = true;
|
|
161
|
+
this.terminalSent = true;
|
|
162
|
+
const error = record(frame.error ?? frame);
|
|
163
|
+
return [{ type: 'error', code: error.code, message: String(error.message ?? 'Responses stream failed.') }];
|
|
164
|
+
}
|
|
165
|
+
if (type === 'response.in_progress' || type === 'response.queued' || type === 'ping')
|
|
166
|
+
return [];
|
|
167
|
+
return invalid(`unsupported event "${type || 'missing type'}".`);
|
|
168
|
+
}
|
|
169
|
+
finish() {
|
|
170
|
+
if (this.terminalSent)
|
|
171
|
+
return [];
|
|
172
|
+
this.terminalSent = true;
|
|
173
|
+
return [{ type: 'response.completed' }];
|
|
174
|
+
}
|
|
175
|
+
key(index, partIndex) {
|
|
176
|
+
return `${index}:${partIndex}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ModelRegistration } from '../../config/types.js';
|
|
2
|
+
import type { Annotation, CanonicalRequest, CanonicalResponse, ContentPart, InputItem, ToolDef, Usage } from '../types.js';
|
|
3
|
+
declare function annotationFromWire(raw: unknown): Annotation;
|
|
4
|
+
declare function partFromWire(raw: unknown): ContentPart;
|
|
5
|
+
export declare function responsesPartToWire(part: ContentPart, role: 'user' | 'assistant'): Record<string, unknown>;
|
|
6
|
+
export declare function responsesToolToWire(tool: ToolDef): Record<string, unknown>;
|
|
7
|
+
/** Canonical IR → OpenAI Responses request. No request-object spreading. */
|
|
8
|
+
export declare function canonicalToResponsesPayload(ir: CanonicalRequest, model: ModelRegistration, stream?: boolean): Record<string, any>;
|
|
9
|
+
export declare function responsesInputToIR(raw: unknown): InputItem[];
|
|
10
|
+
/** OpenAI Responses request → Canonical IR. No Chat-shaped intermediate. */
|
|
11
|
+
export declare function responsesRequestToIR(body: unknown): CanonicalRequest;
|
|
12
|
+
declare function usageFromWire(raw: unknown): Usage;
|
|
13
|
+
export declare function responsesResponseToIR(data: unknown): CanonicalResponse;
|
|
14
|
+
export { annotationFromWire as responsesAnnotationFromWire, partFromWire as responsesPartFromWire, usageFromWire as responsesUsageFromWire, };
|