@downcity/type 0.1.197 → 0.1.200

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 (74) hide show
  1. package/README.md +1 -1
  2. package/bin/index.d.ts +4 -1
  3. package/bin/index.d.ts.map +1 -1
  4. package/bin/index.js +2 -0
  5. package/bin/index.js.map +1 -1
  6. package/bin/types/CityModel.d.ts +21 -11
  7. package/bin/types/CityModel.d.ts.map +1 -1
  8. package/bin/types/CityModel.js +3 -5
  9. package/bin/types/CityModel.js.map +1 -1
  10. package/bin/types/auth/AuthPermission.d.ts +49 -0
  11. package/bin/types/auth/AuthPermission.d.ts.map +1 -0
  12. package/bin/types/auth/AuthPermission.js +87 -0
  13. package/bin/types/auth/AuthPermission.js.map +1 -0
  14. package/bin/types/auth/AuthToken.d.ts +46 -0
  15. package/bin/types/auth/AuthToken.d.ts.map +1 -0
  16. package/bin/types/auth/AuthToken.js +9 -0
  17. package/bin/types/auth/AuthToken.js.map +1 -0
  18. package/bin/types/auth/AuthTypes.d.ts +227 -0
  19. package/bin/types/auth/AuthTypes.d.ts.map +1 -0
  20. package/bin/types/auth/AuthTypes.js +9 -0
  21. package/bin/types/auth/AuthTypes.js.map +1 -0
  22. package/bin/types/model/ModelCall.d.ts +71 -0
  23. package/bin/types/model/ModelCall.d.ts.map +1 -0
  24. package/bin/types/model/ModelCall.js +8 -0
  25. package/bin/types/model/ModelCall.js.map +1 -0
  26. package/bin/types/model/ModelClient.d.ts +15 -0
  27. package/bin/types/model/ModelClient.d.ts.map +1 -0
  28. package/bin/types/model/ModelClient.js +7 -0
  29. package/bin/types/model/ModelClient.js.map +1 -0
  30. package/bin/types/model/ModelContent.d.ts +85 -0
  31. package/bin/types/model/ModelContent.d.ts.map +1 -0
  32. package/bin/types/model/ModelContent.js +7 -0
  33. package/bin/types/model/ModelContent.js.map +1 -0
  34. package/bin/types/model/ModelError.d.ts +21 -0
  35. package/bin/types/model/ModelError.d.ts.map +1 -0
  36. package/bin/types/model/ModelError.js +7 -0
  37. package/bin/types/model/ModelError.js.map +1 -0
  38. package/bin/types/model/ModelJson.d.ts +10 -0
  39. package/bin/types/model/ModelJson.d.ts.map +1 -0
  40. package/bin/types/model/ModelJson.js +7 -0
  41. package/bin/types/model/ModelJson.js.map +1 -0
  42. package/bin/types/model/ModelMessage.d.ts +14 -0
  43. package/bin/types/model/ModelMessage.d.ts.map +1 -0
  44. package/bin/types/model/ModelMessage.js +7 -0
  45. package/bin/types/model/ModelMessage.js.map +1 -0
  46. package/bin/types/model/ModelStreamEvent.d.ts +68 -0
  47. package/bin/types/model/ModelStreamEvent.d.ts.map +1 -0
  48. package/bin/types/model/ModelStreamEvent.js +7 -0
  49. package/bin/types/model/ModelStreamEvent.js.map +1 -0
  50. package/bin/types/model/ModelStreamValidator.d.ts +27 -0
  51. package/bin/types/model/ModelStreamValidator.d.ts.map +1 -0
  52. package/bin/types/model/ModelStreamValidator.js +199 -0
  53. package/bin/types/model/ModelStreamValidator.js.map +1 -0
  54. package/bin/types/model/ModelTool.d.ts +29 -0
  55. package/bin/types/model/ModelTool.d.ts.map +1 -0
  56. package/bin/types/model/ModelTool.js +7 -0
  57. package/bin/types/model/ModelTool.js.map +1 -0
  58. package/bin/types/model/ModelUsage.d.ts +21 -0
  59. package/bin/types/model/ModelUsage.d.ts.map +1 -0
  60. package/bin/types/model/ModelUsage.js +7 -0
  61. package/bin/types/model/ModelUsage.js.map +1 -0
  62. package/bin/types/model/index.d.ts +13 -0
  63. package/bin/types/model/index.d.ts.map +1 -0
  64. package/bin/types/model/index.js +4 -0
  65. package/bin/types/model/index.js.map +1 -0
  66. package/bin/types/tool/RuntimeTool.d.ts +37 -0
  67. package/bin/types/tool/RuntimeTool.d.ts.map +1 -0
  68. package/bin/types/tool/RuntimeTool.js +11 -0
  69. package/bin/types/tool/RuntimeTool.js.map +1 -0
  70. package/bin/types/tool/index.d.ts +5 -0
  71. package/bin/types/tool/index.d.ts.map +1 -0
  72. package/bin/types/tool/index.js +5 -0
  73. package/bin/types/tool/index.js.map +1 -0
  74. package/package.json +1 -4
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Downcity 模型调用协议模块。
3
+ *
4
+ * ModelCall 与模型目录身份分离,同一调用可以由 Federation 路由到不同最终模型。
5
+ */
6
+ import type { ModelMessage } from "./ModelMessage.js";
7
+ import type { ModelTool, ModelToolChoice } from "./ModelTool.js";
8
+ /** 单次标准模型调用。 */
9
+ export interface ModelCall {
10
+ /** 按模型上下文顺序排列的完整消息。 */
11
+ messages: ModelMessage[];
12
+ /** 本轮可供模型调用的工具。 */
13
+ tools?: ModelTool[];
14
+ /** 本轮工具选择策略。 */
15
+ tool_choice?: ModelToolChoice;
16
+ /** 最大输出 token 数。 */
17
+ max_output_tokens?: number;
18
+ /** 采样温度。 */
19
+ temperature?: number;
20
+ /** nucleus sampling 参数。 */
21
+ top_p?: number;
22
+ /** 候选 token 数限制。 */
23
+ top_k?: number;
24
+ /** presence penalty。 */
25
+ presence_penalty?: number;
26
+ /** frequency penalty。 */
27
+ frequency_penalty?: number;
28
+ /** 按顺序匹配的停止序列。 */
29
+ stop_sequences?: string[];
30
+ /** 可选确定性采样种子。 */
31
+ seed?: number;
32
+ /** 用户可请求的推理设置。 */
33
+ reasoning?: ModelReasoningRequest;
34
+ /** 模型输出格式约束。 */
35
+ response_format?: ModelResponseFormat;
36
+ }
37
+ /** 用户可请求的模型推理设置。 */
38
+ export interface ModelReasoningRequest {
39
+ /** 是否启用模型推理。 */
40
+ enabled: boolean;
41
+ /** 用户选择的可选推理强度。 */
42
+ effort?: string;
43
+ }
44
+ /** 模型输出格式约束。 */
45
+ export type ModelResponseFormat = {
46
+ type: "text";
47
+ } | {
48
+ type: "json";
49
+ } | {
50
+ type: "json_schema";
51
+ /** JSON Schema 的稳定名称。 */
52
+ name: string;
53
+ /** 面向模型的可选 Schema 说明。 */
54
+ description?: string;
55
+ /** 模型输出必须遵循的 JSON Schema。 */
56
+ schema: {
57
+ [key: string]: import("./ModelJson.js").ModelJsonValue;
58
+ };
59
+ };
60
+ /** 当前 Downcity Model Protocol 的固定版本。 */
61
+ export declare const MODEL_PROTOCOL_VERSION: 1;
62
+ /** Agent 或客户端发给 Federation 的流式模型请求。 */
63
+ export interface ModelStreamRequest {
64
+ /** Downcity Model Protocol 版本。 */
65
+ protocol_version: typeof MODEL_PROTOCOL_VERSION;
66
+ /** 用户选择的 Federation 模型 ID。 */
67
+ model_id: string;
68
+ /** 标准模型调用。 */
69
+ call: ModelCall;
70
+ }
71
+ //# sourceMappingURL=ModelCall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelCall.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelCall.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjE,gBAAgB;AAChB,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,mBAAmB;IACnB,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,gBAAgB;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,oBAAoB;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB;IAClB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,gBAAgB;IAChB,eAAe,CAAC,EAAE,mBAAmB,CAAC;CACvC;AAED,oBAAoB;AACpB,MAAM,WAAW,qBAAqB;IACpC,gBAAgB;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,gBAAgB;AAChB,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,gBAAgB,EAAE,cAAc,CAAA;KAAE,CAAC;CACpE,CAAC;AAEN,wCAAwC;AACxC,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AAEjD,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,kCAAkC;IAClC,gBAAgB,EAAE,OAAO,sBAAsB,CAAC;IAChD,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,IAAI,EAAE,SAAS,CAAC;CACjB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Downcity 模型调用协议模块。
3
+ *
4
+ * ModelCall 与模型目录身份分离,同一调用可以由 Federation 路由到不同最终模型。
5
+ */
6
+ /** 当前 Downcity Model Protocol 的固定版本。 */
7
+ export const MODEL_PROTOCOL_VERSION = 1;
8
+ //# sourceMappingURL=ModelCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelCall.js","sourceRoot":"","sources":["../../../src/types/model/ModelCall.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyDH,wCAAwC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAU,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Downcity 可执行模型客户端协议模块。
3
+ *
4
+ * 客户端只暴露标准流调用,不继承任何 Provider 的模型接口。
5
+ */
6
+ import type { ModelCall } from "./ModelCall.js";
7
+ import type { ModelStreamEvent } from "./ModelStreamEvent.js";
8
+ /** 可执行 Downcity 模型客户端。 */
9
+ export interface ModelClient {
10
+ /** Federation 模型目录中的模型 ID。 */
11
+ readonly id: string;
12
+ /** 使用标准 Downcity 协议执行一个模型 step。 */
13
+ stream(call: ModelCall, signal?: AbortSignal): Promise<ReadableStream<ModelStreamEvent>>;
14
+ }
15
+ //# sourceMappingURL=ModelClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelClient.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,0BAA0B;AAC1B,MAAM,WAAW,WAAW;IAC1B,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAC1F"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 可执行模型客户端协议模块。
3
+ *
4
+ * 客户端只暴露标准流调用,不继承任何 Provider 的模型接口。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelClient.js","sourceRoot":"","sources":["../../../src/types/model/ModelClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Downcity 模型消息内容协议模块。
3
+ *
4
+ * 内容使用封闭的判别联合,Provider Adapter 只能消费明确受支持的模型语义。
5
+ */
6
+ import type { ModelJsonValue } from "./ModelJson.js";
7
+ /** 模型消息允许携带的内容。 */
8
+ export type ModelContent = ModelTextContent | ModelFileContent | ModelReasoningContent | ModelToolCallContent | ModelToolResultContent;
9
+ /** 模型文本内容。 */
10
+ export interface ModelTextContent {
11
+ /** 内容判别字段。 */
12
+ type: "text";
13
+ /** 非空文本内容。 */
14
+ text: string;
15
+ }
16
+ /** 模型文件内容。 */
17
+ export interface ModelFileContent {
18
+ /** 内容判别字段。 */
19
+ type: "file";
20
+ /** 文件的 IANA MIME 类型。 */
21
+ media_type: string;
22
+ /** 文件内容的唯一来源。 */
23
+ source: ModelFileSource;
24
+ /** 可选原始文件名。 */
25
+ filename?: string;
26
+ }
27
+ /** 模型文件允许使用的来源。 */
28
+ export type ModelFileSource = ModelFileUrlSource | ModelFileBase64Source;
29
+ /** 通过网络 URL 引用的文件来源。 */
30
+ export interface ModelFileUrlSource {
31
+ /** URL 来源判别字段。 */
32
+ type: "url";
33
+ /** 可由 Provider 读取的绝对 HTTP 或 HTTPS URL。 */
34
+ url: string;
35
+ }
36
+ /** 通过 Base64 内联的文件来源。 */
37
+ export interface ModelFileBase64Source {
38
+ /** Base64 来源判别字段。 */
39
+ type: "base64";
40
+ /** 不包含 Data URL 前缀的 Base64 内容。 */
41
+ data: string;
42
+ }
43
+ /** 模型推理内容。 */
44
+ export interface ModelReasoningContent {
45
+ /** 内容判别字段。 */
46
+ type: "reasoning";
47
+ /** Provider 允许返回给调用方的推理文本。 */
48
+ text: string;
49
+ /** Provider 用于后续上下文续接的可选不透明签名。 */
50
+ signature?: string;
51
+ }
52
+ /** assistant 发起的工具调用。 */
53
+ export interface ModelToolCallContent {
54
+ /** 内容判别字段。 */
55
+ type: "tool_call";
56
+ /** 单次模型上下文内稳定且唯一的工具调用 ID。 */
57
+ tool_call_id: string;
58
+ /** 工具名称。 */
59
+ tool_name: string;
60
+ /** 已完成 JSON 解析的工具输入。 */
61
+ input: ModelJsonValue;
62
+ }
63
+ /** 工具执行后返回给模型的结果。 */
64
+ export interface ModelToolResultContent {
65
+ /** 内容判别字段。 */
66
+ type: "tool_result";
67
+ /** 对应工具调用 ID。 */
68
+ tool_call_id: string;
69
+ /** 对应工具名称。 */
70
+ tool_name: string;
71
+ /** 工具执行结果。 */
72
+ outcome: "succeeded" | "failed";
73
+ /** 返回给模型的有序结果内容。 */
74
+ content: ModelToolResultPart[];
75
+ }
76
+ /** 工具结果允许携带的内容。 */
77
+ export type ModelToolResultPart = ModelTextContent | ModelFileContent | ModelJsonContent;
78
+ /** 工具返回的结构化 JSON 内容。 */
79
+ export interface ModelJsonContent {
80
+ /** 内容判别字段。 */
81
+ type: "json";
82
+ /** 可跨进程传输的结构化值。 */
83
+ value: ModelJsonValue;
84
+ }
85
+ //# sourceMappingURL=ModelContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelContent.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,mBAAmB;AACnB,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,gBAAgB,GAChB,qBAAqB,GACrB,oBAAoB,GACpB,sBAAsB,CAAC;AAE3B,cAAc;AACd,MAAM,WAAW,gBAAgB;IAC/B,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,cAAc;AACd,MAAM,WAAW,gBAAgB;IAC/B,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB;IACjB,MAAM,EAAE,eAAe,CAAC;IACxB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,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ACvB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 模型消息内容协议模块。
3
+ *
4
+ * 内容使用封闭的判别联合,Provider Adapter 只能消费明确受支持的模型语义。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelContent.js","sourceRoot":"","sources":["../../../src/types/model/ModelContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Downcity 模型错误协议模块。
3
+ *
4
+ * 错误只暴露稳定、安全且可操作的字段,Provider 原始响应仅进入服务端受控日志。
5
+ */
6
+ /** Downcity 稳定模型错误代码。 */
7
+ export type ModelErrorCode = "invalid_request" | "authentication_failed" | "permission_denied" | "model_unavailable" | "rate_limited" | "context_length_exceeded" | "content_rejected" | "provider_timeout" | "provider_error" | "transport_error" | "cancelled" | "internal_error";
8
+ /** 可跨进程传输的标准模型错误。 */
9
+ export interface ModelError {
10
+ /** Downcity 稳定错误代码。 */
11
+ code: ModelErrorCode;
12
+ /** 可安全展示给调用方的错误说明。 */
13
+ message: string;
14
+ /** 调用方是否可以安全重试。 */
15
+ retryable: boolean;
16
+ /** 可选上游 HTTP 状态码。 */
17
+ status_code?: number;
18
+ /** 可选上游请求 ID。 */
19
+ provider_request_id?: string;
20
+ }
21
+ //# sourceMappingURL=ModelError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelError.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,yBAAyB;AACzB,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,uBAAuB,GACvB,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,yBAAyB,GACzB,kBAAkB,GAClB,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,GACX,gBAAgB,CAAC;AAErB,qBAAqB;AACrB,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,IAAI,EAAE,cAAc,CAAC;IACrB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 模型错误协议模块。
3
+ *
4
+ * 错误只暴露稳定、安全且可操作的字段,Provider 原始响应仅进入服务端受控日志。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelError.js","sourceRoot":"","sources":["../../../src/types/model/ModelError.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Downcity 模型协议 JSON 类型模块。
3
+ *
4
+ * 该模块定义所有可跨进程传输的结构化值,避免协议依赖运行时对象或第三方类型。
5
+ */
6
+ /** Downcity 模型协议允许传输的 JSON 值。 */
7
+ export type ModelJsonValue = string | number | boolean | null | ModelJsonValue[] | {
8
+ [key: string]: ModelJsonValue;
9
+ };
10
+ //# sourceMappingURL=ModelJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelJson.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelJson.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iCAAiC;AACjC,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,cAAc,EAAE,GAChB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 模型协议 JSON 类型模块。
3
+ *
4
+ * 该模块定义所有可跨进程传输的结构化值,避免协议依赖运行时对象或第三方类型。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelJson.js","sourceRoot":"","sources":["../../../src/types/model/ModelJson.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Downcity 模型消息协议模块。
3
+ *
4
+ * ModelMessage 只表达模型上下文,不承担 Session 持久化或 UI 时间线职责。
5
+ */
6
+ import type { ModelContent } from "./ModelContent.js";
7
+ /** 模型上下文中的标准消息。 */
8
+ export interface ModelMessage {
9
+ /** 消息在模型上下文中的角色。 */
10
+ role: "system" | "user" | "assistant" | "tool";
11
+ /** 按原始上下文顺序排列的消息内容。 */
12
+ content: ModelContent[];
13
+ }
14
+ //# sourceMappingURL=ModelMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelMessage.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelMessage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,mBAAmB;AACnB,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,uBAAuB;IACvB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 模型消息协议模块。
3
+ *
4
+ * ModelMessage 只表达模型上下文,不承担 Session 持久化或 UI 时间线职责。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelMessage.js","sourceRoot":"","sources":["../../../src/types/model/ModelMessage.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Downcity 模型流事件协议模块。
3
+ *
4
+ * 所有增量内容通过稳定 content_id 形成可校验的 start、delta、finish 生命周期。
5
+ */
6
+ import type { ModelJsonValue } from "./ModelJson.js";
7
+ import type { ModelError } from "./ModelError.js";
8
+ import type { ModelUsage } from "./ModelUsage.js";
9
+ import { MODEL_PROTOCOL_VERSION } from "./ModelCall.js";
10
+ /** 标准模型完成原因。 */
11
+ export type ModelFinishReason = "stop" | "length" | "tool_call" | "content_filter" | "cancelled" | "error" | "unknown";
12
+ /** 单次模型执行产生的标准流事件。 */
13
+ export type ModelStreamEvent = {
14
+ type: "model_start";
15
+ request_id: string;
16
+ model_id: string;
17
+ } | {
18
+ type: "text_start";
19
+ content_id: string;
20
+ } | {
21
+ type: "text_delta";
22
+ content_id: string;
23
+ delta: string;
24
+ } | {
25
+ type: "text_finish";
26
+ content_id: string;
27
+ } | {
28
+ type: "reasoning_start";
29
+ content_id: string;
30
+ } | {
31
+ type: "reasoning_delta";
32
+ content_id: string;
33
+ delta: string;
34
+ } | {
35
+ type: "reasoning_finish";
36
+ content_id: string;
37
+ signature?: string;
38
+ } | {
39
+ type: "tool_call_start";
40
+ content_id: string;
41
+ tool_call_id: string;
42
+ tool_name: string;
43
+ } | {
44
+ type: "tool_call_delta";
45
+ content_id: string;
46
+ input_delta: string;
47
+ } | {
48
+ type: "tool_call_finish";
49
+ content_id: string;
50
+ input: ModelJsonValue;
51
+ } | {
52
+ type: "model_usage";
53
+ usage: ModelUsage;
54
+ } | {
55
+ type: "model_finish";
56
+ finish_reason: ModelFinishReason;
57
+ } | {
58
+ type: "model_error";
59
+ error: ModelError;
60
+ };
61
+ /** Federation SSE 中单个模型流事件的版本化信封。 */
62
+ export interface ModelStreamEnvelope {
63
+ /** Downcity Model Protocol 版本。 */
64
+ protocol_version: typeof MODEL_PROTOCOL_VERSION;
65
+ /** 当前标准模型流事件。 */
66
+ event: ModelStreamEvent;
67
+ }
68
+ //# sourceMappingURL=ModelStreamEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelStreamEvent.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelStreamEvent.ts"],"names":[],"mappings":"A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AU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,aAAa,EAAE,iBAAiB,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/C,qCAAqC;AACrC,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,gBAAgB,EAAE,OAAO,sBAAsB,CAAC;IAChD,iBAAiB;IACjB,KAAK,EAAE,gBAAgB,CAAC;CACzB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Downcity 模型流事件协议模块。
3
+ *
4
+ * 所有增量内容通过稳定 content_id 形成可校验的 start、delta、finish 生命周期。
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ModelStreamEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelStreamEvent.js","sourceRoot":"","sources":["../../../src/types/model/ModelStreamEvent.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Downcity 模型流状态机校验模块。
3
+ *
4
+ * 该状态机属于 Model Protocol 本身,Federation、Agent 与其它客户端共享同一组
5
+ * content 生命周期和终态不变量,避免各执行边界分别猜测合法事件顺序。
6
+ */
7
+ import type { ModelStreamEvent } from "./ModelStreamEvent.js";
8
+ /** 校验单次 Downcity 模型流的事件顺序与字段不变量。 */
9
+ export declare class ModelStreamValidator {
10
+ private started;
11
+ private terminal;
12
+ private saw_usage;
13
+ private completed_tool_calls;
14
+ private readonly content_states;
15
+ private readonly tool_call_ids;
16
+ /** 接受并校验一个流事件;协议无效时立即抛错。 */
17
+ accept(event: ModelStreamEvent): void;
18
+ /** 在底层流关闭时确认已经收到唯一终态。 */
19
+ finish(): void;
20
+ /** 登记全局唯一的 content 生命周期。 */
21
+ private start_content;
22
+ /** 读取指定类型的活跃 content。 */
23
+ private require_open_content;
24
+ /** 关闭指定 content,并拒绝重复 finish。 */
25
+ private finish_content;
26
+ }
27
+ //# sourceMappingURL=ModelStreamValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelStreamValidator.d.ts","sourceRoot":"","sources":["../../../src/types/model/ModelStreamValidator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAY9D,oCAAoC;AACpC,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAG3B;IACJ,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IAEnD,4BAA4B;IAC5B,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IA6FrC,yBAAyB;IACzB,MAAM,IAAI,IAAI;IAKd,4BAA4B;IAC5B,OAAO,CAAC,aAAa;IAWrB,yBAAyB;IACzB,OAAO,CAAC,oBAAoB;IAW5B,iCAAiC;IACjC,OAAO,CAAC,cAAc;CAQvB"}
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Downcity 模型流状态机校验模块。
3
+ *
4
+ * 该状态机属于 Model Protocol 本身,Federation、Agent 与其它客户端共享同一组
5
+ * content 生命周期和终态不变量,避免各执行边界分别猜测合法事件顺序。
6
+ */
7
+ const FINISH_REASONS = new Set([
8
+ "stop",
9
+ "length",
10
+ "tool_call",
11
+ "content_filter",
12
+ "cancelled",
13
+ "error",
14
+ "unknown",
15
+ ]);
16
+ /** 校验单次 Downcity 模型流的事件顺序与字段不变量。 */
17
+ export class ModelStreamValidator {
18
+ started = false;
19
+ terminal = false;
20
+ saw_usage = false;
21
+ completed_tool_calls = 0;
22
+ content_states = new Map();
23
+ tool_call_ids = new Set();
24
+ /** 接受并校验一个流事件;协议无效时立即抛错。 */
25
+ accept(event) {
26
+ if (!event || typeof event !== "object") {
27
+ throw protocol_error("event must be an object");
28
+ }
29
+ if (this.terminal)
30
+ throw protocol_error("event received after terminal event");
31
+ if (event.type === "model_start") {
32
+ if (this.started)
33
+ throw protocol_error("model_start must appear exactly once");
34
+ require_non_empty_string(event.request_id, "model_start.request_id");
35
+ require_non_empty_string(event.model_id, "model_start.model_id");
36
+ this.started = true;
37
+ return;
38
+ }
39
+ if (!this.started)
40
+ throw protocol_error(`${event.type} received before model_start`);
41
+ if (event.type === "text_start" || event.type === "reasoning_start") {
42
+ this.start_content(event.content_id, event.type === "text_start" ? "text" : "reasoning");
43
+ return;
44
+ }
45
+ if (event.type === "text_delta" || event.type === "reasoning_delta") {
46
+ const kind = event.type === "text_delta" ? "text" : "reasoning";
47
+ this.require_open_content(event.content_id, kind);
48
+ if (typeof event.delta !== "string") {
49
+ throw protocol_error(`${event.type}.delta must be a string`);
50
+ }
51
+ return;
52
+ }
53
+ if (event.type === "text_finish" || event.type === "reasoning_finish") {
54
+ const kind = event.type === "text_finish" ? "text" : "reasoning";
55
+ this.finish_content(event.content_id, kind);
56
+ if (event.type === "reasoning_finish" && event.signature !== undefined) {
57
+ require_non_empty_string(event.signature, "reasoning_finish.signature");
58
+ }
59
+ return;
60
+ }
61
+ if (event.type === "tool_call_start") {
62
+ this.start_content(event.content_id, "tool_call");
63
+ require_non_empty_string(event.tool_call_id, "tool_call_start.tool_call_id");
64
+ require_non_empty_string(event.tool_name, "tool_call_start.tool_name");
65
+ if (this.tool_call_ids.has(event.tool_call_id)) {
66
+ throw protocol_error(`duplicate tool_call_id: ${event.tool_call_id}`);
67
+ }
68
+ this.tool_call_ids.add(event.tool_call_id);
69
+ return;
70
+ }
71
+ if (event.type === "tool_call_delta") {
72
+ this.require_open_content(event.content_id, "tool_call");
73
+ if (typeof event.input_delta !== "string") {
74
+ throw protocol_error("tool_call_delta.input_delta must be a string");
75
+ }
76
+ return;
77
+ }
78
+ if (event.type === "tool_call_finish") {
79
+ this.finish_content(event.content_id, "tool_call");
80
+ require_json_value(event.input, "tool_call_finish.input");
81
+ this.completed_tool_calls += 1;
82
+ return;
83
+ }
84
+ if (event.type === "model_usage") {
85
+ validate_usage(event.usage);
86
+ this.saw_usage = true;
87
+ return;
88
+ }
89
+ if (event.type === "model_finish") {
90
+ if (!FINISH_REASONS.has(event.finish_reason)) {
91
+ throw protocol_error("model_finish.finish_reason is invalid");
92
+ }
93
+ if ([...this.content_states.values()].some((state) => state.open)) {
94
+ throw protocol_error("model_finish received before all content finished");
95
+ }
96
+ if (!this.saw_usage) {
97
+ throw protocol_error("model_finish requires final model_usage");
98
+ }
99
+ if (event.finish_reason === "tool_call" && this.completed_tool_calls === 0) {
100
+ throw protocol_error("tool_call finish reason requires a completed tool call");
101
+ }
102
+ this.terminal = true;
103
+ return;
104
+ }
105
+ if (event.type === "model_error") {
106
+ require_non_empty_string(event.error.code, "model_error.error.code");
107
+ require_non_empty_string(event.error.message, "model_error.error.message");
108
+ if (typeof event.error.retryable !== "boolean") {
109
+ throw protocol_error("model_error.error.retryable must be a boolean");
110
+ }
111
+ this.terminal = true;
112
+ return;
113
+ }
114
+ throw protocol_error(`unknown model stream event: ${String(event.type)}`);
115
+ }
116
+ /** 在底层流关闭时确认已经收到唯一终态。 */
117
+ finish() {
118
+ if (!this.started)
119
+ throw protocol_error("model stream ended without model_start");
120
+ if (!this.terminal)
121
+ throw protocol_error("model stream ended without a terminal event");
122
+ }
123
+ /** 登记全局唯一的 content 生命周期。 */
124
+ start_content(content_id, kind) {
125
+ require_non_empty_string(content_id, `${kind}_start.content_id`);
126
+ if (this.content_states.has(content_id)) {
127
+ throw protocol_error(`duplicate content_id: ${content_id}`);
128
+ }
129
+ this.content_states.set(content_id, { kind, open: true });
130
+ }
131
+ /** 读取指定类型的活跃 content。 */
132
+ require_open_content(content_id, kind) {
133
+ require_non_empty_string(content_id, `${kind}.content_id`);
134
+ const state = this.content_states.get(content_id);
135
+ if (!state || !state.open || state.kind !== kind) {
136
+ throw protocol_error(`${kind} content is not open: ${content_id}`);
137
+ }
138
+ }
139
+ /** 关闭指定 content,并拒绝重复 finish。 */
140
+ finish_content(content_id, kind) {
141
+ this.require_open_content(content_id, kind);
142
+ const state = this.content_states.get(content_id);
143
+ if (state)
144
+ state.open = false;
145
+ }
146
+ }
147
+ /** 校验 usage 只包含可解释的非负 token 累计值。 */
148
+ function validate_usage(usage) {
149
+ if (!usage || typeof usage !== "object")
150
+ throw protocol_error("model_usage.usage must be an object");
151
+ for (const field of ["input_tokens", "output_tokens", "total_tokens"]) {
152
+ const value = usage[field];
153
+ if (!Number.isSafeInteger(value) || value < 0) {
154
+ throw protocol_error(`model_usage.usage.${field} must be a non-negative integer`);
155
+ }
156
+ }
157
+ if (usage.total_tokens !== usage.input_tokens + usage.output_tokens) {
158
+ throw protocol_error("model_usage.usage.total_tokens must equal input_tokens + output_tokens");
159
+ }
160
+ for (const field of [
161
+ "cached_input_tokens",
162
+ "cache_write_tokens",
163
+ "reasoning_tokens",
164
+ ]) {
165
+ const value = usage[field];
166
+ if (value !== undefined && (!Number.isSafeInteger(value) || value < 0)) {
167
+ throw protocol_error(`model_usage.usage.${field} must be a non-negative integer`);
168
+ }
169
+ }
170
+ }
171
+ /** 校验协议必填字符串。 */
172
+ function require_non_empty_string(value, field) {
173
+ if (typeof value !== "string" || !value.trim()) {
174
+ throw protocol_error(`${field} must be a non-empty string`);
175
+ }
176
+ }
177
+ /** 递归校验工具调用输入为 JSON 值。 */
178
+ function require_json_value(value, field) {
179
+ if (value === null || typeof value === "string" || typeof value === "boolean")
180
+ return;
181
+ if (typeof value === "number" && Number.isFinite(value))
182
+ return;
183
+ if (Array.isArray(value)) {
184
+ value.forEach((item, index) => require_json_value(item, `${field}[${index}]`));
185
+ return;
186
+ }
187
+ if (value && typeof value === "object") {
188
+ for (const [key, item] of Object.entries(value)) {
189
+ require_json_value(item, `${field}.${key}`);
190
+ }
191
+ return;
192
+ }
193
+ throw protocol_error(`${field} must be valid JSON`);
194
+ }
195
+ /** 创建稳定的模型流协议错误。 */
196
+ function protocol_error(message) {
197
+ return new Error(`Invalid Downcity model stream: ${message}`);
198
+ }
199
+ //# sourceMappingURL=ModelStreamValidator.js.map