@mlightcad/cad-llm-plugin 0.0.0-stage → 1.8.0-preview.5

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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -2
  3. package/dist/cad-llm-plugin-register.js +613 -0
  4. package/dist/cad-llm-plugin-register.umd.cjs +1 -0
  5. package/dist/cad-llm-plugin.js +21481 -0
  6. package/dist/cad-llm-plugin.umd.cjs +514 -0
  7. package/lib/AcApLlmPlugin.d.ts +39 -0
  8. package/lib/AcApLlmPlugin.d.ts.map +1 -0
  9. package/lib/AcApLlmPlugin.js +119 -0
  10. package/lib/AcApLlmPlugin.js.map +1 -0
  11. package/lib/AcApLlmTextRecognizer.d.ts +43 -0
  12. package/lib/AcApLlmTextRecognizer.d.ts.map +1 -0
  13. package/lib/AcApLlmTextRecognizer.js +303 -0
  14. package/lib/AcApLlmTextRecognizer.js.map +1 -0
  15. package/lib/command/AcApLlmSettingsCmd.d.ts +16 -0
  16. package/lib/command/AcApLlmSettingsCmd.d.ts.map +1 -0
  17. package/lib/command/AcApLlmSettingsCmd.js +114 -0
  18. package/lib/command/AcApLlmSettingsCmd.js.map +1 -0
  19. package/lib/constants.d.ts +7 -0
  20. package/lib/constants.d.ts.map +1 -0
  21. package/lib/constants.js +7 -0
  22. package/lib/constants.js.map +1 -0
  23. package/lib/i18n/ar.d.ts +77 -0
  24. package/lib/i18n/ar.d.ts.map +1 -0
  25. package/lib/i18n/ar.js +77 -0
  26. package/lib/i18n/ar.js.map +1 -0
  27. package/lib/i18n/command.d.ts +30 -0
  28. package/lib/i18n/command.d.ts.map +1 -0
  29. package/lib/i18n/command.js +30 -0
  30. package/lib/i18n/command.js.map +1 -0
  31. package/lib/i18n/cs.d.ts +77 -0
  32. package/lib/i18n/cs.d.ts.map +1 -0
  33. package/lib/i18n/cs.js +77 -0
  34. package/lib/i18n/cs.js.map +1 -0
  35. package/lib/i18n/en.d.ts +82 -0
  36. package/lib/i18n/en.d.ts.map +1 -0
  37. package/lib/i18n/en.js +82 -0
  38. package/lib/i18n/en.js.map +1 -0
  39. package/lib/i18n/index.d.ts +29 -0
  40. package/lib/i18n/index.d.ts.map +1 -0
  41. package/lib/i18n/index.js +142 -0
  42. package/lib/i18n/index.js.map +1 -0
  43. package/lib/i18n/ja.d.ts +77 -0
  44. package/lib/i18n/ja.d.ts.map +1 -0
  45. package/lib/i18n/ja.js +77 -0
  46. package/lib/i18n/ja.js.map +1 -0
  47. package/lib/i18n/ko.d.ts +77 -0
  48. package/lib/i18n/ko.d.ts.map +1 -0
  49. package/lib/i18n/ko.js +77 -0
  50. package/lib/i18n/ko.js.map +1 -0
  51. package/lib/i18n/tr.d.ts +77 -0
  52. package/lib/i18n/tr.d.ts.map +1 -0
  53. package/lib/i18n/tr.js +77 -0
  54. package/lib/i18n/tr.js.map +1 -0
  55. package/lib/i18n/zh.d.ts +77 -0
  56. package/lib/i18n/zh.d.ts.map +1 -0
  57. package/lib/i18n/zh.js +77 -0
  58. package/lib/i18n/zh.js.map +1 -0
  59. package/lib/index.d.ts +25 -0
  60. package/lib/index.d.ts.map +1 -0
  61. package/lib/index.js +25 -0
  62. package/lib/index.js.map +1 -0
  63. package/lib/model/AcApLlmModelFactory.d.ts +14 -0
  64. package/lib/model/AcApLlmModelFactory.d.ts.map +1 -0
  65. package/lib/model/AcApLlmModelFactory.js +46 -0
  66. package/lib/model/AcApLlmModelFactory.js.map +1 -0
  67. package/lib/model/AcApLlmModelListing.d.ts +67 -0
  68. package/lib/model/AcApLlmModelListing.d.ts.map +1 -0
  69. package/lib/model/AcApLlmModelListing.js +275 -0
  70. package/lib/model/AcApLlmModelListing.js.map +1 -0
  71. package/lib/model/anthropicBrowserAccess.d.ts +8 -0
  72. package/lib/model/anthropicBrowserAccess.d.ts.map +1 -0
  73. package/lib/model/anthropicBrowserAccess.js +8 -0
  74. package/lib/model/anthropicBrowserAccess.js.map +1 -0
  75. package/lib/model/normalizeLlmBaseUrl.d.ts +17 -0
  76. package/lib/model/normalizeLlmBaseUrl.d.ts.map +1 -0
  77. package/lib/model/normalizeLlmBaseUrl.js +31 -0
  78. package/lib/model/normalizeLlmBaseUrl.js.map +1 -0
  79. package/lib/model/openAiCompatibleFetch.d.ts +11 -0
  80. package/lib/model/openAiCompatibleFetch.d.ts.map +1 -0
  81. package/lib/model/openAiCompatibleFetch.js +122 -0
  82. package/lib/model/openAiCompatibleFetch.js.map +1 -0
  83. package/lib/model/skipDataUrlDownload.d.ts +12 -0
  84. package/lib/model/skipDataUrlDownload.d.ts.map +1 -0
  85. package/lib/model/skipDataUrlDownload.js +58 -0
  86. package/lib/model/skipDataUrlDownload.js.map +1 -0
  87. package/lib/register.d.ts +20 -0
  88. package/lib/register.d.ts.map +1 -0
  89. package/lib/register.js +139 -0
  90. package/lib/register.js.map +1 -0
  91. package/lib/storage/AcApLlmConfigStore.d.ts +218 -0
  92. package/lib/storage/AcApLlmConfigStore.d.ts.map +1 -0
  93. package/lib/storage/AcApLlmConfigStore.js +637 -0
  94. package/lib/storage/AcApLlmConfigStore.js.map +1 -0
  95. package/lib/storage/AcApLlmModelCatalog.d.ts +68 -0
  96. package/lib/storage/AcApLlmModelCatalog.d.ts.map +1 -0
  97. package/lib/storage/AcApLlmModelCatalog.js +141 -0
  98. package/lib/storage/AcApLlmModelCatalog.js.map +1 -0
  99. package/lib/storage/apiKeyCrypto.d.ts +28 -0
  100. package/lib/storage/apiKeyCrypto.d.ts.map +1 -0
  101. package/lib/storage/apiKeyCrypto.js +214 -0
  102. package/lib/storage/apiKeyCrypto.js.map +1 -0
  103. package/lib/storage/settingsEquality.d.ts +10 -0
  104. package/lib/storage/settingsEquality.d.ts.map +1 -0
  105. package/lib/storage/settingsEquality.js +36 -0
  106. package/lib/storage/settingsEquality.js.map +1 -0
  107. package/lib/ui/AcApLlmModelChoices.d.ts +31 -0
  108. package/lib/ui/AcApLlmModelChoices.d.ts.map +1 -0
  109. package/lib/ui/AcApLlmModelChoices.js +68 -0
  110. package/lib/ui/AcApLlmModelChoices.js.map +1 -0
  111. package/lib/ui/AcApLlmProviderLabels.d.ts +19 -0
  112. package/lib/ui/AcApLlmProviderLabels.d.ts.map +1 -0
  113. package/lib/ui/AcApLlmProviderLabels.js +34 -0
  114. package/lib/ui/AcApLlmProviderLabels.js.map +1 -0
  115. package/lib/ui/AcUiLlmSettingsDialog.d.ts +125 -0
  116. package/lib/ui/AcUiLlmSettingsDialog.d.ts.map +1 -0
  117. package/lib/ui/AcUiLlmSettingsDialog.js +1218 -0
  118. package/lib/ui/AcUiLlmSettingsDialog.js.map +1 -0
  119. package/lib/ui/llmSettingsStyles.d.ts +6 -0
  120. package/lib/ui/llmSettingsStyles.d.ts.map +1 -0
  121. package/lib/ui/llmSettingsStyles.js +6 -0
  122. package/lib/ui/llmSettingsStyles.js.map +1 -0
  123. package/package.json +54 -3
