buckyos 0.7.208 → 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.
Files changed (49) hide show
  1. package/cli/dist/cli.mjs +602 -179
  2. package/cli/dist/cli.mjs.map +1 -1
  3. package/cli/modules/ai.ts +460 -23
  4. package/cli/modules/aiws.ts +1 -1
  5. package/cli/version.ts +1 -1
  6. package/dist/{aicc-67851c41.mjs → aicc-286ba457.mjs} +7 -5
  7. package/dist/aicc-286ba457.mjs.map +1 -0
  8. package/dist/aicc-342f2659.js +2 -0
  9. package/dist/aicc-342f2659.js.map +1 -0
  10. package/dist/aicc_client.d.ts +623 -288
  11. package/dist/aicc_client.d.ts.map +1 -1
  12. package/dist/{aiws_write-83ddc6cc.mjs → aiws_write-5b542439.mjs} +203 -134
  13. package/dist/aiws_write-5b542439.mjs.map +1 -0
  14. package/dist/aiws_write-a0769003.js +13 -0
  15. package/dist/aiws_write-a0769003.js.map +1 -0
  16. package/dist/browser.cjs +1 -1
  17. package/dist/browser.mjs +85 -78
  18. package/dist/{content_objid-76434848.mjs → content_objid-09031ce1.mjs} +2 -2
  19. package/dist/{content_objid-76434848.mjs.map → content_objid-09031ce1.mjs.map} +1 -1
  20. package/dist/{content_objid-addf9e2b.js → content_objid-6342d0ba.js} +2 -2
  21. package/dist/{content_objid-addf9e2b.js.map → content_objid-6342d0ba.js.map} +1 -1
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.mjs +85 -78
  24. package/dist/node.cjs +1 -1
  25. package/dist/node.mjs +84 -77
  26. package/dist/{openai-ae2978de.mjs → openai-1c0d8341.mjs} +2 -2
  27. package/dist/{openai-ae2978de.mjs.map → openai-1c0d8341.mjs.map} +1 -1
  28. package/dist/{openai-f560d518.js → openai-7aa4ffbf.js} +2 -2
  29. package/dist/{openai-f560d518.js.map → openai-7aa4ffbf.js.map} +1 -1
  30. package/dist/{site_manager-604ee369.mjs → site_manager-4f1940eb.mjs} +4 -4
  31. package/dist/{site_manager-604ee369.mjs.map → site_manager-4f1940eb.mjs.map} +1 -1
  32. package/dist/{site_manager-70710895.js → site_manager-ca22ffbd.js} +2 -2
  33. package/dist/{site_manager-70710895.js.map → site_manager-ca22ffbd.js.map} +1 -1
  34. package/dist/xllm/core/run.d.ts.map +1 -1
  35. package/dist/xllm/providers/aicc.d.ts +7 -3
  36. package/dist/xllm/providers/aicc.d.ts.map +1 -1
  37. package/dist/xllm.cjs +1 -1
  38. package/dist/xllm.mjs +4 -4
  39. package/dist/xllm_deno.cjs +1 -1
  40. package/dist/xllm_deno.mjs +3 -3
  41. package/dist/xllm_dev.cjs +1 -1
  42. package/dist/xllm_dev.mjs +2 -2
  43. package/package.json +1 -1
  44. package/dist/aicc-67851c41.mjs.map +0 -1
  45. package/dist/aicc-ccb36ef7.js +0 -2
  46. package/dist/aicc-ccb36ef7.js.map +0 -1
  47. package/dist/aiws_write-825bb6ba.js +0 -13
  48. package/dist/aiws_write-825bb6ba.js.map +0 -1
  49. package/dist/aiws_write-83ddc6cc.mjs.map +0 -1
@@ -36,7 +36,6 @@ export declare const AICC_CORE_METHODS: {
36
36
  };
