buckyos 0.7.183 → 0.7.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/dist/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import * as nodePath from "node:path";
4
4
  import { resolve as resolve$5, dirname as dirname$3 } from "node:path";
5
5
  import { BuckyOSSDK, RuntimeType, buckyos, namelib, VerifyHubClient, createAppInstanceId, parseSessionTokenClaims, ndn, verifyBundle, controlSkeleton, aiwsContentDigest, AIWS_MANIFEST_VERSION, AIWS_MANIFEST_FILE, taskMgrTaskEventPath, ndm_proxy, objectUrl as objectUrl$1, ExecutorCommandStream, AiwsFailure, viewerTimeZone, localDate, calendarOccurrences, ScheduleClient, resolveBindings, noUiDialogs, createOps, orderKeyBetween, bindingsPayload, AIWS_PROTOCOL_VERSION, BindFailure, aiwsTarget, watchControl, buildControl, pullControl, exportBundle, tableDelete, optionAdd, fieldAdd, tableSet, tableInsert, textAppend, textDeleteBlocks, textReplaceBlock, move, rename, setProps, NfspClient, AiwsSourceError, packBuildFiles, commitOps, templateDir, isSourcePath } from "buckyos/node";
6
6
  import * as provisionSdk from "buckyos/provision";
7
- import { AiccLlmClient, LLMComputeException, providerErrorFromRpc } from "buckyos/xllm";
7
+ import { providerErrorFromRpc, AiccLlmClient, LLMComputeException } from "buckyos/xllm";
8
8
  import { createHash } from "node:crypto";
9
9
  import { readFile, writeFile, readdir, stat, lstat, realpath, mkdtemp, rename as rename$1, rm, mkdir, chmod, symlink, copyFile, open } from "node:fs/promises";
10
10
  import { createReadStream, createWriteStream, existsSync } from "node:fs";
@@ -6115,7 +6115,7 @@ async function readSkillDirectory(root, limit) {
6115
6115
  await walk(realRoot, "");
6116
6116
  return { files, ignored };
6117
6117
  }
6118
- const PACKAGE_VERSION = "0.7.183";
6118
+ const PACKAGE_VERSION = "0.7.184";
6119
6119
  const TOOL_VERSION = PACKAGE_VERSION;
6120
6120
  const SDK_VERSION = PACKAGE_VERSION;
6121
6121
  const PROTOCOL_VERSION = "1";
