@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,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare function saturnHomeDir(env?: NodeJS.ProcessEnv): string;
|
|
3
|
+
export declare function userConfigPath(env?: NodeJS.ProcessEnv): string;
|
|
4
|
+
export declare function userCredentialsPath(env?: NodeJS.ProcessEnv): string;
|
|
5
|
+
export declare function userEnvPath(env?: NodeJS.ProcessEnv): string;
|
|
6
|
+
export declare function userAuthCredentialsPath(env?: NodeJS.ProcessEnv): string;
|
|
7
|
+
export declare function userWebSearchEnvPath(env?: NodeJS.ProcessEnv): string;
|
|
8
|
+
export declare function workspaceConfigPath(root: string): string;
|
|
9
|
+
export declare function workspaceEnvPath(root: string): string;
|
|
10
|
+
export declare const providerIdSchema: z.ZodString;
|
|
11
|
+
export declare const credentialRefSchema: z.ZodString;
|
|
12
|
+
export interface ResolvedCredentialMap {
|
|
13
|
+
readonly values: ReadonlyMap<string, string>;
|
|
14
|
+
readonly secrets: readonly string[];
|
|
15
|
+
readonly sources: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function parseDotenvText(text: string): ReadonlyMap<string, string>;
|
|
18
|
+
export declare function resolveCredentialMap(root: string, env?: NodeJS.ProcessEnv): Promise<ResolvedCredentialMap>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { providerIdPattern, RuntimeError } from '@saturn-universe/core';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
export function saturnHomeDir(env = process.env) {
|
|
7
|
+
const custom = env.SATURN_HOME?.trim();
|
|
8
|
+
return custom ? path.resolve(custom) : path.join(os.homedir(), '.saturn');
|
|
9
|
+
}
|
|
10
|
+
export function userConfigPath(env = process.env) {
|
|
11
|
+
return path.join(saturnHomeDir(env), 'config.toml');
|
|
12
|
+
}
|
|
13
|
+
export function userCredentialsPath(env = process.env) {
|
|
14
|
+
return path.join(saturnHomeDir(env), 'credentials.toml');
|
|
15
|
+
}
|
|
16
|
+
export function userEnvPath(env = process.env) {
|
|
17
|
+
return path.join(saturnHomeDir(env), '.env');
|
|
18
|
+
}
|
|
19
|
+
export function userAuthCredentialsPath(env = process.env) {
|
|
20
|
+
return path.join(saturnHomeDir(env), 'credentials.env');
|
|
21
|
+
}
|
|
22
|
+
export function userWebSearchEnvPath(env = process.env) {
|
|
23
|
+
return path.join(saturnHomeDir(env), 'web-search.env');
|
|
24
|
+
}
|
|
25
|
+
export function workspaceConfigPath(root) {
|
|
26
|
+
return path.join(root, '.saturn', 'config.toml');
|
|
27
|
+
}
|
|
28
|
+
export function workspaceEnvPath(root) {
|
|
29
|
+
return path.join(root, '.env');
|
|
30
|
+
}
|
|
31
|
+
const envKeyNameSource = '[A-Za-z_][A-Za-z0-9_]*';
|
|
32
|
+
const envKeyPattern = new RegExp(`^${envKeyNameSource}$`);
|
|
33
|
+
export const providerIdSchema = z.string().max(197).regex(providerIdPattern);
|
|
34
|
+
export const credentialRefSchema = z.string().regex(new RegExp(`^env:${envKeyNameSource}$`));
|
|
35
|
+
const credentialsSchema = z.strictObject({
|
|
36
|
+
version: z.literal(1),
|
|
37
|
+
credentials: z.record(z.string().regex(envKeyPattern), z.string()),
|
|
38
|
+
});
|
|
39
|
+
export function parseDotenvText(text) {
|
|
40
|
+
if (text.includes('\0')) {
|
|
41
|
+
throw new RuntimeError('INVALID_CONFIG', 'Provider .env file is invalid');
|
|
42
|
+
}
|
|
43
|
+
const normalized = text.startsWith('\uFEFF') ? text.slice(1) : text;
|
|
44
|
+
const entries = new Map();
|
|
45
|
+
for (const rawLine of normalized.split(/\r?\n/)) {
|
|
46
|
+
const trimmed = rawLine.trim();
|
|
47
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
48
|
+
continue;
|
|
49
|
+
const line = trimmed.startsWith('export ') ? trimmed.slice(7).trimStart() : trimmed;
|
|
50
|
+
const eq = line.indexOf('=');
|
|
51
|
+
if (eq <= 0) {
|
|
52
|
+
throw new RuntimeError('INVALID_CONFIG', 'Provider .env file is invalid');
|
|
53
|
+
}
|
|
54
|
+
const key = line.slice(0, eq).trim();
|
|
55
|
+
if (!envKeyPattern.test(key)) {
|
|
56
|
+
throw new RuntimeError('INVALID_CONFIG', 'Provider .env file is invalid');
|
|
57
|
+
}
|
|
58
|
+
let value = line.slice(eq + 1).trim();
|
|
59
|
+
if (value.startsWith('"') || value.startsWith("'")) {
|
|
60
|
+
const quote = value[0];
|
|
61
|
+
if (value.length < 2 || !value.endsWith(quote)) {
|
|
62
|
+
throw new RuntimeError('INVALID_CONFIG', 'Provider .env file is invalid');
|
|
63
|
+
}
|
|
64
|
+
value = value.slice(1, -1);
|
|
65
|
+
}
|
|
66
|
+
entries.set(key, value);
|
|
67
|
+
}
|
|
68
|
+
return entries;
|
|
69
|
+
}
|
|
70
|
+
async function readDotenvLayer(filePath) {
|
|
71
|
+
let text;
|
|
72
|
+
try {
|
|
73
|
+
text = await readFile(filePath, 'utf8');
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error.code === 'ENOENT')
|
|
77
|
+
return undefined;
|
|
78
|
+
throw new RuntimeError('INVALID_CONFIG', 'Provider .env file could not be loaded');
|
|
79
|
+
}
|
|
80
|
+
return parseDotenvText(text);
|
|
81
|
+
}
|
|
82
|
+
async function readCredentialsToml(filePath) {
|
|
83
|
+
let text;
|
|
84
|
+
try {
|
|
85
|
+
text = await readFile(filePath, 'utf8');
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error.code === 'ENOENT')
|
|
89
|
+
return undefined;
|
|
90
|
+
throw new RuntimeError('INVALID_CONFIG', 'User credentials file could not be loaded');
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const { parse } = await import('smol-toml');
|
|
94
|
+
const parsed = credentialsSchema.parse(parse(text));
|
|
95
|
+
return new Map(Object.entries(parsed.credentials));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new RuntimeError('INVALID_CONFIG', 'User credentials file is invalid');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export async function resolveCredentialMap(root, env = process.env) {
|
|
102
|
+
const values = new Map();
|
|
103
|
+
const secrets = new Set();
|
|
104
|
+
const sources = [];
|
|
105
|
+
const fileKeys = new Set();
|
|
106
|
+
const applyLayer = (filePath, entries) => {
|
|
107
|
+
if (!entries)
|
|
108
|
+
return;
|
|
109
|
+
sources.push(filePath);
|
|
110
|
+
for (const [key, value] of entries) {
|
|
111
|
+
fileKeys.add(key);
|
|
112
|
+
values.set(key, value);
|
|
113
|
+
if (value.trim())
|
|
114
|
+
secrets.add(value);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const userEnv = userEnvPath(env);
|
|
118
|
+
applyLayer(userEnv, await readDotenvLayer(userEnv));
|
|
119
|
+
const userCredentials = userCredentialsPath(env);
|
|
120
|
+
applyLayer(userCredentials, await readCredentialsToml(userCredentials));
|
|
121
|
+
const authCredentials = userAuthCredentialsPath(env);
|
|
122
|
+
applyLayer(authCredentials, await readDotenvLayer(authCredentials));
|
|
123
|
+
const webSearchEnv = userWebSearchEnvPath(env);
|
|
124
|
+
applyLayer(webSearchEnv, await readDotenvLayer(webSearchEnv));
|
|
125
|
+
const workspaceEnv = workspaceEnvPath(root);
|
|
126
|
+
applyLayer(workspaceEnv, await readDotenvLayer(workspaceEnv));
|
|
127
|
+
for (const [key, value] of Object.entries(env)) {
|
|
128
|
+
if (value === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
values.set(key, value);
|
|
131
|
+
if ((fileKeys.has(key) || key === 'SATURN_PROVIDER_API_KEY') && value.trim()) {
|
|
132
|
+
secrets.add(value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
values,
|
|
137
|
+
secrets: [...secrets],
|
|
138
|
+
sources,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function redactExportValue(value: unknown, secrets?: readonly string[]): unknown;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
export function redactExportValue(value, secrets = []) {
|
|
3
|
+
const orderedSecrets = [
|
|
4
|
+
...new Set(secrets.flatMap((secret) => {
|
|
5
|
+
const trimmed = secret.trim();
|
|
6
|
+
if (!trimmed)
|
|
7
|
+
return [];
|
|
8
|
+
return [
|
|
9
|
+
secret,
|
|
10
|
+
trimmed,
|
|
11
|
+
encodeURIComponent(Buffer.from(trimmed).toString()),
|
|
12
|
+
JSON.stringify(secret).slice(1, -1),
|
|
13
|
+
];
|
|
14
|
+
})),
|
|
15
|
+
].sort((a, b) => b.length - a.length);
|
|
16
|
+
const redactStr = (text) => {
|
|
17
|
+
let out = text;
|
|
18
|
+
for (const secret of orderedSecrets) {
|
|
19
|
+
out = out.split(secret).join('[REDACTED]');
|
|
20
|
+
}
|
|
21
|
+
return out
|
|
22
|
+
.replace(/(https?:\/\/)([^/@\s]+@)/gi, '$1[REDACTED]@')
|
|
23
|
+
.replace(/\b(Bearer|Basic)\s+[^\s"'`,;]+/gi, '$1 [REDACTED]')
|
|
24
|
+
.replace(/\b(sk-[A-Za-z0-9_-]{12,}|tvly-[A-Za-z0-9_-]{8,}|ghp_[A-Za-z0-9]{20,})\b/g, '[REDACTED]');
|
|
25
|
+
};
|
|
26
|
+
const walk = (node, depth = 0) => {
|
|
27
|
+
if (typeof node === 'string')
|
|
28
|
+
return redactStr(node);
|
|
29
|
+
if (node === null || typeof node !== 'object')
|
|
30
|
+
return node;
|
|
31
|
+
if (depth >= 80)
|
|
32
|
+
return '[TRUNCATED]';
|
|
33
|
+
if (Array.isArray(node))
|
|
34
|
+
return node.map((item) => walk(item, depth + 1));
|
|
35
|
+
return Object.fromEntries(Object.entries(node).map(([key, item]) => [
|
|
36
|
+
redactStr(key),
|
|
37
|
+
/^(?:authorization|proxy-authorization|x-api-key|api[_-]?key|token|secret|password|cookie)$/i.test(key)
|
|
38
|
+
? '[REDACTED]'
|
|
39
|
+
: walk(item, depth + 1),
|
|
40
|
+
]));
|
|
41
|
+
};
|
|
42
|
+
return walk(value);
|
|
43
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { AgentSessionId, EventPosition, HostCommand, RequestId, RunProgressPage, RunTimelinePage } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Assert, Equal, Wire } from './wire-shapes.js';
|
|
4
|
+
declare const runProgress: z.ZodObject<{
|
|
5
|
+
events: z.ZodArray<z.ZodObject<{
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
position: z.ZodCustom<EventPosition, EventPosition>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
pauseReason: z.ZodOptional<z.ZodString>;
|
|
10
|
+
cursor: z.ZodCustom<EventPosition, EventPosition>;
|
|
11
|
+
through: z.ZodOptional<z.ZodCustom<EventPosition, EventPosition>>;
|
|
12
|
+
hasMore: z.ZodBoolean;
|
|
13
|
+
draft: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
requestId: z.ZodString;
|
|
15
|
+
revision: z.ZodNumber;
|
|
16
|
+
text: z.ZodString;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
liveAgents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
19
|
+
memberId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
agentSessionId: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<AgentSessionId, string>>>;
|
|
21
|
+
phase: z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
tool: "tool";
|
|
23
|
+
thinking: "thinking";
|
|
24
|
+
streaming: "streaming";
|
|
25
|
+
waiting_approval: "waiting_approval";
|
|
26
|
+
retrying: "retrying";
|
|
27
|
+
idle: "idle";
|
|
28
|
+
}>>;
|
|
29
|
+
reasoningSummary: z.ZodOptional<z.ZodString>;
|
|
30
|
+
requestId: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<RequestId, string>>>;
|
|
31
|
+
currentTool: z.ZodOptional<z.ZodString>;
|
|
32
|
+
stepCount: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
requestStartedAt: z.ZodOptional<z.ZodString>;
|
|
34
|
+
retryAttempt: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
retryMaxAttempts: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
lastActivityAt: z.ZodOptional<z.ZodString>;
|
|
37
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
lastInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
lastOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
lastCachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
outputTokensPerSec: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
}, z.core.$strip>>>;
|
|
43
|
+
telemetry: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
44
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
lastInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
lastOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
lastCachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
outputTokensPerSec: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
}, z.core.$strip>>>;
|
|
50
|
+
pendingApprovals: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
51
|
+
toolCallId: z.ZodString;
|
|
52
|
+
turnId: z.ZodString;
|
|
53
|
+
toolName: z.ZodString;
|
|
54
|
+
memberId: z.ZodOptional<z.ZodString>;
|
|
55
|
+
expiresAt: z.ZodString;
|
|
56
|
+
approvalId: z.ZodString;
|
|
57
|
+
resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
58
|
+
reason: z.ZodString;
|
|
59
|
+
}, z.core.$strip>>>;
|
|
60
|
+
pluginBlock: z.ZodOptional<z.ZodObject<{
|
|
61
|
+
code: z.ZodString;
|
|
62
|
+
message: z.ZodString;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
runId: z.ZodString;
|
|
65
|
+
status: z.ZodString;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
declare const runTimeline: z.ZodObject<{
|
|
68
|
+
events: z.ZodArray<z.ZodObject<{
|
|
69
|
+
type: z.ZodString;
|
|
70
|
+
position: z.ZodCustom<EventPosition, EventPosition>;
|
|
71
|
+
}, z.core.$strip>>;
|
|
72
|
+
nextAfter: z.ZodOptional<z.ZodCustom<EventPosition, EventPosition>>;
|
|
73
|
+
pluginBlock: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
code: z.ZodString;
|
|
75
|
+
message: z.ZodString;
|
|
76
|
+
}, z.core.$strip>>;
|
|
77
|
+
runId: z.ZodString;
|
|
78
|
+
status: z.ZodString;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
type ProgressRequest = Extract<HostCommand, {
|
|
81
|
+
type: 'run.progress';
|
|
82
|
+
}>;
|
|
83
|
+
export declare function parseRunProgressResult(value: unknown, request?: Pick<ProgressRequest, 'runId' | 'after'> & Partial<Pick<ProgressRequest, 'limit'>>): RunProgressPage | undefined;
|
|
84
|
+
export declare function validRunTimelineResult(value: unknown, request: Extract<HostCommand, {
|
|
85
|
+
type: 'run.timeline';
|
|
86
|
+
}>): boolean;
|
|
87
|
+
export type RunProgressSchemaMatchesCore = Assert<Equal<Wire<z.output<typeof runProgress>>, Wire<RunProgressPage>>>;
|
|
88
|
+
export type RunTimelineSchemaMatchesCore = Assert<Equal<Wire<z.output<typeof runTimeline>>, Wire<RunTimelinePage>>>;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { isEventPosition, liveAgentPhases, MAX_RUN_PROGRESS_PAGE_SIZE, RUN_TIMELINE_PAGE_SIZE, } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { approvalIdentity, approvalSummary, runResultIdentity, runStopDetailsSchema, toolApprovalIdentitiesAreUnique, } from './wire-shapes.js';
|
|
4
|
+
const position = z.custom(isEventPosition);
|
|
5
|
+
const runEventPage = {
|
|
6
|
+
...runResultIdentity,
|
|
7
|
+
pluginBlock: runStopDetailsSchema.shape.pluginBlock,
|
|
8
|
+
};
|
|
9
|
+
const runEvents = z.array(z.object({ type: z.string().min(1), position }));
|
|
10
|
+
const id = z.string().min(1);
|
|
11
|
+
const count = z.number().int().nonnegative();
|
|
12
|
+
const metrics = {
|
|
13
|
+
contextWindow: count,
|
|
14
|
+
lastInputTokens: count,
|
|
15
|
+
lastOutputTokens: count,
|
|
16
|
+
lastCachedInputTokens: count,
|
|
17
|
+
outputTokensPerSec: z.number().nonnegative(),
|
|
18
|
+
};
|
|
19
|
+
const liveAgent = z
|
|
20
|
+
.object({
|
|
21
|
+
...metrics,
|
|
22
|
+
memberId: id,
|
|
23
|
+
agentSessionId: id.transform((value) => value),
|
|
24
|
+
phase: z.enum(liveAgentPhases),
|
|
25
|
+
reasoningSummary: z.string(),
|
|
26
|
+
requestId: id.transform((value) => value),
|
|
27
|
+
currentTool: z.string(),
|
|
28
|
+
stepCount: count,
|
|
29
|
+
requestStartedAt: z.string(),
|
|
30
|
+
retryAttempt: count,
|
|
31
|
+
retryMaxAttempts: count,
|
|
32
|
+
lastActivityAt: z.string(),
|
|
33
|
+
})
|
|
34
|
+
.partial();
|
|
35
|
+
const liveAgents = z
|
|
36
|
+
.record(id, liveAgent)
|
|
37
|
+
.refine((agents) => Object.entries(agents).every(([memberId, agent]) => agent.memberId === undefined || agent.memberId === memberId));
|
|
38
|
+
const progressApproval = z.object({
|
|
39
|
+
...approvalSummary,
|
|
40
|
+
toolCallId: approvalIdentity.toolCallId,
|
|
41
|
+
turnId: id,
|
|
42
|
+
toolName: id,
|
|
43
|
+
memberId: id.optional(),
|
|
44
|
+
expiresAt: z.string(),
|
|
45
|
+
});
|
|
46
|
+
const runProgress = z.object({
|
|
47
|
+
...runEventPage,
|
|
48
|
+
events: runEvents.max(MAX_RUN_PROGRESS_PAGE_SIZE),
|
|
49
|
+
pauseReason: runStopDetailsSchema.shape.pauseReason,
|
|
50
|
+
cursor: position,
|
|
51
|
+
through: position.optional(),
|
|
52
|
+
hasMore: z.boolean(),
|
|
53
|
+
draft: z.object({ requestId: id, revision: count, text: z.string() }).optional(),
|
|
54
|
+
liveAgents: liveAgents.optional(),
|
|
55
|
+
telemetry: z.record(id, z.object(metrics).partial()).optional(),
|
|
56
|
+
pendingApprovals: z.array(progressApproval).refine(toolApprovalIdentitiesAreUnique).optional(),
|
|
57
|
+
});
|
|
58
|
+
const runTimeline = z.object({
|
|
59
|
+
...runEventPage,
|
|
60
|
+
events: runEvents.max(RUN_TIMELINE_PAGE_SIZE),
|
|
61
|
+
nextAfter: position.optional(),
|
|
62
|
+
});
|
|
63
|
+
function eventsAdvanceAfter(events, start) {
|
|
64
|
+
let previous = start;
|
|
65
|
+
for (const event of events) {
|
|
66
|
+
const position = BigInt(event.position);
|
|
67
|
+
if (position <= previous)
|
|
68
|
+
return false;
|
|
69
|
+
previous = position;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
export function parseRunProgressResult(value, request) {
|
|
74
|
+
const result = runProgress.safeParse(value);
|
|
75
|
+
if (!result.success)
|
|
76
|
+
return undefined;
|
|
77
|
+
const page = result.data;
|
|
78
|
+
if (!request)
|
|
79
|
+
return page;
|
|
80
|
+
if (page.runId !== request.runId)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (request.limit !== undefined && page.events.length > request.limit)
|
|
83
|
+
return undefined;
|
|
84
|
+
const start = BigInt(request.after);
|
|
85
|
+
const cursor = BigInt(page.cursor);
|
|
86
|
+
if (cursor < start || (page.hasMore && cursor === start))
|
|
87
|
+
return undefined;
|
|
88
|
+
if (page.through !== undefined) {
|
|
89
|
+
const through = BigInt(page.through);
|
|
90
|
+
const hasMore = cursor < through;
|
|
91
|
+
if (page.hasMore !== hasMore || (cursor > through && cursor !== start))
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const last = page.events.at(-1);
|
|
95
|
+
if (last && BigInt(last.position) > cursor)
|
|
96
|
+
return undefined;
|
|
97
|
+
return eventsAdvanceAfter(page.events, start) ? page : undefined;
|
|
98
|
+
}
|
|
99
|
+
export function validRunTimelineResult(value, request) {
|
|
100
|
+
const result = runTimeline.safeParse(value);
|
|
101
|
+
if (!result.success)
|
|
102
|
+
return false;
|
|
103
|
+
const { runId, events, nextAfter } = result.data;
|
|
104
|
+
return (runId === request.runId &&
|
|
105
|
+
(nextAfter === undefined || nextAfter === events.at(-1)?.position) &&
|
|
106
|
+
eventsAdvanceAfter(events, BigInt(request.after)));
|
|
107
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const runQueryResult: z.ZodObject<{
|
|
3
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
4
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
5
|
+
code: z.ZodString;
|
|
6
|
+
diagnosticId: z.ZodString;
|
|
7
|
+
}, z.core.$strip>>;
|
|
8
|
+
turns: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
status: z.ZodString;
|
|
11
|
+
}, z.core.$strip>>>>;
|
|
12
|
+
steps: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
kind: z.ZodString;
|
|
15
|
+
status: z.ZodString;
|
|
16
|
+
}, z.core.$strip>>>>;
|
|
17
|
+
tools: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
18
|
+
call: z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
toolName: z.ZodString;
|
|
21
|
+
arguments: z.ZodOptional<z.ZodUnknown>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
status: z.ZodString;
|
|
24
|
+
memberId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
26
|
+
effect: z.ZodOptional<z.ZodString>;
|
|
27
|
+
outcome: z.ZodObject<{
|
|
28
|
+
status: z.ZodString;
|
|
29
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
30
|
+
code: z.ZodString;
|
|
31
|
+
message: z.ZodString;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
lastFailure: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
error: z.ZodObject<{
|
|
37
|
+
code: z.ZodString;
|
|
38
|
+
message: z.ZodString;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
approval: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
status: z.ZodString;
|
|
43
|
+
request: z.ZodObject<{
|
|
44
|
+
toolCallId: z.ZodOptional<z.ZodString>;
|
|
45
|
+
approvalId: z.ZodString;
|
|
46
|
+
resources: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
47
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
decision: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
decidedAt: z.ZodString;
|
|
51
|
+
approvalId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
toolCallId: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>>;
|
|
54
|
+
}, z.core.$strip>>;
|
|
55
|
+
}, z.core.$strip>>>>;
|
|
56
|
+
pauseReason: z.ZodOptional<z.ZodString>;
|
|
57
|
+
pluginBlock: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
code: z.ZodString;
|
|
59
|
+
message: z.ZodString;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
runId: z.ZodString;
|
|
62
|
+
status: z.ZodString;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export type RunQueryResult = Readonly<z.output<typeof runQueryResult>>;
|
|
65
|
+
export declare function validRunQueryResult(value: unknown, runId: string): boolean;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { approvalIdentity, approvalSummary, runResultIdentity, runStopDetailsSchema, toolApprovalIdentitiesAreUnique, } from './wire-shapes.js';
|
|
3
|
+
const toolError = z.object({ code: z.string(), message: z.string() });
|
|
4
|
+
const toolDetails = z
|
|
5
|
+
.object({
|
|
6
|
+
call: z.object({
|
|
7
|
+
id: approvalIdentity.toolCallId,
|
|
8
|
+
toolName: z.string(),
|
|
9
|
+
arguments: z.unknown().optional(),
|
|
10
|
+
}),
|
|
11
|
+
status: z.string(),
|
|
12
|
+
memberId: z.string().optional(),
|
|
13
|
+
result: z
|
|
14
|
+
.object({
|
|
15
|
+
effect: z.string().optional(),
|
|
16
|
+
outcome: z.object({ status: z.string(), error: toolError.optional() }),
|
|
17
|
+
})
|
|
18
|
+
.optional(),
|
|
19
|
+
lastFailure: z.object({ error: toolError }).optional(),
|
|
20
|
+
approval: z
|
|
21
|
+
.object({
|
|
22
|
+
status: z.string(),
|
|
23
|
+
request: z
|
|
24
|
+
.object({ ...approvalSummary, toolCallId: approvalIdentity.toolCallId })
|
|
25
|
+
.partial({ resources: true, reason: true, toolCallId: true }),
|
|
26
|
+
decision: z
|
|
27
|
+
.object({ ...approvalIdentity, decidedAt: z.string() })
|
|
28
|
+
.partial({ approvalId: true, toolCallId: true })
|
|
29
|
+
.optional(),
|
|
30
|
+
})
|
|
31
|
+
.optional(),
|
|
32
|
+
})
|
|
33
|
+
.refine(({ call, approval }) => {
|
|
34
|
+
if (!approval)
|
|
35
|
+
return true;
|
|
36
|
+
const { request, decision } = approval;
|
|
37
|
+
return ((request.toolCallId === undefined || request.toolCallId === call.id) &&
|
|
38
|
+
(decision?.toolCallId === undefined || decision.toolCallId === call.id) &&
|
|
39
|
+
(decision?.approvalId === undefined || decision.approvalId === request.approvalId));
|
|
40
|
+
});
|
|
41
|
+
const runQueryResult = z.object({
|
|
42
|
+
...runResultIdentity,
|
|
43
|
+
...runStopDetailsSchema.shape,
|
|
44
|
+
startedAt: z
|
|
45
|
+
.string()
|
|
46
|
+
.refine((value) => Number.isFinite(Date.parse(value)))
|
|
47
|
+
.optional(),
|
|
48
|
+
error: z.object({ code: z.string(), diagnosticId: z.string() }).optional(),
|
|
49
|
+
turns: z
|
|
50
|
+
.array(z.object({ id: z.string(), status: z.string() }))
|
|
51
|
+
.readonly()
|
|
52
|
+
.optional(),
|
|
53
|
+
steps: z
|
|
54
|
+
.array(z.object({ id: z.string(), kind: z.string(), status: z.string() }))
|
|
55
|
+
.readonly()
|
|
56
|
+
.optional(),
|
|
57
|
+
tools: z
|
|
58
|
+
.array(toolDetails)
|
|
59
|
+
.refine((tools) => toolApprovalIdentitiesAreUnique(tools.map(({ call, approval }) => ({
|
|
60
|
+
toolCallId: call.id,
|
|
61
|
+
approvalId: approval?.request.approvalId,
|
|
62
|
+
}))))
|
|
63
|
+
.readonly()
|
|
64
|
+
.optional(),
|
|
65
|
+
});
|
|
66
|
+
export function validRunQueryResult(value, runId) {
|
|
67
|
+
const result = runQueryResult.safeParse(value);
|
|
68
|
+
return result.success && result.data.runId === runId;
|
|
69
|
+
}
|