37
37
  export declare const AICC_MANAGEMENT_METHODS: {
38
38
  readonly SERVICE_RELOAD_SETTINGS: "service.reload_settings";
39
- readonly QUOTA_QUERY: "quota.query";
40
39
  readonly USAGE_QUERY: "usage.query";
41
40
  readonly TRACE_QUERY: "trace.query";
42
41
  readonly ROUTING_GET: "routing.get";
@@ -56,36 +55,69 @@ export declare const AICC_MANAGEMENT_METHODS: {
56
55
  readonly DRIVER_METADATA_UPDATE_GET: "driver_metadata_update.get";
57
56
  readonly DRIVER_METADATA_UPDATE_SET: "driver_metadata_update.set";
58
57
  };
59
- /** Token quota and resource visibility (product/ai_center/AI_Center_Quota_PRD.md). */
60
- export declare const AICC_QUOTA_METHODS: {
61
- readonly RULE_LIST: "quota.rule.list";
62
- readonly RULE_GET: "quota.rule.get";
63
- readonly RULE_PREVIEW: "quota.rule.preview";
64
- readonly RULE_CREATE: "quota.rule.create";
65
- readonly RULE_UPDATE: "quota.rule.update";
66
- readonly RULE_DELETE: "quota.rule.delete";
67
- readonly ACCOUNT_GET: "quota.account.get";
68
- readonly ACCOUNT_RECHARGE: "quota.account.recharge";
69
- readonly RECHARGE_GET: "quota.recharge.get";
70
- readonly VISIBILITY_GET: "visibility.get";
71
- readonly VISIBILITY_UPDATE: "visibility.update";
72
- readonly VISIBILITY_PREVIEW: "visibility.preview";
58
+ /** User policy, Credit price list and Credit accounts (buckyos doc/aicc/aicc_user_policy.md). */
59
+ export declare const AICC_POLICY_METHODS: {
60
+ readonly POLICY_LIST: "policy.list";
61
+ readonly POLICY_GET: "policy.get";
62
+ readonly POLICY_UPSERT: "policy.upsert";
63
+ readonly POLICY_DELETE: "policy.delete";
64
+ readonly POLICY_EFFECTIVE: "policy.effective";
65
+ readonly POLICY_STATUS: "policy.status";
66
+ readonly PRICE_GET: "price.get";
67
+ readonly PRICE_UPDATE: "price.update";
68
+ readonly CREDIT_ACCOUNT_GET: "credit.account.get";
69
+ readonly CREDIT_ACCOUNT_LIST: "credit.account.list";
70
+ readonly CREDIT_LEDGER_LIST: "credit.ledger.list";
71
+ readonly CREDIT_RECHARGE: "credit.recharge";
72
+ readonly CREDIT_RECHARGE_GET: "credit.recharge.get";
73
+ readonly CREDIT_ADJUST: "credit.adjust";
74
+ };
75
+ /** The usecase table, routing groups and App bindings (buckyos doc/aicc/aicc_router.md §11–§12). */
76
+ export declare const AICC_ROUTING_METHODS: {
77
+ readonly ROUTING_USECASES: "routing.usecases";
78
+ readonly ROUTING_USECASE_SET: "routing.usecase.set";
79
+ readonly ROUTING_GROUPS_LIST: "routing.groups.list";
80
+ readonly ROUTING_GROUPS_CREATE: "routing.groups.create";
81
+ readonly ROUTING_GROUPS_UPDATE: "routing.groups.update";
82
+ readonly ROUTING_GROUPS_DELETE: "routing.groups.delete";
83
+ readonly ROUTING_BINDINGS_LIST: "routing.bindings.list";
84
+ readonly ROUTING_BINDINGS_SET: "routing.bindings.set";
85
+ readonly ROUTING_BINDINGS_REMOVE: "routing.bindings.remove";
86
+ };
87
+ /** API Tokens (buckyos doc/aicc/aicc_user_policy.md, notepads/aicc-zone-aicc-provider-todo.md §4.3). */
88
+ export declare const AICC_API_TOKEN_METHODS: {
89
+ readonly API_TOKEN_CREATE: "api_token.create";
90
+ readonly API_TOKEN_LIST: "api_token.list";
91
+ readonly API_TOKEN_REVOKE: "api_token.revoke";
73
92
  };
74
93
  export declare const AICC_METHODS: {
75
- readonly RULE_LIST: "quota.rule.list";
76
- readonly RULE_GET: "quota.rule.get";
77
- readonly RULE_PREVIEW: "quota.rule.preview";
78
- readonly RULE_CREATE: "quota.rule.create";
79
- readonly RULE_UPDATE: "quota.rule.update";
80
- readonly RULE_DELETE: "quota.rule.delete";
81
- readonly ACCOUNT_GET: "quota.account.get";
82
- readonly ACCOUNT_RECHARGE: "quota.account.recharge";
83
- readonly RECHARGE_GET: "quota.recharge.get";
84
- readonly VISIBILITY_GET: "visibility.get";
85
- readonly VISIBILITY_UPDATE: "visibility.update";
86
- readonly VISIBILITY_PREVIEW: "visibility.preview";
94
+ readonly API_TOKEN_CREATE: "api_token.create";
95
+ readonly API_TOKEN_LIST: "api_token.list";
96
+ readonly API_TOKEN_REVOKE: "api_token.revoke";
97
+ readonly ROUTING_USECASES: "routing.usecases";
98
+ readonly ROUTING_USECASE_SET: "routing.usecase.set";
99
+ readonly ROUTING_GROUPS_LIST: "routing.groups.list";
100
+ readonly ROUTING_GROUPS_CREATE: "routing.groups.create";
101
+ readonly ROUTING_GROUPS_UPDATE: "routing.groups.update";
102
+ readonly ROUTING_GROUPS_DELETE: "routing.groups.delete";
103
+ readonly ROUTING_BINDINGS_LIST: "routing.bindings.list";
104
+ readonly ROUTING_BINDINGS_SET: "routing.bindings.set";
105
+ readonly ROUTING_BINDINGS_REMOVE: "routing.bindings.remove";
106
+ readonly POLICY_LIST: "policy.list";
107
+ readonly POLICY_GET: "policy.get";
108
+ readonly POLICY_UPSERT: "policy.upsert";
109
+ readonly POLICY_DELETE: "policy.delete";
110
+ readonly POLICY_EFFECTIVE: "policy.effective";
111
+ readonly POLICY_STATUS: "policy.status";
112
+ readonly PRICE_GET: "price.get";
113
+ readonly PRICE_UPDATE: "price.update";
114
+ readonly CREDIT_ACCOUNT_GET: "credit.account.get";
115
+ readonly CREDIT_ACCOUNT_LIST: "credit.account.list";
116
+ readonly CREDIT_LEDGER_LIST: "credit.ledger.list";
117
+ readonly CREDIT_RECHARGE: "credit.recharge";
118
+ readonly CREDIT_RECHARGE_GET: "credit.recharge.get";
119
+ readonly CREDIT_ADJUST: "credit.adjust";
87
120
  readonly SERVICE_RELOAD_SETTINGS: "service.reload_settings";
88
- readonly QUOTA_QUERY: "quota.query";
89
121
  readonly USAGE_QUERY: "usage.query";
90
122
  readonly TRACE_QUERY: "trace.query";
91
123
  readonly ROUTING_GET: "routing.get";
@@ -240,14 +272,16 @@ export interface AiArtifact {
240
272
  mime?: string;
241
273
  metadata?: JsonValue;
242
274
  }
243
- export type AiccErrorCode = 'invalid_request' | 'invalid_method' | 'schema_validation_failed' | 'invalid_model_name' | 'resource_invalid' | 'no_provider_available' | 'no_candidate_model' | 'fallback_not_allowed' | 'provider_start_failed' | 'provider_error' | 'unsupported_execution_mode' | 'timeout' | 'budget_exceeded' | 'policy_denied' | 'idempotency_conflict' | 'settings_revision_conflict' | 'cancelled' | 'internal_error' |
244
- /** An enabled token quota rule has nothing left (`details`: QuotaDenialDetails). */
275
+ export type AiccErrorCode = 'invalid_request' | 'invalid_method' | 'schema_validation_failed' | 'invalid_model_name' | 'resource_invalid' | 'no_provider_available' | 'no_candidate_model' | 'provider_start_failed' | 'provider_error' | 'unsupported_execution_mode' | 'timeout' | 'budget_exceeded' | 'policy_denied' | 'idempotency_conflict' | 'settings_revision_conflict' | 'cancelled' | 'internal_error' |
276
+ /** A time window limit that applies to the call is used up (`details`: QuotaDenialDetails). */
245
277
  'quota_exhausted' |
246
- /** Tokens are left but fewer than the call reserves; lower the budget (`details`: QuotaDenialDetails). */
247
- 'quota_budget_exceeded' |
248
- /** A configured rule could not be read or reserved; retry later, never treat it as unlimited. */
278
+ /** The model is priced for the caller and their AI Credit balance is not above zero
279
+ * (`details`: CreditInsufficientDetails). Not a Provider account running out of credits. */
280
+ 'credit_insufficient' |
281
+ /** Policies, the balance or a limit counter could not be read; retry later, never treat it as unlimited. */
249
282
  'quota_unavailable' |
250
- /** The Provider / model is not permitted to the caller (hidden identities are not disclosed). */
283
+ /** The Provider / model is not permitted to the caller (hidden identities are not disclosed), or it has no
284
+ * price for a caller who pays (`details.reason === 'unpriced'`). */
251
285
  'resource_not_permitted' |
252
286
  /** The AICC user of a delegated run cannot be determined. */
253
287
  'attribution_unavailable' |
@@ -260,7 +294,7 @@ export interface AiccError {
260
294
  retriable?: boolean;
261
295
  details?: JsonValue;
262
296
  }
263
- /** Token quota and resource policy refusals: they reach the client as a detailed kRPC error. */
297
+ /** User policy refusals: they reach the client as a detailed kRPC error. */
264
298
  export declare const AICC_POLICY_REFUSAL_CODES: readonly AiccErrorCode[];
265
299
  /** The AICC error of a refused call (its `code` and `details`), read from the structured kRPC error. */
266
300
  export declare function aiccRefusalOf(error: unknown): AiccError | undefined;
@@ -277,9 +311,11 @@ export interface RouteTraceAttempt {
277
311
  error_code?: AiccErrorCode;
278
312
  fallback_reason?: string;
279
313
  }
314
+ /** `fallback`: set when the answer did not come from the usecase's own model. */
280
315
  export interface RouteTrace {
281
316
  attempts: RouteTraceAttempt[];
282
317
  final_model?: string;
318
+ fallback?: RouteFallback;
283
319
  }
284
320
  export interface AiToolCall {
285
321
  name: string;
@@ -311,11 +347,11 @@ export interface ModelDisable extends Omit<ModelRequirement, "decision" | "video
311
347
  }
312
348
  export interface HelperModelRequirement extends Omit<ModelRequirement, "decision"> {
313
349
  }
350
+ /** `no_fallback`: turn off the usecase's "when unavailable" policy for this request. */
314
351
  export interface RoutePolicy {
315
- profile?: 'cheap' | 'fast' | 'balanced' | 'quality';
352
+ profile?: 'fast' | 'balanced' | 'quality';
316
353
  local_only?: boolean;
317
- allow_fallback?: boolean;
318
- runtime_failover?: boolean;
354
+ no_fallback?: boolean;
319
355
  explain?: boolean;
320
356
  allowed_provider_instances?: string[];
321
357
  blocked_provider_instances?: string[];
@@ -330,28 +366,18 @@ export interface ModelItemPatch {
330
366
  target?: string;
331
367
  weight?: number;
332
368
  }
333
- export type OverlayMergeMode = 'inherit' | 'replace';
334
- export type AiccFallbackMode = 'strict' | 'parent' | 'target_exact' | 'target_logical' | 'disabled';
335
- export interface AiccFallbackRule {
336
- mode: AiccFallbackMode;
337
- target?: string;
338
- }
339
- export type AiccSchedulerProfile = 'cost_first' | 'latency_first' | 'quality_first' | 'balanced' | 'local_first' | 'strict_local';
369
+ export type AiccSchedulerProfile = 'latency_first' | 'quality_first' | 'balanced' | 'local_first' | 'strict_local';
340
370
  export type LockedValue<T> = T | {
341
371
  value: T;
342
372
  locked?: boolean;
343
373
  };
344
374
  export interface AiccSchedulerProfileWeights {
345
- cost?: number;
346
- latency?: number;
347
- reliability?: number;
348
375
  quality?: number;
349
376
  preference?: number;
350
377
  cache?: number;
351
378
  local?: number;
352
379
  }
353
380
  export interface AiccSchedulerProfileConfig {
354
- cost_first?: AiccSchedulerProfileWeights;
355
381
  latency_first?: AiccSchedulerProfileWeights;
356
382
  quality_first?: AiccSchedulerProfileWeights;
357
383
  balanced?: AiccSchedulerProfileWeights;
@@ -362,9 +388,6 @@ export interface AiccPolicyConfig {
362
388
  profile?: LockedValue<AiccSchedulerProfile>;
363
389
  scheduler_profiles?: LockedValue<AiccSchedulerProfileConfig>;
364
390
  local_only?: LockedValue<boolean>;
365
- allow_fallback?: LockedValue<boolean>;
366
- allow_exact_model_fallback?: LockedValue<boolean>;
367
- runtime_failover?: LockedValue<boolean>;
368
391
  explain?: LockedValue<boolean>;
369
392
  blocked_provider_instances?: LockedValue<string[]>;
370
393
  allowed_provider_instances?: LockedValue<string[]>;
@@ -377,37 +400,168 @@ export interface AiccLogicalNodeOverlay {
377
400
  item_overrides?: Record<string, ModelItemPatch>;
378
401
  exact_model_weights?: Record<string, number>;
379
402
  disable_line?: ModelDisable;
380
- fallback?: AiccFallbackRule;
381
403
  policy?: AiccPolicyConfig;
382
404
  route_policy_override?: AiccPolicyConfig;
383
405
  }
384
- export interface AiccLogicalTreeOverlay {
406
+ export type AiccRoutingCommand = {
407
+ kind: 'vendor_factor';
408
+ vendor: string;
409
+ factor: number;
410
+ } | {
411
+ kind: 'spec_factor';
412
+ spec: string;
413
+ factor: number;
414
+ } | {
415
+ kind: 'model_factor';
416
+ vendor: string;
417
+ model: string;
418
+ factor: number;
419
+ } | {
420
+ kind: 'item_weight';
385
421
  path: string;
386
- merge_mode?: OverlayMergeMode;
387
- items?: Record<string, ModelItem>;
388
- item_overrides?: Record<string, ModelItemPatch>;
389
- exact_model_weights?: Record<string, number>;
390
- disable_line?: ModelDisable;
391
- fallback?: AiccFallbackRule;
392
- route_policy_override?: AiccPolicyConfig;
393
- source?: string;
394
- }
395
- export interface AiccSessionLogicalProfile {
396
- name?: string;
397
- overlays?: AiccLogicalTreeOverlay[];
398
- route_policy_override?: AiccPolicyConfig;
399
- }
422
+ item: string;
423
+ weight: number;
424
+ };
425
+ /** `usecases`: the administrator layer of the usecase table. */
400
426
  export interface AiccRouteOverlay {
401
- inherit?: string;
402
427
  logical_tree?: Record<string, AiccLogicalNodeOverlay>;
403
- logical_profile?: AiccSessionLogicalProfile;
404
- logical_profiles?: Record<string, AiccSessionLogicalProfile>;
405
- active_logical_profile?: string;
406
428
  global_exact_model_weights?: Record<string, number>;
407
429
  provider_weights?: Record<string, number>;
430
+ routing_commands?: AiccRoutingCommand[];
408
431
  policy?: AiccPolicyConfig;
409
- revision?: string;
410
- ttl_seconds?: number;
432
+ usecases?: AiccUsecaseRoutes;
433
+ }
434
+ /** What a usecase does when the Provider of its model is unavailable: `none` (default) returns the real error; `same_model` uses the
435
+ * same model on another Provider; `not_pricier` routes again without that Provider, only to a model known not to cost more;
436
+ * `next_model` routes again without that Provider. */
437
+ export type OnUnavailable = 'none' | 'same_model' | 'not_pricier' | 'next_model';
438
+ /** One usecase in a layer or a routing group; absent fields follow the layer below. `model` is `model@provider`;
439
+ * `enabled` only for `llm.fallback` in the administrator layer. */
440
+ export interface AiccUsecaseRoute {
441
+ model?: LockedValue<string>;
442
+ on_unavailable?: LockedValue<OnUnavailable>;
443
+ enabled?: boolean;
444
+ }
445
+ export type AiccUsecaseRoutes = Record<string, AiccUsecaseRoute>;
446
+ /** `coverage`: the usecase (`from`) had no model and the fallback LLM (`to` = `llm.fallback`) served it;
447
+ * `unavailable`: the exact model `from` failed and its policy used `to`. */
448
+ export interface RouteFallback {
449
+ kind: 'coverage' | 'unavailable';
450
+ from: string;
451
+ to: string;
452
+ policy?: OnUnavailable;
453
+ reason?: string;
454
+ }
455
+ export type UsecaseModelState = 'available' | 'missing' | 'not_permitted' | 'unsuitable';
456
+ /** `fallback_llm`: served by the fallback LLM. */
457
+ export type UsecaseCoverage = 'covered' | 'fallback_llm' | 'uncovered';
458
+ /** `layer`: `zone`, `user` or `group:<id>`. */
459
+ export interface UsecaseLayerValue {
460
+ layer: string;
461
+ model?: string;
462
+ model_locked?: boolean;
463
+ model_state?: UsecaseModelState;
464
+ on_unavailable?: OnUnavailable;
465
+ on_unavailable_locked?: boolean;
466
+ enabled?: boolean;
467
+ }
468
+ /** `model`: what this view routes the usecase to now; `*_source`: `default` or the layer that set it; `fallback_to`: what the policy
469
+ * would use if the Provider of `model` were unavailable (`fallback_note` says why it is empty); `detail`: the routing error, for
470
+ * administrators; `enabled`: the row of `llm.fallback`. */
471
+ export interface UsecaseRow {
472
+ usecase: string;
473
+ api_type: string;
474
+ model?: string;
475
+ model_source?: string;
476
+ on_unavailable: OnUnavailable;
477
+ on_unavailable_source: string;
478
+ model_locked?: boolean;
479
+ on_unavailable_locked?: boolean;
480
+ layers?: UsecaseLayerValue[];
481
+ fallback_to?: string;
482
+ fallback_note?: string;
483
+ coverage: UsecaseCoverage;
484
+ coverage_reason?: string;
485
+ detail?: string;
486
+ enabled?: boolean;
487
+ }
488
+ /** `view`: `self` (default), `zone` (administrators), `group:<id>`, `app:<app_id>`. `without_provider` (administrators): the table
489
+ * as if that Provider were deleted or disabled. */
490
+ export interface RoutingUsecasesRequest {
491
+ view?: string;
492
+ without_provider?: string;
493
+ }
494
+ /** `revision`: what `routing.usecase.set` of this view's layer passes. */
495
+ export interface RoutingUsecasesResponse {
496
+ view: string;
497
+ revision: number;
498
+ settings_revision: number;
499
+ fallback_llm_enabled: boolean;
500
+ can_edit: boolean;
501
+ rows: UsecaseRow[];
502
+ }
503
+ export type UsecaseField = 'model' | 'on_unavailable';
504
+ /** `target`: `zone`, `user` or `group:<id>`; `locked` only for `zone`; `enabled` only for `llm.fallback` in `zone`. A stale
505
+ * `revision` fails with `settings_revision_conflict`. */
506
+ export interface RoutingUsecaseSetRequest {
507
+ target: string;
508
+ usecase: string;
509
+ model?: LockedValue<string>;
510
+ on_unavailable?: LockedValue<OnUnavailable>;
511
+ enabled?: boolean;
512
+ clear?: UsecaseField[];
513
+ revision: number;
514
+ }
515
+ export interface RoutingUsecaseSetResponse {
516
+ ok: boolean;
517
+ revision: number;
518
+ }
519
+ /** `app_ids`: the Apps (or Agents) the group is bound to. */
520
+ export interface AiccRoutingGroup {
521
+ group_id: string;
522
+ name: string;
523
+ usecases?: AiccUsecaseRoutes;
524
+ version: number;
525
+ updated_at_ms: number;
526
+ app_ids?: string[];
527
+ }
528
+ export interface RoutingGroupsListResponse {
529
+ groups: AiccRoutingGroup[];
530
+ }
531
+ export interface RoutingGroupCreateRequest {
532
+ name: string;
533
+ usecases?: AiccUsecaseRoutes;
534
+ }
535
+ export interface RoutingGroupUpdateRequest {
536
+ group_id: string;
537
+ version: number;
538
+ name?: string;
539
+ usecases?: AiccUsecaseRoutes;
540
+ }
541
+ export interface RoutingGroupDeleteRequest {
542
+ group_id: string;
543
+ version: number;
544
+ }
545
+ export interface RoutingGroupResponse {
546
+ group: AiccRoutingGroup;
547
+ }
548
+ export interface RoutingOkResponse {
549
+ ok: boolean;
550
+ }
551
+ export interface AiccRoutingBinding {
552
+ app_id: string;
553
+ group_id: string;
554
+ }
555
+ export interface RoutingBindingsListResponse {
556
+ bindings: AiccRoutingBinding[];
557
+ }
558
+ /** One usecase before and after a Provider is added (`provider.validate`). */
559
+ export interface UsecaseCoverageChange {
560
+ usecase: string;
561
+ before?: string;
562
+ before_coverage: UsecaseCoverage;
563
+ after?: string;
564
+ after_coverage: UsecaseCoverage;
411
565
  }
412
566
  export interface RouteResolveRequest {
413
567
  trace_id?: string;
@@ -420,8 +574,8 @@ export interface RouteResolveRequest {
420
574
  policy?: RoutePolicy;
421
575
  estimated_input_tokens?: number;
422
576
  estimated_output_tokens?: number;
423
- session_overlay?: AiccRouteOverlay;
424
- session_id?: string;
577
+ /** A routing group of the caller's own user. */
578
+ route_group?: string;
425
579
  }
426
580
  export interface RouteResolveResponse {
427
581
  selected_exact_model: string;
@@ -436,11 +590,6 @@ export interface RouteResolveResponse {
436
590
  operation: string;
437
591
  enabled_capabilities?: Feature[];
438
592
  disabled_capabilities?: Feature[];
439
- fallback_attempts?: Array<{
440
- exact_model: string;
441
- provider_instance_name: string;
442
- provider_model_id: string;
443
- }>;
444
593
  route_trace?: RouteTrace;
445
594
  inventory_revision: string;
446
595
  }
@@ -450,7 +599,6 @@ export interface InferenceRequest {
450
599
  execution_mode?: AiccExecutionMode;
451
600
  idempotency_key?: string;
452
601
  task_options?: AiTaskOptions;
453
- session_id?: string;
454
602
  }
455
603
  export interface InferenceResponse {
456
604
  task_id: string;
@@ -497,8 +645,7 @@ export interface LlmChatHelperRequest extends ChatFields {
497
645
  policy?: RoutePolicy;
498
646
  idempotency_key?: string;
499
647
  task_options?: AiTaskOptions;
500
- session_overlay?: AiccRouteOverlay;
501
- session_id?: string;
648
+ route_group?: string;
502
649
  }
503
650
  export interface LlmChatInvokeResponse extends InferenceResponse {
504
651
  message?: AiMessage;
@@ -515,8 +662,7 @@ export interface TextToImageHelperRequest extends ImageGenerationFields {
515
662
  policy?: RoutePolicy;
516
663
  idempotency_key?: string;
517
664
  task_options?: AiTaskOptions;
518
- session_overlay?: AiccRouteOverlay;
519
- session_id?: string;
665
+ route_group?: string;
520
666
  }
521
667
  export interface TextToImageInvokeResponse extends InferenceResponse {
522
668
  images?: ResourceRef[];
@@ -932,8 +1078,7 @@ export interface VideoGenerateHelperRequest extends VideoGenerationFields {
932
1078
  policy?: RoutePolicy;
933
1079
  idempotency_key?: string;
934
1080
  task_options?: AiTaskOptions;
935
- session_overlay?: AiccRouteOverlay;
936
- session_id?: string;
1081
+ route_group?: string;
937
1082
  }
938
1083
  export interface VideoEditRequest extends InferenceRequest {
939
1084
  video: ResourceRef;
@@ -1024,8 +1169,9 @@ export interface ComputerUseResponse extends InferenceResponse {
1024
1169
  export type EmptyRequest = Record<string, never>;
1025
1170
  export type ServiceReloadSettingsRequest = EmptyRequest;
1026
1171
  export type RoutingGetRequest = EmptyRequest;
1027
- /** `use` (default): what the caller may use; `manage` (admin): the whole inventory, each model marked `accessible`. */
1028
- export type AiccListView = 'use' | 'manage';
1172
+ /** `use` (default): what the caller may use; `manage` (admin): the whole inventory, each model marked `accessible`;
1173
+ * `provider`: what another AICC needs to add this one as a Provider (`AiccProviderView`). */
1174
+ export type AiccListView = 'use' | 'manage' | 'provider';
1029
1175
  export interface ListModelsRequest {
1030
1176
  view?: AiccListView;
1031
1177
  }
@@ -1039,8 +1185,89 @@ export interface ServiceReloadSettingsResponse {
1039
1185
  ok: boolean;
1040
1186
  settings_revision: number;
1041
1187
  }
1042
- export type QuotaRuleSource = 'admin' | 'user';
1043
- export type QuotaObject = {
1188
+ export type PolicySource = 'admin' | 'user';
1189
+ /** `type:admin|user|limited`, `group:<id>`, `user:<id>` (user side: the more specific overrides), `app:<id>`,
1190
+ * `user_app:<user>/<app>` (App side: only narrows), `token:<id>` (an API Token: the most specific layer of a group
1191
+ * token, a narrowing layer of a sub-account token). */
1192
+ export type PolicySubject = string;
1193
+ export type LimitPeriod = '5h' | '24h' | '7d';
1194
+ export type LimitUnit = 'credit' | 'token';
1195
+ /** `amount`: a decimal string (Credit, up to six decimals) or a whole number of tokens; `'0'` forbids use. */
1196
+ export interface PolicyLimit {
1197
+ period: LimitPeriod;
1198
+ unit: LimitUnit;
1199
+ amount: string;
1200
+ }
1201
+ export type ProviderVisibility = 'all_models' | 'selected_models' | 'hidden';
1202
+ export interface ProviderPolicy {
1203
+ visible?: ProviderVisibility;
1204
+ price_coefficient?: number;
1205
+ limits?: PolicyLimit[];
1206
+ }
1207
+ export interface ModelPolicy {
1208
+ visible?: boolean;
1209
+ price_coefficient?: number;
1210
+ limits?: PolicyLimit[];
1211
+ }
1212
+ /** Every field is optional: an absent field has no opinion. */
1213
+ export interface PolicyBody {
1214
+ all_providers?: boolean;
1215
+ price_coefficient?: number;
1216
+ limits?: PolicyLimit[];
1217
+ providers?: Record<string, ProviderPolicy>;
1218
+ models?: Record<string, ModelPolicy>;
1219
+ /** The account may issue sub-account API Tokens and may be used by another Zone's AICC (user side layers only). */
1220
+ provider_access?: boolean;
1221
+ }
1222
+ export interface AiccPolicy {
1223
+ policy_id: string;
1224
+ source: PolicySource;
1225
+ subject: PolicySubject;
1226
+ enabled: boolean;
1227
+ body: PolicyBody;
1228
+ version: number;
1229
+ created_by: string;
1230
+ created_at_ms: number;
1231
+ updated_by: string;
1232
+ updated_at_ms: number;
1233
+ }
1234
+ export interface AiccPolicyView {
1235
+ policy: AiccPolicy;
1236
+ editable: boolean;
1237
+ unavailable_resources?: string[];
1238
+ }
1239
+ export interface PolicyDraft {
1240
+ source?: PolicySource;
1241
+ subject: PolicySubject;
1242
+ enabled?: boolean;
1243
+ body?: PolicyBody;
1244
+ }
1245
+ export interface PolicyListRequest {
1246
+ scope?: 'mine' | 'manage';
1247
+ }
1248
+ export interface PolicyListResponse {
1249
+ policies: AiccPolicyView[];
1250
+ }
1251
+ export interface PolicyAuditRecord {
1252
+ audit_id: string;
1253
+ target_type: string;
1254
+ target_id: string;
1255
+ action: string;
1256
+ operator: string;
1257
+ before?: JsonValue;
1258
+ after?: JsonValue;
1259
+ created_at_ms: number;
1260
+ }
1261
+ export interface PolicyGetResponse {
1262
+ policy: AiccPolicyView;
1263
+ audit?: PolicyAuditRecord[];
1264
+ }
1265
+ export interface PolicyUpsertRequest {
1266
+ draft: PolicyDraft;
1267
+ expected_version?: number;
1268
+ }
1269
+ /** `user`: the charged user (a group API Token is its own user `token:<id>`); `token`: a sub-account API Token's own limits. */
1270
+ export type LimitCounter = {
1044
1271
  type: 'user';
1045
1272
  user_id: string;
1046
1273
  } | {
@@ -1050,8 +1277,11 @@ export type QuotaObject = {
1050
1277
  type: 'user_app';
1051
1278
  user_id: string;
1052
1279
  app_id: string;
1280
+ } | {
1281
+ type: 'token';
1282
+ token_id: string;
1053
1283
  };
1054
- export type QuotaResource = {
1284
+ export type LimitResource = {
1055
1285
  type: 'all';
1056
1286
  } | {
1057
1287
  type: 'provider';
@@ -1062,218 +1292,291 @@ export type QuotaResource = {
1062
1292
  } | {
1063
1293
  type: 'hidden';
1064
1294
  };
1065
- export type QuotaPeriod = '4h' | '24h' | '72h' | 'week';
1066
- export type QuotaKind = 'periodic' | 'total';
1067
- export type QuotaStatus = 'normal' | 'near_limit' | 'exhausted' | 'forbidden' | 'disabled' | 'resource_unavailable';
1068
- export interface QuotaPendingPeriod {
1069
- period: QuotaPeriod;
1070
- effective_at_ms: number;
1071
- conflict?: boolean;
1072
- }
1073
- export interface QuotaRule {
1074
- rule_id: string;
1075
- source: QuotaRuleSource;
1076
- object: QuotaObject;
1077
- resource: QuotaResource;
1078
- kind: QuotaKind;
1079
- period?: QuotaPeriod;
1080
- limit_tokens?: number;
1081
- account_id?: string;
1082
- enabled: boolean;
1083
- deleted?: boolean;
1084
- pending_period?: QuotaPendingPeriod;
1085
- version: number;
1086
- created_by: string;
1087
- created_at_ms: number;
1088
- updated_by: string;
1089
- updated_at_ms: number;
1090
- }
1091
- export interface QuotaUsageState {
1092
- status: QuotaStatus;
1295
+ export type LimitStatus = 'normal' | 'near_limit' | 'exhausted' | 'forbidden';
1296
+ export interface EffectiveLimit {
1297
+ policy_id: string;
1298
+ source: PolicySource;
1299
+ subject: PolicySubject;
1300
+ counter: LimitCounter;
1301
+ resource: LimitResource;
1302
+ period: LimitPeriod;
1303
+ unit: LimitUnit;
1304
+ amount: string;
1305
+ used: string;
1093
1306
  window_start_ms?: number;
1094
- window_end_ms?: number;
1095
- reset_at_ms: number | null;
1096
- limit_tokens?: number;
1097
- granted_tokens?: number;
1098
- account_start_ms?: number;
1099
- settled_tokens: number;
1100
- reserved_tokens: number;
1101
- pending_tokens: number;
1102
- available_tokens: number;
1103
- debt_tokens: number;
1104
- updated_at_ms: number;
1307
+ /** End of the current window; absent when no window is open (it starts at the next use). */
1308
+ reset_at_ms?: number;
1309
+ status: LimitStatus;
1310
+ }
1311
+ export type CreditPriceSource = 'exact' | 'model' | 'provider_cost';
1312
+ export type CreditPriceState = 'free' | 'priced' | 'unpriced';
1313
+ /** A model's price for one caller. `pricing` token rates are per million tokens. */
1314
+ export interface ModelCreditPrice {
1315
+ state: CreditPriceState;
1316
+ source?: CreditPriceSource;
1317
+ entry_key?: string;
1318
+ pricing?: JsonValue;
1319
+ provider_cost_currency?: string;
1320
+ credit_rate?: number;
1321
+ provider_coefficient: number;
1322
+ model_coefficient: number;
1323
+ }
1324
+ export interface EffectiveModel {
1325
+ exact_model: string;
1326
+ provider_instance_name: string;
1327
+ visible_from: string[];
1328
+ coefficient_from?: string[];
1329
+ price: ModelCreditPrice;
1330
+ usable: boolean;
1105
1331
  }
1106
- export interface QuotaRuleView {
1107
- rule: QuotaRule;
1108
- state: QuotaUsageState;
1109
- editable: boolean;
1332
+ export interface PolicyEffectiveRequest {
1333
+ user_id?: string;
1334
+ app_id?: string;
1335
+ draft?: PolicyDraft;
1110
1336
  }
1111
- export interface QuotaQueryRequest {
1337
+ export interface PolicyEffectiveResponse {
1338
+ user_id: string;
1339
+ app_id?: string;
1340
+ balance: string;
1341
+ models: EffectiveModel[];
1342
+ limits: EffectiveLimit[];
1343
+ unpriced_models?: string[];
1344
+ added?: string[];
1345
+ removed?: string[];
1346
+ affected_users?: string[];
1347
+ caller_loses?: string[];
1348
+ /** The user may issue sub-account API Tokens and may be used by another Zone's AICC; `provider_access_from` is
1349
+ * the policy (subject) it comes from. */
1350
+ provider_access: boolean;
1351
+ provider_access_from?: string;
1352
+ }
1353
+ export interface PolicyStatusRequest {
1112
1354
  app_id?: string;
1113
1355
  }
1114
- export interface QuotaQueryResponse {
1356
+ export interface PolicyStatusResponse {
1115
1357
  user_id: string;
1116
- rules: QuotaRuleView[];
1358
+ balance: string;
1359
+ limits: EffectiveLimit[];
1117
1360
  near_limit_count: number;
1118
1361
  exhausted_count: number;
1119
1362
  }
1120
- export interface QuotaRuleListRequest {
1121
- scope?: 'mine' | 'manage';
1122
- include_deleted?: boolean;
1363
+ /** `entry_key`: `model:<model_driver_id>:<origin_model_id>` or `exact:<provider_model_id>[:variant]@<instance>`;
1364
+ * `pricing` has the shape of a Provider price (`currency` CREDIT, token rates per million tokens). */
1365
+ export interface PriceEntry {
1366
+ entry_key: string;
1367
+ pricing: JsonValue;
1368
+ note?: string;
1369
+ updated_by: string;
1370
+ updated_at_ms: number;
1123
1371
  }
1124
- export interface QuotaRuleListResponse {
1125
- rules: QuotaRuleView[];
1372
+ export interface PriceEntryInput {
1373
+ entry_key: string;
1374
+ pricing: JsonValue;
1375
+ note?: string;
1126
1376
  }
1127
- export interface QuotaAuditRecord {
1128
- audit_id: string;
1129
- target_type: string;
1130
- target_id: string;
1131
- action: string;
1132
- operator: string;
1133
- before?: JsonValue;
1134
- after?: JsonValue;
1135
- created_at_ms: number;
1377
+ export interface PriceGetResponse {
1378
+ revision: number;
1379
+ entries: PriceEntry[];
1380
+ credit_rates?: Record<string, number>;
1381
+ unpriced_models?: string[];
1382
+ }
1383
+ export interface PriceUpdateRequest {
1384
+ expected_revision: number;
1385
+ upserts?: PriceEntryInput[];
1386
+ deletes?: string[];
1387
+ credit_rates?: Record<string, number>;
1388
+ }
1389
+ /** `user_id`: an account of the Zone, or `token:<id>` for a group API Token (`label`: its name). */
1390
+ export interface CreditAccount {
1391
+ user_id: string;
1392
+ balance: string;
1393
+ updated_at_ms: number;
1394
+ label?: string;
1136
1395
  }
1137
- export interface QuotaGrantRecord {
1138
- grant_id: string;
1139
- account_id: string;
1140
- kind: 'initial' | 'recharge';
1141
- amount_tokens: number;
1396
+ export interface CreditEntry {
1397
+ entry_id: string;
1398
+ user_id: string;
1399
+ kind: 'recharge' | 'adjust';
1400
+ amount: string;
1401
+ balance_after: string;
1402
+ recharge_id?: string;
1403
+ external_ref?: JsonValue;
1142
1404
  operator: string;
1143
1405
  note?: string;
1144
1406
  created_at_ms: number;
1145
1407
  }
1146
- export interface QuotaAccountView {
1147
- account_id: string;
1148
- object: QuotaObject;
1149
- resource: QuotaResource;
1150
- granted_tokens: number;
1151
- settled_tokens: number;
1152
- reserved_tokens: number;
1153
- pending_tokens: number;
1154
- available_tokens: number;
1155
- debt_tokens: number;
1156
- start_at_ms: number;
1157
- version: number;
1158
- updated_at_ms: number;
1159
- enforced: boolean;
1160
- }
1161
- export interface QuotaRuleDetail {
1162
- rule: QuotaRuleView;
1163
- constraints: QuotaRuleView[];
1164
- blocking_rule_ids: string[];
1165
- account?: QuotaAccountView;
1166
- grants?: QuotaGrantRecord[];
1167
- audit?: QuotaAuditRecord[];
1168
- }
1169
- export interface QuotaRuleDraft {
1170
- source?: QuotaRuleSource;
1171
- object: QuotaObject;
1172
- resource: QuotaResource;
1173
- kind: QuotaKind;
1174
- period?: QuotaPeriod;
1175
- limit_tokens?: number;
1176
- initial_tokens?: number;
1177
- }
1178
- export interface QuotaRulePreviewResponse {
1179
- state: QuotaUsageState;
1180
- existing_account?: QuotaAccountView;
1181
- conflict_rule_id?: string;
1182
- other_constraints: QuotaRuleView[];
1183
- }
1184
- export interface QuotaRuleUpdateRequest {
1185
- rule_id: string;
1186
- expected_version: number;
1187
- limit_tokens?: number;
1188
- period?: QuotaPeriod;
1189
- enabled?: boolean;
1190
- cancel_pending_period?: boolean;
1408
+ export type CreditChargeStatus = 'charged' | 'free' | 'unpriced' | 'unknown_usage';
1409
+ export interface CreditCharge {
1410
+ attempt_id: string;
1411
+ task_id: string;
1412
+ user_id: string;
1413
+ app_id?: string;
1414
+ operator_id?: string;
1415
+ provider_instance_name: string;
1416
+ exact_model: string;
1417
+ admitted_at_ms: number;
1418
+ tokens: number;
1419
+ amount: string;
1420
+ status: CreditChargeStatus;
1421
+ settled_at_ms: number;
1422
+ }
1423
+ export type CreditLedgerItem = ({
1424
+ type: 'entry';
1425
+ } & CreditEntry) | ({
1426
+ type: 'charge';
1427
+ } & CreditCharge);
1428
+ export interface CreditLedgerListRequest {
1429
+ user_id?: string;
1430
+ start_time_ms?: number;
1431
+ end_time_ms?: number;
1432
+ cursor?: string;
1433
+ limit?: number;
1191
1434
  }
1192
- export interface QuotaRechargeRequest {
1193
- account_id: string;
1435
+ export interface CreditLedgerListResponse {
1436
+ user_id: string;
1437
+ balance: string;
1438
+ items: CreditLedgerItem[];
1439
+ next_cursor?: string;
1440
+ }
1441
+ /** `recharge_id` is the idempotency key (a payment order id); `external_ref` is kept, never interpreted. */
1442
+ export interface CreditRechargeRequest {
1443
+ user_id: string;
1194
1444
  recharge_id: string;
1195
- amount_tokens: number;
1445
+ amount: string;
1196
1446
  note?: string;
1447
+ external_ref?: JsonValue;
1197
1448
  }
1198
- export interface QuotaRechargeResponse {
1199
- recharge: QuotaGrantRecord;
1200
- account: QuotaAccountView;
1449
+ export interface CreditAdjustRequest {
1450
+ user_id: string;
1451
+ adjust_id: string;
1452
+ amount: string;
1453
+ note: string;
1454
+ external_ref?: JsonValue;
1455
+ }
1456
+ export interface CreditEntryResponse {
1457
+ entry: CreditEntry;
1458
+ account: CreditAccount;
1201
1459
  replayed: boolean;
1202
1460
  }
1203
- export interface QuotaBlockingRule {
1204
- rule_id: string;
1205
- source: QuotaRuleSource;
1206
- object: QuotaObject;
1207
- resource: QuotaResource;
1208
- kind: QuotaKind;
1209
- period?: QuotaPeriod;
1210
- state: QuotaUsageState;
1211
- recoverable: boolean;
1212
- }
1213
- /** `details` of `quota_exhausted` / `quota_budget_exceeded`. */
1461
+ export interface QuotaBlockingLimit {
1462
+ policy_id: string;
1463
+ source: PolicySource;
1464
+ subject: PolicySubject;
1465
+ resource: LimitResource;
1466
+ period: LimitPeriod;
1467
+ unit: LimitUnit;
1468
+ used: string;
1469
+ amount: string;
1470
+ reset_at_ms?: number;
1471
+ }
1472
+ /** `details` of `quota_exhausted`. */
1214
1473
  export interface QuotaDenialDetails {
1215
- required_tokens: number;
1216
- max_allowed_tokens: number;
1217
1474
  provider_instance_name: string;
1218
1475
  exact_model: string;
1219
- blocking: QuotaBlockingRule[];
1476
+ blocking: QuotaBlockingLimit[];
1220
1477
  reset_at_ms: number | null;
1221
1478
  }
1222
- export type VisibilityEntry = {
1223
- type: 'all_providers';
1224
- } | {
1225
- type: 'provider_all_models';
1479
+ /** `details` of `credit_insufficient`. */
1480
+ export interface CreditInsufficientDetails {
1481
+ balance: string;
1226
1482
  provider_instance_name: string;
1227
- } | {
1228
- type: 'provider_models';
1229
- provider_instance_name: string;
1230
- exact_models: string[];
1231
- };
1232
- export interface VisibilitySubjectPolicy {
1233
- subject: string;
1234
- entries: VisibilityEntry[];
1235
- updated_by: string;
1236
- updated_at_ms: number;
1483
+ exact_model: string;
1237
1484
  }
1238
- export interface VisibilityGetResponse {
1239
- revision: number;
1240
- subjects: VisibilitySubjectPolicy[];
1241
- providers: {
1242
- provider_instance_name: string;
1243
- enabled: boolean;
1244
- exact_models: string[];
1245
- }[];
1246
- unexposed_models: string[];
1247
- }
1248
- export interface VisibilityUpdateRequest {
1249
- expected_revision: number;
1250
- subject: string;
1251
- entries: VisibilityEntry[];
1485
+ /** `details.reason` of `resource_not_permitted` when a sub-account API Token or a cross-Zone login is used while the
1486
+ * account's `provider_access` is off. */
1487
+ export declare const PROVIDER_ACCESS_DISABLED_REASON = "provider_access_disabled";
1488
+ export interface ProviderAccessDeniedDetails {
1489
+ reason: typeof PROVIDER_ACCESS_DISABLED_REASON;
1490
+ }
1491
+ /** Version of the AICC contract another AICC relies on (inference methods, Provider view, `artifact/open`, protocol
1492
+ * servers); 1 is the 0.7.0 interface. Sent by a calling AICC in the reserved kRPC parameter `aicc_contract_version`. */
1493
+ export declare const AICC_CONTRACT_VERSION = 1;
1494
+ export declare const AICC_CONTRACT_VERSION_PARAM = "aicc_contract_version";
1495
+ /** API keys are `bkai_<16 lowercase hex token id>_<64 hex secret>`. */
1496
+ export declare const AICC_API_TOKEN_PREFIX = "bkai_";
1497
+ export declare function isAiccApiTokenId(value: string): boolean;
1498
+ /** `group`: issued by an administrator for a user group, its own Credit account `token:<id>`; `sub_account`: issued
1499
+ * under a user's name, charges that user and only narrows the user's policy. */
1500
+ export type ApiTokenKind = 'group' | 'sub_account';
1501
+ /** `suspended`: the group of a group token no longer exists, or the account of a sub-account token is not active or
1502
+ * has `provider_access` off. */
1503
+ export type ApiTokenState = 'active' | 'expired' | 'revoked' | 'suspended';
1504
+ /** An API Token as listed; never carries the secret. `balance`: Credit of a group token. */
1505
+ export interface ApiTokenView {
1506
+ token_id: string;
1507
+ kind: ApiTokenKind;
1508
+ group_id?: string;
1509
+ owner_user_id?: string;
1510
+ name: string;
1511
+ created_by: string;
1512
+ created_at_ms: number;
1513
+ expires_at_ms?: number;
1514
+ revoked_at_ms?: number;
1515
+ last_used_at_ms?: number;
1516
+ state: ApiTokenState;
1517
+ balance?: string;
1518
+ }
1519
+ /** `group_id`: a group token (administrators only); otherwise a sub-account token of `user_id` (default: the caller). */
1520
+ export interface ApiTokenCreateRequest {
1521
+ name: string;
1522
+ expires_at_ms?: number;
1523
+ group_id?: string;
1524
+ user_id?: string;
1525
+ }
1526
+ /** `api_key`: the full `bkai_…` key, returned this once; AICC keeps only its hash. */
1527
+ export interface ApiTokenCreateResponse {
1528
+ token: ApiTokenView;
1529
+ api_key: string;
1252
1530
  }
1253
- export interface VisibilityPreviewRequest {
1531
+ export interface ApiTokenListRequest {
1532
+ group_id?: string;
1254
1533
  user_id?: string;
1255
- draft?: {
1256
- subject: string;
1257
- entries: VisibilityEntry[];
1258
- };
1534
+ include_revoked?: boolean;
1259
1535
  }
1260
- export interface VisibilityPreviewResponse {
1261
- user_id: string;
1262
- grants: {
1263
- provider_instance_name: string;
1264
- exact_model?: string;
1265
- sources: string[];
1266
- }[];
1267
- added?: string[];
1268
- removed?: string[];
1269
- affected_users?: string[];
1270
- caller_loses?: string[];
1536
+ export interface ApiTokenListResponse {
1537
+ tokens: ApiTokenView[];
1538
+ }
1539
+ export interface ApiTokenRevokeRequest {
1540
+ token_id: string;
1541
+ }
1542
+ export interface ApiTokenRevokeResponse {
1543
+ token: ApiTokenView;
1544
+ }
1545
+ /** One execution path of a model in the Provider view; an external caller may use `immediate` only. */
1546
+ export interface AiccProviderViewOperation {
1547
+ api_type: ApiType;
1548
+ execution_modes: ProtocolExecutionMode[];
1549
+ }
1550
+ export type AiccProviderViewAvailability = 'available' | 'unavailable';
1551
+ /** One exact model an external caller may use, with the Model Driver identity the downstream matches. */
1552
+ export interface AiccProviderViewModel {
1553
+ exact_model: string;
1554
+ provider_instance_name: string;
1555
+ provider_model_id: string;
1556
+ variant?: string;
1557
+ model_driver_id: string;
1558
+ origin_model_id: string;
1559
+ api_types: ApiType[];
1560
+ operations: AiccProviderViewOperation[];
1561
+ capabilities?: Record<string, JsonValue>;
1562
+ canonical_fields?: Record<string, JsonValue>;
1563
+ video?: JsonValue;
1564
+ credit_price: ModelCreditPrice;
1565
+ availability: AiccProviderViewAvailability;
1566
+ }
1567
+ /** `models.list` with `view: 'provider'`. `revision` changes whenever the listed models or their prices change. */
1568
+ export interface AiccProviderView {
1569
+ contract_version: number;
1570
+ revision: string;
1571
+ models: AiccProviderViewModel[];
1271
1572
  }
1272
1573
  export interface ProviderCatalogEntry {
1273
1574
  provider_profile_id: string;
1274
1575
  display_name: string;
1275
1576
  base_url: string;
1276
1577
  protocol_adapter_id: string;
1578
+ extra_protocol_adapters?: string[];
1579
+ state_namespace?: string;
1277
1580
  provider_rules_id?: string;
1278
1581
  rules_catalog?: JsonValue;
1279
1582
  model_driver_overrides?: Record<string, string>;
@@ -1352,7 +1655,8 @@ export interface ProviderValidateResponse {
1352
1655
  models_recognized: string[];
1353
1656
  unmatched_models: JsonValue[];
1354
1657
  unavailable_presets: JsonValue[];
1355
- routing_candidates: Record<string, string[]>;
1658
+ /** Every usecase of the Zone before and after this Provider is added. */
1659
+ usecase_coverage?: UsecaseCoverageChange[];
1356
1660
  warnings: string[];
1357
1661
  base_url_reachable: boolean;
1358
1662
  auth_valid: boolean;
@@ -1428,6 +1732,7 @@ export interface ProviderInstanceView {
1428
1732
  protocol_adapter_id: string;
1429
1733
  base_url: string;
1430
1734
  enabled: boolean;
1735
+ marked_faulty?: boolean;
1431
1736
  auth: ProviderInstanceAuthView;
1432
1737
  inventory: ProviderInstanceInventoryView;
1433
1738
  health: ProviderInstanceHealthView;
@@ -1454,6 +1759,8 @@ export interface ProviderUpdateRequest {
1454
1759
  protocol_adapter_id?: string;
1455
1760
  discovery?: JsonValue;
1456
1761
  instance_rules?: JsonValue;
1762
+ /** Routing is unchanged, calls are not sent: usecases with a "when unavailable" policy switch at once, others fail. */
1763
+ marked_faulty?: boolean;
1457
1764
  }
1458
1765
  export interface ProviderUpdateResponse {
1459
1766
  ok: boolean;
@@ -1485,8 +1792,13 @@ export interface UsageQueryFilters {
1485
1792
  task_ids?: string[];
1486
1793
  idempotency_keys?: string[];
1487
1794
  methods?: string[];
1795
+ /** `type:*` / `group:*` of the charged user at the time of the call (administrators only). */
1796
+ user_groups?: string[];
1797
+ /** Only usage served by a usecase's "when unavailable" policy. */
1798
+ fallback_only?: boolean;
1488
1799
  }
1489
- export type UsageQueryGroup = 'provider_model' | 'provider_instance_name' | 'request_model' | 'method' | 'capability' | 'caller_app_id' | 'user_id' | 'tenant_id';
1800
+ /** `user_group` counts an event once per `type:*` / `group:*` subject (administrators only). */
1801
+ export type UsageQueryGroup = 'provider_model' | 'provider_instance_name' | 'request_model' | 'method' | 'capability' | 'caller_app_id' | 'user_id' | 'tenant_id' | 'user_group';
1490
1802
  export interface QueryUsageRequest {
1491
1803
  time_range: UsageQueryTimeRange;
1492
1804
  filters?: UsageQueryFilters;
@@ -1506,6 +1818,9 @@ export interface UsageAggregate {
1506
1818
  consumed_request_units: number;
1507
1819
  finance_totals: Money[];
1508
1820
  finance_complete: boolean;
1821
+ /** Credit charged (decimal string); `credit_complete` is false when a charge is `unpriced` or `unknown_usage`. */
1822
+ credit_total: string;
1823
+ credit_complete: boolean;
1509
1824
  }
1510
1825
  export interface AiccUsageEvent {
1511
1826
  event_id: string;
@@ -1528,7 +1843,12 @@ export interface AiccUsageEvent {
1528
1843
  finance_snapshot_json?: JsonValue;
1529
1844
  operator_id?: string;
1530
1845
  attribution?: JsonValue;
1846
+ credit?: string;
1847
+ credit_status?: CreditChargeStatus;
1848
+ subjects?: string[];
1531
1849
  created_at_ms: number;
1850
+ /** The exact model the usecase's "when unavailable" policy replaced. */
1851
+ fallback_from?: string;
1532
1852
  }
1533
1853
  export interface UsageGroupedRow {
1534
1854
  group: Record<string, string>;
@@ -1601,7 +1921,8 @@ export interface RoutingGetResponse {
1601
1921
  }
1602
1922
  export interface RoutingUpdateRequest {
1603
1923
  settings_revision: number;
1604
- provider_weights: Record<string, number>;
1924
+ provider_weights?: Record<string, number>;
1925
+ routing_commands?: AiccRoutingCommand[];
1605
1926
  }
1606
1927
  export interface RoutingUpdateResponse {
1607
1928
  ok: boolean;
@@ -1683,7 +2004,6 @@ export declare class AiccClient {
1683
2004
  computerUse(r: ComputerUseRequest): Promise<ComputerUseResponse>;
1684
2005
  cancel(taskId: string): Promise<CancelResponse>;
1685
2006
  reloadSettings(): Promise<ServiceReloadSettingsResponse>;
1686
- queryQuota(r?: QuotaQueryRequest): Promise<QuotaQueryResponse>;
1687
2007
  queryUsage(r: QueryUsageRequest): Promise<QueryUsageResponse>;
1688
2008
  queryTrace(r?: QueryRouteTraceRequest): Promise<QueryRouteTraceResponse>;
1689
2009
  previewRouting(r?: RoutingPreviewRequest): Promise<RoutingPreviewResponse>;
@@ -1700,27 +2020,42 @@ export declare class AiccClient {
1700
2020
  deleteProvider(r: ProviderDeleteRequest): Promise<ProviderDeleteResponse>;
1701
2021
  refreshProviderModels(r: ProviderRefreshModelsRequest): Promise<ProviderRefreshModelsResponse>;
1702
2022
  listModels(r?: ListModelsRequest): Promise<JsonValue>;
1703
- listQuotaRules(r?: QuotaRuleListRequest): Promise<QuotaRuleListResponse>;
1704
- getQuotaRule(ruleId: string): Promise<QuotaRuleDetail>;
1705
- previewQuotaRule(draft: QuotaRuleDraft): Promise<QuotaRulePreviewResponse>;
1706
- createQuotaRule(draft: QuotaRuleDraft): Promise<QuotaRuleView>;
1707
- updateQuotaRule(r: QuotaRuleUpdateRequest): Promise<QuotaRuleView>;
1708
- deleteQuotaRule(ruleId: string, expectedVersion: number): Promise<{
2023
+ listPolicies(r?: PolicyListRequest): Promise<PolicyListResponse>;
2024
+ getPolicy(policyId: string): Promise<PolicyGetResponse>;
2025
+ upsertPolicy(r: PolicyUpsertRequest): Promise<AiccPolicyView>;
2026
+ deletePolicy(policyId: string, expectedVersion: number): Promise<{
1709
2027
  ok: boolean;
1710
- rule_id: string;
2028
+ policy_id: string;
1711
2029
  }>;
1712
- getQuotaAccount(accountId: string): Promise<{
1713
- account: QuotaAccountView;
1714
- grants: QuotaGrantRecord[];
2030
+ effectivePolicy(r?: PolicyEffectiveRequest): Promise<PolicyEffectiveResponse>;
2031
+ policyStatus(r?: PolicyStatusRequest): Promise<PolicyStatusResponse>;
2032
+ getPrices(): Promise<PriceGetResponse>;
2033
+ updatePrices(r: PriceUpdateRequest): Promise<PriceGetResponse>;
2034
+ getCreditAccount(userId?: string): Promise<CreditAccount>;
2035
+ listCreditAccounts(group?: string): Promise<{
2036
+ accounts: CreditAccount[];
1715
2037
  }>;
1716
- rechargeQuotaAccount(r: QuotaRechargeRequest): Promise<QuotaRechargeResponse>;
1717
- getQuotaRecharge(rechargeId: string): Promise<{
1718
- recharge?: QuotaGrantRecord | undefined;
1719
- account?: QuotaAccountView | undefined;
2038
+ listCreditLedger(r?: CreditLedgerListRequest): Promise<CreditLedgerListResponse>;
2039
+ rechargeCredit(r: CreditRechargeRequest): Promise<CreditEntryResponse>;
2040
+ getCreditRecharge(rechargeId: string): Promise<{
2041
+ entry?: CreditEntry | undefined;
2042
+ account?: CreditAccount | undefined;
1720
2043
  }>;
1721
- getVisibility(): Promise<VisibilityGetResponse>;
1722
- updateVisibility(r: VisibilityUpdateRequest): Promise<VisibilityGetResponse>;
1723
- previewVisibility(r?: VisibilityPreviewRequest): Promise<VisibilityPreviewResponse>;
2044
+ adjustCredit(r: CreditAdjustRequest): Promise<CreditEntryResponse>;
2045
+ apiTokenCreate(r: ApiTokenCreateRequest): Promise<ApiTokenCreateResponse>;
2046
+ apiTokenList(r?: ApiTokenListRequest): Promise<ApiTokenListResponse>;
2047
+ apiTokenRevoke(tokenId: string): Promise<ApiTokenRevokeResponse>;
2048
+ /** What another AICC lists as this AICC's models (`models.list` with `view: 'provider'`). */
2049
+ providerView(): Promise<AiccProviderView>;
2050
+ getRoutingUsecases(r?: RoutingUsecasesRequest): Promise<RoutingUsecasesResponse>;
2051
+ setRoutingUsecase(r: RoutingUsecaseSetRequest): Promise<RoutingUsecaseSetResponse>;
2052
+ listRoutingGroups(): Promise<RoutingGroupsListResponse>;
2053
+ createRoutingGroup(r: RoutingGroupCreateRequest): Promise<RoutingGroupResponse>;
2054
+ updateRoutingGroup(r: RoutingGroupUpdateRequest): Promise<RoutingGroupResponse>;
2055
+ deleteRoutingGroup(groupId: string, version: number): Promise<RoutingOkResponse>;
2056
+ listRoutingBindings(): Promise<RoutingBindingsListResponse>;
2057
+ setRoutingBinding(appId: string, groupId: string): Promise<RoutingOkResponse>;
2058
+ removeRoutingBinding(appId: string): Promise<RoutingOkResponse>;
1724
2059
  getDriverMetadataUpdate(): Promise<DriverMetadataUpdateView>;
1725
2060
  setDriverMetadataUpdate(r: DriverMetadataUpdateSetReq): Promise<DriverMetadataUpdateSetResponse>;
1726
2061
  }