@springbrand/agent-runtime 0.1.0
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/package.json +28 -0
- package/src/db/approval.repo.ts +291 -0
- package/src/db/ext-context.repo.ts +34 -0
- package/src/db/index.ts +83 -0
- package/src/db/message-ui.repo.ts +39 -0
- package/src/db/milestone.repo.ts +96 -0
- package/src/db/runtime-event-outbox.repo.ts +89 -0
- package/src/db/schema.ts +164 -0
- package/src/db/settlement.repo.ts +104 -0
- package/src/db/steer.repo.ts +73 -0
- package/src/db/submission.repo.ts +323 -0
- package/src/index.ts +133 -0
- package/src/kernel/approval-lifecycle.ts +552 -0
- package/src/kernel/bindings.ts +898 -0
- package/src/kernel/degradation.ts +15 -0
- package/src/kernel/extensions.ts +108 -0
- package/src/kernel/profile.ts +116 -0
- package/src/kernel/public-contracts.ts +17 -0
- package/src/kernel/receipts.ts +124 -0
- package/src/kernel/recoverable-chat-agent.ts +899 -0
- package/src/kernel/state.ts +76 -0
- package/src/kernel/submission-lifecycle.ts +600 -0
- package/src/layers/context/budget/gate.ts +88 -0
- package/src/layers/orchestration/subagents/agent-types/contract.ts +78 -0
- package/src/layers/orchestration/subagents/agent-types/extract/index.ts +47 -0
- package/src/layers/orchestration/subagents/agent-types/fanout/index.ts +53 -0
- package/src/layers/orchestration/subagents/agent-types/registry.ts +16 -0
- package/src/layers/orchestration/temporary-agent/core.ts +152 -0
- package/src/layers/orchestration/temporary-agent/runner.ts +133 -0
- package/src/layers/orchestration/temporary-agent/workspace.ts +154 -0
- package/src/lib/artifacts.ts +54 -0
- package/src/lib/egress.ts +44 -0
- package/src/lib/execution-level.ts +27 -0
- package/src/lib/extension-name.ts +18 -0
- package/src/lib/host-actions.ts +57 -0
- package/src/lib/mcp.ts +86 -0
- package/src/lib/model-catalog.ts +7 -0
- package/src/lib/prompt.ts +139 -0
- package/src/lib/telemetry-dev.ts +44 -0
- package/src/pi/assembly/context.ts +510 -0
- package/src/pi/assembly/extensions.ts +661 -0
- package/src/pi/assembly/index.ts +19 -0
- package/src/pi/assembly/snapshot.ts +200 -0
- package/src/pi/message/contract.ts +8 -0
- package/src/pi/message/conversion.ts +73 -0
- package/src/pi/message/index.ts +3 -0
- package/src/pi/message/projection.ts +604 -0
- package/src/pi/runtime-adapter/assembly.ts +552 -0
- package/src/pi/runtime-adapter/execution.ts +683 -0
- package/src/pi/runtime-adapter/index.ts +232 -0
- package/src/pi/runtime-adapter/models.ts +243 -0
- package/src/pi/runtime-adapter/recovery.ts +805 -0
- package/src/pi/runtime-adapter/transcript.ts +825 -0
- package/src/pi/session/index.ts +24 -0
- package/src/pi/session/storage.ts +353 -0
- package/src/pi/tool/ai-adapter.ts +100 -0
- package/src/pi/tool/base.ts +110 -0
- package/src/pi/tool/compiler.ts +444 -0
- package/src/pi/tool/core-host.ts +48 -0
- package/src/pi/tool/core.ts +251 -0
- package/src/pi/tool/index.ts +32 -0
- package/src/pi/tool/mcp.ts +319 -0
- package/src/pi/tool/schedule.ts +198 -0
- package/src/pi/tool/skill.ts +455 -0
- package/src/pi/tool/subagent.ts +148 -0
- package/src/pi/tool/web-search/api.ts +1292 -0
- package/src/pi/tool/web-search/index.ts +2 -0
- package/src/pi/tool/web-search/web-search.ts +127 -0
- package/src/pi/tool/workspace-sandbox.ts +664 -0
- package/src/pi/turn/approval.ts +181 -0
- package/src/pi/turn/index.ts +62 -0
- package/src/pi/turn/tool-recovery.ts +792 -0
- package/src/plugins.ts +1024 -0
- package/src/runtime-agent.ts +654 -0
- package/src/runtime.ts +2880 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记录某项可选 Runtime 能力为什么没有启用。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Plugin 在装配可选能力失败但整体仍可运行时报告它,调用方可从最终 Snapshot 读取诊断。
|
|
6
|
+
*
|
|
7
|
+
* 必需能力不能走这个通道,而应直接让装配失败,否则会提交一个不能正常工作的 Runtime。
|
|
8
|
+
*
|
|
9
|
+
* `Plugin`、`Snapshot` 与 `degradation` 等核心术语见 `../index.ts`。
|
|
10
|
+
*/
|
|
11
|
+
export interface RuntimeDegradation {
|
|
12
|
+
readonly capability: string;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
readonly detail?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 声明一个 Runtime Extension 可以访问的外部能力。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Host 在资源装配时生成它,Extension 加载器在创建执行隔离环境前读取。
|
|
6
|
+
*
|
|
7
|
+
* 权限与 manifest 一起传入,让未声明的网络、工作区、上下文或会话访问默认不可用。
|
|
8
|
+
*
|
|
9
|
+
* `Runtime` 与 `Host` 等核心术语见 `../index.ts`。
|
|
10
|
+
*/
|
|
11
|
+
export interface RuntimeExtensionPermissions {
|
|
12
|
+
readonly network?: readonly string[];
|
|
13
|
+
readonly workspace?: "read" | "read-write" | "none";
|
|
14
|
+
readonly context?: {
|
|
15
|
+
readonly read?: readonly string[] | "all";
|
|
16
|
+
readonly write?: readonly string[] | "own";
|
|
17
|
+
};
|
|
18
|
+
readonly messages?: "none" | "read";
|
|
19
|
+
readonly session?: {
|
|
20
|
+
readonly sendMessage?: boolean;
|
|
21
|
+
readonly metadata?: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 描述 Extension 想向模型上下文贡献的一个内容块。
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* Extension 作者在 manifest 中声明,Pi 装配在 Extension 通过发布、启用和授权筛选后读取。
|
|
30
|
+
*
|
|
31
|
+
* 字段保持为纯数据,便于 Host 在运行 Extension 代码前完成校验和预算分配。
|
|
32
|
+
*
|
|
33
|
+
* `Host` 等核心术语见 `../index.ts`。
|
|
34
|
+
*/
|
|
35
|
+
export interface RuntimeExtensionContextDefinition {
|
|
36
|
+
readonly label: string;
|
|
37
|
+
readonly description?: string;
|
|
38
|
+
readonly type: "readonly" | "writable" | "skill" | "searchable";
|
|
39
|
+
readonly maxTokens?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 把 Extension 的 manifest 与待加载源码放在同一份配置里。
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* extension Plugin 在贡献阶段提供它,Pi Extension 适配器在候选 Runtime 装配时加载。
|
|
47
|
+
*
|
|
48
|
+
* manifest 与源码一起传递,可避免授权信息与实际执行代码在不同查找步骤中错位。
|
|
49
|
+
*
|
|
50
|
+
* `Plugin` 与 `Runtime` 等核心术语见 `../index.ts`。
|
|
51
|
+
*/
|
|
52
|
+
export interface RuntimeExtensionConfig {
|
|
53
|
+
readonly manifest: {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly version: string;
|
|
56
|
+
readonly description?: string;
|
|
57
|
+
readonly permissions?: RuntimeExtensionPermissions;
|
|
58
|
+
readonly context?: readonly RuntimeExtensionContextDefinition[];
|
|
59
|
+
};
|
|
60
|
+
readonly source: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 描述一个已加载 Extension 向模型暴露的 Tool。
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Extension 加载器在发现阶段生成,Pi 装配器用它构造最终的模型 Tool 候选。
|
|
68
|
+
*
|
|
69
|
+
* 描述与执行分开,让装配可以先校验全部 Tool,再对实际调用开放权限。
|
|
70
|
+
*
|
|
71
|
+
* `Tool` 等核心术语见 `../index.ts`。
|
|
72
|
+
*/
|
|
73
|
+
export interface RuntimeExtensionToolDescriptor {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly description: string;
|
|
76
|
+
readonly inputSchema: {
|
|
77
|
+
readonly type: "object";
|
|
78
|
+
readonly properties: Readonly<Record<string, unknown>>;
|
|
79
|
+
readonly required?: readonly string[];
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 提供已校验 Extension 的 Tool 目录和统一执行入口。
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* Pi 装配器在加载 Extension 后使用它,先枚举 `tools`,再在模型真正选中 Tool 时调用 `execute`。
|
|
88
|
+
*
|
|
89
|
+
* 目录和执行句柄共享同一个加载结果,避免展示的 Tool 与实际可执行 Tool 来自不同版本。
|
|
90
|
+
*
|
|
91
|
+
* `Tool` 等核心术语见 `../index.ts`。
|
|
92
|
+
*/
|
|
93
|
+
export interface LoadedRuntimeExtension {
|
|
94
|
+
readonly tools: readonly RuntimeExtensionToolDescriptor[];
|
|
95
|
+
/**
|
|
96
|
+
* 执行目录中指定的 Extension Tool。
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* Pi Tool 适配器在模型已选中 Tool 并完成审批后调用,并应传入当前 Turn 的取消信号。
|
|
100
|
+
*
|
|
101
|
+
* 所有 Extension 调用共用这一入口,使未知 Tool 校验和执行隔离不会被调用方绕过。
|
|
102
|
+
*/
|
|
103
|
+
execute(
|
|
104
|
+
toolName: string,
|
|
105
|
+
args: Readonly<Record<string, unknown>>,
|
|
106
|
+
signal?: AbortSignal,
|
|
107
|
+
): Promise<unknown>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { ExecutionLevel } from "../lib/execution-level";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 指定模型在一次 Turn 中可以使用的推理强度。
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Host 在组装 Profile 时选择它,Runtime Adapter 在发起模型请求时使用该值。
|
|
8
|
+
*
|
|
9
|
+
* 这里保留受支持值的联合类型,让错误配置在进入模型适配层前就能被类型检查发现。
|
|
10
|
+
*
|
|
11
|
+
* `Profile` 与 `Host` 等核心术语见 `../index.ts`。
|
|
12
|
+
*/
|
|
13
|
+
export type ThinkingEffort =
|
|
14
|
+
| "none"
|
|
15
|
+
| "minimal"
|
|
16
|
+
| "low"
|
|
17
|
+
| "medium"
|
|
18
|
+
| "high"
|
|
19
|
+
| "xhigh";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 保存一次装配选定的内存开关与上下文预算。
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* memory Plugin 在贡献阶段提供它,Runtime 在构建上下文和触发压缩时读取。
|
|
26
|
+
*
|
|
27
|
+
* 预算与开关放在同一个 Profile 中,确保一次 Snapshot 只使用一套内存配置。
|
|
28
|
+
*
|
|
29
|
+
* `Plugin`、`Profile` 与 `Snapshot` 等核心术语见 `../index.ts`。
|
|
30
|
+
*/
|
|
31
|
+
export interface RuntimeMemoryProfile {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
memoryTokens: number;
|
|
34
|
+
preferencesTokens: number;
|
|
35
|
+
compactAfterTokens: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 指明本次装配允许连接的一个 MCP 服务。
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* connector Plugin 在贡献阶段加入它,Pi 工具装配只选择 Host 已就绪且 URL 匹配的连接。
|
|
43
|
+
*
|
|
44
|
+
* 这里只保留名称和 URL;连接生命周期、凭据与重试仍由 Host 管理。
|
|
45
|
+
*
|
|
46
|
+
* `Plugin` 与 `Host` 等核心术语见 `../index.ts`。
|
|
47
|
+
*/
|
|
48
|
+
export interface RuntimeMcpServer {
|
|
49
|
+
name: string;
|
|
50
|
+
url: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Turn 期唯一还需要执行的能力筛选:拒绝清单。
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* 「这个 Agent 有没有某个能力」在装配期就已经决定完了 —— Host Action 由
|
|
58
|
+
* `decideHostActions` 挑选后才注入,Workspace、Skill、MCP、Extension 各自由
|
|
59
|
+
* 自己的绑定决定。到了 Turn 期唯一还要做的事,就是把 `deny` 里点名的东西减掉。
|
|
60
|
+
*
|
|
61
|
+
* 这也是它只剩一个字段的原因:能表达「全集减法」的复杂策略对象,是判断时机
|
|
62
|
+
* 太晚的产物,不是需求本身。
|
|
63
|
+
*
|
|
64
|
+
* `Turn` 与 `Host Action` 等核心术语见 `../index.ts`。
|
|
65
|
+
*/
|
|
66
|
+
export interface RuntimeDenyPolicy {
|
|
67
|
+
deny: readonly string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 保存一次装配中真正会影响执行的参数。
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* `RuntimeBuilder` 在所有 Plugin 贡献完成后生成它,Kernel 只通过已提交的 Snapshot 读取。
|
|
75
|
+
*
|
|
76
|
+
* 它不包含业务身份、归属键或存储地址,因为这些选择属于 Host,不应被冻结成执行参数。
|
|
77
|
+
*
|
|
78
|
+
* `RuntimeBuilder`、`Plugin`、`Kernel`、`Snapshot` 与 `Host` 等核心术语见 `../index.ts`。
|
|
79
|
+
*/
|
|
80
|
+
export interface RuntimeProfile {
|
|
81
|
+
model: string;
|
|
82
|
+
thinking: ThinkingEffort;
|
|
83
|
+
systemPrompt?: string;
|
|
84
|
+
denyPolicy?: RuntimeDenyPolicy;
|
|
85
|
+
enabledSubagents: readonly string[];
|
|
86
|
+
mcpServers: readonly RuntimeMcpServer[];
|
|
87
|
+
enabledExtensions: readonly string[];
|
|
88
|
+
executionLevel: ExecutionLevel;
|
|
89
|
+
memory: RuntimeMemoryProfile;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 复制并冻结 Profile,使本次装配的执行选择不再被改写。
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* `RuntimeBuilder.build()` 在创建候选 Snapshot 时调用;调用方应继续使用返回值,不要再持有传入的可变数组。
|
|
97
|
+
*
|
|
98
|
+
* 实现会复制并冻结所有嵌套数组及配置对象,避免 Plugin 在提交后通过原始引用改动 Snapshot。
|
|
99
|
+
*
|
|
100
|
+
* `RuntimeBuilder`、`Plugin` 与 `Snapshot` 等核心术语见 `../index.ts`。
|
|
101
|
+
*/
|
|
102
|
+
export function freezeRuntimeProfile(profile: RuntimeProfile): RuntimeProfile {
|
|
103
|
+
const frozen: RuntimeProfile = {
|
|
104
|
+
...profile,
|
|
105
|
+
denyPolicy: profile.denyPolicy
|
|
106
|
+
? Object.freeze({
|
|
107
|
+
deny: Object.freeze([...profile.denyPolicy.deny]),
|
|
108
|
+
})
|
|
109
|
+
: undefined,
|
|
110
|
+
enabledSubagents: Object.freeze([...profile.enabledSubagents]),
|
|
111
|
+
mcpServers: Object.freeze(profile.mcpServers.map((server) => Object.freeze({ ...server }))),
|
|
112
|
+
enabledExtensions: Object.freeze([...profile.enabledExtensions]),
|
|
113
|
+
memory: Object.freeze({ ...profile.memory }),
|
|
114
|
+
};
|
|
115
|
+
return Object.freeze(frozen);
|
|
116
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 汇总浏览器与 Worker 可以安全共享的数据契约。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* 前端或跨边界代码应从这个入口导入 Profile、消息、回执和公开状态类型,不要依赖 Runtime 的内部模块。
|
|
6
|
+
*
|
|
7
|
+
* 单独保留这个入口,是为了让共享 DTO 与只能在服务端运行的实现保持明确边界。
|
|
8
|
+
*
|
|
9
|
+
* 核心术语见 `../index.ts`。
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
export * from "./profile";
|
|
14
|
+
export * from "../pi/message";
|
|
15
|
+
export * from "./receipts";
|
|
16
|
+
export * from "./state";
|
|
17
|
+
export * from "../lib/execution-level";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { UIMessage } from "ai";
|
|
2
|
+
import type { ExecutionLevel } from "../lib/execution-level";
|
|
3
|
+
|
|
4
|
+
export type ApprovalDecision =
|
|
5
|
+
| { decision: "deny"; reason?: string }
|
|
6
|
+
| { decision: "allow_once" }
|
|
7
|
+
| { decision: "allow_level" };
|
|
8
|
+
|
|
9
|
+
export const APPROVAL_DECISIONS = [
|
|
10
|
+
"deny",
|
|
11
|
+
"allow_once",
|
|
12
|
+
"allow_level",
|
|
13
|
+
] as const satisfies readonly ApprovalDecision["decision"][];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 记录一次待审批 Tool 执行的身份、摘要和原始输入。
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Turn 审批逻辑在请求用户决定前生成,审批生命周期会按 `requestId` 存储、查询和消费。
|
|
20
|
+
*
|
|
21
|
+
* 回执保留当时的输入与风险,使后续决定针对的是原请求,而不是可能已变的当前配置。
|
|
22
|
+
*
|
|
23
|
+
* `Turn` 与 `Tool` 等核心术语见 `../index.ts`。
|
|
24
|
+
*/
|
|
25
|
+
export interface ApprovalReceipt {
|
|
26
|
+
executionId: string;
|
|
27
|
+
source: "action" | "codemode" | "temporary-agent";
|
|
28
|
+
action: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
executionLevel: ExecutionLevel;
|
|
31
|
+
requiredExecutionLevel: ExecutionLevel;
|
|
32
|
+
inputJson: string;
|
|
33
|
+
requestId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 定时到点后要做的事。
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* schedule Tool 或定时 API 在创建任务时提供,Scheduler 在到点后读取并分派。
|
|
41
|
+
*
|
|
42
|
+
* `prompt` 用当前用户的默认 Agent 跑;`agent` 指定由哪个 User Agent 跑。
|
|
43
|
+
*
|
|
44
|
+
* 两者的 prompt 都必须自包含,因为触发时会在独立会话中执行,不会携带创建它的那段对话上下文。
|
|
45
|
+
*/
|
|
46
|
+
export type ScheduleJob =
|
|
47
|
+
| { kind: "prompt"; prompt: string }
|
|
48
|
+
| { kind: "agent"; userAgentId: string; prompt: string };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 定义一个定时任务的触发条件和到点工作。
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* schedule Tool 或 Worker API 创建它,Scheduler 会校验后持久化,并计算下一次触发时间。
|
|
55
|
+
*
|
|
56
|
+
* 触发条件与工作放在同一份规格里,使更新时可以原地替换两者,不用改变任务标识。
|
|
57
|
+
*/
|
|
58
|
+
export interface ScheduleSpec {
|
|
59
|
+
trigger:
|
|
60
|
+
| { kind: "once-at"; at: string }
|
|
61
|
+
| { kind: "once-in"; seconds: number }
|
|
62
|
+
| { kind: "cron"; cron: string }
|
|
63
|
+
| { kind: "interval"; seconds: number };
|
|
64
|
+
job: ScheduleJob;
|
|
65
|
+
label?: string;
|
|
66
|
+
/**
|
|
67
|
+
* cron 里的钟点按哪个时区解释(IANA 名,如 `Asia/Shanghai`)。
|
|
68
|
+
* 缺省为 `UTC` —— 与 Cloudflare Cron Triggers 按 UTC 执行的语义一致,但对人来说几乎总是错的,
|
|
69
|
+
* 所以创建入口都应显式带上用户所在时区。
|
|
70
|
+
*/
|
|
71
|
+
tz?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 返回一次异步提交的当前接收与完成状态。
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* Runtime 在接收提交时创建,Inbox RPC 和 HTTP API 在创建后或轮询时返回给调用方。
|
|
79
|
+
*
|
|
80
|
+
* 接收状态与最终结果共用同一个 `submissionId`,使调用方无需依赖长连接也能查询。
|
|
81
|
+
*
|
|
82
|
+
* `Runtime` 等核心术语见 `../index.ts`。
|
|
83
|
+
*/
|
|
84
|
+
export interface SubmissionReceipt {
|
|
85
|
+
submissionId: string;
|
|
86
|
+
status: string;
|
|
87
|
+
accepted: boolean;
|
|
88
|
+
error?: string;
|
|
89
|
+
createdAt: number;
|
|
90
|
+
completedAt?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Shared discriminator keeps the Stop control and durable transcript semantics aligned. */
|
|
94
|
+
export const USER_STOP_REASON = "Stopped by user";
|
|
95
|
+
|
|
96
|
+
export type MessageDelivery = "steer" | "enqueue";
|
|
97
|
+
|
|
98
|
+
export type MessageDispatchErrorCode =
|
|
99
|
+
| "queue_full"
|
|
100
|
+
| "not_steerable"
|
|
101
|
+
| "invalid_message";
|
|
102
|
+
|
|
103
|
+
export type MessageDispatchReceipt =
|
|
104
|
+
| {
|
|
105
|
+
kind: "accepted";
|
|
106
|
+
submissionId: string;
|
|
107
|
+
messageId: string;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
kind: "steered";
|
|
111
|
+
submissionId: string;
|
|
112
|
+
messageId: string;
|
|
113
|
+
message?: UIMessage;
|
|
114
|
+
}
|
|
115
|
+
| {
|
|
116
|
+
kind: "queued";
|
|
117
|
+
submission: SubmissionReceipt;
|
|
118
|
+
position: number;
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
kind: "rejected";
|
|
122
|
+
code: MessageDispatchErrorCode;
|
|
123
|
+
message: string;
|
|
124
|
+
};
|