buckyos 0.7.206 → 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.
- package/cli/dist/cli.mjs +602 -179
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/ai.ts +460 -23
- package/cli/modules/aiws.ts +1 -1
- package/cli/version.ts +1 -1
- package/dist/{aicc-67851c41.mjs → aicc-286ba457.mjs} +7 -5
- package/dist/aicc-286ba457.mjs.map +1 -0
- package/dist/aicc-342f2659.js +2 -0
- package/dist/aicc-342f2659.js.map +1 -0
- package/dist/aicc_client.d.ts +623 -288
- package/dist/aicc_client.d.ts.map +1 -1
- package/dist/{aiws_write-47c90e76.mjs → aiws_write-5b542439.mjs} +232 -135
- package/dist/{aiws_write-47c90e76.mjs.map → aiws_write-5b542439.mjs.map} +1 -1
- package/dist/aiws_write-a0769003.js +13 -0
- package/dist/{aiws_write-eeea8ed3.js.map → aiws_write-a0769003.js.map} +1 -1
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +3 -0
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +14 -3
- package/dist/app-frame.mjs.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +93 -81
- package/dist/browser.mjs.map +1 -1
- package/dist/{content_objid-0a095cbd.mjs → content_objid-09031ce1.mjs} +2 -2
- package/dist/{content_objid-0a095cbd.mjs.map → content_objid-09031ce1.mjs.map} +1 -1
- package/dist/{content_objid-4742308a.js → content_objid-6342d0ba.js} +2 -2
- package/dist/{content_objid-4742308a.js.map → content_objid-6342d0ba.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +93 -81
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +4 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.mjs +92 -80
- package/dist/node.mjs.map +1 -1
- package/dist/{openai-ae2978de.mjs → openai-1c0d8341.mjs} +2 -2
- package/dist/{openai-ae2978de.mjs.map → openai-1c0d8341.mjs.map} +1 -1
- package/dist/{openai-f560d518.js → openai-7aa4ffbf.js} +2 -2
- package/dist/{openai-f560d518.js.map → openai-7aa4ffbf.js.map} +1 -1
- package/dist/sdk_core.d.ts +18 -0
- package/dist/sdk_core.d.ts.map +1 -1
- package/dist/{site_manager-91b4d899.mjs → site_manager-4f1940eb.mjs} +209 -143
- package/dist/site_manager-4f1940eb.mjs.map +1 -0
- package/dist/site_manager-ca22ffbd.js +2 -0
- package/dist/site_manager-ca22ffbd.js.map +1 -0
- package/dist/user_preferences-1d49850a.mjs +158 -0
- package/dist/user_preferences-1d49850a.mjs.map +1 -0
- package/dist/user_preferences-7288c989.js +2 -0
- package/dist/user_preferences-7288c989.js.map +1 -0
- package/dist/user_preferences.d.ts +50 -0
- package/dist/user_preferences.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts.map +1 -1
- package/dist/xllm/core/run.d.ts.map +1 -1
- package/dist/xllm/core/types.d.ts +0 -2
- package/dist/xllm/core/types.d.ts.map +1 -1
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -1
- package/dist/xllm/hosts/deno/native_tools.d.ts +2 -1
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -1
- package/dist/xllm/index.d.ts +3 -2
- package/dist/xllm/index.d.ts.map +1 -1
- package/dist/xllm/providers/aicc.d.ts +7 -3
- package/dist/xllm/providers/aicc.d.ts.map +1 -1
- package/dist/xllm/runtime/hints.d.ts +9 -4
- package/dist/xllm/runtime/hints.d.ts.map +1 -1
- package/dist/xllm/runtime/step_renderer.d.ts +4 -4
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -1
- package/dist/xllm/runtime/text_budget.d.ts +5 -0
- package/dist/xllm/runtime/text_budget.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +14 -1
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -1
- package/dist/xllm.cjs +1 -1
- package/dist/xllm.cjs.map +1 -1
- package/dist/xllm.mjs +37 -31
- package/dist/xllm_deno.cjs +1 -1
- package/dist/xllm_deno.cjs.map +1 -1
- package/dist/xllm_deno.mjs +125 -44
- package/dist/xllm_deno.mjs.map +1 -1
- package/dist/xllm_dev.cjs +1 -1
- package/dist/xllm_dev.mjs +2 -2
- package/package.json +1 -1
- package/dist/aicc-67851c41.mjs.map +0 -1
- package/dist/aicc-ccb36ef7.js +0 -2
- package/dist/aicc-ccb36ef7.js.map +0 -1
- package/dist/aiws_write-eeea8ed3.js +0 -13
- package/dist/runtime_env-39e4df98.mjs +0 -44
- package/dist/runtime_env-39e4df98.mjs.map +0 -1
- package/dist/runtime_env-6396e1eb.js +0 -2
- package/dist/runtime_env-6396e1eb.js.map +0 -1
- package/dist/site_manager-716a2cf5.js +0 -2
- package/dist/site_manager-716a2cf5.js.map +0 -1
- package/dist/site_manager-91b4d899.mjs.map +0 -1
package/cli/dist/cli.mjs
CHANGED
|
@@ -1697,7 +1697,7 @@ class AuthenticationSession {
|
|
|
1697
1697
|
}
|
|
1698
1698
|
status() {
|
|
1699
1699
|
const session = this.current();
|
|
1700
|
-
const
|
|
1700
|
+
const expiresAt2 = session.principal.tokenExpiresAt;
|
|
1701
1701
|
const exp = numberClaim(session.claims.exp);
|
|
1702
1702
|
const remainingSeconds = exp === void 0 ? null : Math.max(0, exp - Math.floor(this.#now() / 1e3));
|
|
1703
1703
|
return {
|
|
@@ -1707,7 +1707,7 @@ class AuthenticationSession {
|
|
|
1707
1707
|
app_instance_id: session.principal.appInstanceId ?? null,
|
|
1708
1708
|
authentication: session.principal.authentication,
|
|
1709
1709
|
renewable: session.renewable,
|
|
1710
|
-
expires_at:
|
|
1710
|
+
expires_at: expiresAt2 ?? null,
|
|
1711
1711
|
remaining_seconds: remainingSeconds,
|
|
1712
1712
|
developer_mode: this.#developmentMode?.state ?? null,
|
|
1713
1713
|
identity_attempts: this.#identityAttempts
|
|
@@ -6267,7 +6267,7 @@ async function readSkillDirectory(root, limit) {
|
|
|
6267
6267
|
await walk(realRoot, "");
|
|
6268
6268
|
return { files, ignored };
|
|
6269
6269
|
}
|
|
6270
|
-
const PACKAGE_VERSION = "0.7.
|
|
6270
|
+
const PACKAGE_VERSION = "0.7.209";
|
|
6271
6271
|
const TOOL_VERSION = PACKAGE_VERSION;
|
|
6272
6272
|
const SDK_VERSION = PACKAGE_VERSION;
|
|
6273
6273
|
const PROTOCOL_VERSION = "1";
|
|
@@ -12337,171 +12337,7 @@ async function callAgent(ctx, method, params) {
|
|
|
12337
12337
|
throw error;
|
|
12338
12338
|
}
|
|
12339
12339
|
}
|
|
12340
|
-
const AICC = "aicc";
|
|
12341
12340
|
const OBJECT_OUTPUT$6 = { type: "object", additionalProperties: true };
|
|
12342
|
-
const EMPTY_INPUT = { type: "object", properties: {}, additionalProperties: false };
|
|
12343
|
-
const RANGES = ["last1d", "last7d", "last30d"];
|
|
12344
|
-
const GROUPS = [
|
|
12345
|
-
"provider_instance_name",
|
|
12346
|
-
"provider_model",
|
|
12347
|
-
"request_model",
|
|
12348
|
-
"method",
|
|
12349
|
-
"capability",
|
|
12350
|
-
"caller_app_id",
|
|
12351
|
-
"user_id",
|
|
12352
|
-
"tenant_id"
|
|
12353
|
-
];
|
|
12354
|
-
function createAiModule() {
|
|
12355
|
-
return {
|
|
12356
|
-
name: "ai",
|
|
12357
|
-
summary: "Read AI provider, routing, usage and token quota state of the AICC service",
|
|
12358
|
-
commands: [
|
|
12359
|
-
readCommand$2({
|
|
12360
|
-
verb: "providers",
|
|
12361
|
-
summary: "List configured AI provider instances with auth, health, and model inventory",
|
|
12362
|
-
method: "provider.list",
|
|
12363
|
-
description: "Credentials are reported only as configured/kind; secrets are never returned."
|
|
12364
|
-
}),
|
|
12365
|
-
readCommand$2({
|
|
12366
|
-
verb: "routing",
|
|
12367
|
-
summary: "Get the AICC routing overlay and its settings revision",
|
|
12368
|
-
method: "routing.get",
|
|
12369
|
-
description: "An empty routing object means the default routing of the model catalog."
|
|
12370
|
-
}),
|
|
12371
|
-
usageCommand(),
|
|
12372
|
-
quotaCommand()
|
|
12373
|
-
]
|
|
12374
|
-
};
|
|
12375
|
-
}
|
|
12376
|
-
function quotaCommand() {
|
|
12377
|
-
return {
|
|
12378
|
-
verb: "quota",
|
|
12379
|
-
summary: "Show the token quota rules that limit the caller's AI calls and what is left",
|
|
12380
|
-
description: "Admin rules on the caller and the caller's Apps, shared App rules, and the caller's own App limits, each with its current window or total account. A refused call returns quota_exhausted / quota_budget_exceeded with the blocking rules.",
|
|
12381
|
-
options: [
|
|
12382
|
-
{ name: "app", description: "Only the rules that apply to calls of this App (an AppId or AgentId)", type: "string" }
|
|
12383
|
-
],
|
|
12384
|
-
inputSchema: {
|
|
12385
|
-
type: "object",
|
|
12386
|
-
properties: { app: { type: "string", minLength: 1 } },
|
|
12387
|
-
additionalProperties: false
|
|
12388
|
-
},
|
|
12389
|
-
outputSchema: OBJECT_OUTPUT$6,
|
|
12390
|
-
resultSchemaVersion: 1,
|
|
12391
|
-
access: { mode: "fixed", level: "read" },
|
|
12392
|
-
asyncMode: "sync",
|
|
12393
|
-
requiresSession: true,
|
|
12394
|
-
examples: ["buckyos ai quota", "buckyos ai quota --app aiworkspace"],
|
|
12395
|
-
handler: async (ctx, input) => expectObject$4(
|
|
12396
|
-
await callService(ctx, AICC, "quota.query", inputString(input, "app") ? { app_id: inputString(input, "app") } : {}),
|
|
12397
|
-
"quota.query"
|
|
12398
|
-
)
|
|
12399
|
-
};
|
|
12400
|
-
}
|
|
12401
|
-
function readCommand$2(options) {
|
|
12402
|
-
return {
|
|
12403
|
-
verb: options.verb,
|
|
12404
|
-
summary: options.summary,
|
|
12405
|
-
description: options.description,
|
|
12406
|
-
inputSchema: EMPTY_INPUT,
|
|
12407
|
-
outputSchema: OBJECT_OUTPUT$6,
|
|
12408
|
-
resultSchemaVersion: 1,
|
|
12409
|
-
access: { mode: "fixed", level: "read" },
|
|
12410
|
-
asyncMode: "sync",
|
|
12411
|
-
requiresSession: true,
|
|
12412
|
-
examples: [`buckyos ai ${options.verb}`],
|
|
12413
|
-
handler: async (ctx) => expectObject$4(await callService(ctx, AICC, options.method, {}), options.method)
|
|
12414
|
-
};
|
|
12415
|
-
}
|
|
12416
|
-
function usageCommand() {
|
|
12417
|
-
return {
|
|
12418
|
-
verb: "usage",
|
|
12419
|
-
summary: "Aggregate the caller's AI usage: requests, tokens, and cost",
|
|
12420
|
-
description: "Scoped to the caller's own user (a device identity sees only its own calls, not the Zone total). Without --since the range defaults to last7d; --until defaults to now.",
|
|
12421
|
-
options: [
|
|
12422
|
-
{
|
|
12423
|
-
name: "range",
|
|
12424
|
-
description: "last1d, last7d (default), or last30d",
|
|
12425
|
-
type: "string",
|
|
12426
|
-
enum: RANGES
|
|
12427
|
-
},
|
|
12428
|
-
{ name: "since", description: "RFC 3339 or Unix ms lower bound", type: "string" },
|
|
12429
|
-
{ name: "until", description: "RFC 3339 or Unix ms upper bound", type: "string" },
|
|
12430
|
-
{
|
|
12431
|
-
name: "group-by",
|
|
12432
|
-
description: `Comma-separated: ${GROUPS.join(", ")}`,
|
|
12433
|
-
type: "string"
|
|
12434
|
-
},
|
|
12435
|
-
{
|
|
12436
|
-
name: "bucket",
|
|
12437
|
-
description: "Time buckets: hour or day",
|
|
12438
|
-
type: "string",
|
|
12439
|
-
enum: ["hour", "day"]
|
|
12440
|
-
},
|
|
12441
|
-
{ name: "events", description: "Also return the individual usage events", type: "boolean" },
|
|
12442
|
-
{ name: "limit", description: "Event page size", type: "integer" },
|
|
12443
|
-
{ name: "cursor", description: "Opaque event page cursor", type: "string" }
|
|
12444
|
-
],
|
|
12445
|
-
inputSchema: {
|
|
12446
|
-
type: "object",
|
|
12447
|
-
properties: {
|
|
12448
|
-
range: { type: "string", enum: RANGES },
|
|
12449
|
-
since: { type: "string", minLength: 1 },
|
|
12450
|
-
until: { type: "string", minLength: 1 },
|
|
12451
|
-
group_by: { type: "string", minLength: 1 },
|
|
12452
|
-
bucket: { type: "string", enum: ["hour", "day"] },
|
|
12453
|
-
events: { type: "boolean" },
|
|
12454
|
-
limit: { type: "integer", minimum: 1 },
|
|
12455
|
-
cursor: { type: "string", minLength: 1 }
|
|
12456
|
-
},
|
|
12457
|
-
additionalProperties: false
|
|
12458
|
-
},
|
|
12459
|
-
outputSchema: OBJECT_OUTPUT$6,
|
|
12460
|
-
resultSchemaVersion: 1,
|
|
12461
|
-
access: { mode: "fixed", level: "read" },
|
|
12462
|
-
asyncMode: "sync",
|
|
12463
|
-
requiresSession: true,
|
|
12464
|
-
examples: [
|
|
12465
|
-
"buckyos ai usage --range last1d --group-by provider_instance_name,provider_model",
|
|
12466
|
-
"buckyos ai usage --since 2026-10-01T00:00:00Z --bucket day"
|
|
12467
|
-
],
|
|
12468
|
-
handler: async (ctx, input) => {
|
|
12469
|
-
const groupBy = splitServices(input.group_by);
|
|
12470
|
-
const unknown = groupBy.filter((group) => !GROUPS.includes(group));
|
|
12471
|
-
if (unknown.length > 0) {
|
|
12472
|
-
throw new UsageError(
|
|
12473
|
-
"INVALID_ARGUMENT",
|
|
12474
|
-
`unknown group-by ${unknown.join(", ")}; use ${GROUPS.join(", ")}`
|
|
12475
|
-
);
|
|
12476
|
-
}
|
|
12477
|
-
return expectObject$4(
|
|
12478
|
-
await callService(ctx, AICC, "usage.query", {
|
|
12479
|
-
time_range: timeRange(input),
|
|
12480
|
-
...groupBy.length > 0 ? { group_by: groupBy } : {},
|
|
12481
|
-
...input.bucket ? { time_bucket: input.bucket } : {},
|
|
12482
|
-
output_mode: input.events === true ? "summary_and_events" : "summary",
|
|
12483
|
-
...input.limit !== void 0 ? { limit: input.limit } : {},
|
|
12484
|
-
...inputString(input, "cursor") ? { cursor: inputString(input, "cursor") } : {}
|
|
12485
|
-
}),
|
|
12486
|
-
"usage.query"
|
|
12487
|
-
);
|
|
12488
|
-
}
|
|
12489
|
-
};
|
|
12490
|
-
}
|
|
12491
|
-
function timeRange(input) {
|
|
12492
|
-
const since = parseTimestamp(input.since, "since");
|
|
12493
|
-
const until = parseTimestamp(input.until, "until");
|
|
12494
|
-
if (since === void 0) {
|
|
12495
|
-
if (until !== void 0)
|
|
12496
|
-
throw new UsageError("INVALID_ARGUMENT", "--until requires --since");
|
|
12497
|
-
return { kind: inputString(input, "range") ?? "last7d" };
|
|
12498
|
-
}
|
|
12499
|
-
if (input.range !== void 0) {
|
|
12500
|
-
throw new UsageError("ARGUMENT_CONFLICT", "--range cannot be combined with --since");
|
|
12501
|
-
}
|
|
12502
|
-
return { kind: "explicit", start_time_ms: since, end_time_ms: until ?? Date.now() };
|
|
12503
|
-
}
|
|
12504
|
-
const OBJECT_OUTPUT$5 = { type: "object", additionalProperties: true };
|
|
12505
12341
|
const DAY_MS$1 = 864e5;
|
|
12506
12342
|
const EXPIRES_HELP = "1d, 7d (default), 30d, none, or an RFC 3339 time";
|
|
12507
12343
|
function createShareModule() {
|
|
@@ -12612,7 +12448,7 @@ function createCommand() {
|
|
|
12612
12448
|
required: ["path"],
|
|
12613
12449
|
additionalProperties: false
|
|
12614
12450
|
},
|
|
12615
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12451
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12616
12452
|
resultSchemaVersion: 1,
|
|
12617
12453
|
access: { mode: "fixed", level: "write" },
|
|
12618
12454
|
asyncMode: "either",
|
|
@@ -12681,7 +12517,7 @@ function listCommand() {
|
|
|
12681
12517
|
},
|
|
12682
12518
|
additionalProperties: false
|
|
12683
12519
|
},
|
|
12684
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12520
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12685
12521
|
resultSchemaVersion: 1,
|
|
12686
12522
|
access: { mode: "fixed", level: "read" },
|
|
12687
12523
|
asyncMode: "sync",
|
|
@@ -12713,7 +12549,7 @@ function getCommand$1() {
|
|
|
12713
12549
|
required: ["share_id"],
|
|
12714
12550
|
additionalProperties: false
|
|
12715
12551
|
},
|
|
12716
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12552
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12717
12553
|
resultSchemaVersion: 1,
|
|
12718
12554
|
access: { mode: "fixed", level: "read" },
|
|
12719
12555
|
asyncMode: "sync",
|
|
@@ -12750,7 +12586,7 @@ function updateCommand() {
|
|
|
12750
12586
|
required: ["share_id"],
|
|
12751
12587
|
additionalProperties: false
|
|
12752
12588
|
},
|
|
12753
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12589
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12754
12590
|
resultSchemaVersion: 1,
|
|
12755
12591
|
access: { mode: "fixed", level: "write" },
|
|
12756
12592
|
asyncMode: "sync",
|
|
@@ -12794,7 +12630,7 @@ function stopCommand() {
|
|
|
12794
12630
|
required: ["share_id"],
|
|
12795
12631
|
additionalProperties: false
|
|
12796
12632
|
},
|
|
12797
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12633
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12798
12634
|
resultSchemaVersion: 1,
|
|
12799
12635
|
access: { mode: "fixed", level: "destructive" },
|
|
12800
12636
|
asyncMode: "sync",
|
|
@@ -12826,7 +12662,7 @@ function statsCommand() {
|
|
|
12826
12662
|
},
|
|
12827
12663
|
additionalProperties: false
|
|
12828
12664
|
},
|
|
12829
|
-
outputSchema: OBJECT_OUTPUT$
|
|
12665
|
+
outputSchema: OBJECT_OUTPUT$6,
|
|
12830
12666
|
resultSchemaVersion: 1,
|
|
12831
12667
|
access: { mode: "fixed", level: "read" },
|
|
12832
12668
|
asyncMode: "sync",
|
|
@@ -12845,6 +12681,593 @@ function statsCommand() {
|
|
|
12845
12681
|
}
|
|
12846
12682
|
};
|
|
12847
12683
|
}
|
|
12684
|
+
const AICC = "aicc";
|
|
12685
|
+
const OBJECT_OUTPUT$5 = { type: "object", additionalProperties: true };
|
|
12686
|
+
const EMPTY_INPUT = { type: "object", properties: {}, additionalProperties: false };
|
|
12687
|
+
const RANGES = ["last1d", "last7d", "last30d"];
|
|
12688
|
+
const GROUPS = [
|
|
12689
|
+
"provider_instance_name",
|
|
12690
|
+
"provider_model",
|
|
12691
|
+
"request_model",
|
|
12692
|
+
"method",
|
|
12693
|
+
"capability",
|
|
12694
|
+
"caller_app_id",
|
|
12695
|
+
"user_id",
|
|
12696
|
+
"tenant_id",
|
|
12697
|
+
"user_group"
|
|
12698
|
+
];
|
|
12699
|
+
const ON_UNAVAILABLE = ["none", "same_model", "not_pricier", "next_model"];
|
|
12700
|
+
const USECASE_FIELDS = ["model", "on_unavailable"];
|
|
12701
|
+
const GROUP_ACTIONS = ["list", "create", "delete", "bind", "unbind"];
|
|
12702
|
+
const TOKEN_ACTIONS = ["create", "list", "revoke"];
|
|
12703
|
+
const DURATION_MS = { h: 36e5, d: 864e5, w: 7 * 864e5 };
|
|
12704
|
+
function createAiModule() {
|
|
12705
|
+
return {
|
|
12706
|
+
name: "ai",
|
|
12707
|
+
summary: "Read AI providers, usecase routing and usage; set usecase models and routing groups; read AI policies and Credit; recharge Credit; issue API Tokens",
|
|
12708
|
+
commands: [
|
|
12709
|
+
readCommand$2({
|
|
12710
|
+
verb: "providers",
|
|
12711
|
+
summary: "List configured AI provider instances with auth, health, and model inventory",
|
|
12712
|
+
method: "provider.list",
|
|
12713
|
+
description: "Credentials are reported only as configured/kind; secrets are never returned."
|
|
12714
|
+
}),
|
|
12715
|
+
routingCommand(),
|
|
12716
|
+
usecaseCommand(),
|
|
12717
|
+
routingGroupCommand(),
|
|
12718
|
+
usageCommand(),
|
|
12719
|
+
...policyCommands(),
|
|
12720
|
+
tokenCommand()
|
|
12721
|
+
]
|
|
12722
|
+
};
|
|
12723
|
+
}
|
|
12724
|
+
function aiccCommand(command2) {
|
|
12725
|
+
const options = command2.options ?? [];
|
|
12726
|
+
return {
|
|
12727
|
+
verb: command2.verb,
|
|
12728
|
+
summary: command2.summary,
|
|
12729
|
+
description: command2.description,
|
|
12730
|
+
options: options.map(({ key: _key, required: _required, json: _json, ...option }) => option),
|
|
12731
|
+
inputSchema: {
|
|
12732
|
+
type: "object",
|
|
12733
|
+
properties: Object.fromEntries(options.map((option) => [
|
|
12734
|
+
option.name.replaceAll("-", "_"),
|
|
12735
|
+
option.type === "integer" ? { type: "integer", minimum: 1 } : option.type === "boolean" ? { type: "boolean" } : { type: "string", minLength: 1 }
|
|
12736
|
+
])),
|
|
12737
|
+
required: options.filter((option) => option.required).map((option) => option.name.replaceAll("-", "_")),
|
|
12738
|
+
additionalProperties: false
|
|
12739
|
+
},
|
|
12740
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
12741
|
+
resultSchemaVersion: 1,
|
|
12742
|
+
access: { mode: "fixed", level: command2.level },
|
|
12743
|
+
asyncMode: "sync",
|
|
12744
|
+
requiresSession: true,
|
|
12745
|
+
examples: command2.examples,
|
|
12746
|
+
handler: async (ctx, input) => {
|
|
12747
|
+
const params = {};
|
|
12748
|
+
for (const option of options) {
|
|
12749
|
+
const name = option.name.replaceAll("-", "_");
|
|
12750
|
+
if (option.type === "boolean" || option.type === "integer") {
|
|
12751
|
+
if (input[name] !== void 0)
|
|
12752
|
+
params[option.key] = input[name];
|
|
12753
|
+
continue;
|
|
12754
|
+
}
|
|
12755
|
+
const value = option.required ? requiredInputString(input, name) : inputString(input, name);
|
|
12756
|
+
if (value === void 0)
|
|
12757
|
+
continue;
|
|
12758
|
+
if (option.json) {
|
|
12759
|
+
try {
|
|
12760
|
+
params[option.key] = JSON.parse(value);
|
|
12761
|
+
} catch {
|
|
12762
|
+
throw new UsageError("INVALID_ARGUMENT", `--${option.name} must be JSON`);
|
|
12763
|
+
}
|
|
12764
|
+
} else {
|
|
12765
|
+
params[option.key] = value;
|
|
12766
|
+
}
|
|
12767
|
+
}
|
|
12768
|
+
if (params.scope !== void 0)
|
|
12769
|
+
params.scope = params.scope ? "manage" : "mine";
|
|
12770
|
+
return expectObject$4(await callService(ctx, AICC, command2.method, params), command2.method);
|
|
12771
|
+
}
|
|
12772
|
+
};
|
|
12773
|
+
}
|
|
12774
|
+
const USER_OPTION = { name: "user", key: "user_id", description: "Another user (administrators only); defaults to the caller", type: "string" };
|
|
12775
|
+
const APP_OPTION = { name: "app", key: "app_id", description: "Calls through this App or Agent (its App policies apply)", type: "string" };
|
|
12776
|
+
function policyCommands() {
|
|
12777
|
+
return [
|
|
12778
|
+
aiccCommand({
|
|
12779
|
+
verb: "policy",
|
|
12780
|
+
summary: "Show the caller's AI Credit balance and the usage limits that apply, with their windows",
|
|
12781
|
+
description: 'A refused call returns quota_exhausted (a limit is used up), credit_insufficient (the Credit balance is used up) or resource_not_permitted (hidden, or unpriced for a caller who pays: details.reason = "unpriced").',
|
|
12782
|
+
method: "policy.status",
|
|
12783
|
+
level: "read",
|
|
12784
|
+
options: [APP_OPTION],
|
|
12785
|
+
examples: ["buckyos ai policy", "buckyos ai policy --app aiworkspace"]
|
|
12786
|
+
}),
|
|
12787
|
+
aiccCommand({
|
|
12788
|
+
verb: "policy-effective",
|
|
12789
|
+
summary: "Show every model a user can see with its Credit price and source, and every limit that applies",
|
|
12790
|
+
description: "Without --user it is the caller. Each model says which policy makes it visible and whether it is free, priced or unpriced (not usable for a caller who pays).",
|
|
12791
|
+
method: "policy.effective",
|
|
12792
|
+
level: "read",
|
|
12793
|
+
options: [USER_OPTION, APP_OPTION],
|
|
12794
|
+
examples: ["buckyos ai policy-effective", "buckyos ai policy-effective --user bob --app writer.example.zone"]
|
|
12795
|
+
}),
|
|
12796
|
+
aiccCommand({
|
|
12797
|
+
verb: "policies",
|
|
12798
|
+
summary: "List the AI policies that apply to the caller, or with --manage every policy of the Zone",
|
|
12799
|
+
description: "Subjects: type:admin|user|limited, group:<id>, user:<id> (more specific overrides), app:<id>, user_app:<user>/<app> (only narrows). Change them in Desktop AI Center › Policies or with policy.upsert.",
|
|
12800
|
+
method: "policy.list",
|
|
12801
|
+
level: "read",
|
|
12802
|
+
options: [{ name: "manage", key: "scope", description: "Every policy of the Zone (administrators only)", type: "boolean" }],
|
|
12803
|
+
examples: ["buckyos ai policies", "buckyos ai policies --manage"]
|
|
12804
|
+
}),
|
|
12805
|
+
aiccCommand({
|
|
12806
|
+
verb: "prices",
|
|
12807
|
+
summary: "Show the Credit price list (token rates per million tokens) and, for administrators, Credit rates and unpriced models",
|
|
12808
|
+
description: "Keys: model:<model_driver_id>:<origin_model_id> (every Provider of the model) and exact:<model>@<provider> (one channel).",
|
|
12809
|
+
method: "price.get",
|
|
12810
|
+
level: "read",
|
|
12811
|
+
examples: ["buckyos ai prices"]
|
|
12812
|
+
}),
|
|
12813
|
+
aiccCommand({
|
|
12814
|
+
verb: "credit",
|
|
12815
|
+
summary: "Show the AI Credit balance of the caller (or of a user, for administrators)",
|
|
12816
|
+
description: "Credit is the Zone's unit for AI use, unrelated to a Provider account balance; it may be negative after a large call.",
|
|
12817
|
+
method: "credit.account.get",
|
|
12818
|
+
level: "read",
|
|
12819
|
+
options: [USER_OPTION],
|
|
12820
|
+
examples: ["buckyos ai credit", "buckyos ai credit --user bob"]
|
|
12821
|
+
}),
|
|
12822
|
+
aiccCommand({
|
|
12823
|
+
verb: "credit-ledger",
|
|
12824
|
+
summary: "List recharges, adjustments and charges of a Credit account, newest first",
|
|
12825
|
+
description: "Charges with status unpriced or unknown_usage were not charged; an administrator can charge them with credit-adjust.",
|
|
12826
|
+
method: "credit.ledger.list",
|
|
12827
|
+
level: "read",
|
|
12828
|
+
options: [
|
|
12829
|
+
USER_OPTION,
|
|
12830
|
+
{ name: "limit", key: "limit", description: "Page size", type: "integer" },
|
|
12831
|
+
{ name: "cursor", key: "cursor", description: "Opaque page cursor", type: "string" }
|
|
12832
|
+
],
|
|
12833
|
+
examples: ["buckyos ai credit-ledger", "buckyos ai credit-ledger --user bob --limit 20"]
|
|
12834
|
+
}),
|
|
12835
|
+
aiccCommand({
|
|
12836
|
+
verb: "credit-recharge",
|
|
12837
|
+
summary: "Recharge a user's AI Credit once per id (administrators and granted payment gateways)",
|
|
12838
|
+
description: "Needs write on obj://aicc/credit/recharge. The same --id with the same amount is credited once and returns the original entry; with different parameters it fails. Use the payment order id as --id.",
|
|
12839
|
+
method: "credit.recharge",
|
|
12840
|
+
level: "privileged",
|
|
12841
|
+
options: [
|
|
12842
|
+
{ name: "user", key: "user_id", description: "User to recharge", type: "string", required: true },
|
|
12843
|
+
{ name: "amount", key: "amount", description: "Positive Credit amount, up to six decimals", type: "string", required: true },
|
|
12844
|
+
{ name: "id", key: "recharge_id", description: "Idempotency id (payment order id)", type: "string", required: true },
|
|
12845
|
+
{ name: "note", key: "note", description: "Note kept with the entry", type: "string" },
|
|
12846
|
+
{ name: "external-ref", key: "external_ref", description: "JSON a payment gateway keeps with the entry", type: "string", json: true }
|
|
12847
|
+
],
|
|
12848
|
+
examples: [`buckyos ai credit-recharge --user bob --amount 100 --id order-1001 --external-ref '{"gateway":"stripe"}'`]
|
|
12849
|
+
}),
|
|
12850
|
+
aiccCommand({
|
|
12851
|
+
verb: "credit-recharge-get",
|
|
12852
|
+
summary: "Look up a recharge or adjustment by its id (after a timeout, before retrying)",
|
|
12853
|
+
description: "Needs write on obj://aicc/credit/recharge.",
|
|
12854
|
+
method: "credit.recharge.get",
|
|
12855
|
+
level: "read",
|
|
12856
|
+
options: [{ name: "id", key: "recharge_id", description: "Recharge or adjustment id", type: "string", required: true }],
|
|
12857
|
+
examples: ["buckyos ai credit-recharge-get --id order-1001"]
|
|
12858
|
+
}),
|
|
12859
|
+
aiccCommand({
|
|
12860
|
+
verb: "credit-adjust",
|
|
12861
|
+
summary: "Add or remove AI Credit with a note: refunds, corrections, charging unpriced usage",
|
|
12862
|
+
description: "Needs write on obj://aicc/credit/recharge. A negative amount removes Credit; the same --id is applied once.",
|
|
12863
|
+
method: "credit.adjust",
|
|
12864
|
+
level: "privileged",
|
|
12865
|
+
options: [
|
|
12866
|
+
{ name: "user", key: "user_id", description: "User whose balance changes", type: "string", required: true },
|
|
12867
|
+
{ name: "amount", key: "amount", description: "Signed Credit amount, not zero", type: "string", required: true },
|
|
12868
|
+
{ name: "id", key: "adjust_id", description: "Idempotency id", type: "string", required: true },
|
|
12869
|
+
{ name: "note", key: "note", description: "Why (required)", type: "string", required: true }
|
|
12870
|
+
],
|
|
12871
|
+
examples: ["buckyos ai credit-adjust --user bob --amount=-2.5 --id refund-1001 --note 'refund order 1001'"]
|
|
12872
|
+
})
|
|
12873
|
+
];
|
|
12874
|
+
}
|
|
12875
|
+
function tokenCommand() {
|
|
12876
|
+
return {
|
|
12877
|
+
verb: "token",
|
|
12878
|
+
summary: "Issue, list and revoke AICC API Tokens (bkai_… keys) for other software or another Zone's AICC",
|
|
12879
|
+
description: `create --name <name> issues a token and prints its key once: save it, it is never shown again. Without --group it is a sub-account token of yours (or of --user, administrators): it charges that account and needs "Allow use from outside" (provider_access) in the account's policy. --group <id> issues a group token (administrators): an independent user that follows the group's policy and has its own AI Credit account token:<id> (recharge it with credit-recharge --user token:<id>). --expires takes 30d, 12h, 2w, an RFC 3339 time or Unix milliseconds. Other software uses base_url (OpenAI compatible, non-streaming, exact model names only); another BuckyOS AICC adds aicc_endpoint as a "BuckyOS AICC" Provider. list shows yours, or with administrators every token (--group, --user filter; --include-revoked); revoke <token_id> stops it at once. Narrow a token with a policy on subject token:<id> (Desktop AI Center › Policies).`,
|
|
12880
|
+
positionals: [
|
|
12881
|
+
{ name: "action", description: TOKEN_ACTIONS.join(" | "), required: true },
|
|
12882
|
+
{ name: "token_id", description: "revoke: the token id (16 hex digits)", required: false }
|
|
12883
|
+
],
|
|
12884
|
+
options: [
|
|
12885
|
+
{ name: "name", description: "create: what the token is for, such as the other Zone or the software", type: "string" },
|
|
12886
|
+
{ name: "group", description: "create: a group token for this user group (administrators); list: only its tokens", type: "string" },
|
|
12887
|
+
{ name: "user", description: "create: a sub-account token of this user (administrators; default: you); list: only this user's", type: "string" },
|
|
12888
|
+
{ name: "expires", description: "create: 30d, 12h, 2w, RFC 3339 or Unix ms (default: never)", type: "string" },
|
|
12889
|
+
{ name: "include-revoked", description: "list: also revoked tokens", type: "boolean" }
|
|
12890
|
+
],
|
|
12891
|
+
inputSchema: {
|
|
12892
|
+
type: "object",
|
|
12893
|
+
properties: {
|
|
12894
|
+
action: { type: "string", enum: TOKEN_ACTIONS },
|
|
12895
|
+
token_id: { type: "string", minLength: 1 },
|
|
12896
|
+
name: { type: "string", minLength: 1 },
|
|
12897
|
+
group: { type: "string", minLength: 1 },
|
|
12898
|
+
user: { type: "string", minLength: 1 },
|
|
12899
|
+
expires: { type: "string", minLength: 1 },
|
|
12900
|
+
include_revoked: { type: "boolean" }
|
|
12901
|
+
},
|
|
12902
|
+
required: ["action"],
|
|
12903
|
+
additionalProperties: false
|
|
12904
|
+
},
|
|
12905
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
12906
|
+
resultSchemaVersion: 1,
|
|
12907
|
+
access: { mode: "operation", operationIdField: "action", possibleLevels: ["read", "write", "destructive"] },
|
|
12908
|
+
asyncMode: "sync",
|
|
12909
|
+
requiresSession: true,
|
|
12910
|
+
examples: [
|
|
12911
|
+
"buckyos ai token create --name 'my scripts' --expires 90d",
|
|
12912
|
+
"buckyos ai token create --group peers --name zone-a",
|
|
12913
|
+
"buckyos --output table ai token list",
|
|
12914
|
+
"buckyos ai token revoke 0123456789abcdef"
|
|
12915
|
+
],
|
|
12916
|
+
handler: async (ctx, input) => {
|
|
12917
|
+
const call2 = async (method, params) => expectObject$4(await callService(ctx, AICC, method, params), method);
|
|
12918
|
+
const group = inputString(input, "group");
|
|
12919
|
+
const user = inputString(input, "user");
|
|
12920
|
+
if (input.action === "list") {
|
|
12921
|
+
const listed = await call2("api_token.list", {
|
|
12922
|
+
...group ? { group_id: group } : {},
|
|
12923
|
+
...user ? { user_id: user } : {},
|
|
12924
|
+
...input.include_revoked === true ? { include_revoked: true } : {}
|
|
12925
|
+
});
|
|
12926
|
+
const tokens = Array.isArray(listed.tokens) ? listed.tokens : [];
|
|
12927
|
+
return { tokens: tokens.map(tokenRow) };
|
|
12928
|
+
}
|
|
12929
|
+
if (input.action === "revoke") {
|
|
12930
|
+
const tokenId = inputString(input, "token_id");
|
|
12931
|
+
if (!tokenId)
|
|
12932
|
+
throw new UsageError("MISSING_ARGUMENT", "revoke requires a token id");
|
|
12933
|
+
return call2("api_token.revoke", { token_id: tokenId });
|
|
12934
|
+
}
|
|
12935
|
+
if (group && user)
|
|
12936
|
+
throw new UsageError("ARGUMENT_CONFLICT", "--group cannot be combined with --user");
|
|
12937
|
+
const name = inputString(input, "name");
|
|
12938
|
+
if (!name)
|
|
12939
|
+
throw new UsageError("MISSING_ARGUMENT", "create requires --name");
|
|
12940
|
+
const expires = expiresAt(inputString(input, "expires"));
|
|
12941
|
+
const created = await call2("api_token.create", {
|
|
12942
|
+
name,
|
|
12943
|
+
...expires !== void 0 ? { expires_at_ms: expires } : {},
|
|
12944
|
+
...group ? { group_id: group } : {},
|
|
12945
|
+
...user ? { user_id: user } : {}
|
|
12946
|
+
});
|
|
12947
|
+
const warning = "Save this API key now: it is shown only this once and cannot be retrieved later.";
|
|
12948
|
+
await ctx.io.stderr(`warning: ${warning}
|
|
12949
|
+
`);
|
|
12950
|
+
const origin = gatewayOrigin$2(ctx.connection.endpoint);
|
|
12951
|
+
return {
|
|
12952
|
+
api_key: created.api_key,
|
|
12953
|
+
warning,
|
|
12954
|
+
base_url: `${origin}/kapi/aicc/openai/v1`,
|
|
12955
|
+
aicc_endpoint: `${origin}/kapi/aicc`,
|
|
12956
|
+
token: created.token
|
|
12957
|
+
};
|
|
12958
|
+
}
|
|
12959
|
+
};
|
|
12960
|
+
}
|
|
12961
|
+
function tokenRow(token) {
|
|
12962
|
+
const time2 = (value) => typeof value === "number" ? new Date(value).toISOString() : "";
|
|
12963
|
+
return {
|
|
12964
|
+
token_id: token.token_id,
|
|
12965
|
+
name: token.name,
|
|
12966
|
+
kind: token.kind,
|
|
12967
|
+
for: token.kind === "group" ? `group:${token.group_id ?? ""}` : `user:${token.owner_user_id ?? ""}`,
|
|
12968
|
+
state: token.state,
|
|
12969
|
+
balance: token.balance ?? "",
|
|
12970
|
+
last_used: time2(token.last_used_at_ms),
|
|
12971
|
+
expires: time2(token.expires_at_ms),
|
|
12972
|
+
created: time2(token.created_at_ms)
|
|
12973
|
+
};
|
|
12974
|
+
}
|
|
12975
|
+
function expiresAt(text2) {
|
|
12976
|
+
if (!text2)
|
|
12977
|
+
return void 0;
|
|
12978
|
+
const duration = text2.match(/^(\d+)([hdw])$/);
|
|
12979
|
+
const at = duration ? Date.now() + Number(duration[1]) * DURATION_MS[duration[2]] : parseTimestamp(text2, "expires");
|
|
12980
|
+
if (at === void 0 || at <= Date.now())
|
|
12981
|
+
throw new UsageError("INVALID_ARGUMENT", "--expires must be in the future");
|
|
12982
|
+
return at;
|
|
12983
|
+
}
|
|
12984
|
+
function readCommand$2(options) {
|
|
12985
|
+
return {
|
|
12986
|
+
verb: options.verb,
|
|
12987
|
+
summary: options.summary,
|
|
12988
|
+
description: options.description,
|
|
12989
|
+
inputSchema: EMPTY_INPUT,
|
|
12990
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
12991
|
+
resultSchemaVersion: 1,
|
|
12992
|
+
access: { mode: "fixed", level: "read" },
|
|
12993
|
+
asyncMode: "sync",
|
|
12994
|
+
requiresSession: true,
|
|
12995
|
+
examples: [`buckyos ai ${options.verb}`],
|
|
12996
|
+
handler: async (ctx) => expectObject$4(await callService(ctx, AICC, options.method, {}), options.method)
|
|
12997
|
+
};
|
|
12998
|
+
}
|
|
12999
|
+
function routingCommand() {
|
|
13000
|
+
return {
|
|
13001
|
+
verb: "routing",
|
|
13002
|
+
summary: "Show the usecase table: the model each usecase routes to, who set it, and what happens when it is unavailable",
|
|
13003
|
+
description: `Without --view it is the caller's own table. source is the layer that chose the model: default, zone (administrator), user, group:<id> or fallback_llm; "locked" means an administrator fixed it. on_unavailable is none (return the real error), same_model, not_pricier or next_model, with the layer that set it when not the default; would_switch_to is what that policy would use if the model's Provider were unavailable. coverage is covered, fallback_llm (served by the fallback LLM) or uncovered, with the reason. The row llm.fallback is the fallback LLM (enabled: whether it is on; off by default). --json returns the whole routing.usecases response: every layer with its value, lock and model state, and the revision a change passes.`,
|
|
13004
|
+
options: [
|
|
13005
|
+
{ name: "view", description: "zone (administrators), group:<id> or app:<app_id>; defaults to the caller", type: "string" },
|
|
13006
|
+
{ name: "json", description: "The whole routing.usecases response instead of one line per usecase", type: "boolean" }
|
|
13007
|
+
],
|
|
13008
|
+
inputSchema: {
|
|
13009
|
+
type: "object",
|
|
13010
|
+
properties: { view: { type: "string", minLength: 1 }, json: { type: "boolean" } },
|
|
13011
|
+
additionalProperties: false
|
|
13012
|
+
},
|
|
13013
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
13014
|
+
resultSchemaVersion: 1,
|
|
13015
|
+
access: { mode: "fixed", level: "read" },
|
|
13016
|
+
asyncMode: "sync",
|
|
13017
|
+
requiresSession: true,
|
|
13018
|
+
examples: ["buckyos --output table ai routing", "buckyos ai routing --view zone", "buckyos ai routing --view app:writer --json"],
|
|
13019
|
+
handler: async (ctx, input) => {
|
|
13020
|
+
const view = inputString(input, "view");
|
|
13021
|
+
const table = expectObject$4(await callService(ctx, AICC, "routing.usecases", view ? { view } : {}), "routing.usecases");
|
|
13022
|
+
if (input.json === true)
|
|
13023
|
+
return table;
|
|
13024
|
+
const rows = Array.isArray(table.rows) ? table.rows : [];
|
|
13025
|
+
return {
|
|
13026
|
+
view: table.view,
|
|
13027
|
+
revision: table.revision,
|
|
13028
|
+
can_edit: table.can_edit,
|
|
13029
|
+
usecases: rows.map((row) => {
|
|
13030
|
+
const lock = (locked) => locked === true ? ", locked" : "";
|
|
13031
|
+
const policySource = row.on_unavailable_source === "default" && row.on_unavailable_locked !== true ? "" : ` (${row.on_unavailable_source}${lock(row.on_unavailable_locked)})`;
|
|
13032
|
+
return {
|
|
13033
|
+
usecase: row.usecase,
|
|
13034
|
+
model: row.model ?? "",
|
|
13035
|
+
source: row.model_source ? `${row.model_source}${lock(row.model_locked)}` : "",
|
|
13036
|
+
on_unavailable: `${row.on_unavailable}${policySource}`,
|
|
13037
|
+
would_switch_to: row.fallback_to ?? (row.fallback_note ? `(${row.fallback_note})` : ""),
|
|
13038
|
+
coverage: row.coverage_reason ? `${row.coverage} (${row.coverage_reason})` : row.coverage,
|
|
13039
|
+
...row.enabled !== void 0 ? { enabled: row.enabled } : {}
|
|
13040
|
+
};
|
|
13041
|
+
})
|
|
13042
|
+
};
|
|
13043
|
+
}
|
|
13044
|
+
};
|
|
13045
|
+
}
|
|
13046
|
+
function usecaseCommand() {
|
|
13047
|
+
return {
|
|
13048
|
+
verb: "usecase",
|
|
13049
|
+
summary: "Set the model of a usecase, or what it does when that model is unavailable, in your layer, a routing group or the Zone",
|
|
13050
|
+
description: "set <usecase> changes one usecase of a layer: your own by default, one of your routing groups with --group <id>, the administrator layer (the Zone default) with --zone-default (administrators; --lock keeps users and groups from changing what it sets). --model is an exact model <model>@<provider> with the usecase's API type that meets its requirements. --on-unavailable: none (return the real error), same_model (the same model on another Provider), not_pricier (route again without that Provider, only to a model known not to cost more), next_model (route again without that Provider). --clear model,on_unavailable makes them follow the layer below again. The layer's revision is read first; when it changed in between the call fails with settings_revision_conflict: run it again.",
|
|
13051
|
+
positionals: [
|
|
13052
|
+
{ name: "action", description: "set", required: true },
|
|
13053
|
+
{ name: "usecase", description: "A usecase such as llm.code or image.txt2img (buckyos ai routing lists them)", required: true }
|
|
13054
|
+
],
|
|
13055
|
+
options: [
|
|
13056
|
+
{ name: "model", description: "Exact model <model>@<provider>", type: "string" },
|
|
13057
|
+
{ name: "on-unavailable", description: ON_UNAVAILABLE.join(" | "), type: "string", enum: ON_UNAVAILABLE },
|
|
13058
|
+
{ name: "clear", description: `Comma-separated: ${USECASE_FIELDS.join(", ")}`, type: "string" },
|
|
13059
|
+
{ name: "zone-default", description: "The administrator layer, the Zone default (administrators)", type: "boolean" },
|
|
13060
|
+
{ name: "group", description: "One of your routing groups, by id", type: "string" },
|
|
13061
|
+
{ name: "lock", description: "With --zone-default: what this sets cannot be changed by users or groups", type: "boolean" }
|
|
13062
|
+
],
|
|
13063
|
+
inputSchema: {
|
|
13064
|
+
type: "object",
|
|
13065
|
+
properties: {
|
|
13066
|
+
action: { type: "string", enum: ["set"] },
|
|
13067
|
+
usecase: { type: "string", minLength: 1 },
|
|
13068
|
+
model: { type: "string", minLength: 1 },
|
|
13069
|
+
on_unavailable: { type: "string", enum: ON_UNAVAILABLE },
|
|
13070
|
+
clear: { type: "string", minLength: 1 },
|
|
13071
|
+
zone_default: { type: "boolean" },
|
|
13072
|
+
group: { type: "string", minLength: 1 },
|
|
13073
|
+
lock: { type: "boolean" }
|
|
13074
|
+
},
|
|
13075
|
+
required: ["action", "usecase"],
|
|
13076
|
+
additionalProperties: false
|
|
13077
|
+
},
|
|
13078
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
13079
|
+
resultSchemaVersion: 1,
|
|
13080
|
+
access: { mode: "fixed", level: "write" },
|
|
13081
|
+
asyncMode: "sync",
|
|
13082
|
+
requiresSession: true,
|
|
13083
|
+
examples: [
|
|
13084
|
+
"buckyos ai usecase set llm.code --model gpt-6@openai-main --on-unavailable same_model",
|
|
13085
|
+
"buckyos ai usecase set llm.chat --group rg_1 --clear model",
|
|
13086
|
+
"buckyos ai usecase set image.txt2img --zone-default --model gpt-image-2@openai-main --lock"
|
|
13087
|
+
],
|
|
13088
|
+
handler: async (ctx, input) => {
|
|
13089
|
+
const group = inputString(input, "group");
|
|
13090
|
+
if (group && input.zone_default === true)
|
|
13091
|
+
throw new UsageError("ARGUMENT_CONFLICT", "--zone-default cannot be combined with --group");
|
|
13092
|
+
if (input.lock === true && input.zone_default !== true)
|
|
13093
|
+
throw new UsageError("INVALID_ARGUMENT", "--lock requires --zone-default");
|
|
13094
|
+
const model = inputString(input, "model");
|
|
13095
|
+
const onUnavailable = inputString(input, "on_unavailable");
|
|
13096
|
+
const clear = splitServices(input.clear);
|
|
13097
|
+
const unknown = clear.filter((field) => !USECASE_FIELDS.includes(field));
|
|
13098
|
+
if (unknown.length > 0) {
|
|
13099
|
+
throw new UsageError("INVALID_ARGUMENT", `unknown --clear ${unknown.join(", ")}; use ${USECASE_FIELDS.join(", ")}`);
|
|
13100
|
+
}
|
|
13101
|
+
if (!model && !onUnavailable && clear.length === 0) {
|
|
13102
|
+
throw new UsageError("MISSING_ARGUMENT", "give --model, --on-unavailable or --clear");
|
|
13103
|
+
}
|
|
13104
|
+
const target = input.zone_default === true ? "zone" : group ? `group:${group}` : "user";
|
|
13105
|
+
const current = expectObject$4(
|
|
13106
|
+
await callService(ctx, AICC, "routing.usecases", { view: target === "user" ? "self" : target }),
|
|
13107
|
+
"routing.usecases"
|
|
13108
|
+
);
|
|
13109
|
+
const value = (v) => input.lock === true ? { value: v, locked: true } : v;
|
|
13110
|
+
return expectObject$4(
|
|
13111
|
+
await callService(ctx, AICC, "routing.usecase.set", {
|
|
13112
|
+
target,
|
|
13113
|
+
usecase: requiredInputString(input, "usecase"),
|
|
13114
|
+
...model ? { model: value(model) } : {},
|
|
13115
|
+
...onUnavailable ? { on_unavailable: value(onUnavailable) } : {},
|
|
13116
|
+
...clear.length > 0 ? { clear } : {},
|
|
13117
|
+
revision: current.revision
|
|
13118
|
+
}),
|
|
13119
|
+
"routing.usecase.set"
|
|
13120
|
+
);
|
|
13121
|
+
}
|
|
13122
|
+
};
|
|
13123
|
+
}
|
|
13124
|
+
function routingGroupCommand() {
|
|
13125
|
+
return {
|
|
13126
|
+
verb: "routing-group",
|
|
13127
|
+
summary: "List, create and delete your routing groups, and bind Apps to them",
|
|
13128
|
+
description: "A routing group is a set of usecase settings of your own (change them with buckyos ai usecase set --group <id>); calls through an App bound to it use them over your own layer. list shows each group with its usecases, version and bound Apps; create <name> returns the new group with its id; delete <group_id> also removes its App bindings; bind <group_id> --app <app_id> binds an App or Agent (one group per App); unbind --app <app_id> removes its binding.",
|
|
13129
|
+
positionals: [
|
|
13130
|
+
{ name: "action", description: GROUP_ACTIONS.join(" | "), required: true },
|
|
13131
|
+
{ name: "target", description: "create: the name; delete, bind: the group id", required: false }
|
|
13132
|
+
],
|
|
13133
|
+
options: [{ name: "app", description: "bind, unbind: the App or Agent id", type: "string" }],
|
|
13134
|
+
inputSchema: {
|
|
13135
|
+
type: "object",
|
|
13136
|
+
properties: {
|
|
13137
|
+
action: { type: "string", enum: GROUP_ACTIONS },
|
|
13138
|
+
target: { type: "string", minLength: 1 },
|
|
13139
|
+
app: { type: "string", minLength: 1 }
|
|
13140
|
+
},
|
|
13141
|
+
required: ["action"],
|
|
13142
|
+
additionalProperties: false
|
|
13143
|
+
},
|
|
13144
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
13145
|
+
resultSchemaVersion: 1,
|
|
13146
|
+
access: { mode: "operation", operationIdField: "action", possibleLevels: ["read", "write", "destructive"] },
|
|
13147
|
+
asyncMode: "sync",
|
|
13148
|
+
requiresSession: true,
|
|
13149
|
+
examples: [
|
|
13150
|
+
"buckyos ai routing-group list",
|
|
13151
|
+
"buckyos ai routing-group create 'Cheap drafts'",
|
|
13152
|
+
"buckyos ai routing-group bind rg_1 --app writer",
|
|
13153
|
+
"buckyos ai routing-group unbind --app writer",
|
|
13154
|
+
"buckyos ai routing-group delete rg_1"
|
|
13155
|
+
],
|
|
13156
|
+
handler: async (ctx, input) => {
|
|
13157
|
+
const call2 = async (method, params) => expectObject$4(await callService(ctx, AICC, method, params), method);
|
|
13158
|
+
const action = input.action;
|
|
13159
|
+
const target = inputString(input, "target");
|
|
13160
|
+
const app = inputString(input, "app");
|
|
13161
|
+
if (action === "list")
|
|
13162
|
+
return call2("routing.groups.list", {});
|
|
13163
|
+
if ((action === "bind" || action === "unbind") && !app) {
|
|
13164
|
+
throw new UsageError("MISSING_ARGUMENT", `${action} requires --app`);
|
|
13165
|
+
}
|
|
13166
|
+
if (action === "unbind")
|
|
13167
|
+
return call2("routing.bindings.remove", { app_id: app });
|
|
13168
|
+
if (!target) {
|
|
13169
|
+
throw new UsageError("MISSING_ARGUMENT", `${action} requires ${action === "create" ? "a name" : "a group id"}`);
|
|
13170
|
+
}
|
|
13171
|
+
if (action === "create")
|
|
13172
|
+
return call2("routing.groups.create", { name: target });
|
|
13173
|
+
if (action === "bind")
|
|
13174
|
+
return call2("routing.bindings.set", { app_id: app, group_id: target });
|
|
13175
|
+
const groups = (await call2("routing.groups.list", {})).groups;
|
|
13176
|
+
const group = Array.isArray(groups) ? groups.find((item) => item.group_id === target) : void 0;
|
|
13177
|
+
if (!group)
|
|
13178
|
+
throw new ToolError("RESOURCE_NOT_FOUND", `no routing group ${target} of yours`);
|
|
13179
|
+
return call2("routing.groups.delete", { group_id: target, version: group.version });
|
|
13180
|
+
}
|
|
13181
|
+
};
|
|
13182
|
+
}
|
|
13183
|
+
function usageCommand() {
|
|
13184
|
+
return {
|
|
13185
|
+
verb: "usage",
|
|
13186
|
+
summary: "Aggregate the caller's AI usage: requests, tokens, and cost",
|
|
13187
|
+
description: "Scoped to the caller's own user (a device identity sees only its own calls, not the Zone total). Without --since the range defaults to last7d; --until defaults to now.",
|
|
13188
|
+
options: [
|
|
13189
|
+
{
|
|
13190
|
+
name: "range",
|
|
13191
|
+
description: "last1d, last7d (default), or last30d",
|
|
13192
|
+
type: "string",
|
|
13193
|
+
enum: RANGES
|
|
13194
|
+
},
|
|
13195
|
+
{ name: "since", description: "RFC 3339 or Unix ms lower bound", type: "string" },
|
|
13196
|
+
{ name: "until", description: "RFC 3339 or Unix ms upper bound", type: "string" },
|
|
13197
|
+
{
|
|
13198
|
+
name: "group-by",
|
|
13199
|
+
description: `Comma-separated: ${GROUPS.join(", ")}`,
|
|
13200
|
+
type: "string"
|
|
13201
|
+
},
|
|
13202
|
+
{
|
|
13203
|
+
name: "bucket",
|
|
13204
|
+
description: "Time buckets: hour or day",
|
|
13205
|
+
type: "string",
|
|
13206
|
+
enum: ["hour", "day"]
|
|
13207
|
+
},
|
|
13208
|
+
{ name: "events", description: "Also return the individual usage events", type: "boolean" },
|
|
13209
|
+
{ name: "limit", description: "Event page size", type: "integer" },
|
|
13210
|
+
{ name: "cursor", description: "Opaque event page cursor", type: "string" }
|
|
13211
|
+
],
|
|
13212
|
+
inputSchema: {
|
|
13213
|
+
type: "object",
|
|
13214
|
+
properties: {
|
|
13215
|
+
range: { type: "string", enum: RANGES },
|
|
13216
|
+
since: { type: "string", minLength: 1 },
|
|
13217
|
+
until: { type: "string", minLength: 1 },
|
|
13218
|
+
group_by: { type: "string", minLength: 1 },
|
|
13219
|
+
bucket: { type: "string", enum: ["hour", "day"] },
|
|
13220
|
+
events: { type: "boolean" },
|
|
13221
|
+
limit: { type: "integer", minimum: 1 },
|
|
13222
|
+
cursor: { type: "string", minLength: 1 }
|
|
13223
|
+
},
|
|
13224
|
+
additionalProperties: false
|
|
13225
|
+
},
|
|
13226
|
+
outputSchema: OBJECT_OUTPUT$5,
|
|
13227
|
+
resultSchemaVersion: 1,
|
|
13228
|
+
access: { mode: "fixed", level: "read" },
|
|
13229
|
+
asyncMode: "sync",
|
|
13230
|
+
requiresSession: true,
|
|
13231
|
+
examples: [
|
|
13232
|
+
"buckyos ai usage --range last1d --group-by provider_instance_name,provider_model",
|
|
13233
|
+
"buckyos ai usage --since 2026-10-01T00:00:00Z --bucket day"
|
|
13234
|
+
],
|
|
13235
|
+
handler: async (ctx, input) => {
|
|
13236
|
+
const groupBy = splitServices(input.group_by);
|
|
13237
|
+
const unknown = groupBy.filter((group) => !GROUPS.includes(group));
|
|
13238
|
+
if (unknown.length > 0) {
|
|
13239
|
+
throw new UsageError(
|
|
13240
|
+
"INVALID_ARGUMENT",
|
|
13241
|
+
`unknown group-by ${unknown.join(", ")}; use ${GROUPS.join(", ")}`
|
|
13242
|
+
);
|
|
13243
|
+
}
|
|
13244
|
+
return expectObject$4(
|
|
13245
|
+
await callService(ctx, AICC, "usage.query", {
|
|
13246
|
+
time_range: timeRange(input),
|
|
13247
|
+
...groupBy.length > 0 ? { group_by: groupBy } : {},
|
|
13248
|
+
...input.bucket ? { time_bucket: input.bucket } : {},
|
|
13249
|
+
output_mode: input.events === true ? "summary_and_events" : "summary",
|
|
13250
|
+
...input.limit !== void 0 ? { limit: input.limit } : {},
|
|
13251
|
+
...inputString(input, "cursor") ? { cursor: inputString(input, "cursor") } : {}
|
|
13252
|
+
}),
|
|
13253
|
+
"usage.query"
|
|
13254
|
+
);
|
|
13255
|
+
}
|
|
13256
|
+
};
|
|
13257
|
+
}
|
|
13258
|
+
function timeRange(input) {
|
|
13259
|
+
const since = parseTimestamp(input.since, "since");
|
|
13260
|
+
const until = parseTimestamp(input.until, "until");
|
|
13261
|
+
if (since === void 0) {
|
|
13262
|
+
if (until !== void 0)
|
|
13263
|
+
throw new UsageError("INVALID_ARGUMENT", "--until requires --since");
|
|
13264
|
+
return { kind: inputString(input, "range") ?? "last7d" };
|
|
13265
|
+
}
|
|
13266
|
+
if (input.range !== void 0) {
|
|
13267
|
+
throw new UsageError("ARGUMENT_CONFLICT", "--range cannot be combined with --since");
|
|
13268
|
+
}
|
|
13269
|
+
return { kind: "explicit", start_time_ms: since, end_time_ms: until ?? Date.now() };
|
|
13270
|
+
}
|
|
12848
13271
|
const OBJECT_OUTPUT$4 = { type: "object", additionalProperties: true };
|
|
12849
13272
|
const SERVICE$2 = "nfs-server";
|
|
12850
13273
|
const MAX_PUT_BYTES = 32 * 1024 * 1024;
|
|
@@ -13152,14 +13575,14 @@ function linkCommand() {
|
|
|
13152
13575
|
const target = parseBucketTarget(requiredInputString(input, "target"), true);
|
|
13153
13576
|
const text2 = inputString(input, "expires") ?? "1d";
|
|
13154
13577
|
const days = text2.match(/^(\d+)d$/);
|
|
13155
|
-
const
|
|
13156
|
-
if (
|
|
13578
|
+
const expiresAt2 = days ? Date.now() + Number(days[1]) * DAY_MS : parseTimestamp(text2, "expires");
|
|
13579
|
+
if (expiresAt2 === void 0)
|
|
13157
13580
|
throw new UsageError("INVALID_ARGUMENT", "expires is required");
|
|
13158
13581
|
const issued = await call$3(ctx, "bucket.create_access_token", {
|
|
13159
13582
|
bucket_id: target.bucketId,
|
|
13160
13583
|
key: target.key,
|
|
13161
13584
|
actions: ["read"],
|
|
13162
|
-
expires_at:
|
|
13585
|
+
expires_at: expiresAt2,
|
|
13163
13586
|
max_uses: input.max_uses
|
|
13164
13587
|
});
|
|
13165
13588
|
return { ...issued, url: `${gatewayOrigin$1(ctx.connection.endpoint)}${String(issued.path)}` };
|
|
@@ -13204,12 +13627,12 @@ function s3KeyCreateCommand() {
|
|
|
13204
13627
|
handler: async (ctx, input) => {
|
|
13205
13628
|
const text2 = inputString(input, "expires");
|
|
13206
13629
|
const days = text2?.match(/^(\d+)d$/);
|
|
13207
|
-
const
|
|
13630
|
+
const expiresAt2 = !text2 ? void 0 : days ? Date.now() + Number(days[1]) * DAY_MS : parseTimestamp(text2, "expires");
|
|
13208
13631
|
const prefix = inputString(input, "prefix");
|
|
13209
13632
|
const key = await call$3(ctx, "bucket.create_s3_key", {
|
|
13210
13633
|
appid: requiredInputString(input, "app"),
|
|
13211
13634
|
scope: prefix ? { prefix } : void 0,
|
|
13212
|
-
expires_at:
|
|
13635
|
+
expires_at: expiresAt2
|
|
13213
13636
|
});
|
|
13214
13637
|
return { ...key, endpoint: `${gatewayOrigin$1(ctx.connection.endpoint)}/s3`, region: "us-east-1", path_style: true };
|
|
13215
13638
|
}
|
|
@@ -14716,7 +15139,7 @@ const runToolCommand = {
|
|
|
14716
15139
|
const BRIDGE_PREFIX = "aiws ";
|
|
14717
15140
|
const REFUSALS = {
|
|
14718
15141
|
quota_exhausted: "AI_QUOTA_EXHAUSTED",
|
|
14719
|
-
|
|
15142
|
+
credit_insufficient: "AI_CREDIT_INSUFFICIENT",
|
|
14720
15143
|
resource_not_permitted: "AI_RESOURCE_NOT_PERMITTED",
|
|
14721
15144
|
attribution_unavailable: "AI_ATTRIBUTION_UNAVAILABLE",
|
|
14722
15145
|
credentials: "AI_UNAVAILABLE"
|