@@ -13814,7 +13814,7 @@ const placeCommand = {
13814
13814
  const entities = (await call(ctx, "doc.outline", { workspace_id: ws })).entities;
13815
13815
  const byId = new Map(entities.map((e) => [e.entity_id, e]));
13816
13816
  const surface = byId.get(surfaceId);
13817
- if (!surface || surface.kind !== "surface") {
13817
+ if (!surface || surface.kind !== "surface" || surface.path_only) {
13818
13818
  throw new UsageError("AIWS_USAGE", `${surfaceId} is not a canvas of this workspace`);
13819
13819
  }
13820
13820
  const folderId = String(surface.content_folder_id ?? "");
@@ -14388,7 +14388,7 @@ async function markdownInput(input) {
14388
14388
  const tableCommand = {
14389
14389
  verb: "table",
14390
14390
  summary: "Write a table: `add <table> --values` (records), `set <table> <record_id> --values` (cells), `rm <table> <record_id>[,…]`, `field-add <table> --name --type`, `option-add <table> <field> <label>`",
14391
- description: '--values is JSON keyed by field name with display values (a select takes its label, a multi-select labels, a reference an entity id; null clears a cell on set); add takes an object or an array of them, "_id" naming a record id. Each change is expected at the version just read: a concurrent change of the same cell is a REVISION_CONFLICT (read again). field-add --type: text, number, decimal, boolean, date, datetime, select, multi_select, object_ref, currency, json; --options gives a select its labels.',
14391
+ description: '--values is JSON keyed by field name with display values (a select takes its label, a multi-select labels, a reference an entity id; null clears a cell on set); add takes an object or an array of them, "_id" naming a record id. Each change is expected at the version just read: a concurrent change of the same cell is a REVISION_CONFLICT (read again). field-add --type: text, number, decimal, boolean, date, datetime, select, multi_select, object_ref, currency, json; --options gives a select its labels; --default is what new records get when they do not give the field (a display value, like --values: a select takes its label; not on object_ref).',
14392
14392
  positionals: [
14393
14393
  { name: "action", description: "add | set | rm | field-add | option-add", required: true },
14394
14394
  { name: "table", description: `The table: ${PATH_HELP}`, required: true },
@@ -14400,7 +14400,8 @@ const tableCommand = {
14400
14400
  { name: "values", property: "values", description: "add / set: JSON keyed by field name", type: "string" },
14401
14401
  { name: "name", property: "name", description: "field-add: the field name", type: "string" },
14402
14402
  { name: "type", property: "type", description: "field-add: the field type", type: "string", enum: ["text", "number", "decimal", "boolean", "date", "datetime", "select", "multi_select", "object_ref", "currency", "json"] },
14403
- { name: "options", property: "options", description: "field-add: option labels of a select, a JSON array or comma-separated", type: "string" }
14403
+ { name: "options", property: "options", description: "field-add: option labels of a select, a JSON array or comma-separated", type: "string" },
14404
+ { name: "default", property: "default", description: "field-add: the value new records get when they do not give the field (display form)", type: "string" }
14404
14405
  ],
14405
14406
  inputSchema: workspaceInput({
14406
14407
  action: { type: "string", enum: ["add", "set", "rm", "field-add", "option-add"] },
@@ -14410,7 +14411,8 @@ const tableCommand = {
14410
14411
  values: { type: "string" },
14411
14412
  name: { type: "string" },
14412
14413
  type: { type: "string" },
14413
- options: { type: "string" }
14414
+ options: { type: "string" },
14415
+ default: { type: "string" }
14414
14416
  }, ["action", "table"]),
14415
14417
  outputSchema: OBJECT_OUTPUT,
14416
14418
  resultSchemaVersion: 1,
@@ -14422,6 +14424,7 @@ const tableCommand = {
14422
14424
  `buckyos aiws table set /data/销售 r123 --values '{"状态":"已完成"}' --workspace ws_abc`,
14423
14425
  "buckyos aiws table rm /data/销售 r123,r124 --workspace ws_abc",
14424
14426
  "buckyos aiws table field-add /data/销售 --name 负责人 --type text --workspace ws_abc",
14427
+ "buckyos aiws table field-add /data/销售 --name 阶段 --type select --options 线索,成交 --default 线索 --workspace ws_abc",
14425
14428
  "buckyos aiws table option-add /data/销售 状态 已取消 --workspace ws_abc"
14426
14429
  ],
14427
14430
  handler: (ctx, input) => writing(async () => {
@@ -14462,7 +14465,8 @@ const tableCommand = {
14462
14465
  case "field-add": {
14463
14466
  const options = inputString(input, "options");
14464
14467
  const labels = options === void 0 ? void 0 : options.startsWith("[") ? jsonArg(options, "--options") : ids(options);
14465
- const op = fieldAdd(table, { name: requiredInputString(input, "name"), type: requiredInputString(input, "type"), ...labels ? { options: labels } : {} });
14468
+ const fallback = inputString(input, "default");
14469
+ const op = fieldAdd(table, { name: requiredInputString(input, "name"), type: requiredInputString(input, "type"), ...labels ? { options: labels } : {}, ...fallback !== void 0 ? { default: fallback } : {} });
14466
14470
  const field = op.field;
14467
14471
  return { ...await commit(ctx, ws, [op], `add field ${requiredInputString(input, "name")}`), table: table.entity_id, field_id: field.field_id, ...field.options ? { options: field.options } : {} };
14468
14472
  }
@@ -14725,6 +14729,23 @@ const REFUSALS = {
14725
14729
  attribution_unavailable: "AI_ATTRIBUTION_UNAVAILABLE",
14726
14730
  credentials: "AI_UNAVAILABLE"
14727
14731
  };
14732
+ function refusalOf(error) {
14733
+ if (error instanceof LLMComputeException && error.error.kind === "provider" && typeof error.error.failure === "object" && "refused" in error.error.failure) {
14734
+ const e = new Error(error.message);
14735
+ e.code = REFUSALS[error.error.failure.refused.code] ?? "AI_QUOTA_EXHAUSTED";
14736
+ return e;
14737
+ }
14738
+ return error;
14739
+ }
14740
+ function sessionAicc(ctx) {
14741
+ return async (method, params) => {
14742
+ try {
14743
+ return await ctx.clients.call("aicc", method, params, rpcOptions$2(ctx));
14744
+ } catch (error) {
14745
+ throw refusalOf(providerErrorFromRpc(`aicc ${method} failed`, error));
14746
+ }
14747
+ };
14748
+ }
14728
14749
  function sessionInfer(ctx) {
14729
14750
  const call2 = async (method, params) => {
14730
14751
  try {
@@ -14751,12 +14772,7 @@ function sessionInfer(ctx) {
14751
14772
  });
14752
14773
  return { text: r.message.content.map((c) => c.type === "text" ? c.text ?? "" : "").join(""), tokens: r.usage?.output_tokens };
14753
14774
  } catch (error) {
14754
- if (error instanceof LLMComputeException && error.error.kind === "provider" && typeof error.error.failure === "object" && "refused" in error.error.failure) {
14755
- const e = new Error(error.message);
14756
- e.code = REFUSALS[error.error.failure.refused.code] ?? "AI_QUOTA_EXHAUSTED";
14757
- throw e;
14758
- }
14759
- throw error;
14775
+ throw refusalOf(error);
14760
14776
  }
14761
14777
  };
14762
14778
  }
@@ -14798,6 +14814,9 @@ async function execMacro(ctx, input) {
14798
14814
  return { status: res.status, headers, base64: btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join("")) };
14799
14815
  }
14800
14816
  },
14817
+ aicc: sessionAicc(ctx),
14818
+ task: (id) => ctx.clients.call("task-manager", "get_task", { task_id: id }, rpcOptions$2(ctx)),
14819
+ importAsset: (objId) => aiws(ctx, "asset.import_object", { workspace_id: ids2.workspace_id, obj_id: objId }),
14801
14820
  zoneHosts: [zoneHost],
14802
14821
  zoneOrigin: origin,
14803
14822
  budget,
@@ -14819,11 +14838,18 @@ async function execMacro(ctx, input) {
14819
14838
  const cap = Number(budget.program_timeout_secs) || 120;
14820
14839
  const limit = Math.min(cap, Number(manifest?.resources?.timeout_secs) || cap);
14821
14840
  let timedOut = false;
14822
- const timer = setTimeout(() => {
14823
- timedOut = true;
14824
- child.kill();
14825
- }, limit * 1e3);
14841
+ const started = Date.now();
14842
+ let media = 0;
14843
+ let mediaSince = 0;
14844
+ let mediaMs = 0;
14845
+ const timer = setInterval(() => {
14846
+ if (Date.now() - started - mediaMs - (media ? Date.now() - mediaSince : 0) > limit * 1e3) {
14847
+ timedOut = true;
14848
+ child.kill();
14849
+ }
14850
+ }, 1e3);
14826
14851
  const out = [];
14852
+ const pending = /* @__PURE__ */ new Set();
14827
14853
  try {
14828
14854
  for await (const line of child.lines()) {
14829
14855
  if (!line.startsWith(BRIDGE_PREFIX)) {
@@ -14831,10 +14857,19 @@ async function execMacro(ctx, input) {
14831
14857
  continue;
14832
14858
  }
14833
14859
  const msg = JSON.parse(line.slice(BRIDGE_PREFIX.length));
14834
- await child.writeLine(JSON.stringify({ id: msg.id, body: await bridge.handle(msg.op, msg.req) }));
14860
+ const waiting = msg.op === "ai.image" || msg.op === "ai.video";
14861
+ if (waiting && media++ === 0)
14862
+ mediaSince = Date.now();
14863
+ const answer = bridge.handle(msg.op, msg.req).then((body) => child.writeLine(JSON.stringify({ id: msg.id, body }))).finally(() => {
14864
+ if (waiting && --media === 0)
14865
+ mediaMs += Date.now() - mediaSince;
14866
+ pending.delete(answer);
14867
+ });
14868
+ pending.add(answer);
14835
14869
  }
14870
+ await Promise.allSettled([...pending]);
14836
14871
  } finally {
14837
- clearTimeout(timer);
14872
+ clearInterval(timer);
14838
14873
  await child.closeInput();
14839
14874
  }
14840
14875
  const code = await child.status;