@@ -0,0 +1,275 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ };
36
+ var __generator = (this && this.__generator) || function (thisArg, body) {
37
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
38
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
+ function verb(n) { return function (v) { return step([n, v]); }; }
40
+ function step(op) {
41
+ if (f) throw new TypeError("Generator is already executing.");
42
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
43
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
44
+ if (y = 0, t) op = [op[0] & 2, t.value];
45
+ switch (op[0]) {
46
+ case 0: case 1: t = op; break;
47
+ case 4: _.label++; return { value: op[1], done: false };
48
+ case 5: _.label++; y = op[1]; op = [0]; continue;
49
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
+ default:
51
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
+ if (t[2]) _.ops.pop();
56
+ _.trys.pop(); continue;
57
+ }
58
+ op = body.call(thisArg, _);
59
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
+ }
62
+ };
63
+ var __values = (this && this.__values) || function(o) {
64
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
65
+ if (m) return m.call(o);
66
+ if (o && typeof o.length === "number") return {
67
+ next: function () {
68
+ if (o && i >= o.length) o = void 0;
69
+ return { value: o && o[i++], done: !o };
70
+ }
71
+ };
72
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
73
+ };
74
+ var __read = (this && this.__read) || function (o, n) {
75
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
76
+ if (!m) return o;
77
+ var i = m.call(o), r, ar = [], e;
78
+ try {
79
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
80
+ }
81
+ catch (error) { e = { error: error }; }
82
+ finally {
83
+ try {
84
+ if (r && !r.done && (m = i["return"])) m.call(i);
85
+ }
86
+ finally { if (e) throw e.error; }
87
+ }
88
+ return ar;
89
+ };
90
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
91
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
92
+ if (ar || !(i in from)) {
93
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
94
+ ar[i] = from[i];
95
+ }
96
+ }
97
+ return to.concat(ar || Array.prototype.slice.call(from));
98
+ };
99
+ import { ACAP_LLM_ANTHROPIC_BROWSER_ACCESS_HEADER } from './anthropicBrowserAccess.js';
100
+ import { acapLlmNormalizeBaseUrl } from './normalizeLlmBaseUrl.js';
101
+ /** Failure of {@link acapLlmFetchAvailableModels}, carrying a UI-localizable code. */
102
+ var AcApLlmModelListingError = /** @class */ (function (_super) {
103
+ __extends(AcApLlmModelListingError, _super);
104
+ /**
105
+ * @param code - Failure category.
106
+ * @param url - Listing URL that was requested.
107
+ * @param status - HTTP status for `http` failures.
108
+ */
109
+ function AcApLlmModelListingError(code, url, status) {
110
+ var _this = _super.call(this, "Model listing failed (".concat(code, ") at ").concat(url)) || this;
111
+ _this.code = code;
112
+ _this.url = url;
113
+ _this.status = status;
114
+ _this.name = 'AcApLlmModelListingError';
115
+ return _this;
116
+ }
117
+ return AcApLlmModelListingError;
118
+ }(Error));
119
+ export { AcApLlmModelListingError };
120
+ /** Stable API version required by Anthropic's model-listing endpoint. */
121
+ var ANTHROPIC_VERSION = '2023-06-01';
122
+ /** Largest page Anthropic's listing accepts; one page is read. */
123
+ var ANTHROPIC_MODEL_LIMIT = 1000;
124
+ /**
125
+ * Builds the listing URL for a protocol.
126
+ *
127
+ * OpenAI protocols list at `{baseURL}/models`. Anthropic lists at
128
+ * `{root}/v1/models`, where the root is the base URL without one trailing
129
+ * `/v1`, because gateways document both spellings of the same root.
130
+ *
131
+ * @param baseUrl - Base URL from the form.
132
+ * @param protocol - Wire protocol.
133
+ * @returns Listing URL.
134
+ */
135
+ export function acapLlmModelListingUrl(baseUrl, protocol) {
136
+ var _a;
137
+ var base = (_a = acapLlmNormalizeBaseUrl(baseUrl)) !== null && _a !== void 0 ? _a : '';
138
+ if (protocol !== 'anthropic-messages')
139
+ return "".concat(base, "/models");
140
+ var root = base.endsWith('/v1') ? base.slice(0, -3) : base;
141
+ return "".concat(root, "/v1/models?limit=").concat(ANTHROPIC_MODEL_LIMIT);
142
+ }
143
+ /** Returns the first non-empty string among the candidates. */
144
+ function firstString() {
145
+ var e_1, _a;
146
+ var candidates = [];
147
+ for (var _i = 0; _i < arguments.length; _i++) {
148
+ candidates[_i] = arguments[_i];
149
+ }
150
+ try {
151
+ for (var candidates_1 = __values(candidates), candidates_1_1 = candidates_1.next(); !candidates_1_1.done; candidates_1_1 = candidates_1.next()) {
152
+ var candidate = candidates_1_1.value;
153
+ if (typeof candidate === 'string' && candidate.trim())
154
+ return candidate;
155
+ }
156
+ }
157
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
158
+ finally {
159
+ try {
160
+ if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
161
+ }
162
+ finally { if (e_1) throw e_1.error; }
163
+ }
164
+ return undefined;
165
+ }
166
+ /**
167
+ * Parses a model-listing reply.
168
+ *
169
+ * Accepts the standard `{ data: [...] }` array and the `{ models: { id: {...} } }`
170
+ * map some gateways expose. Entries without a usable id are skipped and
171
+ * duplicate ids are collapsed.
172
+ *
173
+ * @param body - Parsed JSON reply.
174
+ * @returns Discovered models in listing order.
175
+ * @throws {@link AcApLlmModelListingError} with code `format` for other shapes.
176
+ */
177
+ export function acapLlmParseModelListing(body, url) {
178
+ var e_2, _a;
179
+ if (url === void 0) { url = ''; }
180
+ var listing = body;
181
+ var entries;
182
+ if (Array.isArray(listing === null || listing === void 0 ? void 0 : listing.data)) {
183
+ entries = listing.data.map(function (raw) { return ({ raw: raw }); });
184
+ }
185
+ else if ((listing === null || listing === void 0 ? void 0 : listing.models) &&
186
+ typeof listing.models === 'object' &&
187
+ !Array.isArray(listing.models)) {
188
+ entries = Object.entries(listing.models)
189
+ .filter(function (_a) {
190
+ var _b = __read(_a, 2), raw = _b[1];
191
+ return !!raw && typeof raw === 'object';
192
+ })
193
+ .map(function (_a) {
194
+ var _b = __read(_a, 2), key = _b[0], raw = _b[1];
195
+ return ({ key: key, raw: raw });
196
+ });
197
+ }
198
+ else {
199
+ throw new AcApLlmModelListingError('format', url);
200
+ }
201
+ var models = new Map();
202
+ try {
203
+ for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
204
+ var _b = entries_1_1.value, key = _b.key, raw = _b.raw;
205
+ var entry = (raw !== null && raw !== void 0 ? raw : {});
206
+ var id = firstString(key, entry.id);
207
+ if (!id || models.has(id))
208
+ continue;
209
+ var name_1 = firstString(entry.name, entry.display_name, entry.displayName);
210
+ models.set(id, name_1 && name_1 !== id ? { id: id, name: name_1 } : { id: id });
211
+ }
212
+ }
213
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
214
+ finally {
215
+ try {
216
+ if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
217
+ }
218
+ finally { if (e_2) throw e_2.error; }
219
+ }
220
+ return __spreadArray([], __read(models.values()), false);
221
+ }
222
+ /**
223
+ * Asks a provider which models it serves, using the values currently in the
224
+ * settings form so a provider can be set up in one pass.
225
+ *
226
+ * @param target - Protocol, base URL and API key.
227
+ * @param fetchImpl - Fetch implementation (injectable for tests).
228
+ * @param signal - Optional abort signal.
229
+ * @returns Discovered models.
230
+ * @throws {@link AcApLlmModelListingError} on network, HTTP or format failures.
231
+ */
232
+ export function acapLlmFetchAvailableModels(target_1) {
233
+ return __awaiter(this, arguments, void 0, function (target, fetchImpl, signal) {
234
+ var url, apiKey, headers, response, error_1, body, _a;
235
+ if (fetchImpl === void 0) { fetchImpl = globalThis.fetch.bind(globalThis); }
236
+ return __generator(this, function (_b) {
237
+ switch (_b.label) {
238
+ case 0:
239
+ url = acapLlmModelListingUrl(target.baseUrl, target.protocol);
240
+ apiKey = target.apiKey.trim();
241
+ headers = target.protocol === 'anthropic-messages'
242
+ ? __assign({ 'x-api-key': apiKey, 'anthropic-version': ANTHROPIC_VERSION }, ACAP_LLM_ANTHROPIC_BROWSER_ACCESS_HEADER) : { Authorization: "Bearer ".concat(apiKey) };
243
+ _b.label = 1;
244
+ case 1:
245
+ _b.trys.push([1, 3, , 4]);
246
+ return [4 /*yield*/, fetchImpl(url, { method: 'GET', headers: headers, signal: signal })];
247
+ case 2:
248
+ response = _b.sent();
249
+ return [3 /*break*/, 4];
250
+ case 3:
251
+ error_1 = _b.sent();
252
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
253
+ throw error_1;
254
+ // Browsers report CORS refusals and unreachable hosts identically.
255
+ throw new AcApLlmModelListingError('network', url);
256
+ case 4:
257
+ if (!response.ok) {
258
+ throw new AcApLlmModelListingError('http', url, response.status);
259
+ }
260
+ _b.label = 5;
261
+ case 5:
262
+ _b.trys.push([5, 7, , 8]);
263
+ return [4 /*yield*/, response.json()];
264
+ case 6:
265
+ body = _b.sent();
266
+ return [3 /*break*/, 8];
267
+ case 7:
268
+ _a = _b.sent();
269
+ throw new AcApLlmModelListingError('format', url);
270
+ case 8: return [2 /*return*/, acapLlmParseModelListing(body, url)];
271
+ }
272
+ });
273
+ });
274
+ }
275
+ //# sourceMappingURL=AcApLlmModelListing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApLlmModelListing.js","sourceRoot":"","sources":["../../src/model/AcApLlmModelListing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,wCAAwC,EAAE,MAAM,6BAA6B,CAAA;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAuBlE,sFAAsF;AACtF;IAA8C,4CAAK;IACjD;;;;OAIG;IACH,kCACW,IAAkC,EAClC,GAAW,EACX,MAAe;QAExB,YAAA,MAAK,YAAC,gCAAyB,IAAI,kBAAQ,GAAG,CAAE,CAAC,SAAA;QAJxC,UAAI,GAAJ,IAAI,CAA8B;QAClC,SAAG,GAAH,GAAG,CAAQ;QACX,YAAM,GAAN,MAAM,CAAS;QAGxB,KAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;;IACxC,CAAC;IACH,+BAAC;AAAD,CAAC,AAdD,CAA8C,KAAK,GAclD;;AAED,yEAAyE;AACzE,IAAM,iBAAiB,GAAG,YAAY,CAAA;AAEtC,kEAAkE;AAClE,IAAM,qBAAqB,GAAG,IAAI,CAAA;AAElC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,QAA4B;;IAE5B,IAAM,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AI,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;wBAEnD,sBAAO,wBAAwB,CAAC,IAAI,EAAE,GAAG,CAAC,EAAA;;;;CAC3C"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Header Anthropic requires before it answers a request made from a browser
3
+ * page; without it the CORS preflight is rejected.
4
+ */
5
+ export declare const ACAP_LLM_ANTHROPIC_BROWSER_ACCESS_HEADER: {
6
+ readonly 'anthropic-dangerous-direct-browser-access': "true";
7
+ };
8
+ //# sourceMappingURL=anthropicBrowserAccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropicBrowserAccess.d.ts","sourceRoot":"","sources":["../../src/model/anthropicBrowserAccess.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,wCAAwC;;CAE3C,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Header Anthropic requires before it answers a request made from a browser
3
+ * page; without it the CORS preflight is rejected.
4
+ */
5
+ export var ACAP_LLM_ANTHROPIC_BROWSER_ACCESS_HEADER = {
6
+ 'anthropic-dangerous-direct-browser-access': 'true'
7
+ };
8
+ //# sourceMappingURL=anthropicBrowserAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropicBrowserAccess.js","sourceRoot":"","sources":["../../src/model/anthropicBrowserAccess.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,IAAM,wCAAwC,GAAG;IACtD,2CAA2C,EAAE,MAAM;CAC3C,CAAA"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Normalizes a user-entered LLM base URL for AI SDK providers.
3
+ *
4
+ * Provider SDKs append paths such as `/messages` or `/chat/completions` to
5
+ * the base URL. Official defaults include `/v1` (e.g.
6
+ * `https://api.anthropic.com/v1`). Gateways like OneAPI/NewAPI expose the
7
+ * same paths under `/v1`, but users often paste only the host
8
+ * (`https://ai-api.example.com`). Without `/v1`, the browser hits a
9
+ * non-API route that typically lacks CORS headers and surfaces as
10
+ * "Failed to fetch".
11
+ *
12
+ * @param baseUrl - Raw base URL from settings (may be empty).
13
+ * @returns Trimmed URL with `/v1` appended when the path is empty, or
14
+ * `undefined` when the input is blank.
15
+ */
16
+ export declare function acapLlmNormalizeBaseUrl(baseUrl: string): string | undefined;
17
+ //# sourceMappingURL=normalizeLlmBaseUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeLlmBaseUrl.d.ts","sourceRoot":"","sources":["../../src/model/normalizeLlmBaseUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa3E"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Normalizes a user-entered LLM base URL for AI SDK providers.
3
+ *
4
+ * Provider SDKs append paths such as `/messages` or `/chat/completions` to
5
+ * the base URL. Official defaults include `/v1` (e.g.
6
+ * `https://api.anthropic.com/v1`). Gateways like OneAPI/NewAPI expose the
7
+ * same paths under `/v1`, but users often paste only the host
8
+ * (`https://ai-api.example.com`). Without `/v1`, the browser hits a
9
+ * non-API route that typically lacks CORS headers and surfaces as
10
+ * "Failed to fetch".
11
+ *
12
+ * @param baseUrl - Raw base URL from settings (may be empty).
13
+ * @returns Trimmed URL with `/v1` appended when the path is empty, or
14
+ * `undefined` when the input is blank.
15
+ */
16
+ export function acapLlmNormalizeBaseUrl(baseUrl) {
17
+ var trimmed = baseUrl.trim().replace(/\/+$/, '');
18
+ if (!trimmed)
19
+ return undefined;
20
+ try {
21
+ var parsed = new URL(trimmed);
22
+ if (!parsed.pathname || parsed.pathname === '/') {
23
+ return "".concat(trimmed, "/v1");
24
+ }
25
+ return trimmed;
26
+ }
27
+ catch (_a) {
28
+ return trimmed;
29
+ }
30
+ }
31
+ //# sourceMappingURL=normalizeLlmBaseUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeLlmBaseUrl.js","sourceRoot":"","sources":["../../src/model/normalizeLlmBaseUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAClD,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAE9B,IAAI,CAAC;QACH,IAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;YAChD,OAAO,UAAG,OAAO,QAAK,CAAA;QACxB,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Wraps `fetch` so OpenAI-compatible providers accept AI SDK 5 request bodies.
3
+ *
4
+ * AI SDK 5 may emit `developer` roles for system prompts on chat models.
5
+ * Most OpenAI-compatible APIs (DeepSeek, etc.) only accept `system`.
6
+ *
7
+ * @param baseFetch - Underlying fetch implementation (defaults to `globalThis.fetch`).
8
+ * @returns A fetch function that normalizes message roles before sending.
9
+ */
10
+ export declare function acapLlmCreateOpenAiCompatibleFetch(baseFetch?: typeof fetch): typeof fetch;
11
+ //# sourceMappingURL=openAiCompatibleFetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAiCompatibleFetch.d.ts","sourceRoot":"","sources":["../../src/model/openAiCompatibleFetch.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAChD,SAAS,GAAE,OAAO,KAAyC,GAC1D,OAAO,KAAK,CA4Bd"}
@@ -0,0 +1,122 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __values = (this && this.__values) || function(o) {
49
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
50
+ if (m) return m.call(o);
51
+ if (o && typeof o.length === "number") return {
52
+ next: function () {
53
+ if (o && i >= o.length) o = void 0;
54
+ return { value: o && o[i++], done: !o };
55
+ }
56
+ };
57
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
+ };
59
+ /**
60
+ * Rewrites `developer` roles to `system` in place for OpenAI-compatible APIs.
61
+ *
62
+ * @param items - Message array from a chat request body, if present.
63
+ */
64
+ function convertDeveloperRoles(items) {
65
+ var e_1, _a;
66
+ if (!items)
67
+ return;
68
+ try {
69
+ for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
70
+ var item = items_1_1.value;
71
+ if (item.role === 'developer') {
72
+ item.role = 'system';
73
+ }
74
+ }
75
+ }
76
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
+ finally {
78
+ try {
79
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
80
+ }
81
+ finally { if (e_1) throw e_1.error; }
82
+ }
83
+ }
84
+ /**
85
+ * Wraps `fetch` so OpenAI-compatible providers accept AI SDK 5 request bodies.
86
+ *
87
+ * AI SDK 5 may emit `developer` roles for system prompts on chat models.
88
+ * Most OpenAI-compatible APIs (DeepSeek, etc.) only accept `system`.
89
+ *
90
+ * @param baseFetch - Underlying fetch implementation (defaults to `globalThis.fetch`).
91
+ * @returns A fetch function that normalizes message roles before sending.
92
+ */
93
+ export function acapLlmCreateOpenAiCompatibleFetch(baseFetch) {
94
+ var _this = this;
95
+ if (baseFetch === void 0) { baseFetch = globalThis.fetch.bind(globalThis); }
96
+ return function (input, init) { return __awaiter(_this, void 0, void 0, function () {
97
+ var body;
98
+ return __generator(this, function (_a) {
99
+ if (!(init === null || init === void 0 ? void 0 : init.body) || typeof init.body !== 'string') {
100
+ return [2 /*return*/, baseFetch(input, init)];
101
+ }
102
+ // Vision requests embed multi-MB base64 images. Skip JSON parse/stringify
103
+ // when there is nothing to rewrite — re-serializing stalls the main thread
104
+ // and leaves the chat stuck in `submitted` with no tokens.
105
+ if (!init.body.includes('"role":"developer"') &&
106
+ !init.body.includes('"role": "developer"')) {
107
+ return [2 /*return*/, baseFetch(input, init)];
108
+ }
109
+ try {
110
+ body = JSON.parse(init.body);
111
+ convertDeveloperRoles(body.messages);
112
+ convertDeveloperRoles(body.input);
113
+ return [2 /*return*/, baseFetch(input, __assign(__assign({}, init), { body: JSON.stringify(body) }))];
114
+ }
115
+ catch (_b) {
116
+ return [2 /*return*/, baseFetch(input, init)];
117
+ }
118
+ return [2 /*return*/];
119
+ });
120
+ }); };
121
+ }
122
+ //# sourceMappingURL=openAiCompatibleFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAiCompatibleFetch.js","sourceRoot":"","sources":["../../src/model/openAiCompatibleFetch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,KAAgC;;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAM;;QAClB,KAAmB,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;YAAtB,IAAM,IAAI,kBAAA;YACb,IAAI,IAAI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import { type Experimental_DownloadFunction } from 'ai';
2
+ /**
3
+ * AI SDK download hook that leaves `data:` URLs inline.
4
+ *
5
+ * OpenAI-compatible providers only declare `https?` in `supportedUrls`, so the
6
+ * default downloader would `fetch` every attached image data URL before the
7
+ * request. That is redundant (the SDK already splits data URLs) and can stall
8
+ * or fail on large vision payloads. Returning `null` passes the URL through
9
+ * for inline base64 handling.
10
+ */
11
+ export declare const acapLlmSkipDataUrlDownload: Experimental_DownloadFunction;
12
+ //# sourceMappingURL=skipDataUrlDownload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipDataUrlDownload.d.ts","sourceRoot":"","sources":["../../src/model/skipDataUrlDownload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,6BAA6B,EAAE,MAAM,IAAI,CAAA;AAIvE;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,EAAE,6BASpC,CAAA"}
@@ -0,0 +1,58 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { createDownload } from 'ai';
38
+ var downloadRemote = createDownload();
39
+ /**
40
+ * AI SDK download hook that leaves `data:` URLs inline.
41
+ *
42
+ * OpenAI-compatible providers only declare `https?` in `supportedUrls`, so the
43
+ * default downloader would `fetch` every attached image data URL before the
44
+ * request. That is redundant (the SDK already splits data URLs) and can stall
45
+ * or fail on large vision payloads. Returning `null` passes the URL through
46
+ * for inline base64 handling.
47
+ */
48
+ export var acapLlmSkipDataUrlDownload = function (requested) {
49
+ return Promise.all(requested.map(function (req) { return __awaiter(void 0, void 0, void 0, function () {
50
+ return __generator(this, function (_a) {
51
+ if (req.isUrlSupportedByModel || req.url.protocol === 'data:') {
52
+ return [2 /*return*/, null];
53
+ }
54
+ return [2 /*return*/, downloadRemote({ url: req.url })];
55
+ });
56
+ }); }));
57
+ };
58
+ //# sourceMappingURL=skipDataUrlDownload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipDataUrlDownload.js","sourceRoot":"","sources":["../../src/model/skipDataUrlDownload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAsC,MAAM,IAAI,CAAA;AAEvE,IAAM,cAAc,GAAG,cAAc,EAAE,CAAA;AAEvC;;;;;;;;GAQG;AACH,MAAM,CAAC,IAAM,0BAA0B,GACrC,UAAA,SAAS;IACP,OAAA,OAAO,CAAC,GAAG,CACT,SAAS,CAAC,GAAG,CAAC,UAAM,GAAG;;YACrB,IAAI,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC9D,sBAAO,IAAI,EAAA;YACb,CAAC;YACD,sBAAO,cAAc,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAA;;SACxC,CAAC,CACH;AAPD,CAOC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { type AcApPluginManager } from '@mlightcad/cad-simple-viewer';
2
+ /**
3
+ * Registers the shared AI model settings for lazy loading:
4
+ *
5
+ * - the `llmsettings` command,
6
+ * - the settings dialog in `AcApLlmSettingsService`, so any feature (CAD
7
+ * agent, PDF text recognition, ...) can open it or check what is
8
+ * configured,
9
+ * - the LLM text recognizer in `AcApTextRecognitionService`, used by `pdftext`
10
+ * when a vision-capable model is configured.
11
+ *
12
+ * Import from `@mlightcad/cad-llm-plugin/register` so the main bundle (which
13
+ * includes the AI SDK) stays out of the application entry chunk.
14
+ *
15
+ * @param pluginManager - Plugin manager that receives the lazy registration.
16
+ */
17
+ export declare function registerLazyLlmPlugin(pluginManager: AcApPluginManager): void;
18
+ export { LLM_PLUGIN_NAME, LLM_PLUGIN_TRIGGERS, LLM_SERVICE_ID } from './constants.js';
19
+ export { type AcApLlmLabelKey, llmT, mergeLlmI18nIntoVueI18n, registerLlmI18n } from './i18n/index.js';
20
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,8BAA8B,CAAA;AAYrC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,iBAAiB,GAAG,IAAI,CA8B5E;AAED,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,EACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,KAAK,eAAe,EACpB,IAAI,EACJ,uBAAuB,EACvB,eAAe,EAChB,MAAM,iBAAiB,CAAA"}