@pencil-agent/nano-pencil 2.0.0-beta.2 → 2.0.0-beta.3
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/dist/build-meta.json +3 -3
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
- package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
- package/dist/node_modules/@pencil-agent/ai/package.json +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
- package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
- package/package.json +3 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: AzureOpenAIResponsesOptions, streamAzureOpenAIResponses, streamSimpleAzureOpenAIResponses
|
|
3
|
+
* [FROM]: Depends on openai, ../env-api-keys.js, ../models.js, ../utils/event-stream.js, ./openai-responses-shared.js
|
|
4
|
+
* [TO]: Consumed by core/lib/ai/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/ai/src/providers/azure-openai-responses.ts -
|
|
6
|
+
*/
|
|
7
|
+
import type { SimpleStreamOptions, StreamFunction, StreamOptions } from "../types.js";
|
|
8
|
+
export interface AzureOpenAIResponsesOptions extends StreamOptions {
|
|
9
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
10
|
+
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
11
|
+
toolChoice?: unknown;
|
|
12
|
+
azureApiVersion?: string;
|
|
13
|
+
azureResourceName?: string;
|
|
14
|
+
azureBaseUrl?: string;
|
|
15
|
+
azureDeploymentName?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate function for Azure OpenAI Responses API
|
|
19
|
+
*/
|
|
20
|
+
export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses", AzureOpenAIResponsesOptions>;
|
|
21
|
+
export declare const streamSimpleAzureOpenAIResponses: StreamFunction<"azure-openai-responses", SimpleStreamOptions>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: AzureOpenAIResponsesOptions, streamAzureOpenAIResponses, streamSimpleAzureOpenAIResponses
|
|
3
|
+
* [FROM]: Depends on openai, ../env-api-keys.js, ../models.js, ../utils/event-stream.js, ./openai-responses-shared.js
|
|
4
|
+
* [TO]: Consumed by core/lib/ai/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/ai/src/providers/azure-openai-responses.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { AzureOpenAI } from "openai";
|
|
8
|
+
import { getEnvApiKey } from "../env-api-keys.js";
|
|
9
|
+
import { supportsXhigh } from "../models.js";
|
|
10
|
+
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
11
|
+
import { convertResponsesMessages, convertResponsesTools, processResponsesStream } from "./openai-responses-shared.js";
|
|
12
|
+
import { buildBaseOptions, clampReasoning } from "./simple-options.js";
|
|
13
|
+
const DEFAULT_AZURE_API_VERSION = "v1";
|
|
14
|
+
const AZURE_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode", "azure-openai-responses"]);
|
|
15
|
+
function parseDeploymentNameMap(value) {
|
|
16
|
+
const map = new Map();
|
|
17
|
+
if (!value)
|
|
18
|
+
return map;
|
|
19
|
+
for (const entry of value.split(",")) {
|
|
20
|
+
const trimmed = entry.trim();
|
|
21
|
+
if (!trimmed)
|
|
22
|
+
continue;
|
|
23
|
+
const [modelId, deploymentName] = trimmed.split("=", 2);
|
|
24
|
+
if (!modelId || !deploymentName)
|
|
25
|
+
continue;
|
|
26
|
+
map.set(modelId.trim(), deploymentName.trim());
|
|
27
|
+
}
|
|
28
|
+
return map;
|
|
29
|
+
}
|
|
30
|
+
function resolveDeploymentName(model, options) {
|
|
31
|
+
if (options?.azureDeploymentName) {
|
|
32
|
+
return options.azureDeploymentName;
|
|
33
|
+
}
|
|
34
|
+
const mappedDeployment = parseDeploymentNameMap(process.env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(model.id);
|
|
35
|
+
return mappedDeployment || model.id;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generate function for Azure OpenAI Responses API
|
|
39
|
+
*/
|
|
40
|
+
export const streamAzureOpenAIResponses = (model, context, options) => {
|
|
41
|
+
const stream = new AssistantMessageEventStream();
|
|
42
|
+
// Start async processing
|
|
43
|
+
(async () => {
|
|
44
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
45
|
+
const output = {
|
|
46
|
+
role: "assistant",
|
|
47
|
+
content: [],
|
|
48
|
+
api: "azure-openai-responses",
|
|
49
|
+
provider: model.provider,
|
|
50
|
+
model: model.id,
|
|
51
|
+
usage: {
|
|
52
|
+
input: 0,
|
|
53
|
+
output: 0,
|
|
54
|
+
cacheRead: 0,
|
|
55
|
+
cacheWrite: 0,
|
|
56
|
+
totalTokens: 0,
|
|
57
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
58
|
+
},
|
|
59
|
+
stopReason: "stop",
|
|
60
|
+
timestamp: Date.now(),
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
// Create Azure OpenAI client
|
|
64
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
65
|
+
const client = createClient(model, apiKey, options);
|
|
66
|
+
const params = buildParams(model, context, options, deploymentName);
|
|
67
|
+
options?.onPayload?.(params);
|
|
68
|
+
const openaiStream = await client.responses.create(params, options?.signal ? { signal: options.signal } : undefined);
|
|
69
|
+
stream.push({ type: "start", partial: output });
|
|
70
|
+
await processResponsesStream(openaiStream, output, stream, model);
|
|
71
|
+
if (options?.signal?.aborted) {
|
|
72
|
+
throw new Error("Request was aborted");
|
|
73
|
+
}
|
|
74
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
75
|
+
throw new Error("An unknown error occurred");
|
|
76
|
+
}
|
|
77
|
+
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
78
|
+
stream.end();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
for (const block of output.content)
|
|
82
|
+
delete block.index;
|
|
83
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
84
|
+
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
85
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
86
|
+
stream.end();
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
return stream;
|
|
90
|
+
};
|
|
91
|
+
export const streamSimpleAzureOpenAIResponses = (model, context, options) => {
|
|
92
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
93
|
+
if (!apiKey) {
|
|
94
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
95
|
+
}
|
|
96
|
+
const base = buildBaseOptions(model, options, apiKey);
|
|
97
|
+
const reasoningEffort = supportsXhigh(model) ? options?.reasoning : clampReasoning(options?.reasoning);
|
|
98
|
+
return streamAzureOpenAIResponses(model, context, {
|
|
99
|
+
...base,
|
|
100
|
+
reasoningEffort,
|
|
101
|
+
toolChoice: options?.toolChoice,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
function normalizeAzureBaseUrl(baseUrl) {
|
|
105
|
+
return baseUrl.replace(/\/+$/, "");
|
|
106
|
+
}
|
|
107
|
+
function buildDefaultBaseUrl(resourceName) {
|
|
108
|
+
return `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
109
|
+
}
|
|
110
|
+
function resolveAzureConfig(model, options) {
|
|
111
|
+
const apiVersion = options?.azureApiVersion || process.env.AZURE_OPENAI_API_VERSION || DEFAULT_AZURE_API_VERSION;
|
|
112
|
+
const baseUrl = options?.azureBaseUrl?.trim() || process.env.AZURE_OPENAI_BASE_URL?.trim() || undefined;
|
|
113
|
+
const resourceName = options?.azureResourceName || process.env.AZURE_OPENAI_RESOURCE_NAME;
|
|
114
|
+
let resolvedBaseUrl = baseUrl;
|
|
115
|
+
if (!resolvedBaseUrl && resourceName) {
|
|
116
|
+
resolvedBaseUrl = buildDefaultBaseUrl(resourceName);
|
|
117
|
+
}
|
|
118
|
+
if (!resolvedBaseUrl && model.baseUrl) {
|
|
119
|
+
resolvedBaseUrl = model.baseUrl;
|
|
120
|
+
}
|
|
121
|
+
if (!resolvedBaseUrl) {
|
|
122
|
+
throw new Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
baseUrl: normalizeAzureBaseUrl(resolvedBaseUrl),
|
|
126
|
+
apiVersion,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function createClient(model, apiKey, options) {
|
|
130
|
+
if (!apiKey) {
|
|
131
|
+
if (!process.env.AZURE_OPENAI_API_KEY) {
|
|
132
|
+
throw new Error("Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
133
|
+
}
|
|
134
|
+
apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
135
|
+
}
|
|
136
|
+
const headers = { ...model.headers };
|
|
137
|
+
if (options?.headers) {
|
|
138
|
+
Object.assign(headers, options.headers);
|
|
139
|
+
}
|
|
140
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
141
|
+
return new AzureOpenAI({
|
|
142
|
+
apiKey,
|
|
143
|
+
apiVersion,
|
|
144
|
+
dangerouslyAllowBrowser: true,
|
|
145
|
+
defaultHeaders: headers,
|
|
146
|
+
baseURL: baseUrl,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function buildParams(model, context, options, deploymentName) {
|
|
150
|
+
const messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS);
|
|
151
|
+
const params = {
|
|
152
|
+
model: deploymentName,
|
|
153
|
+
input: messages,
|
|
154
|
+
stream: true,
|
|
155
|
+
prompt_cache_key: options?.sessionId,
|
|
156
|
+
};
|
|
157
|
+
if (options?.maxTokens) {
|
|
158
|
+
params.max_output_tokens = options?.maxTokens;
|
|
159
|
+
}
|
|
160
|
+
if (options?.temperature !== undefined) {
|
|
161
|
+
params.temperature = options?.temperature;
|
|
162
|
+
}
|
|
163
|
+
if (context.tools) {
|
|
164
|
+
params.tools = convertResponsesTools(context.tools);
|
|
165
|
+
}
|
|
166
|
+
if (options?.toolChoice !== undefined) {
|
|
167
|
+
params.tool_choice = options.toolChoice;
|
|
168
|
+
}
|
|
169
|
+
if (model.reasoning) {
|
|
170
|
+
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
171
|
+
params.reasoning = {
|
|
172
|
+
effort: options?.reasoningEffort || "medium",
|
|
173
|
+
summary: options?.reasoningSummary || "auto",
|
|
174
|
+
};
|
|
175
|
+
params.include = ["reasoning.encrypted_content"];
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if (model.name.toLowerCase().startsWith("gpt-5")) {
|
|
179
|
+
// Jesus Christ, see https://community.openai.com/t/need-reasoning-false-option-for-gpt-5/1351588/7
|
|
180
|
+
messages.push({
|
|
181
|
+
role: "developer",
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
type: "input_text",
|
|
185
|
+
text: "# Juice: 0 !important",
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return params;
|
|
193
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: inferCopilotInitiator, hasCopilotVisionInput, buildCopilotDynamicHeaders
|
|
3
|
+
* [FROM]: No external dependencies
|
|
4
|
+
* [TO]: Consumed by core/lib/ai/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/ai/src/providers/github-copilot-headers.ts -
|
|
6
|
+
*/
|
|
7
|
+
import type { Message } from "../types.js";
|
|
8
|
+
export declare function inferCopilotInitiator(messages: Message[]): "user" | "agent";
|
|
9
|
+
export declare function hasCopilotVisionInput(messages: Message[]): boolean;
|
|
10
|
+
export declare function buildCopilotDynamicHeaders(params: {
|
|
11
|
+
messages: Message[];
|
|
12
|
+
hasImages: boolean;
|
|
13
|
+
}): Record<string, string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: inferCopilotInitiator, hasCopilotVisionInput, buildCopilotDynamicHeaders
|
|
3
|
+
* [FROM]: No external dependencies
|
|
4
|
+
* [TO]: Consumed by core/lib/ai/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/ai/src/providers/github-copilot-headers.ts -
|
|
6
|
+
*/
|
|
7
|
+
// Copilot expects X-Initiator to indicate whether the request is user-initiated
|
|
8
|
+
// or agent-initiated (e.g. follow-up after assistant/tool messages).
|
|
9
|
+
export function inferCopilotInitiator(messages) {
|
|
10
|
+
const last = messages[messages.length - 1];
|
|
11
|
+
return last && last.role !== "user" ? "agent" : "user";
|
|
12
|
+
}
|
|
13
|
+
// Copilot requires Copilot-Vision-Request header when sending images
|
|
14
|
+
export function hasCopilotVisionInput(messages) {
|
|
15
|
+
return messages.some((msg) => {
|
|
16
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
17
|
+
return msg.content.some((c) => c.type === "image");
|
|
18
|
+
}
|
|
19
|
+
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
|
|
20
|
+
return msg.content.some((c) => c.type === "image");
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function buildCopilotDynamicHeaders(params) {
|
|
26
|
+
const headers = {
|
|
27
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
28
|
+
"Openai-Intent": "conversation-edits",
|
|
29
|
+
};
|
|
30
|
+
if (params.hasImages) {
|
|
31
|
+
headers["Copilot-Vision-Request"] = "true";
|
|
32
|
+
}
|
|
33
|
+
return headers;
|
|
34
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini CLI / Antigravity provider.
|
|
3
|
+
* Shared implementation for both google-gemini-cli and google-antigravity providers.
|
|
4
|
+
* Uses the Cloud Code Assist API endpoint to access Gemini and Claude models.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* [WHO]: GoogleGeminiCliOptions, extractRetryDelay, streamGoogleGeminiCli, streamSimpleGoogleGeminiCli, buildRequest
|
|
8
|
+
* [FROM]: Depends on ../models.js, ../utils/event-stream.js, ../utils/sanitize-unicode.js, ./simple-options.js
|
|
9
|
+
* [TO]: Consumed by core/lib/ai/src/index.ts
|
|
10
|
+
* [HERE]: core/lib/ai/src/providers/google-gemini-cli.ts -
|
|
11
|
+
*/
|
|
12
|
+
import type { Content, ThinkingConfig } from "@google/genai";
|
|
13
|
+
import type { Context, Model, SimpleStreamOptions, StreamFunction, StreamOptions } from "../types.js";
|
|
14
|
+
import { convertTools, mapToolChoice } from "./google-shared.js";
|
|
15
|
+
/**
|
|
16
|
+
* Thinking level for Gemini 3 models.
|
|
17
|
+
* Mirrors Google's ThinkingLevel enum values.
|
|
18
|
+
*/
|
|
19
|
+
export type GoogleThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
20
|
+
export interface GoogleGeminiCliOptions extends StreamOptions {
|
|
21
|
+
toolChoice?: "auto" | "none" | "any";
|
|
22
|
+
/**
|
|
23
|
+
* Thinking/reasoning configuration.
|
|
24
|
+
* - Gemini 2.x models: use `budgetTokens` to set the thinking budget
|
|
25
|
+
* - Gemini 3 models (gemini-3-pro-*, gemini-3-flash-*): use `level` instead
|
|
26
|
+
*
|
|
27
|
+
* When using `streamSimple`, this is handled automatically based on the model.
|
|
28
|
+
*/
|
|
29
|
+
thinking?: {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
/** Thinking budget in tokens. Use for Gemini 2.x models. */
|
|
32
|
+
budgetTokens?: number;
|
|
33
|
+
/** Thinking level. Use for Gemini 3 models (LOW/HIGH for Pro, MINIMAL/LOW/MEDIUM/HIGH for Flash). */
|
|
34
|
+
level?: GoogleThinkingLevel;
|
|
35
|
+
};
|
|
36
|
+
projectId?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extract retry delay from Gemini error response (in milliseconds).
|
|
40
|
+
* Checks headers first (Retry-After, x-ratelimit-reset, x-ratelimit-reset-after),
|
|
41
|
+
* then parses body patterns like:
|
|
42
|
+
* - "Your quota will reset after 39s"
|
|
43
|
+
* - "Your quota will reset after 18h31m10s"
|
|
44
|
+
* - "Please retry in Xs" or "Please retry in Xms"
|
|
45
|
+
* - "retryDelay": "34.074824224s" (JSON field)
|
|
46
|
+
*/
|
|
47
|
+
export declare function extractRetryDelay(errorText: string, response?: Response | Headers): number | undefined;
|
|
48
|
+
interface CloudCodeAssistRequest {
|
|
49
|
+
project: string;
|
|
50
|
+
model: string;
|
|
51
|
+
request: {
|
|
52
|
+
contents: Content[];
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
systemInstruction?: {
|
|
55
|
+
role?: string;
|
|
56
|
+
parts: {
|
|
57
|
+
text: string;
|
|
58
|
+
}[];
|
|
59
|
+
};
|
|
60
|
+
generationConfig?: {
|
|
61
|
+
maxOutputTokens?: number;
|
|
62
|
+
temperature?: number;
|
|
63
|
+
thinkingConfig?: ThinkingConfig;
|
|
64
|
+
};
|
|
65
|
+
tools?: ReturnType<typeof convertTools>;
|
|
66
|
+
toolConfig?: {
|
|
67
|
+
functionCallingConfig: {
|
|
68
|
+
mode: ReturnType<typeof mapToolChoice>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
requestType?: string;
|
|
73
|
+
userAgent?: string;
|
|
74
|
+
requestId?: string;
|
|
75
|
+
}
|
|
76
|
+
export declare const streamGoogleGeminiCli: StreamFunction<"google-gemini-cli", GoogleGeminiCliOptions>;
|
|
77
|
+
export declare const streamSimpleGoogleGeminiCli: StreamFunction<"google-gemini-cli", SimpleStreamOptions>;
|
|
78
|
+
export declare function buildRequest(model: Model<"google-gemini-cli">, context: Context, projectId: string, options?: GoogleGeminiCliOptions, isAntigravity?: boolean): CloudCodeAssistRequest;
|
|
79
|
+
export {};
|