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.
@@ -461,7 +461,7 @@ async function markdownInput(input: Record<string, unknown>): Promise<string> {
461
461
  const tableCommand: CommandDefinition = {
462
462
  verb: 'table',
463
463
  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>`',
464
- 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.',
464
+ 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).',
465
465
  positionals: [
466
466
  { name: 'action', description: 'add | set | rm | field-add | option-add', required: true },
467
467
  { name: 'table', description: `The table: ${PATH_HELP}`, required: true },
@@ -474,10 +474,11 @@ const tableCommand: CommandDefinition = {
474
474
  { name: 'name', property: 'name', description: 'field-add: the field name', type: 'string' },
475
475
  { 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'] },
476
476
  { name: 'options', property: 'options', description: 'field-add: option labels of a select, a JSON array or comma-separated', type: 'string' },
477
+ { name: 'default', property: 'default', description: 'field-add: the value new records get when they do not give the field (display form)', type: 'string' },
477
478
  ],
478
479
  inputSchema: workspaceInput({
479
480
  action: { type: 'string', enum: ['add', 'set', 'rm', 'field-add', 'option-add'] }, table: { type: 'string', minLength: 1 }, target: { type: 'string' }, label: { type: 'string' },
480
- values: { type: 'string' }, name: { type: 'string' }, type: { type: 'string' }, options: { type: 'string' },
481
+ values: { type: 'string' }, name: { type: 'string' }, type: { type: 'string' }, options: { type: 'string' }, default: { type: 'string' },
481
482
  }, ['action', 'table']),
482
483
  outputSchema: OBJECT_OUTPUT,
483
484
  resultSchemaVersion: 1,
@@ -489,6 +490,7 @@ const tableCommand: CommandDefinition = {
489
490
  'buckyos aiws table set /data/销售 r123 --values \'{"状态":"已完成"}\' --workspace ws_abc',
490
491
  'buckyos aiws table rm /data/销售 r123,r124 --workspace ws_abc',
491
492
  'buckyos aiws table field-add /data/销售 --name 负责人 --type text --workspace ws_abc',
493
+ 'buckyos aiws table field-add /data/销售 --name 阶段 --type select --options 线索,成交 --default 线索 --workspace ws_abc',
492
494
  'buckyos aiws table option-add /data/销售 状态 已取消 --workspace ws_abc',
493
495
  ],
494
496
  handler: (ctx, input) => writing(async () => {
@@ -526,7 +528,8 @@ const tableCommand: CommandDefinition = {
526
528
  case 'field-add': {
527
529
  const options = inputString(input, 'options')
528
530
  const labels = options === undefined ? undefined : options.startsWith('[') ? jsonArg(options, '--options') as string[] : ids(options)
529
- const op = fieldAdd(table, { name: requiredInputString(input, 'name'), type: requiredInputString(input, 'type'), ...(labels ? { options: labels } : {}) })
531
+ const fallback = inputString(input, 'default')
532
+ const op = fieldAdd(table, { name: requiredInputString(input, 'name'), type: requiredInputString(input, 'type'), ...(labels ? { options: labels } : {}), ...(fallback !== undefined ? { default: fallback } : {}) })
530
533
  const field = op.field as { field_id: string; options?: unknown[] }
531
534
  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 } : {}) }
532
535
  }
@@ -796,6 +799,27 @@ const REFUSALS: Record<string, string> = {
796
799
 
797
800
  interface MacroRun { source: string; results: unknown; log: string; code: number }
798
801
 
802
+ /** An AICC refusal as the run's sub-code (AI_QUOTA_EXHAUSTED…), anything else as it came. */
803
+ function refusalOf(error: unknown): unknown {
804
+ if (error instanceof LLMComputeException && error.error.kind === 'provider' && typeof error.error.failure === 'object' && 'refused' in error.error.failure) {
805
+ const e = new Error(error.message) as Error & { code?: string }
806
+ e.code = REFUSALS[error.error.failure.refused.code] ?? 'AI_QUOTA_EXHAUSTED'
807
+ return e
808
+ }
809
+ return error
810
+ }
811
+
812
+ /** One AICC call of a macro's generated picture or clip, with this session; a refusal carries the run's sub-code. */
813
+ function sessionAicc(ctx: CommandContext) {
814
+ return async (method: string, params: Record<string, unknown>) => {
815
+ try {
816
+ return await ctx.clients.call('aicc', method, params, rpcOptions(ctx))
817
+ } catch (error) {
818
+ throw refusalOf(providerErrorFromRpc(`aicc ${method} failed`, error))
819
+ }
820
+ }
821
+ }
822
+
799
823
  /** One inference with this session's AICC; a refusal carries the run's sub-code. */
800
824
  function sessionInfer(ctx: CommandContext) {
801
825
  const call = async (method: string, params: unknown) => {
@@ -815,12 +839,7 @@ function sessionInfer(ctx: CommandContext) {
815
839
  })
816
840
  return { text: r.message.content.map((c) => (c.type === 'text' ? c.text ?? '' : '')).join(''), tokens: r.usage?.output_tokens }
817
841
  } catch (error) {
818
- if (error instanceof LLMComputeException && error.error.kind === 'provider' && typeof error.error.failure === 'object' && 'refused' in error.error.failure) {
819
- const e = new Error(error.message) as Error & { code?: string }
820
- e.code = REFUSALS[error.error.failure.refused.code] ?? 'AI_QUOTA_EXHAUSTED'
821
- throw e
822
- }
823
- throw error
842
+ throw refusalOf(error)
824
843
  }
825
844
  }
826
845
  }
@@ -855,6 +874,9 @@ async function execMacro(ctx: CommandContext, input: Record<string, unknown>): P
855
874
  res.headers.forEach((v, k) => { headers[k] = v })
856
875
  try { return { status: res.status, headers, text: new TextDecoder('utf-8', { fatal: true }).decode(bytes) } } catch { return { status: res.status, headers, base64: btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join('')) } }
857
876
  },
877
+ aicc: sessionAicc(ctx),
878
+ task: (id: string) => ctx.clients.call('task-manager', 'get_task', { task_id: id }, rpcOptions(ctx)),
879
+ importAsset: (objId: string) => aiws(ctx, 'asset.import_object', { workspace_id: ids.workspace_id, obj_id: objId }),
858
880
  zoneHosts: [zoneHost], zoneOrigin: origin, budget, manifest,
859
881
  })
860
882
  await host.remove(`${dir}/output/.aiws/results.json`).catch(() => undefined)
@@ -866,16 +888,31 @@ async function execMacro(ctx: CommandContext, input: Record<string, unknown>): P
866
888
  const cap = Number(budget.program_timeout_secs) || 120
867
889
  const limit = Math.min(cap, Number(manifest?.resources?.timeout_secs) || cap)
868
890
  let timedOut = false
869
- const timer = setTimeout(() => { timedOut = true; child.kill() }, limit * 1000)
891
+ // the time the macro itself took: waits for generated pictures and clips have their own limit
892
+ const started = Date.now()
893
+ let media = 0
894
+ let mediaSince = 0
895
+ let mediaMs = 0
896
+ const timer = setInterval(() => {
897
+ if (Date.now() - started - mediaMs - (media ? Date.now() - mediaSince : 0) > limit * 1000) { timedOut = true; child.kill() }
898
+ }, 1000)
870
899
  const out: string[] = []
900
+ const pending = new Set<Promise<void>>()
871
901
  try {
872
902
  for await (const line of child.lines()) {
873
903
  if (!line.startsWith(BRIDGE_PREFIX)) { out.push(line); continue }
874
904
  const msg = JSON.parse(line.slice(BRIDGE_PREFIX.length)) as { id: number; op: string; req: unknown }
875
- await child.writeLine(JSON.stringify({ id: msg.id, body: await bridge.handle(msg.op, msg.req) }))
905
+ // answered as they come: a macro that generates several pictures at once waits for the slowest, not the sum
906
+ const waiting = msg.op === 'ai.image' || msg.op === 'ai.video'
907
+ if (waiting && media++ === 0) mediaSince = Date.now()
908
+ const answer: Promise<void> = bridge.handle(msg.op, msg.req)
909
+ .then((body) => child.writeLine(JSON.stringify({ id: msg.id, body })))
910
+ .finally(() => { if (waiting && --media === 0) mediaMs += Date.now() - mediaSince; pending.delete(answer) })
911
+ pending.add(answer)
876
912
  }
913
+ await Promise.allSettled([...pending])
877
914
  } finally {
878
- clearTimeout(timer)
915
+ clearInterval(timer)
879
916
  await child.closeInput()
880
917
  }
881
918
  const code = await child.status
@@ -39,6 +39,8 @@ type Envelope = Record<string, unknown> & {
39
39
  parent_id?: string | null
40
40
  order_key?: string | null
41
41
  deleted?: boolean
42
+ /** a path node: an entity the caller cannot read, listed above one it can (no name, no content) */
43
+ path_only?: boolean
42
44
  }
43
45
  // the shapes of buckyos-websdk aiws_bind.ts (the CLI reads the SDK's built JavaScript)
44
46
  type BindingDecl = {
@@ -204,7 +206,7 @@ export const placeCommand: CommandDefinition = {
204
206
  const entities = (await call(ctx, 'doc.outline', { workspace_id: ws })).entities as Envelope[]
205
207
  const byId = new Map(entities.map((e) => [e.entity_id, e]))
206
208
  const surface = byId.get(surfaceId)
207
- if (!surface || surface.kind !== 'surface') {
209
+ if (!surface || surface.kind !== 'surface' || surface.path_only) {
208
210
  throw new UsageError('AIWS_USAGE', `${surfaceId} is not a canvas of this workspace`)
209
211
  }
210
212
  const folderId = String(surface.content_folder_id ?? '')
package/cli/version.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Generated by scripts/generate-cli-version.mjs. Do not edit.
2
- export const PACKAGE_VERSION = '0.7.183'
2
+ export const PACKAGE_VERSION = '0.7.184'
3
3
  export const TOOL_VERSION = PACKAGE_VERSION
4
4
  export const SDK_VERSION = PACKAGE_VERSION
5
5
  export const PROTOCOL_VERSION = '1'