@linxiraos/pi-ai 1.1.26 → 1.2.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/CHANGELOG.md +9 -8
- package/README.md +15 -0
- package/dist/types/auth/affinity.d.ts +33 -6
- package/dist/types/auth/cascade.d.ts +44 -7
- package/dist/types/auth/oauth.d.ts +9 -6
- package/dist/types/auth/policy.d.ts +1 -0
- package/dist/types/auth/refresh.d.ts +1 -2
- package/dist/types/auth/select.d.ts +6 -4
- package/dist/types/auth/sqlite-credential-store.d.ts +21 -1
- package/dist/types/auth/store.d.ts +8 -2
- package/dist/types/auth/types.d.ts +99 -15
- package/dist/types/auth-broker/client.d.ts +3 -3
- package/dist/types/auth-broker/discover.d.ts +1 -1
- package/dist/types/auth-broker/refresher.d.ts +6 -1
- package/dist/types/auth-broker/remote-store.d.ts +6 -4
- package/dist/types/auth-broker/server.d.ts +2 -0
- package/dist/types/auth-broker/snapshot-cache.d.ts +12 -0
- package/dist/types/auth-gateway/dispatch.d.ts +13 -5
- package/dist/types/auth-gateway/http.d.ts +0 -2
- package/dist/types/auth-gateway/index.d.ts +1 -0
- package/dist/types/auth-gateway/routes/embeddings.d.ts +2 -2
- package/dist/types/auth-gateway/routes/images.d.ts +3 -3
- package/dist/types/auth-gateway/routes/rerank.d.ts +2 -2
- package/dist/types/auth-gateway/routes/speech.d.ts +2 -2
- package/dist/types/auth-gateway/routes/systemone.d.ts +2 -2
- package/dist/types/auth-gateway/routes/transcriptions.d.ts +2 -2
- package/dist/types/auth-gateway/routes/video.d.ts +4 -4
- package/dist/types/auth-gateway/server.d.ts +22 -5
- package/dist/types/auth-gateway/session-state.d.ts +6 -0
- package/dist/types/auth-gateway/stdio.d.ts +12 -0
- package/dist/types/auth-storage.d.ts +7 -6
- package/dist/types/dialect/terminator-wait.d.ts +19 -0
- package/dist/types/env-api-key.d.ts +21 -0
- package/dist/types/error/auth.d.ts +10 -0
- package/dist/types/error/flags.d.ts +38 -0
- package/dist/types/images/index.d.ts +2 -3
- package/dist/types/images/shared.d.ts +6 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/judgment/index.d.ts +2 -1
- package/dist/types/judgment/native.d.ts +80 -0
- package/dist/types/judgment/openai-decisions.d.ts +3 -0
- package/dist/types/judgment/question-file.d.ts +52 -0
- package/dist/types/judgment/systemone.d.ts +7 -0
- package/dist/types/judgment/types.d.ts +2 -2
- package/dist/types/judgment/wire.d.ts +36 -0
- package/dist/types/provider-details.d.ts +1 -1
- package/dist/types/provider-session-state.d.ts +2 -2
- package/dist/types/providers/anthropic-client.d.ts +10 -0
- package/dist/types/providers/anthropic-state.d.ts +2 -0
- package/dist/types/providers/anthropic.d.ts +38 -3
- package/dist/types/providers/aws-credentials.d.ts +4 -8
- package/dist/types/providers/connect-error-detail.d.ts +9 -0
- package/dist/types/providers/connect-frame.d.ts +44 -0
- package/dist/types/providers/cursor/interaction-query.d.ts +0 -2
- package/dist/types/providers/cursor.d.ts +8 -8
- package/dist/types/providers/google-auth.d.ts +4 -1
- package/dist/types/providers/google-shared.d.ts +24 -4
- package/dist/types/providers/inference-headers.d.ts +6 -0
- package/dist/types/providers/mock.d.ts +3 -1
- package/dist/types/providers/openai-codex/request-transformer.d.ts +2 -0
- package/dist/types/providers/openai-codex-responses.d.ts +1 -1
- package/dist/types/providers/openai-configuration-update.d.ts +20 -11
- package/dist/types/providers/openai-responses-wire.d.ts +1 -55
- package/dist/types/providers/openai-responses.d.ts +40 -3
- package/dist/types/providers/openai-shared.d.ts +30 -5
- package/dist/types/providers/pi-native-client.d.ts +1 -1
- package/dist/types/providers/transform-messages.d.ts +25 -0
- package/dist/types/providers/vision-guard.d.ts +1 -1
- package/dist/types/registry/oauth/cloudflare-workers-ai.d.ts +3 -0
- package/dist/types/registry/oauth/cursor.d.ts +10 -2
- package/dist/types/registry/oauth/index.d.ts +2 -0
- package/dist/types/registry/oauth/snowflake.d.ts +3 -0
- package/dist/types/registry/snowflake.d.ts +4 -0
- package/dist/types/stream.d.ts +0 -21
- package/dist/types/transcription/types.d.ts +2 -1
- package/dist/types/types.d.ts +116 -14
- package/dist/types/usage.d.ts +2 -0
- package/dist/types/utils/anthropic-auth.d.ts +21 -7
- package/dist/types/utils/aws-profile.d.ts +5 -0
- package/dist/types/utils/block-symbols.d.ts +14 -0
- package/dist/types/utils/dsml-leak.d.ts +29 -0
- package/dist/types/utils/glyph-codec.d.ts +1 -1
- package/dist/types/utils/idle-iterator.d.ts +11 -0
- package/dist/types/utils/leaked-thinking-stream.d.ts +1 -1
- package/dist/types/utils/resolve-peer.d.ts +2 -0
- package/dist/types/utils/retry-wait.d.ts +9 -0
- package/dist/types/utils/schema/normalize.d.ts +8 -3
- package/dist/types/utils/stream-markup-healing.d.ts +4 -4
- package/dist/types/utils/tool-call-arguments.d.ts +8 -0
- package/dist/types/utils.d.ts +6 -0
- package/package.json +6 -6
- package/src/auth/affinity.ts +130 -37
- package/src/auth/blocks.ts +94 -15
- package/src/auth/cascade.ts +112 -17
- package/src/auth/health.ts +3 -2
- package/src/auth/oauth.ts +25 -10
- package/src/auth/policy.ts +10 -1
- package/src/auth/pool.ts +0 -5
- package/src/auth/refresh.ts +17 -12
- package/src/auth/resets.ts +1 -1
- package/src/auth/rotation.ts +8 -2
- package/src/auth/select.ts +102 -30
- package/src/auth/sqlite-credential-store.ts +119 -49
- package/src/auth/store.ts +8 -2
- package/src/auth/types.ts +108 -17
- package/src/auth/usage-cache.ts +16 -5
- package/src/auth/usage.ts +2 -2
- package/src/auth-broker/client.ts +7 -4
- package/src/auth-broker/discover.ts +6 -5
- package/src/auth-broker/refresher.ts +8 -1
- package/src/auth-broker/remote-store.ts +200 -62
- package/src/auth-broker/server.ts +316 -130
- package/src/auth-broker/snapshot-cache.ts +142 -2
- package/src/auth-gateway/dispatch.ts +15 -7
- package/src/auth-gateway/http.ts +0 -8
- package/src/auth-gateway/index.ts +1 -0
- package/src/auth-gateway/routes/embeddings.ts +2 -2
- package/src/auth-gateway/routes/images.ts +4 -4
- package/src/auth-gateway/routes/rerank.ts +2 -2
- package/src/auth-gateway/routes/speech.ts +2 -2
- package/src/auth-gateway/routes/systemone.ts +22 -14
- package/src/auth-gateway/routes/transcriptions.ts +2 -2
- package/src/auth-gateway/routes/video.ts +7 -7
- package/src/auth-gateway/server.ts +175 -134
- package/src/auth-gateway/session-state.ts +51 -9
- package/src/auth-gateway/stdio.ts +132 -0
- package/src/auth-storage.ts +23 -9
- package/src/dialect/deepseek.ts +67 -8
- package/src/dialect/gemini.ts +8 -2
- package/src/dialect/hermes.ts +8 -2
- package/src/dialect/kimi.ts +8 -2
- package/src/dialect/qwen-xml.ts +8 -2
- package/src/dialect/qwen3.ts +8 -2
- package/src/dialect/terminator-wait.ts +42 -0
- package/src/env-api-key.ts +78 -0
- package/src/error/auth.ts +20 -0
- package/src/error/flags.ts +143 -24
- package/src/error/rate-limit.ts +8 -6
- package/src/images/google-antigravity.ts +0 -1
- package/src/images/index.ts +3 -17
- package/src/images/openai-hosted.ts +13 -4
- package/src/images/openai-images.ts +19 -13
- package/src/images/shared.ts +10 -2
- package/src/index.ts +2 -1
- package/src/judgment/index.ts +2 -1
- package/src/judgment/native.ts +333 -0
- package/src/judgment/openai-decisions-predicate.md +9 -0
- package/src/judgment/openai-decisions.ts +129 -0
- package/src/judgment/question-file.ts +90 -0
- package/src/judgment/systemone.ts +65 -0
- package/src/judgment/text.ts +9 -1
- package/src/judgment/types.ts +2 -2
- package/src/judgment/wire.ts +42 -0
- package/src/provider-details.ts +1 -1
- package/src/provider-session-state.ts +2 -2
- package/src/providers/amazon-bedrock.ts +19 -8
- package/src/providers/anthropic-client.ts +16 -1
- package/src/providers/anthropic-state.ts +6 -0
- package/src/providers/anthropic.ts +962 -238
- package/src/providers/apple-foundation-models.ts +10 -4
- package/src/providers/aws-credentials.ts +65 -5
- package/src/providers/azure-openai-responses.ts +1 -1
- package/src/providers/connect-error-detail.ts +21 -0
- package/src/providers/connect-frame.ts +107 -0
- package/src/providers/cursor/interaction-query.ts +1 -9
- package/src/providers/cursor.ts +590 -133
- package/src/providers/devin.ts +68 -58
- package/src/providers/factory-droid/gemini.ts +38 -51
- package/src/providers/factory-droid.ts +2 -0
- package/src/providers/gitlab-duo-workflow.ts +5 -2
- package/src/providers/gitlab-duo.ts +1 -0
- package/src/providers/google-auth.ts +10 -3
- package/src/providers/google-gemini-cli.ts +4 -0
- package/src/providers/google-shared.ts +134 -105
- package/src/providers/google-vertex.ts +0 -1
- package/src/providers/google.ts +1 -1
- package/src/providers/inference-headers.ts +19 -0
- package/src/providers/mock.ts +4 -0
- package/src/providers/ollama.ts +1 -1
- package/src/providers/openai-anthropic-shim.ts +1 -0
- package/src/providers/openai-codex/request-transformer.ts +16 -11
- package/src/providers/openai-codex-responses.ts +201 -76
- package/src/providers/openai-completions.ts +12 -2
- package/src/providers/openai-configuration-update.ts +54 -15
- package/src/providers/openai-responses-wire.ts +1 -55
- package/src/providers/openai-responses.ts +437 -33
- package/src/providers/openai-shared.ts +267 -72
- package/src/providers/pi-native-client.ts +2 -2
- package/src/providers/pi-native-server.ts +1 -0
- package/src/providers/systemone-server.ts +1 -1
- package/src/providers/transcriptions-server.ts +1 -1
- package/src/providers/transform-messages.ts +240 -84
- package/src/providers/vision-guard.ts +1 -1
- package/src/registry/aws.ts +51 -14
- package/src/registry/cloudflare-ai-gateway.ts +26 -3
- package/src/registry/hooks/api-key.ts +1 -0
- package/src/registry/hooks/custom.ts +2 -0
- package/src/registry/hooks/env.ts +2 -5
- package/src/registry/oauth/callback-server.ts +6 -1
- package/src/registry/oauth/cloudflare-ai-gateway.ts +2 -2
- package/src/registry/oauth/cloudflare-workers-ai.ts +32 -0
- package/src/registry/oauth/cursor.ts +80 -17
- package/src/registry/oauth/index.ts +5 -0
- package/src/registry/oauth/snowflake.ts +183 -0
- package/src/registry/registry.ts +2 -0
- package/src/registry/snowflake.ts +149 -0
- package/src/stream.ts +85 -107
- package/src/transcription/types.ts +2 -1
- package/src/types.ts +142 -15
- package/src/usage/claude.ts +19 -12
- package/src/usage/commandcode.ts +1 -1
- package/src/usage/cursor.ts +14 -25
- package/src/usage/github-copilot.ts +1 -1
- package/src/usage/kimi.ts +1 -1
- package/src/usage/minimax-code.ts +8 -1
- package/src/usage.ts +8 -0
- package/src/utils/anthropic-auth.ts +34 -10
- package/src/utils/aws-profile.ts +10 -4
- package/src/utils/block-symbols.ts +17 -0
- package/src/utils/dsml-leak.ts +109 -0
- package/src/utils/empty-completion-retry.ts +2 -3
- package/src/utils/glyph-codec.ts +200 -7
- package/src/utils/idle-iterator.ts +80 -35
- package/src/utils/leaked-thinking-stream.ts +47 -25
- package/src/utils/resolve-peer.ts +7 -0
- package/src/utils/retry-wait.ts +19 -0
- package/src/utils/schema/CONSTRAINTS.md +9 -7
- package/src/utils/schema/fields.ts +20 -0
- package/src/utils/schema/normalize.ts +65 -23
- package/src/utils/schema/wire.ts +3 -3
- package/src/utils/stream-markup-healing.ts +4 -4
- package/src/utils/thinking-loop.ts +36 -13
- package/src/utils/tool-call-arguments.ts +16 -0
- package/src/utils/transport-fetch.ts +1 -1
- package/src/utils.ts +41 -10
- package/dist/types/judgment/typesafe.d.ts +0 -49
- package/src/judgment/typesafe.ts +0 -183
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Judge questions authored as JSON files: `instructions` plus optional
|
|
3
|
+
* `criteria`, keyed by question id. A JSON import widens every string, so a
|
|
4
|
+
* question's kind follows from the shape of its `criteria` rather than a
|
|
5
|
+
* `type` field — the same rule at compile time ({@link QuestionFor}) and at
|
|
6
|
+
* load ({@link judgeQuestions}):
|
|
7
|
+
* - a list of levels, lowest first → {@link ScoreQuestion}
|
|
8
|
+
* - absent, or only `true`/`false` rubrics → {@link NoulQuestion}
|
|
9
|
+
* - any other labels → {@link ChoiceQuestion} over them; `{}` when the caller
|
|
10
|
+
* supplies every label (table rows, labels shared with another question)
|
|
11
|
+
*
|
|
12
|
+
* Instructions may be Handlebars templates; {@link renderQuestion} fills them.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts ignore
|
|
16
|
+
* import graph from "./auto-graph.json" with { type: "json" };
|
|
17
|
+
* const QUESTIONS = judgeQuestions(graph);
|
|
18
|
+
* QUESTIONS.shading; // ChoiceQuestion<"shared" | "series" | "row">
|
|
19
|
+
* renderQuestion(QUESTIONS.order, { column: "latency" });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { prompt } from "@linxiraos/pi-utils";
|
|
23
|
+
import type { ChoiceQuestion, NoulQuestion, Question, ScoreQuestion } from "./types.js";
|
|
24
|
+
/** One question as a JSON question file writes it; {@link QuestionFor} gives its kind. */
|
|
25
|
+
export interface QuestionSpec {
|
|
26
|
+
instructions: string;
|
|
27
|
+
criteria?: string[] | {
|
|
28
|
+
readonly [label: string]: string | null;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** A JSON question file: {@link QuestionSpec}s keyed by question id. */
|
|
32
|
+
export interface QuestionFile {
|
|
33
|
+
readonly [id: string]: QuestionSpec;
|
|
34
|
+
}
|
|
35
|
+
/** The question a {@link QuestionSpec} declares, with choice labels taken from its criteria keys. */
|
|
36
|
+
export type QuestionFor<S extends QuestionSpec> = S extends {
|
|
37
|
+
criteria: string[];
|
|
38
|
+
} ? ScoreQuestion : S extends {
|
|
39
|
+
criteria: infer C extends object;
|
|
40
|
+
} ? [keyof C] extends [never] ? ChoiceQuestion : [keyof C] extends ["true" | "false"] ? NoulQuestion : ChoiceQuestion<Extract<keyof C, string>> : NoulQuestion;
|
|
41
|
+
/** Every question a {@link QuestionFile} declares, keyed as in the file. */
|
|
42
|
+
export type QuestionsFor<F extends QuestionFile> = {
|
|
43
|
+
[K in keyof F]: QuestionFor<F[K]>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The typed questions of a JSON question file; answers to them come back typed
|
|
47
|
+
* through {@link JudgmentResult}.
|
|
48
|
+
* @throws when a score question lists fewer than two levels.
|
|
49
|
+
*/
|
|
50
|
+
export declare function judgeQuestions<F extends QuestionFile>(file: F): QuestionsFor<F>;
|
|
51
|
+
/** `question` with its instructions rendered as a Handlebars template over `context`. */
|
|
52
|
+
export declare function renderQuestion<Q extends Question>(question: Q, context: prompt.TemplateContext): Q;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type JudgmentWire } from "./wire.js";
|
|
2
|
+
/** TypeSafe's own route, shared by every System One server. */
|
|
3
|
+
export declare const typesafeWire: JudgmentWire;
|
|
4
|
+
/** OpenRouter Decisions: the System One body under `/api/alpha`. */
|
|
5
|
+
export declare const openrouterDecisionsWire: JudgmentWire;
|
|
6
|
+
/** Cloudflare Workers AI decision models (Clef) through the account-scoped `ai/run` route. */
|
|
7
|
+
export declare const workersAiWire: JudgmentWire;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* — about one {@link JudgmentState}. Every question in a request sees the same
|
|
8
8
|
* state and is answered independently, so callers batch independent questions
|
|
9
9
|
* into one call. The shape mirrors TypeSafe's System One API so the native
|
|
10
|
-
* backend ({@link
|
|
10
|
+
* backend ({@link NativeJudge}) forwards requests verbatim, while the text
|
|
11
11
|
* bridge ({@link TextJudge}) renders the same questions into keyword prompts
|
|
12
12
|
* for an ordinary chat model.
|
|
13
13
|
*/
|
|
@@ -75,7 +75,7 @@ export interface JudgmentRequest<Q extends Questions = Questions> {
|
|
|
75
75
|
questions: Q;
|
|
76
76
|
}
|
|
77
77
|
export interface JudgmentResult<Q extends Questions = Questions> {
|
|
78
|
-
/** Transport that produced the answers (`typesafe`, or the chat model's api). */
|
|
78
|
+
/** Transport that produced the answers (a judgment api such as `typesafe`, or the chat model's api). */
|
|
79
79
|
api: string;
|
|
80
80
|
provider: string;
|
|
81
81
|
model: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire dialects of the native judgment APIs: how {@link NativeJudge} addresses,
|
|
3
|
+
* encodes, and decodes one request for each API it serves. Internal to the
|
|
4
|
+
* judgment module; `native.ts` maps every judgment API to its dialect.
|
|
5
|
+
*/
|
|
6
|
+
import type { Usage } from "../types.js";
|
|
7
|
+
import type { JudgmentRequest } from "./types.js";
|
|
8
|
+
/** Where one attempt posts and which bearer token it sends. */
|
|
9
|
+
export interface JudgmentTarget {
|
|
10
|
+
url: string;
|
|
11
|
+
token: string;
|
|
12
|
+
}
|
|
13
|
+
/** One decoded response. */
|
|
14
|
+
export interface DecodedJudgment {
|
|
15
|
+
/** Model that answered, when the response names one. */
|
|
16
|
+
model: string | undefined;
|
|
17
|
+
/** Wire answers keyed by question id; {@link NativeJudge} checks each against its question's type. */
|
|
18
|
+
answers: Readonly<Record<string, unknown>>;
|
|
19
|
+
/** Question ids the model declined to answer. */
|
|
20
|
+
refused: readonly string[];
|
|
21
|
+
usage: Usage;
|
|
22
|
+
}
|
|
23
|
+
/** How one judgment API addresses, encodes, and decodes a request. */
|
|
24
|
+
export interface JudgmentWire {
|
|
25
|
+
/**
|
|
26
|
+
* Target of one attempt made with credential `key` against `model`.
|
|
27
|
+
* Throws when the credential cannot address the endpoint (e.g. no account id).
|
|
28
|
+
*/
|
|
29
|
+
target(baseUrl: string, model: string, key: string): JudgmentTarget;
|
|
30
|
+
/** Request body for `model`. */
|
|
31
|
+
encode(request: JudgmentRequest, model: string): unknown;
|
|
32
|
+
/** The response's answers and usage; `undefined` when the payload is not this API's response shape. */
|
|
33
|
+
decode(payload: unknown): DecodedJudgment | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** `value` when it is a finite number. */
|
|
36
|
+
export declare function finiteNumber(value: unknown): number | undefined;
|
|
@@ -14,7 +14,7 @@ export interface ProviderDetailsContext {
|
|
|
14
14
|
authMode?: string;
|
|
15
15
|
/**
|
|
16
16
|
* Human-readable description of the active credential, e.g.
|
|
17
|
-
* `"broker http://
|
|
17
|
+
* `"broker http://zeta.internal:8765 · oauth #5 (foo@bar.com)"`.
|
|
18
18
|
* Rendered as a `Source` field; omitted when undefined.
|
|
19
19
|
*/
|
|
20
20
|
credentialSource?: string;
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* siblings are endpoint-scoped and stay: `strictToolsDisabled`
|
|
19
19
|
* (grammar-too-large 400 for the model's tool schema),
|
|
20
20
|
* `replayUnsignedThinkingDisabled` / `thinkingReplayDisabled` (the endpoint
|
|
21
|
-
* is a signing proxy), `prefixDroppedThinkingBlocks` (blocks
|
|
22
|
-
*
|
|
21
|
+
* is a signing proxy), `prefixDroppedThinkingBlocks` (blocks a prefix-binding
|
|
22
|
+
* 400 made the client strip).
|
|
23
23
|
* - **OpenAI Responses** — the `previous_response_id` chain baselines are
|
|
24
24
|
* account-scoped: a stored response belongs to the account that created it.
|
|
25
25
|
* Strict-tools / reasoning-effort fallbacks, replay warmup and the chaining
|
|
@@ -94,6 +94,13 @@ export interface AnthropicMessagesClientLike {
|
|
|
94
94
|
create(params: MessageCreateParams, options?: AnthropicRequestOptions): unknown;
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Endpoint the client targets, when it exposes one. SDK-style clients
|
|
99
|
+
* (`Anthropic`, `AnthropicVertex`) and {@link AnthropicMessagesClient}
|
|
100
|
+
* publish it; a client that exposes none keeps its transport opaque, and the
|
|
101
|
+
* provider must not assume the model's own routing on its behalf.
|
|
102
|
+
*/
|
|
103
|
+
baseURL?: string;
|
|
97
104
|
}
|
|
98
105
|
export declare class AnthropicMessagesClient implements AnthropicMessagesClientLike {
|
|
99
106
|
#private;
|
|
@@ -101,12 +108,15 @@ export declare class AnthropicMessagesClient implements AnthropicMessagesClientL
|
|
|
101
108
|
readonly beta: {
|
|
102
109
|
readonly messages: AnthropicMessages;
|
|
103
110
|
};
|
|
111
|
+
/** Endpoint shared with the HTTP transport. */
|
|
112
|
+
get baseURL(): string;
|
|
104
113
|
constructor(options: AnthropicClientOptions);
|
|
105
114
|
request(path: string, params: MessageCreateParams, options?: AnthropicRequestOptions): AnthropicApiRequest;
|
|
106
115
|
}
|
|
107
116
|
/** Shared Anthropic HTTP transport for Messages and resource APIs. */
|
|
108
117
|
export declare class AnthropicHttpClient {
|
|
109
118
|
#private;
|
|
119
|
+
readonly baseURL: string;
|
|
110
120
|
constructor(options: AnthropicClientOptions);
|
|
111
121
|
request(method: "GET" | "POST", path: string, params?: unknown, options?: AnthropicRequestOptions): Promise<Response>;
|
|
112
122
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Api, Model, ProviderSessionState } from "../types.js";
|
|
2
2
|
/** Root key for Anthropic's per-session provider state. */
|
|
3
3
|
export declare const ANTHROPIC_PROVIDER_SESSION_STATE_KEY = "anthropic-messages";
|
|
4
|
+
/** Caller-map anchor for session-scoped opaque injected clients. */
|
|
5
|
+
export declare const ANTHROPIC_OPAQUE_CLIENT_ANCHOR_KEY = "anthropic-opaque-clients";
|
|
4
6
|
/** Normalize an Anthropic base URL to its origin path without `/v1`. */
|
|
5
7
|
export declare function normalizeAnthropicBaseUrl(baseUrl?: string): string | undefined;
|
|
6
8
|
/** Resolve the endpoint for a first-party Anthropic model without loading its provider implementation. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Effort } from "@linxiraos/pi-catalog/effort";
|
|
2
|
+
import type { AnthropicCompactionRequest, AnthropicOutputEffort, FetchImpl, Message, Model, ServiceTier, SimpleStreamOptions, StreamFunction, StreamOptions, Usage } from "../types.js";
|
|
2
3
|
import { type AnthropicFetchOptions, type AnthropicMessagesClientLike } from "./anthropic-client.js";
|
|
3
4
|
import { type FallbackParam, type MessageParam, type TextBlockParam } from "./anthropic-wire.js";
|
|
4
5
|
import { resolvesToOfficialAnthropicEndpoint, supportsAnthropicCompaction, supportsAnthropicCompactionOnClient } from "./anthropic-compaction.js";
|
|
@@ -134,6 +135,13 @@ export type AnthropicClientOptionsArgs = {
|
|
|
134
135
|
thinkingEnabled?: boolean;
|
|
135
136
|
thinkingDisplay?: AnthropicThinkingDisplay;
|
|
136
137
|
disableStrictTools?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Withhold the prompt-cache betas (see `buildClaudeCodeBetas`). Set when the
|
|
140
|
+
* request carries no breakpoint at all, and also when it carries breakpoints
|
|
141
|
+
* stripped of `ttl`/`scope`: both betas govern those options, so a body
|
|
142
|
+
* without them must advertise neither.
|
|
143
|
+
*/
|
|
144
|
+
dropPromptCacheBetas?: boolean;
|
|
137
145
|
fetch?: FetchImpl;
|
|
138
146
|
maxRetryDelayMs?: number;
|
|
139
147
|
sessionId?: string;
|
|
@@ -168,6 +176,12 @@ export type AnthropicClientOptionsResult = {
|
|
|
168
176
|
* omitted there.
|
|
169
177
|
*/
|
|
170
178
|
export declare function resolveAnthropicCustomHeadersForBaseUrl(baseUrl: string | undefined): Record<string, string> | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Merge headers case-insensitively; later sources win and preserve their key casing.
|
|
181
|
+
* Undefined sources are ignored. Differently cased duplicates are removed so the
|
|
182
|
+
* Headers constructor cannot join competing values comma-separated on the wire.
|
|
183
|
+
*/
|
|
184
|
+
export declare function mergeHeaders(...headerSources: (Record<string, string> | undefined)[]): Record<string, string>;
|
|
171
185
|
export type AnthropicUsageLike = {
|
|
172
186
|
cache_creation?: {
|
|
173
187
|
ephemeral_5m_input_tokens?: number | null;
|
|
@@ -209,10 +223,19 @@ export type AnthropicSystemBlock = {
|
|
|
209
223
|
type SystemBlockOptions = {
|
|
210
224
|
includeClaudeCodeInstruction?: boolean;
|
|
211
225
|
extraInstructions?: string[];
|
|
212
|
-
/** Text of the first user
|
|
226
|
+
/** Text of the first conversational wire user turn, used as the billing fingerprint seed. */
|
|
213
227
|
firstUserMessageText?: string;
|
|
214
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* Cache lifetime shared by the OAuth system breakpoint and later message
|
|
230
|
+
* breakpoints. Omitted → the identity block keeps its default `ephemeral`
|
|
231
|
+
* breakpoint; see `dropCacheControl` to emit none at all.
|
|
232
|
+
*/
|
|
215
233
|
cacheControl?: AnthropicCacheControl;
|
|
234
|
+
/**
|
|
235
|
+
* Emit no `cache_control` on any block: the endpoint rejected the field.
|
|
236
|
+
* Distinct from an undefined `cacheControl`, which only means "default".
|
|
237
|
+
*/
|
|
238
|
+
dropCacheControl?: boolean;
|
|
216
239
|
};
|
|
217
240
|
export declare function buildAnthropicSystemBlocks(systemPrompt: readonly string[] | undefined, options?: SystemBlockOptions): AnthropicSystemBlock[] | undefined;
|
|
218
241
|
export declare function normalizeExtraBetas(betas?: string[] | string): string[];
|
|
@@ -234,6 +257,16 @@ export declare function budgetThinkingOutput(maxTokens: number | undefined, budg
|
|
|
234
257
|
maxTokens: number;
|
|
235
258
|
budgetTokens: number;
|
|
236
259
|
};
|
|
260
|
+
/**
|
|
261
|
+
* The effort whose thinking allowance an on-demand compaction request over
|
|
262
|
+
* `messages` gets. It sends no effort change of its own, so once an earlier
|
|
263
|
+
* request recorded an effort, the one it left in force applies, even when
|
|
264
|
+
* `requested` differs or is off. When that request named none, the API's
|
|
265
|
+
* per-model default applies, which is not known here: the request gets the
|
|
266
|
+
* largest effort's allowance (`max_tokens` is a cap, not spend). Without a
|
|
267
|
+
* recorded effort the request sets its own.
|
|
268
|
+
*/
|
|
269
|
+
export declare function resolveAnthropicCompactionEffort(model: Model<"anthropic-messages">, messages: readonly Message[], requested: Effort | undefined): Effort | undefined;
|
|
237
270
|
/**
|
|
238
271
|
* Whether the conversation has stopped being thinking-led, so routes with
|
|
239
272
|
* `compat.stripThinkingHistory` drop the budget `thinking` config and replay
|
|
@@ -269,5 +302,7 @@ export declare function convertAnthropicMessages(messages: Message[], model: Mod
|
|
|
269
302
|
dropAllThinking?: boolean;
|
|
270
303
|
droppedThinkingBlocks?: ReadonlySet<string>;
|
|
271
304
|
credentialId?: number;
|
|
305
|
+
/** On-demand compaction request: it ends inside the conversation, so it gets nothing live requests lack there. */
|
|
306
|
+
compactionRequest?: AnthropicCompactionRequest;
|
|
272
307
|
}): AnthropicMessageParam[];
|
|
273
308
|
export declare function normalizeAnthropicToolSchema(schema: unknown): unknown;
|
|
@@ -29,14 +29,10 @@ export interface CredentialResolveOptions {
|
|
|
29
29
|
fetch?: FetchImpl;
|
|
30
30
|
}
|
|
31
31
|
export declare function resolveAwsCredentials(opts?: CredentialResolveOptions): Promise<ResolvedCredentials>;
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
* a backslash only escapes `$`, `` ` ``, `"`, and `\` — every other backslash
|
|
37
|
-
* is preserved verbatim, which is what makes Windows paths like
|
|
38
|
-
* `"C:\Program Files\tool\auth.exe"` survive tokenization. */
|
|
39
|
-
export declare function tokenizeCredentialProcessCommand(cmd: string): string[];
|
|
32
|
+
/** Split a `credential_process` command into argv the way botocore's
|
|
33
|
+
* `compat_shell_split` does: Windows command-line (CRT) rules on `win32`,
|
|
34
|
+
* POSIX shell rules everywhere else. */
|
|
35
|
+
export declare function tokenizeCredentialProcessCommand(cmd: string, platform?: NodeJS.Platform): string[];
|
|
40
36
|
/** Test/diagnostic helper — drops cached credentials. */
|
|
41
37
|
export declare function clearAwsCredentialCache(): void;
|
|
42
38
|
/**
|
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
* usable is present.
|
|
5
5
|
*/
|
|
6
6
|
export declare function summarizeConnectErrorDetails(details: unknown): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* True when Cursor's `aiserver.v1.ErrorDetails` entry declares the failure
|
|
9
|
+
* retryable. Its JSON `debug` form carries `details.isRetryable` — set on
|
|
10
|
+
* upstream outages such as ERROR_OPENAI ("Unable to reach the model
|
|
11
|
+
* provider") whose bare `code: message` text (`unavailable: Error`)
|
|
12
|
+
* classifies as a hard failure on its own. Other detail types are ignored
|
|
13
|
+
* even when they share the `debug.details` shape.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hasRetryableCursorErrorDetail(details: unknown): boolean;
|
|
7
16
|
/**
|
|
8
17
|
* Formats a Connect end-stream error object into a diagnosable message.
|
|
9
18
|
* The "Connect error code: message" prefix is preserved exactly; detail
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connect-protocol streaming envelope shared by the Cursor and Devin
|
|
3
|
+
* transports: 1 flag byte + 4-byte big-endian payload length + payload.
|
|
4
|
+
*/
|
|
5
|
+
/** Flag bit: payload is compressed with the negotiated encoding (gzip). */
|
|
6
|
+
export declare const CONNECT_COMPRESSED_FLAG = 1;
|
|
7
|
+
/** Flag bit: payload is the end-of-stream JSON trailer. */
|
|
8
|
+
export declare const CONNECT_END_STREAM_FLAG = 2;
|
|
9
|
+
/** Wrap one Connect-protocol message: 1 flag byte + 4-byte big-endian length + payload. */
|
|
10
|
+
export declare function frameConnectMessage(data: Uint8Array, flags?: number): Buffer;
|
|
11
|
+
/** One decoded Connect envelope. */
|
|
12
|
+
export interface ConnectFrame {
|
|
13
|
+
flags: number;
|
|
14
|
+
payload: Buffer;
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@link ConnectFrameDecoder}. */
|
|
17
|
+
export interface ConnectFrameDecoderOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Payload cap: a length prefix above `maxPayloadBytes` throws `error(length)`
|
|
20
|
+
* before any of that payload is buffered. Uncapped when omitted.
|
|
21
|
+
*/
|
|
22
|
+
limit?: {
|
|
23
|
+
maxPayloadBytes: number;
|
|
24
|
+
error: (length: number) => Error;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Incremental Connect frame decoder. Incoming chunks are kept as-is and a frame
|
|
29
|
+
* spanning several chunks is joined once, when the length the header announced
|
|
30
|
+
* has fully arrived — re-concatenating the pending bytes on every chunk made a
|
|
31
|
+
* multi-MB frame cost O(size × chunks).
|
|
32
|
+
*
|
|
33
|
+
* Payloads alias the chunk they came from whenever a frame fits in one chunk,
|
|
34
|
+
* so callers must not reuse chunk buffers they hand in.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ConnectFrameDecoder {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(options?: ConnectFrameDecoderOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Buffer `chunk` (if any) and yield every frame now complete, in wire order.
|
|
41
|
+
* An oversize length prefix throws after the frames that precede it.
|
|
42
|
+
*/
|
|
43
|
+
decode(chunk?: Uint8Array): Generator<ConnectFrame, void, undefined>;
|
|
44
|
+
}
|
|
@@ -7,8 +7,6 @@ type ProtoUnknownField = {
|
|
|
7
7
|
interface CursorInteractionWriter {
|
|
8
8
|
write(frame: Uint8Array): void;
|
|
9
9
|
}
|
|
10
|
-
/** Wrap one Connect-protocol message: 1 flag byte + 4-byte big-endian length + payload. */
|
|
11
|
-
export declare function frameConnectMessage(data: Uint8Array, flags?: number): Buffer;
|
|
12
10
|
/** Well-formed protobuf-es `$unknown` entries on `message`; anything else on the bag is ignored. */
|
|
13
11
|
export declare function protoUnknownFields(message: object): ProtoUnknownField[];
|
|
14
12
|
/**
|
|
@@ -169,13 +169,13 @@ export declare function emptyGrepPatternRejection(pattern: string | undefined, g
|
|
|
169
169
|
* so reparsing unconditionally would erase the arguments of every such block
|
|
170
170
|
* caught open by a truncated stream.
|
|
171
171
|
*
|
|
172
|
-
* Server-owned blocks are also paired here. `connect-scm
|
|
173
|
-
* stamped {@link kCursorExecResolved} the moment they open,
|
|
174
|
-
* synthesizes no placeholder for them and only their
|
|
175
|
-
* pairs a result. A transport that closes before
|
|
176
|
-
* call unpaired, and `buildSessionContext` strips
|
|
177
|
-
* rebuilt transcript — the interaction disappears.
|
|
178
|
-
* emitted instead.
|
|
172
|
+
* Server-owned blocks are also paired here. `connect-scm`, `todo` and
|
|
173
|
+
* `web-fetch` are stamped {@link kCursorExecResolved} the moment they open,
|
|
174
|
+
* so `agent-loop.ts` synthesizes no placeholder for them and only their
|
|
175
|
+
* `toolCallCompleted` frame pairs a result. A transport that closes before
|
|
176
|
+
* that frame would leave the call unpaired, and `buildSessionContext` strips
|
|
177
|
+
* a dangling call from every rebuilt transcript — the interaction disappears.
|
|
178
|
+
* An interrupted result is emitted instead.
|
|
179
179
|
*
|
|
180
180
|
* MCP blocks are excluded even when resolved: the exec dispatch that marked
|
|
181
181
|
* them owns their result, and `drainInFlightDispatches` awaits it before this
|
|
@@ -228,7 +228,7 @@ export declare function processInteractionUpdate(update: any, output: AssistantM
|
|
|
228
228
|
/**
|
|
229
229
|
* Cursor AgentService reconstructs the model prompt from `requestContext.rules`,
|
|
230
230
|
* not from the client-supplied `rootPromptMessagesJson` system blobs. Map each
|
|
231
|
-
*
|
|
231
|
+
* OMP system-prompt entry to a global CursorRule so always-apply rules survive
|
|
232
232
|
* that reconstruction.
|
|
233
233
|
*/
|
|
234
234
|
export declare function buildCursorRequestContextRules(systemPrompt: readonly string[] | undefined): CursorRule[];
|
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
* Sources, in priority order:
|
|
6
6
|
* 1. `GOOGLE_APPLICATION_CREDENTIALS` env → file with `type: "service_account"` (RS256 JWT exchange)
|
|
7
7
|
* or `type: "authorized_user"` (refresh-token exchange).
|
|
8
|
-
* 2.
|
|
8
|
+
* 2. gcloud user ADC: `%APPDATA%\gcloud\application_default_credentials.json` on Windows,
|
|
9
|
+
* `~/.config/gcloud/application_default_credentials.json` elsewhere (authorized_user flow).
|
|
9
10
|
* 3. GCE / Cloud Run metadata server (`metadata.google.internal`).
|
|
10
11
|
*
|
|
11
12
|
* Tokens are cached per source key and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` before expiry
|
|
12
13
|
* (default 60s). Concurrent callers waiting on a refresh share the same in-flight promise.
|
|
13
14
|
*/
|
|
14
15
|
import type { FetchImpl } from "../types.js";
|
|
16
|
+
/** gcloud's user ADC file: `%APPDATA%\gcloud\…` on Windows, `~/.config/gcloud/…` elsewhere. */
|
|
17
|
+
export declare function userAdcPath(platform?: typeof process.platform, appData?: string | undefined): string;
|
|
15
18
|
/**
|
|
16
19
|
* Returns a Bearer access token suitable for the `Authorization` header on Vertex AI calls.
|
|
17
20
|
* The token is cached in module scope and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` ms before it expires.
|
|
@@ -145,6 +145,22 @@ export declare function pushBlockEndEvent(block: TextContent | ThinkingContent,
|
|
|
145
145
|
* before invoking — this helper does not mutate `output.content`.
|
|
146
146
|
*/
|
|
147
147
|
export declare function pushToolCallEvents(toolCall: ToolCall, contentIndex: number, output: AssistantMessage, stream: AssistantMessageEventStream): void;
|
|
148
|
+
/** How {@link GoogleTextBlocks} keeps thought text: healed of leaked fence delimiters (#8719), or as received. */
|
|
149
|
+
export type GoogleThoughtText = "healed" | "verbatim";
|
|
150
|
+
/**
|
|
151
|
+
* Folds streamed generateContent text and thought parts into text and thinking
|
|
152
|
+
* blocks, opening a new block whenever the part kind changes. A part's
|
|
153
|
+
* `thoughtSignature` stays on the block it belongs to; the empty text part
|
|
154
|
+
* Gemini sends after a reply's last chunk signs the open block.
|
|
155
|
+
*/
|
|
156
|
+
export declare class GoogleTextBlocks {
|
|
157
|
+
#private;
|
|
158
|
+
constructor(output: AssistantMessage, stream: AssistantMessageEventStream, thoughtText: GoogleThoughtText);
|
|
159
|
+
/** Folds one response part; parts without text are ignored. */
|
|
160
|
+
push(part: Part): void;
|
|
161
|
+
/** Ends the open block, releasing thinking text the fence stripper held back. */
|
|
162
|
+
close(): void;
|
|
163
|
+
}
|
|
148
164
|
/**
|
|
149
165
|
* Append a new text- or thinking-block to `output.content` and push the matching
|
|
150
166
|
* `text_start` / `thinking_start` event. `onBeforeStartEvent` lets the SSE consumer
|
|
@@ -153,6 +169,13 @@ export declare function pushToolCallEvents(toolCall: ToolCall, contentIndex: num
|
|
|
153
169
|
export declare function startTextOrThinkingBlock(isThinking: true, output: AssistantMessage, stream: AssistantMessageEventStream, onBeforeStartEvent?: () => void): ThinkingContent;
|
|
154
170
|
export declare function startTextOrThinkingBlock(isThinking: false, output: AssistantMessage, stream: AssistantMessageEventStream, onBeforeStartEvent?: () => void): TextContent;
|
|
155
171
|
export declare function startTextOrThinkingBlock(isThinking: boolean, output: AssistantMessage, stream: AssistantMessageEventStream, onBeforeStartEvent?: () => void): TextContent | ThinkingContent;
|
|
172
|
+
/**
|
|
173
|
+
* Error for an in-band `error` frame in a 200 generateContent stream. Keeps the
|
|
174
|
+
* RPC status alongside the message: an in-band quota failure is classified
|
|
175
|
+
* from this text, and `RESOURCE_EXHAUSTED` is the only account-exhaustion
|
|
176
|
+
* signal some of these chunks carry (#13090).
|
|
177
|
+
*/
|
|
178
|
+
export declare function googleStreamChunkError(error: NonNullable<GenerateContentResponse["error"]>, provider: string): Error;
|
|
156
179
|
/**
|
|
157
180
|
* Drives the chunked `generateContentStream` iterator into an `AssistantMessage` and
|
|
158
181
|
* the corresponding `AssistantMessageEventStream`. Shared between `streamGoogle` and
|
|
@@ -163,7 +186,7 @@ export declare function startTextOrThinkingBlock(isThinking: boolean, output: As
|
|
|
163
186
|
* pushing `start`/`done`/`error` events, and the surrounding try/catch that translates
|
|
164
187
|
* thrown errors into `output.stopReason`/`errorMessage`.
|
|
165
188
|
*
|
|
166
|
-
* This helper handles: the chunk loop,
|
|
189
|
+
* This helper handles: the chunk loop, text/thinking blocks ({@link GoogleTextBlocks}), usage metadata
|
|
167
190
|
* decoding (`calculateCost` included), tool-call id collision avoidance, finish-reason
|
|
168
191
|
* mapping, and the abort/stop-reason post-checks that re-throw to bubble into the
|
|
169
192
|
* caller's catch.
|
|
@@ -176,8 +199,6 @@ export declare function consumeGoogleStream<T extends GoogleApiType>(args: {
|
|
|
176
199
|
options: {
|
|
177
200
|
signal?: AbortSignal;
|
|
178
201
|
} | undefined;
|
|
179
|
-
/** Vertex preserves `textSignature` on streamed text deltas; google-generative-ai does not. */
|
|
180
|
-
retainTextSignature?: boolean;
|
|
181
202
|
onFirstToken?: () => void;
|
|
182
203
|
}): Promise<void>;
|
|
183
204
|
/**
|
|
@@ -210,7 +231,6 @@ export declare function streamGoogleGenAI<T extends "google-generative-ai" | "go
|
|
|
210
231
|
model: Model<T>;
|
|
211
232
|
options: GoogleSharedStreamOptions | undefined;
|
|
212
233
|
api: T;
|
|
213
|
-
retainTextSignature?: boolean;
|
|
214
234
|
prepare: () => GoogleGenAIRequestPlan | Promise<GoogleGenAIRequestPlan>;
|
|
215
235
|
}): AssistantMessageEventStream;
|
|
216
236
|
/**
|
|
@@ -7,6 +7,12 @@ export interface InferenceHeaderOptions {
|
|
|
7
7
|
}
|
|
8
8
|
/** Set a header unless the map already contains that field under any casing. */
|
|
9
9
|
export declare function setHeaderIfAbsent(headers: Record<string, string>, name: string, value: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Label a request with the conversation id under the model's resolved
|
|
12
|
+
* `compat.sessionHeader` (KDL `session-header`). A header the caller or config
|
|
13
|
+
* already set wins; without a conversation id nothing is sent.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applySessionHeader(headers: Record<string, string> | Headers, compat: object | undefined, sessionId: string | undefined): void;
|
|
10
16
|
/**
|
|
11
17
|
* Project omp's identity and authoritative conversation id onto the headers
|
|
12
18
|
* understood by the active inference protocol and host.
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
* // Inspect calls afterwards.
|
|
42
42
|
* expect(mock.calls).toHaveLength(2);
|
|
43
43
|
*/
|
|
44
|
-
import type { AnthropicFallbackCreditHandle, Api, Context, Model, SimpleStreamOptions, StopDetails, StopReason, Usage } from "../types.js";
|
|
44
|
+
import type { AnthropicFallbackCreditHandle, Api, Context, Model, ServiceTier, SimpleStreamOptions, StopDetails, StopReason, Usage } from "../types.js";
|
|
45
45
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
46
46
|
/** The API string this provider serves. */
|
|
47
47
|
export declare const MOCK_API: "mock";
|
|
@@ -78,6 +78,8 @@ export interface MockResponse {
|
|
|
78
78
|
usage?: Partial<Omit<Usage, "cost">> & {
|
|
79
79
|
cost?: Partial<Usage["cost"]>;
|
|
80
80
|
};
|
|
81
|
+
/** Service tier the mock reports serving the turn, as a real provider's response echo would. */
|
|
82
|
+
serviceTier?: ServiceTier;
|
|
81
83
|
/** Pre-set responseId. */
|
|
82
84
|
responseId?: string;
|
|
83
85
|
/** If set, the stream emits a terminal error event instead of completing. */
|
|
@@ -78,6 +78,8 @@ export interface RequestBody {
|
|
|
78
78
|
* explicit option; normal inference defaults to the full Responses contract.
|
|
79
79
|
*/
|
|
80
80
|
export declare function resolveCodexResponsesLite(requested: boolean | undefined): boolean;
|
|
81
|
+
/** Wire tier of the model's lowest effort, which a `minimizeEffort` request runs at. */
|
|
82
|
+
export declare function lowestCodexWireEffort(model: Model<"openai-codex-responses">): ReasoningConfig["effort"] | undefined;
|
|
81
83
|
/**
|
|
82
84
|
* Repair both halves of unpaired tool exchanges so the Responses input grammar
|
|
83
85
|
* stays valid — the API rejects either orphan with a 400:
|
|
@@ -148,7 +148,7 @@ export declare function buildTransformedCodexRequestBody(model: Model<"openai-co
|
|
|
148
148
|
*/
|
|
149
149
|
export declare function openCodexCompactionEventStream(model: Model<"openai-codex-responses">, body: OpenAICodexCompactionBody, options: OpenAICodexCompactionStreamOptions): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
150
150
|
export declare const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses">;
|
|
151
|
-
export declare function prewarmOpenAICodexResponses(model: Model<"openai-codex-responses">, options?: Pick<OpenAICodexResponsesOptions, "apiKey" | "headers" | "sessionId" | "signal" | "preferWebsockets" | "providerSessionState" | "responsesLite">): Promise<void>;
|
|
151
|
+
export declare function prewarmOpenAICodexResponses(model: Model<"openai-codex-responses">, options?: Pick<OpenAICodexResponsesOptions, "apiKey" | "headers" | "sessionId" | "signal" | "preferWebsockets" | "providerSessionState" | "responsesLite" | "serviceTier">): Promise<void>;
|
|
152
152
|
export interface OpenAICodexTransportDetails {
|
|
153
153
|
websocketPreferred: boolean;
|
|
154
154
|
lastTransport?: CodexTransport;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mid-conversation reasoning effort via `configuration_update` input items
|
|
3
|
-
* (GPT-6
|
|
3
|
+
* (GPT-6 family; `model.compat.supportsConfigurationUpdate`).
|
|
4
4
|
*
|
|
5
5
|
* The request-level `reasoning.effort` is pinned to the value of the session's
|
|
6
6
|
* first request so the cached prompt prefix survives an effort change. Each
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
* planning.
|
|
13
13
|
*
|
|
14
14
|
* Used by both the platform Responses provider and the Codex provider; the
|
|
15
|
-
* state lives in each provider's session state, keyed per conversation.
|
|
15
|
+
* state lives in each provider's session state, keyed per conversation. A side
|
|
16
|
+
* request plans against a copy of its parent conversation's state (see
|
|
17
|
+
* {@link resolveOpenAIEffortControlState}), so it sends the parent's prefix.
|
|
16
18
|
*
|
|
17
|
-
* Wire constraints (
|
|
18
|
-
*
|
|
19
|
+
* Wire constraints (OpenAI reasoning guide): the GPT-6 family supports the item
|
|
20
|
+
* in standard (not `pro`) reasoning mode, adjacent updates are rejected, and
|
|
19
21
|
* `/responses/compact` rejects histories containing them — compaction
|
|
20
22
|
* requests are built outside this planner and never carry the items.
|
|
21
23
|
*/
|
|
@@ -35,16 +37,21 @@ interface EffortTransition<TEffort extends string> {
|
|
|
35
37
|
}
|
|
36
38
|
/** Per-conversation effort baseline and recorded transitions. */
|
|
37
39
|
export interface OpenAIEffortControlState<TEffort extends string = string> {
|
|
40
|
+
sessionId: string;
|
|
38
41
|
baseEffort?: TEffort;
|
|
39
42
|
currentEffort?: TEffort;
|
|
40
43
|
transitions: EffortTransition<TEffort>[];
|
|
41
44
|
}
|
|
42
|
-
export declare function createOpenAIEffortControlState<TEffort extends string>(): OpenAIEffortControlState<TEffort>;
|
|
45
|
+
export declare function createOpenAIEffortControlState<TEffort extends string>(sessionId: string): OpenAIEffortControlState<TEffort>;
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
47
|
+
* Control state a Responses or Codex request plans against. A side request
|
|
48
|
+
* (`parentSessionId`) gets a throwaway copy of its parent's state, fresh when
|
|
49
|
+
* the parent has none: it replays the parent's updates, and its own effort
|
|
50
|
+
* change never reaches the parent. Other requests get their session's state.
|
|
46
51
|
*/
|
|
47
|
-
export declare function
|
|
52
|
+
export declare function resolveOpenAIEffortControlState<TEffort extends string>(states: Map<string, OpenAIEffortControlState<TEffort>>, keyOf: (sessionId: string) => string, sessionId: string, parentSessionId: string | undefined): OpenAIEffortControlState<TEffort>;
|
|
53
|
+
/** Release one conversation's effort state from the Responses and Codex `releaseSession` implementations. */
|
|
54
|
+
export declare function releaseOpenAIEffortControlSession<TEffort extends string>(states: Map<string, OpenAIEffortControlState<TEffort>>, sessionId: string): void;
|
|
48
55
|
interface AnchorableItem {
|
|
49
56
|
type?: string | null;
|
|
50
57
|
role?: string;
|
|
@@ -57,8 +64,10 @@ interface AnchorableItem {
|
|
|
57
64
|
*
|
|
58
65
|
* `input` is the freshly built transcript for this request, without any
|
|
59
66
|
* `configuration_update` items. `requested` is the wire effort the caller
|
|
60
|
-
* would otherwise send at the request level.
|
|
61
|
-
*
|
|
67
|
+
* would otherwise send at the request level. `minimized` replaces it once a
|
|
68
|
+
* baseline exists, where the change rides an update and keeps the cached
|
|
69
|
+
* prefix; a request that sets the baseline runs at `requested`. Returns the
|
|
70
|
+
* effort to send at the request level (the baseline).
|
|
62
71
|
*/
|
|
63
|
-
export declare function planStableOpenAIEffort<TItem extends AnchorableItem, TEffort extends string>(state: OpenAIEffortControlState<TEffort>, input: Array<TItem | ConfigurationUpdateItem>, requested: TEffort): TEffort;
|
|
72
|
+
export declare function planStableOpenAIEffort<TItem extends AnchorableItem, TEffort extends string>(state: OpenAIEffortControlState<TEffort>, input: Array<TItem | ConfigurationUpdateItem>, requested: TEffort, minimized?: TEffort): TEffort;
|
|
64
73
|
export {};
|