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/modules/ai.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { CommandDefinition, CommandModule, JsonSchema } from '../core/command.ts'
|
|
2
|
-
import { UsageError } from '../core/errors.ts'
|
|
2
|
+
import { ToolError, UsageError } from '../core/errors.ts'
|
|
3
|
+
import type { AccessLevel, OptionDefinition } from '../core/command.ts'
|
|
3
4
|
import {
|
|
4
5
|
callService,
|
|
5
6
|
expectObject,
|
|
6
7
|
inputString,
|
|
7
8
|
parseTimestamp,
|
|
9
|
+
requiredInputString,
|
|
8
10
|
splitServices,
|
|
9
11
|
} from '../core/service.ts'
|
|
12
|
+
import { gatewayOrigin } from './share.ts'
|
|
10
13
|
|
|
11
14
|
const AICC = 'aicc'
|
|
12
15
|
const OBJECT_OUTPUT: JsonSchema = { type: 'object', additionalProperties: true }
|
|
@@ -21,13 +24,19 @@ const GROUPS = [
|
|
|
21
24
|
'caller_app_id',
|
|
22
25
|
'user_id',
|
|
23
26
|
'tenant_id',
|
|
27
|
+
'user_group',
|
|
24
28
|
]
|
|
29
|
+
const ON_UNAVAILABLE = ['none', 'same_model', 'not_pricier', 'next_model']
|
|
30
|
+
const USECASE_FIELDS = ['model', 'on_unavailable']
|
|
31
|
+
const GROUP_ACTIONS = ['list', 'create', 'delete', 'bind', 'unbind']
|
|
32
|
+
const TOKEN_ACTIONS = ['create', 'list', 'revoke']
|
|
33
|
+
const DURATION_MS: Record<string, number> = { h: 3_600_000, d: 86_400_000, w: 7 * 86_400_000 }
|
|
25
34
|
|
|
26
|
-
//
|
|
35
|
+
// The AICC service (/kapi/aicc): read views, the usecase table and routing groups; provider changes stay in Control Panel.
|
|
27
36
|
export function createAiModule(): CommandModule {
|
|
28
37
|
return {
|
|
29
38
|
name: 'ai',
|
|
30
|
-
summary: 'Read AI
|
|
39
|
+
summary: 'Read AI providers, usecase routing and usage; set usecase models and routing groups; read AI policies and Credit; recharge Credit; issue API Tokens',
|
|
31
40
|
commands: [
|
|
32
41
|
readCommand({
|
|
33
42
|
verb: 'providers',
|
|
@@ -36,46 +45,286 @@ export function createAiModule(): CommandModule {
|
|
|
36
45
|
description:
|
|
37
46
|
'Credentials are reported only as configured/kind; secrets are never returned.',
|
|
38
47
|
}),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
method: 'routing.get',
|
|
43
|
-
description: 'An empty routing object means the default routing of the model catalog.',
|
|
44
|
-
}),
|
|
48
|
+
routingCommand(),
|
|
49
|
+
usecaseCommand(),
|
|
50
|
+
routingGroupCommand(),
|
|
45
51
|
usageCommand(),
|
|
46
|
-
|
|
52
|
+
...policyCommands(),
|
|
53
|
+
tokenCommand(),
|
|
47
54
|
],
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
interface AiccCommand {
|
|
59
|
+
verb: string
|
|
60
|
+
summary: string
|
|
61
|
+
description: string
|
|
62
|
+
method: string
|
|
63
|
+
level: AccessLevel
|
|
64
|
+
options?: (OptionDefinition & { key: string; required?: boolean; json?: boolean })[]
|
|
65
|
+
examples: string[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function aiccCommand(command: AiccCommand): CommandDefinition {
|
|
69
|
+
const options = command.options ?? []
|
|
52
70
|
return {
|
|
53
|
-
verb:
|
|
54
|
-
summary:
|
|
71
|
+
verb: command.verb,
|
|
72
|
+
summary: command.summary,
|
|
73
|
+
description: command.description,
|
|
74
|
+
options: options.map(({ key: _key, required: _required, json: _json, ...option }) => option),
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: Object.fromEntries(options.map((option) => [
|
|
78
|
+
option.name.replaceAll('-', '_'),
|
|
79
|
+
option.type === 'integer' ? { type: 'integer', minimum: 1 } : option.type === 'boolean' ? { type: 'boolean' } : { type: 'string', minLength: 1 },
|
|
80
|
+
])),
|
|
81
|
+
required: options.filter((option) => option.required).map((option) => option.name.replaceAll('-', '_')),
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
outputSchema: OBJECT_OUTPUT,
|
|
85
|
+
resultSchemaVersion: 1,
|
|
86
|
+
access: { mode: 'fixed', level: command.level },
|
|
87
|
+
asyncMode: 'sync',
|
|
88
|
+
requiresSession: true,
|
|
89
|
+
examples: command.examples,
|
|
90
|
+
handler: async (ctx, input) => {
|
|
91
|
+
const params: Record<string, unknown> = {}
|
|
92
|
+
for (const option of options) {
|
|
93
|
+
const name = option.name.replaceAll('-', '_')
|
|
94
|
+
if (option.type === 'boolean' || option.type === 'integer') {
|
|
95
|
+
if (input[name] !== undefined) params[option.key] = input[name]
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
const value = option.required ? requiredInputString(input, name) : inputString(input, name)
|
|
99
|
+
if (value === undefined) continue
|
|
100
|
+
if (option.json) {
|
|
101
|
+
try {
|
|
102
|
+
params[option.key] = JSON.parse(value)
|
|
103
|
+
} catch {
|
|
104
|
+
throw new UsageError('INVALID_ARGUMENT', `--${option.name} must be JSON`)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
params[option.key] = value
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (params.scope !== undefined) params.scope = params.scope ? 'manage' : 'mine'
|
|
111
|
+
return expectObject(await callService(ctx, AICC, command.method, params), command.method)
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const USER_OPTION = { name: 'user', key: 'user_id', description: 'Another user (administrators only); defaults to the caller', type: 'string' } as const
|
|
117
|
+
const APP_OPTION = { name: 'app', key: 'app_id', description: 'Calls through this App or Agent (its App policies apply)', type: 'string' } as const
|
|
118
|
+
|
|
119
|
+
// AI user policy, price list and Credit (buckyos doc/aicc/aicc_user_policy.md).
|
|
120
|
+
function policyCommands(): CommandDefinition[] {
|
|
121
|
+
return [
|
|
122
|
+
aiccCommand({
|
|
123
|
+
verb: 'policy',
|
|
124
|
+
summary: "Show the caller's AI Credit balance and the usage limits that apply, with their windows",
|
|
125
|
+
description:
|
|
126
|
+
'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").',
|
|
127
|
+
method: 'policy.status',
|
|
128
|
+
level: 'read',
|
|
129
|
+
options: [APP_OPTION],
|
|
130
|
+
examples: ['buckyos ai policy', 'buckyos ai policy --app aiworkspace'],
|
|
131
|
+
}),
|
|
132
|
+
aiccCommand({
|
|
133
|
+
verb: 'policy-effective',
|
|
134
|
+
summary: 'Show every model a user can see with its Credit price and source, and every limit that applies',
|
|
135
|
+
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).',
|
|
136
|
+
method: 'policy.effective',
|
|
137
|
+
level: 'read',
|
|
138
|
+
options: [USER_OPTION, APP_OPTION],
|
|
139
|
+
examples: ['buckyos ai policy-effective', 'buckyos ai policy-effective --user bob --app writer.example.zone'],
|
|
140
|
+
}),
|
|
141
|
+
aiccCommand({
|
|
142
|
+
verb: 'policies',
|
|
143
|
+
summary: 'List the AI policies that apply to the caller, or with --manage every policy of the Zone',
|
|
144
|
+
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.',
|
|
145
|
+
method: 'policy.list',
|
|
146
|
+
level: 'read',
|
|
147
|
+
options: [{ name: 'manage', key: 'scope', description: 'Every policy of the Zone (administrators only)', type: 'boolean' }],
|
|
148
|
+
examples: ['buckyos ai policies', 'buckyos ai policies --manage'],
|
|
149
|
+
}),
|
|
150
|
+
aiccCommand({
|
|
151
|
+
verb: 'prices',
|
|
152
|
+
summary: 'Show the Credit price list (token rates per million tokens) and, for administrators, Credit rates and unpriced models',
|
|
153
|
+
description: 'Keys: model:<model_driver_id>:<origin_model_id> (every Provider of the model) and exact:<model>@<provider> (one channel).',
|
|
154
|
+
method: 'price.get',
|
|
155
|
+
level: 'read',
|
|
156
|
+
examples: ['buckyos ai prices'],
|
|
157
|
+
}),
|
|
158
|
+
aiccCommand({
|
|
159
|
+
verb: 'credit',
|
|
160
|
+
summary: 'Show the AI Credit balance of the caller (or of a user, for administrators)',
|
|
161
|
+
description: 'Credit is the Zone\'s unit for AI use, unrelated to a Provider account balance; it may be negative after a large call.',
|
|
162
|
+
method: 'credit.account.get',
|
|
163
|
+
level: 'read',
|
|
164
|
+
options: [USER_OPTION],
|
|
165
|
+
examples: ['buckyos ai credit', 'buckyos ai credit --user bob'],
|
|
166
|
+
}),
|
|
167
|
+
aiccCommand({
|
|
168
|
+
verb: 'credit-ledger',
|
|
169
|
+
summary: 'List recharges, adjustments and charges of a Credit account, newest first',
|
|
170
|
+
description: 'Charges with status unpriced or unknown_usage were not charged; an administrator can charge them with credit-adjust.',
|
|
171
|
+
method: 'credit.ledger.list',
|
|
172
|
+
level: 'read',
|
|
173
|
+
options: [USER_OPTION, { name: 'limit', key: 'limit', description: 'Page size', type: 'integer' },
|
|
174
|
+
{ name: 'cursor', key: 'cursor', description: 'Opaque page cursor', type: 'string' }],
|
|
175
|
+
examples: ['buckyos ai credit-ledger', 'buckyos ai credit-ledger --user bob --limit 20'],
|
|
176
|
+
}),
|
|
177
|
+
aiccCommand({
|
|
178
|
+
verb: 'credit-recharge',
|
|
179
|
+
summary: 'Recharge a user\'s AI Credit once per id (administrators and granted payment gateways)',
|
|
180
|
+
description:
|
|
181
|
+
'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.',
|
|
182
|
+
method: 'credit.recharge',
|
|
183
|
+
level: 'privileged',
|
|
184
|
+
options: [
|
|
185
|
+
{ name: 'user', key: 'user_id', description: 'User to recharge', type: 'string', required: true },
|
|
186
|
+
{ name: 'amount', key: 'amount', description: 'Positive Credit amount, up to six decimals', type: 'string', required: true },
|
|
187
|
+
{ name: 'id', key: 'recharge_id', description: 'Idempotency id (payment order id)', type: 'string', required: true },
|
|
188
|
+
{ name: 'note', key: 'note', description: 'Note kept with the entry', type: 'string' },
|
|
189
|
+
{ name: 'external-ref', key: 'external_ref', description: 'JSON a payment gateway keeps with the entry', type: 'string', json: true },
|
|
190
|
+
],
|
|
191
|
+
examples: ["buckyos ai credit-recharge --user bob --amount 100 --id order-1001 --external-ref '{\"gateway\":\"stripe\"}'"],
|
|
192
|
+
}),
|
|
193
|
+
aiccCommand({
|
|
194
|
+
verb: 'credit-recharge-get',
|
|
195
|
+
summary: 'Look up a recharge or adjustment by its id (after a timeout, before retrying)',
|
|
196
|
+
description: 'Needs write on obj://aicc/credit/recharge.',
|
|
197
|
+
method: 'credit.recharge.get',
|
|
198
|
+
level: 'read',
|
|
199
|
+
options: [{ name: 'id', key: 'recharge_id', description: 'Recharge or adjustment id', type: 'string', required: true }],
|
|
200
|
+
examples: ['buckyos ai credit-recharge-get --id order-1001'],
|
|
201
|
+
}),
|
|
202
|
+
aiccCommand({
|
|
203
|
+
verb: 'credit-adjust',
|
|
204
|
+
summary: 'Add or remove AI Credit with a note: refunds, corrections, charging unpriced usage',
|
|
205
|
+
description: 'Needs write on obj://aicc/credit/recharge. A negative amount removes Credit; the same --id is applied once.',
|
|
206
|
+
method: 'credit.adjust',
|
|
207
|
+
level: 'privileged',
|
|
208
|
+
options: [
|
|
209
|
+
{ name: 'user', key: 'user_id', description: 'User whose balance changes', type: 'string', required: true },
|
|
210
|
+
{ name: 'amount', key: 'amount', description: 'Signed Credit amount, not zero', type: 'string', required: true },
|
|
211
|
+
{ name: 'id', key: 'adjust_id', description: 'Idempotency id', type: 'string', required: true },
|
|
212
|
+
{ name: 'note', key: 'note', description: 'Why (required)', type: 'string', required: true },
|
|
213
|
+
],
|
|
214
|
+
examples: ["buckyos ai credit-adjust --user bob --amount=-2.5 --id refund-1001 --note 'refund order 1001'"],
|
|
215
|
+
}),
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// API Tokens: AICC's own keys for other software and other Zones' AICC (notepads/aicc-zone-aicc-provider-todo.md §4.3).
|
|
220
|
+
function tokenCommand(): CommandDefinition {
|
|
221
|
+
return {
|
|
222
|
+
verb: 'token',
|
|
223
|
+
summary: 'Issue, list and revoke AICC API Tokens (bkai_… keys) for other software or another Zone\'s AICC',
|
|
55
224
|
description:
|
|
56
|
-
'
|
|
225
|
+
'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).',
|
|
226
|
+
positionals: [
|
|
227
|
+
{ name: 'action', description: TOKEN_ACTIONS.join(' | '), required: true },
|
|
228
|
+
{ name: 'token_id', description: 'revoke: the token id (16 hex digits)', required: false },
|
|
229
|
+
],
|
|
57
230
|
options: [
|
|
58
|
-
{ name: '
|
|
231
|
+
{ name: 'name', description: 'create: what the token is for, such as the other Zone or the software', type: 'string' },
|
|
232
|
+
{ name: 'group', description: 'create: a group token for this user group (administrators); list: only its tokens', type: 'string' },
|
|
233
|
+
{ name: 'user', description: 'create: a sub-account token of this user (administrators; default: you); list: only this user\'s', type: 'string' },
|
|
234
|
+
{ name: 'expires', description: 'create: 30d, 12h, 2w, RFC 3339 or Unix ms (default: never)', type: 'string' },
|
|
235
|
+
{ name: 'include-revoked', description: 'list: also revoked tokens', type: 'boolean' },
|
|
59
236
|
],
|
|
60
237
|
inputSchema: {
|
|
61
238
|
type: 'object',
|
|
62
|
-
properties: {
|
|
239
|
+
properties: {
|
|
240
|
+
action: { type: 'string', enum: TOKEN_ACTIONS },
|
|
241
|
+
token_id: { type: 'string', minLength: 1 },
|
|
242
|
+
name: { type: 'string', minLength: 1 },
|
|
243
|
+
group: { type: 'string', minLength: 1 },
|
|
244
|
+
user: { type: 'string', minLength: 1 },
|
|
245
|
+
expires: { type: 'string', minLength: 1 },
|
|
246
|
+
include_revoked: { type: 'boolean' },
|
|
247
|
+
},
|
|
248
|
+
required: ['action'],
|
|
63
249
|
additionalProperties: false,
|
|
64
250
|
},
|
|
65
251
|
outputSchema: OBJECT_OUTPUT,
|
|
66
252
|
resultSchemaVersion: 1,
|
|
67
|
-
access: { mode: '
|
|
253
|
+
access: { mode: 'operation', operationIdField: 'action', possibleLevels: ['read', 'write', 'destructive'] },
|
|
68
254
|
asyncMode: 'sync',
|
|
69
255
|
requiresSession: true,
|
|
70
|
-
examples: [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
256
|
+
examples: [
|
|
257
|
+
"buckyos ai token create --name 'my scripts' --expires 90d",
|
|
258
|
+
"buckyos ai token create --group peers --name zone-a",
|
|
259
|
+
'buckyos --output table ai token list',
|
|
260
|
+
'buckyos ai token revoke 0123456789abcdef',
|
|
261
|
+
],
|
|
262
|
+
handler: async (ctx, input) => {
|
|
263
|
+
const call = async (method: string, params: Record<string, unknown>) =>
|
|
264
|
+
expectObject(await callService(ctx, AICC, method, params), method)
|
|
265
|
+
const group = inputString(input, 'group')
|
|
266
|
+
const user = inputString(input, 'user')
|
|
267
|
+
if (input.action === 'list') {
|
|
268
|
+
const listed = await call('api_token.list', {
|
|
269
|
+
...(group ? { group_id: group } : {}),
|
|
270
|
+
...(user ? { user_id: user } : {}),
|
|
271
|
+
...(input.include_revoked === true ? { include_revoked: true } : {}),
|
|
272
|
+
})
|
|
273
|
+
const tokens = Array.isArray(listed.tokens) ? listed.tokens as Record<string, unknown>[] : []
|
|
274
|
+
return { tokens: tokens.map(tokenRow) }
|
|
275
|
+
}
|
|
276
|
+
if (input.action === 'revoke') {
|
|
277
|
+
const tokenId = inputString(input, 'token_id')
|
|
278
|
+
if (!tokenId) throw new UsageError('MISSING_ARGUMENT', 'revoke requires a token id')
|
|
279
|
+
return call('api_token.revoke', { token_id: tokenId })
|
|
280
|
+
}
|
|
281
|
+
if (group && user) throw new UsageError('ARGUMENT_CONFLICT', '--group cannot be combined with --user')
|
|
282
|
+
const name = inputString(input, 'name')
|
|
283
|
+
if (!name) throw new UsageError('MISSING_ARGUMENT', 'create requires --name')
|
|
284
|
+
const expires = expiresAt(inputString(input, 'expires'))
|
|
285
|
+
const created = await call('api_token.create', {
|
|
286
|
+
name,
|
|
287
|
+
...(expires !== undefined ? { expires_at_ms: expires } : {}),
|
|
288
|
+
...(group ? { group_id: group } : {}),
|
|
289
|
+
...(user ? { user_id: user } : {}),
|
|
290
|
+
})
|
|
291
|
+
const warning = 'Save this API key now: it is shown only this once and cannot be retrieved later.'
|
|
292
|
+
await ctx.io.stderr(`warning: ${warning}\n`)
|
|
293
|
+
const origin = gatewayOrigin(ctx.connection.endpoint)
|
|
294
|
+
return {
|
|
295
|
+
api_key: created.api_key,
|
|
296
|
+
warning,
|
|
297
|
+
base_url: `${origin}/kapi/aicc/openai/v1`,
|
|
298
|
+
aicc_endpoint: `${origin}/kapi/aicc`,
|
|
299
|
+
token: created.token,
|
|
300
|
+
}
|
|
301
|
+
},
|
|
76
302
|
}
|
|
77
303
|
}
|
|
78
304
|
|
|
305
|
+
function tokenRow(token: Record<string, unknown>): Record<string, unknown> {
|
|
306
|
+
const time = (value: unknown) => typeof value === 'number' ? new Date(value).toISOString() : ''
|
|
307
|
+
return {
|
|
308
|
+
token_id: token.token_id,
|
|
309
|
+
name: token.name,
|
|
310
|
+
kind: token.kind,
|
|
311
|
+
for: token.kind === 'group' ? `group:${token.group_id ?? ''}` : `user:${token.owner_user_id ?? ''}`,
|
|
312
|
+
state: token.state,
|
|
313
|
+
balance: token.balance ?? '',
|
|
314
|
+
last_used: time(token.last_used_at_ms),
|
|
315
|
+
expires: time(token.expires_at_ms),
|
|
316
|
+
created: time(token.created_at_ms),
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function expiresAt(text: string | undefined): number | undefined {
|
|
321
|
+
if (!text) return undefined
|
|
322
|
+
const duration = text.match(/^(\d+)([hdw])$/)
|
|
323
|
+
const at = duration ? Date.now() + Number(duration[1]) * DURATION_MS[duration[2]] : parseTimestamp(text, 'expires')
|
|
324
|
+
if (at === undefined || at <= Date.now()) throw new UsageError('INVALID_ARGUMENT', '--expires must be in the future')
|
|
325
|
+
return at
|
|
326
|
+
}
|
|
327
|
+
|
|
79
328
|
function readCommand(options: {
|
|
80
329
|
verb: string
|
|
81
330
|
summary: string
|
|
@@ -98,6 +347,194 @@ function readCommand(options: {
|
|
|
98
347
|
}
|
|
99
348
|
}
|
|
100
349
|
|
|
350
|
+
// The usecase table (buckyos doc/aicc/aicc_router.md §11–§12).
|
|
351
|
+
function routingCommand(): CommandDefinition {
|
|
352
|
+
return {
|
|
353
|
+
verb: 'routing',
|
|
354
|
+
summary: 'Show the usecase table: the model each usecase routes to, who set it, and what happens when it is unavailable',
|
|
355
|
+
description:
|
|
356
|
+
'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.',
|
|
357
|
+
options: [
|
|
358
|
+
{ name: 'view', description: 'zone (administrators), group:<id> or app:<app_id>; defaults to the caller', type: 'string' },
|
|
359
|
+
{ name: 'json', description: 'The whole routing.usecases response instead of one line per usecase', type: 'boolean' },
|
|
360
|
+
],
|
|
361
|
+
inputSchema: {
|
|
362
|
+
type: 'object',
|
|
363
|
+
properties: { view: { type: 'string', minLength: 1 }, json: { type: 'boolean' } },
|
|
364
|
+
additionalProperties: false,
|
|
365
|
+
},
|
|
366
|
+
outputSchema: OBJECT_OUTPUT,
|
|
367
|
+
resultSchemaVersion: 1,
|
|
368
|
+
access: { mode: 'fixed', level: 'read' },
|
|
369
|
+
asyncMode: 'sync',
|
|
370
|
+
requiresSession: true,
|
|
371
|
+
examples: ['buckyos --output table ai routing', 'buckyos ai routing --view zone', 'buckyos ai routing --view app:writer --json'],
|
|
372
|
+
handler: async (ctx, input) => {
|
|
373
|
+
const view = inputString(input, 'view')
|
|
374
|
+
const table = expectObject(await callService(ctx, AICC, 'routing.usecases', view ? { view } : {}), 'routing.usecases')
|
|
375
|
+
if (input.json === true) return table
|
|
376
|
+
const rows = Array.isArray(table.rows) ? table.rows as Record<string, unknown>[] : []
|
|
377
|
+
return {
|
|
378
|
+
view: table.view,
|
|
379
|
+
revision: table.revision,
|
|
380
|
+
can_edit: table.can_edit,
|
|
381
|
+
usecases: rows.map((row) => {
|
|
382
|
+
const lock = (locked: unknown) => locked === true ? ', locked' : ''
|
|
383
|
+
const policySource = row.on_unavailable_source === 'default' && row.on_unavailable_locked !== true
|
|
384
|
+
? ''
|
|
385
|
+
: ` (${row.on_unavailable_source}${lock(row.on_unavailable_locked)})`
|
|
386
|
+
return {
|
|
387
|
+
usecase: row.usecase,
|
|
388
|
+
model: row.model ?? '',
|
|
389
|
+
source: row.model_source ? `${row.model_source}${lock(row.model_locked)}` : '',
|
|
390
|
+
on_unavailable: `${row.on_unavailable}${policySource}`,
|
|
391
|
+
would_switch_to: row.fallback_to ?? (row.fallback_note ? `(${row.fallback_note})` : ''),
|
|
392
|
+
coverage: row.coverage_reason ? `${row.coverage} (${row.coverage_reason})` : row.coverage,
|
|
393
|
+
...(row.enabled !== undefined ? { enabled: row.enabled } : {}),
|
|
394
|
+
}
|
|
395
|
+
}),
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function usecaseCommand(): CommandDefinition {
|
|
402
|
+
return {
|
|
403
|
+
verb: 'usecase',
|
|
404
|
+
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',
|
|
405
|
+
description:
|
|
406
|
+
'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.',
|
|
407
|
+
positionals: [
|
|
408
|
+
{ name: 'action', description: 'set', required: true },
|
|
409
|
+
{ name: 'usecase', description: 'A usecase such as llm.code or image.txt2img (buckyos ai routing lists them)', required: true },
|
|
410
|
+
],
|
|
411
|
+
options: [
|
|
412
|
+
{ name: 'model', description: 'Exact model <model>@<provider>', type: 'string' },
|
|
413
|
+
{ name: 'on-unavailable', description: ON_UNAVAILABLE.join(' | '), type: 'string', enum: ON_UNAVAILABLE },
|
|
414
|
+
{ name: 'clear', description: `Comma-separated: ${USECASE_FIELDS.join(', ')}`, type: 'string' },
|
|
415
|
+
{ name: 'zone-default', description: 'The administrator layer, the Zone default (administrators)', type: 'boolean' },
|
|
416
|
+
{ name: 'group', description: 'One of your routing groups, by id', type: 'string' },
|
|
417
|
+
{ name: 'lock', description: 'With --zone-default: what this sets cannot be changed by users or groups', type: 'boolean' },
|
|
418
|
+
],
|
|
419
|
+
inputSchema: {
|
|
420
|
+
type: 'object',
|
|
421
|
+
properties: {
|
|
422
|
+
action: { type: 'string', enum: ['set'] },
|
|
423
|
+
usecase: { type: 'string', minLength: 1 },
|
|
424
|
+
model: { type: 'string', minLength: 1 },
|
|
425
|
+
on_unavailable: { type: 'string', enum: ON_UNAVAILABLE },
|
|
426
|
+
clear: { type: 'string', minLength: 1 },
|
|
427
|
+
zone_default: { type: 'boolean' },
|
|
428
|
+
group: { type: 'string', minLength: 1 },
|
|
429
|
+
lock: { type: 'boolean' },
|
|
430
|
+
},
|
|
431
|
+
required: ['action', 'usecase'],
|
|
432
|
+
additionalProperties: false,
|
|
433
|
+
},
|
|
434
|
+
outputSchema: OBJECT_OUTPUT,
|
|
435
|
+
resultSchemaVersion: 1,
|
|
436
|
+
access: { mode: 'fixed', level: 'write' },
|
|
437
|
+
asyncMode: 'sync',
|
|
438
|
+
requiresSession: true,
|
|
439
|
+
examples: [
|
|
440
|
+
'buckyos ai usecase set llm.code --model gpt-6@openai-main --on-unavailable same_model',
|
|
441
|
+
'buckyos ai usecase set llm.chat --group rg_1 --clear model',
|
|
442
|
+
'buckyos ai usecase set image.txt2img --zone-default --model gpt-image-2@openai-main --lock',
|
|
443
|
+
],
|
|
444
|
+
handler: async (ctx, input) => {
|
|
445
|
+
const group = inputString(input, 'group')
|
|
446
|
+
if (group && input.zone_default === true) throw new UsageError('ARGUMENT_CONFLICT', '--zone-default cannot be combined with --group')
|
|
447
|
+
if (input.lock === true && input.zone_default !== true) throw new UsageError('INVALID_ARGUMENT', '--lock requires --zone-default')
|
|
448
|
+
const model = inputString(input, 'model')
|
|
449
|
+
const onUnavailable = inputString(input, 'on_unavailable')
|
|
450
|
+
const clear = splitServices(input.clear)
|
|
451
|
+
const unknown = clear.filter((field) => !USECASE_FIELDS.includes(field))
|
|
452
|
+
if (unknown.length > 0) {
|
|
453
|
+
throw new UsageError('INVALID_ARGUMENT', `unknown --clear ${unknown.join(', ')}; use ${USECASE_FIELDS.join(', ')}`)
|
|
454
|
+
}
|
|
455
|
+
if (!model && !onUnavailable && clear.length === 0) {
|
|
456
|
+
throw new UsageError('MISSING_ARGUMENT', 'give --model, --on-unavailable or --clear')
|
|
457
|
+
}
|
|
458
|
+
const target = input.zone_default === true ? 'zone' : group ? `group:${group}` : 'user'
|
|
459
|
+
const current = expectObject(
|
|
460
|
+
await callService(ctx, AICC, 'routing.usecases', { view: target === 'user' ? 'self' : target }),
|
|
461
|
+
'routing.usecases',
|
|
462
|
+
)
|
|
463
|
+
const value = (v: string) => input.lock === true ? { value: v, locked: true } : v
|
|
464
|
+
return expectObject(
|
|
465
|
+
await callService(ctx, AICC, 'routing.usecase.set', {
|
|
466
|
+
target,
|
|
467
|
+
usecase: requiredInputString(input, 'usecase'),
|
|
468
|
+
...(model ? { model: value(model) } : {}),
|
|
469
|
+
...(onUnavailable ? { on_unavailable: value(onUnavailable) } : {}),
|
|
470
|
+
...(clear.length > 0 ? { clear } : {}),
|
|
471
|
+
revision: current.revision,
|
|
472
|
+
}),
|
|
473
|
+
'routing.usecase.set',
|
|
474
|
+
)
|
|
475
|
+
},
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function routingGroupCommand(): CommandDefinition {
|
|
480
|
+
return {
|
|
481
|
+
verb: 'routing-group',
|
|
482
|
+
summary: 'List, create and delete your routing groups, and bind Apps to them',
|
|
483
|
+
description:
|
|
484
|
+
'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.',
|
|
485
|
+
positionals: [
|
|
486
|
+
{ name: 'action', description: GROUP_ACTIONS.join(' | '), required: true },
|
|
487
|
+
{ name: 'target', description: 'create: the name; delete, bind: the group id', required: false },
|
|
488
|
+
],
|
|
489
|
+
options: [{ name: 'app', description: 'bind, unbind: the App or Agent id', type: 'string' }],
|
|
490
|
+
inputSchema: {
|
|
491
|
+
type: 'object',
|
|
492
|
+
properties: {
|
|
493
|
+
action: { type: 'string', enum: GROUP_ACTIONS },
|
|
494
|
+
target: { type: 'string', minLength: 1 },
|
|
495
|
+
app: { type: 'string', minLength: 1 },
|
|
496
|
+
},
|
|
497
|
+
required: ['action'],
|
|
498
|
+
additionalProperties: false,
|
|
499
|
+
},
|
|
500
|
+
outputSchema: OBJECT_OUTPUT,
|
|
501
|
+
resultSchemaVersion: 1,
|
|
502
|
+
access: { mode: 'operation', operationIdField: 'action', possibleLevels: ['read', 'write', 'destructive'] },
|
|
503
|
+
asyncMode: 'sync',
|
|
504
|
+
requiresSession: true,
|
|
505
|
+
examples: [
|
|
506
|
+
'buckyos ai routing-group list',
|
|
507
|
+
"buckyos ai routing-group create 'Cheap drafts'",
|
|
508
|
+
'buckyos ai routing-group bind rg_1 --app writer',
|
|
509
|
+
'buckyos ai routing-group unbind --app writer',
|
|
510
|
+
'buckyos ai routing-group delete rg_1',
|
|
511
|
+
],
|
|
512
|
+
handler: async (ctx, input) => {
|
|
513
|
+
const call = async (method: string, params: Record<string, unknown>) =>
|
|
514
|
+
expectObject(await callService(ctx, AICC, method, params), method)
|
|
515
|
+
const action = input.action
|
|
516
|
+
const target = inputString(input, 'target')
|
|
517
|
+
const app = inputString(input, 'app')
|
|
518
|
+
if (action === 'list') return call('routing.groups.list', {})
|
|
519
|
+
if ((action === 'bind' || action === 'unbind') && !app) {
|
|
520
|
+
throw new UsageError('MISSING_ARGUMENT', `${action} requires --app`)
|
|
521
|
+
}
|
|
522
|
+
if (action === 'unbind') return call('routing.bindings.remove', { app_id: app })
|
|
523
|
+
if (!target) {
|
|
524
|
+
throw new UsageError('MISSING_ARGUMENT', `${action} requires ${action === 'create' ? 'a name' : 'a group id'}`)
|
|
525
|
+
}
|
|
526
|
+
if (action === 'create') return call('routing.groups.create', { name: target })
|
|
527
|
+
if (action === 'bind') return call('routing.bindings.set', { app_id: app, group_id: target })
|
|
528
|
+
const groups = (await call('routing.groups.list', {})).groups
|
|
529
|
+
const group = Array.isArray(groups)
|
|
530
|
+
? (groups as Record<string, unknown>[]).find((item) => item.group_id === target)
|
|
531
|
+
: undefined
|
|
532
|
+
if (!group) throw new ToolError('RESOURCE_NOT_FOUND', `no routing group ${target} of yours`)
|
|
533
|
+
return call('routing.groups.delete', { group_id: target, version: group.version })
|
|
534
|
+
},
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
101
538
|
function usageCommand(): CommandDefinition {
|
|
102
539
|
return {
|
|
103
540
|
verb: 'usage',
|
package/cli/modules/aiws.ts
CHANGED
|
@@ -792,7 +792,7 @@ const runToolCommand: CommandDefinition = {
|
|
|
792
792
|
|
|
793
793
|
const BRIDGE_PREFIX = '\x1eaiws '
|
|
794
794
|
const REFUSALS: Record<string, string> = {
|
|
795
|
-
quota_exhausted: 'AI_QUOTA_EXHAUSTED',
|
|
795
|
+
quota_exhausted: 'AI_QUOTA_EXHAUSTED', credit_insufficient: 'AI_CREDIT_INSUFFICIENT', resource_not_permitted: 'AI_RESOURCE_NOT_PERMITTED',
|
|
796
796
|
attribution_unavailable: 'AI_ATTRIBUTION_UNAVAILABLE', credentials: 'AI_UNAVAILABLE',
|
|
797
797
|
}
|
|
798
798
|
|
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.
|
|
2
|
+
export const PACKAGE_VERSION = '0.7.209'
|
|
3
3
|
export const TOOL_VERSION = PACKAGE_VERSION
|
|
4
4
|
export const SDK_VERSION = PACKAGE_VERSION
|
|
5
5
|
export const PROTOCOL_VERSION = '1'
|
|
@@ -401,11 +401,11 @@ function addRecordUsage(base, extra) {
|
|
|
401
401
|
return cur;
|
|
402
402
|
}
|
|
403
403
|
const REFUSED_QUOTA_EXHAUSTED = "quota_exhausted";
|
|
404
|
-
const
|
|
404
|
+
const REFUSED_CREDIT_INSUFFICIENT = "credit_insufficient";
|
|
405
405
|
const REFUSED_RESOURCE_NOT_PERMITTED = "resource_not_permitted";
|
|
406
406
|
const REFUSED_ATTRIBUTION_UNAVAILABLE = "attribution_unavailable";
|
|
407
407
|
const REFUSED_CREDENTIALS = "credentials";
|
|
408
|
-
const REFUSAL_CODES = [REFUSED_QUOTA_EXHAUSTED,
|
|
408
|
+
const REFUSAL_CODES = [REFUSED_QUOTA_EXHAUSTED, REFUSED_CREDIT_INSUFFICIENT, REFUSED_RESOURCE_NOT_PERMITTED, REFUSED_ATTRIBUTION_UNAVAILABLE];
|
|
409
409
|
function anyJsonObjectSchema() {
|
|
410
410
|
return { type: "object", additionalProperties: true };
|
|
411
411
|
}
|
|
@@ -462,8 +462,9 @@ function aiccErrorText(e) {
|
|
|
462
462
|
return e ? ` (${e.code}: ${e.message})` : "";
|
|
463
463
|
}
|
|
464
464
|
class AiccLlmClient {
|
|
465
|
-
constructor(client) {
|
|
465
|
+
constructor(client, options = {}) {
|
|
466
466
|
this.client = client;
|
|
467
|
+
this.options = options;
|
|
467
468
|
}
|
|
468
469
|
async infer(req) {
|
|
469
470
|
var _a;
|
|
@@ -504,7 +505,8 @@ class AiccLlmClient {
|
|
|
504
505
|
logical_model: req.model_alias,
|
|
505
506
|
...common,
|
|
506
507
|
...Object.keys(requirements).length ? { requirements } : {},
|
|
507
|
-
...Object.keys(disable).length ? { disable } : {}
|
|
508
|
+
...Object.keys(disable).length ? { disable } : {},
|
|
509
|
+
...this.options.route_group ? { route_group: this.options.route_group } : {}
|
|
508
510
|
};
|
|
509
511
|
response = await this.client.helperLlmChat(r);
|
|
510
512
|
}
|
|
@@ -579,4 +581,4 @@ export {
|
|
|
579
581
|
mergeUsage as y,
|
|
580
582
|
rustTextContent as z
|
|
581
583
|
};
|
|
582
|
-
//# sourceMappingURL=aicc-
|
|
584
|
+
//# sourceMappingURL=aicc-286ba457.mjs.map
|