@saturn-universe/protocol 0.0.0-stage → 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/LICENSE +661 -0
- package/dist/diagnostic-results.d.ts +57 -0
- package/dist/diagnostic-results.js +54 -0
- package/dist/endpoint.d.ts +11 -0
- package/dist/endpoint.js +73 -0
- package/dist/host-results.d.ts +102 -0
- package/dist/host-results.js +105 -0
- package/dist/host-status.d.ts +181 -0
- package/dist/host-status.js +102 -0
- package/dist/index.d.ts +839 -0
- package/dist/index.js +342 -0
- package/dist/ipc-framing.d.ts +10 -0
- package/dist/ipc-framing.js +29 -0
- package/dist/mcp-config.d.ts +34 -0
- package/dist/mcp-config.js +268 -0
- package/dist/provider-credentials.d.ts +18 -0
- package/dist/provider-credentials.js +140 -0
- package/dist/redaction.d.ts +1 -0
- package/dist/redaction.js +43 -0
- package/dist/run-event-results.d.ts +89 -0
- package/dist/run-event-results.js +107 -0
- package/dist/run-query-result.d.ts +66 -0
- package/dist/run-query-result.js +69 -0
- package/dist/session-results.d.ts +215 -0
- package/dist/session-results.js +174 -0
- package/dist/skills.d.ts +68 -0
- package/dist/skills.js +447 -0
- package/dist/team-results.d.ts +86 -0
- package/dist/team-results.js +61 -0
- package/dist/wire-shapes.d.ts +44 -0
- package/dist/wire-shapes.js +40 -0
- package/package.json +17 -3
- package/README.md +0 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SurfaceQuerySnapshot } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Assert, Equal } from './wire-shapes.js';
|
|
4
|
+
declare const surfaceSnapshot: z.ZodObject<{
|
|
5
|
+
agentSessionId: z.ZodString;
|
|
6
|
+
lastStreamSeq: z.ZodNumber;
|
|
7
|
+
throughPosition: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<import("@saturn-universe/core").EventPosition, string>>;
|
|
8
|
+
items: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
9
|
+
message: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
agentSessionId: z.ZodString;
|
|
12
|
+
runId: z.ZodString;
|
|
13
|
+
turnId: z.ZodString;
|
|
14
|
+
role: z.ZodEnum<{
|
|
15
|
+
user: "user";
|
|
16
|
+
assistant: "assistant";
|
|
17
|
+
tool: "tool";
|
|
18
|
+
}>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
sourceEventId: z.ZodString;
|
|
21
|
+
orderSeq: z.ZodNumber;
|
|
22
|
+
orderPart: z.ZodNumber;
|
|
23
|
+
active: z.ZodBoolean;
|
|
24
|
+
supersededBy: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>>;
|
|
26
|
+
groups: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
27
|
+
assistantMessageId: z.ZodString;
|
|
28
|
+
callIds: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
29
|
+
settledCallIds: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
30
|
+
complete: z.ZodBoolean;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
declare const contextSnapshot: z.ZodObject<{
|
|
34
|
+
generation: z.ZodNumber;
|
|
35
|
+
throughPosition: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<import("@saturn-universe/core").EventPosition, string>>;
|
|
36
|
+
surfaceSeq: z.ZodNumber;
|
|
37
|
+
pendingRequestIds: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
38
|
+
runState: z.ZodObject<{
|
|
39
|
+
throughPosition: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<import("@saturn-universe/core").EventPosition, string>>;
|
|
40
|
+
runId: z.ZodString;
|
|
41
|
+
status: z.ZodString;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
activeRequest: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
assemblyHash: z.ZodString;
|
|
46
|
+
selectedMessageIds: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type SurfaceQueryResult = Readonly<z.output<typeof surfaceSnapshot>>;
|
|
50
|
+
export type ContextQueryResult = Readonly<z.output<typeof contextSnapshot>>;
|
|
51
|
+
export type SurfaceQuerySchemaMatchesSnapshot = [
|
|
52
|
+
Assert<Equal<keyof SurfaceQuerySnapshot, keyof SurfaceQueryResult>>,
|
|
53
|
+
Assert<SurfaceQuerySnapshot extends SurfaceQueryResult ? true : false>
|
|
54
|
+
];
|
|
55
|
+
export declare function validSurfaceQueryResult(value: unknown, agentSessionId: string): boolean;
|
|
56
|
+
export declare function validContextQueryResult(value: unknown, runId: string): boolean;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { eventPositionSchema, runResultIdentity } from './wire-shapes.js';
|
|
3
|
+
const identifier = z.string().min(1);
|
|
4
|
+
const identifiers = z.array(identifier).readonly();
|
|
5
|
+
const sequence = z.number().int().nonnegative();
|
|
6
|
+
const surfaceItem = z.object({
|
|
7
|
+
message: z.object({
|
|
8
|
+
id: identifier,
|
|
9
|
+
agentSessionId: identifier,
|
|
10
|
+
runId: identifier,
|
|
11
|
+
turnId: identifier,
|
|
12
|
+
role: z.enum(['user', 'assistant', 'tool']),
|
|
13
|
+
}),
|
|
14
|
+
sourceEventId: identifier,
|
|
15
|
+
orderSeq: sequence,
|
|
16
|
+
orderPart: sequence,
|
|
17
|
+
active: z.boolean(),
|
|
18
|
+
supersededBy: identifier.optional(),
|
|
19
|
+
});
|
|
20
|
+
const surfaceGroup = z.object({
|
|
21
|
+
assistantMessageId: identifier,
|
|
22
|
+
callIds: identifiers,
|
|
23
|
+
settledCallIds: identifiers,
|
|
24
|
+
complete: z.boolean(),
|
|
25
|
+
});
|
|
26
|
+
const surfaceSnapshot = z.object({
|
|
27
|
+
agentSessionId: identifier,
|
|
28
|
+
lastStreamSeq: sequence,
|
|
29
|
+
throughPosition: eventPositionSchema,
|
|
30
|
+
items: z.array(surfaceItem).readonly(),
|
|
31
|
+
groups: z.array(surfaceGroup).readonly(),
|
|
32
|
+
});
|
|
33
|
+
const contextSnapshot = z.object({
|
|
34
|
+
generation: sequence.positive(),
|
|
35
|
+
throughPosition: eventPositionSchema,
|
|
36
|
+
surfaceSeq: sequence,
|
|
37
|
+
pendingRequestIds: identifiers,
|
|
38
|
+
runState: z.object({ ...runResultIdentity, throughPosition: eventPositionSchema }),
|
|
39
|
+
activeRequest: z
|
|
40
|
+
.object({ id: identifier, assemblyHash: identifier, selectedMessageIds: identifiers })
|
|
41
|
+
.optional(),
|
|
42
|
+
});
|
|
43
|
+
export function validSurfaceQueryResult(value, agentSessionId) {
|
|
44
|
+
const result = surfaceSnapshot.safeParse(value);
|
|
45
|
+
if (!result.success || result.data.agentSessionId !== agentSessionId)
|
|
46
|
+
return false;
|
|
47
|
+
return result.data.items.every((item) => item.message.agentSessionId === agentSessionId && item.orderSeq <= result.data.lastStreamSeq);
|
|
48
|
+
}
|
|
49
|
+
export function validContextQueryResult(value, runId) {
|
|
50
|
+
const result = contextSnapshot.safeParse(value);
|
|
51
|
+
return (result.success &&
|
|
52
|
+
result.data.runState.runId === runId &&
|
|
53
|
+
BigInt(result.data.runState.throughPosition) <= BigInt(result.data.throughPosition));
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function workspaceHashKey(root: string, platform?: string): string;
|
|
2
|
+
export declare function isUnsupportedUnixSocketFs(targetPath: string, mountsContent?: string): boolean;
|
|
3
|
+
export interface HostEndpointOptions {
|
|
4
|
+
readonly platform?: string;
|
|
5
|
+
readonly tmpdir?: string;
|
|
6
|
+
readonly mountsContent?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveHostEndpoint(root: string, options?: HostEndpointOptions): {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly endpoint: string;
|
|
11
|
+
};
|
package/dist/endpoint.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
const MAX_UNIX_SOCKET_PATH_BYTES = 103;
|
|
6
|
+
const UNSUPPORTED_SOCKET_FS_TYPES = new Set(['9p', 'drvfs']);
|
|
7
|
+
function unescapeMountPath(value) {
|
|
8
|
+
return value.replace(/\\(040|011|012|134)/g, (_match, octal) => {
|
|
9
|
+
switch (octal) {
|
|
10
|
+
case '040':
|
|
11
|
+
return ' ';
|
|
12
|
+
case '011':
|
|
13
|
+
return '\t';
|
|
14
|
+
case '012':
|
|
15
|
+
return '\n';
|
|
16
|
+
case '134':
|
|
17
|
+
return '\\';
|
|
18
|
+
default:
|
|
19
|
+
return _match;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function workspaceHashKey(root, platform = process.platform) {
|
|
24
|
+
return createHash('sha256')
|
|
25
|
+
.update(platform === 'win32' ? root.toLowerCase() : root)
|
|
26
|
+
.digest('hex');
|
|
27
|
+
}
|
|
28
|
+
export function isUnsupportedUnixSocketFs(targetPath, mountsContent) {
|
|
29
|
+
let content = mountsContent;
|
|
30
|
+
if (content === undefined) {
|
|
31
|
+
try {
|
|
32
|
+
content = readFileSync('/proc/mounts', 'utf8');
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const normalizedTarget = targetPath.length > 1 ? targetPath.replace(/\/+$/, '') : targetPath;
|
|
39
|
+
let bestMountLength = -1;
|
|
40
|
+
let bestFsType;
|
|
41
|
+
for (const line of content.split('\n')) {
|
|
42
|
+
const trimmed = line.trim();
|
|
43
|
+
if (!trimmed)
|
|
44
|
+
continue;
|
|
45
|
+
const fields = trimmed.split(/\s+/);
|
|
46
|
+
if (fields.length < 3)
|
|
47
|
+
continue;
|
|
48
|
+
const rawMount = unescapeMountPath(fields[1]);
|
|
49
|
+
const mountPoint = rawMount.length > 1 ? rawMount.replace(/\/+$/, '') : rawMount;
|
|
50
|
+
const fsType = fields[2];
|
|
51
|
+
const matches = mountPoint === '/' || normalizedTarget === mountPoint || normalizedTarget.startsWith(`${mountPoint}/`);
|
|
52
|
+
if (matches && mountPoint.length > bestMountLength) {
|
|
53
|
+
bestMountLength = mountPoint.length;
|
|
54
|
+
bestFsType = fsType;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return bestFsType !== undefined && UNSUPPORTED_SOCKET_FS_TYPES.has(bestFsType);
|
|
58
|
+
}
|
|
59
|
+
export function resolveHostEndpoint(root, options = {}) {
|
|
60
|
+
const platform = options.platform ?? process.platform;
|
|
61
|
+
const key = workspaceHashKey(root, platform);
|
|
62
|
+
if (platform === 'win32') {
|
|
63
|
+
return { key, endpoint: `\\\\.\\pipe\\saturn-${key}` };
|
|
64
|
+
}
|
|
65
|
+
const defaultEndpoint = path.posix.join(root, '.saturn', 'runtime.sock');
|
|
66
|
+
const needsFallback = Buffer.byteLength(defaultEndpoint) > MAX_UNIX_SOCKET_PATH_BYTES ||
|
|
67
|
+
(platform === 'linux' && isUnsupportedUnixSocketFs(root, options.mountsContent));
|
|
68
|
+
if (needsFallback) {
|
|
69
|
+
const socketDir = options.tmpdir ?? os.tmpdir();
|
|
70
|
+
return { key, endpoint: path.posix.join(socketDir, `saturn-${key.slice(0, 32)}.sock`) };
|
|
71
|
+
}
|
|
72
|
+
return { key, endpoint: defaultEndpoint };
|
|
73
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ApprovalId, EventPosition, HostCommand, RunId, RunProgressPage, RunTimelinePage, Session, SessionExportPage, SessionHistoryMessage, SessionHistoryPage, SessionListItem, SurfaceCompactionReceipt, ToolCallId, TurnId, Workspace } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ContextQueryResult, SurfaceQueryResult } from './diagnostic-results.js';
|
|
4
|
+
import { type HostStatusSnapshot } from './host-status.js';
|
|
5
|
+
import { type RunQueryResult } from './run-query-result.js';
|
|
6
|
+
import { type SessionSummary, type SessionUsageResult } from './session-results.js';
|
|
7
|
+
import type { TeamInboxResult, TeamQueryResult } from './team-results.js';
|
|
8
|
+
import type { Assert, Equal, ModelDisplay, Wire } from './wire-shapes.js';
|
|
9
|
+
type CreationReceipt = {
|
|
10
|
+
readonly cursor?: EventPosition;
|
|
11
|
+
};
|
|
12
|
+
export interface HostCommandResults {
|
|
13
|
+
readonly 'host.status': HostStatusSnapshot;
|
|
14
|
+
readonly 'host.shutdown': Readonly<z.output<typeof hostShutdown>>;
|
|
15
|
+
readonly 'run.model': ModelDisplay;
|
|
16
|
+
readonly 'run.submit': Readonly<Wire<z.output<typeof runSubmission>>>;
|
|
17
|
+
readonly 'run.resume': Readonly<z.output<typeof runResume>>;
|
|
18
|
+
readonly 'run.cancel': Readonly<Wire<z.output<typeof runCancellation>>>;
|
|
19
|
+
readonly 'run.steer': Readonly<z.output<typeof runSteering>>;
|
|
20
|
+
readonly 'run.query': RunQueryResult;
|
|
21
|
+
readonly 'run.progress': RunProgressPage;
|
|
22
|
+
readonly 'run.timeline': RunTimelinePage;
|
|
23
|
+
readonly 'team.query': TeamQueryResult;
|
|
24
|
+
readonly 'team.inbox': TeamInboxResult;
|
|
25
|
+
readonly 'session.query': SessionSummary;
|
|
26
|
+
readonly 'session.btw': Readonly<z.output<typeof sideQuestion>>;
|
|
27
|
+
readonly 'session.usage': SessionUsageResult;
|
|
28
|
+
readonly 'session.history': SessionHistoryPage;
|
|
29
|
+
readonly 'session.history.message': SessionHistoryMessage;
|
|
30
|
+
readonly 'session.export': SessionExportPage;
|
|
31
|
+
readonly 'session.list': readonly SessionListItem[];
|
|
32
|
+
readonly 'workspace.query': readonly Pick<Workspace, 'id'>[];
|
|
33
|
+
readonly 'workspace.create': CreationReceipt & {
|
|
34
|
+
readonly workspaceId: Workspace['id'];
|
|
35
|
+
};
|
|
36
|
+
readonly 'session.create': CreationReceipt & {
|
|
37
|
+
readonly sessionId: Session['id'];
|
|
38
|
+
};
|
|
39
|
+
readonly 'surface.compact': SurfaceCompactionReceipt;
|
|
40
|
+
readonly 'surface.query': SurfaceQueryResult;
|
|
41
|
+
readonly 'context.query': ContextQueryResult;
|
|
42
|
+
readonly 'tool.approval.resolve': Readonly<z.output<typeof approvalResolution>>;
|
|
43
|
+
readonly 'tool.reconcile': Readonly<z.output<typeof toolReconciliation>>;
|
|
44
|
+
}
|
|
45
|
+
declare const hostShutdown: z.ZodObject<{
|
|
46
|
+
stopping: z.ZodLiteral<true>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
declare const workspaceList: z.ZodArray<z.ZodObject<{
|
|
49
|
+
id: z.ZodCustom<import("@saturn-universe/core").WorkspaceId, import("@saturn-universe/core").WorkspaceId>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
51
|
+
declare const workspaceCreation: z.ZodObject<{
|
|
52
|
+
workspaceId: z.ZodCustom<import("@saturn-universe/core").WorkspaceId, import("@saturn-universe/core").WorkspaceId>;
|
|
53
|
+
cursor: z.ZodOptional<z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
declare const sessionCreation: z.ZodObject<{
|
|
56
|
+
sessionId: z.ZodCustom<import("@saturn-universe/core").SessionId, import("@saturn-universe/core").SessionId>;
|
|
57
|
+
cursor: z.ZodOptional<z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
declare const runSubmission: z.ZodObject<{
|
|
60
|
+
runId: z.ZodCustom<RunId, RunId>;
|
|
61
|
+
turnId: z.ZodCustom<TurnId, TurnId>;
|
|
62
|
+
cursor: z.ZodOptional<z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
declare const runResume: z.ZodObject<{
|
|
65
|
+
runId: z.ZodCustom<RunId, RunId>;
|
|
66
|
+
cursor: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
declare const runCancellation: z.ZodObject<{
|
|
69
|
+
runId: z.ZodCustom<RunId, RunId>;
|
|
70
|
+
cursor: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
71
|
+
status: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
declare const runSteering: z.ZodObject<{
|
|
74
|
+
runId: z.ZodCustom<RunId, RunId>;
|
|
75
|
+
accepted: z.ZodLiteral<true>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
declare const sideQuestion: z.ZodObject<{
|
|
78
|
+
answer: z.ZodString;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
declare const surfaceCompaction: z.ZodObject<{
|
|
81
|
+
runId: z.ZodCustom<RunId, RunId>;
|
|
82
|
+
compactionId: z.ZodString;
|
|
83
|
+
replacedCount: z.ZodNumber;
|
|
84
|
+
cursor: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
declare const approvalResolution: z.ZodObject<{
|
|
87
|
+
approvalId: z.ZodCustom<ApprovalId, ApprovalId>;
|
|
88
|
+
cursor: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
declare const toolReconciliation: z.ZodObject<{
|
|
91
|
+
toolCallId: z.ZodCustom<ToolCallId, ToolCallId>;
|
|
92
|
+
cursor: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
export declare function validHostCommandResult(command: HostCommand, result: unknown): boolean;
|
|
95
|
+
export type HostResultCommandsAreExhaustive = Assert<Equal<keyof HostCommandResults, HostCommand['type']>>;
|
|
96
|
+
export type WorkspaceAndSessionResultSchemasMatchContracts = [
|
|
97
|
+
Assert<Equal<Wire<z.output<typeof workspaceList>>, Wire<HostCommandResults['workspace.query']>>>,
|
|
98
|
+
Assert<Equal<Wire<z.output<typeof workspaceCreation>>, Wire<HostCommandResults['workspace.create']>>>,
|
|
99
|
+
Assert<Equal<Wire<z.output<typeof sessionCreation>>, Wire<HostCommandResults['session.create']>>>
|
|
100
|
+
];
|
|
101
|
+
export type SurfaceCompactionResultSchemaMatchesContract = Assert<Equal<Wire<z.output<typeof surfaceCompaction>>, Wire<SurfaceCompactionReceipt>>>;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DEFAULT_SESSION_LIST_LIMIT } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { validContextQueryResult, validSurfaceQueryResult } from './diagnostic-results.js';
|
|
4
|
+
import { parseHostStatusResult } from './host-status.js';
|
|
5
|
+
import { parseRunProgressResult, validRunTimelineResult } from './run-event-results.js';
|
|
6
|
+
import { validRunQueryResult } from './run-query-result.js';
|
|
7
|
+
import { parseSessionExportResult, parseSessionListResult, parseSessionSummaryResult, parseSessionUsageResult, validSessionHistoryResult, } from './session-results.js';
|
|
8
|
+
import { validTeamInboxResult, validTeamQueryResult } from './team-results.js';
|
|
9
|
+
import { eventPositionSchema as eventPosition, modelDisplaySchema } from './wire-shapes.js';
|
|
10
|
+
const hostShutdown = z.object({ stopping: z.literal(true) });
|
|
11
|
+
const hasIdentifier = (value) => typeof value === 'string' && value.length > 0;
|
|
12
|
+
const workspaceId = z.custom(hasIdentifier);
|
|
13
|
+
const workspaceList = z.array(z.object({ id: workspaceId }));
|
|
14
|
+
const cursor = eventPosition.optional();
|
|
15
|
+
const workspaceCreation = z.object({ workspaceId, cursor });
|
|
16
|
+
const sessionCreation = z.object({ sessionId: z.custom(hasIdentifier), cursor });
|
|
17
|
+
const runId = z.custom(hasIdentifier);
|
|
18
|
+
const runSubmission = z.object({ runId, turnId: z.custom(hasIdentifier), cursor });
|
|
19
|
+
const runResume = z.object({ runId, cursor: eventPosition });
|
|
20
|
+
const runCancellation = runResume.extend({ status: z.string().optional() });
|
|
21
|
+
const runSteering = z.object({ runId, accepted: z.literal(true) });
|
|
22
|
+
const sideQuestion = z.object({ answer: z.string().trim().min(1) });
|
|
23
|
+
const surfaceCompaction = z.object({
|
|
24
|
+
runId,
|
|
25
|
+
compactionId: z.string().min(1),
|
|
26
|
+
replacedCount: z.number().int().positive(),
|
|
27
|
+
cursor: eventPosition,
|
|
28
|
+
});
|
|
29
|
+
const approvalResolution = z.object({
|
|
30
|
+
approvalId: z.custom(hasIdentifier),
|
|
31
|
+
cursor: eventPosition,
|
|
32
|
+
});
|
|
33
|
+
const toolReconciliation = z.object({
|
|
34
|
+
toolCallId: z.custom(hasIdentifier),
|
|
35
|
+
cursor: eventPosition,
|
|
36
|
+
});
|
|
37
|
+
export function validHostCommandResult(command, result) {
|
|
38
|
+
switch (command.type) {
|
|
39
|
+
case 'host.status':
|
|
40
|
+
return parseHostStatusResult(result) !== undefined;
|
|
41
|
+
case 'host.shutdown':
|
|
42
|
+
return hostShutdown.safeParse(result).success;
|
|
43
|
+
case 'run.model':
|
|
44
|
+
return modelDisplaySchema.safeParse(result).success;
|
|
45
|
+
case 'run.submit':
|
|
46
|
+
return runSubmission.safeParse(result).success;
|
|
47
|
+
case 'run.resume':
|
|
48
|
+
// Resuming a checkpoint creates a new Run rather than transitioning the original.
|
|
49
|
+
return runResume.safeParse(result).success;
|
|
50
|
+
case 'run.cancel': {
|
|
51
|
+
const receipt = runCancellation.safeParse(result);
|
|
52
|
+
return receipt.success && receipt.data.runId === command.runId;
|
|
53
|
+
}
|
|
54
|
+
case 'run.steer': {
|
|
55
|
+
const receipt = runSteering.safeParse(result);
|
|
56
|
+
return receipt.success && receipt.data.runId === command.runId;
|
|
57
|
+
}
|
|
58
|
+
case 'run.query':
|
|
59
|
+
return validRunQueryResult(result, command.runId);
|
|
60
|
+
case 'run.progress':
|
|
61
|
+
return parseRunProgressResult(result, command) !== undefined;
|
|
62
|
+
case 'run.timeline':
|
|
63
|
+
return validRunTimelineResult(result, command);
|
|
64
|
+
case 'team.query':
|
|
65
|
+
return validTeamQueryResult(command, result);
|
|
66
|
+
case 'team.inbox':
|
|
67
|
+
return validTeamInboxResult(command, result);
|
|
68
|
+
case 'session.query':
|
|
69
|
+
return parseSessionSummaryResult(result, command.sessionId) !== undefined;
|
|
70
|
+
case 'session.btw':
|
|
71
|
+
return sideQuestion.safeParse(result).success;
|
|
72
|
+
case 'session.usage':
|
|
73
|
+
return parseSessionUsageResult(result) !== undefined;
|
|
74
|
+
case 'session.history':
|
|
75
|
+
case 'session.history.message':
|
|
76
|
+
return validSessionHistoryResult(command, result);
|
|
77
|
+
case 'session.export':
|
|
78
|
+
return parseSessionExportResult(result, command) !== undefined;
|
|
79
|
+
case 'session.list':
|
|
80
|
+
return (parseSessionListResult(result, command.workspaceId, command.limit ?? DEFAULT_SESSION_LIST_LIMIT) !==
|
|
81
|
+
undefined);
|
|
82
|
+
case 'workspace.query':
|
|
83
|
+
return workspaceList.safeParse(result).success;
|
|
84
|
+
case 'workspace.create':
|
|
85
|
+
return workspaceCreation.safeParse(result).success;
|
|
86
|
+
case 'session.create':
|
|
87
|
+
return sessionCreation.safeParse(result).success;
|
|
88
|
+
case 'surface.compact': {
|
|
89
|
+
const receipt = surfaceCompaction.safeParse(result);
|
|
90
|
+
return receipt.success && receipt.data.runId === command.runId;
|
|
91
|
+
}
|
|
92
|
+
case 'surface.query':
|
|
93
|
+
return validSurfaceQueryResult(result, command.agentSessionId);
|
|
94
|
+
case 'context.query':
|
|
95
|
+
return validContextQueryResult(result, command.runId);
|
|
96
|
+
case 'tool.approval.resolve': {
|
|
97
|
+
const receipt = approvalResolution.safeParse(result);
|
|
98
|
+
return receipt.success && receipt.data.approvalId === command.decision.approvalId;
|
|
99
|
+
}
|
|
100
|
+
case 'tool.reconcile': {
|
|
101
|
+
const receipt = toolReconciliation.safeParse(result);
|
|
102
|
+
return receipt.success && receipt.data.toolCallId === command.toolCallId;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { HostSandboxStatus, ModelPricing, ModeSummary, PermissionMode, ProviderProtocol } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { DiscoveredSkillSummary } from './skills.js';
|
|
4
|
+
import type { Assert, Equal, ModelDisplay, Wire } from './wire-shapes.js';
|
|
5
|
+
interface HostModelDisplay extends Partial<ModelDisplay> {
|
|
6
|
+
readonly reasoningModel?: boolean;
|
|
7
|
+
readonly reasoningEfforts?: readonly string[];
|
|
8
|
+
readonly contextWindow?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface HostProfileSummary extends HostModelDisplay {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly defaultReasoningEffort?: string | null;
|
|
13
|
+
readonly providerId?: string;
|
|
14
|
+
readonly protocol?: ProviderProtocol;
|
|
15
|
+
readonly pricingSource?: 'builtin';
|
|
16
|
+
readonly pricing?: ModelPricing;
|
|
17
|
+
readonly baseURL?: string;
|
|
18
|
+
readonly ready?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface HostMcpServerSummary {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly scope?: 'user' | 'project' | 'workspace' | 'explicit';
|
|
23
|
+
readonly transport?: 'stdio' | 'http';
|
|
24
|
+
readonly discovery: 'ready' | 'unavailable' | 'auth_required' | 'trust_required' | 'pending_trust';
|
|
25
|
+
readonly toolCount: number;
|
|
26
|
+
readonly error?: string;
|
|
27
|
+
}
|
|
28
|
+
interface HostStatusFields extends HostModelDisplay {
|
|
29
|
+
readonly epoch: number;
|
|
30
|
+
readonly cursor: string;
|
|
31
|
+
readonly configSource?: string;
|
|
32
|
+
readonly workspaceTools?: boolean;
|
|
33
|
+
readonly defaultProfile?: string;
|
|
34
|
+
readonly selectedProfile?: string;
|
|
35
|
+
readonly taskProfiles?: Readonly<Record<string, string>>;
|
|
36
|
+
readonly profiles?: readonly HostProfileSummary[];
|
|
37
|
+
readonly activeMode: ModeSummary;
|
|
38
|
+
readonly availableModes: readonly ModeSummary[];
|
|
39
|
+
readonly sandbox?: HostSandboxStatus;
|
|
40
|
+
readonly boardUrl?: string;
|
|
41
|
+
readonly modes?: readonly string[];
|
|
42
|
+
readonly skills?: readonly string[];
|
|
43
|
+
readonly discoveredSkills?: readonly DiscoveredSkillSummary[];
|
|
44
|
+
readonly mcpServers?: readonly HostMcpServerSummary[];
|
|
45
|
+
readonly teamPresets?: readonly string[];
|
|
46
|
+
readonly runDefaults?: {
|
|
47
|
+
readonly permissionMode?: PermissionMode;
|
|
48
|
+
readonly reasoningEffort?: string;
|
|
49
|
+
readonly workerReasoningEffort?: string;
|
|
50
|
+
readonly modeRef?: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export type HostStatusSnapshot = HostStatusFields & Readonly<Record<string, unknown>>;
|
|
54
|
+
declare const hostStatus: z.ZodObject<{
|
|
55
|
+
profiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
56
|
+
defaultReasoningEffort: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
pricingSource: z.ZodOptional<z.ZodLiteral<"builtin">>;
|
|
58
|
+
pricing: z.ZodOptional<z.ZodObject<{
|
|
59
|
+
inputPerMillion: z.ZodNumber;
|
|
60
|
+
cachedInputPerMillion: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
outputPerMillion: z.ZodNumber;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
64
|
+
ready: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
reasoningModel: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
reasoningEfforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
67
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
modelId: z.ZodOptional<z.ZodString>;
|
|
69
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
70
|
+
name: z.ZodString;
|
|
71
|
+
providerId: z.ZodOptional<z.ZodString>;
|
|
72
|
+
protocol: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
|
|
73
|
+
"openai-responses": "openai-responses";
|
|
74
|
+
"openai-chat": "openai-chat";
|
|
75
|
+
anthropic: "anthropic";
|
|
76
|
+
gemini: "gemini";
|
|
77
|
+
"anthropic-messages": "anthropic-messages";
|
|
78
|
+
"google-gemini": "google-gemini";
|
|
79
|
+
}>, z.ZodTransform<"openai-responses" | "openai-chat" | "anthropic" | "gemini" | undefined, "openai-responses" | "openai-chat" | "anthropic" | "gemini" | "anthropic-messages" | "google-gemini">>>;
|
|
80
|
+
}, z.core.$strip>>>;
|
|
81
|
+
activeMode: z.ZodObject<{
|
|
82
|
+
ref: z.ZodString;
|
|
83
|
+
displayName: z.ZodString;
|
|
84
|
+
description: z.ZodString;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
availableModes: z.ZodArray<z.ZodObject<{
|
|
87
|
+
ref: z.ZodString;
|
|
88
|
+
displayName: z.ZodString;
|
|
89
|
+
description: z.ZodString;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
sandbox: z.ZodOptional<z.ZodObject<{
|
|
92
|
+
backend: z.ZodEnum<{
|
|
93
|
+
host: "host";
|
|
94
|
+
docker: "docker";
|
|
95
|
+
gvisor: "gvisor";
|
|
96
|
+
sysbox: "sysbox";
|
|
97
|
+
}>;
|
|
98
|
+
scope: z.ZodEnum<{
|
|
99
|
+
none: "none";
|
|
100
|
+
per_run_and_worker: "per_run_and_worker";
|
|
101
|
+
}>;
|
|
102
|
+
state: z.ZodEnum<{
|
|
103
|
+
ready: "ready";
|
|
104
|
+
unavailable: "unavailable";
|
|
105
|
+
disabled: "disabled";
|
|
106
|
+
fallback_host: "fallback_host";
|
|
107
|
+
}>;
|
|
108
|
+
image: z.ZodOptional<z.ZodString>;
|
|
109
|
+
activeContainers: z.ZodNumber;
|
|
110
|
+
fallbackActive: z.ZodBoolean;
|
|
111
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strip>>;
|
|
113
|
+
boardUrl: z.ZodOptional<z.ZodString>;
|
|
114
|
+
modes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
115
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
116
|
+
discoveredSkills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
117
|
+
name: z.ZodString;
|
|
118
|
+
description: z.ZodString;
|
|
119
|
+
scope: z.ZodEnum<{
|
|
120
|
+
user: "user";
|
|
121
|
+
project: "project";
|
|
122
|
+
mode: "mode";
|
|
123
|
+
config: "config";
|
|
124
|
+
}>;
|
|
125
|
+
source: z.ZodString;
|
|
126
|
+
resources: z.ZodArray<z.ZodString>;
|
|
127
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
128
|
+
license: z.ZodOptional<z.ZodString>;
|
|
129
|
+
compatibility: z.ZodOptional<z.ZodString>;
|
|
130
|
+
allowedTools: z.ZodOptional<z.ZodString>;
|
|
131
|
+
indexedBySecurityPlugin: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
+
}, z.core.$strip>>>;
|
|
133
|
+
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
134
|
+
id: z.ZodString;
|
|
135
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
136
|
+
user: "user";
|
|
137
|
+
project: "project";
|
|
138
|
+
workspace: "workspace";
|
|
139
|
+
explicit: "explicit";
|
|
140
|
+
}>>;
|
|
141
|
+
transport: z.ZodOptional<z.ZodEnum<{
|
|
142
|
+
stdio: "stdio";
|
|
143
|
+
http: "http";
|
|
144
|
+
}>>;
|
|
145
|
+
discovery: z.ZodEnum<{
|
|
146
|
+
ready: "ready";
|
|
147
|
+
unavailable: "unavailable";
|
|
148
|
+
auth_required: "auth_required";
|
|
149
|
+
trust_required: "trust_required";
|
|
150
|
+
pending_trust: "pending_trust";
|
|
151
|
+
}>;
|
|
152
|
+
toolCount: z.ZodNumber;
|
|
153
|
+
error: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, z.core.$strip>>>;
|
|
155
|
+
teamPresets: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
156
|
+
runDefaults: z.ZodOptional<z.ZodObject<{
|
|
157
|
+
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
158
|
+
default: "default";
|
|
159
|
+
strict: "strict";
|
|
160
|
+
full: "full";
|
|
161
|
+
}>>;
|
|
162
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
163
|
+
workerReasoningEffort: z.ZodOptional<z.ZodString>;
|
|
164
|
+
modeRef: z.ZodOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strip>>;
|
|
166
|
+
reasoningModel: z.ZodOptional<z.ZodBoolean>;
|
|
167
|
+
reasoningEfforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
168
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
169
|
+
modelId: z.ZodOptional<z.ZodString>;
|
|
170
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
171
|
+
epoch: z.ZodNumber;
|
|
172
|
+
cursor: z.ZodCustom<string, string>;
|
|
173
|
+
configSource: z.ZodOptional<z.ZodString>;
|
|
174
|
+
workspaceTools: z.ZodOptional<z.ZodBoolean>;
|
|
175
|
+
defaultProfile: z.ZodOptional<z.ZodString>;
|
|
176
|
+
selectedProfile: z.ZodOptional<z.ZodString>;
|
|
177
|
+
taskProfiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
178
|
+
}, z.core.$strip>;
|
|
179
|
+
export type HostStatusSchemaMatchesFields = Assert<Equal<Wire<z.output<typeof hostStatus>>, Wire<HostStatusFields>>>;
|
|
180
|
+
export declare function parseHostStatusResult(value: unknown): HostStatusSnapshot | undefined;
|
|
181
|
+
export {};
|