buckyos 0.7.123 → 0.7.124

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.
@@ -1169,6 +1169,7 @@ const AICC_AI_METHODS = {
1169
1169
  EMBEDDING_TEXT: "embedding.text",
1170
1170
  EMBEDDING_MULTIMODAL: "embedding.multimodal",
1171
1171
  RERANK: "rerank",
1172
+ DECISION_EVALUATE: "decision.evaluate",
1172
1173
  IMAGE_IMG2IMG: "image.img2img",
1173
1174
  IMAGE_INPAINT: "image.inpaint",
1174
1175
  IMAGE_UPSCALE: "image.upscale",
@@ -1200,6 +1201,7 @@ const AICC_MANAGEMENT_METHODS = {
1200
1201
  USAGE_QUERY: "usage.query",
1201
1202
  TRACE_QUERY: "trace.query",
1202
1203
  ROUTING_GET: "routing.get",
1204
+ ROUTING_PREVIEW: "routing.preview",
1203
1205
  ROUTING_UPDATE: "routing.update",
1204
1206
  PROVIDER_CATALOG: "provider.catalog",
1205
1207
  PROTOCOL_ADAPTER_LIST: "protocol_adapter.list",
@@ -1290,6 +1292,7 @@ const schemas = {
1290
1292
  [AICC_AI_METHODS.IMAGES_GENERATE]: [...common, "prompt", "negative_prompt", "n", "aspect_ratio", "size", "quality", "style", "seed", "output"],
1291
1293
  [AICC_AI_METHODS.EMBEDDING_TEXT]: [...common, "items", "chunking", "embedding_space_id", "dimensions", "normalize", "prefer_artifact"],
1292
1294
  [AICC_AI_METHODS.EMBEDDING_MULTIMODAL]: [...common, "items", "dimensions", "normalize"],
1295
+ [AICC_AI_METHODS.DECISION_EVALUATE]: [...common, "state", "questions"],
1293
1296
  [AICC_AI_METHODS.RERANK]: [...common, "query", "documents", "n", "return_documents"],
1294
1297
  [AICC_AI_METHODS.IMAGE_IMG2IMG]: [...common, "images", "prompt", "strength", "output"],
1295
1298
  [AICC_AI_METHODS.IMAGE_INPAINT]: [...common, "image", "mask", "prompt", "mask_semantics", "output"],
@@ -1318,6 +1321,7 @@ const schemas = {
1318
1321
  [AICC_MANAGEMENT_METHODS.USAGE_QUERY]: ["time_range", "filters", "group_by", "time_bucket", "output_mode", "limit", "cursor"],
1319
1322
  [AICC_MANAGEMENT_METHODS.TRACE_QUERY]: ["limit", "cursor", "start_time_ms", "end_time_ms", "task_ids", "request_ids", "api_types", "provider_instance_names", "selected_exact_models", "scheduler_profiles", "query", "outcome"],
1320
1323
  [AICC_MANAGEMENT_METHODS.ROUTING_GET]: [],
1324
+ [AICC_MANAGEMENT_METHODS.ROUTING_PREVIEW]: ["paths", "explain", "requirements"],
1321
1325
  [AICC_MANAGEMENT_METHODS.ROUTING_UPDATE]: ["settings_revision", "provider_weights"],
1322
1326
  [AICC_MANAGEMENT_METHODS.PROVIDER_CATALOG]: [],
1323
1327
  [AICC_MANAGEMENT_METHODS.PROTOCOL_ADAPTER_LIST]: [],
@@ -1376,6 +1380,13 @@ class AiccClient {
1376
1380
  embeddingMultimodal(r) {
1377
1381
  return this.inference(AICC_AI_METHODS.EMBEDDING_MULTIMODAL, r);
1378
1382
  }
1383
+ async decisionEvaluate(r) {
1384
+ validateDecisionRequest(r);
1385
+ const result = await this.inference(AICC_AI_METHODS.DECISION_EVALUATE, r);
1386
+ if (result.status === "succeeded")
1387
+ validateDecisionAnswers(r, result.answers ?? []);
1388
+ return result;
1389
+ }
1379
1390
  rerank(r) {
1380
1391
  return this.inference(AICC_AI_METHODS.RERANK, r);
1381
1392
  }
@@ -1450,6 +1461,9 @@ class AiccClient {
1450
1461
  queryTrace(r = {}) {
1451
1462
  return this.call(AICC_MANAGEMENT_METHODS.TRACE_QUERY, r);
1452
1463
  }
1464
+ previewRouting(r = {}) {
1465
+ return this.call(AICC_MANAGEMENT_METHODS.ROUTING_PREVIEW, r);
1466
+ }
1453
1467
  getRouting() {
1454
1468
  return this.call(AICC_MANAGEMENT_METHODS.ROUTING_GET, {});
1455
1469
  }
@@ -1494,6 +1508,132 @@ class AiccClient {
1494
1508
  return this.call(AICC_MANAGEMENT_METHODS.DRIVER_METADATA_UPDATE_SET, r);
1495
1509
  }
1496
1510
  }
1511
+ function decisionText(value, nonempty = true) {
1512
+ if (typeof value === "string")
1513
+ return !nonempty || value.trim().length > 0;
1514
+ return value !== null && typeof value === "object" && (!nonempty || Object.keys(value).length > 0);
1515
+ }
1516
+ function decisionId(value) {
1517
+ return typeof value === "string" && /^[A-Za-z0-9_.-]{1,128}$/.test(value);
1518
+ }
1519
+ function decisionJson(value) {
1520
+ if (value === null || typeof value !== "object")
1521
+ return JSON.stringify(value);
1522
+ if (Array.isArray(value))
1523
+ return `[${value.map(decisionJson).join(",")}]`;
1524
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${decisionJson(value[key])}`).join(",")}}`;
1525
+ }
1526
+ function decisionBytes(value) {
1527
+ return new TextEncoder().encode(JSON.stringify(value)).length;
1528
+ }
1529
+ function decisionRequirements(request) {
1530
+ const stateBytes = decisionBytes(request.state);
1531
+ const decision = {
1532
+ question_types: [],
1533
+ structured_state: typeof request.state !== "string",
1534
+ structured_rules: false,
1535
+ question_count: request.questions.length,
1536
+ max_options: 0,
1537
+ max_levels: 0,
1538
+ input_bytes: stateBytes + decisionBytes(request.questions),
1539
+ max_state_question_bytes: 0
1540
+ };
1541
+ for (const question of request.questions) {
1542
+ if (!decision.question_types.includes(question.type))
1543
+ decision.question_types.push(question.type);
1544
+ const rules = [question.instructions];
1545
+ if (question.type === "choice") {
1546
+ decision.max_options = Math.max(decision.max_options, question.options.length);
1547
+ rules.push(...question.options.map((option) => option.description));
1548
+ } else if (question.type === "score") {
1549
+ decision.max_levels = Math.max(decision.max_levels, question.levels.length);
1550
+ rules.push(...question.levels);
1551
+ } else if (question.criteria)
1552
+ rules.push(...Object.values(question.criteria));
1553
+ decision.structured_rules || (decision.structured_rules = rules.some((value) => value !== null && typeof value === "object"));
1554
+ decision.max_state_question_bytes = Math.max(decision.max_state_question_bytes, stateBytes + decisionBytes(question));
1555
+ }
1556
+ return { decision };
1557
+ }
1558
+ function validateDecisionRequest(request) {
1559
+ exact(request.exact_model);
1560
+ strict(request, schemas[AICC_AI_METHODS.DECISION_EVALUATE]);
1561
+ if (!decisionText(request.state, false) || !Array.isArray(request.questions) || !request.questions.length || request.questions.length > 1024) {
1562
+ throw new RPCError("decision requires a text/JSON state and 1..1024 questions");
1563
+ }
1564
+ const ids = /* @__PURE__ */ new Set();
1565
+ for (const question of request.questions) {
1566
+ if (!question || !decisionId(question.id) || ids.has(question.id) || !decisionText(question.instructions))
1567
+ throw new RPCError("invalid decision question");
1568
+ ids.add(question.id);
1569
+ if (question.type === "choice") {
1570
+ strict(question, ["type", "id", "instructions", "options"]);
1571
+ if (!Array.isArray(question.options) || !question.options.length || question.options.length > 1024)
1572
+ throw new RPCError("invalid decision options");
1573
+ const options = /* @__PURE__ */ new Set();
1574
+ for (const option of question.options) {
1575
+ strict(option, ["id", "description"]);
1576
+ if (!decisionId(option.id) || options.has(option.id) || !(option.description === null || decisionText(option.description)))
1577
+ throw new RPCError("invalid decision option");
1578
+ options.add(option.id);
1579
+ }
1580
+ } else if (question.type === "score") {
1581
+ strict(question, ["type", "id", "instructions", "levels"]);
1582
+ if (!Array.isArray(question.levels) || question.levels.length < 2 || question.levels.length > 1024 || question.levels.some((level) => !decisionText(level)) || new Set(question.levels.map(decisionJson)).size !== question.levels.length)
1583
+ throw new RPCError("invalid decision levels");
1584
+ } else if (question.type === "boolean") {
1585
+ strict(question, ["type", "id", "instructions", "criteria"]);
1586
+ if (question.criteria !== void 0) {
1587
+ if (question.criteria === null || typeof question.criteria !== "object" || Array.isArray(question.criteria))
1588
+ throw new RPCError("invalid decision criteria");
1589
+ strict(question.criteria, ["true", "false"]);
1590
+ if (Object.values(question.criteria).some((value) => !decisionText(value)))
1591
+ throw new RPCError("invalid decision criteria");
1592
+ }
1593
+ } else
1594
+ throw new RPCError("invalid decision question type");
1595
+ }
1596
+ if (decisionRequirements(request).decision.input_bytes > 1024 * 1024)
1597
+ throw new RPCError("decision input exceeds 1 MiB");
1598
+ }
1599
+ function validateDecisionAnswers(request, answers) {
1600
+ const probability = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
1601
+ const invalid = () => {
1602
+ throw new RPCError("invalid or incomplete decision answers");
1603
+ };
1604
+ if (!Array.isArray(answers) || answers.length !== request.questions.length)
1605
+ invalid();
1606
+ const ids = /* @__PURE__ */ new Set();
1607
+ for (const answer of answers) {
1608
+ if (!answer || ids.has(answer.id))
1609
+ invalid();
1610
+ ids.add(answer.id);
1611
+ const question = request.questions.find((question2) => question2.id === answer.id);
1612
+ if (!question)
1613
+ throw new RPCError("unknown decision question ID");
1614
+ if (question.type !== answer.type || answer.confidence !== void 0 && !probability(answer.confidence))
1615
+ invalid();
1616
+ if (answer.type === "boolean") {
1617
+ strict(answer, ["type", "id", "probability_true", "confidence"]);
1618
+ if (!probability(answer.probability_true))
1619
+ invalid();
1620
+ continue;
1621
+ }
1622
+ strict(answer, answer.type === "choice" ? ["type", "id", "selected", "probabilities", "confidence"] : ["type", "id", "score", "levels", "probabilities", "confidence"]);
1623
+ const keys = question.type === "choice" ? question.options.map((option) => option.id) : question.type === "score" ? question.levels.map((_, i) => String(i)) : [];
1624
+ if (!answer.probabilities || Array.isArray(answer.probabilities) || Object.keys(answer.probabilities).length !== keys.length || keys.some((key) => !Object.prototype.hasOwnProperty.call(answer.probabilities, key) || !probability(answer.probabilities[key])) || Math.abs(Object.values(answer.probabilities).reduce((sum, p) => sum + p, 0) - 1) > 1e-4)
1625
+ invalid();
1626
+ if (answer.type === "choice") {
1627
+ if (!keys.includes(answer.selected) || Object.values(answer.probabilities).some((p) => p > answer.probabilities[answer.selected] + 1e-4))
1628
+ invalid();
1629
+ } else if (answer.type === "score" && question.type === "score") {
1630
+ const expected = keys.reduce((sum, key, i) => sum + i * answer.probabilities[key], 0);
1631
+ if (!Number.isFinite(answer.score) || answer.score < 0 || answer.score > keys.length - 1 || Math.abs(answer.score - expected) > 1e-4 * (keys.length - 1) || decisionJson(answer.levels) !== decisionJson(question.levels))
1632
+ invalid();
1633
+ } else
1634
+ invalid();
1635
+ }
1636
+ }
1497
1637
  const DEFAULT_QUEUE_CONFIG = {
1498
1638
  max_messages: null,
1499
1639
  retention_seconds: null,
@@ -28306,7 +28446,7 @@ export {
28306
28446
  TASK_ERR_STALE_RUNNER_EPOCH as Z,
28307
28447
  TASK_ERR_INVALID_PHASE as _,
28308
28448
  ndm_proxy as a,
28309
- BNS_DNS_TXT_DEFAULT_TTL as a$,
28449
+ BNS_EVM_DEFAULT_MAX_FEE_PER_GAS as a$,
28310
28450
  TASK_ERR_CONTROL_ALREADY_PENDING as a0,
28311
28451
  TASK_ERR_ALREADY_COMPLETED as a1,
28312
28452
  TASK_ERR_INPUT_SCHEMA_MISMATCH as a2,
@@ -28333,17 +28473,17 @@ export {
28333
28473
  aiccMessageFirstText as aN,
28334
28474
  validateAiccMessage as aO,
28335
28475
  AiccClient as aP,
28336
- KEventReader as aQ,
28337
- KEventClient as aR,
28338
- appIdFromDid as aS,
28339
- parseAppId as aT,
28340
- appDidFromId as aU,
28341
- createAppInstanceId as aV,
28342
- parseAppInstanceId as aW,
28343
- BNS_EVM_DEFAULT_GAS_LIMIT as aX,
28344
- BNS_EVM_DEFAULT_MAX_FEE_PER_GAS as aY,
28345
- BNS_EVM_DEFAULT_MAX_PRIORITY_FEE_PER_GAS as aZ,
28346
- BNS_MAX_INLINE_DOCUMENT_BYTES as a_,
28476
+ decisionRequirements as aQ,
28477
+ validateDecisionRequest as aR,
28478
+ validateDecisionAnswers as aS,
28479
+ KEventReader as aT,
28480
+ KEventClient as aU,
28481
+ appIdFromDid as aV,
28482
+ parseAppId as aW,
28483
+ appDidFromId as aX,
28484
+ createAppInstanceId as aY,
28485
+ parseAppInstanceId as aZ,
28486
+ BNS_EVM_DEFAULT_GAS_LIMIT as a_,
28347
28487
  TaskExecutorKind as aa,
28348
28488
  TaskPhase as ab,
28349
28489
  isTerminalTaskPhase as ac,
@@ -28371,14 +28511,17 @@ export {
28371
28511
  WorkflowScheduledTaskMisfirePolicy as ay,
28372
28512
  WorkflowScheduledTaskFireStatus as az,
28373
28513
  bns_client as b,
28374
- BNS_DNS_TXT_DOC_TYPE as b0,
28375
- BNS_PUBLISH_DOCUMENT_ABI as b1,
28376
- BnsEvmTxError as b2,
28377
- BnsEvmTxBuilder as b3,
28378
- decodeBnsPublishDocumentCalldata as b4,
28379
- BnsTxExecutorError as b5,
28380
- walletUserHasSnAccount as b6,
28381
- BnsTxExecutor as b7,
28514
+ BNS_EVM_DEFAULT_MAX_PRIORITY_FEE_PER_GAS as b0,
28515
+ BNS_MAX_INLINE_DOCUMENT_BYTES as b1,
28516
+ BNS_DNS_TXT_DEFAULT_TTL as b2,
28517
+ BNS_DNS_TXT_DOC_TYPE as b3,
28518
+ BNS_PUBLISH_DOCUMENT_ABI as b4,
28519
+ BnsEvmTxError as b5,
28520
+ BnsEvmTxBuilder as b6,
28521
+ decodeBnsPublishDocumentCalldata as b7,
28522
+ BnsTxExecutorError as b8,
28523
+ walletUserHasSnAccount as b9,
28524
+ BnsTxExecutor as ba,
28382
28525
  createSDKModule as c,
28383
28526
  BS_SERVICE_TASK_MANAGER as d,
28384
28527
  getActiveRuntimeType as e,
@@ -28404,4 +28547,4 @@ export {
28404
28547
  WORKFLOW_SCHEDULE_TASK_SCHEMA_ID as y,
28405
28548
  WORKFLOW_SEND_MESSAGE_TASK_SCHEMA_ID as z
28406
28549
  };
28407
- //# sourceMappingURL=ndm_proxy-3fce55e8.mjs.map
28550
+ //# sourceMappingURL=ndm_proxy-ebc5a1bf.mjs.map