@maiaos/cli 0.1.0-canary.44938d4.manual.1
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 +382 -0
- package/dist/bin/maia.NOTICES.txt +31 -0
- package/dist/bin/maia.cdx.json +138 -0
- package/dist/bin/maia.mjs +115 -0
- package/dist/command-line/arguments.d.ts +21 -0
- package/dist/command-line/arguments.js +99 -0
- package/dist/command-line/context.d.ts +112 -0
- package/dist/command-line/context.js +2 -0
- package/dist/command-line/help.d.ts +36 -0
- package/dist/command-line/help.js +267 -0
- package/dist/command-line/output.d.ts +2111 -0
- package/dist/command-line/output.js +643 -0
- package/dist/command-line/stdin.d.ts +7 -0
- package/dist/command-line/stdin.js +34 -0
- package/dist/command-receipt/command.d.ts +3 -0
- package/dist/command-receipt/command.js +63 -0
- package/dist/command-receipt/compact-list.d.ts +18 -0
- package/dist/command-receipt/compact-list.js +18 -0
- package/dist/context/client.d.ts +4 -0
- package/dist/context/client.js +19 -0
- package/dist/context/commands.d.ts +3 -0
- package/dist/context/commands.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +202 -0
- package/dist/integration-authorization/client.d.ts +16 -0
- package/dist/integration-authorization/client.js +30 -0
- package/dist/integration-authorization/commands.d.ts +3 -0
- package/dist/integration-authorization/commands.js +92 -0
- package/dist/local-node/client.d.ts +31 -0
- package/dist/local-node/client.js +99 -0
- package/dist/orchestration/client.d.ts +59 -0
- package/dist/orchestration/client.js +66 -0
- package/dist/orchestration/commands.d.ts +3 -0
- package/dist/orchestration/commands.js +336 -0
- package/dist/orchestration/compact-aggregate.d.ts +123 -0
- package/dist/orchestration/compact-aggregate.js +110 -0
- package/dist/orchestration/compact-run-list.d.ts +19 -0
- package/dist/orchestration/compact-run-list.js +16 -0
- package/dist/project-workspace/client.d.ts +43 -0
- package/dist/project-workspace/client.js +54 -0
- package/dist/project-workspace/commands.d.ts +5 -0
- package/dist/project-workspace/commands.js +239 -0
- package/dist/runtime/client.d.ts +6 -0
- package/dist/runtime/client.js +10 -0
- package/dist/runtime/command.d.ts +3 -0
- package/dist/runtime/command.js +20 -0
- package/dist/session/client.d.ts +32 -0
- package/dist/session/client.js +30 -0
- package/dist/session/commands.d.ts +3 -0
- package/dist/session/commands.js +160 -0
- package/dist/status/client.d.ts +5 -0
- package/dist/status/client.js +15 -0
- package/dist/status/command.d.ts +3 -0
- package/dist/status/command.js +17 -0
- package/dist/status/compact.d.ts +31 -0
- package/dist/status/compact.js +46 -0
- package/dist/terminal/arguments.d.ts +12 -0
- package/dist/terminal/arguments.js +79 -0
- package/dist/terminal/client.d.ts +45 -0
- package/dist/terminal/client.js +48 -0
- package/dist/terminal/commands.d.ts +3 -0
- package/dist/terminal/commands.js +151 -0
- package/dist/terminal/compact-list.d.ts +148 -0
- package/dist/terminal/compact-list.js +152 -0
- package/dist/terminal/control-commands.d.ts +7 -0
- package/dist/terminal/control-commands.js +211 -0
- package/dist/turn/client.d.ts +17 -0
- package/dist/turn/client.js +23 -0
- package/dist/turn/commands.d.ts +3 -0
- package/dist/turn/commands.js +126 -0
- package/dist/turn/prompt.d.ts +2 -0
- package/dist/turn/prompt.js +9 -0
- package/guidance/maia-cli/SKILL.md +75 -0
- package/guidance/maia-orchestration/SKILL.md +54 -0
- package/package.json +50 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { OrchestrationDispatchSettleTerminalResult, OrchestrationDispatchShowResult, OrchestrationInboxAckResult, OrchestrationInboxCheckParameters, OrchestrationInboxCheckResult, OrchestrationQuestionCancelResult, OrchestrationQuestionOpenResult, OrchestrationQuestionReplyResult, OrchestrationRunCreateResult, OrchestrationRunListResult, OrchestrationRunShowResult, OrchestrationTaskGraph, OrchestrationTaskListResult, OrchestrationTaskShowResult } from "@maiaos/sdk";
|
|
2
|
+
import { type CliNodeResult } from "../local-node/client.js";
|
|
3
|
+
type MutationInput = {
|
|
4
|
+
readonly commandId?: string;
|
|
5
|
+
};
|
|
6
|
+
type CreateRunInput = {
|
|
7
|
+
readonly commandId?: string;
|
|
8
|
+
readonly graph: OrchestrationTaskGraph;
|
|
9
|
+
readonly terminalId: string;
|
|
10
|
+
readonly workspaceId: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const createRun: (input: CreateRunInput) => Promise<CliNodeResult<OrchestrationRunCreateResult>>;
|
|
13
|
+
export declare const listRuns: (input: {
|
|
14
|
+
readonly afterCursor: string;
|
|
15
|
+
readonly limit: number;
|
|
16
|
+
readonly workspaceId: string;
|
|
17
|
+
}) => Promise<CliNodeResult<OrchestrationRunListResult>>;
|
|
18
|
+
export declare const showRun: (runId: string) => Promise<CliNodeResult<OrchestrationRunShowResult>>;
|
|
19
|
+
export declare const listTasks: (input: {
|
|
20
|
+
readonly afterCursor: string;
|
|
21
|
+
readonly limit: number;
|
|
22
|
+
readonly runId: string;
|
|
23
|
+
}) => Promise<CliNodeResult<OrchestrationTaskListResult>>;
|
|
24
|
+
export declare const showDispatch: (runId: string) => Promise<CliNodeResult<OrchestrationDispatchShowResult>>;
|
|
25
|
+
export declare const showTask: (input: {
|
|
26
|
+
readonly runId: string;
|
|
27
|
+
readonly taskId: string;
|
|
28
|
+
}) => Promise<CliNodeResult<OrchestrationTaskShowResult>>;
|
|
29
|
+
export declare const checkRunInbox: (input: OrchestrationInboxCheckParameters) => Promise<CliNodeResult<OrchestrationInboxCheckResult>>;
|
|
30
|
+
export declare const acknowledgeRunDelivery: (input: MutationInput & {
|
|
31
|
+
readonly coordinatorEpoch: 1;
|
|
32
|
+
readonly deliveryId: string;
|
|
33
|
+
readonly expectedMailboxRevision: string;
|
|
34
|
+
readonly owner: OrchestrationInboxCheckParameters["owner"];
|
|
35
|
+
readonly runId: string;
|
|
36
|
+
}) => Promise<CliNodeResult<OrchestrationInboxAckResult>>;
|
|
37
|
+
type QuestionScopeInput = MutationInput & {
|
|
38
|
+
readonly coordinatorEpoch: 1;
|
|
39
|
+
readonly dispatchId: string;
|
|
40
|
+
readonly expectedDispatchRevision: string;
|
|
41
|
+
readonly expectedRunRevision: string;
|
|
42
|
+
readonly runId: string;
|
|
43
|
+
};
|
|
44
|
+
export declare const openRunQuestion: (input: QuestionScopeInput & {
|
|
45
|
+
readonly body: string;
|
|
46
|
+
readonly subject: string;
|
|
47
|
+
}) => Promise<CliNodeResult<OrchestrationQuestionOpenResult>>;
|
|
48
|
+
export declare const replyRunQuestion: (input: QuestionScopeInput & {
|
|
49
|
+
readonly answer: string;
|
|
50
|
+
readonly expectedQuestionRevision: string;
|
|
51
|
+
readonly questionId: string;
|
|
52
|
+
}) => Promise<CliNodeResult<OrchestrationQuestionReplyResult>>;
|
|
53
|
+
export declare const cancelRunQuestion: (input: QuestionScopeInput & {
|
|
54
|
+
readonly expectedQuestionRevision: string;
|
|
55
|
+
readonly questionId: string;
|
|
56
|
+
}) => Promise<CliNodeResult<OrchestrationQuestionCancelResult>>;
|
|
57
|
+
export declare const settleRunDispatchTerminal: (input: QuestionScopeInput) => Promise<CliNodeResult<OrchestrationDispatchSettleTerminalResult>>;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { inspectOrchestrationRunCreateAdmission, orchestrationDispatchSettleTerminalParametersSchema, orchestrationDispatchShowParametersSchema, orchestrationInboxAckParametersSchema, orchestrationInboxCheckParametersSchema, orchestrationQuestionCancelParametersSchema, orchestrationQuestionOpenParametersSchema, orchestrationQuestionReplyParametersSchema, orchestrationRunCreateParametersSchema, orchestrationRunListParametersSchema, orchestrationRunShowParametersSchema, orchestrationTaskListParametersSchema, orchestrationTaskShowParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import { invalidNodeInput, newCliIdentifier, runNodeClientOperation, runValidatedNodeOperation, } from "../local-node/client.js";
|
|
3
|
+
const admittedRunCreateParameters = (input, commandId) => {
|
|
4
|
+
const parameters = orchestrationRunCreateParametersSchema.safeParse({
|
|
5
|
+
commandId,
|
|
6
|
+
expectedRevision: "0",
|
|
7
|
+
graph: input.graph,
|
|
8
|
+
terminalId: input.terminalId,
|
|
9
|
+
workspaceId: input.workspaceId,
|
|
10
|
+
});
|
|
11
|
+
if (!parameters.success)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
inspectOrchestrationRunCreateAdmission(parameters.data);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return parameters.data;
|
|
20
|
+
};
|
|
21
|
+
export const createRun = (input) => {
|
|
22
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
23
|
+
const parameters = admittedRunCreateParameters(input, commandId);
|
|
24
|
+
if (parameters === undefined)
|
|
25
|
+
return invalidNodeInput();
|
|
26
|
+
return runNodeClientOperation((client, options) => client.createOrchestrationRun(parameters, options), { commandId });
|
|
27
|
+
};
|
|
28
|
+
export const listRuns = (input) => {
|
|
29
|
+
return runValidatedNodeOperation(input, orchestrationRunListParametersSchema, (client, parameters, options) => client.listOrchestrationRuns(parameters, options));
|
|
30
|
+
};
|
|
31
|
+
export const showRun = (runId) => {
|
|
32
|
+
return runValidatedNodeOperation({ runId }, orchestrationRunShowParametersSchema, (client, parameters, options) => client.showOrchestrationRun(parameters, options));
|
|
33
|
+
};
|
|
34
|
+
export const listTasks = (input) => {
|
|
35
|
+
return runValidatedNodeOperation(input, orchestrationTaskListParametersSchema, (client, parameters, options) => client.listOrchestrationTasks(parameters, options));
|
|
36
|
+
};
|
|
37
|
+
export const showDispatch = (runId) => {
|
|
38
|
+
return runValidatedNodeOperation({ runId }, orchestrationDispatchShowParametersSchema, (client, parameters, options) => client.showOrchestrationDispatch(parameters, options));
|
|
39
|
+
};
|
|
40
|
+
export const showTask = (input) => {
|
|
41
|
+
return runValidatedNodeOperation(input, orchestrationTaskShowParametersSchema, (client, parameters, options) => client.showOrchestrationTask(parameters, options));
|
|
42
|
+
};
|
|
43
|
+
export const checkRunInbox = (input) => {
|
|
44
|
+
return runValidatedNodeOperation(input, orchestrationInboxCheckParametersSchema, (client, parameters, options) => client.checkOrchestrationInbox(parameters, options));
|
|
45
|
+
};
|
|
46
|
+
export const acknowledgeRunDelivery = (input) => {
|
|
47
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
48
|
+
return runValidatedNodeOperation({ ...input, commandId }, orchestrationInboxAckParametersSchema, (client, parameters, options) => client.acknowledgeOrchestrationDelivery(parameters, options), { commandId });
|
|
49
|
+
};
|
|
50
|
+
export const openRunQuestion = (input) => {
|
|
51
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
52
|
+
return runValidatedNodeOperation({ ...input, commandId }, orchestrationQuestionOpenParametersSchema, (client, parameters, options) => client.openOrchestrationQuestion(parameters, options), { commandId });
|
|
53
|
+
};
|
|
54
|
+
export const replyRunQuestion = (input) => {
|
|
55
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
56
|
+
return runValidatedNodeOperation({ ...input, commandId }, orchestrationQuestionReplyParametersSchema, (client, parameters, options) => client.replyOrchestrationQuestion(parameters, options), { commandId });
|
|
57
|
+
};
|
|
58
|
+
export const cancelRunQuestion = (input) => {
|
|
59
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
60
|
+
return runValidatedNodeOperation({ ...input, commandId }, orchestrationQuestionCancelParametersSchema, (client, parameters, options) => client.cancelOrchestrationQuestion(parameters, options), { commandId });
|
|
61
|
+
};
|
|
62
|
+
export const settleRunDispatchTerminal = (input) => {
|
|
63
|
+
const commandId = input.commandId ?? newCliIdentifier("command");
|
|
64
|
+
return runValidatedNodeOperation({ ...input, commandId }, orchestrationDispatchSettleTerminalParametersSchema, (client, parameters, options) => client.settleOrchestrationDispatchTerminal(parameters, options), { commandId });
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { DEFAULT_ORCHESTRATION_TASK_LIST_PAGE_SIZE, orchestrationQuestionOpenParametersSchema, orchestrationQuestionReplyParametersSchema, orchestrationTaskGraphSchema, } from "@maiaos/sdk";
|
|
2
|
+
import { CliArgumentError, parseOptions, readCursor, readExpectedRevision, readPageSize, requirePositionals, } from "../command-line/arguments.js";
|
|
3
|
+
import { writeDispatchSettleResult, writeDispatchShowResult, writeInboxAckResult, writeInboxCheckResult, writeQuestionCancelResult, writeQuestionOpenResult, writeQuestionReplyResult, writeRunCreateResult, writeRunListResult, writeRunShowResult, writeTaskListResult, writeTaskShowResult, } from "../command-line/output.js";
|
|
4
|
+
const requireOption = (parsed, name) => {
|
|
5
|
+
const value = parsed.options.get(name);
|
|
6
|
+
if (value === undefined) {
|
|
7
|
+
throw new CliArgumentError(`Option '${name}' is required.`);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const coordinatorEpoch = (parsed) => {
|
|
12
|
+
if (requireOption(parsed, "--coordinator-epoch") !== "1") {
|
|
13
|
+
throw new CliArgumentError("Option '--coordinator-epoch' must be exactly 1 for local v1.");
|
|
14
|
+
}
|
|
15
|
+
return 1;
|
|
16
|
+
};
|
|
17
|
+
const revision = (parsed, name) => readExpectedRevision(requireOption(parsed, name));
|
|
18
|
+
const mutationCommandId = (parsed) => {
|
|
19
|
+
const commandId = parsed.options.get("--command-id");
|
|
20
|
+
return commandId === undefined ? {} : { commandId };
|
|
21
|
+
};
|
|
22
|
+
const questionScope = (parsed, runId, dispatchId) => ({
|
|
23
|
+
coordinatorEpoch: coordinatorEpoch(parsed),
|
|
24
|
+
dispatchId,
|
|
25
|
+
expectedDispatchRevision: revision(parsed, "--expected-dispatch-revision"),
|
|
26
|
+
expectedRunRevision: revision(parsed, "--expected-run-revision"),
|
|
27
|
+
runId,
|
|
28
|
+
...mutationCommandId(parsed),
|
|
29
|
+
});
|
|
30
|
+
const parseRunCreateScope = (tokens) => {
|
|
31
|
+
const parsed = parseOptions(tokens, new Set(["--command-id"]), new Set(["--graph-stdin"]));
|
|
32
|
+
requirePositionals(parsed.positionals, 2, "maia run create <workspace-id> <terminal-id> --graph-stdin");
|
|
33
|
+
if (!parsed.flags.has("--graph-stdin")) {
|
|
34
|
+
throw new CliArgumentError("Option '--graph-stdin' is required.");
|
|
35
|
+
}
|
|
36
|
+
const [workspaceId, terminalId] = parsed.positionals;
|
|
37
|
+
if (workspaceId === undefined || terminalId === undefined) {
|
|
38
|
+
throw new CliArgumentError("The Run scope is incomplete.");
|
|
39
|
+
}
|
|
40
|
+
return { parsed, terminalId, workspaceId };
|
|
41
|
+
};
|
|
42
|
+
const readTaskGraph = async (context) => {
|
|
43
|
+
if (context.io.stdin === undefined) {
|
|
44
|
+
throw new CliArgumentError("Standard input is unavailable.");
|
|
45
|
+
}
|
|
46
|
+
const graphText = await context.io.stdin({
|
|
47
|
+
label: "orchestration graph",
|
|
48
|
+
maxBytes: 64 * 1024,
|
|
49
|
+
maxChunks: 1024,
|
|
50
|
+
});
|
|
51
|
+
let rawGraph;
|
|
52
|
+
try {
|
|
53
|
+
rawGraph = JSON.parse(graphText);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new CliArgumentError("Standard input must be one valid JSON graph.");
|
|
57
|
+
}
|
|
58
|
+
const graph = orchestrationTaskGraphSchema.safeParse(rawGraph);
|
|
59
|
+
if (!graph.success) {
|
|
60
|
+
throw new CliArgumentError("Standard input is not a valid Task graph.");
|
|
61
|
+
}
|
|
62
|
+
return graph.data;
|
|
63
|
+
};
|
|
64
|
+
const runCreate = async (tokens, context) => {
|
|
65
|
+
const { parsed, terminalId, workspaceId } = parseRunCreateScope(tokens);
|
|
66
|
+
const graph = await readTaskGraph(context);
|
|
67
|
+
const result = await context.dependencies.createRun({
|
|
68
|
+
graph,
|
|
69
|
+
terminalId,
|
|
70
|
+
workspaceId,
|
|
71
|
+
...mutationCommandId(parsed),
|
|
72
|
+
});
|
|
73
|
+
return writeRunCreateResult(result, context);
|
|
74
|
+
};
|
|
75
|
+
const runShow = async (tokens, context) => {
|
|
76
|
+
const parsed = parseOptions(tokens, new Set());
|
|
77
|
+
requirePositionals(parsed.positionals, 1, "maia run show <run-id>");
|
|
78
|
+
const runId = parsed.positionals[0];
|
|
79
|
+
if (runId === undefined)
|
|
80
|
+
throw new CliArgumentError("The Run ID is missing.");
|
|
81
|
+
const result = await context.dependencies.showRun(runId);
|
|
82
|
+
return writeRunShowResult(result, context);
|
|
83
|
+
};
|
|
84
|
+
const runList = async (tokens, context) => {
|
|
85
|
+
const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--workspace"]));
|
|
86
|
+
requirePositionals(parsed.positionals, 0, "maia run list --workspace <id>");
|
|
87
|
+
const workspaceId = parsed.options.get("--workspace");
|
|
88
|
+
if (workspaceId === undefined) {
|
|
89
|
+
throw new CliArgumentError("Option '--workspace' is required.");
|
|
90
|
+
}
|
|
91
|
+
const result = await context.dependencies.listRuns({
|
|
92
|
+
afterCursor: readCursor(parsed.options.get("--after")),
|
|
93
|
+
limit: readPageSize(parsed.options.get("--limit")),
|
|
94
|
+
workspaceId,
|
|
95
|
+
});
|
|
96
|
+
return writeRunListResult(result, context, workspaceId);
|
|
97
|
+
};
|
|
98
|
+
const readTaskListPageSize = (value) => {
|
|
99
|
+
if (value === undefined)
|
|
100
|
+
return DEFAULT_ORCHESTRATION_TASK_LIST_PAGE_SIZE;
|
|
101
|
+
if (!/^(?:[1-9]|[12]\d|3[0-2])$/u.test(value)) {
|
|
102
|
+
throw new CliArgumentError("Option '--limit' must be an integer from 1 to 32.");
|
|
103
|
+
}
|
|
104
|
+
return Number(value);
|
|
105
|
+
};
|
|
106
|
+
const runTaskList = async (tokens, context) => {
|
|
107
|
+
const parsed = parseOptions(tokens, new Set(["--after", "--limit"]));
|
|
108
|
+
requirePositionals(parsed.positionals, 1, "maia run task list <run-id>");
|
|
109
|
+
const runId = parsed.positionals[0];
|
|
110
|
+
if (runId === undefined)
|
|
111
|
+
throw new CliArgumentError("The Run ID is missing.");
|
|
112
|
+
const result = await context.dependencies.listTasks({
|
|
113
|
+
afterCursor: readCursor(parsed.options.get("--after")),
|
|
114
|
+
limit: readTaskListPageSize(parsed.options.get("--limit")),
|
|
115
|
+
runId,
|
|
116
|
+
});
|
|
117
|
+
return writeTaskListResult(result, context);
|
|
118
|
+
};
|
|
119
|
+
const runTaskShow = async (tokens, context) => {
|
|
120
|
+
const parsed = parseOptions(tokens, new Set());
|
|
121
|
+
requirePositionals(parsed.positionals, 2, "maia run task show <run-id> <task-id>");
|
|
122
|
+
const [runId, taskId] = parsed.positionals;
|
|
123
|
+
if (runId === undefined || taskId === undefined) {
|
|
124
|
+
throw new CliArgumentError("The Task show scope is incomplete.");
|
|
125
|
+
}
|
|
126
|
+
const result = await context.dependencies.showTask({ runId, taskId });
|
|
127
|
+
return writeTaskShowResult(result, context);
|
|
128
|
+
};
|
|
129
|
+
const inboxOwner = (parsed, runId) => {
|
|
130
|
+
const kind = requireOption(parsed, "--owner");
|
|
131
|
+
if (kind !== "run" && kind !== "dispatch") {
|
|
132
|
+
throw new CliArgumentError("Option '--owner' must be run or dispatch.");
|
|
133
|
+
}
|
|
134
|
+
const id = requireOption(parsed, "--owner-id");
|
|
135
|
+
if (kind === "run" && id !== runId) {
|
|
136
|
+
throw new CliArgumentError("A Run inbox owner ID must equal the Run ID.");
|
|
137
|
+
}
|
|
138
|
+
return { id, kind };
|
|
139
|
+
};
|
|
140
|
+
const inboxCheck = async (tokens, context) => {
|
|
141
|
+
const parsed = parseOptions(tokens, new Set(["--coordinator-epoch", "--limit", "--owner", "--owner-id"]));
|
|
142
|
+
requirePositionals(parsed.positionals, 1, "maia run inbox check <run-id>");
|
|
143
|
+
const runId = parsed.positionals[0];
|
|
144
|
+
if (runId === undefined)
|
|
145
|
+
throw new CliArgumentError("The Run ID is missing.");
|
|
146
|
+
const limitValue = parsed.options.get("--limit") ?? "8";
|
|
147
|
+
if (!/^(?:[1-9]|1[0-6])$/u.test(limitValue)) {
|
|
148
|
+
throw new CliArgumentError("Option '--limit' must be from 1 to 16.");
|
|
149
|
+
}
|
|
150
|
+
const result = await context.dependencies.checkRunInbox({
|
|
151
|
+
coordinatorEpoch: coordinatorEpoch(parsed),
|
|
152
|
+
limit: Number(limitValue),
|
|
153
|
+
owner: inboxOwner(parsed, runId),
|
|
154
|
+
runId,
|
|
155
|
+
});
|
|
156
|
+
return writeInboxCheckResult(result, context);
|
|
157
|
+
};
|
|
158
|
+
const inboxAckOptions = new Set([
|
|
159
|
+
"--command-id",
|
|
160
|
+
"--coordinator-epoch",
|
|
161
|
+
"--delivery-id",
|
|
162
|
+
"--expected-mailbox-revision",
|
|
163
|
+
"--owner",
|
|
164
|
+
"--owner-id",
|
|
165
|
+
]);
|
|
166
|
+
const inboxAck = async (tokens, context) => {
|
|
167
|
+
const parsed = parseOptions(tokens, inboxAckOptions);
|
|
168
|
+
requirePositionals(parsed.positionals, 1, "maia run inbox ack <run-id>");
|
|
169
|
+
const runId = parsed.positionals[0];
|
|
170
|
+
if (runId === undefined)
|
|
171
|
+
throw new CliArgumentError("The Run ID is missing.");
|
|
172
|
+
const result = await context.dependencies.acknowledgeRunDelivery({
|
|
173
|
+
coordinatorEpoch: coordinatorEpoch(parsed),
|
|
174
|
+
deliveryId: requireOption(parsed, "--delivery-id"),
|
|
175
|
+
expectedMailboxRevision: revision(parsed, "--expected-mailbox-revision"),
|
|
176
|
+
owner: inboxOwner(parsed, runId),
|
|
177
|
+
runId,
|
|
178
|
+
...mutationCommandId(parsed),
|
|
179
|
+
});
|
|
180
|
+
return writeInboxAckResult(result, context);
|
|
181
|
+
};
|
|
182
|
+
const questionScopeOptions = [
|
|
183
|
+
"--command-id",
|
|
184
|
+
"--coordinator-epoch",
|
|
185
|
+
"--expected-dispatch-revision",
|
|
186
|
+
"--expected-run-revision",
|
|
187
|
+
];
|
|
188
|
+
const runDispatchIdentifiers = (parsed, usage, label) => {
|
|
189
|
+
requirePositionals(parsed.positionals, 2, usage);
|
|
190
|
+
const [runId, dispatchId] = parsed.positionals;
|
|
191
|
+
if (runId === undefined || dispatchId === undefined) {
|
|
192
|
+
throw new CliArgumentError(`The ${label} scope is incomplete.`);
|
|
193
|
+
}
|
|
194
|
+
return { dispatchId, runId };
|
|
195
|
+
};
|
|
196
|
+
const questionIdentifiers = (parsed, usage) => {
|
|
197
|
+
requirePositionals(parsed.positionals, 3, usage);
|
|
198
|
+
const [runId, dispatchId, questionId] = parsed.positionals;
|
|
199
|
+
if (runId === undefined ||
|
|
200
|
+
dispatchId === undefined ||
|
|
201
|
+
questionId === undefined) {
|
|
202
|
+
throw new CliArgumentError("The Question scope is incomplete.");
|
|
203
|
+
}
|
|
204
|
+
return { dispatchId, questionId, runId };
|
|
205
|
+
};
|
|
206
|
+
const parseQuestionOpen = (tokens) => {
|
|
207
|
+
const parsed = parseOptions(tokens, new Set([...questionScopeOptions, "--subject"]), new Set(["--body-stdin"]));
|
|
208
|
+
const identifiers = runDispatchIdentifiers(parsed, "maia run question open <run-id> <dispatch-id>", "Question");
|
|
209
|
+
if (!parsed.flags.has("--body-stdin")) {
|
|
210
|
+
throw new CliArgumentError("Option '--body-stdin' is required.");
|
|
211
|
+
}
|
|
212
|
+
const input = {
|
|
213
|
+
...questionScope(parsed, identifiers.runId, identifiers.dispatchId),
|
|
214
|
+
subject: requireOption(parsed, "--subject"),
|
|
215
|
+
};
|
|
216
|
+
if (!orchestrationQuestionOpenParametersSchema.safeParse({
|
|
217
|
+
...input,
|
|
218
|
+
body: "validated-after-metadata",
|
|
219
|
+
commandId: input.commandId ?? "command_metadata_validation",
|
|
220
|
+
}).success) {
|
|
221
|
+
throw new CliArgumentError("The Question-open metadata is invalid.");
|
|
222
|
+
}
|
|
223
|
+
return input;
|
|
224
|
+
};
|
|
225
|
+
const questionOpen = async (tokens, context) => {
|
|
226
|
+
const input = parseQuestionOpen(tokens);
|
|
227
|
+
if (context.io.stdin === undefined) {
|
|
228
|
+
throw new CliArgumentError("Standard input is unavailable.");
|
|
229
|
+
}
|
|
230
|
+
const body = await context.io.stdin({
|
|
231
|
+
label: "Question body",
|
|
232
|
+
maxBytes: 4 * 1024,
|
|
233
|
+
maxChunks: 256,
|
|
234
|
+
});
|
|
235
|
+
const result = await context.dependencies.openRunQuestion({
|
|
236
|
+
...input,
|
|
237
|
+
body,
|
|
238
|
+
});
|
|
239
|
+
return writeQuestionOpenResult(result, context);
|
|
240
|
+
};
|
|
241
|
+
const parseQuestionReply = (tokens) => {
|
|
242
|
+
const parsed = parseOptions(tokens, new Set([...questionScopeOptions, "--expected-question-revision"]), new Set(["--answer-stdin"]));
|
|
243
|
+
const identifiers = questionIdentifiers(parsed, "maia run question reply <run-id> <dispatch-id> <question-id>");
|
|
244
|
+
if (!parsed.flags.has("--answer-stdin")) {
|
|
245
|
+
throw new CliArgumentError("Option '--answer-stdin' is required.");
|
|
246
|
+
}
|
|
247
|
+
const input = {
|
|
248
|
+
...questionScope(parsed, identifiers.runId, identifiers.dispatchId),
|
|
249
|
+
expectedQuestionRevision: revision(parsed, "--expected-question-revision"),
|
|
250
|
+
questionId: identifiers.questionId,
|
|
251
|
+
};
|
|
252
|
+
if (!orchestrationQuestionReplyParametersSchema.safeParse({
|
|
253
|
+
...input,
|
|
254
|
+
answer: "validated-after-metadata",
|
|
255
|
+
commandId: input.commandId ?? "command_metadata_validation",
|
|
256
|
+
}).success) {
|
|
257
|
+
throw new CliArgumentError("The Question-reply metadata is invalid.");
|
|
258
|
+
}
|
|
259
|
+
return input;
|
|
260
|
+
};
|
|
261
|
+
const questionReply = async (tokens, context) => {
|
|
262
|
+
const input = parseQuestionReply(tokens);
|
|
263
|
+
if (context.io.stdin === undefined) {
|
|
264
|
+
throw new CliArgumentError("Standard input is unavailable.");
|
|
265
|
+
}
|
|
266
|
+
const answer = await context.io.stdin({
|
|
267
|
+
label: "Question answer",
|
|
268
|
+
maxBytes: 4 * 1024,
|
|
269
|
+
maxChunks: 256,
|
|
270
|
+
});
|
|
271
|
+
const result = await context.dependencies.replyRunQuestion({
|
|
272
|
+
...input,
|
|
273
|
+
answer,
|
|
274
|
+
});
|
|
275
|
+
return writeQuestionReplyResult(result, context);
|
|
276
|
+
};
|
|
277
|
+
const questionCancel = async (tokens, context) => {
|
|
278
|
+
const parsed = parseOptions(tokens, new Set([...questionScopeOptions, "--expected-question-revision"]));
|
|
279
|
+
const { dispatchId, questionId, runId } = questionIdentifiers(parsed, "maia run question cancel <run-id> <dispatch-id> <question-id>");
|
|
280
|
+
const result = await context.dependencies.cancelRunQuestion({
|
|
281
|
+
...questionScope(parsed, runId, dispatchId),
|
|
282
|
+
expectedQuestionRevision: revision(parsed, "--expected-question-revision"),
|
|
283
|
+
questionId,
|
|
284
|
+
});
|
|
285
|
+
return writeQuestionCancelResult(result, context);
|
|
286
|
+
};
|
|
287
|
+
const runDispatchShow = async (tokens, context) => {
|
|
288
|
+
const parsed = parseOptions(tokens, new Set());
|
|
289
|
+
requirePositionals(parsed.positionals, 1, "maia run dispatch show <run-id>");
|
|
290
|
+
const runId = parsed.positionals[0];
|
|
291
|
+
if (runId === undefined)
|
|
292
|
+
throw new CliArgumentError("The Run ID is missing.");
|
|
293
|
+
const result = await context.dependencies.showDispatch(runId);
|
|
294
|
+
return writeDispatchShowResult(result, context);
|
|
295
|
+
};
|
|
296
|
+
const dispatchSettle = async (tokens, context) => {
|
|
297
|
+
const parsed = parseOptions(tokens, new Set(questionScopeOptions));
|
|
298
|
+
const { dispatchId, runId } = runDispatchIdentifiers(parsed, "maia run dispatch settle-terminal <run-id> <dispatch-id>", "Dispatch");
|
|
299
|
+
const result = await context.dependencies.settleRunDispatchTerminal(questionScope(parsed, runId, dispatchId));
|
|
300
|
+
return writeDispatchSettleResult(result, context);
|
|
301
|
+
};
|
|
302
|
+
const runDispatchCommand = (nested, tokens, context) => {
|
|
303
|
+
if (nested === "show")
|
|
304
|
+
return runDispatchShow(tokens, context);
|
|
305
|
+
if (nested === "settle-terminal")
|
|
306
|
+
return dispatchSettle(tokens, context);
|
|
307
|
+
throw new CliArgumentError("Usage: maia run <create|list|show|task list|task show|inbox check|inbox ack|question open|question reply|question cancel|dispatch show|dispatch settle-terminal>");
|
|
308
|
+
};
|
|
309
|
+
export const runOrchestrationCommand = (tokens, context) => {
|
|
310
|
+
const [subcommand, nested, ...rest] = tokens;
|
|
311
|
+
if (subcommand === "create")
|
|
312
|
+
return runCreate(tokens.slice(1), context);
|
|
313
|
+
if (subcommand === "list")
|
|
314
|
+
return runList(tokens.slice(1), context);
|
|
315
|
+
if (subcommand === "show")
|
|
316
|
+
return runShow(tokens.slice(1), context);
|
|
317
|
+
if (subcommand === "task" && nested === "list")
|
|
318
|
+
return runTaskList(rest, context);
|
|
319
|
+
if (subcommand === "task" && nested === "show")
|
|
320
|
+
return runTaskShow(rest, context);
|
|
321
|
+
if (subcommand === "inbox" && nested === "check")
|
|
322
|
+
return inboxCheck(rest, context);
|
|
323
|
+
if (subcommand === "inbox" && nested === "ack")
|
|
324
|
+
return inboxAck(rest, context);
|
|
325
|
+
if (subcommand === "question" && nested === "open")
|
|
326
|
+
return questionOpen(rest, context);
|
|
327
|
+
if (subcommand === "question" && nested === "reply")
|
|
328
|
+
return questionReply(rest, context);
|
|
329
|
+
if (subcommand === "question" && nested === "cancel")
|
|
330
|
+
return questionCancel(rest, context);
|
|
331
|
+
if (subcommand === "dispatch") {
|
|
332
|
+
return runDispatchCommand(nested, rest, context);
|
|
333
|
+
}
|
|
334
|
+
throw new CliArgumentError("Usage: maia run <create|list|show|task list|task show|inbox check|inbox ack|question open|question reply|question cancel|dispatch show|dispatch settle-terminal>");
|
|
335
|
+
};
|
|
336
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { OrchestrationAggregate, OrchestrationDelivery, OrchestrationDispatchSettleTerminalResult, OrchestrationDispatchShowResult, OrchestrationInboxAckResult, OrchestrationQuestion, OrchestrationQuestionCancelResult, OrchestrationQuestionOpenResult, OrchestrationQuestionReplyResult, OrchestrationRunCreateResult, OrchestrationRunShowResult } from "@maiaos/sdk";
|
|
2
|
+
type ProtocolDispatch = OrchestrationDispatchShowResult["dispatch"];
|
|
3
|
+
type ProtocolReceipt = OrchestrationRunCreateResult["receipt"];
|
|
4
|
+
export type CliDispatchShowDispatch = {
|
|
5
|
+
readonly attemptId: ProtocolDispatch["attemptId"];
|
|
6
|
+
readonly failure?: Extract<ProtocolDispatch, {
|
|
7
|
+
readonly state: "failed";
|
|
8
|
+
}>["failure"];
|
|
9
|
+
readonly id: ProtocolDispatch["id"];
|
|
10
|
+
readonly revision: ProtocolDispatch["revision"];
|
|
11
|
+
readonly runId: ProtocolDispatch["runId"];
|
|
12
|
+
readonly state: ProtocolDispatch["state"];
|
|
13
|
+
readonly taskId: ProtocolDispatch["taskId"];
|
|
14
|
+
readonly terminalId: ProtocolDispatch["terminalId"];
|
|
15
|
+
};
|
|
16
|
+
export type CliCompactMailbox = {
|
|
17
|
+
readonly id: OrchestrationAggregate["mailboxes"][number]["id"];
|
|
18
|
+
readonly owner: OrchestrationAggregate["mailboxes"][number]["owner"];
|
|
19
|
+
readonly revision: OrchestrationAggregate["mailboxes"][number]["revision"];
|
|
20
|
+
};
|
|
21
|
+
export type CliCompactQuestion = {
|
|
22
|
+
readonly answer?: Extract<OrchestrationQuestion, {
|
|
23
|
+
readonly state: "answered";
|
|
24
|
+
}>["answer"];
|
|
25
|
+
readonly body: OrchestrationQuestion["body"];
|
|
26
|
+
readonly id: OrchestrationQuestion["id"];
|
|
27
|
+
readonly revision: OrchestrationQuestion["revision"];
|
|
28
|
+
readonly state: OrchestrationQuestion["state"];
|
|
29
|
+
readonly subject: OrchestrationQuestion["subject"];
|
|
30
|
+
readonly taskId: OrchestrationQuestion["taskId"];
|
|
31
|
+
};
|
|
32
|
+
export type CliCompactAggregate = {
|
|
33
|
+
readonly attempt: {
|
|
34
|
+
readonly id: OrchestrationAggregate["attempt"]["id"];
|
|
35
|
+
readonly revision: OrchestrationAggregate["attempt"]["revision"];
|
|
36
|
+
readonly state: OrchestrationAggregate["attempt"]["state"];
|
|
37
|
+
readonly taskId: OrchestrationAggregate["attempt"]["taskId"];
|
|
38
|
+
};
|
|
39
|
+
readonly dispatch: CliDispatchShowDispatch;
|
|
40
|
+
readonly mailboxes: readonly CliCompactMailbox[];
|
|
41
|
+
readonly question?: CliCompactQuestion;
|
|
42
|
+
readonly run: {
|
|
43
|
+
readonly dispatchTaskId: OrchestrationAggregate["run"]["dispatchTaskId"];
|
|
44
|
+
readonly id: OrchestrationAggregate["run"]["id"];
|
|
45
|
+
readonly revision: OrchestrationAggregate["run"]["revision"];
|
|
46
|
+
readonly rootTaskId: OrchestrationAggregate["run"]["rootTaskId"];
|
|
47
|
+
readonly state: OrchestrationAggregate["run"]["state"];
|
|
48
|
+
readonly terminalId: OrchestrationAggregate["run"]["terminalId"];
|
|
49
|
+
readonly workspaceId: OrchestrationAggregate["run"]["workspaceId"];
|
|
50
|
+
};
|
|
51
|
+
readonly taskCount: number;
|
|
52
|
+
};
|
|
53
|
+
export type CliCompactDelivery = {
|
|
54
|
+
readonly deliveryId: OrchestrationDelivery["id"];
|
|
55
|
+
readonly mailboxId: OrchestrationDelivery["mailboxId"];
|
|
56
|
+
readonly questionId?: string;
|
|
57
|
+
readonly sequence: OrchestrationDelivery["sequence"];
|
|
58
|
+
readonly subject: OrchestrationDelivery["message"]["subject"];
|
|
59
|
+
readonly type: OrchestrationDelivery["message"]["type"];
|
|
60
|
+
};
|
|
61
|
+
export type CliCompactReceipt = {
|
|
62
|
+
readonly aggregateRevision: ProtocolReceipt["aggregateRevision"];
|
|
63
|
+
readonly commandId: ProtocolReceipt["commandId"];
|
|
64
|
+
readonly receiptId: ProtocolReceipt["receiptId"];
|
|
65
|
+
readonly state: ProtocolReceipt["state"];
|
|
66
|
+
readonly target: ProtocolReceipt["target"];
|
|
67
|
+
};
|
|
68
|
+
export type CliRunShowResult = {
|
|
69
|
+
readonly aggregate: CliCompactAggregate;
|
|
70
|
+
readonly command: "run.show";
|
|
71
|
+
};
|
|
72
|
+
export type CliRunCreateResult = {
|
|
73
|
+
readonly aggregate: CliCompactAggregate;
|
|
74
|
+
readonly command: "run.create";
|
|
75
|
+
readonly delivery: OrchestrationRunCreateResult["delivery"];
|
|
76
|
+
readonly initialDelivery: CliCompactDelivery;
|
|
77
|
+
readonly receipt: CliCompactReceipt;
|
|
78
|
+
};
|
|
79
|
+
export type CliQuestionOpenResult = {
|
|
80
|
+
readonly aggregate: CliCompactAggregate;
|
|
81
|
+
readonly command: "run.question.open";
|
|
82
|
+
readonly delivery: CliCompactDelivery;
|
|
83
|
+
readonly receipt: CliCompactReceipt;
|
|
84
|
+
};
|
|
85
|
+
export type CliQuestionReplyResult = {
|
|
86
|
+
readonly aggregate: CliCompactAggregate;
|
|
87
|
+
readonly command: "run.question.reply";
|
|
88
|
+
readonly delivery: CliCompactDelivery;
|
|
89
|
+
readonly receipt: CliCompactReceipt;
|
|
90
|
+
};
|
|
91
|
+
export type CliQuestionCancelResult = {
|
|
92
|
+
readonly aggregate: CliCompactAggregate;
|
|
93
|
+
readonly command: "run.question.cancel";
|
|
94
|
+
readonly receipt: CliCompactReceipt;
|
|
95
|
+
};
|
|
96
|
+
export type CliDispatchSettleResult = {
|
|
97
|
+
readonly aggregate: CliCompactAggregate;
|
|
98
|
+
readonly command: "run.dispatch.settle-terminal";
|
|
99
|
+
readonly delivery: CliCompactDelivery;
|
|
100
|
+
readonly receipt: CliCompactReceipt;
|
|
101
|
+
};
|
|
102
|
+
export type CliInboxAckResult = {
|
|
103
|
+
readonly command: "run.inbox.ack";
|
|
104
|
+
readonly delivery: CliCompactDelivery;
|
|
105
|
+
readonly mailboxId: OrchestrationInboxAckResult["mailbox"]["id"];
|
|
106
|
+
readonly mailboxRevision: OrchestrationInboxAckResult["mailbox"]["revision"];
|
|
107
|
+
readonly owner: OrchestrationInboxAckResult["mailbox"]["owner"];
|
|
108
|
+
readonly receipt: CliCompactReceipt;
|
|
109
|
+
readonly runId: OrchestrationInboxAckResult["mailbox"]["runId"];
|
|
110
|
+
};
|
|
111
|
+
export declare const projectDispatchShowDispatch: (dispatch: ProtocolDispatch) => CliDispatchShowDispatch;
|
|
112
|
+
export declare const projectOrchestrationAggregate: (aggregate: OrchestrationAggregate) => CliCompactAggregate;
|
|
113
|
+
export declare const projectOrchestrationDelivery: (delivery: OrchestrationDelivery) => CliCompactDelivery;
|
|
114
|
+
export declare const projectOrchestrationReceipt: (receipt: ProtocolReceipt) => CliCompactReceipt;
|
|
115
|
+
export declare const projectRunShowResult: (value: OrchestrationRunShowResult) => CliRunShowResult;
|
|
116
|
+
export declare const projectRunCreateResult: (value: OrchestrationRunCreateResult) => CliRunCreateResult;
|
|
117
|
+
export declare const projectQuestionOpenResult: (value: OrchestrationQuestionOpenResult) => CliQuestionOpenResult;
|
|
118
|
+
export declare const projectQuestionReplyResult: (value: OrchestrationQuestionReplyResult) => CliQuestionReplyResult;
|
|
119
|
+
export declare const projectQuestionCancelResult: (value: OrchestrationQuestionCancelResult) => CliQuestionCancelResult;
|
|
120
|
+
export declare const projectDispatchSettleResult: (value: OrchestrationDispatchSettleTerminalResult) => CliDispatchSettleResult;
|
|
121
|
+
export declare const projectInboxAckResult: (value: OrchestrationInboxAckResult) => CliInboxAckResult;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=compact-aggregate.d.ts.map
|