@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,26 @@
|
|
|
1
|
+
import type { AbstractPowerSyncDatabase } from '@powersync/common';
|
|
2
|
+
import { type DeviceHostStatus } from './deviceHost.js';
|
|
3
|
+
type Logger = (message: string, details?: Record<string, unknown>) => void;
|
|
4
|
+
export type GatewayServiceDeps = {
|
|
5
|
+
db: AbstractPowerSyncDatabase;
|
|
6
|
+
userId: string;
|
|
7
|
+
authorization: string;
|
|
8
|
+
log?: Logger;
|
|
9
|
+
credentialsUrl?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Runs every enabled gateway inside the daemon: the daemon owns the PowerSync
|
|
13
|
+
* database, so gateway writes share its connection and upload queue.
|
|
14
|
+
*/
|
|
15
|
+
export declare class GatewayService {
|
|
16
|
+
private readonly deps;
|
|
17
|
+
private hosts;
|
|
18
|
+
private readonly log;
|
|
19
|
+
constructor(deps: GatewayServiceDeps);
|
|
20
|
+
start(): Promise<void>;
|
|
21
|
+
stop(): Promise<void>;
|
|
22
|
+
/** Re-reads the account's gateways (after add/remove) without restarting the daemon. */
|
|
23
|
+
reload(): Promise<DeviceHostStatus[]>;
|
|
24
|
+
status(): DeviceHostStatus[];
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { getPackageVersion } from '../utils/version.js';
|
|
3
|
+
import { createGatewayAdapter } from './adapters/index.js';
|
|
4
|
+
import { getMachineId, loadGateways } from './config.js';
|
|
5
|
+
import { GatewayDeviceHost } from './deviceHost.js';
|
|
6
|
+
import { interruptOrphanedRuns, retireRemovedRobots, upsertRobot } from './threadStore.js';
|
|
7
|
+
const defaultLog = (message, details) => {
|
|
8
|
+
process.stderr.write(`[dinox-gateway] ${message}${details ? ` ${JSON.stringify(details)}` : ''}\n`);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Runs every enabled gateway inside the daemon: the daemon owns the PowerSync
|
|
12
|
+
* database, so gateway writes share its connection and upload queue.
|
|
13
|
+
*/
|
|
14
|
+
export class GatewayService {
|
|
15
|
+
deps;
|
|
16
|
+
hosts = [];
|
|
17
|
+
log;
|
|
18
|
+
constructor(deps) {
|
|
19
|
+
this.deps = deps;
|
|
20
|
+
this.log = deps.log ?? defaultLog;
|
|
21
|
+
}
|
|
22
|
+
async start() {
|
|
23
|
+
const configured = await loadGateways(this.deps.userId);
|
|
24
|
+
const machineId = await getMachineId();
|
|
25
|
+
// Reconcile before anything else, also when the last gateway was removed.
|
|
26
|
+
const retired = await retireRemovedRobots(this.deps.db, {
|
|
27
|
+
userId: this.deps.userId,
|
|
28
|
+
machineId,
|
|
29
|
+
keepIds: configured.map((gateway) => gateway.id),
|
|
30
|
+
}).catch((error) => {
|
|
31
|
+
this.log('retire removed robots failed', { error: String(error) });
|
|
32
|
+
return [];
|
|
33
|
+
});
|
|
34
|
+
if (retired.length > 0)
|
|
35
|
+
this.log('retired robots of removed gateways', { count: retired.length });
|
|
36
|
+
const gateways = configured.filter((gateway) => gateway.enabled);
|
|
37
|
+
if (gateways.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
const interrupted = await interruptOrphanedRuns(this.deps.db, this.deps.userId);
|
|
40
|
+
if (interrupted > 0)
|
|
41
|
+
this.log('marked runs from a previous host as interrupted', { count: interrupted });
|
|
42
|
+
for (const gateway of gateways) {
|
|
43
|
+
await upsertRobot(this.deps.db, {
|
|
44
|
+
id: gateway.id,
|
|
45
|
+
userId: this.deps.userId,
|
|
46
|
+
name: gateway.name,
|
|
47
|
+
deviceId: gateway.deviceId,
|
|
48
|
+
agentType: gateway.kind,
|
|
49
|
+
cwd: gateway.cwd ?? null,
|
|
50
|
+
deviceName: os.hostname(),
|
|
51
|
+
machineId,
|
|
52
|
+
...(gateway.agentId ? { agentId: gateway.agentId } : {}),
|
|
53
|
+
}).catch((error) => this.log('register robot failed', { gateway: gateway.name, error: String(error) }));
|
|
54
|
+
const host = new GatewayDeviceHost({
|
|
55
|
+
gateway,
|
|
56
|
+
db: this.deps.db,
|
|
57
|
+
userId: this.deps.userId,
|
|
58
|
+
authorization: this.deps.authorization,
|
|
59
|
+
adapter: createGatewayAdapter(gateway, (message, details) => this.log(message, { gateway: gateway.name, ...details })),
|
|
60
|
+
appVersion: getPackageVersion(),
|
|
61
|
+
log: (message, details) => this.log(message, { gateway: gateway.name, ...details }),
|
|
62
|
+
credentialsUrl: this.deps.credentialsUrl,
|
|
63
|
+
});
|
|
64
|
+
host.start();
|
|
65
|
+
this.hosts.push(host);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async stop() {
|
|
69
|
+
const hosts = this.hosts;
|
|
70
|
+
this.hosts = [];
|
|
71
|
+
await Promise.allSettled(hosts.map((host) => host.stop()));
|
|
72
|
+
}
|
|
73
|
+
/** Re-reads the account's gateways (after add/remove) without restarting the daemon. */
|
|
74
|
+
async reload() {
|
|
75
|
+
await this.stop();
|
|
76
|
+
await this.start();
|
|
77
|
+
return this.status();
|
|
78
|
+
}
|
|
79
|
+
status() {
|
|
80
|
+
return this.hosts.map((host) => host.status());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ChatUIMessage, ThreadRunEventStatus } from '../vendor/electron/shared/external-types.js';
|
|
2
|
+
import { type RemoteDeviceRunStreamEvent, type RemoteToolApprovalPrompt } from '../vendor/electron/shared/remote-device-agent.js';
|
|
3
|
+
export type RunSnapshot = {
|
|
4
|
+
revision: number;
|
|
5
|
+
status: ThreadRunEventStatus;
|
|
6
|
+
assistant: ChatUIMessage;
|
|
7
|
+
pendingApprovals: RemoteToolApprovalPrompt[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Keeps an event under the NATS payload budget: drop parts (the snapshot is
|
|
11
|
+
* self-correcting and `run.status` recovers the rest), then drop extras.
|
|
12
|
+
*/
|
|
13
|
+
export declare function boundRunEvent(event: RemoteDeviceRunStreamEvent): RemoteDeviceRunStreamEvent;
|
|
14
|
+
/**
|
|
15
|
+
* One per run. Streaming snapshots are coalesced to the latest per 100ms;
|
|
16
|
+
* approval and terminal states go out immediately (and supersede a pending one).
|
|
17
|
+
*/
|
|
18
|
+
export declare class RunStreamPublisher {
|
|
19
|
+
private readonly ids;
|
|
20
|
+
private readonly publish;
|
|
21
|
+
private sequence;
|
|
22
|
+
private pending;
|
|
23
|
+
private timer;
|
|
24
|
+
private disposed;
|
|
25
|
+
constructor(ids: {
|
|
26
|
+
runId: string;
|
|
27
|
+
threadId: string;
|
|
28
|
+
}, publish: (event: RemoteDeviceRunStreamEvent) => void);
|
|
29
|
+
push(snapshot: RunSnapshot): void;
|
|
30
|
+
dispose(): void;
|
|
31
|
+
private clearTimer;
|
|
32
|
+
private emit;
|
|
33
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { REMOTE_DEVICE_MAX_EVENT_BYTES, REMOTE_DEVICE_PROTOCOL_VERSION, } from '../vendor/electron/shared/remote-device-agent.js';
|
|
2
|
+
import { TERMINAL_RUN_STATUSES } from './threadStore.js';
|
|
3
|
+
const COALESCE_MS = 100;
|
|
4
|
+
const MAX_APPROVALS = 32;
|
|
5
|
+
function byteLength(value) {
|
|
6
|
+
return Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Keeps an event under the NATS payload budget: drop parts (the snapshot is
|
|
10
|
+
* self-correcting and `run.status` recovers the rest), then drop extras.
|
|
11
|
+
*/
|
|
12
|
+
export function boundRunEvent(event) {
|
|
13
|
+
if (byteLength(event) <= REMOTE_DEVICE_MAX_EVENT_BYTES)
|
|
14
|
+
return event;
|
|
15
|
+
const metadata = event.assistant.message.metadata ?? {};
|
|
16
|
+
const stripped = {
|
|
17
|
+
...event,
|
|
18
|
+
assistant: {
|
|
19
|
+
message: {
|
|
20
|
+
...event.assistant.message,
|
|
21
|
+
parts: [],
|
|
22
|
+
metadata: { status: metadata.status, runId: metadata.runId },
|
|
23
|
+
},
|
|
24
|
+
truncated: true,
|
|
25
|
+
},
|
|
26
|
+
pendingApprovals: event.pendingApprovals?.slice(0, MAX_APPROVALS),
|
|
27
|
+
};
|
|
28
|
+
if (byteLength(stripped) <= REMOTE_DEVICE_MAX_EVENT_BYTES)
|
|
29
|
+
return stripped;
|
|
30
|
+
const minimal = { ...stripped, pendingApprovals: [], usage: null };
|
|
31
|
+
if (byteLength(minimal) <= REMOTE_DEVICE_MAX_EVENT_BYTES)
|
|
32
|
+
return minimal;
|
|
33
|
+
throw new Error('run.event exceeds the remote-device payload limit');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One per run. Streaming snapshots are coalesced to the latest per 100ms;
|
|
37
|
+
* approval and terminal states go out immediately (and supersede a pending one).
|
|
38
|
+
*/
|
|
39
|
+
export class RunStreamPublisher {
|
|
40
|
+
ids;
|
|
41
|
+
publish;
|
|
42
|
+
sequence = 0;
|
|
43
|
+
pending = null;
|
|
44
|
+
timer = null;
|
|
45
|
+
disposed = false;
|
|
46
|
+
constructor(ids, publish) {
|
|
47
|
+
this.ids = ids;
|
|
48
|
+
this.publish = publish;
|
|
49
|
+
}
|
|
50
|
+
push(snapshot) {
|
|
51
|
+
if (this.disposed)
|
|
52
|
+
return;
|
|
53
|
+
if (TERMINAL_RUN_STATUSES.has(snapshot.status) || snapshot.status === 'waiting_approval') {
|
|
54
|
+
this.clearTimer();
|
|
55
|
+
this.pending = null;
|
|
56
|
+
this.emit(snapshot);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.pending = snapshot;
|
|
60
|
+
this.timer ??= setTimeout(() => {
|
|
61
|
+
this.timer = null;
|
|
62
|
+
const latest = this.pending;
|
|
63
|
+
this.pending = null;
|
|
64
|
+
if (latest)
|
|
65
|
+
this.emit(latest);
|
|
66
|
+
}, COALESCE_MS);
|
|
67
|
+
}
|
|
68
|
+
dispose() {
|
|
69
|
+
this.disposed = true;
|
|
70
|
+
this.clearTimer();
|
|
71
|
+
this.pending = null;
|
|
72
|
+
}
|
|
73
|
+
clearTimer() {
|
|
74
|
+
if (this.timer)
|
|
75
|
+
clearTimeout(this.timer);
|
|
76
|
+
this.timer = null;
|
|
77
|
+
}
|
|
78
|
+
emit(snapshot) {
|
|
79
|
+
this.sequence += 1;
|
|
80
|
+
this.publish(boundRunEvent({
|
|
81
|
+
protocolVersion: REMOTE_DEVICE_PROTOCOL_VERSION,
|
|
82
|
+
type: 'run.event',
|
|
83
|
+
runId: this.ids.runId,
|
|
84
|
+
threadId: this.ids.threadId,
|
|
85
|
+
sequence: this.sequence,
|
|
86
|
+
emittedAt: new Date().toISOString(),
|
|
87
|
+
revision: snapshot.revision,
|
|
88
|
+
status: snapshot.status,
|
|
89
|
+
assistant: { message: snapshot.assistant },
|
|
90
|
+
pendingApprovals: snapshot.pendingApprovals,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { AbstractPowerSyncDatabase } from '@powersync/common';
|
|
2
|
+
import type { ChatUIMessage, ThreadRunCreateThreadRequest, ThreadRunEventStatus } from '../vendor/electron/shared/external-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Persistence for gateway runs, written exactly like Dinox desktop's remote host
|
|
5
|
+
* (dinox-electron ThreadRunQueueService / ThreadRunCoordinatorHelpers) so every
|
|
6
|
+
* client reads identical rows:
|
|
7
|
+
* - the user message is written when the run is accepted;
|
|
8
|
+
* - live progress stays in the local-only `local_thread_run` snapshot;
|
|
9
|
+
* - the assistant message lands in `c_chat_message` once, when the run ends.
|
|
10
|
+
*/
|
|
11
|
+
type Tx = Pick<AbstractPowerSyncDatabase, 'execute' | 'getOptional' | 'getAll'>;
|
|
12
|
+
export declare const TERMINAL_RUN_STATUSES: ReadonlySet<ThreadRunEventStatus>;
|
|
13
|
+
export type StoredRun = {
|
|
14
|
+
id: string;
|
|
15
|
+
threadId: string;
|
|
16
|
+
status: ThreadRunEventStatus;
|
|
17
|
+
requestId: string | null;
|
|
18
|
+
assistant: ChatUIMessage | null;
|
|
19
|
+
updatedAt: string | null;
|
|
20
|
+
};
|
|
21
|
+
/** Mirrors desktop `withRunMetadata`: the UI reads `metadata.status` for streaming state. */
|
|
22
|
+
export declare function withRunMetadata(message: ChatUIMessage, runId: string, status: ThreadRunEventStatus): ChatUIMessage;
|
|
23
|
+
/**
|
|
24
|
+
* Synced queue marker on a user message (`metadata.queue`), shared by every
|
|
25
|
+
* client: the run that answers it has not started yet. It lives on the synced
|
|
26
|
+
* message because run rows (`local_thread_run`) are local to one process, so
|
|
27
|
+
* other devices could not otherwise show the queue. Removed when the run starts.
|
|
28
|
+
*/
|
|
29
|
+
export type MessageQueueMarker = {
|
|
30
|
+
state: 'queued' | 'withdrawn';
|
|
31
|
+
runId: string;
|
|
32
|
+
executor: 'gateway';
|
|
33
|
+
queuedAt: string;
|
|
34
|
+
};
|
|
35
|
+
/** The answering run merged this turn into a later one; it never gets its own reply. */
|
|
36
|
+
export declare function withMergedInto(message: ChatUIMessage, mergedIntoRunId: string): ChatUIMessage;
|
|
37
|
+
/** Next `order_index` after `parentId` (midpoint before its next sibling) or at the end. */
|
|
38
|
+
export declare function resolveNextOrderIndex(tx: Tx, input: {
|
|
39
|
+
threadId: string;
|
|
40
|
+
parentId: string | null;
|
|
41
|
+
}): Promise<number>;
|
|
42
|
+
export declare function threadExists(db: Tx, threadId: string, userId: string): Promise<boolean>;
|
|
43
|
+
export type EnqueueRunInput = {
|
|
44
|
+
runId: string;
|
|
45
|
+
threadId: string;
|
|
46
|
+
userId: string;
|
|
47
|
+
requestId: string;
|
|
48
|
+
userMessage: ChatUIMessage;
|
|
49
|
+
assistantMessage: ChatUIMessage;
|
|
50
|
+
parentMessageId: string | null;
|
|
51
|
+
createThread: ThreadRunCreateThreadRequest | null;
|
|
52
|
+
requestPayload: Record<string, unknown>;
|
|
53
|
+
/** Waits behind another turn of the same thread: marks the user message as queued. */
|
|
54
|
+
queued: boolean;
|
|
55
|
+
/** FIFO order within the thread. */
|
|
56
|
+
queueIndex: number;
|
|
57
|
+
/**
|
|
58
|
+
* Parent of a queued turn: the reply still being written, or the turn queued
|
|
59
|
+
* just before it. Absent for a turn that runs now, which follows the thread's
|
|
60
|
+
* last message.
|
|
61
|
+
*/
|
|
62
|
+
queuedAfterMessageId?: string;
|
|
63
|
+
};
|
|
64
|
+
/** Persists the accepted turn atomically: thread (if new), user message, queued run. */
|
|
65
|
+
export declare function enqueueRun(db: AbstractPowerSyncDatabase, input: EnqueueRunInput): Promise<{
|
|
66
|
+
threadCreated: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
/** Live progress for `run.status` recovery; never touches synced tables. */
|
|
69
|
+
export declare function updateRunSnapshot(db: Tx, input: {
|
|
70
|
+
runId: string;
|
|
71
|
+
status: ThreadRunEventStatus;
|
|
72
|
+
assistant: ChatUIMessage;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
/** Ends the run and writes the final assistant message into the synced transcript. */
|
|
75
|
+
export declare function commitRunTerminal(db: AbstractPowerSyncDatabase, input: {
|
|
76
|
+
runId: string;
|
|
77
|
+
threadId: string;
|
|
78
|
+
userId: string;
|
|
79
|
+
userMessageId: string;
|
|
80
|
+
status: ThreadRunEventStatus;
|
|
81
|
+
assistant: ChatUIMessage;
|
|
82
|
+
errorText: string | null;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
export declare function findRun(db: Tx, input: {
|
|
85
|
+
runId: string;
|
|
86
|
+
userId: string;
|
|
87
|
+
}): Promise<StoredRun | null>;
|
|
88
|
+
/** The queued turns start now: their messages stop showing as queued. */
|
|
89
|
+
export declare function startQueuedRuns(db: AbstractPowerSyncDatabase, userMessageIds: string[]): Promise<void>;
|
|
90
|
+
/** Ends a queued turn that was merged into a later one: no reply of its own is written. */
|
|
91
|
+
export declare function finishMergedRun(db: Tx, input: {
|
|
92
|
+
runId: string;
|
|
93
|
+
mergedIntoRunId: string;
|
|
94
|
+
assistant: ChatUIMessage;
|
|
95
|
+
}): Promise<ChatUIMessage>;
|
|
96
|
+
/**
|
|
97
|
+
* The user took a queued turn back before it ran: the run is cancelled and its
|
|
98
|
+
* message removed from the transcript (marked `withdrawn` so other devices can
|
|
99
|
+
* tell a withdrawal from a deletion).
|
|
100
|
+
*/
|
|
101
|
+
export declare function withdrawQueuedRun(db: AbstractPowerSyncDatabase, input: {
|
|
102
|
+
runId: string;
|
|
103
|
+
userMessageId: string;
|
|
104
|
+
assistant: ChatUIMessage;
|
|
105
|
+
}): Promise<ChatUIMessage>;
|
|
106
|
+
/** Runs left non-terminal by a previous process can never finish; mark them interrupted. */
|
|
107
|
+
export declare function interruptOrphanedRuns(db: Tx, userId: string): Promise<number>;
|
|
108
|
+
/** Agent session bound to a thread, scoped to the thread's current topic. */
|
|
109
|
+
export type GatewaySessionBinding = {
|
|
110
|
+
sessionId: string;
|
|
111
|
+
topicId: string | null;
|
|
112
|
+
gatewayId: string;
|
|
113
|
+
};
|
|
114
|
+
export declare function readSessionBinding(db: Tx, threadId: string): Promise<GatewaySessionBinding | null>;
|
|
115
|
+
export declare function writeSessionBinding(db: Tx, threadId: string, binding: GatewaySessionBinding): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* The thread's current topic: the latest "new topic" marker the app wrote
|
|
118
|
+
* (`entry_type = 'internal'`, `meta_data.kind = 'context_reset'`). A new topic
|
|
119
|
+
* starts a fresh agent session.
|
|
120
|
+
*/
|
|
121
|
+
export declare function readCurrentTopicId(db: Tx, threadId: string): Promise<string | null>;
|
|
122
|
+
/** File parts resolve only to resources this user owns with an https storage URL. */
|
|
123
|
+
export declare function resolveTrustedResource(db: Tx, input: {
|
|
124
|
+
resourceId: string;
|
|
125
|
+
userId: string;
|
|
126
|
+
}): Promise<{
|
|
127
|
+
url: string;
|
|
128
|
+
name: string;
|
|
129
|
+
mediaType: string | null;
|
|
130
|
+
} | null>;
|
|
131
|
+
/** Registers the gateway as a `c_robot` the app can list and bind agents to (no secrets). */
|
|
132
|
+
export type RobotRegistration = {
|
|
133
|
+
id: string;
|
|
134
|
+
userId: string;
|
|
135
|
+
name: string;
|
|
136
|
+
deviceId: string;
|
|
137
|
+
agentType: string;
|
|
138
|
+
cwd: string | null;
|
|
139
|
+
/** This machine's hostname, shown with the robot. */
|
|
140
|
+
deviceName: string;
|
|
141
|
+
/** Marks the robot as hosted by this installation, for reconciliation. */
|
|
142
|
+
machineId: string;
|
|
143
|
+
agentId?: string;
|
|
144
|
+
};
|
|
145
|
+
export declare function upsertRobot(db: Tx, input: RobotRegistration): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Soft-deletes this machine's gateway robots that are no longer configured
|
|
148
|
+
* (removed, or replaced before ids were deterministic), so the app never
|
|
149
|
+
* offers an agent that nothing hosts. Robots from other machines are untouched.
|
|
150
|
+
*/
|
|
151
|
+
export declare function retireRemovedRobots(db: Tx, input: {
|
|
152
|
+
userId: string;
|
|
153
|
+
machineId: string;
|
|
154
|
+
keepIds: string[];
|
|
155
|
+
}): Promise<string[]>;
|
|
156
|
+
export declare function softDeleteRobot(db: Tx, robotId: string): Promise<void>;
|
|
157
|
+
export {};
|