@yolk-sdk/emulators 0.1.0-canary.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2135 -0
- package/dist/anthropic.d.mts +269 -0
- package/dist/anthropic.d.mts.map +1 -0
- package/dist/anthropic.mjs +177 -0
- package/dist/anthropic.mjs.map +1 -0
- package/dist/chat-completions.d.mts +288 -0
- package/dist/chat-completions.d.mts.map +1 -0
- package/dist/chat-completions.mjs +451 -0
- package/dist/chat-completions.mjs.map +1 -0
- package/dist/codex.d.mts +265 -0
- package/dist/codex.d.mts.map +1 -0
- package/dist/codex.mjs +199 -0
- package/dist/codex.mjs.map +1 -0
- package/dist/dropbox/api.d.mts +63 -0
- package/dist/dropbox/api.d.mts.map +1 -0
- package/dist/dropbox/api.mjs +565 -0
- package/dist/dropbox/api.mjs.map +1 -0
- package/dist/dropbox/state.d.mts +136 -0
- package/dist/dropbox/state.d.mts.map +1 -0
- package/dist/dropbox/state.mjs +209 -0
- package/dist/dropbox/state.mjs.map +1 -0
- package/dist/dropbox.d.mts +79 -0
- package/dist/dropbox.d.mts.map +1 -0
- package/dist/dropbox.mjs +124 -0
- package/dist/dropbox.mjs.map +1 -0
- package/dist/email-fixtures.d.mts +36 -0
- package/dist/email-fixtures.d.mts.map +1 -0
- package/dist/email-fixtures.mjs +1080 -0
- package/dist/email-fixtures.mjs.map +1 -0
- package/dist/email.d.mts +160 -0
- package/dist/email.d.mts.map +1 -0
- package/dist/email.mjs +608 -0
- package/dist/email.mjs.map +1 -0
- package/dist/emulator-compose.d.mts +40 -0
- package/dist/emulator-compose.d.mts.map +1 -0
- package/dist/emulator-compose.mjs +91 -0
- package/dist/emulator-compose.mjs.map +1 -0
- package/dist/emulator-http.d.mts +53 -0
- package/dist/emulator-http.d.mts.map +1 -0
- package/dist/emulator-http.mjs +117 -0
- package/dist/emulator-http.mjs.map +1 -0
- package/dist/emulator-kernel.d.mts +176 -0
- package/dist/emulator-kernel.d.mts.map +1 -0
- package/dist/emulator-kernel.mjs +413 -0
- package/dist/emulator-kernel.mjs.map +1 -0
- package/dist/fixture-route.d.mts +129 -0
- package/dist/fixture-route.d.mts.map +1 -0
- package/dist/fixture-route.mjs +257 -0
- package/dist/fixture-route.mjs.map +1 -0
- package/dist/fortnox/api.d.mts +92 -0
- package/dist/fortnox/api.d.mts.map +1 -0
- package/dist/fortnox/api.mjs +750 -0
- package/dist/fortnox/api.mjs.map +1 -0
- package/dist/fortnox/state.d.mts +533 -0
- package/dist/fortnox/state.d.mts.map +1 -0
- package/dist/fortnox/state.mjs +612 -0
- package/dist/fortnox/state.mjs.map +1 -0
- package/dist/fortnox.d.mts +128 -0
- package/dist/fortnox.d.mts.map +1 -0
- package/dist/fortnox.mjs +403 -0
- package/dist/fortnox.mjs.map +1 -0
- package/dist/gateway-evaluate-recordings.d.mts +12 -0
- package/dist/gateway-evaluate-recordings.d.mts.map +1 -0
- package/dist/gateway-evaluate-recordings.mjs +128 -0
- package/dist/gateway-evaluate-recordings.mjs.map +1 -0
- package/dist/gateway.d.mts +272 -0
- package/dist/gateway.d.mts.map +1 -0
- package/dist/gateway.mjs +400 -0
- package/dist/gateway.mjs.map +1 -0
- package/dist/github/api.d.mts +63 -0
- package/dist/github/api.d.mts.map +1 -0
- package/dist/github/api.mjs +527 -0
- package/dist/github/api.mjs.map +1 -0
- package/dist/github/state.d.mts +272 -0
- package/dist/github/state.d.mts.map +1 -0
- package/dist/github/state.mjs +303 -0
- package/dist/github/state.mjs.map +1 -0
- package/dist/github.d.mts +77 -0
- package/dist/github.d.mts.map +1 -0
- package/dist/github.mjs +180 -0
- package/dist/github.mjs.map +1 -0
- package/dist/google/calendar.d.mts +10 -0
- package/dist/google/calendar.d.mts.map +1 -0
- package/dist/google/calendar.mjs +252 -0
- package/dist/google/calendar.mjs.map +1 -0
- package/dist/google/drive.d.mts +8 -0
- package/dist/google/drive.d.mts.map +1 -0
- package/dist/google/drive.mjs +252 -0
- package/dist/google/drive.mjs.map +1 -0
- package/dist/google/gmail.d.mts +10 -0
- package/dist/google/gmail.d.mts.map +1 -0
- package/dist/google/gmail.mjs +591 -0
- package/dist/google/gmail.mjs.map +1 -0
- package/dist/google/shared.d.mts +107 -0
- package/dist/google/shared.d.mts.map +1 -0
- package/dist/google/shared.mjs +146 -0
- package/dist/google/shared.mjs.map +1 -0
- package/dist/google/state.d.mts +385 -0
- package/dist/google/state.d.mts.map +1 -0
- package/dist/google/state.mjs +496 -0
- package/dist/google/state.mjs.map +1 -0
- package/dist/google.d.mts +75 -0
- package/dist/google.d.mts.map +1 -0
- package/dist/google.mjs +210 -0
- package/dist/google.mjs.map +1 -0
- package/dist/linkedin-search/api.d.mts +45 -0
- package/dist/linkedin-search/api.d.mts.map +1 -0
- package/dist/linkedin-search/api.mjs +181 -0
- package/dist/linkedin-search/api.mjs.map +1 -0
- package/dist/linkedin-search/state.d.mts +123 -0
- package/dist/linkedin-search/state.d.mts.map +1 -0
- package/dist/linkedin-search/state.mjs +261 -0
- package/dist/linkedin-search/state.mjs.map +1 -0
- package/dist/linkedin-search.d.mts +69 -0
- package/dist/linkedin-search.d.mts.map +1 -0
- package/dist/linkedin-search.mjs +158 -0
- package/dist/linkedin-search.mjs.map +1 -0
- package/dist/mcp/api.d.mts +44 -0
- package/dist/mcp/api.d.mts.map +1 -0
- package/dist/mcp/api.mjs +557 -0
- package/dist/mcp/api.mjs.map +1 -0
- package/dist/mcp/recordings.d.mts +40 -0
- package/dist/mcp/recordings.d.mts.map +1 -0
- package/dist/mcp/recordings.mjs +2390 -0
- package/dist/mcp/recordings.mjs.map +1 -0
- package/dist/mcp/state.d.mts +71 -0
- package/dist/mcp/state.d.mts.map +1 -0
- package/dist/mcp/state.mjs +83 -0
- package/dist/mcp/state.mjs.map +1 -0
- package/dist/mcp.d.mts +84 -0
- package/dist/mcp.d.mts.map +1 -0
- package/dist/mcp.mjs +241 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/messages.d.mts +183 -0
- package/dist/messages.d.mts.map +1 -0
- package/dist/messages.mjs +532 -0
- package/dist/messages.mjs.map +1 -0
- package/dist/microsoft/api.d.mts +47 -0
- package/dist/microsoft/api.d.mts.map +1 -0
- package/dist/microsoft/api.mjs +178 -0
- package/dist/microsoft/api.mjs.map +1 -0
- package/dist/microsoft/calendar.d.mts +30 -0
- package/dist/microsoft/calendar.d.mts.map +1 -0
- package/dist/microsoft/calendar.mjs +271 -0
- package/dist/microsoft/calendar.mjs.map +1 -0
- package/dist/microsoft/drive.d.mts +36 -0
- package/dist/microsoft/drive.d.mts.map +1 -0
- package/dist/microsoft/drive.mjs +298 -0
- package/dist/microsoft/drive.mjs.map +1 -0
- package/dist/microsoft/graph.d.mts +198 -0
- package/dist/microsoft/graph.d.mts.map +1 -0
- package/dist/microsoft/graph.mjs +264 -0
- package/dist/microsoft/graph.mjs.map +1 -0
- package/dist/microsoft/mail.d.mts +48 -0
- package/dist/microsoft/mail.d.mts.map +1 -0
- package/dist/microsoft/mail.mjs +488 -0
- package/dist/microsoft/mail.mjs.map +1 -0
- package/dist/microsoft/state.d.mts +480 -0
- package/dist/microsoft/state.d.mts.map +1 -0
- package/dist/microsoft/state.mjs +625 -0
- package/dist/microsoft/state.mjs.map +1 -0
- package/dist/microsoft.d.mts +168 -0
- package/dist/microsoft.d.mts.map +1 -0
- package/dist/microsoft.mjs +483 -0
- package/dist/microsoft.mjs.map +1 -0
- package/dist/node.d.mts +47 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +178 -0
- package/dist/node.mjs.map +1 -0
- package/dist/notion/api.d.mts +51 -0
- package/dist/notion/api.d.mts.map +1 -0
- package/dist/notion/api.mjs +507 -0
- package/dist/notion/api.mjs.map +1 -0
- package/dist/notion/state.d.mts +329 -0
- package/dist/notion/state.d.mts.map +1 -0
- package/dist/notion/state.mjs +432 -0
- package/dist/notion/state.mjs.map +1 -0
- package/dist/notion.d.mts +72 -0
- package/dist/notion.d.mts.map +1 -0
- package/dist/notion.mjs +127 -0
- package/dist/notion.mjs.map +1 -0
- package/dist/openai.d.mts +165 -0
- package/dist/openai.d.mts.map +1 -0
- package/dist/openai.mjs +141 -0
- package/dist/openai.mjs.map +1 -0
- package/dist/opencode-recordings.d.mts +7 -0
- package/dist/opencode-recordings.d.mts.map +1 -0
- package/dist/opencode-recordings.mjs +222 -0
- package/dist/opencode-recordings.mjs.map +1 -0
- package/dist/opencode.d.mts +70 -0
- package/dist/opencode.d.mts.map +1 -0
- package/dist/opencode.mjs +217 -0
- package/dist/opencode.mjs.map +1 -0
- package/dist/r2-fixtures.d.mts +36 -0
- package/dist/r2-fixtures.d.mts.map +1 -0
- package/dist/r2-fixtures.mjs +245 -0
- package/dist/r2-fixtures.mjs.map +1 -0
- package/dist/r2-guard.d.mts +43 -0
- package/dist/r2-guard.d.mts.map +1 -0
- package/dist/r2-guard.mjs +215 -0
- package/dist/r2-guard.mjs.map +1 -0
- package/dist/r2.d.mts +166 -0
- package/dist/r2.d.mts.map +1 -0
- package/dist/r2.mjs +517 -0
- package/dist/r2.mjs.map +1 -0
- package/dist/responses.d.mts +231 -0
- package/dist/responses.d.mts.map +1 -0
- package/dist/responses.mjs +556 -0
- package/dist/responses.mjs.map +1 -0
- package/dist/route-evidence.d.mts +45 -0
- package/dist/route-evidence.d.mts.map +1 -0
- package/dist/route-evidence.mjs +56 -0
- package/dist/route-evidence.mjs.map +1 -0
- package/dist/router.d.mts +93 -0
- package/dist/router.d.mts.map +1 -0
- package/dist/router.mjs +259 -0
- package/dist/router.mjs.map +1 -0
- package/dist/stateful-core.d.mts +17 -0
- package/dist/stateful-core.d.mts.map +1 -0
- package/dist/stateful-core.mjs +41 -0
- package/dist/stateful-core.mjs.map +1 -0
- package/dist/stateful-emulator.d.mts +565 -0
- package/dist/stateful-emulator.d.mts.map +1 -0
- package/dist/stateful-emulator.mjs +1228 -0
- package/dist/stateful-emulator.mjs.map +1 -0
- package/dist/stateful-secrets.d.mts +84 -0
- package/dist/stateful-secrets.d.mts.map +1 -0
- package/dist/stateful-secrets.mjs +216 -0
- package/dist/stateful-secrets.mjs.map +1 -0
- package/dist/subscription-usage-recordings.d.mts +9 -0
- package/dist/subscription-usage-recordings.d.mts.map +1 -0
- package/dist/subscription-usage-recordings.mjs +53 -0
- package/dist/subscription-usage-recordings.mjs.map +1 -0
- package/dist/subscription-usage.d.mts +53 -0
- package/dist/subscription-usage.d.mts.map +1 -0
- package/dist/subscription-usage.mjs +21 -0
- package/dist/subscription-usage.mjs.map +1 -0
- package/dist/telegram/api.d.mts +34 -0
- package/dist/telegram/api.d.mts.map +1 -0
- package/dist/telegram/api.mjs +257 -0
- package/dist/telegram/api.mjs.map +1 -0
- package/dist/telegram/state.d.mts +128 -0
- package/dist/telegram/state.d.mts.map +1 -0
- package/dist/telegram/state.mjs +154 -0
- package/dist/telegram/state.mjs.map +1 -0
- package/dist/telegram.d.mts +62 -0
- package/dist/telegram.d.mts.map +1 -0
- package/dist/telegram.mjs +127 -0
- package/dist/telegram.mjs.map +1 -0
- package/dist/todoist/api.d.mts +55 -0
- package/dist/todoist/api.d.mts.map +1 -0
- package/dist/todoist/api.mjs +415 -0
- package/dist/todoist/api.mjs.map +1 -0
- package/dist/todoist/state.d.mts +275 -0
- package/dist/todoist/state.d.mts.map +1 -0
- package/dist/todoist/state.mjs +345 -0
- package/dist/todoist/state.mjs.map +1 -0
- package/dist/todoist.d.mts +68 -0
- package/dist/todoist.d.mts.map +1 -0
- package/dist/todoist.mjs +181 -0
- package/dist/todoist.mjs.map +1 -0
- package/dist/xai.d.mts +267 -0
- package/dist/xai.d.mts.map +1 -0
- package/dist/xai.mjs +252 -0
- package/dist/xai.mjs.map +1 -0
- package/package.json +157 -0
- package/src/anthropic.ts +289 -0
- package/src/chat-completions.ts +924 -0
- package/src/codex.ts +296 -0
- package/src/dropbox/api.ts +1084 -0
- package/src/dropbox/state.ts +364 -0
- package/src/dropbox.ts +203 -0
- package/src/email-fixtures.ts +1297 -0
- package/src/email.ts +1108 -0
- package/src/emulator-compose.ts +147 -0
- package/src/emulator-http.ts +184 -0
- package/src/emulator-kernel.ts +844 -0
- package/src/fixture-route.ts +561 -0
- package/src/fortnox/api.ts +1352 -0
- package/src/fortnox/state.ts +798 -0
- package/src/fortnox.ts +801 -0
- package/src/gateway-evaluate-recordings.ts +153 -0
- package/src/gateway.ts +530 -0
- package/src/github/api.ts +986 -0
- package/src/github/state.ts +439 -0
- package/src/github.ts +271 -0
- package/src/google/calendar.ts +486 -0
- package/src/google/drive.ts +471 -0
- package/src/google/gmail.ts +1011 -0
- package/src/google/shared.ts +321 -0
- package/src/google/state.ts +686 -0
- package/src/google.ts +298 -0
- package/src/linkedin-search/api.ts +363 -0
- package/src/linkedin-search/state.ts +373 -0
- package/src/linkedin-search.ts +241 -0
- package/src/mcp/api.ts +995 -0
- package/src/mcp/recordings.ts +2665 -0
- package/src/mcp/state.ts +125 -0
- package/src/mcp.ts +319 -0
- package/src/messages.ts +844 -0
- package/src/microsoft/api.ts +426 -0
- package/src/microsoft/calendar.ts +491 -0
- package/src/microsoft/drive.ts +541 -0
- package/src/microsoft/graph.ts +550 -0
- package/src/microsoft/mail.ts +833 -0
- package/src/microsoft/state.ts +822 -0
- package/src/microsoft.ts +982 -0
- package/src/node.ts +293 -0
- package/src/notion/api.ts +976 -0
- package/src/notion/state.ts +512 -0
- package/src/notion.ts +210 -0
- package/src/openai.ts +198 -0
- package/src/opencode-recordings.ts +257 -0
- package/src/opencode.ts +271 -0
- package/src/r2-fixtures.ts +295 -0
- package/src/r2-guard.ts +323 -0
- package/src/r2.ts +890 -0
- package/src/responses.ts +901 -0
- package/src/route-evidence.ts +90 -0
- package/src/router.ts +490 -0
- package/src/stateful-core.ts +70 -0
- package/src/stateful-emulator.ts +2571 -0
- package/src/stateful-secrets.ts +299 -0
- package/src/subscription-usage-recordings.ts +77 -0
- package/src/subscription-usage.ts +68 -0
- package/src/telegram/api.ts +437 -0
- package/src/telegram/state.ts +229 -0
- package/src/telegram.ts +227 -0
- package/src/todoist/api.ts +736 -0
- package/src/todoist/state.ts +456 -0
- package/src/todoist.ts +316 -0
- package/src/xai.ts +341 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { EmulatorEvidence, EmulatorRouteEvidence } from "./route-evidence.mjs";
|
|
2
|
+
import { EmulatorApi, EmulatorCoverage, EmulatorFaultState, EmulatorRouteCoverage } from "./emulator-kernel.mjs";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
|
|
5
|
+
//#region src/chat-completions.d.ts
|
|
6
|
+
/** Optional fault filter; an omitted field matches every request. `path` ending in `*` is a prefix. */
|
|
7
|
+
declare const ChatFaultMatch: Schema.Struct<{
|
|
8
|
+
readonly path: Schema.optionalKey<Schema.String>;
|
|
9
|
+
readonly model: Schema.optionalKey<Schema.String>;
|
|
10
|
+
}>;
|
|
11
|
+
type ChatFaultMatch = typeof ChatFaultMatch.Type;
|
|
12
|
+
/**
|
|
13
|
+
* Wire faults for emulated routes:
|
|
14
|
+
*
|
|
15
|
+
* - `status`: answer with this status, headers, and body instead of a
|
|
16
|
+
* completion (for example 429 with `retry-after`). The body defaults to the
|
|
17
|
+
* emulator's error envelope. Statuses that cannot carry a body (1xx, 204,
|
|
18
|
+
* 205, 304) and redirects (3xx) are rejected, as are invalid header names or
|
|
19
|
+
* values and a `location` header; scripted errors follow the same rules.
|
|
20
|
+
* - `error-after-chunks`: send `chunks` body chunks, then error the body
|
|
21
|
+
* stream (a dropped connection).
|
|
22
|
+
* - `truncate-after-chunks`: send `chunks` body chunks, then close the body
|
|
23
|
+
* cleanly (for example without `data: [DONE]`).
|
|
24
|
+
*
|
|
25
|
+
* A whole JSON body counts as one chunk. A chunk fault that cannot take
|
|
26
|
+
* effect (`error-after-chunks` beyond the chunk count, or
|
|
27
|
+
* `truncate-after-chunks` at or beyond it) answers 500 with an emulator error
|
|
28
|
+
* instead of silently doing nothing, and is not consumed.
|
|
29
|
+
*/
|
|
30
|
+
declare const ChatFault: Schema.Union<readonly [Schema.Struct<{
|
|
31
|
+
readonly match: Schema.optionalKey<Schema.Struct<{
|
|
32
|
+
readonly path: Schema.optionalKey<Schema.String>;
|
|
33
|
+
readonly model: Schema.optionalKey<Schema.String>;
|
|
34
|
+
}>>;
|
|
35
|
+
readonly count: Schema.optionalKey<Schema.Int>;
|
|
36
|
+
readonly kind: Schema.Literal<"status">;
|
|
37
|
+
readonly status: Schema.Int;
|
|
38
|
+
readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
39
|
+
readonly body: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
40
|
+
}>, Schema.Struct<{
|
|
41
|
+
readonly match: Schema.optionalKey<Schema.Struct<{
|
|
42
|
+
readonly path: Schema.optionalKey<Schema.String>;
|
|
43
|
+
readonly model: Schema.optionalKey<Schema.String>;
|
|
44
|
+
}>>;
|
|
45
|
+
readonly count: Schema.optionalKey<Schema.Int>;
|
|
46
|
+
readonly kind: Schema.Literal<"error-after-chunks">;
|
|
47
|
+
readonly chunks: Schema.Int;
|
|
48
|
+
}>, Schema.Struct<{
|
|
49
|
+
readonly match: Schema.optionalKey<Schema.Struct<{
|
|
50
|
+
readonly path: Schema.optionalKey<Schema.String>;
|
|
51
|
+
readonly model: Schema.optionalKey<Schema.String>;
|
|
52
|
+
}>>;
|
|
53
|
+
readonly count: Schema.optionalKey<Schema.Int>;
|
|
54
|
+
readonly kind: Schema.Literal<"truncate-after-chunks">;
|
|
55
|
+
readonly chunks: Schema.Int;
|
|
56
|
+
}>]>;
|
|
57
|
+
type ChatFault = typeof ChatFault.Type;
|
|
58
|
+
type ChatFaultKind = ChatFault['kind'];
|
|
59
|
+
/** Usage for a scripted turn (sent as the wire `usage` object). */
|
|
60
|
+
declare const ChatScriptedUsage: Schema.Struct<{
|
|
61
|
+
readonly promptTokens: Schema.Int;
|
|
62
|
+
readonly completionTokens: Schema.Int;
|
|
63
|
+
readonly reasoningTokens: Schema.optionalKey<Schema.Int>;
|
|
64
|
+
}>;
|
|
65
|
+
type ChatScriptedUsage = typeof ChatScriptedUsage.Type;
|
|
66
|
+
/** One scripted tool call; its JSON arguments stream as these fragments. */
|
|
67
|
+
declare const ChatScriptedToolCall: Schema.Struct<{
|
|
68
|
+
readonly name: Schema.NonEmptyString;
|
|
69
|
+
readonly argumentFragments: Schema.$Array<Schema.String>;
|
|
70
|
+
readonly id: Schema.optionalKey<Schema.NonEmptyString>;
|
|
71
|
+
}>;
|
|
72
|
+
type ChatScriptedToolCall = typeof ChatScriptedToolCall.Type;
|
|
73
|
+
/** Scripted completion fields every Chat Completions emulator accepts. */
|
|
74
|
+
declare const chatScriptedCompletionFields: {
|
|
75
|
+
text: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
76
|
+
toolCalls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
77
|
+
readonly name: Schema.NonEmptyString;
|
|
78
|
+
readonly argumentFragments: Schema.$Array<Schema.String>;
|
|
79
|
+
readonly id: Schema.optionalKey<Schema.NonEmptyString>;
|
|
80
|
+
}>>>;
|
|
81
|
+
usage: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
|
|
82
|
+
readonly promptTokens: Schema.Int;
|
|
83
|
+
readonly completionTokens: Schema.Int;
|
|
84
|
+
readonly reasoningTokens: Schema.optionalKey<Schema.Int>;
|
|
85
|
+
}>>>;
|
|
86
|
+
finishReason: Schema.optionalKey<Schema.NonEmptyString>;
|
|
87
|
+
};
|
|
88
|
+
/** Scripted completion fields for emulators that emulate streamed reasoning. */
|
|
89
|
+
declare const chatScriptedReasoningFields: {
|
|
90
|
+
reasoning: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
91
|
+
reasoningField: Schema.optionalKey<Schema.Literals<readonly ["reasoning_content", "reasoning"]>>;
|
|
92
|
+
order: Schema.optionalKey<Schema.Literals<readonly ["reasoning-first", "text-first"]>>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The reasoning variant of a scripted completion (the Gateway's shape; `/openai` uses the
|
|
96
|
+
* reasoning-free `OpenAiScriptedCompletion`). Every field is exact (nothing is
|
|
97
|
+
* filled in) except: `usage` omitted is synthesized when the request asks for
|
|
98
|
+
* usage, and `null` drops it; `finishReason` omitted is `tool_calls` with tool
|
|
99
|
+
* calls, else `stop`. `order` defaults to `reasoning-first`; `reasoningField`
|
|
100
|
+
* defaults to the emulator's wire profile field (`reasoning` for the Gateway,
|
|
101
|
+
* as recorded live; `reasoning_content` is the DeepSeek-native alternative).
|
|
102
|
+
*/
|
|
103
|
+
declare const ChatScriptedReasoningCompletion: Schema.Struct<{
|
|
104
|
+
readonly text: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
105
|
+
readonly reasoning: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
106
|
+
readonly reasoningField: Schema.optionalKey<Schema.Literals<readonly ["reasoning_content", "reasoning"]>>;
|
|
107
|
+
readonly order: Schema.optionalKey<Schema.Literals<readonly ["reasoning-first", "text-first"]>>;
|
|
108
|
+
readonly toolCalls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
109
|
+
readonly name: Schema.NonEmptyString;
|
|
110
|
+
readonly argumentFragments: Schema.$Array<Schema.String>;
|
|
111
|
+
readonly id: Schema.optionalKey<Schema.NonEmptyString>;
|
|
112
|
+
}>>>;
|
|
113
|
+
readonly usage: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
|
|
114
|
+
readonly promptTokens: Schema.Int;
|
|
115
|
+
readonly completionTokens: Schema.Int;
|
|
116
|
+
readonly reasoningTokens: Schema.optionalKey<Schema.Int>;
|
|
117
|
+
}>>>;
|
|
118
|
+
readonly finishReason: Schema.optionalKey<Schema.NonEmptyString>;
|
|
119
|
+
}>;
|
|
120
|
+
type ChatScriptedReasoningCompletion = typeof ChatScriptedReasoningCompletion.Type;
|
|
121
|
+
/** A scripted error response: status, body (a string is sent as is), and optional headers. */
|
|
122
|
+
declare const ChatScriptedError: Schema.Struct<{
|
|
123
|
+
readonly error: Schema.Struct<{
|
|
124
|
+
readonly status: Schema.Int;
|
|
125
|
+
readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
126
|
+
readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
127
|
+
}>;
|
|
128
|
+
}>;
|
|
129
|
+
type ChatScriptedError = typeof ChatScriptedError.Type;
|
|
130
|
+
/**
|
|
131
|
+
* The reasoning variant of a scripted turn, queued for the next chat completion request. It is
|
|
132
|
+
* also the widest turn shape, so it bounds every emulator's turn type.
|
|
133
|
+
*/
|
|
134
|
+
declare const ChatScriptedReasoningTurn: Schema.Union<readonly [Schema.Struct<{
|
|
135
|
+
readonly error: Schema.Struct<{
|
|
136
|
+
readonly status: Schema.Int;
|
|
137
|
+
readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
138
|
+
readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
139
|
+
}>;
|
|
140
|
+
}>, Schema.Struct<{
|
|
141
|
+
readonly text: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
142
|
+
readonly reasoning: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
143
|
+
readonly reasoningField: Schema.optionalKey<Schema.Literals<readonly ["reasoning_content", "reasoning"]>>;
|
|
144
|
+
readonly order: Schema.optionalKey<Schema.Literals<readonly ["reasoning-first", "text-first"]>>;
|
|
145
|
+
readonly toolCalls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
146
|
+
readonly name: Schema.NonEmptyString;
|
|
147
|
+
readonly argumentFragments: Schema.$Array<Schema.String>;
|
|
148
|
+
readonly id: Schema.optionalKey<Schema.NonEmptyString>;
|
|
149
|
+
}>>>;
|
|
150
|
+
readonly usage: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
|
|
151
|
+
readonly promptTokens: Schema.Int;
|
|
152
|
+
readonly completionTokens: Schema.Int;
|
|
153
|
+
readonly reasoningTokens: Schema.optionalKey<Schema.Int>;
|
|
154
|
+
}>>>;
|
|
155
|
+
readonly finishReason: Schema.optionalKey<Schema.NonEmptyString>;
|
|
156
|
+
}>]>;
|
|
157
|
+
type ChatScriptedReasoningTurn = typeof ChatScriptedReasoningTurn.Type;
|
|
158
|
+
type ChatLedgerEntry = {
|
|
159
|
+
/** 1-based arrival order since the last ledger clear or reset. */readonly seq: number;
|
|
160
|
+
readonly method: string;
|
|
161
|
+
readonly path: string; /** Parsed JSON request body, when it was valid JSON. */
|
|
162
|
+
readonly body?: Schema.Json;
|
|
163
|
+
readonly model?: string;
|
|
164
|
+
readonly stream?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* The output-token limit from the emulator's completion-token request field (`max_tokens` or
|
|
167
|
+
* `max_completion_tokens`), when it is a number. Recorded as sent; never validated.
|
|
168
|
+
*/
|
|
169
|
+
readonly maxCompletionTokens?: number;
|
|
170
|
+
readonly reasoningEffort?: string;
|
|
171
|
+
readonly thinking?: Schema.Json;
|
|
172
|
+
readonly toolNames: ReadonlyArray<string>; /** Kind of the fault that shaped the response. */
|
|
173
|
+
readonly fault?: ChatFaultKind; /** Why a matching fault could not take effect (the response was a 500 emulator error). */
|
|
174
|
+
readonly faultError?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Set when the emulator could not build the planned response; the request was
|
|
177
|
+
* answered with a 500 emulator error (still evidence-tagged) and no fault was used up.
|
|
178
|
+
*/
|
|
179
|
+
readonly responseError?: string; /** Set when a scripted turn answered the request. */
|
|
180
|
+
readonly scripted?: 'completion' | 'error'; /** Evidence of the matched route; `unknown-route` for requests that failed closed. */
|
|
181
|
+
readonly evidence: EmulatorEvidence | 'unknown-route';
|
|
182
|
+
readonly status: number; /** Body chunks handed to the transport so far (each produced when pulled). */
|
|
183
|
+
readonly bodyChunks: number;
|
|
184
|
+
};
|
|
185
|
+
type ChatFaultState = EmulatorFaultState<ChatFault>;
|
|
186
|
+
type ChatRouteCoverage = EmulatorRouteCoverage;
|
|
187
|
+
type ChatCoverage = EmulatorCoverage;
|
|
188
|
+
type ChatCompletionsEmulator<Turn> = EmulatorApi<Turn, ChatFault, ChatLedgerEntry>;
|
|
189
|
+
/** One wire error: the emulator's envelope renders it. */
|
|
190
|
+
type ChatWireError = {
|
|
191
|
+
readonly message: string;
|
|
192
|
+
readonly type: string;
|
|
193
|
+
readonly code: string;
|
|
194
|
+
};
|
|
195
|
+
/** The id and model every chunk of one emulated response repeats. */
|
|
196
|
+
type ChatResponseIdentity = {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly model: string;
|
|
199
|
+
};
|
|
200
|
+
/** Token counts behind a wire `usage` object. */
|
|
201
|
+
type ChatUsageCounts = {
|
|
202
|
+
readonly promptTokens: number;
|
|
203
|
+
readonly completionTokens: number;
|
|
204
|
+
readonly reasoningTokens: number | undefined;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Per-service response details on top of the shared framing. Every field is optional; an omitted
|
|
208
|
+
* field keeps the plain OpenAI Chat Completions wire (the `/openai` emulator passes no profile).
|
|
209
|
+
*/
|
|
210
|
+
type ChatWireProfile = {
|
|
211
|
+
/**
|
|
212
|
+
* SSE events per network (body) chunk; default 1. Events are packed counting from the end, so
|
|
213
|
+
* the last chunk carries the finish event together with `data: [DONE]` and the first chunk may
|
|
214
|
+
* carry fewer. Chunk faults count these network chunks.
|
|
215
|
+
*/
|
|
216
|
+
readonly eventsPerChunk?: number;
|
|
217
|
+
/**
|
|
218
|
+
* Where streamed usage goes when `stream_options.include_usage` is set: a trailing chunk with
|
|
219
|
+
* empty `choices` (`usage-chunk`, default) or the finish event itself (`finish-event`).
|
|
220
|
+
*/
|
|
221
|
+
readonly streamUsage?: 'usage-chunk' | 'finish-event'; /** The first streamed delta; default `{ role: 'assistant', content: '' }`. */
|
|
222
|
+
readonly openingDelta?: Schema.JsonObject; /** Extra fields on every streamed choice, placed before `finish_reason` (for example `logprobs`). */
|
|
223
|
+
readonly choiceFields?: Schema.JsonObject; /** The default reasoning field for default and scripted output; default `reasoning_content`. */
|
|
224
|
+
readonly reasoningField?: 'reasoning_content' | 'reasoning'; /** Streamed `reasoning` deltas also carry `reasoning_details` (`reasoning.text` entries). */
|
|
225
|
+
readonly reasoningDetails?: boolean; /** Extra top-level fields on every streamed chunk (for example `system_fingerprint`). */
|
|
226
|
+
readonly chunkFields?: (identity: ChatResponseIdentity) => Schema.JsonObject; /** Extra fields on the finish event: top-level (`chunk`) and inside its `delta`. */
|
|
227
|
+
readonly finishFields?: (identity: ChatResponseIdentity) => {
|
|
228
|
+
readonly chunk: Schema.JsonObject;
|
|
229
|
+
readonly delta: Schema.JsonObject;
|
|
230
|
+
}; /** Renders token counts as the wire `usage` object (streamed and JSON). */
|
|
231
|
+
readonly usage?: (counts: ChatUsageCounts) => Schema.JsonObject;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* What differs between Chat Completions emulators. The core owns everything else (framing,
|
|
235
|
+
* faults, scripting, ledger, control plane, evidence).
|
|
236
|
+
*/
|
|
237
|
+
type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
|
|
238
|
+
/** The chat completions path, for example `/v1/chat/completions`. */readonly path: string; /** Route evidence manifest; must list exactly the chat completions route. */
|
|
239
|
+
readonly routes: ReadonlyArray<EmulatorRouteEvidence>;
|
|
240
|
+
readonly knownModels: ReadonlyArray<string>;
|
|
241
|
+
/**
|
|
242
|
+
* Streamed reasoning: `undefined` when the emulator does not emulate reasoning (default plans
|
|
243
|
+
* never reason and `/_emulate/state` omits `reasoningModels`); otherwise the models that stream
|
|
244
|
+
* reasoning when a request asks for it.
|
|
245
|
+
*/
|
|
246
|
+
readonly reasoningModels: ReadonlyArray<string> | undefined; /** Renders a wire error as the service's JSON error envelope. */
|
|
247
|
+
readonly errorEnvelope: (error: ChatWireError) => Schema.Json;
|
|
248
|
+
/**
|
|
249
|
+
* Status and answer for an unknown (or missing) model id: an `error` rendered with
|
|
250
|
+
* `errorEnvelope`, or a `body` built from the requested id (for a service whose unknown-model
|
|
251
|
+
* envelope differs from its other errors).
|
|
252
|
+
*/
|
|
253
|
+
readonly unknownModel: {
|
|
254
|
+
readonly status: number;
|
|
255
|
+
readonly error: ChatWireError;
|
|
256
|
+
} | {
|
|
257
|
+
readonly status: number;
|
|
258
|
+
readonly body: (model: string | undefined) => Schema.Json;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Requests authenticate with a non-empty `Authorization: Bearer` credential, never checked or
|
|
262
|
+
* stored; anything else answers 401 with `unauthorized`.
|
|
263
|
+
*/
|
|
264
|
+
readonly auth: {
|
|
265
|
+
readonly unauthorized: ChatWireError;
|
|
266
|
+
}; /** Request field carrying the output-token limit, recorded in the ledger. */
|
|
267
|
+
readonly completionTokenField: 'max_tokens' | 'max_completion_tokens'; /** Response id prefix; ids are `${prefix}-${seq}`. */
|
|
268
|
+
readonly responseIdPrefix: string; /** Default answer text deltas. */
|
|
269
|
+
readonly defaultText: ReadonlyArray<string>; /** The emulator's scripted-turn schema (decoded strictly). */
|
|
270
|
+
readonly turnSchema: Schema.Decoder<Turn>; /** Builds the error thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input. */
|
|
271
|
+
readonly inputInvalid: (input: 'fault' | 'turn', reason: string) => Error; /** Per-service wire details; omitted: the plain OpenAI Chat Completions wire. */
|
|
272
|
+
readonly wire?: ChatWireProfile;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Create a Chat Completions emulator from its config. Each call has
|
|
276
|
+
* independent ledger, fault, and script state.
|
|
277
|
+
*
|
|
278
|
+
* Precedence per chat request: authentication and JSON validation, then the
|
|
279
|
+
* first matching fault if it is a `status` fault, then the next scripted
|
|
280
|
+
* turn, then model validation and defaults; a first matching chunk fault then
|
|
281
|
+
* shapes the body. Only the first matching fault (in insertion order)
|
|
282
|
+
* applies. Credential headers are never recorded, and the bearer value is
|
|
283
|
+
* never checked or stored.
|
|
284
|
+
*/
|
|
285
|
+
declare const makeChatCompletionsEmulator: <Turn extends ChatScriptedReasoningTurn>(config: ChatCompletionsEmulatorConfig<Turn>) => ChatCompletionsEmulator<Turn>;
|
|
286
|
+
//#endregion
|
|
287
|
+
export { ChatCompletionsEmulator, ChatCompletionsEmulatorConfig, ChatCoverage, ChatFault, ChatFaultKind, ChatFaultMatch, ChatFaultState, ChatLedgerEntry, ChatResponseIdentity, ChatRouteCoverage, ChatScriptedError, ChatScriptedReasoningCompletion, ChatScriptedReasoningTurn, ChatScriptedToolCall, ChatScriptedUsage, ChatUsageCounts, ChatWireError, ChatWireProfile, chatScriptedCompletionFields, chatScriptedReasoningFields, makeChatCompletionsEmulator };
|
|
288
|
+
//# sourceMappingURL=chat-completions.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-completions.d.mts","names":[],"sources":["../src/chat-completions.ts"],"mappings":"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"}
|