@peer-agent/protocol 0.0.1-beta.46 → 0.0.1-beta.48

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/dist/index.d.ts CHANGED
@@ -305,6 +305,71 @@ export type LlmWireProtocol = 'openai-chat' | 'openai-responses' | 'anthropic-me
305
305
  export type LlmChannelId = string;
306
306
  export type LlmReasoningParamStyle = 'openai-effort' | 'anthropic-enabled-budget' | 'anthropic-adaptive-effort' | 'anthropic-output-effort' | 'qwen-enable' | 'none';
307
307
  export type LlmReasoningEffortMap = Readonly<Record<string, string | number>>;
308
+ /**
309
+ * 服务连接用户可见主状态(服务商中心 P0)。
310
+ * 配置是否完整、凭据是否有效、端点是否可达、模型是否可用是内部事实;
311
+ * UI 将这些事实归纳为少量连接状态,而不是把“已保存”当成“可用”。
312
+ */
313
+ export type LlmConnectionState = 'draft' | 'pending_verification' | 'checking' | 'available' | 'partial' | 'needs_attention' | 'unavailable' | 'disabled';
314
+ /** 服务模板支持级别:原生适配 / 验证兼容 / 自定义兼容 / 实验性。 */
315
+ export type LlmServiceSupportTier = 'native' | 'verified' | 'custom' | 'experimental';
316
+ /**
317
+ * 添加服务目录的接入分类。
318
+ * 先按接入方式分组,再展示品牌卡片。
319
+ */
320
+ export type LlmServiceAccessCategory = 'recommended' | 'oauth' | 'official_api' | 'cloud' | 'third_party' | 'local' | 'custom_compatible';
321
+ /** 阶段化诊断的检查层次。 */
322
+ export type LlmDiagnosticStageId = 'config' | 'connectivity' | 'auth' | 'catalog' | 'min_inference' | 'agent_capability';
323
+ export type LlmDiagnosticStageStatus = 'passed' | 'failed' | 'skipped' | 'pending';
324
+ /**
325
+ * 面向用户的错误分类(诊断 / 聊天修复共用)。
326
+ * 技术错误码可进入 sanitizedDetail,不应直接作为主文案。
327
+ */
328
+ export type LlmDiagnosticErrorCategory = 'credential_missing' | 'credential_invalid' | 'auth_expired' | 'endpoint_unreachable' | 'rate_limited' | 'quota_exhausted' | 'permission_denied' | 'model_not_found' | 'protocol_mismatch' | 'capability_mismatch' | 'local_runtime_stopped' | 'timeout' | 'unknown';
329
+ export interface LlmDiagnosticStage {
330
+ readonly id: LlmDiagnosticStageId;
331
+ readonly status: LlmDiagnosticStageStatus;
332
+ readonly title: string;
333
+ readonly detail?: string;
334
+ readonly durationMs?: number;
335
+ }
336
+ export interface LlmDiagnosticSnapshot {
337
+ readonly connectionId?: string;
338
+ readonly configVersion?: number;
339
+ readonly startedAt: string;
340
+ readonly finishedAt?: string;
341
+ readonly trigger?: 'user' | 'background' | 'request' | 'add_flow';
342
+ readonly stages: readonly LlmDiagnosticStage[];
343
+ readonly errorCategory?: LlmDiagnosticErrorCategory;
344
+ readonly sanitizedDetail?: string;
345
+ readonly suggestedActions?: readonly string[];
346
+ }
347
+ /**
348
+ * 服务模板:用户发现与默认配置的产品对象。
349
+ * 一个 channel 可映射多个模板(例如 OpenAI API Key 与 ChatGPT 订阅)。
350
+ */
351
+ export interface LlmServiceTemplateDescriptor {
352
+ readonly id: string;
353
+ readonly brand: string;
354
+ readonly title: string;
355
+ readonly description: string;
356
+ readonly accessCategory: LlmServiceAccessCategory;
357
+ readonly supportTier: LlmServiceSupportTier;
358
+ readonly channelId: LlmChannelId;
359
+ readonly authMethod: LlmAuthMethod;
360
+ readonly legacyProvider: LlmProviderType;
361
+ readonly defaultWire: LlmWireProtocol;
362
+ readonly defaults: {
363
+ readonly baseUrl: string;
364
+ readonly model: string;
365
+ readonly hideBaseUrlByDefault?: boolean;
366
+ };
367
+ readonly searchAliases?: readonly string[];
368
+ readonly regions?: readonly string[];
369
+ readonly tags?: readonly string[];
370
+ readonly docsUrl?: string;
371
+ readonly knownLimitations?: readonly string[];
372
+ }
308
373
  export interface LlmChannelDescriptor {
309
374
  readonly id: LlmChannelId;
310
375
  readonly label: string;
@@ -331,6 +396,8 @@ export interface LlmChannelDescriptor {
331
396
  readonly authMethods?: Partial<Readonly<Record<LlmAuthMethod, {
332
397
  readonly wire: LlmWireProtocol;
333
398
  }>>>;
399
+ /** 可选:将该 channel 映射到一个或多个服务模板(添加服务目录)。 */
400
+ readonly serviceTemplates?: readonly LlmServiceTemplateDescriptor[];
334
401
  }
335
402
  export type LlmAuthMethod = 'api_key' | 'oauth_chatgpt' | 'oauth_google' | 'oauth_grok' | 'qoder_local_auth' | 'local_cli';
336
403
  export type LlmOAuthConnectionStatus = 'connected' | 'expired' | 'disconnected';
@@ -414,12 +481,27 @@ export interface LlmProviderConfig {
414
481
  readonly oauthProjectId?: string;
415
482
  readonly customHeaders?: Readonly<Record<string, string>>;
416
483
  readonly customHeadersInvalid?: boolean;
484
+ /**
485
+ * 服务模板 ID(服务商中心)。
486
+ * 旧配置可缺省;UI/迁移层按 channelId+authMethod 回填。
487
+ */
488
+ readonly serviceTemplateId?: string;
489
+ /** 服务连接用户可见状态;缺省时由 UI/服务层按凭据与诊断推导。 */
490
+ readonly connectionState?: LlmConnectionState;
491
+ readonly connectionStateReason?: string;
492
+ /** 配置版本:诊断结果必须绑定版本,避免旧结果污染新配置。 */
493
+ readonly configVersion?: number;
494
+ readonly lastCheckedAt?: string;
495
+ readonly lastSuccessAt?: string;
496
+ readonly lastErrorCategory?: LlmDiagnosticErrorCategory;
417
497
  }
418
498
  export interface LlmProviderConfigView extends LlmProviderConfig {
419
499
  readonly apiKeyMasked: string;
420
500
  readonly apiKeyConfigured: boolean;
421
501
  readonly oauthStatus?: LlmOAuthStatus;
422
502
  readonly credentialId?: string;
503
+ /** 最近一次脱敏诊断快照(可选)。 */
504
+ readonly lastDiagnostic?: LlmDiagnosticSnapshot;
423
505
  }
424
506
  export interface LlmModelConfig {
425
507
  readonly id: string;
@@ -530,6 +612,14 @@ export interface LlmProviderTestResult {
530
612
  readonly model?: string;
531
613
  readonly latencyMs?: number;
532
614
  readonly error?: string;
615
+ /** 面向用户的错误分类;缺省时 UI 可回退到 unknown。 */
616
+ readonly errorCategory?: LlmDiagnosticErrorCategory;
617
+ /** 阶段化诊断结果(配置 / 网络 / 认证 / 目录 / 最小请求…)。 */
618
+ readonly stages?: readonly LlmDiagnosticStage[];
619
+ readonly diagnostic?: LlmDiagnosticSnapshot;
620
+ /** 测试后推导出的连接状态建议。 */
621
+ readonly connectionState?: LlmConnectionState;
622
+ readonly connectionStateReason?: string;
533
623
  }
534
624
  export interface ClientBootstrap {
535
625
  readonly session: ClientSessionState;
@@ -22,8 +22,29 @@ export interface RuntimeTurnUsage extends UsageAmounts {
22
22
  readonly usageScope: 'runtime_turn';
23
23
  readonly providerRequestCount: number;
24
24
  }
25
+ /** Durable billable sum for one provider/model key inside a conversation ledger. */
26
+ export interface ConversationLifetimeModelUsage {
27
+ /** Stable provider binding id, e.g. '5198c365-...::ultimate'. */
28
+ readonly modelProviderId: string;
29
+ readonly model?: string;
30
+ readonly providerName?: string;
31
+ readonly inputTokens: number;
32
+ readonly outputTokens: number;
33
+ readonly totalTokens: number;
34
+ readonly cacheReadTokens: number;
35
+ readonly cacheWriteTokens: number;
36
+ readonly estimatedCostUsd: number;
37
+ readonly requestCount: number;
38
+ }
25
39
  /** Durable billable sum across completed runtime turns in one conversation. */
26
40
  export interface ConversationLifetimeUsage extends UsageAmounts {
27
41
  readonly usageScope: 'conversation_lifetime';
28
42
  readonly runtimeTurnCount?: number;
43
+ /**
44
+ * Per-model split of the same lifetime totals. Keyed by modelProviderId.
45
+ * Absent for conversations recorded before the byModel ledger existed
46
+ * (statistics then fall back to the request-level snapshot, or to the
47
+ * legacy "lifetime totals × current price" estimate).
48
+ */
49
+ readonly byModel?: Readonly<Record<string, ConversationLifetimeModelUsage>>;
29
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.0.1-beta.46",
3
+ "version": "0.0.1-beta.48",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",