@dinoxx/dinox-cli 2.2.0 → 2.4.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/README.md +17 -3
- package/dist/cli.js +6 -0
- package/dist/commands/domain/options.d.ts +10 -0
- package/dist/commands/domain/options.js +75 -0
- package/dist/commands/domain/run.d.ts +24 -0
- package/dist/commands/domain/run.js +137 -0
- package/dist/commands/gateway/index.d.ts +4 -0
- package/dist/commands/gateway/index.js +300 -0
- package/dist/commands/notes/actions.js +47 -18
- package/dist/commands/notes/createFromTemplate.d.ts +35 -0
- package/dist/commands/notes/createFromTemplate.js +58 -0
- package/dist/commands/notes/descriptors.js +9 -4
- package/dist/commands/notes/repo/read.js +4 -23
- package/dist/commands/notes/repo/write.d.ts +2 -0
- package/dist/commands/notes/repo/write.js +1 -1
- package/dist/commands/properties/index.d.ts +16 -0
- package/dist/commands/properties/index.js +640 -0
- package/dist/commands/properties/repo.d.ts +150 -0
- package/dist/commands/properties/repo.js +272 -0
- package/dist/commands/savedViews/fields.d.ts +28 -0
- package/dist/commands/savedViews/fields.js +87 -0
- package/dist/commands/savedViews/index.js +203 -164
- package/dist/commands/savedViews/model.d.ts +27 -69
- package/dist/commands/savedViews/model.js +63 -279
- package/dist/commands/savedViews/repo.d.ts +64 -62
- package/dist/commands/savedViews/repo.js +309 -428
- package/dist/commands/schema/renderSkills.js +33 -5
- package/dist/commands/schema/spec.js +6 -0
- package/dist/commands/templates/index.d.ts +4 -0
- package/dist/commands/templates/index.js +290 -0
- package/dist/commands/templates/model.d.ts +12 -34
- package/dist/commands/templates/model.js +39 -83
- package/dist/commands/templates/repo.d.ts +53 -0
- package/dist/commands/templates/repo.js +78 -0
- package/dist/config/paths.d.ts +1 -0
- package/dist/config/paths.js +1 -1
- package/dist/daemon/server.d.ts +1 -0
- package/dist/daemon/server.js +31 -0
- package/dist/gateway/adapters/acp.d.ts +42 -0
- package/dist/gateway/adapters/acp.js +285 -0
- package/dist/gateway/adapters/echo.d.ts +12 -0
- package/dist/gateway/adapters/echo.js +51 -0
- package/dist/gateway/adapters/index.d.ts +9 -0
- package/dist/gateway/adapters/index.js +30 -0
- package/dist/gateway/assistantProjection.d.ts +32 -0
- package/dist/gateway/assistantProjection.js +193 -0
- package/dist/gateway/config.d.ts +50 -0
- package/dist/gateway/config.js +253 -0
- package/dist/gateway/detect.d.ts +40 -0
- package/dist/gateway/detect.js +145 -0
- package/dist/gateway/deviceHost.d.ts +82 -0
- package/dist/gateway/deviceHost.js +530 -0
- package/dist/gateway/mcpServer.d.ts +4 -0
- package/dist/gateway/mcpServer.js +118 -0
- package/dist/gateway/protocol.d.ts +29 -0
- package/dist/gateway/protocol.js +127 -0
- package/dist/gateway/runExecutor.d.ts +67 -0
- package/dist/gateway/runExecutor.js +316 -0
- package/dist/gateway/service.d.ts +26 -0
- package/dist/gateway/service.js +82 -0
- package/dist/gateway/streamPublisher.d.ts +33 -0
- package/dist/gateway/streamPublisher.js +93 -0
- package/dist/gateway/threadStore.d.ts +157 -0
- package/dist/gateway/threadStore.js +430 -0
- package/dist/gateway/types.d.ts +117 -0
- package/dist/gateway/types.js +9 -0
- package/dist/skills/registry.js +7 -0
- package/dist/utils/errorCodes.d.ts +212 -0
- package/dist/utils/errorCodes.js +53 -0
- package/dist/vendor/electron/domain/note-templates.d.ts +3 -0
- package/dist/vendor/electron/domain/note-templates.js +232 -0
- package/dist/vendor/electron/domain/properties.d.ts +10 -0
- package/dist/vendor/electron/domain/properties.js +1549 -0
- package/dist/vendor/electron/domain/saved-view-analytics.d.ts +45 -0
- package/dist/vendor/electron/domain/saved-view-analytics.js +365 -0
- package/dist/vendor/electron/domain/saved-view-relative-date.d.ts +21 -0
- package/dist/vendor/electron/domain/saved-view-relative-date.js +153 -0
- package/dist/vendor/electron/domain/saved-views.d.ts +61 -0
- package/dist/vendor/electron/domain/saved-views.js +1120 -0
- package/dist/vendor/electron/rpc.d.ts +22 -0
- package/dist/vendor/electron/rpc.js +27 -0
- package/dist/vendor/electron/shared/ai-errors.d.ts +11 -0
- package/dist/vendor/electron/shared/ai-errors.js +107 -0
- package/dist/vendor/electron/shared/external-types.d.ts +20 -0
- package/dist/vendor/electron/shared/external-types.js +1 -0
- package/dist/vendor/electron/shared/index.d.ts +9 -0
- package/dist/vendor/electron/shared/index.js +7 -0
- package/dist/vendor/electron/shared/note-properties.d.ts +328 -0
- package/dist/vendor/electron/shared/note-properties.js +1027 -0
- package/dist/vendor/electron/shared/note-templates.d.ts +82 -0
- package/dist/vendor/electron/shared/note-templates.js +84 -0
- package/dist/vendor/electron/shared/powersync-read-models.d.ts +1716 -0
- package/dist/vendor/electron/shared/powersync-read-models.js +1 -0
- package/dist/vendor/electron/shared/remote-device-agent.d.ts +373 -0
- package/dist/vendor/electron/shared/remote-device-agent.js +191 -0
- package/dist/vendor/electron/shared/saved-views.d.ts +394 -0
- package/dist/vendor/electron/shared/saved-views.js +981 -0
- package/dist/vendor/electron/sql-utils.d.ts +5 -0
- package/dist/vendor/electron/sql-utils.js +32 -0
- package/package.json +10 -4
- package/dist/commands/savedViews/semantics.d.ts +0 -46
- package/dist/commands/savedViews/semantics.js +0 -738
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import type { ChatUIMessage } from "./external-types.js";
|
|
2
|
+
import type { ThreadRunCreateThreadRequest, ThreadRunEventStatus, ThreadRunUsageSnapshot } from "./external-types.js";
|
|
3
|
+
export declare const REMOTE_DEVICE_PROTOCOL_VERSION: 2;
|
|
4
|
+
export declare const REMOTE_DEVICE_PROTOCOL_NAME: "dinox.remote-device.v2";
|
|
5
|
+
export declare const REMOTE_DEVICE_PROTOCOL_CONTRACT: {
|
|
6
|
+
readonly version: 2;
|
|
7
|
+
readonly name: "dinox.remote-device.v2";
|
|
8
|
+
readonly messageTypes: readonly ["device.discover", "device.discovered", "device.presence", "device.info", "device.info.result", "skills.list", "skills.list.result", "workspace.list", "workspace.list.result", "workspace.file.read", "workspace.file.read.result", "query.cancel", "run.request", "run.ack", "run.status", "run.status.result", "run.cancel", "run.cancel.ack", "tool.approval.respond", "tool.approval.ack", "run.event"];
|
|
9
|
+
readonly ackCodes: readonly ["accepted", "attachment_unavailable", "busy", "delivery_unknown", "disabled", "invalid_request", "thread_not_found", "enqueue_failed"];
|
|
10
|
+
readonly subjectActions: readonly ["request", "cancel", "info", "query", "query-cancel", "approve"];
|
|
11
|
+
readonly messageFields: {
|
|
12
|
+
readonly "device.discover": "requestId,clientDeviceId";
|
|
13
|
+
readonly "device.discovered": "requestId,device";
|
|
14
|
+
readonly "device.presence": "status,sequence,emittedAt,device";
|
|
15
|
+
readonly "device.info": "requestId";
|
|
16
|
+
readonly "device.info.result": "requestId,device";
|
|
17
|
+
readonly "skills.list": "requestId,clientDeviceId,threadId;projectId,deadlineAt";
|
|
18
|
+
readonly "skills.list.result": "requestId,threadId,ok,skills,fetchedAt;error";
|
|
19
|
+
readonly "workspace.list": "requestId,clientDeviceId,threadId;parentPath,cursor,limit,deadlineAt";
|
|
20
|
+
readonly "workspace.list.result": "requestId,threadId,parentPath,ok,entries,nextCursor,truncated,fetchedAt;error";
|
|
21
|
+
readonly "workspace.file.read": "requestId,clientDeviceId,threadId,path;deadlineAt";
|
|
22
|
+
readonly "workspace.file.read.result": "requestId,threadId,path,ok,preview,size,fetchedAt;modifiedAt,error";
|
|
23
|
+
readonly "query.cancel": "requestId,clientDeviceId,queryRequestId";
|
|
24
|
+
readonly "run.request": "requestId,runId,threadId,clientDeviceId,createdAt,prompt,userMessage,assistantMessage;parentMessageId,createThread";
|
|
25
|
+
readonly "run.ack": "requestId,runId,threadId,accepted,code;status,error";
|
|
26
|
+
readonly "run.status": "requestId,runId,threadId,clientDeviceId";
|
|
27
|
+
readonly "run.status.result": "requestId,runId,threadId,found;status,updatedAt,assistant,pendingApprovals,error";
|
|
28
|
+
readonly "run.cancel": "requestId,runId,threadId,clientDeviceId";
|
|
29
|
+
readonly "run.cancel.ack": "requestId,runId,threadId,cancelled;error";
|
|
30
|
+
readonly "tool.approval.respond": "requestId,clientDeviceId,runId,threadId,approvalId,approved;reason";
|
|
31
|
+
readonly "tool.approval.ack": "requestId,runId,threadId,approvalId,accepted,code;status,pendingApprovals,error";
|
|
32
|
+
readonly "run.event": "runId,threadId,sequence,emittedAt,revision,status,assistant;pendingApprovals,usage";
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare const REMOTE_DEVICE_PRESENCE_INTERVAL_MS = 15000;
|
|
36
|
+
export declare const REMOTE_DEVICE_PRESENCE_TTL_MS = 45000;
|
|
37
|
+
export declare const REMOTE_DEVICE_REQUEST_TIMEOUT_MS = 5000;
|
|
38
|
+
export declare const REMOTE_DEVICE_MAX_EVENT_BYTES = 900000;
|
|
39
|
+
export declare const REMOTE_WORKSPACE_FILE_PREVIEW_MAX_BYTES: number;
|
|
40
|
+
export declare const REMOTE_WORKSPACE_PREVIEW_RETENTION_MS: number;
|
|
41
|
+
export type RemoteDeviceConnectionStatus = "disabled" | "signed_out" | "connecting" | "connected" | "reconnecting" | "error";
|
|
42
|
+
export interface RemoteDeviceCapabilities {
|
|
43
|
+
threadRun: true;
|
|
44
|
+
cancel: true;
|
|
45
|
+
stream: "assistant-snapshot";
|
|
46
|
+
toolApproval: "desktop";
|
|
47
|
+
remoteToolApproval?: {
|
|
48
|
+
respond: true;
|
|
49
|
+
decisions: readonly ["approve_once", "deny"];
|
|
50
|
+
recovery: "run-status";
|
|
51
|
+
};
|
|
52
|
+
skills?: {
|
|
53
|
+
list: true;
|
|
54
|
+
explicitSelection: true;
|
|
55
|
+
maxSelected: number;
|
|
56
|
+
};
|
|
57
|
+
workspace?: {
|
|
58
|
+
list: true;
|
|
59
|
+
scope: "thread";
|
|
60
|
+
filePreview: false | {
|
|
61
|
+
read: true;
|
|
62
|
+
maxBytes: number;
|
|
63
|
+
kinds: readonly ["text", "image"];
|
|
64
|
+
delivery: "signed-url";
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface RemoteDeviceInfo {
|
|
69
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
70
|
+
protocol: typeof REMOTE_DEVICE_PROTOCOL_NAME;
|
|
71
|
+
deviceId: string;
|
|
72
|
+
deviceName: string;
|
|
73
|
+
platform: string;
|
|
74
|
+
appVersion: string;
|
|
75
|
+
connectedAt: string;
|
|
76
|
+
busyThreadIds: string[];
|
|
77
|
+
capabilities: RemoteDeviceCapabilities;
|
|
78
|
+
}
|
|
79
|
+
export interface RemoteDeviceDiscoverRequest {
|
|
80
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
81
|
+
type: "device.discover";
|
|
82
|
+
requestId: string;
|
|
83
|
+
clientDeviceId: string;
|
|
84
|
+
}
|
|
85
|
+
export interface RemoteDeviceDiscoverResponse {
|
|
86
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
87
|
+
type: "device.discovered";
|
|
88
|
+
requestId: string;
|
|
89
|
+
device: RemoteDeviceInfo;
|
|
90
|
+
}
|
|
91
|
+
export interface RemoteDevicePresenceEvent {
|
|
92
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
93
|
+
type: "device.presence";
|
|
94
|
+
status: "online" | "offline";
|
|
95
|
+
sequence: number;
|
|
96
|
+
emittedAt: string;
|
|
97
|
+
device: RemoteDeviceInfo;
|
|
98
|
+
}
|
|
99
|
+
export interface RemoteDeviceInfoRequest {
|
|
100
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
101
|
+
type: "device.info";
|
|
102
|
+
requestId: string;
|
|
103
|
+
}
|
|
104
|
+
export interface RemoteDeviceInfoResponse {
|
|
105
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
106
|
+
type: "device.info.result";
|
|
107
|
+
requestId: string;
|
|
108
|
+
device: RemoteDeviceInfo;
|
|
109
|
+
}
|
|
110
|
+
export type RemoteDeviceQueryErrorCode = "invalid_request" | "thread_not_found" | "unsupported" | "file_too_large" | "not_previewable" | "query_failed";
|
|
111
|
+
export interface RemoteDeviceQueryError {
|
|
112
|
+
code: RemoteDeviceQueryErrorCode;
|
|
113
|
+
message: string;
|
|
114
|
+
}
|
|
115
|
+
export interface RemoteDeviceSkillSummary {
|
|
116
|
+
skillKey: string;
|
|
117
|
+
name: string;
|
|
118
|
+
description: string;
|
|
119
|
+
}
|
|
120
|
+
export interface RemoteDeviceSkillsListRequest {
|
|
121
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
122
|
+
type: "skills.list";
|
|
123
|
+
requestId: string;
|
|
124
|
+
clientDeviceId: string;
|
|
125
|
+
threadId: string;
|
|
126
|
+
projectId?: string | null;
|
|
127
|
+
deadlineAt?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface RemoteDeviceSkillsListResponse {
|
|
130
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
131
|
+
type: "skills.list.result";
|
|
132
|
+
requestId: string;
|
|
133
|
+
threadId: string;
|
|
134
|
+
ok: boolean;
|
|
135
|
+
skills: RemoteDeviceSkillSummary[];
|
|
136
|
+
fetchedAt: string;
|
|
137
|
+
error?: RemoteDeviceQueryError;
|
|
138
|
+
}
|
|
139
|
+
export type RemoteWorkspaceEntryKind = "directory" | "file" | "symlink";
|
|
140
|
+
export interface RemoteWorkspaceEntry {
|
|
141
|
+
path: string;
|
|
142
|
+
name: string;
|
|
143
|
+
kind: RemoteWorkspaceEntryKind;
|
|
144
|
+
hasChildren: boolean;
|
|
145
|
+
size?: number;
|
|
146
|
+
modifiedAt?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface RemoteDeviceWorkspaceListRequest {
|
|
149
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
150
|
+
type: "workspace.list";
|
|
151
|
+
requestId: string;
|
|
152
|
+
clientDeviceId: string;
|
|
153
|
+
threadId: string;
|
|
154
|
+
parentPath?: string;
|
|
155
|
+
cursor?: string | null;
|
|
156
|
+
limit?: number;
|
|
157
|
+
deadlineAt?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface RemoteDeviceWorkspaceListResponse {
|
|
160
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
161
|
+
type: "workspace.list.result";
|
|
162
|
+
requestId: string;
|
|
163
|
+
threadId: string;
|
|
164
|
+
parentPath: string;
|
|
165
|
+
ok: boolean;
|
|
166
|
+
entries: RemoteWorkspaceEntry[];
|
|
167
|
+
nextCursor: string | null;
|
|
168
|
+
truncated: boolean;
|
|
169
|
+
fetchedAt: string;
|
|
170
|
+
error?: RemoteDeviceQueryError;
|
|
171
|
+
}
|
|
172
|
+
export interface RemoteDeviceWorkspaceFileReadRequest {
|
|
173
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
174
|
+
type: "workspace.file.read";
|
|
175
|
+
requestId: string;
|
|
176
|
+
clientDeviceId: string;
|
|
177
|
+
threadId: string;
|
|
178
|
+
path: string;
|
|
179
|
+
deadlineAt?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface RemoteDeviceQueryCancelRequest {
|
|
182
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
183
|
+
type: "query.cancel";
|
|
184
|
+
requestId: string;
|
|
185
|
+
clientDeviceId: string;
|
|
186
|
+
queryRequestId: string;
|
|
187
|
+
}
|
|
188
|
+
export type RemoteWorkspaceImageMediaType = "image/png" | "image/jpeg" | "image/gif" | "image/webp";
|
|
189
|
+
export type RemoteWorkspaceFilePreview = {
|
|
190
|
+
kind: "text";
|
|
191
|
+
mediaType: "text/plain";
|
|
192
|
+
delivery: "signed-url";
|
|
193
|
+
downloadUrl: string;
|
|
194
|
+
} | {
|
|
195
|
+
kind: "image";
|
|
196
|
+
mediaType: RemoteWorkspaceImageMediaType;
|
|
197
|
+
delivery: "signed-url";
|
|
198
|
+
downloadUrl: string;
|
|
199
|
+
};
|
|
200
|
+
export interface RemoteDeviceWorkspaceFileReadResponse {
|
|
201
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
202
|
+
type: "workspace.file.read.result";
|
|
203
|
+
requestId: string;
|
|
204
|
+
threadId: string;
|
|
205
|
+
path: string;
|
|
206
|
+
ok: boolean;
|
|
207
|
+
preview: RemoteWorkspaceFilePreview | null;
|
|
208
|
+
size: number | null;
|
|
209
|
+
modifiedAt?: string;
|
|
210
|
+
fetchedAt: string;
|
|
211
|
+
error?: RemoteDeviceQueryError;
|
|
212
|
+
}
|
|
213
|
+
export type RemoteDeviceQueryRequest = RemoteDeviceSkillsListRequest | RemoteDeviceWorkspaceListRequest | RemoteDeviceWorkspaceFileReadRequest;
|
|
214
|
+
export type RemoteDeviceQueryResponse = RemoteDeviceSkillsListResponse | RemoteDeviceWorkspaceListResponse | RemoteDeviceWorkspaceFileReadResponse;
|
|
215
|
+
export interface RemoteDeviceRunRequest {
|
|
216
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
217
|
+
type: "run.request";
|
|
218
|
+
requestId: string;
|
|
219
|
+
runId: string;
|
|
220
|
+
threadId: string;
|
|
221
|
+
clientDeviceId: string;
|
|
222
|
+
createdAt: string;
|
|
223
|
+
prompt: string;
|
|
224
|
+
userMessage: ChatUIMessage;
|
|
225
|
+
assistantMessage: ChatUIMessage;
|
|
226
|
+
parentMessageId?: string | null;
|
|
227
|
+
createThread?: ThreadRunCreateThreadRequest | null;
|
|
228
|
+
}
|
|
229
|
+
export type RemoteDeviceRunAckCode = "accepted" | "attachment_unavailable" | "busy" | "delivery_unknown" | "disabled" | "invalid_request" | "thread_not_found" | "enqueue_failed";
|
|
230
|
+
export interface RemoteDeviceRunAck {
|
|
231
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
232
|
+
type: "run.ack";
|
|
233
|
+
requestId: string;
|
|
234
|
+
runId: string;
|
|
235
|
+
threadId: string;
|
|
236
|
+
accepted: boolean;
|
|
237
|
+
code: RemoteDeviceRunAckCode;
|
|
238
|
+
threadDisposition?: RemoteDeviceThreadDisposition;
|
|
239
|
+
status?: ThreadRunEventStatus;
|
|
240
|
+
error?: string;
|
|
241
|
+
}
|
|
242
|
+
export type RemoteDeviceThreadDisposition = "created_desktop_local" | "already_present_desktop_local";
|
|
243
|
+
export interface RemoteDeviceRunStatusRequest {
|
|
244
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
245
|
+
type: "run.status";
|
|
246
|
+
requestId: string;
|
|
247
|
+
runId: string;
|
|
248
|
+
threadId: string;
|
|
249
|
+
clientDeviceId: string;
|
|
250
|
+
}
|
|
251
|
+
export interface RemoteDeviceRunStatusResponse {
|
|
252
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
253
|
+
type: "run.status.result";
|
|
254
|
+
requestId: string;
|
|
255
|
+
runId: string;
|
|
256
|
+
threadId: string;
|
|
257
|
+
found: boolean;
|
|
258
|
+
status?: ThreadRunEventStatus;
|
|
259
|
+
updatedAt?: string;
|
|
260
|
+
assistant?: RemoteDeviceAssistantSnapshot;
|
|
261
|
+
pendingApprovals?: RemoteToolApprovalPrompt[];
|
|
262
|
+
error?: string;
|
|
263
|
+
}
|
|
264
|
+
export interface RemoteToolApprovalPrompt {
|
|
265
|
+
approvalId: string;
|
|
266
|
+
runId: string;
|
|
267
|
+
threadId: string;
|
|
268
|
+
toolCallId: string;
|
|
269
|
+
toolName: string;
|
|
270
|
+
inputPreview: string;
|
|
271
|
+
requestedAt: string;
|
|
272
|
+
expiresAt: string;
|
|
273
|
+
}
|
|
274
|
+
export interface RemoteDeviceToolApprovalRequest {
|
|
275
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
276
|
+
type: "tool.approval.respond";
|
|
277
|
+
requestId: string;
|
|
278
|
+
clientDeviceId: string;
|
|
279
|
+
runId: string;
|
|
280
|
+
threadId: string;
|
|
281
|
+
approvalId: string;
|
|
282
|
+
approved: boolean;
|
|
283
|
+
reason?: string;
|
|
284
|
+
}
|
|
285
|
+
export type RemoteDeviceToolApprovalAckCode = "applied" | "already_applied" | "invalid_request" | "stale" | "failed";
|
|
286
|
+
export interface RemoteDeviceToolApprovalAck {
|
|
287
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
288
|
+
type: "tool.approval.ack";
|
|
289
|
+
requestId: string;
|
|
290
|
+
runId: string;
|
|
291
|
+
threadId: string;
|
|
292
|
+
approvalId: string;
|
|
293
|
+
accepted: boolean;
|
|
294
|
+
code: RemoteDeviceToolApprovalAckCode;
|
|
295
|
+
status?: ThreadRunEventStatus;
|
|
296
|
+
pendingApprovals?: RemoteToolApprovalPrompt[];
|
|
297
|
+
error?: string;
|
|
298
|
+
}
|
|
299
|
+
export interface RemoteDeviceCancelRequest {
|
|
300
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
301
|
+
type: "run.cancel";
|
|
302
|
+
requestId: string;
|
|
303
|
+
runId: string;
|
|
304
|
+
threadId: string;
|
|
305
|
+
clientDeviceId: string;
|
|
306
|
+
}
|
|
307
|
+
export interface RemoteDeviceCancelAck {
|
|
308
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
309
|
+
type: "run.cancel.ack";
|
|
310
|
+
requestId: string;
|
|
311
|
+
runId: string;
|
|
312
|
+
threadId: string;
|
|
313
|
+
cancelled: boolean;
|
|
314
|
+
error?: string;
|
|
315
|
+
}
|
|
316
|
+
export interface RemoteDeviceAssistantSnapshot {
|
|
317
|
+
message: ChatUIMessage;
|
|
318
|
+
truncated?: boolean;
|
|
319
|
+
}
|
|
320
|
+
export interface RemoteDeviceRunStreamEvent {
|
|
321
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
322
|
+
type: "run.event";
|
|
323
|
+
runId: string;
|
|
324
|
+
threadId: string;
|
|
325
|
+
sequence: number;
|
|
326
|
+
emittedAt: string;
|
|
327
|
+
revision: number;
|
|
328
|
+
status: ThreadRunEventStatus;
|
|
329
|
+
assistant: RemoteDeviceAssistantSnapshot;
|
|
330
|
+
pendingApprovals?: RemoteToolApprovalPrompt[];
|
|
331
|
+
usage?: ThreadRunUsageSnapshot | null;
|
|
332
|
+
}
|
|
333
|
+
export interface NatsDeviceCredentials {
|
|
334
|
+
account: string;
|
|
335
|
+
credentials: string;
|
|
336
|
+
deviceId: string;
|
|
337
|
+
expiresAt: string;
|
|
338
|
+
inboxPrefix: string;
|
|
339
|
+
protocolVersion: number;
|
|
340
|
+
role: "mobile" | "desktop";
|
|
341
|
+
url: string;
|
|
342
|
+
userNo: string;
|
|
343
|
+
}
|
|
344
|
+
export interface NatsDeviceCredentialsEnvelope {
|
|
345
|
+
code: string;
|
|
346
|
+
msg?: string;
|
|
347
|
+
data?: NatsDeviceCredentials;
|
|
348
|
+
}
|
|
349
|
+
export interface RemoteDeviceHostConfig {
|
|
350
|
+
enabled: boolean;
|
|
351
|
+
deviceName: string;
|
|
352
|
+
}
|
|
353
|
+
export interface RemoteDeviceHostStatus {
|
|
354
|
+
config: RemoteDeviceHostConfig;
|
|
355
|
+
deviceId: string;
|
|
356
|
+
connectionStatus: RemoteDeviceConnectionStatus;
|
|
357
|
+
connectedAt: string | null;
|
|
358
|
+
credentialsExpireAt: string | null;
|
|
359
|
+
lastError: string | null;
|
|
360
|
+
}
|
|
361
|
+
export interface RemoteDeviceHostConfigUpdate {
|
|
362
|
+
enabled?: boolean;
|
|
363
|
+
deviceName?: string;
|
|
364
|
+
}
|
|
365
|
+
export declare function normalizeRemoteSubjectToken(value: string, field: "userNo" | "threadId" | "runId" | "deviceId"): string;
|
|
366
|
+
export declare function remoteDiscoverSubject(userNo: string): string;
|
|
367
|
+
export declare function remotePresenceSubject(userNo: string, deviceId: string): string;
|
|
368
|
+
export declare function remoteDeviceSubject(userNo: string, deviceId: string, action: "request" | "cancel" | "info" | "query" | "query-cancel" | "approve"): string;
|
|
369
|
+
export declare function remoteRunStreamSubject(userNo: string, threadId: string, runId: string): string;
|
|
370
|
+
export declare function isRemoteProtocolMessage(value: unknown): value is {
|
|
371
|
+
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
|
372
|
+
type: string;
|
|
373
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
export const REMOTE_DEVICE_PROTOCOL_VERSION = 2;
|
|
2
|
+
export const REMOTE_DEVICE_PROTOCOL_NAME = "dinox.remote-device.v2";
|
|
3
|
+
export const REMOTE_DEVICE_PROTOCOL_CONTRACT = {
|
|
4
|
+
version: REMOTE_DEVICE_PROTOCOL_VERSION,
|
|
5
|
+
name: REMOTE_DEVICE_PROTOCOL_NAME,
|
|
6
|
+
messageTypes: [
|
|
7
|
+
"device.discover",
|
|
8
|
+
"device.discovered",
|
|
9
|
+
"device.presence",
|
|
10
|
+
"device.info",
|
|
11
|
+
"device.info.result",
|
|
12
|
+
"skills.list",
|
|
13
|
+
"skills.list.result",
|
|
14
|
+
"workspace.list",
|
|
15
|
+
"workspace.list.result",
|
|
16
|
+
"workspace.file.read",
|
|
17
|
+
"workspace.file.read.result",
|
|
18
|
+
"query.cancel",
|
|
19
|
+
"run.request",
|
|
20
|
+
"run.ack",
|
|
21
|
+
"run.status",
|
|
22
|
+
"run.status.result",
|
|
23
|
+
"run.cancel",
|
|
24
|
+
"run.cancel.ack",
|
|
25
|
+
"tool.approval.respond",
|
|
26
|
+
"tool.approval.ack",
|
|
27
|
+
"run.event",
|
|
28
|
+
],
|
|
29
|
+
ackCodes: [
|
|
30
|
+
"accepted",
|
|
31
|
+
"attachment_unavailable",
|
|
32
|
+
"busy",
|
|
33
|
+
"delivery_unknown",
|
|
34
|
+
"disabled",
|
|
35
|
+
"invalid_request",
|
|
36
|
+
"thread_not_found",
|
|
37
|
+
"enqueue_failed",
|
|
38
|
+
],
|
|
39
|
+
subjectActions: ["request", "cancel", "info", "query", "query-cancel", "approve"],
|
|
40
|
+
messageFields: {
|
|
41
|
+
"device.discover": "requestId,clientDeviceId",
|
|
42
|
+
"device.discovered": "requestId,device",
|
|
43
|
+
"device.presence": "status,sequence,emittedAt,device",
|
|
44
|
+
"device.info": "requestId",
|
|
45
|
+
"device.info.result": "requestId,device",
|
|
46
|
+
"skills.list": "requestId,clientDeviceId,threadId;projectId,deadlineAt",
|
|
47
|
+
"skills.list.result": "requestId,threadId,ok,skills,fetchedAt;error",
|
|
48
|
+
"workspace.list": "requestId,clientDeviceId,threadId;parentPath,cursor,limit,deadlineAt",
|
|
49
|
+
"workspace.list.result": "requestId,threadId,parentPath,ok,entries,nextCursor,truncated,fetchedAt;error",
|
|
50
|
+
"workspace.file.read": "requestId,clientDeviceId,threadId,path;deadlineAt",
|
|
51
|
+
"workspace.file.read.result": "requestId,threadId,path,ok,preview,size,fetchedAt;modifiedAt,error",
|
|
52
|
+
"query.cancel": "requestId,clientDeviceId,queryRequestId",
|
|
53
|
+
"run.request": "requestId,runId,threadId,clientDeviceId,createdAt,prompt,userMessage,assistantMessage;parentMessageId,createThread",
|
|
54
|
+
"run.ack": "requestId,runId,threadId,accepted,code;status,error",
|
|
55
|
+
"run.status": "requestId,runId,threadId,clientDeviceId",
|
|
56
|
+
"run.status.result": "requestId,runId,threadId,found;status,updatedAt,assistant,pendingApprovals,error",
|
|
57
|
+
"run.cancel": "requestId,runId,threadId,clientDeviceId",
|
|
58
|
+
"run.cancel.ack": "requestId,runId,threadId,cancelled;error",
|
|
59
|
+
"tool.approval.respond": "requestId,clientDeviceId,runId,threadId,approvalId,approved;reason",
|
|
60
|
+
"tool.approval.ack": "requestId,runId,threadId,approvalId,accepted,code;status,pendingApprovals,error",
|
|
61
|
+
"run.event": "runId,threadId,sequence,emittedAt,revision,status,assistant;pendingApprovals,usage",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export const REMOTE_DEVICE_PRESENCE_INTERVAL_MS = 15_000;
|
|
65
|
+
export const REMOTE_DEVICE_PRESENCE_TTL_MS = 45_000;
|
|
66
|
+
export const REMOTE_DEVICE_REQUEST_TIMEOUT_MS = 5_000;
|
|
67
|
+
export const REMOTE_DEVICE_MAX_EVENT_BYTES = 900_000;
|
|
68
|
+
export const REMOTE_WORKSPACE_FILE_PREVIEW_MAX_BYTES = 5 * 1024 * 1024;
|
|
69
|
+
export const REMOTE_WORKSPACE_PREVIEW_RETENTION_MS = 24 * 60 * 60_000;
|
|
70
|
+
const SUBJECT_TOKEN_PATTERN = /^[a-z0-9][a-z0-9_-]{0,127}$/;
|
|
71
|
+
const DEVICE_TOKEN_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
72
|
+
export function normalizeRemoteSubjectToken(value, field) {
|
|
73
|
+
const normalized = value.trim().toLowerCase();
|
|
74
|
+
const pattern = field === "deviceId" ? DEVICE_TOKEN_PATTERN : SUBJECT_TOKEN_PATTERN;
|
|
75
|
+
if (!pattern.test(normalized)) {
|
|
76
|
+
throw new Error(`${field} 不是合法的 NATS subject token`);
|
|
77
|
+
}
|
|
78
|
+
return normalized;
|
|
79
|
+
}
|
|
80
|
+
export function remoteDiscoverSubject(userNo) {
|
|
81
|
+
return `dinox.${normalizeRemoteSubjectToken(userNo, "userNo")}.discover`;
|
|
82
|
+
}
|
|
83
|
+
export function remotePresenceSubject(userNo, deviceId) {
|
|
84
|
+
return `dinox.${normalizeRemoteSubjectToken(userNo, "userNo")}.presence.${normalizeRemoteSubjectToken(deviceId, "deviceId")}`;
|
|
85
|
+
}
|
|
86
|
+
export function remoteDeviceSubject(userNo, deviceId, action) {
|
|
87
|
+
return `dinox.${normalizeRemoteSubjectToken(userNo, "userNo")}.device.${normalizeRemoteSubjectToken(deviceId, "deviceId")}.${action}`;
|
|
88
|
+
}
|
|
89
|
+
export function remoteRunStreamSubject(userNo, threadId, runId) {
|
|
90
|
+
return `dinox.${normalizeRemoteSubjectToken(userNo, "userNo")}.thread.${normalizeRemoteSubjectToken(threadId, "threadId")}.stream.${normalizeRemoteSubjectToken(runId, "runId")}`;
|
|
91
|
+
}
|
|
92
|
+
export function isRemoteProtocolMessage(value) {
|
|
93
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
94
|
+
return false;
|
|
95
|
+
const record = value;
|
|
96
|
+
if (record.protocolVersion !== REMOTE_DEVICE_PROTOCOL_VERSION ||
|
|
97
|
+
typeof record.type !== "string" ||
|
|
98
|
+
!REMOTE_DEVICE_PROTOCOL_CONTRACT.messageTypes.includes(record.type)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const descriptor = REMOTE_DEVICE_PROTOCOL_CONTRACT.messageFields[record.type];
|
|
102
|
+
const [required = ""] = descriptor.split(";");
|
|
103
|
+
return required
|
|
104
|
+
.split(",")
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.every((field) => Object.prototype.hasOwnProperty.call(record, field) && record[field] !== undefined) && hasValidRemoteFieldShapes(record);
|
|
107
|
+
}
|
|
108
|
+
function hasValidRemoteFieldShapes(record) {
|
|
109
|
+
for (const field of [
|
|
110
|
+
"requestId",
|
|
111
|
+
"runId",
|
|
112
|
+
"threadId",
|
|
113
|
+
"clientDeviceId",
|
|
114
|
+
"queryRequestId",
|
|
115
|
+
"approvalId",
|
|
116
|
+
]) {
|
|
117
|
+
if (field in record && (typeof record[field] !== "string" || !record[field]))
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
for (const field of ["found", "ok", "accepted", "cancelled", "approved", "truncated"]) {
|
|
121
|
+
if (field in record && typeof record[field] !== "boolean")
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
for (const field of ["sequence", "revision", "size"]) {
|
|
125
|
+
if (field in record &&
|
|
126
|
+
record[field] !== null &&
|
|
127
|
+
(typeof record[field] !== "number" || !Number.isFinite(record[field]))) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const field of ["skills", "entries", "busyThreadIds", "pendingApprovals"]) {
|
|
132
|
+
if (field in record && !Array.isArray(record[field]))
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if ("device" in record && !isRemoteDeviceInfoShape(record.device))
|
|
136
|
+
return false;
|
|
137
|
+
if ("assistant" in record && !isRemoteAssistantSnapshotShape(record.assistant))
|
|
138
|
+
return false;
|
|
139
|
+
if ("status" in record &&
|
|
140
|
+
record.type !== "device.presence" &&
|
|
141
|
+
!isRemoteRunStatusValue(record.status)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (record.type === "device.presence" &&
|
|
145
|
+
record.status !== "online" &&
|
|
146
|
+
record.status !== "offline") {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
function isRemoteDeviceInfoShape(value) {
|
|
152
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
153
|
+
return false;
|
|
154
|
+
const device = value;
|
|
155
|
+
return (device.protocolVersion === REMOTE_DEVICE_PROTOCOL_VERSION &&
|
|
156
|
+
device.protocol === REMOTE_DEVICE_PROTOCOL_NAME &&
|
|
157
|
+
typeof device.deviceId === "string" &&
|
|
158
|
+
Boolean(device.deviceId) &&
|
|
159
|
+
typeof device.deviceName === "string" &&
|
|
160
|
+
Array.isArray(device.busyThreadIds) &&
|
|
161
|
+
Boolean(device.capabilities) &&
|
|
162
|
+
typeof device.capabilities === "object");
|
|
163
|
+
}
|
|
164
|
+
function isRemoteAssistantSnapshotShape(value) {
|
|
165
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
166
|
+
return false;
|
|
167
|
+
const snapshot = value;
|
|
168
|
+
const message = snapshot.message;
|
|
169
|
+
if (!message || typeof message !== "object" || Array.isArray(message))
|
|
170
|
+
return false;
|
|
171
|
+
const candidate = message;
|
|
172
|
+
return (typeof candidate.id === "string" &&
|
|
173
|
+
Boolean(candidate.id) &&
|
|
174
|
+
candidate.role === "assistant" &&
|
|
175
|
+
Array.isArray(candidate.parts) &&
|
|
176
|
+
(snapshot.truncated === undefined || typeof snapshot.truncated === "boolean"));
|
|
177
|
+
}
|
|
178
|
+
function isRemoteRunStatusValue(value) {
|
|
179
|
+
return (typeof value === "string" &&
|
|
180
|
+
[
|
|
181
|
+
"queued",
|
|
182
|
+
"running",
|
|
183
|
+
"waiting_approval",
|
|
184
|
+
"finalizing",
|
|
185
|
+
"succeeded",
|
|
186
|
+
"failed",
|
|
187
|
+
"cancelled",
|
|
188
|
+
"interrupted",
|
|
189
|
+
"expired",
|
|
190
|
+
].includes(value));
|
|
191
|
+
}
|