cortico 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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/package.json +43 -0
- package/src/boot.ts +46 -0
- package/src/bot.ts +1342 -0
- package/src/config-file.ts +41 -0
- package/src/core/README.md +92 -0
- package/src/core/billing.ts +26 -0
- package/src/core/blobs.ts +106 -0
- package/src/core/bus.ts +311 -0
- package/src/core/config-schema.ts +201 -0
- package/src/core/config.ts +262 -0
- package/src/core/core.ts +699 -0
- package/src/core/cost.ts +244 -0
- package/src/core/event-store.ts +304 -0
- package/src/core/fork.ts +113 -0
- package/src/core/generation.ts +118 -0
- package/src/core/instance-lock.ts +215 -0
- package/src/core/ipc-logger.ts +105 -0
- package/src/core/language.ts +62 -0
- package/src/core/log-context.ts +38 -0
- package/src/core/loop.ts +1858 -0
- package/src/core/markers.ts +48 -0
- package/src/core/prefix.ts +121 -0
- package/src/core/run.ts +95 -0
- package/src/core/secrets.ts +18 -0
- package/src/core/session.ts +56 -0
- package/src/core/sessions.ts +261 -0
- package/src/core/state.ts +104 -0
- package/src/core/template.ts +72 -0
- package/src/core/timers.ts +129 -0
- package/src/core/tool-log.ts +135 -0
- package/src/core/transcript.ts +92 -0
- package/src/core/truncate.ts +121 -0
- package/src/core/types.ts +1140 -0
- package/src/core/usage-log.ts +79 -0
- package/src/core/util.ts +386 -0
- package/src/deploy-listing.ts +160 -0
- package/src/deploy.ts +162 -0
- package/src/extensions/README.md +72 -0
- package/src/extensions/dry-mount.ts +390 -0
- package/src/extensions/manifest.ts +153 -0
- package/src/extensions/runtime.ts +42 -0
- package/src/extensions.ts +519 -0
- package/src/launcher.ts +285 -0
- package/src/paths.ts +155 -0
- package/src/protocol/open-responses/LICENSE +201 -0
- package/src/protocol/open-responses/README.md +14 -0
- package/src/protocol/open-responses/context-helpers.ts +27 -0
- package/src/protocol/open-responses/context-log.ts +59 -0
- package/src/protocol/open-responses/context.ts +89 -0
- package/src/protocol/open-responses/generated.ts +115 -0
- package/src/protocol/open-responses/index.ts +33 -0
- package/src/protocol/open-responses/openapi.json +4230 -0
- package/src/protocol/open-responses/stream.ts +146 -0
- package/src/protocol/open-responses/tokens.ts +31 -0
- package/src/providers/README.md +86 -0
- package/src/providers/base.ts +111 -0
- package/src/providers/configuration.ts +97 -0
- package/src/providers/console/config.ts +21 -0
- package/src/providers/console/settings.ts +443 -0
- package/src/providers/console/strings.ts +74 -0
- package/src/providers/console/types.ts +11 -0
- package/src/providers/llamacpp/archive.ts +148 -0
- package/src/providers/llamacpp/catalog.ts +247 -0
- package/src/providers/llamacpp/config.ts +36 -0
- package/src/providers/llamacpp/console/client.ts +6 -0
- package/src/providers/llamacpp/console/models-panel.ts +120 -0
- package/src/providers/llamacpp/console/runtime-panel.ts +173 -0
- package/src/providers/llamacpp/console/server.ts +153 -0
- package/src/providers/llamacpp/index.ts +95 -0
- package/src/providers/llamacpp/native.ts +51 -0
- package/src/providers/llamacpp/options.ts +117 -0
- package/src/providers/llamacpp/runtime-store.ts +139 -0
- package/src/providers/llamacpp/runtime.ts +214 -0
- package/src/providers/llamacpp/server.ts +286 -0
- package/src/providers/llamacpp/strings.ts +230 -0
- package/src/providers/openai-responses-compat/config.ts +20 -0
- package/src/providers/openai-responses-compat/index.ts +89 -0
- package/src/providers/openai-responses-compat/native.ts +127 -0
- package/src/providers/openai-responses-compat/strings.ts +19 -0
- package/src/providers/pricebook.ts +75 -0
- package/src/providers/registry.ts +137 -0
- package/src/providers/strings.ts +71 -0
- package/src/providers/transport/chat.ts +156 -0
- package/src/providers/transport/errors.ts +48 -0
- package/src/providers/transport/history.ts +68 -0
- package/src/providers/transport/native-input.ts +83 -0
- package/src/providers/transport/native-types.ts +13 -0
- package/src/providers/transport/response-assembly.ts +191 -0
- package/src/providers/transport/response-http.ts +196 -0
- package/src/providers/transport/response-meters.ts +27 -0
- package/src/providers/transport/responses-input.ts +56 -0
- package/src/web/README.md +84 -0
- package/src/web/client/console-pages/builtins/llm-settings/panel.ts +625 -0
- package/src/web/client/console-pages/builtins/llm-settings/pricing-panel.ts +168 -0
- package/src/web/client/console-pages/builtins/llm-settings/strings.ts +213 -0
- package/src/web/client/console-pages/builtins.ts +10 -0
- package/src/web/client/console-pages/context.ts +135 -0
- package/src/web/client/console-pages/host.ts +633 -0
- package/src/web/client/console-pages/loader.ts +132 -0
- package/src/web/client/console-pages/strings.ts +90 -0
- package/src/web/client/console-pages/tools/strings.ts +49 -0
- package/src/web/client/console-pages/tools/view.ts +215 -0
- package/src/web/client/core/api.ts +200 -0
- package/src/web/client/core/language.ts +56 -0
- package/src/web/client/core/lifecycle.ts +132 -0
- package/src/web/client/core/router.ts +199 -0
- package/src/web/client/core/stream.ts +157 -0
- package/src/web/client/core/websocket.ts +82 -0
- package/src/web/client/features/appearance/index.ts +333 -0
- package/src/web/client/features/appearance/strings.ts +87 -0
- package/src/web/client/features/config/index.ts +11 -0
- package/src/web/client/features/config/strings.ts +41 -0
- package/src/web/client/features/config/view.ts +428 -0
- package/src/web/client/features/core/events.ts +197 -0
- package/src/web/client/features/core/index.ts +254 -0
- package/src/web/client/features/core/run.ts +56 -0
- package/src/web/client/features/core/runlog.ts +214 -0
- package/src/web/client/features/core/sessions.ts +53 -0
- package/src/web/client/features/core/strings.ts +157 -0
- package/src/web/client/features/extensions/index.ts +422 -0
- package/src/web/client/features/extensions/strings.ts +164 -0
- package/src/web/client/features/feature.ts +93 -0
- package/src/web/client/features/live/context.ts +280 -0
- package/src/web/client/features/live/fork.ts +156 -0
- package/src/web/client/features/live/index.ts +392 -0
- package/src/web/client/features/live/onboarding.ts +113 -0
- package/src/web/client/features/live/protocol.ts +122 -0
- package/src/web/client/features/live/sessions.ts +71 -0
- package/src/web/client/features/live/status.ts +68 -0
- package/src/web/client/features/live/strings.ts +252 -0
- package/src/web/client/features/live/timeline.ts +590 -0
- package/src/web/client/features/prompts/editor.ts +292 -0
- package/src/web/client/features/prompts/index.ts +346 -0
- package/src/web/client/features/prompts/strings.ts +136 -0
- package/src/web/client/features/prompts/view.ts +256 -0
- package/src/web/client/features/providers/index.ts +100 -0
- package/src/web/client/features/providers/strings.ts +23 -0
- package/src/web/client/features/settings/general.ts +28 -0
- package/src/web/client/features/settings/index.ts +82 -0
- package/src/web/client/features/settings/strings.ts +33 -0
- package/src/web/client/features/storage/index.ts +1 -0
- package/src/web/client/features/storage/strings.ts +45 -0
- package/src/web/client/features/storage/view.ts +154 -0
- package/src/web/client/features/usage/chart.ts +486 -0
- package/src/web/client/features/usage/index.ts +407 -0
- package/src/web/client/features/usage/labels.ts +46 -0
- package/src/web/client/features/usage/range.ts +36 -0
- package/src/web/client/features/usage/state.ts +37 -0
- package/src/web/client/features/usage/strings.ts +191 -0
- package/src/web/client/features/usage/tooltip.ts +86 -0
- package/src/web/client/features/usage/types.ts +96 -0
- package/src/web/client/features/worlds/index.ts +424 -0
- package/src/web/client/features/worlds/strings.ts +121 -0
- package/src/web/client/main.ts +273 -0
- package/src/web/client/shell/avatar.ts +233 -0
- package/src/web/client/shell/index.ts +549 -0
- package/src/web/client/shell/strings.ts +89 -0
- package/src/web/client/theme/handoff.ts +43 -0
- package/src/web/client/theme/palette.ts +109 -0
- package/src/web/client/theme/registry.ts +130 -0
- package/src/web/client/theme/storage.ts +72 -0
- package/src/web/client/theme/strings.ts +123 -0
- package/src/web/client/theme/studio.ts +366 -0
- package/src/web/client/ui/actions.ts +109 -0
- package/src/web/client/ui/data.ts +185 -0
- package/src/web/client/ui/dom.ts +23 -0
- package/src/web/client/ui/fields.ts +191 -0
- package/src/web/client/ui/format.ts +75 -0
- package/src/web/client/ui/icons.ts +183 -0
- package/src/web/client/ui/images.ts +91 -0
- package/src/web/client/ui/index.ts +89 -0
- package/src/web/client/ui/lamp.ts +125 -0
- package/src/web/client/ui/log.ts +98 -0
- package/src/web/client/ui/overlay.ts +184 -0
- package/src/web/client/ui/page.ts +8 -0
- package/src/web/client/ui/prompt-input.tsx +311 -0
- package/src/web/client/ui/sheet.ts +131 -0
- package/src/web/client/ui/strings.ts +71 -0
- package/src/web/console-pages.ts +367 -0
- package/src/web/files.ts +107 -0
- package/src/web/path-picker.ts +296 -0
- package/src/web/public/index.html +17 -0
- package/src/web/public/styles.css +1715 -0
- package/src/web/server.ts +1883 -0
- package/src/web/shared/client-panel.ts +603 -0
- package/src/web/shared/console-protocol.ts +560 -0
- package/src/web/shared/css.d.ts +1 -0
- package/src/web/shared/path-picker.ts +23 -0
- package/src/web/shared/theme.ts +256 -0
- package/src/web/theme-store.ts +37 -0
- package/src/world.ts +449 -0
- package/src/worlds/bilibili/ENV_PROMPT.md +5 -0
- package/src/worlds/bilibili/README.md +176 -0
- package/src/worlds/bilibili/audience-admission.ts +995 -0
- package/src/worlds/bilibili/client.ts +528 -0
- package/src/worlds/bilibili/coalescing-buffer.ts +125 -0
- package/src/worlds/bilibili/config.ts +185 -0
- package/src/worlds/bilibili/console/client.ts +202 -0
- package/src/worlds/bilibili/definition.ts +35 -0
- package/src/worlds/bilibili/gift-frame.ts +131 -0
- package/src/worlds/bilibili/normalize.ts +452 -0
- package/src/worlds/bilibili/overlay/announcement.ts +76 -0
- package/src/worlds/bilibili/overlay/assets.ts +82 -0
- package/src/worlds/bilibili/overlay/model.ts +494 -0
- package/src/worlds/bilibili/overlay/project.ts +202 -0
- package/src/worlds/bilibili/overlay/server.ts +286 -0
- package/src/worlds/bilibili/overlay/types.ts +217 -0
- package/src/worlds/bilibili/overlay/web/app.js +690 -0
- package/src/worlds/bilibili/overlay/web/editor.css +297 -0
- package/src/worlds/bilibili/overlay/web/editor.html +102 -0
- package/src/worlds/bilibili/overlay/web/editor.js +2116 -0
- package/src/worlds/bilibili/overlay/web/overlay.html +13 -0
- package/src/worlds/bilibili/overlay/web/styles.css +258 -0
- package/src/worlds/bilibili/protobuf.ts +123 -0
- package/src/worlds/bilibili/wire.ts +94 -0
- package/src/worlds/bilibili/world.ts +1389 -0
- package/src/worlds/console-fixture/ENV_PROMPT.md +1 -0
- package/src/worlds/console-fixture/console/client.ts +72 -0
- package/src/worlds/console-fixture/world.ts +73 -0
- package/src/worlds/index.ts +15 -0
- package/src/worlds/minecraft/ENV_PROMPT.md +32 -0
- package/src/worlds/minecraft/ENV_PROMPT_CAMERA.md +2 -0
- package/src/worlds/minecraft/LICENSE-mineflayer-pathfinder.txt +21 -0
- package/src/worlds/minecraft/README.md +917 -0
- package/src/worlds/minecraft/blueprint-plan.ts +915 -0
- package/src/worlds/minecraft/blueprint-registry.ts +566 -0
- package/src/worlds/minecraft/blueprint-repair.ts +236 -0
- package/src/worlds/minecraft/blueprint-resource.ts +272 -0
- package/src/worlds/minecraft/blueprint.ts +492 -0
- package/src/worlds/minecraft/body-lease.ts +340 -0
- package/src/worlds/minecraft/bridge.ts +749 -0
- package/src/worlds/minecraft/check.ts +651 -0
- package/src/worlds/minecraft/chests.ts +292 -0
- package/src/worlds/minecraft/client-launch.ts +272 -0
- package/src/worlds/minecraft/client-options.ts +85 -0
- package/src/worlds/minecraft/client-skins.ts +164 -0
- package/src/worlds/minecraft/client-window.ps1 +91 -0
- package/src/worlds/minecraft/client.ts +423 -0
- package/src/worlds/minecraft/combat-context.ts +109 -0
- package/src/worlds/minecraft/combat.ts +1552 -0
- package/src/worlds/minecraft/config.ts +499 -0
- package/src/worlds/minecraft/console/access.ts +218 -0
- package/src/worlds/minecraft/console/client.ts +244 -0
- package/src/worlds/minecraft/console/log.ts +110 -0
- package/src/worlds/minecraft/console/mount.ts +420 -0
- package/src/worlds/minecraft/console/skin.ts +257 -0
- package/src/worlds/minecraft/console/style.css +154 -0
- package/src/worlds/minecraft/console/world.ts +449 -0
- package/src/worlds/minecraft/deaths.ts +135 -0
- package/src/worlds/minecraft/definition.ts +18 -0
- package/src/worlds/minecraft/engine-child.ts +274 -0
- package/src/worlds/minecraft/engine-ipc.ts +98 -0
- package/src/worlds/minecraft/entity-facts.ts +132 -0
- package/src/worlds/minecraft/escape.ts +407 -0
- package/src/worlds/minecraft/executor.ts +14494 -0
- package/src/worlds/minecraft/explored.ts +156 -0
- package/src/worlds/minecraft/geometry.ts +205 -0
- package/src/worlds/minecraft/goal-plan.ts +647 -0
- package/src/worlds/minecraft/item-break.ts +126 -0
- package/src/worlds/minecraft/item-facts.ts +146 -0
- package/src/worlds/minecraft/item-pick.ts +67 -0
- package/src/worlds/minecraft/level-dat.ts +176 -0
- package/src/worlds/minecraft/log.ts +132 -0
- package/src/worlds/minecraft/mineflayer-fixes.ts +1180 -0
- package/src/worlds/minecraft/names.ts +377 -0
- package/src/worlds/minecraft/pathfinder-lib.d.ts +13 -0
- package/src/worlds/minecraft/pathfinder-perf.ts +796 -0
- package/src/worlds/minecraft/piglin.ts +49 -0
- package/src/worlds/minecraft/policy.ts +547 -0
- package/src/worlds/minecraft/precheck.ts +655 -0
- package/src/worlds/minecraft/proxy.ts +445 -0
- package/src/worlds/minecraft/ranged.ts +635 -0
- package/src/worlds/minecraft/readouts.ts +102 -0
- package/src/worlds/minecraft/round.ts +26 -0
- package/src/worlds/minecraft/search-observation.ts +92 -0
- package/src/worlds/minecraft/server-config.ts +467 -0
- package/src/worlds/minecraft/server.ts +658 -0
- package/src/worlds/minecraft/show.ts +84 -0
- package/src/worlds/minecraft/skills.ts +1763 -0
- package/src/worlds/minecraft/terrain.ts +1735 -0
- package/src/worlds/minecraft/window.ts +96 -0
- package/src/worlds/minecraft/works.ts +179 -0
- package/src/worlds/minecraft/world.ts +6438 -0
- package/src/worlds/qq/ENV_PROMPT.md +5 -0
- package/src/worlds/qq/config.ts +108 -0
- package/src/worlds/qq/console/client.ts +126 -0
- package/src/worlds/qq/console/events.ts +155 -0
- package/src/worlds/qq/console/gate.ts +232 -0
- package/src/worlds/qq/console/roster.ts +203 -0
- package/src/worlds/qq/console/style.css +65 -0
- package/src/worlds/qq/conversation.ts +28 -0
- package/src/worlds/qq/definition.ts +62 -0
- package/src/worlds/qq/driver.ts +375 -0
- package/src/worlds/qq/history-tools.ts +209 -0
- package/src/worlds/qq/normalize.ts +323 -0
- package/src/worlds/qq/qface-map.ts +282 -0
- package/src/worlds/qq/vision-prompt.ts +27 -0
- package/src/worlds/qq/vision.ts +642 -0
- package/src/worlds/qq/vlm.ts +142 -0
- package/src/worlds/qq/world.ts +1503 -0
- package/src/worlds/terminal/ENV_PROMPT.md +11 -0
- package/src/worlds/terminal/config.ts +9 -0
- package/src/worlds/terminal/definition.ts +14 -0
- package/src/worlds/terminal/world.ts +700 -0
- package/src/worlds/websearch/ENV_PROMPT.md +1 -0
- package/src/worlds/websearch/brave-client.ts +261 -0
- package/src/worlds/websearch/config.ts +75 -0
- package/src/worlds/websearch/definition.ts +20 -0
- package/src/worlds/websearch/world.ts +171 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModelSpec, ToolSchema, LLMUsage } from '../../core/types.ts';
|
|
2
|
+
import type { Request, Schemas } from './index.ts';
|
|
3
|
+
import type { TokenMeters } from '../../core/generation.ts';
|
|
4
|
+
import { inputItem, itemText, type ContextRecord } from './context.ts';
|
|
5
|
+
|
|
6
|
+
export function hasRole(entry: ContextRecord, role: string): boolean {
|
|
7
|
+
return entry.item.type === 'message' && entry.item.role === role;
|
|
8
|
+
}
|
|
9
|
+
export function textOf(entry: ContextRecord): string { return itemText(entry.item); }
|
|
10
|
+
export function withoutPastReasoning(entries: readonly ContextRecord[]): ContextRecord[] {
|
|
11
|
+
return entries.filter(entry => entry.item.type !== 'reasoning' || entry.context.head);
|
|
12
|
+
}
|
|
13
|
+
export function responseRequest(spec: ModelSpec, context: readonly ContextRecord[], tools: readonly ToolSchema[] = []): Request {
|
|
14
|
+
return {
|
|
15
|
+
model: spec.model, input: context.map(inputItem), tools: tools.map(tool => ({ ...tool, type: 'function' })),
|
|
16
|
+
// effort 词表归端点(见 ModelSpec.reasoningEffort);协议枚举只覆盖 OpenAI 自己的取值。
|
|
17
|
+
reasoning: spec.thinking ? { ...(spec.reasoningEffort ? { effort: spec.reasoningEffort as Schemas['ReasoningEffortEnum'] } : {}) } : { effort: 'none' },
|
|
18
|
+
...(spec.temperature !== undefined ? { temperature: spec.temperature } : {}),
|
|
19
|
+
...(spec.maxTokens !== undefined ? { max_output_tokens: spec.maxTokens } : {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Legacy numeric dashboard totals sum only known measurements; billing retains nullable meters. */
|
|
24
|
+
export function usageCounters(meters: TokenMeters): LLMUsage {
|
|
25
|
+
return { promptTokens: meters.input ?? 0, completionTokens: meters.output ?? 0,
|
|
26
|
+
cacheHitTokens: meters.cachedInput ?? 0, cacheMissTokens: meters.uncachedInput ?? 0, reasoningTokens: meters.reasoning ?? undefined };
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { appendFileSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import type { ContextRecord } from './context.ts';
|
|
4
|
+
|
|
5
|
+
function freeze<T>(value: T): T {
|
|
6
|
+
if (value !== null && typeof value === 'object') {
|
|
7
|
+
for (const child of Object.values(value)) freeze(child);
|
|
8
|
+
Object.freeze(value);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Immutable standard Items with runtime metadata stored in a separate field. */
|
|
14
|
+
export class ContextLog {
|
|
15
|
+
private entries: readonly ContextRecord[] = Object.freeze([]);
|
|
16
|
+
constructor(readonly file: string, private readonly stamp?: () => string) {
|
|
17
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get records(): readonly ContextRecord[] { return this.entries; }
|
|
21
|
+
|
|
22
|
+
load(): void {
|
|
23
|
+
if (!existsSync(this.file)) { this.entries = Object.freeze([]); return; }
|
|
24
|
+
const rows = readFileSync(this.file, 'utf8').split(/\r?\n/).filter(line => line.trim()).map((line, index) => {
|
|
25
|
+
let row: ContextRecord;
|
|
26
|
+
try { row = JSON.parse(line) as ContextRecord; }
|
|
27
|
+
catch { throw new Error(`Invalid session JSON at ${this.file}:${index + 1}`); }
|
|
28
|
+
if (!row || row.version !== 2 || !row.item || typeof row.item !== 'object' || Array.isArray(row.item)
|
|
29
|
+
|| !row.context || typeof row.context !== 'object' || Array.isArray(row.context))
|
|
30
|
+
throw new Error(`Invalid context record at ${this.file}:${index + 1}`);
|
|
31
|
+
return freeze(row);
|
|
32
|
+
});
|
|
33
|
+
this.entries = Object.freeze(rows);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
append(entry: ContextRecord): ContextRecord {
|
|
37
|
+
const next = structuredClone(entry);
|
|
38
|
+
if (this.stamp && next.context.ts === undefined) next.context.ts = this.stamp();
|
|
39
|
+
appendFileSync(this.file, JSON.stringify(next) + '\n');
|
|
40
|
+
this.entries = Object.freeze([...this.entries, freeze(next)]);
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
reset(records: readonly ContextRecord[]): void {
|
|
45
|
+
const next = records.map(entry => freeze(structuredClone(entry)));
|
|
46
|
+
atomicContextWrite(this.file, next);
|
|
47
|
+
this.entries = Object.freeze(next);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function atomicContextWrite(path: string, records: readonly ContextRecord[]): void {
|
|
52
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
53
|
+
const fd = openSync(temporary, 'w');
|
|
54
|
+
try {
|
|
55
|
+
writeFileSync(fd, records.map(row => JSON.stringify(row)).join('\n') + (records.length ? '\n' : ''));
|
|
56
|
+
fsyncSync(fd);
|
|
57
|
+
} finally { closeSync(fd); }
|
|
58
|
+
renameSync(temporary, path);
|
|
59
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { BlobRef, FrameEventRef } from '../../core/types.ts';
|
|
2
|
+
import type { InputItem, OutputItem, Response, Schemas } from './index.ts';
|
|
3
|
+
|
|
4
|
+
/** Context preserves the standard input and output item shapes without flattening responses. */
|
|
5
|
+
export type Item = InputItem | OutputItem;
|
|
6
|
+
export interface ItemOrigin {
|
|
7
|
+
instance: string;
|
|
8
|
+
module: string;
|
|
9
|
+
model: string;
|
|
10
|
+
compatibilityDomain: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ContextMeta {
|
|
13
|
+
ts?: string;
|
|
14
|
+
ephemeral?: true;
|
|
15
|
+
/** 合成开头的项:不写入 session,交接时不进保留内容。 */
|
|
16
|
+
head?: true;
|
|
17
|
+
frame?: { events: FrameEventRef[] };
|
|
18
|
+
blobs?: BlobRef[];
|
|
19
|
+
responseId?: string;
|
|
20
|
+
responseStatus?: string;
|
|
21
|
+
origin?: ItemOrigin;
|
|
22
|
+
}
|
|
23
|
+
export interface ContextRecord {
|
|
24
|
+
version: 2;
|
|
25
|
+
item: Item;
|
|
26
|
+
context: ContextMeta;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function record(item: Item, context: ContextMeta = {}): ContextRecord {
|
|
30
|
+
return { version: 2, item, context };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function message(role: 'system' | 'developer' | 'user' | 'assistant', text: string, context: ContextMeta = {}): ContextRecord {
|
|
34
|
+
return record({
|
|
35
|
+
type: 'message', id: `msg_${crypto.randomUUID()}`, status: 'completed', role,
|
|
36
|
+
content: role === 'assistant' ? [{ type: 'output_text', text, annotations: [] }] : [{ type: 'input_text', text }],
|
|
37
|
+
}, context);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function functionCall(callId: string, name: string, args: string, context: ContextMeta = {}): ContextRecord {
|
|
41
|
+
return record({ type: 'function_call', id: `fc_${crypto.randomUUID()}`, call_id: callId, name, arguments: args, status: 'completed' }, context);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function functionResult(callId: string, text: string, context: ContextMeta = {}): ContextRecord {
|
|
45
|
+
return record({ type: 'function_call_output', id: `fco_${crypto.randomUUID()}`, call_id: callId, status: 'completed', output: text }, context);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function partsText(content: string | readonly unknown[] | null | undefined): string {
|
|
49
|
+
if (typeof content === 'string') return content;
|
|
50
|
+
return (content ?? []).map(part => {
|
|
51
|
+
const p = part as { text?: string; refusal?: string };
|
|
52
|
+
return p.text ?? p.refusal ?? '';
|
|
53
|
+
}).join('');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Extract readable text from the Item without changing its stored shape. */
|
|
57
|
+
export function itemText(item: Item): string {
|
|
58
|
+
if (item.type === 'message') return partsText(item.content);
|
|
59
|
+
if (item.type === 'function_call_output') return partsText(item.output);
|
|
60
|
+
if (item.type === 'reasoning') return partsText(item.content) || partsText(item.summary);
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function withText(entry: ContextRecord, text: string): ContextRecord {
|
|
65
|
+
const item = entry.item;
|
|
66
|
+
if (item.type === 'function_call_output') return { ...entry, item: { ...item, output: text } };
|
|
67
|
+
if (item.type !== 'message') throw new Error(`Cannot replace text on ${item.type}`);
|
|
68
|
+
return { ...entry, item: { ...item, content: text } as InputItem };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function responseRecords(response: Response, origin: ItemOrigin, context: ContextMeta = {}): ContextRecord[] {
|
|
72
|
+
return response.output.map(item => record(structuredClone(item), {
|
|
73
|
+
...context, responseId: response.id, responseStatus: response.status, origin,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Build a standard request Item; provider context records retain output reasoning content. */
|
|
78
|
+
export function inputItem(entry: ContextRecord): InputItem {
|
|
79
|
+
const item = entry.item;
|
|
80
|
+
if (item.type === 'reasoning') {
|
|
81
|
+
const reasoning: Schemas['ReasoningItemParam'] = {
|
|
82
|
+
type: 'reasoning', summary: item.summary.filter(part => part.type === 'summary_text') as Schemas['ReasoningSummaryContentParam'][],
|
|
83
|
+
};
|
|
84
|
+
if (item.id) reasoning.id = item.id;
|
|
85
|
+
if (item.encrypted_content) reasoning.encrypted_content = item.encrypted_content;
|
|
86
|
+
return reasoning;
|
|
87
|
+
}
|
|
88
|
+
return structuredClone(item) as InputItem;
|
|
89
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Generated by scripts/generate-open-responses.ts. Source: Open Responses (Apache-2.0).
|
|
2
|
+
export const OPEN_RESPONSES_VERSION = "2026-04-24";
|
|
3
|
+
export const OPEN_RESPONSES_SCHEMA_SHA256 = "d598753c3a86fd8a2434828fe39dcc8786a7a694bbe46080a0d24c9fa40e72df";
|
|
4
|
+
export interface Schemas {
|
|
5
|
+
"ItemReferenceParam": { "type"?: ("item_reference" | null); "id": string; };
|
|
6
|
+
"ReasoningSummaryContentParam": { "type": "summary_text"; "text": string; };
|
|
7
|
+
"ReasoningItemParam": { "id"?: (string | null); "type": "reasoning"; "summary": Array<Schemas["ReasoningSummaryContentParam"]>; "content"?: (null); "encrypted_content"?: (string | null); };
|
|
8
|
+
"CompactionSummaryItemParam": { "id"?: (string | null); "type": "compaction"; "encrypted_content": string; };
|
|
9
|
+
"InputTextContentParam": { "type": "input_text"; "text": string; };
|
|
10
|
+
"DetailEnum": "low" | "high" | "auto";
|
|
11
|
+
"InputImageContentParamAutoParam": { "type": "input_image"; "image_url"?: (string | null); "detail"?: ((Schemas["ImageDetail"] & unknown) | null); };
|
|
12
|
+
"InputFileContentParam": { "type": "input_file"; "filename"?: (string | null); "file_data"?: (string | null); "file_url"?: (string | null); };
|
|
13
|
+
"UserMessageItemParam": { "id"?: (string | null); "type": "message"; "role": "user"; "content": (Array<(Schemas["InputTextContentParam"] | Schemas["InputImageContentParamAutoParam"] | Schemas["InputFileContentParam"])> | string); "status"?: (string | null); };
|
|
14
|
+
"SystemMessageItemParam": { "id"?: (string | null); "type": "message"; "role": "system"; "content": (Array<(Schemas["InputTextContentParam"])> | string); "status"?: (string | null); };
|
|
15
|
+
"DeveloperMessageItemParam": { "id"?: (string | null); "type": "message"; "role": "developer"; "content": (Array<(Schemas["InputTextContentParam"])> | string); "status"?: (string | null); };
|
|
16
|
+
"UrlCitationParam": { "type": "url_citation"; "start_index": number; "end_index": number; "url": string; "title": string; };
|
|
17
|
+
"OutputTextContentParam": { "type": "output_text"; "text": string; "annotations"?: (Array<Schemas["UrlCitationParam"]>); };
|
|
18
|
+
"RefusalContentParam": { "type": "refusal"; "refusal": string; };
|
|
19
|
+
"AssistantMessageItemParam": { "id"?: (string | null); "type": "message"; "role": "assistant"; "content": (Array<(Schemas["OutputTextContentParam"] | Schemas["RefusalContentParam"])> | string); "phase"?: "commentary" | "final_answer"; "status"?: (string | null); };
|
|
20
|
+
"FunctionCallItemStatus": "in_progress" | "completed" | "incomplete";
|
|
21
|
+
"FunctionCallItemParam": { "id"?: (string | null); "call_id": string; "type": "function_call"; "name": string; "arguments": string; "status"?: ((Schemas["FunctionCallStatus"] & unknown) | null); };
|
|
22
|
+
"FunctionCallOutputItemParam": { "id"?: (string | null); "call_id": string; "type": "function_call_output"; "output": (string | Array<(Schemas["InputTextContentParam"] | Schemas["InputImageContentParamAutoParam"] | Schemas["InputFileContentParam"] | Schemas["InputVideoContent"])>); "status"?: ((Schemas["FunctionCallStatus"] & unknown) | null); };
|
|
23
|
+
"ItemParam": (Schemas["ItemReferenceParam"] | Schemas["ReasoningItemParam"] | Schemas["CompactionSummaryItemParam"] | Schemas["UserMessageItemParam"] | Schemas["SystemMessageItemParam"] | Schemas["DeveloperMessageItemParam"] | Schemas["AssistantMessageItemParam"] | Schemas["FunctionCallItemParam"] | Schemas["FunctionCallOutputItemParam"]);
|
|
24
|
+
"IncludeEnum": "reasoning.encrypted_content" | "message.output_text.logprobs";
|
|
25
|
+
"EmptyModelParam": Record<string, unknown>;
|
|
26
|
+
"FunctionToolParam": { "name": string; "description"?: (string | null); "parameters"?: (Schemas["EmptyModelParam"] | null); "strict"?: boolean; "type": "function"; };
|
|
27
|
+
"ResponsesToolParam": (Schemas["FunctionToolParam"]);
|
|
28
|
+
"SpecificFunctionParam": { "type": "function"; "name": string; };
|
|
29
|
+
"SpecificToolChoiceParam": (Schemas["SpecificFunctionParam"]);
|
|
30
|
+
"ToolChoiceValueEnum": "none" | "auto" | "required";
|
|
31
|
+
"AllowedToolsParam": { "type": "allowed_tools"; "tools": Array<Schemas["SpecificToolChoiceParam"]>; "mode"?: (Schemas["ToolChoiceValueEnum"] & unknown); };
|
|
32
|
+
"ToolChoiceParam": (Schemas["SpecificToolChoiceParam"] | Schemas["ToolChoiceValueEnum"] | Schemas["AllowedToolsParam"]);
|
|
33
|
+
"MetadataParam": { [key: string]: string; };
|
|
34
|
+
"VerbosityEnum": "low" | "medium" | "high";
|
|
35
|
+
"TextParam": { "format"?: (Schemas["TextFormatParam"] | null); "verbosity"?: (Schemas["VerbosityEnum"] & unknown); };
|
|
36
|
+
"StreamOptionsParam": { "include_obfuscation"?: boolean; };
|
|
37
|
+
"ReasoningEffortEnum": "none" | "low" | "medium" | "high" | "xhigh";
|
|
38
|
+
"ReasoningSummaryEnum": "concise" | "detailed" | "auto";
|
|
39
|
+
"ReasoningParam": { "effort"?: ((Schemas["ReasoningEffortEnum"]) | null); "summary"?: ((Schemas["ReasoningSummaryEnum"] & unknown) | null); };
|
|
40
|
+
"TruncationEnum": "auto" | "disabled";
|
|
41
|
+
"ServiceTierEnum": "auto" | "default" | "flex" | "priority";
|
|
42
|
+
"CreateResponseBody": { "model"?: (string | null); "input"?: ((string | Array<Schemas["ItemParam"]>) | null); "previous_response_id"?: (string | null); "include"?: Array<Schemas["IncludeEnum"]>; "tools"?: (Array<Schemas["ResponsesToolParam"]> | null); "tool_choice"?: ((Schemas["ToolChoiceParam"] & unknown) | null); "metadata"?: ((Schemas["MetadataParam"] & unknown) | null); "text"?: ((Schemas["TextParam"] & unknown) | null); "temperature"?: (number | null); "top_p"?: (number | null); "presence_penalty"?: (number | null); "frequency_penalty"?: (number | null); "parallel_tool_calls"?: (boolean | null); "stream"?: boolean; "stream_options"?: ((Schemas["StreamOptionsParam"] & unknown) | null); "background"?: boolean; "max_output_tokens"?: (number | null); "max_tool_calls"?: (number | null); "reasoning"?: ((Schemas["ReasoningParam"] & unknown) | null); "safety_identifier"?: (string | null); "prompt_cache_key"?: (string | null); "truncation"?: (Schemas["TruncationEnum"] & unknown); "instructions"?: (string | null); "store"?: boolean; "service_tier"?: (Schemas["ServiceTierEnum"] & unknown); "top_logprobs"?: (number | null); };
|
|
43
|
+
"WebSocketResponseCreateEvent": ({ "type": "response.create"; "stream"?: string; "stream_options"?: string; "background"?: string; } & Schemas["CreateResponseBody"]);
|
|
44
|
+
"WebSocketErrorEvent": { "type": "error"; "status": number; "error": { "type"?: string; "code": string; "message": string; "param"?: (string | null); [key: string]: unknown; }; };
|
|
45
|
+
"IncompleteDetails": { "reason": string; };
|
|
46
|
+
"MessageRole": "user" | "assistant" | "system" | "developer";
|
|
47
|
+
"InputTextContent": { "type": "input_text"; "text": string; };
|
|
48
|
+
"UrlCitationBody": { "type": "url_citation"; "url": string; "start_index": number; "end_index": number; "title": string; };
|
|
49
|
+
"Annotation": (Schemas["UrlCitationBody"]);
|
|
50
|
+
"TopLogProb": { "token": string; "logprob": number; "bytes": Array<number>; };
|
|
51
|
+
"LogProb": { "token": string; "logprob": number; "bytes": Array<number>; "top_logprobs": Array<Schemas["TopLogProb"]>; };
|
|
52
|
+
"OutputTextContent": { "type": "output_text"; "text": string; "annotations": Array<Schemas["Annotation"]>; "logprobs"?: Array<Schemas["LogProb"]>; };
|
|
53
|
+
"TextContent": { "type": "text"; "text": string; };
|
|
54
|
+
"SummaryTextContent": { "type": "summary_text"; "text": string; };
|
|
55
|
+
"ReasoningTextContent": { "type": "reasoning_text"; "text": string; };
|
|
56
|
+
"RefusalContent": { "type": "refusal"; "refusal": string; };
|
|
57
|
+
"ImageDetail": "low" | "high" | "auto";
|
|
58
|
+
"InputImageContent": { "type": "input_image"; "image_url": (string | null); "detail": (Schemas["ImageDetail"] & unknown); };
|
|
59
|
+
"InputFileContent": { "type": "input_file"; "filename"?: string; "file_url"?: string; };
|
|
60
|
+
"MessageStatus": "in_progress" | "completed" | "incomplete";
|
|
61
|
+
"Message": { "type": "message"; "id": string; "status": (Schemas["MessageStatus"] & unknown); "role": (Schemas["MessageRole"] & unknown); "content": Array<(Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"] | Schemas["InputVideoContent"])>; "phase"?: "commentary" | "final_answer"; };
|
|
62
|
+
"FunctionCallStatus": "in_progress" | "completed" | "incomplete";
|
|
63
|
+
"FunctionCall": { "type": "function_call"; "id": string; "call_id": string; "name": string; "arguments": string; "status": (Schemas["FunctionCallStatus"] & unknown); };
|
|
64
|
+
"FunctionCallOutputStatusEnum": "in_progress" | "completed" | "incomplete";
|
|
65
|
+
"FunctionCallOutput": { "type": "function_call_output"; "id": string; "call_id": string; "output": (string | Array<(Schemas["InputTextContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"])>); "status": (Schemas["FunctionCallOutputStatusEnum"] & unknown); };
|
|
66
|
+
"ReasoningBody": { "type": "reasoning"; "id": string; "content"?: Array<(Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"])>; "summary": Array<(Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"])>; "encrypted_content"?: string; };
|
|
67
|
+
"CompactionBody": { "type": "compaction"; "id": string; "encrypted_content": string; "created_by"?: string; };
|
|
68
|
+
"ItemField": (Schemas["Message"] | Schemas["FunctionCall"] | Schemas["FunctionCallOutput"] | Schemas["ReasoningBody"] | Schemas["CompactionBody"]);
|
|
69
|
+
"Error": { "code": string; "message": string; };
|
|
70
|
+
"FunctionTool": { "type": "function"; "name": string; "description": (string | null); "parameters": ({ [key: string]: unknown; } | null); "strict": (boolean | null); };
|
|
71
|
+
"Tool": (Schemas["FunctionTool"]);
|
|
72
|
+
"FunctionToolChoice": { "type": "function"; "name"?: string; };
|
|
73
|
+
"AllowedToolChoice": { "type": "allowed_tools"; "tools": Array<(Schemas["FunctionToolChoice"])>; "mode": Schemas["ToolChoiceValueEnum"]; };
|
|
74
|
+
"TextResponseFormat": { "type": "text"; };
|
|
75
|
+
"JsonObjectResponseFormat": { "type": "json_object"; };
|
|
76
|
+
"JsonSchemaResponseFormat": { "type": "json_schema"; "name": string; "description": (string | null); "schema": (null); "strict": boolean; };
|
|
77
|
+
"TextField": { "format": (Schemas["TextResponseFormat"] | Schemas["JsonObjectResponseFormat"] | Schemas["JsonSchemaResponseFormat"]); "verbosity"?: Schemas["VerbosityEnum"]; };
|
|
78
|
+
"Reasoning": { "effort": ((Schemas["ReasoningEffortEnum"]) | null); "summary": ((Schemas["ReasoningSummaryEnum"] & unknown) | null); };
|
|
79
|
+
"InputTokensDetails": { "cached_tokens": number; };
|
|
80
|
+
"OutputTokensDetails": { "reasoning_tokens": number; };
|
|
81
|
+
"Usage": { "input_tokens": number; "output_tokens": number; "total_tokens": number; "input_tokens_details": (Schemas["InputTokensDetails"] & unknown); "output_tokens_details": (Schemas["OutputTokensDetails"] & unknown); };
|
|
82
|
+
"ResponseResource": { "id": string; "object": "response"; "created_at": number; "completed_at": (number | null); "status": string; "incomplete_details": ((Schemas["IncompleteDetails"] & unknown) | null); "model": string; "previous_response_id": (string | null); "instructions": ((string) | null); "output": Array<Schemas["ItemField"]>; "error": ((Schemas["Error"] & unknown) | null); "tools": Array<Schemas["Tool"]>; "tool_choice": (Schemas["FunctionToolChoice"] | Schemas["ToolChoiceValueEnum"] | Schemas["AllowedToolChoice"]); "truncation": (Schemas["TruncationEnum"] & unknown); "parallel_tool_calls": boolean; "text": (Schemas["TextField"] & unknown); "top_p": number; "presence_penalty": number; "frequency_penalty": number; "top_logprobs": number; "temperature": number; "reasoning": ((Schemas["Reasoning"] & unknown) | null); "usage": ((Schemas["Usage"] & unknown) | null); "max_output_tokens": (number | null); "max_tool_calls": (number | null); "store": boolean; "background": boolean; "service_tier": string; "metadata": unknown; "safety_identifier": (string | null); "prompt_cache_key": (string | null); };
|
|
83
|
+
"ResponseCreatedStreamingEvent": { "type": "response.created"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
84
|
+
"ResponseQueuedStreamingEvent": { "type": "response.queued"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
85
|
+
"ResponseInProgressStreamingEvent": { "type": "response.in_progress"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
86
|
+
"ResponseCompletedStreamingEvent": { "type": "response.completed"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
87
|
+
"ResponseFailedStreamingEvent": { "type": "response.failed"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
88
|
+
"ResponseIncompleteStreamingEvent": { "type": "response.incomplete"; "sequence_number": number; "response": (Schemas["ResponseResource"] & unknown); };
|
|
89
|
+
"ResponseOutputItemAddedStreamingEvent": { "type": "response.output_item.added"; "sequence_number": number; "output_index": number; "item": ((Schemas["ItemField"] & unknown) | null); };
|
|
90
|
+
"ResponseOutputItemDoneStreamingEvent": { "type": "response.output_item.done"; "sequence_number": number; "output_index": number; "item": ((Schemas["ItemField"] & unknown) | null); };
|
|
91
|
+
"ResponseReasoningSummaryPartAddedStreamingEvent": { "type": "response.reasoning_summary_part.added"; "sequence_number": number; "item_id": string; "output_index": number; "summary_index": number; "part": (Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"]); };
|
|
92
|
+
"ResponseReasoningSummaryPartDoneStreamingEvent": { "type": "response.reasoning_summary_part.done"; "sequence_number": number; "item_id": string; "output_index": number; "summary_index": number; "part": (Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"]); };
|
|
93
|
+
"ResponseContentPartAddedStreamingEvent": { "type": "response.content_part.added"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "part": (Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"]); };
|
|
94
|
+
"ResponseContentPartDoneStreamingEvent": { "type": "response.content_part.done"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "part": (Schemas["InputTextContent"] | Schemas["OutputTextContent"] | Schemas["TextContent"] | Schemas["SummaryTextContent"] | Schemas["ReasoningTextContent"] | Schemas["RefusalContent"] | Schemas["InputImageContent"] | Schemas["InputFileContent"]); };
|
|
95
|
+
"ResponseOutputTextDeltaStreamingEvent": { "type": "response.output_text.delta"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "delta": string; "logprobs"?: Array<Schemas["LogProb"]>; "obfuscation"?: string; };
|
|
96
|
+
"ResponseOutputTextDoneStreamingEvent": { "type": "response.output_text.done"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "text": string; "logprobs"?: Array<Schemas["LogProb"]>; };
|
|
97
|
+
"ResponseRefusalDeltaStreamingEvent": { "type": "response.refusal.delta"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "delta": string; };
|
|
98
|
+
"ResponseRefusalDoneStreamingEvent": { "type": "response.refusal.done"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "refusal": string; };
|
|
99
|
+
"ResponseReasoningDeltaStreamingEvent": { "type": "response.reasoning.delta"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "delta": string; "obfuscation"?: string; };
|
|
100
|
+
"ResponseReasoningDoneStreamingEvent": { "type": "response.reasoning.done"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "text": string; };
|
|
101
|
+
"ResponseReasoningSummaryDeltaStreamingEvent": { "type": "response.reasoning_summary_text.delta"; "sequence_number": number; "item_id": string; "output_index": number; "summary_index": number; "delta": string; "obfuscation"?: string; };
|
|
102
|
+
"ResponseReasoningSummaryDoneStreamingEvent": { "type": "response.reasoning_summary_text.done"; "sequence_number": number; "item_id": string; "output_index": number; "summary_index": number; "text": string; };
|
|
103
|
+
"ResponseOutputTextAnnotationAddedStreamingEvent": { "type": "response.output_text.annotation.added"; "sequence_number": number; "item_id": string; "output_index": number; "content_index": number; "annotation_index": number; "annotation": ((Schemas["Annotation"] & unknown) | null); };
|
|
104
|
+
"ResponseFunctionCallArgumentsDeltaStreamingEvent": { "type": "response.function_call_arguments.delta"; "sequence_number": number; "item_id": string; "output_index": number; "delta": string; "obfuscation"?: string; };
|
|
105
|
+
"ResponseFunctionCallArgumentsDoneStreamingEvent": { "type": "response.function_call_arguments.done"; "sequence_number": number; "item_id": string; "output_index": number; "arguments": string; };
|
|
106
|
+
"ErrorPayload": { "type": string; "code": (string | null); "message": string; "param": (string | null); "headers"?: { [key: string]: string; }; };
|
|
107
|
+
"ErrorStreamingEvent": { "type": "error"; "sequence_number": number; "error": (Schemas["ErrorPayload"] & unknown); };
|
|
108
|
+
"CompactResponseMethodPublicBody": { "model": string; "input"?: ((string | Array<Schemas["ItemParam"]>) | null); "previous_response_id"?: (string | null); "instructions"?: (string | null); "prompt_cache_key"?: (string | null); };
|
|
109
|
+
"CompactResource": { "id": string; "object": "response.compaction"; "output": Array<Schemas["ItemField"]>; "created_at": number; "usage": (Schemas["Usage"] & unknown); };
|
|
110
|
+
"InputVideoContent": { "type": "input_video"; "video_url": string; };
|
|
111
|
+
"JsonSchemaResponseFormatParam": { "type"?: "json_schema"; "description"?: string; "name"?: string; "schema"?: { [key: string]: unknown; }; "strict"?: (boolean | null); };
|
|
112
|
+
"TextFormatParam": (Schemas["TextResponseFormat"] | Schemas["JsonSchemaResponseFormatParam"]);
|
|
113
|
+
}
|
|
114
|
+
export type StreamEvent = Schemas["ResponseCreatedStreamingEvent"] | Schemas["ResponseQueuedStreamingEvent"] | Schemas["ResponseInProgressStreamingEvent"] | Schemas["ResponseCompletedStreamingEvent"] | Schemas["ResponseFailedStreamingEvent"] | Schemas["ResponseIncompleteStreamingEvent"] | Schemas["ResponseOutputItemAddedStreamingEvent"] | Schemas["ResponseOutputItemDoneStreamingEvent"] | Schemas["ResponseReasoningSummaryPartAddedStreamingEvent"] | Schemas["ResponseReasoningSummaryPartDoneStreamingEvent"] | Schemas["ResponseContentPartAddedStreamingEvent"] | Schemas["ResponseContentPartDoneStreamingEvent"] | Schemas["ResponseOutputTextDeltaStreamingEvent"] | Schemas["ResponseOutputTextDoneStreamingEvent"] | Schemas["ResponseRefusalDeltaStreamingEvent"] | Schemas["ResponseRefusalDoneStreamingEvent"] | Schemas["ResponseReasoningDeltaStreamingEvent"] | Schemas["ResponseReasoningDoneStreamingEvent"] | Schemas["ResponseReasoningSummaryDeltaStreamingEvent"] | Schemas["ResponseReasoningSummaryDoneStreamingEvent"] | Schemas["ResponseOutputTextAnnotationAddedStreamingEvent"] | Schemas["ResponseFunctionCallArgumentsDeltaStreamingEvent"] | Schemas["ResponseFunctionCallArgumentsDoneStreamingEvent"] | Schemas["ErrorStreamingEvent"];
|
|
115
|
+
export const STREAM_EVENT_TYPES: ReadonlySet<string> = new Set(["response.created","response.queued","response.in_progress","response.completed","response.failed","response.incomplete","response.output_item.added","response.output_item.done","response.reasoning_summary_part.added","response.reasoning_summary_part.done","response.content_part.added","response.content_part.done","response.output_text.delta","response.output_text.done","response.refusal.delta","response.refusal.done","response.reasoning.delta","response.reasoning.done","response.reasoning_summary_text.delta","response.reasoning_summary_text.done","response.output_text.annotation.added","response.function_call_arguments.delta","response.function_call_arguments.done","error"]);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Schemas } from './generated.ts';
|
|
2
|
+
export { OPEN_RESPONSES_VERSION, OPEN_RESPONSES_SCHEMA_SHA256 } from './generated.ts';
|
|
3
|
+
export type { Schemas, StreamEvent } from './generated.ts';
|
|
4
|
+
|
|
5
|
+
export type Response = Schemas['ResponseResource'];
|
|
6
|
+
export type Request = Schemas['CreateResponseBody'];
|
|
7
|
+
export type InputItem = Schemas['ItemParam'];
|
|
8
|
+
export type OutputItem = Schemas['ItemField'];
|
|
9
|
+
export type Usage = Schemas['Usage'];
|
|
10
|
+
export type FunctionCall = Schemas['FunctionCall'];
|
|
11
|
+
|
|
12
|
+
/** Initial response fields for adapters whose native API has no response resource. */
|
|
13
|
+
export function createResponse(id: string, request: Request, now = Date.now()): Response {
|
|
14
|
+
return {
|
|
15
|
+
id, object: 'response', created_at: Math.floor(now / 1000), completed_at: null,
|
|
16
|
+
status: 'in_progress', incomplete_details: null, model: request.model ?? '',
|
|
17
|
+
previous_response_id: request.previous_response_id ?? null,
|
|
18
|
+
instructions: request.instructions ?? null, output: [], error: null,
|
|
19
|
+
tools: (request.tools ?? []) as Response['tools'],
|
|
20
|
+
tool_choice: (request.tool_choice ?? 'auto') as Response['tool_choice'],
|
|
21
|
+
truncation: request.truncation ?? 'disabled', parallel_tool_calls: request.parallel_tool_calls ?? false,
|
|
22
|
+
text: (request.text ?? { format: { type: 'text' } }) as Response['text'],
|
|
23
|
+
top_p: request.top_p ?? 1, presence_penalty: request.presence_penalty ?? 0,
|
|
24
|
+
frequency_penalty: request.frequency_penalty ?? 0, top_logprobs: request.top_logprobs ?? 0,
|
|
25
|
+
temperature: request.temperature ?? 1,
|
|
26
|
+
reasoning: request.reasoning ? { effort: request.reasoning.effort ?? null, summary: request.reasoning.summary ?? null } : null,
|
|
27
|
+
usage: null,
|
|
28
|
+
max_output_tokens: request.max_output_tokens ?? null, max_tool_calls: request.max_tool_calls ?? null,
|
|
29
|
+
store: request.store ?? false, background: request.background ?? false,
|
|
30
|
+
service_tier: request.service_tier ?? 'default', metadata: request.metadata ?? null,
|
|
31
|
+
safety_identifier: request.safety_identifier ?? null, prompt_cache_key: request.prompt_cache_key ?? null,
|
|
32
|
+
};
|
|
33
|
+
}
|