@openclaw/ai 0.0.0 → 2026.7.1-2

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -3
  3. package/dist/anthropic-B5gZQM5X.mjs +1383 -0
  4. package/dist/api-registry-BXYnCOIR.d.mts +33 -0
  5. package/dist/azure-openai-responses-DNoSk8Uy.mjs +141 -0
  6. package/dist/azure-openai-responses-client-compat-a_O_GVQV.mjs +41 -0
  7. package/dist/diagnostics-BaTA9eVl.d.mts +25 -0
  8. package/dist/diagnostics-COpOtRwq.mjs +36 -0
  9. package/dist/diagnostics.d.mts +2 -0
  10. package/dist/diagnostics.mjs +2 -0
  11. package/dist/env-api-keys-CtMlqaQ4.mjs +171 -0
  12. package/dist/event-stream-0nZeBKl2.d.mts +26 -0
  13. package/dist/event-stream-ReMmOTzX.mjs +65 -0
  14. package/dist/event-stream.d.mts +2 -0
  15. package/dist/event-stream.mjs +2 -0
  16. package/dist/github-copilot-headers-BsH5cqGj.mjs +48 -0
  17. package/dist/google-D6sIQ1bL.mjs +55 -0
  18. package/dist/google-shared-ZPSl2qTi.mjs +548 -0
  19. package/dist/google-vertex-rDGwkoZK.mjs +111 -0
  20. package/dist/hash-CHgqbJmD.mjs +16 -0
  21. package/dist/headers-B_e4-1J0.mjs +9 -0
  22. package/dist/host-4t713IeR.mjs +37 -0
  23. package/dist/index-BoTnz8cv.d.mts +74 -0
  24. package/dist/index.d.mts +69 -0
  25. package/dist/index.mjs +7 -0
  26. package/dist/internal/anthropic.d.mts +234 -0
  27. package/dist/internal/anthropic.mjs +4 -0
  28. package/dist/internal/openai.d.mts +244 -0
  29. package/dist/internal/openai.mjs +7 -0
  30. package/dist/internal/runtime.d.mts +245 -0
  31. package/dist/internal/runtime.mjs +176 -0
  32. package/dist/internal/shared.d.mts +48 -0
  33. package/dist/internal/shared.mjs +3 -0
  34. package/dist/json-parse-DzNSIQBq.mjs +134 -0
  35. package/dist/llm-request-activity-CehVkZP-.mjs +35 -0
  36. package/dist/mistral-CePVNdws.mjs +563 -0
  37. package/dist/model-utils-DgmOla96.mjs +69 -0
  38. package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +39 -0
  39. package/dist/openai-chatgpt-responses-DVC4Bk_A.mjs +1068 -0
  40. package/dist/openai-completions-B9QLIq2U.mjs +844 -0
  41. package/dist/openai-responses-B6LylGxM.mjs +136 -0
  42. package/dist/openai-responses-shared-sj2YUPYc.mjs +1944 -0
  43. package/dist/openai-tool-projection-BknoV11q.mjs +195 -0
  44. package/dist/providers.d.mts +11 -0
  45. package/dist/providers.mjs +109 -0
  46. package/dist/reasoning-tag-text-partitioner-axhAdUwg.mjs +394 -0
  47. package/dist/sanitize-unicode-BZiVbGwK.d.mts +24 -0
  48. package/dist/sanitize-unicode-DT5o51ur.mjs +26 -0
  49. package/dist/src-CZ503MYJ.mjs +99 -0
  50. package/dist/stream-CREqxHgU.mjs +74 -0
  51. package/dist/stream-first-event-timeout-RjWszj8c.mjs +106 -0
  52. package/dist/streaming-byte-guard-BrbkbwUu.mjs +46 -0
  53. package/dist/tool-schema-json-projection-BXtBc_mD.mjs +74 -0
  54. package/dist/transform-messages-BhGF_fF4.mjs +507 -0
  55. package/dist/types-BVVgDSdq.d.mts +1 -0
  56. package/dist/types-DRgdPqaZ.d.mts +587 -0
  57. package/dist/types.d.mts +6 -0
  58. package/dist/types.mjs +5 -0
  59. package/dist/validation-BDMWOr8d.d.mts +9 -0
  60. package/dist/validation-FrchoOlv.mjs +199 -0
  61. package/dist/validation.d.mts +2 -0
  62. package/dist/validation.mjs +2 -0
  63. package/npm-shrinkwrap.json +645 -0
  64. package/package.json +74 -2
