buckyos 0.7.208 → 0.7.209

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 (49) hide show
  1. package/cli/dist/cli.mjs +602 -179
  2. package/cli/dist/cli.mjs.map +1 -1
  3. package/cli/modules/ai.ts +460 -23
  4. package/cli/modules/aiws.ts +1 -1
  5. package/cli/version.ts +1 -1
  6. package/dist/{aicc-67851c41.mjs → aicc-286ba457.mjs} +7 -5
  7. package/dist/aicc-286ba457.mjs.map +1 -0
  8. package/dist/aicc-342f2659.js +2 -0
  9. package/dist/aicc-342f2659.js.map +1 -0
  10. package/dist/aicc_client.d.ts +623 -288
  11. package/dist/aicc_client.d.ts.map +1 -1
  12. package/dist/{aiws_write-83ddc6cc.mjs → aiws_write-5b542439.mjs} +203 -134
  13. package/dist/aiws_write-5b542439.mjs.map +1 -0
  14. package/dist/aiws_write-a0769003.js +13 -0
  15. package/dist/aiws_write-a0769003.js.map +1 -0
  16. package/dist/browser.cjs +1 -1
  17. package/dist/browser.mjs +85 -78
  18. package/dist/{content_objid-76434848.mjs → content_objid-09031ce1.mjs} +2 -2
  19. package/dist/{content_objid-76434848.mjs.map → content_objid-09031ce1.mjs.map} +1 -1
  20. package/dist/{content_objid-addf9e2b.js → content_objid-6342d0ba.js} +2 -2
  21. package/dist/{content_objid-addf9e2b.js.map → content_objid-6342d0ba.js.map} +1 -1
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.mjs +85 -78
  24. package/dist/node.cjs +1 -1
  25. package/dist/node.mjs +84 -77
  26. package/dist/{openai-ae2978de.mjs → openai-1c0d8341.mjs} +2 -2
  27. package/dist/{openai-ae2978de.mjs.map → openai-1c0d8341.mjs.map} +1 -1
  28. package/dist/{openai-f560d518.js → openai-7aa4ffbf.js} +2 -2
  29. package/dist/{openai-f560d518.js.map → openai-7aa4ffbf.js.map} +1 -1
  30. package/dist/{site_manager-604ee369.mjs → site_manager-4f1940eb.mjs} +4 -4
  31. package/dist/{site_manager-604ee369.mjs.map → site_manager-4f1940eb.mjs.map} +1 -1
  32. package/dist/{site_manager-70710895.js → site_manager-ca22ffbd.js} +2 -2
  33. package/dist/{site_manager-70710895.js.map → site_manager-ca22ffbd.js.map} +1 -1
  34. package/dist/xllm/core/run.d.ts.map +1 -1
  35. package/dist/xllm/providers/aicc.d.ts +7 -3
  36. package/dist/xllm/providers/aicc.d.ts.map +1 -1
  37. package/dist/xllm.cjs +1 -1
  38. package/dist/xllm.mjs +4 -4
  39. package/dist/xllm_deno.cjs +1 -1
  40. package/dist/xllm_deno.mjs +3 -3
  41. package/dist/xllm_dev.cjs +1 -1
  42. package/dist/xllm_dev.mjs +2 -2
  43. package/package.json +1 -1
  44. package/dist/aicc-67851c41.mjs.map +0 -1
  45. package/dist/aicc-ccb36ef7.js +0 -2
  46. package/dist/aicc-ccb36ef7.js.map +0 -1
  47. package/dist/aiws_write-825bb6ba.js +0 -13
  48. package/dist/aiws_write-825bb6ba.js.map +0 -1
  49. package/dist/aiws_write-83ddc6cc.mjs.map +0 -1
package/dist/node.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as createSDKModule } from "./aiws_write-83ddc6cc.mjs";
2
- import { ac, aO, bJ, aT, bK, bP, bO, bL, bN, bQ, bM, bH, bI, bG, af, aU, ap, ao, aq, ar, aW, aV, aY, aX, bX, cp, cf, cg, cb, cc, cd, ce, ch, g, B, cj, ci, cn, cl, l, cD, cC, cB, cA, a4, a3, a2, a1, bk, aj, ab, aE, E, cE, cH, cF, a0, aD, aP, ak, c5, c4, t, M, C, D, z, x, w, H, G, N, F, y, A, aQ, aR, aC, m, R, aF, bo, S, b4, b3, b2, b7, b5, b1, aZ, a_, b6, a$, b8, b0, az, aA, ay, b9, aB, aS, bl, bi, bn, bp, bd, bm, bq, bh, be, bg, a7, a6, V, W, a5, aM, aI, aN, aG, aK, aL, br, aH, aJ, bF, by, bs, bB, bw, bA, bv, bt, bx, bz, bE, bD, bC, bu, Z, ae, cq, bV, bU, bR, bT, _, c8, c6, co, bj, b, f, an, cJ, Y, cV, ax, a8, a9, c9, e, bY, ck, cy, cG, cN, cI, i, k, j, h, cx, cv, ai, ah, L, bS, q, I, bf, aa, at, as, cw, aw, u, v, cW, cT, U, a, d, n, al, P, K, J, X, T, cz, cO, ad, c7, ca, au, ag, p, b$, o, cs, O, av, cS, r, ct, cU, s, cr, cu, cM, cK, cL, bc, ba, bb, cP, cR, cQ, bW, b_, bZ, Q, c2, c1, c0, c3, $, cm, am } from "./aiws_write-83ddc6cc.mjs";
1
+ import { c as createSDKModule } from "./aiws_write-5b542439.mjs";
2
+ import { ac, aO, bJ, bO, bX, aT, bV, bW, bK, bR, bQ, bL, bP, bM, bS, bN, bH, bI, bG, af, aU, ap, ao, aq, ar, aW, aV, aY, aX, c2, cw, cm, cn, ci, cj, ck, cl, co, g, B, cq, cp, cu, cs, l, cK, cJ, cI, cH, a4, a3, a2, a1, bk, aj, ab, aE, E, cL, cO, cM, a0, aD, aP, ak, cc, cb, t, M, C, D, z, x, w, H, G, N, F, y, A, aQ, aR, bU, aC, m, R, aF, bo, S, b4, b3, b2, b7, b5, b1, aZ, a_, b6, a$, b8, b0, az, aA, ay, b9, aB, aS, bl, bi, bn, bp, bd, bm, bq, bh, be, bg, a7, a6, V, W, a5, aM, aI, aN, aG, aK, aL, br, aH, aJ, bF, by, bs, bB, bw, bA, bv, bt, bx, bz, bE, bD, bC, bu, Z, ae, cx, c0, b$, bT, b_, _, cf, cd, cv, bj, b, f, an, cQ, Y, d0, ax, a8, a9, cg, e, c3, cr, cF, cN, cU, cP, i, k, j, h, cE, cC, ai, ah, L, bZ, bY, q, I, bf, aa, at, as, cD, aw, u, v, d1, c_, U, a, d, n, al, P, K, J, X, T, cG, cV, ad, ce, ch, au, ag, p, c6, o, cz, O, av, cZ, r, cA, c$, s, cy, cB, cT, cR, cS, bc, ba, bb, cW, cY, cX, c1, c5, c4, Q, c9, c8, c7, ca, $, ct, am } from "./aiws_write-5b542439.mjs";
3
3
  import { h as h2 } from "./account-7a7bde6f.mjs";
4
4
  import { a as a10, D as D2, N as N2, r as r2, q as q2, g as g2, j as j2, f as f2, c, e as e2, b as b10, d as d2, k as k2, h as h3, i as i2, n as n2, o as o2, m as m2, l as l2, p as p2 } from "./ndn_types-0fac2499.mjs";
5
5
  import { APP_OPEN_ACTION, appWindowId, formatAppOpenUrl, isAppPath, parseAppOpenUrl, parseAppWindowId, parseBuckyosUrl, parseSystemOpenApp, readAppOpenRequest, readAppWindowDeclaration, resolveOpenApp, systemOpenAppUrl } from "./open-app.mjs";
