@finalai/agent-provider 0.1.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.
Potentially problematic release.
This version of @finalai/agent-provider might be problematic. Click here for more details.
- package/README.md +12 -0
- package/dist/modules/channel-context.d.mts +102 -0
- package/dist/modules/channel-context.mjs +52 -0
- package/dist/modules/channel-context.mjs.map +7 -0
- package/dist/modules/channel-socket.d.mts +65 -0
- package/dist/modules/channel-socket.mjs +188 -0
- package/dist/modules/channel-socket.mjs.map +7 -0
- package/dist/modules/channel.d.mts +382 -0
- package/dist/modules/channel.mjs +146 -0
- package/dist/modules/channel.mjs.map +7 -0
- package/dist/modules/conformance/agent.d.mts +20 -0
- package/dist/modules/conformance/agent.mjs +623 -0
- package/dist/modules/conformance/agent.mjs.map +7 -0
- package/dist/modules/conformance/fixtures.d.mts +41 -0
- package/dist/modules/conformance/fixtures.mjs +190 -0
- package/dist/modules/conformance/fixtures.mjs.map +7 -0
- package/dist/modules/conformance/harness-kit.d.mts +82 -0
- package/dist/modules/conformance/harness-kit.mjs +1303 -0
- package/dist/modules/conformance/harness-kit.mjs.map +7 -0
- package/dist/modules/conformance/image.d.mts +2 -0
- package/dist/modules/conformance/image.mjs +79 -0
- package/dist/modules/conformance/image.mjs.map +7 -0
- package/dist/modules/conformance/index.d.mts +8 -0
- package/dist/modules/conformance/index.mjs +12 -0
- package/dist/modules/conformance/index.mjs.map +7 -0
- package/dist/modules/conformance/local-harness.d.mts +25 -0
- package/dist/modules/conformance/local-harness.mjs +108 -0
- package/dist/modules/conformance/local-harness.mjs.map +7 -0
- package/dist/modules/conformance/protocol.d.mts +30 -0
- package/dist/modules/conformance/protocol.mjs +56 -0
- package/dist/modules/conformance/protocol.mjs.map +7 -0
- package/dist/modules/conformance/sandbox-kit.d.mts +19 -0
- package/dist/modules/conformance/sandbox-kit.mjs +320 -0
- package/dist/modules/conformance/sandbox-kit.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/chat-completions.d.mts +30 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs +125 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/directives.d.mts +84 -0
- package/dist/modules/conformance/scripted-model/directives.mjs +304 -0
- package/dist/modules/conformance/scripted-model/directives.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/handler.d.mts +14 -0
- package/dist/modules/conformance/scripted-model/handler.mjs +133 -0
- package/dist/modules/conformance/scripted-model/handler.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/index.d.mts +6 -0
- package/dist/modules/conformance/scripted-model/index.mjs +7 -0
- package/dist/modules/conformance/scripted-model/index.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/messages.d.mts +39 -0
- package/dist/modules/conformance/scripted-model/messages.mjs +139 -0
- package/dist/modules/conformance/scripted-model/messages.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/responses.d.mts +62 -0
- package/dist/modules/conformance/scripted-model/responses.mjs +273 -0
- package/dist/modules/conformance/scripted-model/responses.mjs.map +7 -0
- package/dist/modules/conformance/scripted-model/sse.d.mts +15 -0
- package/dist/modules/conformance/scripted-model/sse.mjs +75 -0
- package/dist/modules/conformance/scripted-model/sse.mjs.map +7 -0
- package/dist/modules/conformance/v1-agent.d.mts +24 -0
- package/dist/modules/conformance/v1-agent.mjs +40 -0
- package/dist/modules/conformance/v1-agent.mjs.map +7 -0
- package/dist/modules/credential-routes.d.mts +24 -0
- package/dist/modules/credential-routes.mjs +25 -0
- package/dist/modules/credential-routes.mjs.map +7 -0
- package/dist/modules/credentials.d.mts +206 -0
- package/dist/modules/credentials.mjs +207 -0
- package/dist/modules/credentials.mjs.map +7 -0
- package/dist/modules/dynamic.d.mts +32 -0
- package/dist/modules/dynamic.mjs +77 -0
- package/dist/modules/dynamic.mjs.map +7 -0
- package/dist/modules/harness.d.mts +397 -0
- package/dist/modules/harness.mjs +213 -0
- package/dist/modules/harness.mjs.map +7 -0
- package/dist/modules/index.d.mts +15 -0
- package/dist/modules/index.mjs +40 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/json.d.mts +12 -0
- package/dist/modules/json.mjs +19 -0
- package/dist/modules/json.mjs.map +7 -0
- package/dist/modules/local-channel-socket.d.mts +23 -0
- package/dist/modules/local-channel-socket.mjs +141 -0
- package/dist/modules/local-channel-socket.mjs.map +7 -0
- package/dist/modules/manifest.d.mts +558 -0
- package/dist/modules/manifest.mjs +266 -0
- package/dist/modules/manifest.mjs.map +7 -0
- package/dist/modules/mcp-content.d.mts +21 -0
- package/dist/modules/mcp-content.mjs +86 -0
- package/dist/modules/mcp-content.mjs.map +7 -0
- package/dist/modules/provider-ref.d.mts +29 -0
- package/dist/modules/provider-ref.mjs +55 -0
- package/dist/modules/provider-ref.mjs.map +7 -0
- package/dist/modules/sandbox/bytes.d.mts +9 -0
- package/dist/modules/sandbox/bytes.mjs +154 -0
- package/dist/modules/sandbox/bytes.mjs.map +7 -0
- package/dist/modules/sandbox/client.d.mts +51 -0
- package/dist/modules/sandbox/client.mjs +500 -0
- package/dist/modules/sandbox/client.mjs.map +7 -0
- package/dist/modules/sandbox/confined-files.d.mts +22 -0
- package/dist/modules/sandbox/confined-files.mjs +142 -0
- package/dist/modules/sandbox/confined-files.mjs.map +7 -0
- package/dist/modules/sandbox/convenience.d.mts +10 -0
- package/dist/modules/sandbox/convenience.mjs +116 -0
- package/dist/modules/sandbox/convenience.mjs.map +7 -0
- package/dist/modules/sandbox/editor.d.mts +49 -0
- package/dist/modules/sandbox/editor.mjs +43 -0
- package/dist/modules/sandbox/editor.mjs.map +7 -0
- package/dist/modules/sandbox/frame-channel.d.mts +47 -0
- package/dist/modules/sandbox/frame-channel.mjs +153 -0
- package/dist/modules/sandbox/frame-channel.mjs.map +7 -0
- package/dist/modules/sandbox/index.d.mts +18 -0
- package/dist/modules/sandbox/index.mjs +70 -0
- package/dist/modules/sandbox/index.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-channel.d.mts +9 -0
- package/dist/modules/sandbox/mcp-channel.mjs +77 -0
- package/dist/modules/sandbox/mcp-channel.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-hosted.d.mts +46 -0
- package/dist/modules/sandbox/mcp-hosted.mjs +221 -0
- package/dist/modules/sandbox/mcp-hosted.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-search.d.mts +51 -0
- package/dist/modules/sandbox/mcp-search.mjs +129 -0
- package/dist/modules/sandbox/mcp-search.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-shell.d.mts +21 -0
- package/dist/modules/sandbox/mcp-shell.mjs +205 -0
- package/dist/modules/sandbox/mcp-shell.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-testing.d.mts +11 -0
- package/dist/modules/sandbox/mcp-testing.mjs +33 -0
- package/dist/modules/sandbox/mcp-testing.mjs.map +7 -0
- package/dist/modules/sandbox/mcp.d.mts +83 -0
- package/dist/modules/sandbox/mcp.mjs +971 -0
- package/dist/modules/sandbox/mcp.mjs.map +7 -0
- package/dist/modules/sandbox/memory-sandbox.d.mts +32 -0
- package/dist/modules/sandbox/memory-sandbox.mjs +416 -0
- package/dist/modules/sandbox/memory-sandbox.mjs.map +7 -0
- package/dist/modules/sandbox/memory-shell.d.mts +29 -0
- package/dist/modules/sandbox/memory-shell.mjs +278 -0
- package/dist/modules/sandbox/memory-shell.mjs.map +7 -0
- package/dist/modules/sandbox/open-scope-node.d.mts +4 -0
- package/dist/modules/sandbox/open-scope-node.mjs +19 -0
- package/dist/modules/sandbox/open-scope-node.mjs.map +7 -0
- package/dist/modules/sandbox/open-scope.d.mts +16 -0
- package/dist/modules/sandbox/open-scope.mjs +66 -0
- package/dist/modules/sandbox/open-scope.mjs.map +7 -0
- package/dist/modules/sandbox/paths.d.mts +7 -0
- package/dist/modules/sandbox/paths.mjs +50 -0
- package/dist/modules/sandbox/paths.mjs.map +7 -0
- package/dist/modules/sandbox/rpc-peer.d.mts +35 -0
- package/dist/modules/sandbox/rpc-peer.mjs +224 -0
- package/dist/modules/sandbox/rpc-peer.mjs.map +7 -0
- package/dist/modules/sandbox/seeds.d.mts +26 -0
- package/dist/modules/sandbox/seeds.mjs +228 -0
- package/dist/modules/sandbox/seeds.mjs.map +7 -0
- package/dist/modules/sandbox/server.d.mts +66 -0
- package/dist/modules/sandbox/server.mjs +567 -0
- package/dist/modules/sandbox/server.mjs.map +7 -0
- package/dist/modules/sandbox/snapshots.d.mts +49 -0
- package/dist/modules/sandbox/snapshots.mjs +55 -0
- package/dist/modules/sandbox/snapshots.mjs.map +7 -0
- package/dist/modules/sandbox/stream-mux.d.mts +18 -0
- package/dist/modules/sandbox/stream-mux.mjs +285 -0
- package/dist/modules/sandbox/stream-mux.mjs.map +7 -0
- package/dist/modules/sandbox/testing.d.mts +25 -0
- package/dist/modules/sandbox/testing.mjs +64 -0
- package/dist/modules/sandbox/testing.mjs.map +7 -0
- package/dist/modules/sandbox/types.d.mts +352 -0
- package/dist/modules/sandbox/types.mjs +86 -0
- package/dist/modules/sandbox/types.mjs.map +7 -0
- package/dist/modules/sandbox/wire.d.mts +671 -0
- package/dist/modules/sandbox/wire.mjs +537 -0
- package/dist/modules/sandbox/wire.mjs.map +7 -0
- package/dist/modules/sandbox/workspace-root.d.mts +8 -0
- package/dist/modules/sandbox/workspace-root.mjs +79 -0
- package/dist/modules/sandbox/workspace-root.mjs.map +7 -0
- package/dist/modules/schemas.d.mts +121 -0
- package/dist/modules/schemas.mjs +146 -0
- package/dist/modules/schemas.mjs.map +7 -0
- package/dist/modules/semantic-events.d.mts +31 -0
- package/dist/modules/semantic-events.mjs +23 -0
- package/dist/modules/semantic-events.mjs.map +7 -0
- package/package.json +199 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/conformance/scripted-model/index.ts"],
|
|
4
|
+
"sourcesContent": ["// The scripted conformance model (`@finalai/agent-provider/conformance/scripted-model`):\n// a vendor-shaped model endpoint that follows the kit's directives. Web APIs\n// only; it runs in Node and workerd. See handler.ts and directives.ts.\nexport * from \"./chat-completions.mjs\";\nexport * from \"./directives.mjs\";\nexport * from \"./handler.mjs\";\nexport * from \"./messages.mjs\";\nexport * from \"./responses.mjs\";\nexport * from \"./sse.mjs\";\n"],
|
|
5
|
+
"mappings": "AAGA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { type ScriptedAction, type ScriptedConversationIface } from "./directives.mjs";
|
|
3
|
+
import { type HeldStreamTimingIface } from "./sse.mjs";
|
|
4
|
+
export declare const messagesRequestSchema: z.ZodObject<{
|
|
5
|
+
model: z.ZodString;
|
|
6
|
+
stream: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
8
|
+
role: z.ZodString;
|
|
9
|
+
content: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
10
|
+
[x: string]: unknown;
|
|
11
|
+
type: string;
|
|
12
|
+
content: string;
|
|
13
|
+
text?: string | undefined;
|
|
14
|
+
is_error?: boolean | undefined;
|
|
15
|
+
}[], string>>, z.ZodArray<z.ZodObject<{
|
|
16
|
+
type: z.ZodString;
|
|
17
|
+
text: z.ZodOptional<z.ZodString>;
|
|
18
|
+
content: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
19
|
+
type: z.ZodString;
|
|
20
|
+
text: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$loose>>, z.ZodTransform<string, {
|
|
22
|
+
[x: string]: unknown;
|
|
23
|
+
type: string;
|
|
24
|
+
text?: string | undefined;
|
|
25
|
+
}[]>>]>>;
|
|
26
|
+
is_error: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
}, z.core.$loose>>]>;
|
|
28
|
+
}, z.core.$loose>>;
|
|
29
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
30
|
+
name: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$loose>>>;
|
|
32
|
+
}, z.core.$loose>;
|
|
33
|
+
export type MessagesRequest = z.infer<typeof messagesRequestSchema>;
|
|
34
|
+
export declare const messagesConversation: (request: MessagesRequest) => ScriptedConversationIface;
|
|
35
|
+
export declare const messagesResponse: (args: {
|
|
36
|
+
request: MessagesRequest;
|
|
37
|
+
action: ScriptedAction;
|
|
38
|
+
timing: HeldStreamTimingIface;
|
|
39
|
+
}) => Response;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
ConversationEntryKind,
|
|
4
|
+
qualifiedToolName,
|
|
5
|
+
replyPlan,
|
|
6
|
+
ScriptedActionKind
|
|
7
|
+
} from "./directives.mjs";
|
|
8
|
+
import {
|
|
9
|
+
heldSseResponse,
|
|
10
|
+
jsonResponse,
|
|
11
|
+
pausedSseResponse,
|
|
12
|
+
sseEvent,
|
|
13
|
+
sseResponse
|
|
14
|
+
} from "./sse.mjs";
|
|
15
|
+
const textBlockSchema = z.looseObject({ type: z.string(), text: z.string().optional() });
|
|
16
|
+
const resultTextSchema = z.union([
|
|
17
|
+
z.string(),
|
|
18
|
+
z.array(textBlockSchema).transform(
|
|
19
|
+
(blocks) => blocks.filter((block) => block.type === "text").map((block) => block.text ?? "").join("\n")
|
|
20
|
+
)
|
|
21
|
+
]).default("");
|
|
22
|
+
const blockSchema = z.looseObject({
|
|
23
|
+
type: z.string(),
|
|
24
|
+
text: z.string().optional(),
|
|
25
|
+
content: resultTextSchema,
|
|
26
|
+
is_error: z.boolean().optional()
|
|
27
|
+
});
|
|
28
|
+
const messagesRequestSchema = z.looseObject({
|
|
29
|
+
model: z.string(),
|
|
30
|
+
stream: z.boolean().optional(),
|
|
31
|
+
messages: z.array(
|
|
32
|
+
z.looseObject({
|
|
33
|
+
role: z.string(),
|
|
34
|
+
// A string is one text block.
|
|
35
|
+
content: z.union([
|
|
36
|
+
z.string().transform((text) => [blockSchema.parse({ type: "text", text })]),
|
|
37
|
+
z.array(blockSchema)
|
|
38
|
+
])
|
|
39
|
+
})
|
|
40
|
+
),
|
|
41
|
+
tools: z.array(z.looseObject({ name: z.string().optional() })).optional()
|
|
42
|
+
});
|
|
43
|
+
const withoutTrailingReminders = (value) => value.replace(
|
|
44
|
+
/(?:\n\n<system-reminder>(?:(?!<\/system-reminder>)[\s\S])*<\/system-reminder>)+\s*$/u,
|
|
45
|
+
""
|
|
46
|
+
);
|
|
47
|
+
const messagesConversation = (request) => ({
|
|
48
|
+
entries: request.messages.flatMap((message) => {
|
|
49
|
+
if (message.role !== "user") return [];
|
|
50
|
+
return message.content.flatMap((block) => {
|
|
51
|
+
if (block.type === "text") {
|
|
52
|
+
return [{ kind: ConversationEntryKind.User, text: block.text ?? "" }];
|
|
53
|
+
}
|
|
54
|
+
if (block.type === "tool_result") {
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
kind: ConversationEntryKind.ToolResult,
|
|
58
|
+
text: withoutTrailingReminders(block.content),
|
|
59
|
+
isError: block.is_error === true
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
});
|
|
65
|
+
}),
|
|
66
|
+
tools: (request.tools ?? []).flatMap(
|
|
67
|
+
(tool) => tool.name == null ? [] : [{ name: tool.name, namespace: null }]
|
|
68
|
+
),
|
|
69
|
+
toolSearch: false,
|
|
70
|
+
codeMode: null
|
|
71
|
+
});
|
|
72
|
+
const USAGE = { input_tokens: 12, output_tokens: 4 };
|
|
73
|
+
const messagesResponse = (args) => {
|
|
74
|
+
const { request, action } = args;
|
|
75
|
+
if (action.kind === ScriptedActionKind.Error) {
|
|
76
|
+
return jsonResponse(400, {
|
|
77
|
+
type: "error",
|
|
78
|
+
error: { type: "invalid_request_error", message: action.message }
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const id = `msg_${crypto.randomUUID()}`;
|
|
82
|
+
const toolCall = action.kind === ScriptedActionKind.ToolCall ? {
|
|
83
|
+
id: `toolu_${crypto.randomUUID()}`,
|
|
84
|
+
name: qualifiedToolName(action.tool),
|
|
85
|
+
input: action.arguments
|
|
86
|
+
} : null;
|
|
87
|
+
const plan = replyPlan(action) ?? { first: "", second: "", pauseMs: 0, held: false };
|
|
88
|
+
const stopReason = toolCall == null ? "end_turn" : "tool_use";
|
|
89
|
+
const message = (content, stop) => ({
|
|
90
|
+
id,
|
|
91
|
+
type: "message",
|
|
92
|
+
role: "assistant",
|
|
93
|
+
model: request.model,
|
|
94
|
+
content,
|
|
95
|
+
stop_reason: stop,
|
|
96
|
+
stop_sequence: null,
|
|
97
|
+
usage: USAGE
|
|
98
|
+
});
|
|
99
|
+
if (request.stream !== true) {
|
|
100
|
+
const content = toolCall == null ? [{ type: "text", text: `${plan.first}${plan.second}` }] : [{ type: "tool_use", id: toolCall.id, name: toolCall.name, input: toolCall.input }];
|
|
101
|
+
return jsonResponse(200, message(content, stopReason));
|
|
102
|
+
}
|
|
103
|
+
const event = (type, data) => sseEvent(type, { type, ...data });
|
|
104
|
+
const end = [
|
|
105
|
+
event("content_block_stop", { index: 0 }),
|
|
106
|
+
event("message_delta", {
|
|
107
|
+
delta: { stop_reason: stopReason, stop_sequence: null },
|
|
108
|
+
usage: { output_tokens: USAGE.output_tokens }
|
|
109
|
+
}),
|
|
110
|
+
event("message_stop", {})
|
|
111
|
+
];
|
|
112
|
+
const head = [event("message_start", { message: message([], null) })];
|
|
113
|
+
if (toolCall != null) {
|
|
114
|
+
head.push(
|
|
115
|
+
event("content_block_start", {
|
|
116
|
+
index: 0,
|
|
117
|
+
content_block: { type: "tool_use", id: toolCall.id, name: toolCall.name, input: {} }
|
|
118
|
+
}),
|
|
119
|
+
event("content_block_delta", {
|
|
120
|
+
index: 0,
|
|
121
|
+
delta: { type: "input_json_delta", partial_json: JSON.stringify(toolCall.input) }
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
return sseResponse([...head, ...end]);
|
|
125
|
+
}
|
|
126
|
+
const delta = (text) => text === "" ? [] : [event("content_block_delta", { index: 0, delta: { type: "text_delta", text } })];
|
|
127
|
+
head.push(
|
|
128
|
+
event("content_block_start", { index: 0, content_block: { type: "text", text: "" } }),
|
|
129
|
+
...delta(plan.first)
|
|
130
|
+
);
|
|
131
|
+
if (plan.held) return heldSseResponse(head, args.timing);
|
|
132
|
+
return pausedSseResponse(head, [...delta(plan.second), ...end], plan.pauseMs);
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
messagesConversation,
|
|
136
|
+
messagesRequestSchema,
|
|
137
|
+
messagesResponse
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=messages.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/conformance/scripted-model/messages.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport type { JsonObject, JsonValue } from \"../../json.mjs\";\nimport {\n ConversationEntryKind,\n qualifiedToolName,\n replyPlan,\n ScriptedActionKind,\n type ConversationEntry,\n type ScriptedAction,\n type ScriptedConversationIface,\n} from \"./directives.mjs\";\nimport {\n heldSseResponse,\n jsonResponse,\n pausedSseResponse,\n sseEvent,\n sseResponse,\n type HeldStreamTimingIface,\n type SseEventIface,\n} from \"./sse.mjs\";\n\n// Anthropic Messages (`POST \u2026/v1/messages`), as Claude Code (remote-claude-code)\n// and the nanocode Claude engine speak it. Tool results are `tool_result`\n// blocks of a user message.\n\nconst textBlockSchema = z.looseObject({ type: z.string(), text: z.string().optional() });\n\n// A tool result's content as text: a string or its text blocks, one per line.\nconst resultTextSchema = z\n .union([\n z.string(),\n z.array(textBlockSchema).transform((blocks) =>\n blocks\n .filter((block) => block.type === 'text')\n .map((block) => block.text ?? '')\n .join('\\n'),\n ),\n ])\n .default('');\n\nconst blockSchema = z.looseObject({\n type: z.string(),\n text: z.string().optional(),\n content: resultTextSchema,\n is_error: z.boolean().optional(),\n});\n\nexport const messagesRequestSchema = z.looseObject({\n model: z.string(),\n stream: z.boolean().optional(),\n messages: z.array(\n z.looseObject({\n role: z.string(),\n // A string is one text block.\n content: z.union([\n z.string().transform((text) => [blockSchema.parse({ type: 'text', text })]),\n z.array(blockSchema),\n ]),\n }),\n ),\n tools: z.array(z.looseObject({ name: z.string().optional() })).optional(),\n});\n\nexport type MessagesRequest = z.infer<typeof messagesRequestSchema>;\n\n// Claude appends token-budget reminders to tool results; the scripted model ignores\n// that CLI context as a real model would, leaving the fixture's own result intact.\nconst withoutTrailingReminders = (value: string): string =>\n value.replace(\n /(?:\\n\\n<system-reminder>(?:(?!<\\/system-reminder>)[\\s\\S])*<\\/system-reminder>)+\\s*$/u,\n '',\n );\n\nexport const messagesConversation = (request: MessagesRequest): ScriptedConversationIface => ({\n entries: request.messages.flatMap((message): ConversationEntry[] => {\n if (message.role !== 'user') return [];\n return message.content.flatMap((block): ConversationEntry[] => {\n if (block.type === 'text') {\n return [{ kind: ConversationEntryKind.User, text: block.text ?? '' }];\n }\n if (block.type === 'tool_result') {\n return [\n {\n kind: ConversationEntryKind.ToolResult,\n text: withoutTrailingReminders(block.content),\n isError: block.is_error === true,\n },\n ];\n }\n return [];\n });\n }),\n tools: (request.tools ?? []).flatMap((tool) =>\n tool.name == null ? [] : [{ name: tool.name, namespace: null }],\n ),\n toolSearch: false,\n codeMode: null,\n});\n\nconst USAGE = { input_tokens: 12, output_tokens: 4 };\n\nexport const messagesResponse = (args: {\n request: MessagesRequest;\n action: ScriptedAction;\n timing: HeldStreamTimingIface;\n}): Response => {\n const { request, action } = args;\n if (action.kind === ScriptedActionKind.Error) {\n return jsonResponse(400, {\n type: 'error',\n error: { type: 'invalid_request_error', message: action.message },\n });\n }\n const id = `msg_${crypto.randomUUID()}`;\n const toolCall =\n action.kind === ScriptedActionKind.ToolCall\n ? {\n id: `toolu_${crypto.randomUUID()}`,\n name: qualifiedToolName(action.tool),\n input: action.arguments,\n }\n : null;\n // Messages has no tool search; the decision never asks for it here.\n const plan = replyPlan(action) ?? { first: '', second: '', pauseMs: 0, held: false };\n const stopReason = toolCall == null ? 'end_turn' : 'tool_use';\n const message = (content: JsonValue[], stop: string | null): JsonObject => ({\n id,\n type: 'message',\n role: 'assistant',\n model: request.model,\n content,\n stop_reason: stop,\n stop_sequence: null,\n usage: USAGE,\n });\n if (request.stream !== true) {\n const content: JsonValue[] =\n toolCall == null\n ? [{ type: 'text', text: `${plan.first}${plan.second}` }]\n : [{ type: 'tool_use', id: toolCall.id, name: toolCall.name, input: toolCall.input }];\n return jsonResponse(200, message(content, stopReason));\n }\n const event = (type: string, data: JsonObject): SseEventIface =>\n sseEvent(type, { type, ...data });\n const end: SseEventIface[] = [\n event('content_block_stop', { index: 0 }),\n event('message_delta', {\n delta: { stop_reason: stopReason, stop_sequence: null },\n usage: { output_tokens: USAGE.output_tokens },\n }),\n event('message_stop', {}),\n ];\n const head: SseEventIface[] = [event('message_start', { message: message([], null) })];\n if (toolCall != null) {\n head.push(\n event('content_block_start', {\n index: 0,\n content_block: { type: 'tool_use', id: toolCall.id, name: toolCall.name, input: {} },\n }),\n event('content_block_delta', {\n index: 0,\n delta: { type: 'input_json_delta', partial_json: JSON.stringify(toolCall.input) },\n }),\n );\n return sseResponse([...head, ...end]);\n }\n const delta = (text: string): SseEventIface[] =>\n text === ''\n ? []\n : [event('content_block_delta', { index: 0, delta: { type: 'text_delta', text } })];\n head.push(\n event('content_block_start', { index: 0, content_block: { type: 'text', text: '' } }),\n ...delta(plan.first),\n );\n if (plan.held) return heldSseResponse(head, args.timing);\n return pausedSseResponse(head, [...delta(plan.second), ...end], plan.pauseMs);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AAEnB;AAAA,E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AAAA,MACD,MAAM,uBAAuB;AAAA,QAC3B,OAAO;AAAA,QACP,OAAO,EAAE,MAAM,oBAAoB,cAAc,KAAK,UAAU,SAAS,KAAK,EAAE;AAAA,MAClF,CAAC;AAAA,IACH;AACA,WAAO,YAAY,CAAC,GAAG,MAAM,GAAG,GAAG,CAAC;AAAA,EACtC;AACA,QAAM,QAAQ,CAAC,SACb,SAAS,KACL,CAAC,IACD,CAAC,MAAM,uBAAuB,EAAE,OAAO,GAAG,OAAO,EAAE,MAAM,cAAc,KAAK,EAAE,CAAC,CAAC;AACtF,OAAK;AAAA,IACH,MAAM,uBAAuB,EAAE,OAAO,GAAG,eAAe,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE,CAAC;AAAA,IACpF,GAAG,MAAM,KAAK,KAAK;AAAA,EACrB;AACA,MAAI,KAAK,KAAM,QAAO,gBAAgB,MAAM,KAAK,MAAM;AACvD,SAAO,kBAAkB,MAAM,CAAC,GAAG,MAAM,KAAK,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,OAAO;AAC9E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { type ScriptedAction, type ScriptedConversationIface } from "./directives.mjs";
|
|
3
|
+
import { type HeldStreamTimingIface } from "./sse.mjs";
|
|
4
|
+
export declare const RESPONSES_LITE_HEADER = "x-openai-internal-codex-responses-lite";
|
|
5
|
+
export interface ToolOutputIface {
|
|
6
|
+
text: string;
|
|
7
|
+
isError: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const responsesRequestSchema: z.ZodObject<{
|
|
10
|
+
model: z.ZodString;
|
|
11
|
+
stream: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
input: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
type: string;
|
|
15
|
+
content: string;
|
|
16
|
+
role?: string | undefined;
|
|
17
|
+
output?: ToolOutputIface | undefined;
|
|
18
|
+
tools?: z.core.util.JSONType[] | undefined;
|
|
19
|
+
}[], string>>, z.ZodArray<z.ZodObject<{
|
|
20
|
+
type: z.ZodDefault<z.ZodString>;
|
|
21
|
+
role: z.ZodOptional<z.ZodString>;
|
|
22
|
+
content: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
23
|
+
type: z.ZodString;
|
|
24
|
+
text: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$loose>>, z.ZodTransform<string, {
|
|
26
|
+
[x: string]: unknown;
|
|
27
|
+
type: string;
|
|
28
|
+
text?: string | undefined;
|
|
29
|
+
}[]>>]>>;
|
|
30
|
+
output: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<ToolOutputIface, string>>, z.ZodUnion<readonly [z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
31
|
+
type: z.ZodString;
|
|
32
|
+
text: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, z.core.$loose>>, z.ZodTransform<string, {
|
|
34
|
+
[x: string]: unknown;
|
|
35
|
+
type: string;
|
|
36
|
+
text?: string | undefined;
|
|
37
|
+
}[]>>]>, z.ZodTransform<ToolOutputIface, string>>, z.ZodPipe<z.ZodObject<{
|
|
38
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
39
|
+
type: z.ZodString;
|
|
40
|
+
text: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$loose>>, z.ZodTransform<string, {
|
|
42
|
+
[x: string]: unknown;
|
|
43
|
+
type: string;
|
|
44
|
+
text?: string | undefined;
|
|
45
|
+
}[]>>]>;
|
|
46
|
+
success: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
}, z.core.$loose>, z.ZodTransform<ToolOutputIface, {
|
|
48
|
+
[x: string]: unknown;
|
|
49
|
+
content: string;
|
|
50
|
+
success?: boolean | undefined;
|
|
51
|
+
}>>]>, z.ZodPipe<z.ZodJSONSchema, z.ZodTransform<ToolOutputIface, z.core.util.JSONType>>]>>;
|
|
52
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodJSONSchema>>;
|
|
53
|
+
}, z.core.$loose>>]>;
|
|
54
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodJSONSchema>>;
|
|
55
|
+
}, z.core.$loose>;
|
|
56
|
+
export type ResponsesRequest = z.infer<typeof responsesRequestSchema>;
|
|
57
|
+
export declare const responsesConversation: (request: ResponsesRequest) => ScriptedConversationIface;
|
|
58
|
+
export declare const responsesResponse: (args: {
|
|
59
|
+
request: ResponsesRequest;
|
|
60
|
+
action: ScriptedAction;
|
|
61
|
+
timing: HeldStreamTimingIface;
|
|
62
|
+
}) => Response;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
ConversationEntryKind,
|
|
4
|
+
replyPlan,
|
|
5
|
+
ScriptedActionKind
|
|
6
|
+
} from "./directives.mjs";
|
|
7
|
+
import {
|
|
8
|
+
heldSseResponse,
|
|
9
|
+
jsonResponse,
|
|
10
|
+
pausedSseResponse,
|
|
11
|
+
sseEvent,
|
|
12
|
+
sseResponse
|
|
13
|
+
} from "./sse.mjs";
|
|
14
|
+
const RESPONSES_LITE_HEADER = "x-openai-internal-codex-responses-lite";
|
|
15
|
+
const partSchema = z.looseObject({ type: z.string(), text: z.string().optional() });
|
|
16
|
+
const contentTextSchema = z.union([
|
|
17
|
+
z.string(),
|
|
18
|
+
z.array(partSchema).transform(
|
|
19
|
+
(parts) => parts.map((part) => part.text ?? "").filter((value) => value !== "").join("\n")
|
|
20
|
+
)
|
|
21
|
+
]);
|
|
22
|
+
const withoutTimingEnvelope = (text) => /^Wall time: [0-9]+(?:\.[0-9]+)? seconds\nOutput:\n([\s\S]*)$/u.exec(text)?.[1] ?? text;
|
|
23
|
+
const structuredOutputSchema = z.union([
|
|
24
|
+
contentTextSchema.transform(
|
|
25
|
+
(text) => ({ text: withoutTimingEnvelope(text), isError: false })
|
|
26
|
+
),
|
|
27
|
+
z.looseObject({ content: contentTextSchema, success: z.boolean().optional() }).transform(
|
|
28
|
+
(value) => ({
|
|
29
|
+
text: withoutTimingEnvelope(value.content),
|
|
30
|
+
isError: value.success === false
|
|
31
|
+
})
|
|
32
|
+
)
|
|
33
|
+
]);
|
|
34
|
+
const decodeTextOutput = (text) => {
|
|
35
|
+
const content = withoutTimingEnvelope(text);
|
|
36
|
+
try {
|
|
37
|
+
const decoded = structuredOutputSchema.safeParse(JSON.parse(content));
|
|
38
|
+
if (decoded.success) return decoded.data;
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
return { text: content, isError: false };
|
|
42
|
+
};
|
|
43
|
+
const toolOutputSchema = z.union([
|
|
44
|
+
z.string().transform(decodeTextOutput),
|
|
45
|
+
structuredOutputSchema,
|
|
46
|
+
z.json().transform((value) => ({ text: JSON.stringify(value), isError: false }))
|
|
47
|
+
]);
|
|
48
|
+
const itemSchema = z.looseObject({
|
|
49
|
+
type: z.string().default("message"),
|
|
50
|
+
role: z.string().optional(),
|
|
51
|
+
content: contentTextSchema.default(""),
|
|
52
|
+
output: toolOutputSchema.optional(),
|
|
53
|
+
tools: z.array(z.json()).optional()
|
|
54
|
+
});
|
|
55
|
+
const responsesRequestSchema = z.looseObject({
|
|
56
|
+
model: z.string(),
|
|
57
|
+
stream: z.boolean().optional(),
|
|
58
|
+
// A bare string is one user message.
|
|
59
|
+
input: z.union([
|
|
60
|
+
z.string().transform((text) => [itemSchema.parse({ role: "user", content: text })]),
|
|
61
|
+
z.array(itemSchema)
|
|
62
|
+
]),
|
|
63
|
+
tools: z.array(z.json()).optional()
|
|
64
|
+
});
|
|
65
|
+
const toolSchema = z.looseObject({
|
|
66
|
+
type: z.string(),
|
|
67
|
+
name: z.string().optional(),
|
|
68
|
+
description: z.string().optional(),
|
|
69
|
+
tools: z.array(z.json()).optional(),
|
|
70
|
+
parameters: z.looseObject({
|
|
71
|
+
properties: z.looseObject({
|
|
72
|
+
sandbox_permissions: z.looseObject({ enum: z.array(z.string()).optional() }).optional()
|
|
73
|
+
}).optional()
|
|
74
|
+
}).optional()
|
|
75
|
+
});
|
|
76
|
+
const nestedToolsOf = (description) => [...description.matchAll(/declare const tools: \{ ([A-Za-z_$][\w$]*)\(/gu)].flatMap(
|
|
77
|
+
(match) => match[1] == null ? [] : [match[1]]
|
|
78
|
+
);
|
|
79
|
+
const collectTools = (values, namespace, into) => {
|
|
80
|
+
for (const value of values) {
|
|
81
|
+
const parsed = toolSchema.safeParse(value);
|
|
82
|
+
if (!parsed.success) continue;
|
|
83
|
+
const tool = parsed.data;
|
|
84
|
+
if (tool.type === "tool_search") into.toolSearch = true;
|
|
85
|
+
else if (tool.type === "namespace") collectTools(tool.tools ?? [], tool.name ?? null, into);
|
|
86
|
+
else if ((tool.type === "function" || tool.type === "custom") && tool.name != null) {
|
|
87
|
+
const offered = { name: tool.name, namespace };
|
|
88
|
+
if (tool.parameters?.properties?.sandbox_permissions?.enum?.includes("require_escalated") === true)
|
|
89
|
+
offered.supportsEscalation = true;
|
|
90
|
+
into.tools.push(offered);
|
|
91
|
+
const nested = tool.type === "custom" ? nestedToolsOf(tool.description ?? "") : [];
|
|
92
|
+
if (nested.length > 0) into.codeMode ??= { tool: { name: tool.name, namespace }, nested };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const responsesConversation = (request) => {
|
|
97
|
+
const toolset = { tools: [], toolSearch: false, codeMode: null };
|
|
98
|
+
collectTools(request.tools ?? [], null, toolset);
|
|
99
|
+
const entries = request.input.flatMap((item) => {
|
|
100
|
+
if (item.tools != null) collectTools(item.tools, null, toolset);
|
|
101
|
+
if (item.type === "message" && item.role === "user") {
|
|
102
|
+
return [{ kind: ConversationEntryKind.User, text: item.content }];
|
|
103
|
+
}
|
|
104
|
+
if (item.type === "function_call_output" || item.type === "custom_tool_call_output") {
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
kind: ConversationEntryKind.ToolResult,
|
|
108
|
+
...item.output ?? { text: "", isError: false }
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
if (item.type === "tool_search_output") {
|
|
113
|
+
return [{ kind: ConversationEntryKind.ToolSearchOutput }];
|
|
114
|
+
}
|
|
115
|
+
return [];
|
|
116
|
+
});
|
|
117
|
+
return { entries, ...toolset };
|
|
118
|
+
};
|
|
119
|
+
const USAGE = {
|
|
120
|
+
input_tokens: 12,
|
|
121
|
+
input_tokens_details: { cached_tokens: 0 },
|
|
122
|
+
output_tokens: 4,
|
|
123
|
+
output_tokens_details: { reasoning_tokens: 0 },
|
|
124
|
+
total_tokens: 16
|
|
125
|
+
};
|
|
126
|
+
const responsesResponse = (args) => {
|
|
127
|
+
const { request, action } = args;
|
|
128
|
+
if (action.kind === ScriptedActionKind.Error) {
|
|
129
|
+
return jsonResponse(400, {
|
|
130
|
+
error: { message: action.message, type: "invalid_request_error", param: null, code: null }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const responseId = `resp_${crypto.randomUUID()}`;
|
|
134
|
+
const body = (status, output) => ({
|
|
135
|
+
id: responseId,
|
|
136
|
+
object: "response",
|
|
137
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
138
|
+
model: request.model,
|
|
139
|
+
status,
|
|
140
|
+
output,
|
|
141
|
+
usage: status === "completed" ? USAGE : null
|
|
142
|
+
});
|
|
143
|
+
const messageId = `msg_${crypto.randomUUID()}`;
|
|
144
|
+
const message = (status, content) => ({
|
|
145
|
+
type: "message",
|
|
146
|
+
id: messageId,
|
|
147
|
+
role: "assistant",
|
|
148
|
+
status,
|
|
149
|
+
content
|
|
150
|
+
});
|
|
151
|
+
const part = (value) => ({
|
|
152
|
+
type: "output_text",
|
|
153
|
+
text: value,
|
|
154
|
+
annotations: []
|
|
155
|
+
});
|
|
156
|
+
const callId = `call_${crypto.randomUUID()}`;
|
|
157
|
+
const plan = replyPlan(action);
|
|
158
|
+
const fullText = plan == null ? "" : `${plan.first}${plan.second}`;
|
|
159
|
+
const done = (() => {
|
|
160
|
+
if (action.kind === ScriptedActionKind.CodeCall) {
|
|
161
|
+
const call = {
|
|
162
|
+
type: "custom_tool_call",
|
|
163
|
+
id: `ctc_${crypto.randomUUID()}`,
|
|
164
|
+
call_id: callId,
|
|
165
|
+
name: action.tool.name,
|
|
166
|
+
input: action.source,
|
|
167
|
+
status: "completed"
|
|
168
|
+
};
|
|
169
|
+
if (action.tool.namespace != null) call.namespace = action.tool.namespace;
|
|
170
|
+
return call;
|
|
171
|
+
}
|
|
172
|
+
if (action.kind === ScriptedActionKind.ToolCall) {
|
|
173
|
+
const call = {
|
|
174
|
+
type: "function_call",
|
|
175
|
+
id: `fc_${crypto.randomUUID()}`,
|
|
176
|
+
call_id: callId,
|
|
177
|
+
name: action.tool.name,
|
|
178
|
+
arguments: JSON.stringify(action.arguments),
|
|
179
|
+
status: "completed"
|
|
180
|
+
};
|
|
181
|
+
if (action.tool.namespace != null) call.namespace = action.tool.namespace;
|
|
182
|
+
return call;
|
|
183
|
+
}
|
|
184
|
+
if (action.kind === ScriptedActionKind.ToolSearch) {
|
|
185
|
+
return {
|
|
186
|
+
type: "tool_search_call",
|
|
187
|
+
id: `tsc_${crypto.randomUUID()}`,
|
|
188
|
+
call_id: callId,
|
|
189
|
+
execution: "client",
|
|
190
|
+
status: "completed",
|
|
191
|
+
arguments: { query: action.query }
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return message("completed", [part(fullText)]);
|
|
195
|
+
})();
|
|
196
|
+
if (request.stream !== true) return jsonResponse(200, body("completed", [done]));
|
|
197
|
+
let sequence = 0;
|
|
198
|
+
const event = (type, data) => {
|
|
199
|
+
sequence += 1;
|
|
200
|
+
return sseEvent(type, { type, sequence_number: sequence, ...data });
|
|
201
|
+
};
|
|
202
|
+
const head = [event("response.created", { response: body("in_progress", []) })];
|
|
203
|
+
const end = () => [
|
|
204
|
+
event("response.output_item.done", { output_index: 0, item: done }),
|
|
205
|
+
event("response.completed", { response: body("completed", [done]) })
|
|
206
|
+
];
|
|
207
|
+
if (action.kind === ScriptedActionKind.CodeCall) {
|
|
208
|
+
head.push(
|
|
209
|
+
event("response.output_item.added", {
|
|
210
|
+
output_index: 0,
|
|
211
|
+
item: { ...done, status: "in_progress", input: "" }
|
|
212
|
+
}),
|
|
213
|
+
event("response.custom_tool_call_input.delta", {
|
|
214
|
+
item_id: done.id ?? null,
|
|
215
|
+
output_index: 0,
|
|
216
|
+
delta: action.source
|
|
217
|
+
}),
|
|
218
|
+
event("response.custom_tool_call_input.done", {
|
|
219
|
+
item_id: done.id ?? null,
|
|
220
|
+
output_index: 0,
|
|
221
|
+
input: action.source
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
return sseResponse([...head, ...end()]);
|
|
225
|
+
}
|
|
226
|
+
if (action.kind === ScriptedActionKind.ToolCall) {
|
|
227
|
+
const argumentsText = JSON.stringify(action.arguments);
|
|
228
|
+
head.push(
|
|
229
|
+
event("response.output_item.added", {
|
|
230
|
+
output_index: 0,
|
|
231
|
+
item: { ...done, status: "in_progress", arguments: "" }
|
|
232
|
+
}),
|
|
233
|
+
event("response.function_call_arguments.delta", {
|
|
234
|
+
item_id: done.id ?? null,
|
|
235
|
+
output_index: 0,
|
|
236
|
+
delta: argumentsText
|
|
237
|
+
}),
|
|
238
|
+
event("response.function_call_arguments.done", {
|
|
239
|
+
item_id: done.id ?? null,
|
|
240
|
+
output_index: 0,
|
|
241
|
+
name: action.tool.name,
|
|
242
|
+
arguments: argumentsText
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
return sseResponse([...head, ...end()]);
|
|
246
|
+
}
|
|
247
|
+
if (plan == null) {
|
|
248
|
+
head.push(event("response.output_item.added", { output_index: 0, item: done }));
|
|
249
|
+
return sseResponse([...head, ...end()]);
|
|
250
|
+
}
|
|
251
|
+
const at = { item_id: messageId, output_index: 0, content_index: 0 };
|
|
252
|
+
const delta = (text) => text === "" ? [] : [event("response.output_text.delta", { ...at, delta: text })];
|
|
253
|
+
head.push(
|
|
254
|
+
event("response.output_item.added", { output_index: 0, item: message("in_progress", []) }),
|
|
255
|
+
event("response.content_part.added", { ...at, part: part("") }),
|
|
256
|
+
...delta(plan.first)
|
|
257
|
+
);
|
|
258
|
+
if (plan.held) return heldSseResponse(head, args.timing);
|
|
259
|
+
const tail = [
|
|
260
|
+
...delta(plan.second),
|
|
261
|
+
event("response.output_text.done", { ...at, text: fullText }),
|
|
262
|
+
event("response.content_part.done", { ...at, part: part(fullText) }),
|
|
263
|
+
...end()
|
|
264
|
+
];
|
|
265
|
+
return pausedSseResponse(head, tail, plan.pauseMs);
|
|
266
|
+
};
|
|
267
|
+
export {
|
|
268
|
+
RESPONSES_LITE_HEADER,
|
|
269
|
+
responsesConversation,
|
|
270
|
+
responsesRequestSchema,
|
|
271
|
+
responsesResponse
|
|
272
|
+
};
|
|
273
|
+
//# sourceMappingURL=responses.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/conformance/scripted-model/responses.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport type { JsonObject, JsonValue } from \"../../json.mjs\";\nimport {\n ConversationEntryKind,\n replyPlan,\n ScriptedActionKind,\n type CodeModeToolIface,\n type ConversationEntry,\n type OfferedToolIface,\n type ScriptedAction,\n type ScriptedConversationIface,\n} from \"./directives.mjs\";\nimport {\n heldSseResponse,\n jsonResponse,\n pausedSseResponse,\n sseEvent,\n sseResponse,\n type HeldStreamTimingIface,\n type SseEventIface,\n} from \"./sse.mjs\";\n\n// OpenAI Responses (`POST \u2026/responses`), as the Codex CLI (remote-codex) and\n// the nanocode Codex engine speak it. Responses Lite (header\n// `x-openai-internal-codex-responses-lite`) carries the tools as an\n// `additional_tools` input item instead of `tools`; deferred tools arrive in a\n// `tool_search_output` item after a client-executed `tool_search_call`.\n\nexport const RESPONSES_LITE_HEADER = 'x-openai-internal-codex-responses-lite';\n\nconst partSchema = z.looseObject({ type: z.string(), text: z.string().optional() });\n// Message content and tool output parts as text, one line per part.\nconst contentTextSchema = z.union([\n z.string(),\n z.array(partSchema).transform((parts) =>\n parts\n .map((part) => part.text ?? '')\n .filter((value) => value !== '')\n .join('\\n'),\n ),\n]);\n\nexport interface ToolOutputIface {\n text: string;\n isError: boolean;\n}\n\n// Codex's native MCP client adds a timing envelope around the original tool content.\nconst withoutTimingEnvelope = (text: string): string =>\n /^Wall time: [0-9]+(?:\\.[0-9]+)? seconds\\nOutput:\\n([\\s\\S]*)$/u.exec(text)?.[1] ?? text;\n\nconst structuredOutputSchema = z.union([\n contentTextSchema.transform(\n (text): ToolOutputIface => ({ text: withoutTimingEnvelope(text), isError: false }),\n ),\n z.looseObject({ content: contentTextSchema, success: z.boolean().optional() }).transform(\n (value): ToolOutputIface => ({\n text: withoutTimingEnvelope(value.content),\n isError: value.success === false,\n }),\n ),\n]);\n\n// Text that is the JSON of a structured output (Codex sends MCP results so)\n// reads as that output; other text is the output itself.\nconst decodeTextOutput = (text: string): ToolOutputIface => {\n const content = withoutTimingEnvelope(text);\n try {\n const decoded = structuredOutputSchema.safeParse(JSON.parse(content));\n if (decoded.success) return decoded.data;\n } catch {\n // Plain text.\n }\n return { text: content, isError: false };\n};\n\n// A tool output: text, content parts, `{content, success}`, or JSON text of those.\nconst toolOutputSchema = z.union([\n z.string().transform(decodeTextOutput),\n structuredOutputSchema,\n z.json().transform((value): ToolOutputIface => ({ text: JSON.stringify(value), isError: false })),\n]);\n\nconst itemSchema = z.looseObject({\n type: z.string().default('message'),\n role: z.string().optional(),\n content: contentTextSchema.default(''),\n output: toolOutputSchema.optional(),\n tools: z.array(z.json()).optional(),\n});\n\nexport const responsesRequestSchema = z.looseObject({\n model: z.string(),\n stream: z.boolean().optional(),\n // A bare string is one user message.\n input: z.union([\n z.string().transform((text) => [itemSchema.parse({ role: 'user', content: text })]),\n z.array(itemSchema),\n ]),\n tools: z.array(z.json()).optional(),\n});\n\nexport type ResponsesRequest = z.infer<typeof responsesRequestSchema>;\n\nconst toolSchema = z.looseObject({\n type: z.string(),\n name: z.string().optional(),\n description: z.string().optional(),\n tools: z.array(z.json()).optional(),\n parameters: z\n .looseObject({\n properties: z\n .looseObject({\n sandbox_permissions: z.looseObject({ enum: z.array(z.string()).optional() }).optional(),\n })\n .optional(),\n })\n .optional(),\n});\n\ninterface ToolsetIface {\n tools: OfferedToolIface[];\n toolSearch: boolean;\n codeMode: CodeModeToolIface | null;\n}\n\n// Codex code mode declares each nested tool in the code tool's description as\n// `declare const tools: { <name>(...`.\nconst nestedToolsOf = (description: string): string[] =>\n [...description.matchAll(/declare const tools: \\{ ([A-Za-z_$][\\w$]*)\\(/gu)].flatMap((match) =>\n match[1] == null ? [] : [match[1]],\n );\n\n// Namespace children keep their namespace for the function call.\nconst collectTools = (values: JsonValue[], namespace: string | null, into: ToolsetIface): void => {\n for (const value of values) {\n const parsed = toolSchema.safeParse(value);\n if (!parsed.success) continue;\n const tool = parsed.data;\n if (tool.type === 'tool_search') into.toolSearch = true;\n else if (tool.type === 'namespace') collectTools(tool.tools ?? [], tool.name ?? null, into);\n else if ((tool.type === 'function' || tool.type === 'custom') && tool.name != null) {\n const offered: OfferedToolIface = { name: tool.name, namespace };\n if (\n tool.parameters?.properties?.sandbox_permissions?.enum?.includes('require_escalated') ===\n true\n )\n offered.supportsEscalation = true;\n into.tools.push(offered);\n const nested = tool.type === 'custom' ? nestedToolsOf(tool.description ?? '') : [];\n if (nested.length > 0) into.codeMode ??= { tool: { name: tool.name, namespace }, nested };\n }\n }\n};\n\nexport const responsesConversation = (request: ResponsesRequest): ScriptedConversationIface => {\n const toolset: ToolsetIface = { tools: [], toolSearch: false, codeMode: null };\n collectTools(request.tools ?? [], null, toolset);\n const entries = request.input.flatMap((item): ConversationEntry[] => {\n if (item.tools != null) collectTools(item.tools, null, toolset);\n if (item.type === 'message' && item.role === 'user') {\n return [{ kind: ConversationEntryKind.User, text: item.content }];\n }\n if (item.type === 'function_call_output' || item.type === 'custom_tool_call_output') {\n return [\n {\n kind: ConversationEntryKind.ToolResult,\n ...(item.output ?? { text: '', isError: false }),\n },\n ];\n }\n if (item.type === 'tool_search_output') {\n return [{ kind: ConversationEntryKind.ToolSearchOutput }];\n }\n return [];\n });\n return { entries, ...toolset };\n};\n\nconst USAGE: JsonObject = {\n input_tokens: 12,\n input_tokens_details: { cached_tokens: 0 },\n output_tokens: 4,\n output_tokens_details: { reasoning_tokens: 0 },\n total_tokens: 16,\n};\n\nexport const responsesResponse = (args: {\n request: ResponsesRequest;\n action: ScriptedAction;\n timing: HeldStreamTimingIface;\n}): Response => {\n const { request, action } = args;\n if (action.kind === ScriptedActionKind.Error) {\n return jsonResponse(400, {\n error: { message: action.message, type: 'invalid_request_error', param: null, code: null },\n });\n }\n const responseId = `resp_${crypto.randomUUID()}`;\n const body = (status: string, output: JsonValue[]): JsonObject => ({\n id: responseId,\n object: 'response',\n created_at: Math.floor(Date.now() / 1000),\n model: request.model,\n status,\n output,\n usage: status === 'completed' ? USAGE : null,\n });\n const messageId = `msg_${crypto.randomUUID()}`;\n const message = (status: string, content: JsonValue[]): JsonObject => ({\n type: 'message',\n id: messageId,\n role: 'assistant',\n status,\n content,\n });\n const part = (value: string): JsonObject => ({\n type: 'output_text',\n text: value,\n annotations: [],\n });\n const callId = `call_${crypto.randomUUID()}`;\n const plan = replyPlan(action);\n const fullText = plan == null ? '' : `${plan.first}${plan.second}`;\n const done = ((): JsonObject => {\n if (action.kind === ScriptedActionKind.CodeCall) {\n const call: JsonObject = {\n type: 'custom_tool_call',\n id: `ctc_${crypto.randomUUID()}`,\n call_id: callId,\n name: action.tool.name,\n input: action.source,\n status: 'completed',\n };\n if (action.tool.namespace != null) call.namespace = action.tool.namespace;\n return call;\n }\n if (action.kind === ScriptedActionKind.ToolCall) {\n const call: JsonObject = {\n type: 'function_call',\n id: `fc_${crypto.randomUUID()}`,\n call_id: callId,\n name: action.tool.name,\n arguments: JSON.stringify(action.arguments),\n status: 'completed',\n };\n if (action.tool.namespace != null) call.namespace = action.tool.namespace;\n return call;\n }\n if (action.kind === ScriptedActionKind.ToolSearch) {\n return {\n type: 'tool_search_call',\n id: `tsc_${crypto.randomUUID()}`,\n call_id: callId,\n execution: 'client',\n status: 'completed',\n arguments: { query: action.query },\n };\n }\n return message('completed', [part(fullText)]);\n })();\n if (request.stream !== true) return jsonResponse(200, body('completed', [done]));\n let sequence = 0;\n const event = (type: string, data: JsonObject): SseEventIface => {\n sequence += 1;\n return sseEvent(type, { type, sequence_number: sequence, ...data });\n };\n const head: SseEventIface[] = [event('response.created', { response: body('in_progress', []) })];\n const end = (): SseEventIface[] => [\n event('response.output_item.done', { output_index: 0, item: done }),\n event('response.completed', { response: body('completed', [done]) }),\n ];\n if (action.kind === ScriptedActionKind.CodeCall) {\n head.push(\n event('response.output_item.added', {\n output_index: 0,\n item: { ...done, status: 'in_progress', input: '' },\n }),\n event('response.custom_tool_call_input.delta', {\n item_id: done.id ?? null,\n output_index: 0,\n delta: action.source,\n }),\n event('response.custom_tool_call_input.done', {\n item_id: done.id ?? null,\n output_index: 0,\n input: action.source,\n }),\n );\n return sseResponse([...head, ...end()]);\n }\n if (action.kind === ScriptedActionKind.ToolCall) {\n const argumentsText = JSON.stringify(action.arguments);\n head.push(\n event('response.output_item.added', {\n output_index: 0,\n item: { ...done, status: 'in_progress', arguments: '' },\n }),\n event('response.function_call_arguments.delta', {\n item_id: done.id ?? null,\n output_index: 0,\n delta: argumentsText,\n }),\n event('response.function_call_arguments.done', {\n item_id: done.id ?? null,\n output_index: 0,\n name: action.tool.name,\n arguments: argumentsText,\n }),\n );\n return sseResponse([...head, ...end()]);\n }\n if (plan == null) {\n head.push(event('response.output_item.added', { output_index: 0, item: done }));\n return sseResponse([...head, ...end()]);\n }\n const at = { item_id: messageId, output_index: 0, content_index: 0 };\n const delta = (text: string): SseEventIface[] =>\n text === '' ? [] : [event('response.output_text.delta', { ...at, delta: text })];\n head.push(\n event('response.output_item.added', { output_index: 0, item: message('in_progress', []) }),\n event('response.content_part.added', { ...at, part: part('') }),\n ...delta(plan.first),\n );\n if (plan.held) return heldSseResponse(head, args.timing);\n // Sequence numbers follow emission order, so the tail is built after the head.\n const tail = [\n ...delta(plan.second),\n event('response.output_text.done', { ...at, text: fullText }),\n event('response.content_part.done', { ...at, part: part(fullText) }),\n ...end(),\n ];\n return pausedSseResponse(head, tail, plan.pauseMs);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AAEnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAQA,MAAM,wBAAwB;AAErC,MAAM,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAElF,MAAM,oBAAoB,EAAE,MAAM;AAAA,EAChC,EAAE,OAAO;AAAA,EACT,EAAE,MAAM,UAAU,EAAE;AAAA,IAAU,CAAC,UAC7B,MACG,IAAI,CAAC,SAAS,KAAK,QAAQ,EAAE,EAC7B,OAAO,CAAC,UAAU,UAAU,EAAE,EAC9B,KAAK,IAAI;AAAA,EACd;AACF,CAAC;AAQD,MAAM,wBAAwB,CAAC,SAC7B,gEAAgE,KAAK,IAAI,IAAI,CAAC,KAAK;AAErF,MAAM,yBAAyB,EAAE,MAAM;AAAA,EACrC,kBAAkB;AAAA,IAChB,CAAC,UAA2B,EAAE,MAAM,sBAAsB,IAAI,GAAG,SAAS,MAAM;AAAA,EAClF;AAAA,EACA,EAAE,YAAY,EAAE,SAAS,mBAAmB,SAAS,EAAE,QAAQ,EAAE,SA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BAA+B,EAAE,GAAG,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;AAAA,IAC9D,GAAG,MAAM,KAAK,KAAK;AAAA,EACrB;AACA,MAAI,KAAK,KAAM,QAAO,gBAAgB,MAAM,KAAK,MAAM;AAEvD,QAAM,OAAO;AAAA,IACX,GAAG,MAAM,KAAK,MAAM;AAAA,IACpB,MAAM,6BAA6B,EAAE,GAAG,IAAI,MAAM,SAAS,CAAC;AAAA,IAC5D,MAAM,8BAA8B,EAAE,GAAG,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;AAAA,IACnE,GAAG,IAAI;AAAA,EACT;AACA,SAAO,kBAAkB,MAAM,MAAM,KAAK,OAAO;AACnD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JsonValue } from "../../json.mjs";
|
|
2
|
+
export interface SseEventIface {
|
|
3
|
+
event: string | null;
|
|
4
|
+
data: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const sseEvent: (event: string | null, data: JsonValue) => SseEventIface;
|
|
7
|
+
export declare const sseResponse: (events: SseEventIface[]) => Response;
|
|
8
|
+
export declare const jsonResponse: (status: number, body: JsonValue) => Response;
|
|
9
|
+
export interface HeldStreamTimingIface {
|
|
10
|
+
holdMs: number;
|
|
11
|
+
keepaliveMs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_HELD_STREAM_TIMING: HeldStreamTimingIface;
|
|
14
|
+
export declare const heldSseResponse: (events: SseEventIface[], timing: HeldStreamTimingIface) => Response;
|
|
15
|
+
export declare const pausedSseResponse: (head: SseEventIface[], tail: SseEventIface[], pauseMs: number) => Response;
|