@@ -0,0 +1,136 @@
1
+ import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-CtMlqaQ4.mjs";
2
+ import { t as AssistantMessageEventStream } from "./event-stream-ReMmOTzX.mjs";
3
+ import { n as getAiTransportHost } from "./host-4t713IeR.mjs";
4
+ import { o as buildBaseOptions } from "./transform-messages-BhGF_fF4.mjs";
5
+ import { a as resolveCacheRetention, i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-BsH5cqGj.mjs";
6
+ import { a as resolveResponsesReasoningEffort, n as convertResponsesMessages, o as runResponsesStreamLifecycle, r as createResponsesAssistantOutput, t as applyCommonResponsesParams } from "./openai-responses-shared-sj2YUPYc.mjs";
7
+ import { a as clampOpenAIPromptCacheKey } from "./openai-tool-projection-BknoV11q.mjs";
8
+ import OpenAI from "openai";
9
+ //#region packages/ai/src/providers/openai-responses.ts
10
+ var openai_responses_exports = /* @__PURE__ */ __exportAll({
11
+ streamOpenAIResponses: () => streamOpenAIResponses,
12
+ streamSimpleOpenAIResponses: () => streamSimpleOpenAIResponses
13
+ });
14
+ const OPENAI_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
15
+ function getCompat(model) {
16
+ return {
17
+ sendSessionIdHeader: model.compat?.sendSessionIdHeader ?? true,
18
+ supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true
19
+ };
20
+ }
21
+ function getPromptCacheRetention(compat, cacheRetention) {
22
+ return cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0;
23
+ }
24
+ function formatOpenAIResponsesError(error) {
25
+ if (error instanceof Error) {
26
+ const status = error.status;
27
+ const statusCode = typeof status === "number" ? status : void 0;
28
+ if (statusCode !== void 0) return `OpenAI API error (${statusCode}): ${error.message}`;
29
+ return error.message;
30
+ }
31
+ try {
32
+ return JSON.stringify(error);
33
+ } catch {
34
+ return String(error);
35
+ }
36
+ }
37
+ /**
38
+ * Generate function for OpenAI Responses API
39
+ */
40
+ const streamOpenAIResponses = (model, context, options) => {
41
+ const stream = new AssistantMessageEventStream();
42
+ runResponsesStreamLifecycle({
43
+ stream,
44
+ model,
45
+ output: createResponsesAssistantOutput(model),
46
+ options,
47
+ createClient: () => {
48
+ const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
49
+ const cacheSessionId = resolveCacheRetention(options?.cacheRetention) === "none" ? void 0 : options?.sessionId;
50
+ return createClient(model, context, apiKey, options?.headers, cacheSessionId);
51
+ },
52
+ buildParams: () => buildParams(model, context, options),
53
+ processStreamOptions: {
54
+ serviceTier: options?.serviceTier,
55
+ applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model)
56
+ },
57
+ formatError: formatOpenAIResponsesError
58
+ });
59
+ return stream;
60
+ };
61
+ const streamSimpleOpenAIResponses = (model, context, options) => {
62
+ const apiKey = options?.apiKey || getEnvApiKey(model.provider);
63
+ if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
64
+ const base = buildBaseOptions(model, options, apiKey);
65
+ return streamOpenAIResponses(model, context, {
66
+ ...base,
67
+ reasoningEffort: resolveResponsesReasoningEffort(model, options?.reasoning),
68
+ replayResponsesItemIds: options?.replayResponsesItemIds
69
+ });
70
+ };
71
+ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
72
+ if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
73
+ const compat = getCompat(model);
74
+ const headers = { ...model.headers };
75
+ if (model.provider === "github-copilot") {
76
+ const hasImages = hasCopilotVisionInput(context.messages);
77
+ const copilotHeaders = buildCopilotDynamicHeaders({
78
+ messages: context.messages,
79
+ hasImages
80
+ });
81
+ Object.assign(headers, copilotHeaders);
82
+ }
83
+ if (sessionId) {
84
+ if (compat.sendSessionIdHeader) headers.session_id = sessionId;
85
+ headers["x-client-request-id"] = sessionId;
86
+ }
87
+ if (optionsHeaders) Object.assign(headers, optionsHeaders);
88
+ const defaultHeaders = model.provider === "cloudflare-ai-gateway" ? {
89
+ ...headers,
90
+ Authorization: headers.Authorization ?? null,
91
+ "cf-aig-authorization": `Bearer ${apiKey}`
92
+ } : headers;
93
+ return new OpenAI({
94
+ apiKey,
95
+ baseURL: isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl,
96
+ dangerouslyAllowBrowser: true,
97
+ defaultHeaders,
98
+ fetch: getAiTransportHost().buildModelFetch(model)
99
+ });
100
+ }
101
+ function buildParams(model, context, options) {
102
+ const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, { replayResponsesItemIds: options?.replayResponsesItemIds ?? false });
103
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention);
104
+ const compat = getCompat(model);
105
+ const params = {
106
+ model: model.id,
107
+ input: messages,
108
+ stream: true,
109
+ prompt_cache_key: cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId),
110
+ prompt_cache_retention: getPromptCacheRetention(compat, cacheRetention),
111
+ store: false
112
+ };
113
+ if (options?.maxTokens) params.max_output_tokens = options?.maxTokens;
114
+ if (options?.temperature !== void 0) params.temperature = options?.temperature;
115
+ if (options?.serviceTier !== void 0) params.service_tier = options.serviceTier;
116
+ applyCommonResponsesParams(params, model, context, options, { setDefaultReasoningOff: model.provider !== "github-copilot" });
117
+ return params;
118
+ }
119
+ function getServiceTierCostMultiplier(model, serviceTier) {
120
+ switch (serviceTier) {
121
+ case "flex": return .5;
122
+ case "priority": return model.id === "gpt-5.5" ? 2.5 : 2;
123
+ default: return 1;
124
+ }
125
+ }
126
+ function applyServiceTierPricing(usage, serviceTier, model) {
127
+ const multiplier = getServiceTierCostMultiplier(model, serviceTier);
128
+ if (multiplier === 1) return;
129
+ usage.cost.input *= multiplier;
130
+ usage.cost.output *= multiplier;
131
+ usage.cost.cacheRead *= multiplier;
132
+ usage.cost.cacheWrite *= multiplier;
133
+ usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
134
+ }
135
+ //#endregion
136
+ export { streamOpenAIResponses as n, streamSimpleOpenAIResponses as r, openai_responses_exports as t };