@@ -51,14 +51,19 @@ export {
51
51
  ac as ACCESS_DENIED_ERROR_CODE,
52
52
  aO as AGENT_DELEGATE_TASK_SCHEMA_ID,
53
53
  bJ as AICC_AI_METHODS,
54
+ bO as AICC_API_TOKEN_METHODS,
55
+ bX as AICC_API_TOKEN_PREFIX,
54
56
  aT as AICC_COMPUTE_TASK_SCHEMA_ID,
57
+ bV as AICC_CONTRACT_VERSION,
58
+ bW as AICC_CONTRACT_VERSION_PARAM,
55
59
  bK as AICC_CORE_METHODS,
56
- bP as AICC_EXECUTION_MODES,
57
- bO as AICC_FEATURES,
60
+ bR as AICC_EXECUTION_MODES,
61
+ bQ as AICC_FEATURES,
58
62
  bL as AICC_MANAGEMENT_METHODS,
59
- bN as AICC_METHODS,
60
- bQ as AICC_POLICY_REFUSAL_CODES,
61
- bM as AICC_QUOTA_METHODS,
63
+ bP as AICC_METHODS,
64
+ bM as AICC_POLICY_METHODS,
65
+ bS as AICC_POLICY_REFUSAL_CODES,
66
+ bN as AICC_ROUTING_METHODS,
62
67
  bH as AICC_SERVICE_SERVICE_NAME,
63
68
  bI as AICC_SERVICE_SERVICE_PORT,
64
69
  bG as AICC_SERVICE_UNIQUE_ID,
@@ -84,30 +89,30 @@ export {
84
89
  aV as APP_UNINSTALL_TASK_SCHEMA_ID,
85
90
  aY as APP_UPDATE_BATCH_TASK_SCHEMA_ID,
86
91
  aX as APP_UPDATE_TASK_SCHEMA_ID,
87
- bX as AiccClient,
92
+ c2 as AiccClient,
88
93
  a12 as AiwsFailure,
89
94
  AiwsSourceError,
90
- cp as AudioError,
91
- cf as BNS_DNS_TXT_DEFAULT_TTL,
92
- cg as BNS_DNS_TXT_DOC_TYPE,
93
- cb as BNS_EVM_DEFAULT_GAS_LIMIT,
94
- cc as BNS_EVM_DEFAULT_MAX_FEE_PER_GAS,
95
- cd as BNS_EVM_DEFAULT_MAX_PRIORITY_FEE_PER_GAS,
96
- ce as BNS_MAX_INLINE_DOCUMENT_BYTES,
97
- ch as BNS_PUBLISH_DOCUMENT_ABI,
95
+ cw as AudioError,
96
+ cm as BNS_DNS_TXT_DEFAULT_TTL,
97
+ cn as BNS_DNS_TXT_DOC_TYPE,
98
+ ci as BNS_EVM_DEFAULT_GAS_LIMIT,
99
+ cj as BNS_EVM_DEFAULT_MAX_FEE_PER_GAS,
100
+ ck as BNS_EVM_DEFAULT_MAX_PRIORITY_FEE_PER_GAS,
101
+ cl as BNS_MAX_INLINE_DOCUMENT_BYTES,
102
+ co as BNS_PUBLISH_DOCUMENT_ABI,
98
103
  g as BS_SERVICE_TASK_MANAGER,
99
104
  B as BS_SERVICE_VERIFY_HUB,
100
105
  aj2 as BindFailure,
101
- cj as BnsEvmTxBuilder,
102
- ci as BnsEvmTxError,
103
- cn as BnsTxExecutor,
104
- cl as BnsTxExecutorError,
106
+ cq as BnsEvmTxBuilder,
107
+ cp as BnsEvmTxError,
108
+ cu as BnsTxExecutor,
109
+ cs as BnsTxExecutorError,
105
110
  l as BuckyOSSDK,
106
111
  H2 as CALENDAR_SCHEMA_ID,
107
- cD as COMPUTER_ELEMENT_ACTIONS,
108
- cC as COMPUTER_ELEMENT_STATES,
109
- cB as COMPUTER_ROLES,
110
- cA as COMPUTER_SEMANTIC_FORMAT,
112
+ cK as COMPUTER_ELEMENT_ACTIONS,
113
+ cJ as COMPUTER_ELEMENT_STATES,
114
+ cI as COMPUTER_ROLES,
115
+ cH as COMPUTER_SEMANTIC_FORMAT,
111
116
  a4 as CONTACT_CHANGED_EVENT_PATTERN,
112
117
  a3 as CONTACT_TAG_HOMESTATION_FOLLOWING,
113
118
  a2 as CONTACT_TAG_ZONE_AGENT,
@@ -119,15 +124,15 @@ export {
119
124
  D2 as DID_OBJECT_SERVICE_TYPE,
120
125
  aE as DOWNLOAD_TASK_SCHEMA_ID,
121
126
  E as EXTERNAL_PRINCIPAL_CLAIM,
122
- cE as ExecutorClient,
123
- cH as ExecutorCommandStream,
124
- cF as ExecutorStreamError,
127
+ cL as ExecutorClient,
128
+ cO as ExecutorCommandStream,
129
+ cM as ExecutorStreamError,
125
130
  a0 as FRIEND_INTENT,
126
131
  aD as HUMAN_APPROVAL_SCHEMA_ID,
127
132
  aP as HUMAN_INPUT_TASK_SCHEMA_ID,
128
133
  ak as JUMP_ACTION_PATHS,
129
- c5 as KEventClient,
130
- c4 as KEventReader,
134
+ cc as KEventClient,
135
+ cb as KEventReader,
131
136
  t as MsgCenterClient,
132
137
  M as MsgQueueClient,
133
138
  N2 as NODE_IDENTITY_SCHEMA_V2,
@@ -145,6 +150,7 @@ export {
145
150
  NfspClient,
146
151
  aQ as OPENDAN_ASYNC_TOOL_TASK_SCHEMA_ID,
147
152
  aR as OPENDAN_COMMAND_TASK_SCHEMA_ID,
153
+ bU as PROVIDER_ACCESS_DISABLED_REASON,
148
154
  aC as RAW_TASK_SCHEMA_ID,
149
155
  R3 as RPCError,
150
156
  R2 as RRuleError,
@@ -220,20 +226,20 @@ export {
220
226
  bu as WorkflowStepType,
221
227
  Z as ZONE_USER_TYPES,
222
228
  ae as accessDenialOf,
223
- cq as acquireBackgroundAudio,
224
- bV as aiccMessageFirstText,
225
- bU as aiccMessageTextContent,
226
- bR as aiccRefusalOf,
227
- bT as aiccTextMessage,
229
+ cx as acquireBackgroundAudio,
230
+ c0 as aiccMessageFirstText,
231
+ b$ as aiccMessageTextContent,
232
+ bT as aiccRefusalOf,
233
+ b_ as aiccTextMessage,
228
234
  aiwsContentDigest,
229
235
  c10 as aiwsTarget,
230
236
  aiwsTemplateDigest,
231
237
  _ as answerNotify,
232
- c8 as appDidFromId,
233
- c6 as appIdFromDid,
238
+ cf as appDidFromId,
239
+ cd as appIdFromDid,
234
240
  appWindowId,
235
241
  attachEvent,
236
- co as audioCapabilities,
242
+ cv as audioCapabilities,
237
243
  bj as baselineTaskControlProfile,
238
244
  al2 as bindingAccepts,
239
245
  at2 as bindingsPayload,
@@ -247,7 +253,7 @@ export {
247
253
  P2 as calendarFields,
248
254
  aa2 as calendarOccurrences,
249
255
  a02 as canonicalOriginal,
250
- cJ as cellValue,
256
+ cQ as cellValue,
251
257
  an2 as checkBindResult,
252
258
  av2 as checkBindSteps,
253
259
  checkComponent,
@@ -255,14 +261,14 @@ export {
255
261
  checkDeclarative,
256
262
  collectSources,
257
263
  Y as commitNotifyAnswer,
258
- cV as commitOps,
264
+ d0 as commitOps,
259
265
  h4 as commitWithParts,
260
266
  compatManifest,
261
267
  ax as completeAppAccessTokenLogin,
262
268
  a8 as contactTagApp,
263
269
  a9 as contactTagKind,
264
270
  controlSkeleton,
265
- c9 as createAppInstanceId,
271
+ cg as createAppInstanceId,
266
272
  createControlSource,
267
273
  createEventReader,
268
274
  as2 as createOps,
@@ -273,14 +279,14 @@ export {
273
279
  o4 as dayNumber,
274
280
  q3 as dayOf,
275
281
  n3 as daysInMonth,
276
- bY as decisionRequirements,
277
- ck as decodeBnsPublishDocumentCalldata,
282
+ c3 as decisionRequirements,
283
+ cr as decodeBnsPublishDocumentCalldata,
278
284
  ao2 as defaultOnBind,
279
285
  aq2 as defaultOnInit,
280
- cy as deleteRecording,
286
+ cF as deleteRecording,
281
287
  $2 as deleteRecordsOp,
282
288
  F2 as describeRRule,
283
- cG as encodeExecutorControl,
289
+ cN as encodeExecutorControl,
284
290
  ensureFolder,
285
291
  ab2 as eventAddOps,
286
292
  ad2 as eventDeleteOps,
@@ -289,8 +295,8 @@ export {
289
295
  ae2 as eventSkipOps,
290
296
  x2 as expandSeries,
291
297
  exportBundle,
292
- cN as fieldAdd,
293
- cI as fieldNamed,
298
+ cU as fieldAdd,
299
+ cP as fieldNamed,
294
300
  findFolder,
295
301
  ah2 as findOccurrence,
296
302
  folderName,
@@ -313,8 +319,8 @@ export {
313
319
  r2 as getDidIdentifier,
314
320
  q2 as getDidMethod,
315
321
  getKEventClient,
316
- cx as getRecording,
317
- cv as getRecordingStatus,
322
+ cE as getRecording,
323
+ cC as getRecordingStatus,
318
324
  a11 as getRuntimeEnvironment,
319
325
  getRuntimeType,
320
326
  getServiceRpcClient,
@@ -334,7 +340,8 @@ export {
334
340
  initBuckyOS,
335
341
  L as inputPrompt,
336
342
  _2 as insertRecordOp,
337
- bS as isAiccAiMethod,
343
+ bZ as isAiccAiMethod,
344
+ bY as isAiccApiTokenId,
338
345
  isAppPath,
339
346
  g2 as isBuckyOSAgentDocument,
340
347
  j2 as isBuckyOSDIDObjectCard,
@@ -358,7 +365,7 @@ export {
358
365
  at as issueAppCustomerLink,
359
366
  as as issueAppLoginCode,
360
367
  joinPath,
361
- cw as listRecordings,
368
+ cD as listRecordings,
362
369
  a82 as localDate,
363
370
  v2 as localDay,
364
371
  login,
@@ -369,8 +376,8 @@ export {
369
376
  logout,
370
377
  u as mailboxAddress,
371
378
  v as mailboxResource,
372
- cW as markdownToBlocks,
373
- cT as move,
379
+ d1 as markdownToBlocks,
380
+ c_ as move,
374
381
  U as msgMachineData,
375
382
  n2 as namelib,
376
383
  a as ndm,
@@ -386,18 +393,18 @@ export {
386
393
  T as notifyUrl,
387
394
  o3 as objectUrl,
388
395
  D3 as occurrenceId,
389
- cz as onRecordingState,
396
+ cG as onRecordingState,
390
397
  onUserPreferencesChanged,
391
398
  openExternalUrl,
392
- cO as optionAdd,
399
+ cV as optionAdd,
393
400
  a72 as orderAt,
394
401
  V2 as orderKeyBetween,
395
402
  X2 as orderKeysBetween,
396
403
  C2 as originalOf,
397
404
  packBuildFiles,
398
405
  ad as parseAccessDenial,
399
- c7 as parseAppId,
400
- ca as parseAppInstanceId,
406
+ ce as parseAppId,
407
+ ch as parseAppInstanceId,
401
408
  au as parseAppLoginExchangeResult,
402
409
  parseAppOpenUrl,
403
410
  parseAppWindowId,
@@ -410,10 +417,10 @@ export {
410
417
  j3 as parseRRule,
411
418
  p as parseSessionTokenClaims,
412
419
  parseSystemOpenApp,
413
- b$ as parseVideoPrompt,
420
+ c6 as parseVideoPrompt,
414
421
  p2 as parseW3CDIDDocumentBase,
415
422
  o as parseZoneUserType,
416
- cs as pauseRecording,
423
+ cz as pauseRecording,
417
424
  O as promptOptions,
418
425
  pullControl,
419
426
  av as randomAppLoginNonce,
@@ -423,17 +430,17 @@ export {
423
430
  r3 as readUserPreferences,
424
431
  G2 as recurrencePresets,
425
432
  removeEvent,
426
- cS as rename,
433
+ cZ as rename,
427
434
  ar2 as resolveBindings,
428
435
  r as resolveDidFromHost,
429
436
  resolveOpenApp,
430
437
  resolve_did,
431
- ct as resumeRecording,
438
+ cA as resumeRecording,
432
439
  ai2 as scheduleBoardOps,
433
440
  N3 as scheduleLabel,
434
441
  B2 as seriesStartOf,
435
442
  setAppSetting,
436
- cU as setProps,
443
+ c$ as setProps,
437
444
  Z2 as setValuesOps,
438
445
  slotCells,
439
446
  s as sn,
@@ -442,21 +449,21 @@ export {
442
449
  sourcesDigest,
443
450
  sourcesKey,
444
451
  Q2 as standardTableOp,
445
- cr as startRecording,
452
+ cy as startRecording,
446
453
  ap2 as stepsOnBind,
447
- cu as stopRecording,
454
+ cB as stopRecording,
448
455
  subscribeKEvent,
449
456
  systemOpenAppUrl,
450
- cM as tableDelete,
451
- cK as tableInsert,
452
- cL as tableSet,
457
+ cT as tableDelete,
458
+ cR as tableInsert,
459
+ cS as tableSet,
453
460
  bc as taskMgrErrorCode,
454
461
  ba as taskMgrTaskEventPath,
455
462
  bb as taskMgrTreeEventPath,
456
463
  templateDir,
457
- cP as textAppend,
458
- cR as textDeleteBlocks,
459
- cQ as textReplaceBlock,
464
+ cW as textAppend,
465
+ cY as textDeleteBlocks,
466
+ cX as textReplaceBlock,
460
467
  a32 as todoAddOps,
461
468
  a42 as todoCompleteOps,
462
469
  O2 as todoFields,
@@ -464,19 +471,19 @@ export {
464
471
  a52 as todoMoveOps,
465
472
  a62 as todoUpdateOps,
466
473
  unbuiltChanges,
467
- bW as validateAiccMessage,
468
- b_ as validateDecisionAnswers,
469
- bZ as validateDecisionRequest,
474
+ c1 as validateAiccMessage,
475
+ c5 as validateDecisionAnswers,
476
+ c4 as validateDecisionRequest,
470
477
  Q as validateNotifyAnswer,
471
- c2 as validateVideoEdit,
472
- c1 as validateVideoGeneration,
473
- c0 as validateVideoOutput,
478
+ c9 as validateVideoEdit,
479
+ c8 as validateVideoGeneration,
480
+ c7 as validateVideoOutput,
474
481
  verifyBundle,
475
- c3 as videoGenerationRequirement,
482
+ ca as videoGenerationRequirement,
476
483
  a92 as viewerTimeZone,
477
484
  $ as waitNotify,
478
485
  walletSignWithActiveDid,
479
- cm as walletUserHasSnAccount,
486
+ ct as walletUserHasSnAccount,
480
487
  watchControl,
481
488
  w2 as weekdayOf,
482
489
  writeBuildState,
@@ -1,4 +1,4 @@
1
- import { u as textContent, w as toolCalls, j as anyJsonObjectSchema, L as LLMComputeException, p as providerError } from "./aicc-67851c41.mjs";
1
+ import { u as textContent, w as toolCalls, j as anyJsonObjectSchema, L as LLMComputeException, p as providerError } from "./aicc-286ba457.mjs";
2
2
  function openaiHttpFailure(status, body) {
3
3
  var _a, _b;
4
4
  let code;
@@ -160,4 +160,4 @@ export {
160
160
  messagesToOpenai as m,
161
161
  openaiHttpFailure as o
162
162
  };
163
- //# sourceMappingURL=openai-ae2978de.mjs.map
163
+ //# sourceMappingURL=openai-1c0d8341.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-ae2978de.mjs","sources":["../src/xllm/dev/openai.ts"],"sourcesContent":["// OpenAI-compatible Chat Completions client (Rust `OpenAiLlmClient`), for\n// development and mocks. Only page code can inject it; configuration cannot\n// select it. CORS is the endpoint's business.\n\nimport type { AiContent, AiMessage, AiResponse, AiToolCall, JsonValue, LlmClient, LlmInferenceRequest, ProviderFailure } from '../core/types'\nimport { LLMComputeException, providerError } from '../core/errors'\nimport { textContent, toolCalls } from '../core/messages'\nimport { anyJsonObjectSchema } from '../providers/aicc'\n\n/** Failure class of a non-2xx response (Rust `openai_http_failure` after T2-0). */\nexport function openaiHttpFailure(status: number, body: string): ProviderFailure {\n let code: unknown\n try {\n code = (JSON.parse(body) as { error?: { code?: unknown } })?.error?.code\n } catch {\n code = undefined\n }\n if (code === 'context_length_exceeded') return 'context_limit'\n if (status === 401 || status === 403) return { refused: { code: 'credentials' } }\n if ([400, 404, 422].includes(status)) return 'permanent'\n if ([408, 409, 425, 429, 500, 502, 503, 504].includes(status)) return 'transient'\n return 'unknown'\n}\n\nfunction contentToOpenai(content: AiContent[]): JsonValue {\n const parts: JsonValue[] = []\n for (const c of content) {\n if (c.type === 'text') parts.push({ type: 'text', text: c.text })\n else if (c.type === 'image') {\n const s = c.source\n const url = s.kind === 'url' ? s.url : s.kind === 'base64' ? `data:${s.mime};base64,${s.data_base64}` : s.obj_id\n parts.push({ type: 'image_url', image_url: { url } })\n } else if (c.type === 'document') {\n const label = c.title ?? 'document'\n const desc = c.source.kind === 'url' ? c.source.url : '(inline document omitted)'\n parts.push({ type: 'text', text: `[${label}: ${desc}]` })\n }\n }\n const only = parts[0] as { type?: string; text?: string } | undefined\n if (parts.length === 1 && only?.type === 'text') return only.text as string\n return parts\n}\n\nexport function messagesToOpenai(messages: AiMessage[]): JsonValue[] {\n const out: JsonValue[] = []\n for (const m of messages) {\n if (m.role === 'system' || m.role === 'developer') out.push({ role: 'system', content: textContent(m) })\n else if (m.role === 'user') out.push({ role: 'user', content: contentToOpenai(m.content) })\n else if (m.role === 'assistant') {\n const text = textContent(m)\n const calls = toolCalls(m).map(c => ({ id: c.call_id, type: 'function', function: { name: c.name, arguments: JSON.stringify(c.args) } }))\n const obj: { [k: string]: JsonValue } = { role: 'assistant', content: text === '' ? null : text }\n if (calls.length) obj.tool_calls = calls\n out.push(obj)\n } else {\n for (const b of m.content) {\n if (b.type === 'tool_result') {\n out.push({ role: 'tool', tool_call_id: b.call_id, content: b.content.filter(c => c.type === 'text').map(c => (c as { text: string }).text).join('\\n') })\n }\n }\n }\n }\n return out\n}\n\nfunction truncateChars(s: string, max: number): string {\n const chars = [...s]\n return chars.length <= max ? s : chars.slice(0, max).join('') + '…'\n}\n\nexport interface OpenAiLlmOptions {\n baseUrl?: string\n apiKey: string\n headers?: Record<string, string>\n fetch?: typeof fetch\n}\n\nexport class OpenAiLlmClient implements LlmClient {\n private readonly baseUrl: string\n\n constructor(private readonly options: OpenAiLlmOptions) {\n this.baseUrl = (options.baseUrl?.trim() || 'https://api.openai.com/v1').replace(/\\/+$/, '')\n if (!options.apiKey?.trim()) throw new Error('openai provider: no API key')\n }\n\n async infer(req: LlmInferenceRequest): Promise<AiResponse> {\n const body: { [k: string]: JsonValue } = { model: req.model_alias, messages: messagesToOpenai(req.messages) }\n if (req.temperature !== undefined) body.temperature = req.temperature\n if (req.max_completion_tokens !== undefined) body.max_tokens = req.max_completion_tokens\n if (req.allow_tool_calls && req.tool_specs.length) {\n body.tools = req.tool_specs.map(s => ({ type: 'function', function: { name: s.name, description: s.description, parameters: s.args_schema } }))\n body.tool_choice = 'auto'\n }\n if (req.force_json) body.response_format = { type: 'json_schema', json_schema: { name: 'xllm_result', schema: req.json_schema ?? anyJsonObjectSchema() } }\n if (req.provider_options && typeof req.provider_options === 'object' && !Array.isArray(req.provider_options)) {\n Object.assign(body, req.provider_options)\n }\n const f = this.options.fetch ?? globalThis.fetch.bind(globalThis)\n let response: Response\n try {\n response = await f(`${this.baseUrl}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${this.options.apiKey}`, ...(this.options.headers ?? {}) },\n body: JSON.stringify(body),\n signal: req.signal,\n })\n } catch (e) {\n if (req.signal.aborted) throw new LLMComputeException({ kind: 'cancelled' })\n throw providerError('transient', `openai request failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n let text: string\n try {\n text = await response.text()\n } catch (e) {\n throw providerError('transient', `openai read body failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n if (!response.ok) throw providerError(openaiHttpFailure(response.status, text), `openai http ${response.status}: ${truncateChars(text, 512)}`)\n let parsed: { choices?: { message?: { content?: unknown; tool_calls?: unknown[] }; finish_reason?: unknown }[]; usage?: Record<string, unknown>; model?: unknown }\n try {\n parsed = JSON.parse(text)\n } catch (e) {\n throw providerError('unknown', `openai invalid JSON: ${e instanceof Error ? e.message : String(e)}`)\n }\n const choice = parsed.choices?.[0]\n if (!choice) throw providerError('unknown', 'openai response has no choices')\n const message = choice.message ?? {}\n const content: AiMessage['content'] = []\n if (typeof message.content === 'string') content.push({ type: 'text', text: message.content })\n for (const c of (message.tool_calls ?? []) as { id?: string; function?: { name?: string; arguments?: string } }[]) {\n let args: AiToolCall['args'] = {}\n try {\n const v = JSON.parse(c.function?.arguments ?? '{}')\n if (v && typeof v === 'object' && !Array.isArray(v)) args = v\n } catch {\n args = {}\n }\n content.push({ type: 'tool_use', call_id: c.id ?? '', name: c.function?.name ?? '', args })\n }\n if (content.length === 0) content.push({ type: 'text', text: '' })\n const out: AiResponse = { message: { role: 'assistant', content } }\n if (typeof choice.finish_reason === 'string') out.finish_reason = choice.finish_reason\n const u = parsed.usage\n if (u) {\n out.usage = { request_units: 1 }\n if (typeof u.prompt_tokens === 'number') out.usage.input_tokens = u.prompt_tokens\n if (typeof u.completion_tokens === 'number') out.usage.output_tokens = u.completion_tokens\n if (typeof u.total_tokens === 'number') out.usage.total_tokens = u.total_tokens\n }\n if (typeof parsed.model === 'string') out.extra = { model: parsed.model }\n return out\n }\n}\n"],"names":[],"mappings":";AAUgB,SAAA,kBAAkB,QAAgB,MAA+B;;AAC3E,MAAA;AACA,MAAA;AACF,YAAQ,gBAAK,MAAM,IAAI,MA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,QAAQ,EAAE,eAAe,EAAE;AAC3B,UAAA,OAAO,EAAE,kBAAkB;AAAc,YAAA,MAAM,eAAe,EAAE;AAChE,UAAA,OAAO,EAAE,sBAAsB;AAAc,YAAA,MAAM,gBAAgB,EAAE;AACrE,UAAA,OAAO,EAAE,iBAAiB;AAAc,YAAA,MAAM,eAAe,EAAE;AAAA,IACrE;AACI,QAAA,OAAO,OAAO,UAAU;AAAU,UAAI,QAAQ,EAAE,OAAO,OAAO,MAAM;AACjE,WAAA;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"openai-1c0d8341.mjs","sources":["../src/xllm/dev/openai.ts"],"sourcesContent":["// OpenAI-compatible Chat Completions client (Rust `OpenAiLlmClient`), for\n// development and mocks. Only page code can inject it; configuration cannot\n// select it. CORS is the endpoint's business.\n\nimport type { AiContent, AiMessage, AiResponse, AiToolCall, JsonValue, LlmClient, LlmInferenceRequest, ProviderFailure } from '../core/types'\nimport { LLMComputeException, providerError } from '../core/errors'\nimport { textContent, toolCalls } from '../core/messages'\nimport { anyJsonObjectSchema } from '../providers/aicc'\n\n/** Failure class of a non-2xx response (Rust `openai_http_failure` after T2-0). */\nexport function openaiHttpFailure(status: number, body: string): ProviderFailure {\n let code: unknown\n try {\n code = (JSON.parse(body) as { error?: { code?: unknown } })?.error?.code\n } catch {\n code = undefined\n }\n if (code === 'context_length_exceeded') return 'context_limit'\n if (status === 401 || status === 403) return { refused: { code: 'credentials' } }\n if ([400, 404, 422].includes(status)) return 'permanent'\n if ([408, 409, 425, 429, 500, 502, 503, 504].includes(status)) return 'transient'\n return 'unknown'\n}\n\nfunction contentToOpenai(content: AiContent[]): JsonValue {\n const parts: JsonValue[] = []\n for (const c of content) {\n if (c.type === 'text') parts.push({ type: 'text', text: c.text })\n else if (c.type === 'image') {\n const s = c.source\n const url = s.kind === 'url' ? s.url : s.kind === 'base64' ? `data:${s.mime};base64,${s.data_base64}` : s.obj_id\n parts.push({ type: 'image_url', image_url: { url } })\n } else if (c.type === 'document') {\n const label = c.title ?? 'document'\n const desc = c.source.kind === 'url' ? c.source.url : '(inline document omitted)'\n parts.push({ type: 'text', text: `[${label}: ${desc}]` })\n }\n }\n const only = parts[0] as { type?: string; text?: string } | undefined\n if (parts.length === 1 && only?.type === 'text') return only.text as string\n return parts\n}\n\nexport function messagesToOpenai(messages: AiMessage[]): JsonValue[] {\n const out: JsonValue[] = []\n for (const m of messages) {\n if (m.role === 'system' || m.role === 'developer') out.push({ role: 'system', content: textContent(m) })\n else if (m.role === 'user') out.push({ role: 'user', content: contentToOpenai(m.content) })\n else if (m.role === 'assistant') {\n const text = textContent(m)\n const calls = toolCalls(m).map(c => ({ id: c.call_id, type: 'function', function: { name: c.name, arguments: JSON.stringify(c.args) } }))\n const obj: { [k: string]: JsonValue } = { role: 'assistant', content: text === '' ? null : text }\n if (calls.length) obj.tool_calls = calls\n out.push(obj)\n } else {\n for (const b of m.content) {\n if (b.type === 'tool_result') {\n out.push({ role: 'tool', tool_call_id: b.call_id, content: b.content.filter(c => c.type === 'text').map(c => (c as { text: string }).text).join('\\n') })\n }\n }\n }\n }\n return out\n}\n\nfunction truncateChars(s: string, max: number): string {\n const chars = [...s]\n return chars.length <= max ? s : chars.slice(0, max).join('') + '…'\n}\n\nexport interface OpenAiLlmOptions {\n baseUrl?: string\n apiKey: string\n headers?: Record<string, string>\n fetch?: typeof fetch\n}\n\nexport class OpenAiLlmClient implements LlmClient {\n private readonly baseUrl: string\n\n constructor(private readonly options: OpenAiLlmOptions) {\n this.baseUrl = (options.baseUrl?.trim() || 'https://api.openai.com/v1').replace(/\\/+$/, '')\n if (!options.apiKey?.trim()) throw new Error('openai provider: no API key')\n }\n\n async infer(req: LlmInferenceRequest): Promise<AiResponse> {\n const body: { [k: string]: JsonValue } = { model: req.model_alias, messages: messagesToOpenai(req.messages) }\n if (req.temperature !== undefined) body.temperature = req.temperature\n if (req.max_completion_tokens !== undefined) body.max_tokens = req.max_completion_tokens\n if (req.allow_tool_calls && req.tool_specs.length) {\n body.tools = req.tool_specs.map(s => ({ type: 'function', function: { name: s.name, description: s.description, parameters: s.args_schema } }))\n body.tool_choice = 'auto'\n }\n if (req.force_json) body.response_format = { type: 'json_schema', json_schema: { name: 'xllm_result', schema: req.json_schema ?? anyJsonObjectSchema() } }\n if (req.provider_options && typeof req.provider_options === 'object' && !Array.isArray(req.provider_options)) {\n Object.assign(body, req.provider_options)\n }\n const f = this.options.fetch ?? globalThis.fetch.bind(globalThis)\n let response: Response\n try {\n response = await f(`${this.baseUrl}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${this.options.apiKey}`, ...(this.options.headers ?? {}) },\n body: JSON.stringify(body),\n signal: req.signal,\n })\n } catch (e) {\n if (req.signal.aborted) throw new LLMComputeException({ kind: 'cancelled' })\n throw providerError('transient', `openai request failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n let text: string\n try {\n text = await response.text()\n } catch (e) {\n throw providerError('transient', `openai read body failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n if (!response.ok) throw providerError(openaiHttpFailure(response.status, text), `openai http ${response.status}: ${truncateChars(text, 512)}`)\n let parsed: { choices?: { message?: { content?: unknown; tool_calls?: unknown[] }; finish_reason?: unknown }[]; usage?: Record<string, unknown>; model?: unknown }\n try {\n parsed = JSON.parse(text)\n } catch (e) {\n throw providerError('unknown', `openai invalid JSON: ${e instanceof Error ? e.message : String(e)}`)\n }\n const choice = parsed.choices?.[0]\n if (!choice) throw providerError('unknown', 'openai response has no choices')\n const message = choice.message ?? {}\n const content: AiMessage['content'] = []\n if (typeof message.content === 'string') content.push({ type: 'text', text: message.content })\n for (const c of (message.tool_calls ?? []) as { id?: string; function?: { name?: string; arguments?: string } }[]) {\n let args: AiToolCall['args'] = {}\n try {\n const v = JSON.parse(c.function?.arguments ?? '{}')\n if (v && typeof v === 'object' && !Array.isArray(v)) args = v\n } catch {\n args = {}\n }\n content.push({ type: 'tool_use', call_id: c.id ?? '', name: c.function?.name ?? '', args })\n }\n if (content.length === 0) content.push({ type: 'text', text: '' })\n const out: AiResponse = { message: { role: 'assistant', content } }\n if (typeof choice.finish_reason === 'string') out.finish_reason = choice.finish_reason\n const u = parsed.usage\n if (u) {\n out.usage = { request_units: 1 }\n if (typeof u.prompt_tokens === 'number') out.usage.input_tokens = u.prompt_tokens\n if (typeof u.completion_tokens === 'number') out.usage.output_tokens = u.completion_tokens\n if (typeof u.total_tokens === 'number') out.usage.total_tokens = u.total_tokens\n }\n if (typeof parsed.model === 'string') out.extra = { model: parsed.model }\n return out\n }\n}\n"],"names":[],"mappings":";AAUgB,SAAA,kBAAkB,QAAgB,MAA+B;;AAC3E,MAAA;AACA,MAAA;AACF,YAAQ,gBAAK,MAAM,IAAI,MAAf,mBAAqD,UAArD,mBAA4D;AAAA,EAAA,QAC9D;AACC,WAAA;AAAA,EACT;AACA,MAAI,SAAS;AAAkC,WAAA;AAC3C,MAAA,WAAW,OAAO,WAAW;AAAK,WAAO,EAAE,SAAS,EAAE,MAAM,cAAgB,EAAA;AAChF,MAAI,CAAC,KAAK,KAAK,GAAG,EAAE,SAAS,MAAM;AAAU,WAAA;AACzC,MAAA,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG,EAAE,SAAS,MAAM;AAAU,WAAA;AAC/D,SAAA;AACT;AAEA,SAAS,gBAAgB,SAAiC;AACxD,QAAM,QAAqB,CAAA;AAC3B,aAAW,KAAK,SAAS;AACvB,QAAI,EAAE,SAAS;AAAQ,YAAM,KAAK,EAAE,MAAM,QAAQ,MAAM,EAAE,MAAM;AAAA,aACvD,EAAE,SAAS,SAAS;AAC3B,YAAM,IAAI,EAAE;AACZ,YAAM,MAAM,EAAE,SAAS,QAAQ,EAAE,MAAM,EAAE,SAAS,WAAW,QAAQ,EAAE,IAAI,WAAW,EAAE,WAAW,KAAK,EAAE;AACpG,YAAA,KAAK,EAAE,MAAM,aAAa,WAAW,EAAE,OAAO;AAAA,IAAA,WAC3C,EAAE,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I,KAAK,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,CAAC;AAAU,iBAAA;AAAA,MAAA,QACtD;AACN,eAAO,CAAA;AAAA,MACT;AACA,cAAQ,KAAK,EAAE,MAAM,YAAY,SAAS,EAAE,MAAM,IAAI,QAAM,OAAE,aAAF,mBAAY,SAAQ,IAAI,MAAM;AAAA,IAC5F;AACA,QAAI,QAAQ,WAAW;AAAG,cAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,IAAI;AACjE,UAAM,MAAkB,EAAE,SAAS,EAAE,MAAM,aAAa;AACpD,QAAA,OAAO,OAAO,kBAAkB;AAAU,UAAI,gBAAgB,OAAO;AACzE,UAAM,IAAI,OAAO;AACjB,QAAI,GAAG;AACD,UAAA,QAAQ,EAAE,eAAe,EAAE;AAC3B,UAAA,OAAO,EAAE,kBAAkB;AAAc,YAAA,MAAM,eAAe,EAAE;AAChE,UAAA,OAAO,EAAE,sBAAsB;AAAc,YAAA,MAAM,gBAAgB,EAAE;AACrE,UAAA,OAAO,EAAE,iBAAiB;AAAc,YAAA,MAAM,eAAe,EAAE;AAAA,IACrE;AACI,QAAA,OAAO,OAAO,UAAU;AAAU,UAAI,QAAQ,EAAE,OAAO,OAAO,MAAM;AACjE,WAAA;AAAA,EACT;AACF;"}
@@ -1,2 +1,2 @@
1
- "use strict";const t=require("./aicc-ccb36ef7.js");function e(t,e){var o,n;let s;try{s=null==(n=null==(o=JSON.parse(e))?void 0:o.error)?void 0:n.code}catch{s=void 0}return"context_length_exceeded"===s?"context_limit":401===t||403===t?{refused:{code:"credentials"}}:[400,404,422].includes(t)?"permanent":[408,409,425,429,500,502,503,504].includes(t)?"transient":"unknown"}function o(t){const e=[];for(const n of t)if("text"===n.type)e.push({type:"text",text:n.text});else if("image"===n.type){const t=n.source,o="url"===t.kind?t.url:"base64"===t.kind?`data:${t.mime};base64,${t.data_base64}`:t.obj_id;e.push({type:"image_url",image_url:{url:o}})}else if("document"===n.type){const t=n.title??"document",o="url"===n.source.kind?n.source.url:"(inline document omitted)";e.push({type:"text",text:`[${t}: ${o}]`})}const o=e[0];return 1===e.length&&"text"===(null==o?void 0:o.type)?o.text:e}function n(e){const n=[];for(const s of e)if("system"===s.role||"developer"===s.role)n.push({role:"system",content:t.textContent(s)});else if("user"===s.role)n.push({role:"user",content:o(s.content)});else if("assistant"===s.role){const e=t.textContent(s),o=t.toolCalls(s).map((t=>({id:t.call_id,type:"function",function:{name:t.name,arguments:JSON.stringify(t.args)}}))),r={role:"assistant",content:""===e?null:e};o.length&&(r.tool_calls=o),n.push(r)}else for(const t of s.content)"tool_result"===t.type&&n.push({role:"tool",tool_call_id:t.call_id,content:t.content.filter((t=>"text"===t.type)).map((t=>t.text)).join("\n")});return n}exports.OpenAiLlmClient=class{constructor(t){var e,o;if(this.options=t,this.baseUrl=((null==(e=t.baseUrl)?void 0:e.trim())||"https://api.openai.com/v1").replace(/\/+$/,""),!(null==(o=t.apiKey)?void 0:o.trim()))throw new Error("openai provider: no API key")}async infer(o){var s,r,i;const a={model:o.model_alias,messages:n(o.messages)};void 0!==o.temperature&&(a.temperature=o.temperature),void 0!==o.max_completion_tokens&&(a.max_tokens=o.max_completion_tokens),o.allow_tool_calls&&o.tool_specs.length&&(a.tools=o.tool_specs.map((t=>({type:"function",function:{name:t.name,description:t.description,parameters:t.args_schema}}))),a.tool_choice="auto"),o.force_json&&(a.response_format={type:"json_schema",json_schema:{name:"xllm_result",schema:o.json_schema??t.anyJsonObjectSchema()}}),o.provider_options&&"object"==typeof o.provider_options&&!Array.isArray(o.provider_options)&&Object.assign(a,o.provider_options);const l=this.options.fetch??globalThis.fetch.bind(globalThis);let c,p,u;try{c=await l(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${this.options.apiKey}`,...this.options.headers??{}},body:JSON.stringify(a),signal:o.signal})}catch(y){if(o.signal.aborted)throw new t.LLMComputeException({kind:"cancelled"});throw t.providerError("transient",`openai request failed: ${y instanceof Error?y.message:String(y)}`)}try{p=await c.text()}catch(y){throw t.providerError("transient",`openai read body failed: ${y instanceof Error?y.message:String(y)}`)}if(!c.ok)throw t.providerError(e(c.status,p),`openai http ${c.status}: ${function(t,e){const o=[...t];return o.length<=e?t:o.slice(0,e).join("")+"…"}(p,512)}`);try{u=JSON.parse(p)}catch(y){throw t.providerError("unknown",`openai invalid JSON: ${y instanceof Error?y.message:String(y)}`)}const m=null==(s=u.choices)?void 0:s[0];if(!m)throw t.providerError("unknown","openai response has no choices");const d=m.message??{},h=[];"string"==typeof d.content&&h.push({type:"text",text:d.content});for(const t of d.tool_calls??[]){let e={};try{const o=JSON.parse((null==(r=t.function)?void 0:r.arguments)??"{}");o&&"object"==typeof o&&!Array.isArray(o)&&(e=o)}catch{e={}}h.push({type:"tool_use",call_id:t.id??"",name:(null==(i=t.function)?void 0:i.name)??"",args:e})}0===h.length&&h.push({type:"text",text:""});const f={message:{role:"assistant",content:h}};"string"==typeof m.finish_reason&&(f.finish_reason=m.finish_reason);const _=u.usage;return _&&(f.usage={request_units:1},"number"==typeof _.prompt_tokens&&(f.usage.input_tokens=_.prompt_tokens),"number"==typeof _.completion_tokens&&(f.usage.output_tokens=_.completion_tokens),"number"==typeof _.total_tokens&&(f.usage.total_tokens=_.total_tokens)),"string"==typeof u.model&&(f.extra={model:u.model}),f}},exports.messagesToOpenai=n,exports.openaiHttpFailure=e;
2
- //# sourceMappingURL=openai-f560d518.js.map
1
+ "use strict";const t=require("./aicc-342f2659.js");function e(t,e){var o,n;let s;try{s=null==(n=null==(o=JSON.parse(e))?void 0:o.error)?void 0:n.code}catch{s=void 0}return"context_length_exceeded"===s?"context_limit":401===t||403===t?{refused:{code:"credentials"}}:[400,404,422].includes(t)?"permanent":[408,409,425,429,500,502,503,504].includes(t)?"transient":"unknown"}function o(t){const e=[];for(const n of t)if("text"===n.type)e.push({type:"text",text:n.text});else if("image"===n.type){const t=n.source,o="url"===t.kind?t.url:"base64"===t.kind?`data:${t.mime};base64,${t.data_base64}`:t.obj_id;e.push({type:"image_url",image_url:{url:o}})}else if("document"===n.type){const t=n.title??"document",o="url"===n.source.kind?n.source.url:"(inline document omitted)";e.push({type:"text",text:`[${t}: ${o}]`})}const o=e[0];return 1===e.length&&"text"===(null==o?void 0:o.type)?o.text:e}function n(e){const n=[];for(const s of e)if("system"===s.role||"developer"===s.role)n.push({role:"system",content:t.textContent(s)});else if("user"===s.role)n.push({role:"user",content:o(s.content)});else if("assistant"===s.role){const e=t.textContent(s),o=t.toolCalls(s).map((t=>({id:t.call_id,type:"function",function:{name:t.name,arguments:JSON.stringify(t.args)}}))),r={role:"assistant",content:""===e?null:e};o.length&&(r.tool_calls=o),n.push(r)}else for(const t of s.content)"tool_result"===t.type&&n.push({role:"tool",tool_call_id:t.call_id,content:t.content.filter((t=>"text"===t.type)).map((t=>t.text)).join("\n")});return n}exports.OpenAiLlmClient=class{constructor(t){var e,o;if(this.options=t,this.baseUrl=((null==(e=t.baseUrl)?void 0:e.trim())||"https://api.openai.com/v1").replace(/\/+$/,""),!(null==(o=t.apiKey)?void 0:o.trim()))throw new Error("openai provider: no API key")}async infer(o){var s,r,i;const a={model:o.model_alias,messages:n(o.messages)};void 0!==o.temperature&&(a.temperature=o.temperature),void 0!==o.max_completion_tokens&&(a.max_tokens=o.max_completion_tokens),o.allow_tool_calls&&o.tool_specs.length&&(a.tools=o.tool_specs.map((t=>({type:"function",function:{name:t.name,description:t.description,parameters:t.args_schema}}))),a.tool_choice="auto"),o.force_json&&(a.response_format={type:"json_schema",json_schema:{name:"xllm_result",schema:o.json_schema??t.anyJsonObjectSchema()}}),o.provider_options&&"object"==typeof o.provider_options&&!Array.isArray(o.provider_options)&&Object.assign(a,o.provider_options);const l=this.options.fetch??globalThis.fetch.bind(globalThis);let c,p,u;try{c=await l(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${this.options.apiKey}`,...this.options.headers??{}},body:JSON.stringify(a),signal:o.signal})}catch(y){if(o.signal.aborted)throw new t.LLMComputeException({kind:"cancelled"});throw t.providerError("transient",`openai request failed: ${y instanceof Error?y.message:String(y)}`)}try{p=await c.text()}catch(y){throw t.providerError("transient",`openai read body failed: ${y instanceof Error?y.message:String(y)}`)}if(!c.ok)throw t.providerError(e(c.status,p),`openai http ${c.status}: ${function(t,e){const o=[...t];return o.length<=e?t:o.slice(0,e).join("")+"…"}(p,512)}`);try{u=JSON.parse(p)}catch(y){throw t.providerError("unknown",`openai invalid JSON: ${y instanceof Error?y.message:String(y)}`)}const m=null==(s=u.choices)?void 0:s[0];if(!m)throw t.providerError("unknown","openai response has no choices");const d=m.message??{},h=[];"string"==typeof d.content&&h.push({type:"text",text:d.content});for(const t of d.tool_calls??[]){let e={};try{const o=JSON.parse((null==(r=t.function)?void 0:r.arguments)??"{}");o&&"object"==typeof o&&!Array.isArray(o)&&(e=o)}catch{e={}}h.push({type:"tool_use",call_id:t.id??"",name:(null==(i=t.function)?void 0:i.name)??"",args:e})}0===h.length&&h.push({type:"text",text:""});const f={message:{role:"assistant",content:h}};"string"==typeof m.finish_reason&&(f.finish_reason=m.finish_reason);const _=u.usage;return _&&(f.usage={request_units:1},"number"==typeof _.prompt_tokens&&(f.usage.input_tokens=_.prompt_tokens),"number"==typeof _.completion_tokens&&(f.usage.output_tokens=_.completion_tokens),"number"==typeof _.total_tokens&&(f.usage.total_tokens=_.total_tokens)),"string"==typeof u.model&&(f.extra={model:u.model}),f}},exports.messagesToOpenai=n,exports.openaiHttpFailure=e;
2
+ //# sourceMappingURL=openai-7aa4ffbf.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-f560d518.js","sources":["../src/xllm/dev/openai.ts"],"sourcesContent":["// OpenAI-compatible Chat Completions client (Rust `OpenAiLlmClient`), for\n// development and mocks. Only page code can inject it; configuration cannot\n// select it. CORS is the endpoint's business.\n\nimport type { AiContent, AiMessage, AiResponse, AiToolCall, JsonValue, LlmClient, LlmInferenceRequest, ProviderFailure } from '../core/types'\nimport { LLMComputeException, providerError } from '../core/errors'\nimport { textContent, toolCalls } from '../core/messages'\nimport { anyJsonObjectSchema } from '../providers/aicc'\n\n/** Failure class of a non-2xx response (Rust `openai_http_failure` after T2-0). */\nexport function openaiHttpFailure(status: number, body: string): ProviderFailure {\n let code: unknown\n try {\n code = (JSON.parse(body) as { error?: { code?: unknown } })?.error?.code\n } catch {\n code = undefined\n }\n if (code === 'context_length_exceeded') return 'context_limit'\n if (status === 401 || status === 403) return { refused: { code: 'credentials' } }\n if ([400, 404, 422].includes(status)) return 'permanent'\n if ([408, 409, 425, 429, 500, 502, 503, 504].includes(status)) return 'transient'\n return 'unknown'\n}\n\nfunction contentToOpenai(content: AiContent[]): JsonValue {\n const parts: JsonValue[] = []\n for (const c of content) {\n if (c.type === 'text') parts.push({ type: 'text', text: c.text })\n else if (c.type === 'image') {\n const s = c.source\n const url = s.kind === 'url' ? s.url : s.kind === 'base64' ? `data:${s.mime};base64,${s.data_base64}` : s.obj_id\n parts.push({ type: 'image_url', image_url: { url } })\n } else if (c.type === 'document') {\n const label = c.title ?? 'document'\n const desc = c.source.kind === 'url' ? c.source.url : '(inline document omitted)'\n parts.push({ type: 'text', text: `[${label}: ${desc}]` })\n }\n }\n const only = parts[0] as { type?: string; text?: string } | undefined\n if (parts.length === 1 && only?.type === 'text') return only.text as string\n return parts\n}\n\nexport function messagesToOpenai(messages: AiMessage[]): JsonValue[] {\n const out: JsonValue[] = []\n for (const m of messages) {\n if (m.role === 'system' || m.role === 'developer') out.push({ role: 'system', content: textContent(m) })\n else if (m.role === 'user') out.push({ role: 'user', content: contentToOpenai(m.content) })\n else if (m.role === 'assistant') {\n const text = textContent(m)\n const calls = toolCalls(m).map(c => ({ id: c.call_id, type: 'function', function: { name: c.name, arguments: JSON.stringify(c.args) } }))\n const obj: { [k: string]: JsonValue } = { role: 'assistant', content: text === '' ? null : text }\n if (calls.length) obj.tool_calls = calls\n out.push(obj)\n } else {\n for (const b of m.content) {\n if (b.type === 'tool_result') {\n out.push({ role: 'tool', tool_call_id: b.call_id, content: b.content.filter(c => c.type === 'text').map(c => (c as { text: string }).text).join('\\n') })\n }\n }\n }\n }\n return out\n}\n\nfunction truncateChars(s: string, max: number): string {\n const chars = [...s]\n return chars.length <= max ? s : chars.slice(0, max).join('') + '…'\n}\n\nexport interface OpenAiLlmOptions {\n baseUrl?: string\n apiKey: string\n headers?: Record<string, string>\n fetch?: typeof fetch\n}\n\nexport class OpenAiLlmClient implements LlmClient {\n private readonly baseUrl: string\n\n constructor(private readonly options: OpenAiLlmOptions) {\n this.baseUrl = (options.baseUrl?.trim() || 'https://api.openai.com/v1').replace(/\\/+$/, '')\n if (!options.apiKey?.trim()) throw new Error('openai provider: no API key')\n }\n\n async infer(req: LlmInferenceRequest): Promise<AiResponse> {\n const body: { [k: string]: JsonValue } = { model: req.model_alias, messages: messagesToOpenai(req.messages) }\n if (req.temperature !== undefined) body.temperature = req.temperature\n if (req.max_completion_tokens !== undefined) body.max_tokens = req.max_completion_tokens\n if (req.allow_tool_calls && req.tool_specs.length) {\n body.tools = req.tool_specs.map(s => ({ type: 'function', function: { name: s.name, description: s.description, parameters: s.args_schema } }))\n body.tool_choice = 'auto'\n }\n if (req.force_json) body.response_format = { type: 'json_schema', json_schema: { name: 'xllm_result', schema: req.json_schema ?? anyJsonObjectSchema() } }\n if (req.provider_options && typeof req.provider_options === 'object' && !Array.isArray(req.provider_options)) {\n Object.assign(body, req.provider_options)\n }\n const f = this.options.fetch ?? globalThis.fetch.bind(globalThis)\n let response: Response\n try {\n response = await f(`${this.baseUrl}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${this.options.apiKey}`, ...(this.options.headers ?? {}) },\n body: JSON.stringify(body),\n signal: req.signal,\n })\n } catch (e) {\n if (req.signal.aborted) throw new LLMComputeException({ kind: 'cancelled' })\n throw providerError('transient', `openai request failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n let text: string\n try {\n text = await response.text()\n } catch (e) {\n throw providerError('transient', `openai read body failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n if (!response.ok) throw providerError(openaiHttpFailure(response.status, text), `openai http ${response.status}: ${truncateChars(text, 512)}`)\n let parsed: { choices?: { message?: { content?: unknown; tool_calls?: unknown[] }; finish_reason?: unknown }[]; usage?: Record<string, unknown>; model?: unknown }\n try {\n parsed = JSON.parse(text)\n } catch (e) {\n throw providerError('unknown', `openai invalid JSON: ${e instanceof Error ? e.message : String(e)}`)\n }\n const choice = parsed.choices?.[0]\n if (!choice) throw providerError('unknown', 'openai response has no choices')\n const message = choice.message ?? {}\n const content: AiMessage['content'] = []\n if (typeof message.content === 'string') content.push({ type: 'text', text: message.content })\n for (const c of (message.tool_calls ?? []) as { id?: string; function?: { name?: string; arguments?: string } }[]) {\n let args: AiToolCall['args'] = {}\n try {\n const v = JSON.parse(c.function?.arguments ?? '{}')\n if (v && typeof v === 'object' && !Array.isArray(v)) args = v\n } catch {\n args = {}\n }\n content.push({ type: 'tool_use', call_id: c.id ?? '', name: c.function?.name ?? '', args })\n }\n if (content.length === 0) content.push({ type: 'text', text: '' })\n const out: AiResponse = { message: { role: 'assistant', content } }\n if (typeof choice.finish_reason === 'string') out.finish_reason = choice.finish_reason\n const u = parsed.usage\n if (u) {\n out.usage = { request_units: 1 }\n if (typeof u.prompt_tokens === 'number') out.usage.input_tokens = u.prompt_tokens\n if (typeof u.completion_tokens === 'number') out.usage.output_tokens = u.completion_tokens\n if (typeof u.total_tokens === 'number') out.usage.total_tokens = u.total_tokens\n }\n if (typeof parsed.model === 'string') out.extra = { model: parsed.model }\n return out\n }\n}\n"],"names":["openaiHttpFailure","status","body","code","_b","parse","_a","error","refused","includes","contentToOpenai","content","parts","c","type","push","text","s","source","url","kind","mime","data_base64","obj_id","image_url","label","title","desc","only","length","messagesToOpenai","messages","out","m","role","textContent","calls","toolCalls","map","id","call_id","function","name","arguments","JSON","stringify","args","obj","tool_calls","b","tool_call_id","filter","join","constructor","options","this","baseUrl","trim","replace","apiKey","Error","infer","req","model","model_alias","temperature","max_completion_tokens","max_tokens","allow_tool_calls","tool_specs","tools","description","parameters","args_schema","tool_choice","force_json","response_format","json_schema","schema","anyJsonObjectSchema","provider_options","Array","isArray","Object","assign","f","fetch","globalThis","bind","response","parsed","method","headers","authorization","signal","e","aborted","LLMComputeException","providerError","message","String","ok","max","chars","slice","truncateChars","choice","choices","v","_c","finish_reason","u","usage","request_units","prompt_tokens","input_tokens","completion_tokens","output_tokens","total_tokens","extra"],"mappings":"mDAUgB,SAAAA,EAAkBC,EAAgBC,WAC5C,IAAAC,EACA,IACFA,EAAQ,OAAAC,EAAA,cAAKC,MAAMH,SAAX,EAAAI,EAAqDC,YAAO,EAAAH,EAAAD,IAAA,CAC9D,MACCA,OAAA,CACT,CACA,MAAa,4BAATA,EAA2C,gBAChC,MAAXF,GAA6B,MAAXA,EAAuB,CAAEO,QAAS,CAAEL,KAAM,gBAC5D,CAAC,IAAK,IAAK,KAAKM,SAASR,GAAgB,YACzC,CAAC,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,KAAKQ,SAASR,GAAgB,YAC/D,SACT,CAEA,SAASS,EAAgBC,GACvB,MAAMC,EAAqB,GAC3B,IAAA,MAAWC,KAAKF,EACd,GAAe,SAAXE,EAAEC,KAAiBF,EAAMG,KAAK,CAAED,KAAM,OAAQE,KAAMH,EAAEG,YACjD,GAAW,UAAXH,EAAEC,KAAkB,CAC3B,MAAMG,EAAIJ,EAAEK,OACNC,EAAiB,QAAXF,EAAEG,KAAiBH,EAAEE,IAAiB,WAAXF,EAAEG,KAAoB,QAAQH,EAAEI,eAAeJ,EAAEK,cAAgBL,EAAEM,OACpGX,EAAAG,KAAK,CAAED,KAAM,YAAaU,UAAW,CAAEL,QAAO,MAAA,GAChC,aAAXN,EAAEC,KAAqB,CAC1B,MAAAW,EAAQZ,EAAEa,OAAS,WACnBC,EAAyB,QAAlBd,EAAEK,OAAOE,KAAiBP,EAAEK,OAAOC,IAAM,4B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7D,MAAMgB,EAAkB,CAAEmE,QAAS,CAAEjE,KAAM,YAAavB,YACpB,iBAAzB+F,EAAOI,gBAA4B9E,EAAI8E,cAAgBJ,EAAOI,eACzE,MAAMC,EAAIrB,EAAOsB,MAQV,OAPHD,IACE/E,EAAAgF,MAAQ,CAAEC,cAAe,GACE,iBAApBF,EAAEG,gBAAgClF,EAAAgF,MAAMG,aAAeJ,EAAEG,eACjC,iBAAxBH,EAAEK,oBAAoCpF,EAAAgF,MAAMK,cAAgBN,EAAEK,mBAC3C,iBAAnBL,EAAEO,eAA+BtF,EAAAgF,MAAMM,aAAeP,EAAEO,eAEzC,iBAAjB5B,EAAO3B,QAAoB/B,EAAIuF,MAAQ,CAAExD,MAAO2B,EAAO3B,QAC3D/B,CACT"}
1
+ {"version":3,"file":"openai-7aa4ffbf.js","sources":["../src/xllm/dev/openai.ts"],"sourcesContent":["// OpenAI-compatible Chat Completions client (Rust `OpenAiLlmClient`), for\n// development and mocks. Only page code can inject it; configuration cannot\n// select it. CORS is the endpoint's business.\n\nimport type { AiContent, AiMessage, AiResponse, AiToolCall, JsonValue, LlmClient, LlmInferenceRequest, ProviderFailure } from '../core/types'\nimport { LLMComputeException, providerError } from '../core/errors'\nimport { textContent, toolCalls } from '../core/messages'\nimport { anyJsonObjectSchema } from '../providers/aicc'\n\n/** Failure class of a non-2xx response (Rust `openai_http_failure` after T2-0). */\nexport function openaiHttpFailure(status: number, body: string): ProviderFailure {\n let code: unknown\n try {\n code = (JSON.parse(body) as { error?: { code?: unknown } })?.error?.code\n } catch {\n code = undefined\n }\n if (code === 'context_length_exceeded') return 'context_limit'\n if (status === 401 || status === 403) return { refused: { code: 'credentials' } }\n if ([400, 404, 422].includes(status)) return 'permanent'\n if ([408, 409, 425, 429, 500, 502, 503, 504].includes(status)) return 'transient'\n return 'unknown'\n}\n\nfunction contentToOpenai(content: AiContent[]): JsonValue {\n const parts: JsonValue[] = []\n for (const c of content) {\n if (c.type === 'text') parts.push({ type: 'text', text: c.text })\n else if (c.type === 'image') {\n const s = c.source\n const url = s.kind === 'url' ? s.url : s.kind === 'base64' ? `data:${s.mime};base64,${s.data_base64}` : s.obj_id\n parts.push({ type: 'image_url', image_url: { url } })\n } else if (c.type === 'document') {\n const label = c.title ?? 'document'\n const desc = c.source.kind === 'url' ? c.source.url : '(inline document omitted)'\n parts.push({ type: 'text', text: `[${label}: ${desc}]` })\n }\n }\n const only = parts[0] as { type?: string; text?: string } | undefined\n if (parts.length === 1 && only?.type === 'text') return only.text as string\n return parts\n}\n\nexport function messagesToOpenai(messages: AiMessage[]): JsonValue[] {\n const out: JsonValue[] = []\n for (const m of messages) {\n if (m.role === 'system' || m.role === 'developer') out.push({ role: 'system', content: textContent(m) })\n else if (m.role === 'user') out.push({ role: 'user', content: contentToOpenai(m.content) })\n else if (m.role === 'assistant') {\n const text = textContent(m)\n const calls = toolCalls(m).map(c => ({ id: c.call_id, type: 'function', function: { name: c.name, arguments: JSON.stringify(c.args) } }))\n const obj: { [k: string]: JsonValue } = { role: 'assistant', content: text === '' ? null : text }\n if (calls.length) obj.tool_calls = calls\n out.push(obj)\n } else {\n for (const b of m.content) {\n if (b.type === 'tool_result') {\n out.push({ role: 'tool', tool_call_id: b.call_id, content: b.content.filter(c => c.type === 'text').map(c => (c as { text: string }).text).join('\\n') })\n }\n }\n }\n }\n return out\n}\n\nfunction truncateChars(s: string, max: number): string {\n const chars = [...s]\n return chars.length <= max ? s : chars.slice(0, max).join('') + '…'\n}\n\nexport interface OpenAiLlmOptions {\n baseUrl?: string\n apiKey: string\n headers?: Record<string, string>\n fetch?: typeof fetch\n}\n\nexport class OpenAiLlmClient implements LlmClient {\n private readonly baseUrl: string\n\n constructor(private readonly options: OpenAiLlmOptions) {\n this.baseUrl = (options.baseUrl?.trim() || 'https://api.openai.com/v1').replace(/\\/+$/, '')\n if (!options.apiKey?.trim()) throw new Error('openai provider: no API key')\n }\n\n async infer(req: LlmInferenceRequest): Promise<AiResponse> {\n const body: { [k: string]: JsonValue } = { model: req.model_alias, messages: messagesToOpenai(req.messages) }\n if (req.temperature !== undefined) body.temperature = req.temperature\n if (req.max_completion_tokens !== undefined) body.max_tokens = req.max_completion_tokens\n if (req.allow_tool_calls && req.tool_specs.length) {\n body.tools = req.tool_specs.map(s => ({ type: 'function', function: { name: s.name, description: s.description, parameters: s.args_schema } }))\n body.tool_choice = 'auto'\n }\n if (req.force_json) body.response_format = { type: 'json_schema', json_schema: { name: 'xllm_result', schema: req.json_schema ?? anyJsonObjectSchema() } }\n if (req.provider_options && typeof req.provider_options === 'object' && !Array.isArray(req.provider_options)) {\n Object.assign(body, req.provider_options)\n }\n const f = this.options.fetch ?? globalThis.fetch.bind(globalThis)\n let response: Response\n try {\n response = await f(`${this.baseUrl}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${this.options.apiKey}`, ...(this.options.headers ?? {}) },\n body: JSON.stringify(body),\n signal: req.signal,\n })\n } catch (e) {\n if (req.signal.aborted) throw new LLMComputeException({ kind: 'cancelled' })\n throw providerError('transient', `openai request failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n let text: string\n try {\n text = await response.text()\n } catch (e) {\n throw providerError('transient', `openai read body failed: ${e instanceof Error ? e.message : String(e)}`)\n }\n if (!response.ok) throw providerError(openaiHttpFailure(response.status, text), `openai http ${response.status}: ${truncateChars(text, 512)}`)\n let parsed: { choices?: { message?: { content?: unknown; tool_calls?: unknown[] }; finish_reason?: unknown }[]; usage?: Record<string, unknown>; model?: unknown }\n try {\n parsed = JSON.parse(text)\n } catch (e) {\n throw providerError('unknown', `openai invalid JSON: ${e instanceof Error ? e.message : String(e)}`)\n }\n const choice = parsed.choices?.[0]\n if (!choice) throw providerError('unknown', 'openai response has no choices')\n const message = choice.message ?? {}\n const content: AiMessage['content'] = []\n if (typeof message.content === 'string') content.push({ type: 'text', text: message.content })\n for (const c of (message.tool_calls ?? []) as { id?: string; function?: { name?: string; arguments?: string } }[]) {\n let args: AiToolCall['args'] = {}\n try {\n const v = JSON.parse(c.function?.arguments ?? '{}')\n if (v && typeof v === 'object' && !Array.isArray(v)) args = v\n } catch {\n args = {}\n }\n content.push({ type: 'tool_use', call_id: c.id ?? '', name: c.function?.name ?? '', args })\n }\n if (content.length === 0) content.push({ type: 'text', text: '' })\n const out: AiResponse = { message: { role: 'assistant', content } }\n if (typeof choice.finish_reason === 'string') out.finish_reason = choice.finish_reason\n const u = parsed.usage\n if (u) {\n out.usage = { request_units: 1 }\n if (typeof u.prompt_tokens === 'number') out.usage.input_tokens = u.prompt_tokens\n if (typeof u.completion_tokens === 'number') out.usage.output_tokens = u.completion_tokens\n if (typeof u.total_tokens === 'number') out.usage.total_tokens = u.total_tokens\n }\n if (typeof parsed.model === 'string') out.extra = { model: parsed.model }\n return out\n }\n}\n"],"names":["openaiHttpFailure","status","body","code","_b","parse","_a","error","refused","includes","contentToOpenai","content","parts","c","type","push","text","s","source","url","kind","mime","data_base64","obj_id","image_url","label","title","desc","only","length","messagesToOpenai","messages","out","m","role","textContent","calls","toolCalls","map","id","call_id","function","name","arguments","JSON","stringify","args","obj","tool_calls","b","tool_call_id","filter","join","constructor","options","this","baseUrl","trim","replace","apiKey","Error","infer","req","model","model_alias","temperature","max_completion_tokens","max_tokens","allow_tool_calls","tool_specs","tools","description","parameters","args_schema","tool_choice","force_json","response_format","json_schema","schema","anyJsonObjectSchema","provider_options","Array","isArray","Object","assign","f","fetch","globalThis","bind","response","parsed","method","headers","authorization","signal","e","aborted","LLMComputeException","providerError","message","String","ok","max","chars","slice","truncateChars","choice","choices","v","_c","finish_reason","u","usage","request_units","prompt_tokens","input_tokens","completion_tokens","output_tokens","total_tokens","extra"],"mappings":"mDAUgB,SAAAA,EAAkBC,EAAgBC,WAC5C,IAAAC,EACA,IACFA,EAAQ,OAAAC,EAAA,cAAKC,MAAMH,SAAX,EAAAI,EAAqDC,YAAO,EAAAH,EAAAD,IAAA,CAC9D,MACCA,OAAA,CACT,CACA,MAAa,4BAATA,E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- import { n as canonicalJson, r as rustTrim, o as jsonEqual, L as LLMComputeException, i as isObject, m as cloneJson, t as textMessage, q as nowMs, u as textContent, c as computeErrorMessage, v as validateResponse, w as toolCalls, a as asComputeError, x as toolObservationMessage, y as mergeUsage, l as llmCorrectable, f as rustTrimEnd, X as XllmError, z as rustTextContent, B as compareCodePoints, s as serdeJson, C as charOffset, D as collapseWhitespace, d as charCount, e as errorSource, E as addRecordUsage, F as refusedCode } from "./aicc-67851c41.mjs";
1
+ import { n as canonicalJson, r as rustTrim, o as jsonEqual, L as LLMComputeException, i as isObject, m as cloneJson, t as textMessage, q as nowMs, u as textContent, c as computeErrorMessage, v as validateResponse, w as toolCalls, a as asComputeError, x as toolObservationMessage, y as mergeUsage, l as llmCorrectable, f as rustTrimEnd, X as XllmError, z as rustTextContent, B as compareCodePoints, s as serdeJson, C as charOffset, D as collapseWhitespace, d as charCount, e as errorSource, E as addRecordUsage, F as refusedCode } from "./aicc-286ba457.mjs";
2
2
  function utf8Length(s) {
3
3
  let n = 0;
4
4
  for (let i = 0; i < s.length; i++) {
@@ -5144,7 +5144,7 @@ function stepRenderer(hosted) {
5144
5144
  return hosted ? new XmlStepRenderer().withoutTimestamps() : new XmlStepRenderer();
5145
5145
  }
5146
5146
  const REFUSED_QUOTA_EXHAUSTED = "quota_exhausted";
5147
- const REFUSED_QUOTA_BUDGET_EXCEEDED = "quota_budget_exceeded";
5147
+ const REFUSED_CREDIT_INSUFFICIENT = "credit_insufficient";
5148
5148
  const REFUSED_RESOURCE_NOT_PERMITTED = "resource_not_permitted";
5149
5149
  const REFUSED_ATTRIBUTION_UNAVAILABLE = "attribution_unavailable";
5150
5150
  const HOST_PROMPT_SECTIONS_ALL = { capabilities: true, cmd_manual: true, runtime_protocol: true };
@@ -6100,7 +6100,7 @@ function classifyError(err) {
6100
6100
  const code = refusedCode(f);
6101
6101
  if (code === REFUSED_CREDENTIALS)
6102
6102
  return rec(true, REFUSED_CREDENTIALS, "fix the credential referenced by the current identity, then resume");
6103
- const condition = code === REFUSED_QUOTA_EXHAUSTED || code === REFUSED_QUOTA_BUDGET_EXCEEDED ? "the AI token quota does not cover this call; wait for it to reset, lower the output budget, or ask an administrator; do not retry right away" : code === REFUSED_RESOURCE_NOT_PERMITTED ? "the model is not permitted to this user; choose a permitted model or ask an administrator" : code === REFUSED_ATTRIBUTION_UNAVAILABLE ? "the user whose AI resources this run uses cannot be determined" : "the AI service refused this call under its policy; do not retry right away";
6103
+ const condition = code === REFUSED_QUOTA_EXHAUSTED ? "an AI usage limit of this user is used up; wait for its window to reset or ask an administrator; do not retry right away" : code === REFUSED_CREDIT_INSUFFICIENT ? "the user's AI Credit balance is used up; ask an administrator to recharge it, or use a free model; do not retry right away" : code === REFUSED_RESOURCE_NOT_PERMITTED ? "the model is not permitted to this user; choose a permitted model or ask an administrator" : code === REFUSED_ATTRIBUTION_UNAVAILABLE ? "the user whose AI resources this run uses cannot be determined" : "the AI service refused this call under its policy; do not retry right away";
6104
6104
  return rec(false, code, condition);
6105
6105
  }
6106
6106
  case "checkpoint":
@@ -6498,4 +6498,4 @@ export {
6498
6498
  assemblePrompt as y,
6499
6499
  RUNTIME_PROTOCOL_VERSION as z
6500
6500
  };
6501
- //# sourceMappingURL=site_manager-604ee369.mjs.map
6501
+ //# sourceMappingURL=site_manager-4f1940eb.mjs.map