@maiaos/sdk 0.1.0-canary.2
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 +177 -0
- package/dist/agent-permission/agent-permission.d.ts +9 -0
- package/dist/agent-permission/agent-permission.js +5 -0
- package/dist/agent-permission/effect.d.ts +4 -0
- package/dist/agent-permission/effect.js +34 -0
- package/dist/agent-permission/index.d.ts +2 -0
- package/dist/agent-permission/index.js +2 -0
- package/dist/approval/approval.d.ts +10 -0
- package/dist/approval/approval.js +5 -0
- package/dist/approval/effect.d.ts +5 -0
- package/dist/approval/effect.js +43 -0
- package/dist/approval/index.d.ts +2 -0
- package/dist/approval/index.js +2 -0
- package/dist/call/call.d.ts +26 -0
- package/dist/call/call.js +6 -0
- package/dist/call/effect.d.ts +5 -0
- package/dist/call/effect.js +46 -0
- package/dist/call/index.d.ts +2 -0
- package/dist/call/index.js +2 -0
- package/dist/client/effect.d.ts +8 -0
- package/dist/client/effect.js +283 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/local-node-client.d.ts +100 -0
- package/dist/client/local-node-client.js +4 -0
- package/dist/connection/connection.d.ts +19 -0
- package/dist/connection/connection.js +5 -0
- package/dist/connection/effect.d.ts +5 -0
- package/dist/connection/effect.js +119 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.js +2 -0
- package/dist/container/container.d.ts +14 -0
- package/dist/container/container.js +5 -0
- package/dist/container/effect.d.ts +4 -0
- package/dist/container/effect.js +90 -0
- package/dist/container/index.d.ts +2 -0
- package/dist/container/index.js +2 -0
- package/dist/discovery/discovery.d.ts +11 -0
- package/dist/discovery/discovery.js +5 -0
- package/dist/discovery/effect.d.ts +5 -0
- package/dist/discovery/effect.js +44 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/discovery/index.js +2 -0
- package/dist/execution/effect.d.ts +4 -0
- package/dist/execution/effect.js +8 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/relocation.d.ts +10 -0
- package/dist/execution/relocation.js +4 -0
- package/dist/feature-bindings/feature-bindings.d.ts +10 -0
- package/dist/feature-bindings/feature-bindings.js +2 -0
- package/dist/feature-bindings/index.d.ts +2 -0
- package/dist/feature-bindings/index.js +2 -0
- package/dist/hold/effect.d.ts +5 -0
- package/dist/hold/effect.js +61 -0
- package/dist/hold/hold.d.ts +12 -0
- package/dist/hold/hold.js +5 -0
- package/dist/hold/index.d.ts +2 -0
- package/dist/hold/index.js +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +21 -0
- package/dist/interaction/effect.d.ts +5 -0
- package/dist/interaction/effect.js +79 -0
- package/dist/interaction/index.d.ts +2 -0
- package/dist/interaction/index.js +2 -0
- package/dist/interaction/interaction.d.ts +12 -0
- package/dist/interaction/interaction.js +5 -0
- package/dist/node/attach.d.ts +11 -0
- package/dist/node/attach.js +33 -0
- package/dist/node/bridge-frame.d.ts +18 -0
- package/dist/node/bridge-frame.js +67 -0
- package/dist/node/bridge.d.ts +31 -0
- package/dist/node/bridge.js +148 -0
- package/dist/node/discovery.d.ts +187 -0
- package/dist/node/discovery.js +408 -0
- package/dist/node/effect.d.ts +9 -0
- package/dist/node/effect.js +9 -0
- package/dist/node/fetch.d.ts +2 -0
- package/dist/node/fetch.js +2 -0
- package/dist/node/http.d.ts +27 -0
- package/dist/node/http.js +258 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +3 -0
- package/dist/node/local-node.d.ts +26 -0
- package/dist/node/local-node.js +67 -0
- package/dist/node/session.d.ts +15 -0
- package/dist/node/session.js +27 -0
- package/dist/node/ssh.d.ts +16 -0
- package/dist/node/ssh.js +74 -0
- package/dist/node/transport.d.ts +52 -0
- package/dist/node/transport.js +211 -0
- package/dist/node-changes/effect.d.ts +11 -0
- package/dist/node-changes/effect.js +61 -0
- package/dist/node-changes/index.d.ts +2 -0
- package/dist/node-changes/index.js +2 -0
- package/dist/node-changes/node-changes.d.ts +21 -0
- package/dist/node-changes/node-changes.js +23 -0
- package/dist/port-lease/effect.d.ts +5 -0
- package/dist/port-lease/effect.js +53 -0
- package/dist/port-lease/index.d.ts +2 -0
- package/dist/port-lease/index.js +2 -0
- package/dist/port-lease/port-lease.d.ts +11 -0
- package/dist/port-lease/port-lease.js +5 -0
- package/dist/presentation/client.d.ts +10 -0
- package/dist/presentation/client.js +4 -0
- package/dist/presentation/effect.d.ts +5 -0
- package/dist/presentation/effect.js +30 -0
- package/dist/presentation/index.d.ts +5 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/project-list.d.ts +7 -0
- package/dist/presentation/project-list.js +24 -0
- package/dist/presentation/session-list.d.ts +7 -0
- package/dist/presentation/session-list.js +32 -0
- package/dist/project-guard/effect.d.ts +5 -0
- package/dist/project-guard/effect.js +39 -0
- package/dist/project-guard/index.d.ts +2 -0
- package/dist/project-guard/index.js +2 -0
- package/dist/project-guard/project-guard.d.ts +10 -0
- package/dist/project-guard/project-guard.js +5 -0
- package/dist/project-workspace/effect.d.ts +5 -0
- package/dist/project-workspace/effect.js +124 -0
- package/dist/project-workspace/index.d.ts +2 -0
- package/dist/project-workspace/index.js +2 -0
- package/dist/project-workspace/project-workspace.d.ts +23 -0
- package/dist/project-workspace/project-workspace.js +4 -0
- package/dist/provider-pool/effect.d.ts +4 -0
- package/dist/provider-pool/effect.js +5 -0
- package/dist/provider-pool/index.d.ts +2 -0
- package/dist/provider-pool/index.js +2 -0
- package/dist/provider-pool/provider-pool.d.ts +7 -0
- package/dist/provider-pool/provider-pool.js +4 -0
- package/dist/remote-node/effect.d.ts +4 -0
- package/dist/remote-node/effect.js +57 -0
- package/dist/remote-node/index.d.ts +2 -0
- package/dist/remote-node/index.js +2 -0
- package/dist/remote-node/remote-node.d.ts +12 -0
- package/dist/remote-node/remote-node.js +5 -0
- package/dist/request/classify.d.ts +15 -0
- package/dist/request/classify.js +96 -0
- package/dist/request/client-error.d.ts +10 -0
- package/dist/request/client-error.js +11 -0
- package/dist/request/effect.d.ts +22 -0
- package/dist/request/effect.js +104 -0
- package/dist/request/envelope-schema.d.ts +2 -0
- package/dist/request/envelope-schema.js +2 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.js +4 -0
- package/dist/request/maia-client.d.ts +21 -0
- package/dist/request/maia-client.js +9 -0
- package/dist/request/options.d.ts +9 -0
- package/dist/request/options.js +2 -0
- package/dist/run-ledger/effect.d.ts +5 -0
- package/dist/run-ledger/effect.js +72 -0
- package/dist/run-ledger/index.d.ts +2 -0
- package/dist/run-ledger/index.js +2 -0
- package/dist/run-ledger/run-ledger.d.ts +12 -0
- package/dist/run-ledger/run-ledger.js +2 -0
- package/dist/session/effect.d.ts +4 -0
- package/dist/session/effect.js +7 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +2 -0
- package/dist/session/mailbox.d.ts +9 -0
- package/dist/session/mailbox.js +4 -0
- package/dist/session-creation/effect.d.ts +25 -0
- package/dist/session-creation/effect.js +269 -0
- package/dist/session-creation/index.d.ts +3 -0
- package/dist/session-creation/index.js +3 -0
- package/dist/session-creation/session-creation.d.ts +18 -0
- package/dist/session-creation/session-creation.js +24 -0
- package/dist/session-creation/tasks.d.ts +69 -0
- package/dist/session-creation/tasks.js +37 -0
- package/dist/session-view/index.d.ts +2 -0
- package/dist/session-view/index.js +2 -0
- package/dist/session-view/view.d.ts +42 -0
- package/dist/session-view/view.js +137 -0
- package/dist/stream/effect.d.ts +29 -0
- package/dist/stream/effect.js +77 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.js +2 -0
- package/dist/stream/stream.d.ts +9 -0
- package/dist/stream/stream.js +2 -0
- package/dist/voice/effect.d.ts +7 -0
- package/dist/voice/effect.js +71 -0
- package/dist/voice/index.d.ts +4 -0
- package/dist/voice/index.js +3 -0
- package/dist/voice/managed-turn.d.ts +9 -0
- package/dist/voice/managed-turn.js +4 -0
- package/dist/voice/orchestrator-contract.d.ts +5 -0
- package/dist/voice/orchestrator-contract.js +4 -0
- package/dist/voice/orchestrator.d.ts +25 -0
- package/dist/voice/orchestrator.js +169 -0
- package/dist/voice/pi-relay-contract.d.ts +4 -0
- package/dist/voice/pi-relay-contract.js +2 -0
- package/dist/voice/pi-relay.d.ts +12 -0
- package/dist/voice/pi-relay.js +9 -0
- package/dist/voice/wire-schema.d.ts +215 -0
- package/dist/voice/wire-schema.js +16 -0
- package/package.json +84 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProtocolRequestEnvelope, RuntimeParser } from "@maiaos/protocol";
|
|
2
|
+
export type CancellationSignal = AbortSignal;
|
|
3
|
+
export type TransportRequestOptions = {
|
|
4
|
+
readonly signal?: CancellationSignal;
|
|
5
|
+
};
|
|
6
|
+
export type MaiaTransport = {
|
|
7
|
+
readonly request: (envelope: ProtocolRequestEnvelope<unknown>, options?: TransportRequestOptions) => Promise<unknown>;
|
|
8
|
+
};
|
|
9
|
+
export type RuntimeSchema<TValue> = RuntimeParser<TValue>;
|
|
10
|
+
export type MaiaRequest<TInput, TOutput> = {
|
|
11
|
+
readonly inputSchema: RuntimeSchema<TInput>;
|
|
12
|
+
readonly messageId: string;
|
|
13
|
+
readonly outputSchema: RuntimeSchema<TOutput>;
|
|
14
|
+
readonly payload: TInput;
|
|
15
|
+
readonly signal?: CancellationSignal;
|
|
16
|
+
};
|
|
17
|
+
export type MaiaClient = {
|
|
18
|
+
readonly request: <TInput, TOutput>(request: MaiaRequest<TInput, TOutput>) => Promise<TOutput>;
|
|
19
|
+
};
|
|
20
|
+
export declare const createMaiaClient: (transport: MaiaTransport) => MaiaClient;
|
|
21
|
+
//# sourceMappingURL=maia-client.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { executeMaiaRequest, fromPromiseTransport } from "./effect.js";
|
|
3
|
+
export const createMaiaClient = (transport) => {
|
|
4
|
+
const effectTransport = fromPromiseTransport(transport);
|
|
5
|
+
return {
|
|
6
|
+
request: (request) => Effect.runPromise(executeMaiaRequest(effectTransport, request)),
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=maia-client.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LocalNodeRequestPayload } from "@maiaos/protocol";
|
|
2
|
+
export type LocalNodeRequestOptions = {
|
|
3
|
+
readonly messageId: string;
|
|
4
|
+
readonly signal?: AbortSignal;
|
|
5
|
+
};
|
|
6
|
+
export type LocalNodeRequester = <TOutput>(payload: LocalNodeRequestPayload, outputSchema: {
|
|
7
|
+
readonly parse: (value: unknown) => TOutput;
|
|
8
|
+
}, options: LocalNodeRequestOptions) => Promise<TOutput>;
|
|
9
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type EffectClient, type LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
|
+
import { MaiaClientError } from "../request/index.js";
|
|
3
|
+
import type { RunLedgerClient } from "./run-ledger.js";
|
|
4
|
+
export declare const makeRunLedgerOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<RunLedgerClient, MaiaClientError | TError>;
|
|
5
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { runLedgerCreateResultSchema, runLedgerListResultSchema, runLedgerTaskDispatchResultSchema, runLedgerTaskListResultSchema, runLedgerTaskSettleResultSchema, runLedgerTaskShowResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { verifiedMutation, } from "../request/effect.js";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
const requireMatch = (matches) => {
|
|
5
|
+
if (!matches)
|
|
6
|
+
throw new MaiaClientError("invalid_response", "The Run ledger response did not match the request.");
|
|
7
|
+
};
|
|
8
|
+
const parseCreate = (value, input) => {
|
|
9
|
+
const result = runLedgerCreateResultSchema.parse(value);
|
|
10
|
+
requireMatch(result.commandId === input.commandId &&
|
|
11
|
+
result.run.workspaceId === input.workspaceId &&
|
|
12
|
+
result.tasks.map((task) => task.clientKey).join("\n") ===
|
|
13
|
+
input.tasks.map((task) => task.clientKey).join("\n"));
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const parseDispatch = (value, input) => {
|
|
17
|
+
const result = runLedgerTaskDispatchResultSchema.parse(value);
|
|
18
|
+
requireMatch(result.commandId === input.commandId &&
|
|
19
|
+
result.task.runId === input.runId &&
|
|
20
|
+
result.task.id === input.taskId &&
|
|
21
|
+
result.dispatch.sessionId === input.sessionId &&
|
|
22
|
+
BigInt(result.task.revision) === BigInt(input.expectedTaskRevision) + 1n);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const parseSettle = (value, input) => {
|
|
26
|
+
const result = runLedgerTaskSettleResultSchema.parse(value);
|
|
27
|
+
const settled = result.task.dispatches.at(-1);
|
|
28
|
+
requireMatch(result.commandId === input.commandId &&
|
|
29
|
+
result.task.runId === input.runId &&
|
|
30
|
+
result.task.id === input.taskId &&
|
|
31
|
+
settled?.sessionId === input.sessionId &&
|
|
32
|
+
settled.state === input.outcome &&
|
|
33
|
+
settled.evidence === input.evidence &&
|
|
34
|
+
(input.turnId === undefined || settled.settledTurnId === input.turnId) &&
|
|
35
|
+
BigInt(result.task.revision) === BigInt(input.expectedTaskRevision) + 1n);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
const parseList = (value, input) => {
|
|
39
|
+
const result = runLedgerListResultSchema.parse(value);
|
|
40
|
+
requireMatch(result.items.length <= input.limit &&
|
|
41
|
+
result.items.every((run) => run.workspaceId === input.workspaceId) &&
|
|
42
|
+
(result.nextCursor === undefined ||
|
|
43
|
+
result.nextCursor !== input.afterCursor));
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
const parseTaskList = (value, input) => {
|
|
47
|
+
const result = runLedgerTaskListResultSchema.parse(value);
|
|
48
|
+
requireMatch(result.run.id === input.runId &&
|
|
49
|
+
(input.ready !== true ||
|
|
50
|
+
result.items.every((task) => task.state === "ready")));
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const parseTaskShow = (value, input) => {
|
|
54
|
+
const result = runLedgerTaskShowResultSchema.parse(value);
|
|
55
|
+
requireMatch(result.task.runId === input.runId && result.task.id === input.taskId);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
const makeRunLedgerMutations = (request) => ({
|
|
59
|
+
createRunLedger: (parameters, options) => request({ method: "run.ledger.create", parameters }, { parse: (value) => parseCreate(value, parameters) }, options),
|
|
60
|
+
dispatchRunLedgerTask: (parameters, options) => request({ method: "run.ledger.task.dispatch", parameters }, { parse: (value) => parseDispatch(value, parameters) }, options),
|
|
61
|
+
settleRunLedgerTask: (parameters, options) => request({ method: "run.ledger.task.settle", parameters }, { parse: (value) => parseSettle(value, parameters) }, options),
|
|
62
|
+
});
|
|
63
|
+
export const makeRunLedgerOperations = (request) => {
|
|
64
|
+
const verified = (payload, output, options) => verifiedMutation(request(payload, output, options), options);
|
|
65
|
+
return {
|
|
66
|
+
...makeRunLedgerMutations(verified),
|
|
67
|
+
listRunLedgers: (parameters, options) => request({ method: "run.ledger.list", parameters }, { parse: (value) => parseList(value, parameters) }, options),
|
|
68
|
+
listRunLedgerTasks: (parameters, options) => request({ method: "run.ledger.task.list", parameters }, { parse: (value) => parseTaskList(value, parameters) }, options),
|
|
69
|
+
showRunLedgerTask: (parameters, options) => request({ method: "run.ledger.task.show", parameters }, { parse: (value) => parseTaskShow(value, parameters) }, options),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { MAX_RUN_LEDGER_EVIDENCE_BYTES, MAX_RUN_LEDGER_FAILED_DISPATCHES, MAX_RUN_LEDGER_LIST_PAGE_SIZE, RUN_LEDGER_ERROR_CODES, RUN_LEDGER_SCHEMA_VERSION, type RunLedgerClient, type RunLedgerCreateParameters, runLedgerCreateParametersSchema, type RunLedgerCreateResult, runLedgerCreateResultSchema, type RunLedgerDispatch, type RunLedgerDispatchSummary, type RunLedgerErrorCode, type RunLedgerListParameters, runLedgerListParametersSchema, type RunLedgerListResult, runLedgerListResultSchema, type RunLedgerRun, type RunLedgerTask, type RunLedgerTaskDispatchParameters, runLedgerTaskDispatchParametersSchema, type RunLedgerTaskDispatchResult, runLedgerTaskDispatchResultSchema, type RunLedgerTaskListParameters, runLedgerTaskListParametersSchema, type RunLedgerTaskListResult, runLedgerTaskListResultSchema, type RunLedgerTaskSettleParameters, runLedgerTaskSettleParametersSchema, type RunLedgerTaskSettleResult, runLedgerTaskSettleResultSchema, type RunLedgerTaskShowParameters, runLedgerTaskShowParametersSchema, type RunLedgerTaskShowResult, runLedgerTaskShowResultSchema, type RunLedgerTaskSummary, } from "./run-ledger.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { MAX_RUN_LEDGER_EVIDENCE_BYTES, MAX_RUN_LEDGER_FAILED_DISPATCHES, MAX_RUN_LEDGER_LIST_PAGE_SIZE, RUN_LEDGER_ERROR_CODES, RUN_LEDGER_SCHEMA_VERSION, runLedgerCreateParametersSchema, runLedgerCreateResultSchema, runLedgerListParametersSchema, runLedgerListResultSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskDispatchResultSchema, runLedgerTaskListParametersSchema, runLedgerTaskListResultSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskSettleResultSchema, runLedgerTaskShowParametersSchema, runLedgerTaskShowResultSchema, } from "./run-ledger.js";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RunLedgerCreateParameters, RunLedgerCreateResult, RunLedgerListParameters, RunLedgerListResult, RunLedgerTaskDispatchParameters, RunLedgerTaskDispatchResult, RunLedgerTaskListParameters, RunLedgerTaskListResult, RunLedgerTaskSettleParameters, RunLedgerTaskSettleResult, RunLedgerTaskShowParameters, RunLedgerTaskShowResult } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeRequestOptions } from "../request/index.js";
|
|
3
|
+
export type RunLedgerClient = {
|
|
4
|
+
readonly createRunLedger: (parameters: RunLedgerCreateParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerCreateResult>;
|
|
5
|
+
readonly dispatchRunLedgerTask: (parameters: RunLedgerTaskDispatchParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerTaskDispatchResult>;
|
|
6
|
+
readonly listRunLedgers: (parameters: RunLedgerListParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerListResult>;
|
|
7
|
+
readonly listRunLedgerTasks: (parameters: RunLedgerTaskListParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerTaskListResult>;
|
|
8
|
+
readonly settleRunLedgerTask: (parameters: RunLedgerTaskSettleParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerTaskSettleResult>;
|
|
9
|
+
readonly showRunLedgerTask: (parameters: RunLedgerTaskShowParameters, options: LocalNodeRequestOptions) => Promise<RunLedgerTaskShowResult>;
|
|
10
|
+
};
|
|
11
|
+
export { MAX_RUN_LEDGER_EVIDENCE_BYTES, MAX_RUN_LEDGER_FAILED_DISPATCHES, MAX_RUN_LEDGER_LIST_PAGE_SIZE, RUN_LEDGER_ERROR_CODES, RUN_LEDGER_SCHEMA_VERSION, type RunLedgerCreateParameters, runLedgerCreateParametersSchema, type RunLedgerCreateResult, runLedgerCreateResultSchema, type RunLedgerDispatch, type RunLedgerDispatchSummary, type RunLedgerErrorCode, type RunLedgerListParameters, runLedgerListParametersSchema, type RunLedgerListResult, runLedgerListResultSchema, type RunLedgerRun, type RunLedgerTask, type RunLedgerTaskDispatchParameters, runLedgerTaskDispatchParametersSchema, type RunLedgerTaskDispatchResult, runLedgerTaskDispatchResultSchema, type RunLedgerTaskListParameters, runLedgerTaskListParametersSchema, type RunLedgerTaskListResult, runLedgerTaskListResultSchema, type RunLedgerTaskSettleParameters, runLedgerTaskSettleParametersSchema, type RunLedgerTaskSettleResult, runLedgerTaskSettleResultSchema, type RunLedgerTaskShowParameters, runLedgerTaskShowParametersSchema, type RunLedgerTaskShowResult, runLedgerTaskShowResultSchema, type RunLedgerTaskSummary, } from "@maiaos/protocol";
|
|
12
|
+
//# sourceMappingURL=run-ledger.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { MAX_RUN_LEDGER_EVIDENCE_BYTES, MAX_RUN_LEDGER_FAILED_DISPATCHES, MAX_RUN_LEDGER_LIST_PAGE_SIZE, RUN_LEDGER_ERROR_CODES, RUN_LEDGER_SCHEMA_VERSION, runLedgerCreateParametersSchema, runLedgerCreateResultSchema, runLedgerListParametersSchema, runLedgerListResultSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskDispatchResultSchema, runLedgerTaskListParametersSchema, runLedgerTaskListResultSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskSettleResultSchema, runLedgerTaskShowParametersSchema, runLedgerTaskShowResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
//# sourceMappingURL=run-ledger.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EffectClient, LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
|
+
import type { SessionMailboxClient } from "./mailbox.js";
|
|
3
|
+
export declare const makeSessionMailboxOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<SessionMailboxClient, TError>;
|
|
4
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { sessionInboxAckResultSchema, sessionInboxCheckResultSchema, sessionMessageSendResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
export const makeSessionMailboxOperations = (request) => ({
|
|
3
|
+
acknowledgeSessionDelivery: (parameters, options) => request({ method: "session.inbox.ack", parameters }, sessionInboxAckResultSchema, options),
|
|
4
|
+
checkSessionInbox: (parameters, options) => request({ method: "session.inbox.check", parameters }, sessionInboxCheckResultSchema, options),
|
|
5
|
+
sendSessionMessage: (parameters, options) => request({ method: "session.message.send", parameters }, sessionMessageSendResultSchema, options),
|
|
6
|
+
});
|
|
7
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SessionInboxAckParameters, SessionInboxAckResult, SessionInboxCheckParameters, SessionInboxCheckResult, SessionMessageSendParameters, SessionMessageSendResult } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeRequester, LocalNodeRequestOptions } from "../request/index.js";
|
|
3
|
+
export type SessionMailboxClient = {
|
|
4
|
+
readonly acknowledgeSessionDelivery: (parameters: SessionInboxAckParameters, options: LocalNodeRequestOptions) => Promise<SessionInboxAckResult>;
|
|
5
|
+
readonly checkSessionInbox: (parameters: SessionInboxCheckParameters, options: LocalNodeRequestOptions) => Promise<SessionInboxCheckResult>;
|
|
6
|
+
readonly sendSessionMessage: (parameters: SessionMessageSendParameters, options: LocalNodeRequestOptions) => Promise<SessionMessageSendResult>;
|
|
7
|
+
};
|
|
8
|
+
export declare const makeSessionMailboxClient: (request: LocalNodeRequester) => SessionMailboxClient;
|
|
9
|
+
//# sourceMappingURL=mailbox.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { fromPromiseRequester, toPromiseClient } from "../request/effect.js";
|
|
2
|
+
import { makeSessionMailboxOperations } from "./effect.js";
|
|
3
|
+
export const makeSessionMailboxClient = (request) => toPromiseClient(makeSessionMailboxOperations(fromPromiseRequester(request)));
|
|
4
|
+
//# sourceMappingURL=mailbox.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Session } from "@maiaos/protocol";
|
|
2
|
+
import * as Crypto from "effect/Crypto";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import type { EffectClient } from "../request/effect.js";
|
|
5
|
+
import { MaiaClientError } from "../request/index.js";
|
|
6
|
+
import { type SessionCreationClient, type SessionCreationInput, type SessionCreationOutcome, type SessionCreationPlan } from "./tasks.js";
|
|
7
|
+
export type SessionCreationEffectClient<TError = MaiaClientError> = EffectClient<SessionCreationClient, TError>;
|
|
8
|
+
export type NextIdentifier = (prefix: "command" | "request") => Effect.Effect<string>;
|
|
9
|
+
export declare const fromPromiseClient: <TClient extends Partial<SessionCreationClient>>(client: TClient) => EffectClient<TClient, unknown>;
|
|
10
|
+
export declare const planSessionCreationWith: <TError>(client: SessionCreationEffectClient<TError>, input: SessionCreationInput, nextId: NextIdentifier) => Effect.Effect<SessionCreationPlan, MaiaClientError | TError>;
|
|
11
|
+
export declare const awaitSessionRunningWith: <TError>(client: Pick<SessionCreationEffectClient<TError>, "showSession">, sessionId: string, options: {
|
|
12
|
+
readonly deadlineMilliseconds: number;
|
|
13
|
+
readonly nextId: NextIdentifier;
|
|
14
|
+
}) => Effect.Effect<Session, MaiaClientError | TError>;
|
|
15
|
+
type RunOptions = {
|
|
16
|
+
readonly nextId: NextIdentifier;
|
|
17
|
+
readonly previous?: readonly SessionCreationOutcome[];
|
|
18
|
+
readonly report?: (outcomes: readonly SessionCreationOutcome[]) => Effect.Effect<void>;
|
|
19
|
+
};
|
|
20
|
+
export declare const createSessionsWith: <TError>(client: SessionCreationEffectClient<TError>, plan: SessionCreationPlan, options: RunOptions) => Effect.Effect<readonly SessionCreationOutcome[]>;
|
|
21
|
+
export declare const planSessionCreationEffect: (client: SessionCreationEffectClient, input: SessionCreationInput) => Effect.Effect<SessionCreationPlan, MaiaClientError, Crypto.Crypto>;
|
|
22
|
+
export declare const createSessionsEffect: (client: SessionCreationEffectClient, plan: SessionCreationPlan, options?: Omit<RunOptions, "nextId">) => Effect.Effect<readonly SessionCreationOutcome[], never, Crypto.Crypto>;
|
|
23
|
+
export declare const awaitSessionRunningEffect: (client: Pick<SessionCreationEffectClient, "showSession">, sessionId: string, deadlineMilliseconds: number) => Effect.Effect<Session, MaiaClientError, Crypto.Crypto>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as Crypto from "effect/Crypto";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Ref from "effect/Ref";
|
|
6
|
+
import * as Schedule from "effect/Schedule";
|
|
7
|
+
import { classifyClientError, MaiaClientError } from "../request/index.js";
|
|
8
|
+
import { orderExecutionWorkspaces, sessionCreationSettled, splitTasks, } from "./tasks.js";
|
|
9
|
+
const ITEM_CONCURRENCY = 4;
|
|
10
|
+
const RUNNING_DEADLINE_MILLISECONDS = 120_000;
|
|
11
|
+
const WORKSPACE_PAGE = 100;
|
|
12
|
+
export const fromPromiseClient = (client) => Object.fromEntries(Object.entries(client).map(([name, operation]) => [
|
|
13
|
+
name,
|
|
14
|
+
(parameters, options) => Effect.tryPromise({
|
|
15
|
+
catch: (error) => error,
|
|
16
|
+
try: (signal) => operation(parameters, { ...options, signal }),
|
|
17
|
+
}),
|
|
18
|
+
]));
|
|
19
|
+
const invalid = (message) => new MaiaClientError("invalid_request", message);
|
|
20
|
+
const pickWorkspace = (workspaces, workspaceId) => {
|
|
21
|
+
const ready = orderExecutionWorkspaces(workspaces);
|
|
22
|
+
const chosen = workspaceId === undefined
|
|
23
|
+
? ready[0]
|
|
24
|
+
: ready.find((workspace) => workspace.id === workspaceId);
|
|
25
|
+
return chosen === undefined
|
|
26
|
+
? Effect.fail(invalid("The Project has no ready execution Workspace by that ID."))
|
|
27
|
+
: Effect.succeed(chosen.id);
|
|
28
|
+
};
|
|
29
|
+
const chooseWorkspace = (client, input, nextId) => {
|
|
30
|
+
const { projectId, workspaceId } = input;
|
|
31
|
+
if (projectId === undefined)
|
|
32
|
+
return workspaceId === undefined
|
|
33
|
+
? Effect.fail(invalid("Name a Project or a Workspace."))
|
|
34
|
+
: Effect.succeed(workspaceId);
|
|
35
|
+
return nextId("request").pipe(Effect.flatMap((messageId) => client.listWorkspaces({ afterCursor: "0", limit: WORKSPACE_PAGE, projectId }, { messageId })), Effect.flatMap((page) => pickWorkspace(page.items, workspaceId)));
|
|
36
|
+
};
|
|
37
|
+
const mintCommands = (nextId) => Effect.all({
|
|
38
|
+
create: nextId("command"),
|
|
39
|
+
send: nextId("command"),
|
|
40
|
+
start: nextId("command"),
|
|
41
|
+
});
|
|
42
|
+
export const planSessionCreationWith = (client, input, nextId) => Effect.gen(function* () {
|
|
43
|
+
const { accepted, refusals } = splitTasks(input);
|
|
44
|
+
if (accepted.length === 0)
|
|
45
|
+
return yield* Effect.fail(invalid("Add at least one task line."));
|
|
46
|
+
const workspaceId = yield* chooseWorkspace(client, input, nextId);
|
|
47
|
+
const items = yield* Effect.forEach(accepted, (entry, index) => Effect.map(mintCommands(nextId), (commands) => ({
|
|
48
|
+
commands,
|
|
49
|
+
index,
|
|
50
|
+
...entry,
|
|
51
|
+
})));
|
|
52
|
+
return { items, refusals, session: input.session, workspaceId };
|
|
53
|
+
});
|
|
54
|
+
const STOPPED_STATES = new Set([
|
|
55
|
+
"failed",
|
|
56
|
+
"stopped",
|
|
57
|
+
"stopping",
|
|
58
|
+
]);
|
|
59
|
+
const SETTLED_STATES = new Set([
|
|
60
|
+
...STOPPED_STATES,
|
|
61
|
+
"running",
|
|
62
|
+
]);
|
|
63
|
+
const backoff = Schedule.min([
|
|
64
|
+
Schedule.exponential("250 millis"),
|
|
65
|
+
Schedule.spaced("2 seconds"),
|
|
66
|
+
]);
|
|
67
|
+
const neverSeen = () => new MaiaClientError("deadline_exceeded", "The Session did not answer before the deadline.");
|
|
68
|
+
const showWhileOffline = (client, sessionId, nextId) => nextId("request").pipe(Effect.flatMap((messageId) => client.showSession({ sessionId }, { messageId })), Effect.map((result) => result.session), Effect.retry({
|
|
69
|
+
schedule: backoff,
|
|
70
|
+
while: (error) => classifyClientError(error, { mutation: false }).kind === "offline",
|
|
71
|
+
}));
|
|
72
|
+
export const awaitSessionRunningWith = (client, sessionId, options) => Effect.flatMap(Ref.make(Option.none()), (last) => showWhileOffline(client, sessionId, options.nextId).pipe(Effect.tap((session) => Ref.set(last, Option.some(session))), Effect.repeat({
|
|
73
|
+
schedule: backoff,
|
|
74
|
+
until: (session) => SETTLED_STATES.has(session.state),
|
|
75
|
+
}), Effect.timeoutOrElse({
|
|
76
|
+
duration: options.deadlineMilliseconds,
|
|
77
|
+
orElse: () => Effect.flatMap(Ref.get(last), (seen) => Option.match(seen, {
|
|
78
|
+
onNone: () => Effect.fail(neverSeen()),
|
|
79
|
+
onSome: (session) => Effect.succeed(session),
|
|
80
|
+
})),
|
|
81
|
+
})));
|
|
82
|
+
class StepFailure extends Data.TaggedError("SessionCreationStepFailure") {
|
|
83
|
+
}
|
|
84
|
+
const update = (context, change) => Ref.update(context.outcome, change).pipe(Effect.andThen(context.publish));
|
|
85
|
+
const send = (context, step) => update(context, ({ error: _error, ...outcome }) => ({
|
|
86
|
+
...outcome,
|
|
87
|
+
sent: step.record(outcome.sent),
|
|
88
|
+
})).pipe(Effect.andThen(context.nextId("request")), Effect.flatMap((messageId) => step.request(step.parameters, { messageId })), Effect.mapError((cause) => new StepFailure({ cause, operation: step.operation })));
|
|
89
|
+
const sentBefore = (context) => Effect.map(Ref.get(context.outcome), (outcome) => outcome.sent);
|
|
90
|
+
const createStep = (context, item) => Effect.gen(function* () {
|
|
91
|
+
const parameters = (yield* sentBefore(context))
|
|
92
|
+
.create ?? {
|
|
93
|
+
...context.plan.session,
|
|
94
|
+
commandId: item.commands.create,
|
|
95
|
+
expectedRevision: "0",
|
|
96
|
+
workspaceId: context.plan.workspaceId,
|
|
97
|
+
};
|
|
98
|
+
const result = yield* send(context, {
|
|
99
|
+
operation: "session.create",
|
|
100
|
+
parameters,
|
|
101
|
+
record: (sent) => ({ ...sent, create: parameters }),
|
|
102
|
+
request: context.client.createSession,
|
|
103
|
+
});
|
|
104
|
+
yield* update(context, (outcome) => ({
|
|
105
|
+
...outcome,
|
|
106
|
+
receipts: { ...outcome.receipts, create: result.receipt },
|
|
107
|
+
sessionId: result.session.id,
|
|
108
|
+
stage: "created",
|
|
109
|
+
}));
|
|
110
|
+
return result.session;
|
|
111
|
+
});
|
|
112
|
+
const startStep = (context, item, session) => Effect.gen(function* () {
|
|
113
|
+
const parameters = (yield* sentBefore(context))
|
|
114
|
+
.start ?? {
|
|
115
|
+
commandId: item.commands.start,
|
|
116
|
+
expectedRevision: session.revision,
|
|
117
|
+
sessionId: session.id,
|
|
118
|
+
};
|
|
119
|
+
const result = yield* send(context, {
|
|
120
|
+
operation: "session.start",
|
|
121
|
+
parameters,
|
|
122
|
+
record: (sent) => ({ ...sent, start: parameters }),
|
|
123
|
+
request: context.client.startSession,
|
|
124
|
+
});
|
|
125
|
+
yield* update(context, (outcome) => ({
|
|
126
|
+
...outcome,
|
|
127
|
+
receipts: { ...outcome.receipts, start: result.receipt },
|
|
128
|
+
stage: "started",
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
const runningStep = (context, sessionId) => awaitSessionRunningWith(context.client, sessionId, {
|
|
132
|
+
deadlineMilliseconds: RUNNING_DEADLINE_MILLISECONDS,
|
|
133
|
+
nextId: context.nextId,
|
|
134
|
+
}).pipe(Effect.mapError((cause) => new StepFailure({ cause, operation: "session.show" })), Effect.filterOrFail((session) => session.state === "running", (session) => new StepFailure({
|
|
135
|
+
operation: "session.show",
|
|
136
|
+
state: session.state,
|
|
137
|
+
...(session.failure === undefined
|
|
138
|
+
? {}
|
|
139
|
+
: { failure: session.failure }),
|
|
140
|
+
})), Effect.tap(() => update(context, (outcome) => ({ ...outcome, stage: "running" }))));
|
|
141
|
+
const sendStep = (context, item, session) => Effect.gen(function* () {
|
|
142
|
+
const parameters = (yield* sentBefore(context))
|
|
143
|
+
.send ?? {
|
|
144
|
+
commandId: item.commands.send,
|
|
145
|
+
expectedRevision: session.revision,
|
|
146
|
+
input: { text: item.task, type: "text" },
|
|
147
|
+
sessionId: session.id,
|
|
148
|
+
};
|
|
149
|
+
const result = yield* send(context, {
|
|
150
|
+
operation: "turn.send",
|
|
151
|
+
parameters,
|
|
152
|
+
record: (sent) => ({ ...sent, send: parameters }),
|
|
153
|
+
request: context.client.sendTurn,
|
|
154
|
+
});
|
|
155
|
+
yield* update(context, (outcome) => ({
|
|
156
|
+
...outcome,
|
|
157
|
+
receipts: { ...outcome.receipts, send: result.receipt },
|
|
158
|
+
stage: "sent",
|
|
159
|
+
turnId: result.turn.id,
|
|
160
|
+
}));
|
|
161
|
+
});
|
|
162
|
+
const failedCommand = (sent, operationId) => {
|
|
163
|
+
switch (operationId) {
|
|
164
|
+
case "session.create":
|
|
165
|
+
return sent.create?.commandId;
|
|
166
|
+
case "session.start":
|
|
167
|
+
return sent.start?.commandId;
|
|
168
|
+
case "turn.send":
|
|
169
|
+
return sent.send?.commandId;
|
|
170
|
+
case "session.show":
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const failedOutcome = (outcome, failure) => {
|
|
175
|
+
const operationId = failure.operation;
|
|
176
|
+
const error = failure.state === undefined
|
|
177
|
+
? classifyClientError(failure.cause, {
|
|
178
|
+
mutation: operationId !== "session.show",
|
|
179
|
+
operationId,
|
|
180
|
+
})
|
|
181
|
+
: {
|
|
182
|
+
_tag: "MaiaError",
|
|
183
|
+
code: `session_${failure.state}`,
|
|
184
|
+
kind: "refused",
|
|
185
|
+
operationId,
|
|
186
|
+
retryable: !STOPPED_STATES.has(failure.state),
|
|
187
|
+
};
|
|
188
|
+
const commandId = failedCommand(outcome.sent, operationId);
|
|
189
|
+
return {
|
|
190
|
+
...outcome,
|
|
191
|
+
error: {
|
|
192
|
+
...error,
|
|
193
|
+
...(commandId === undefined ? {} : { commandId }),
|
|
194
|
+
...(failure.failure === undefined ? {} : { failure: failure.failure }),
|
|
195
|
+
operationId,
|
|
196
|
+
},
|
|
197
|
+
stage: error.kind === "outcome_unknown" ? "unknown" : "refused",
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
const runItem = (context, item) => Effect.gen(function* () {
|
|
201
|
+
const created = yield* createStep(context, item);
|
|
202
|
+
yield* startStep(context, item, created);
|
|
203
|
+
const { task } = item;
|
|
204
|
+
if (task === undefined)
|
|
205
|
+
return;
|
|
206
|
+
const replay = (yield* sentBefore(context)).send !== undefined;
|
|
207
|
+
const running = replay ? created : yield* runningStep(context, created.id);
|
|
208
|
+
yield* sendStep(context, { ...item, task }, running);
|
|
209
|
+
}).pipe(Effect.catch((error) => update(context, (outcome) => failedOutcome(outcome, error))));
|
|
210
|
+
const pending = (item) => ({
|
|
211
|
+
index: item.index,
|
|
212
|
+
receipts: {},
|
|
213
|
+
sent: {},
|
|
214
|
+
stage: "pending",
|
|
215
|
+
});
|
|
216
|
+
const publisher = (outcomes, report) => report === undefined
|
|
217
|
+
? Effect.void
|
|
218
|
+
: Effect.flatMap(Effect.forEach(outcomes, Ref.get), report);
|
|
219
|
+
const belongsTo = (plan, item, { sent }) => (sent.create === undefined ||
|
|
220
|
+
(sent.create.commandId === item.commands.create &&
|
|
221
|
+
sent.create.workspaceId === plan.workspaceId)) &&
|
|
222
|
+
(sent.start === undefined || sent.start.commandId === item.commands.start) &&
|
|
223
|
+
(sent.send === undefined ||
|
|
224
|
+
(sent.send.commandId === item.commands.send &&
|
|
225
|
+
sent.send.input.text === item.task));
|
|
226
|
+
const foreign = (item) => ({
|
|
227
|
+
error: {
|
|
228
|
+
_tag: "MaiaError",
|
|
229
|
+
code: "previous_mismatch",
|
|
230
|
+
kind: "invalid",
|
|
231
|
+
operationId: "session.create",
|
|
232
|
+
retryable: false,
|
|
233
|
+
},
|
|
234
|
+
index: item.index,
|
|
235
|
+
receipts: {},
|
|
236
|
+
sent: {},
|
|
237
|
+
stage: "refused",
|
|
238
|
+
});
|
|
239
|
+
const startingOutcomes = (plan, previous) => plan.items.map((item) => {
|
|
240
|
+
const prior = previous?.find((outcome) => outcome.index === item.index);
|
|
241
|
+
if (prior === undefined)
|
|
242
|
+
return [pending(item), true];
|
|
243
|
+
return belongsTo(plan, item, prior)
|
|
244
|
+
? [prior, !sessionCreationSettled(prior, item)]
|
|
245
|
+
: [foreign(item), false];
|
|
246
|
+
});
|
|
247
|
+
export const createSessionsWith = (client, plan, options) => Effect.gen(function* () {
|
|
248
|
+
const starting = startingOutcomes(plan, options.previous);
|
|
249
|
+
const outcomes = yield* Effect.forEach(starting, ([outcome]) => Ref.make(outcome));
|
|
250
|
+
const publish = publisher(outcomes, options.report);
|
|
251
|
+
const { nextId } = options;
|
|
252
|
+
yield* publish;
|
|
253
|
+
yield* Effect.forEach(plan.items, (item, index) => {
|
|
254
|
+
const outcome = outcomes[index];
|
|
255
|
+
return outcome === undefined || starting[index]?.[1] !== true
|
|
256
|
+
? Effect.void
|
|
257
|
+
: runItem({ client, nextId, outcome, plan, publish }, item);
|
|
258
|
+
}, { concurrency: ITEM_CONCURRENCY, discard: true });
|
|
259
|
+
return yield* Effect.forEach(outcomes, Ref.get);
|
|
260
|
+
});
|
|
261
|
+
const cryptoIdentifier = (crypto) => (prefix) => Effect.map(Effect.orDie(crypto.randomUUIDv4), (uuid) => `${prefix}_${uuid.replaceAll("-", "")}`);
|
|
262
|
+
const withCrypto = (program) => Effect.flatMap(Crypto.Crypto, (crypto) => program(cryptoIdentifier(crypto)));
|
|
263
|
+
export const planSessionCreationEffect = (client, input) => withCrypto((nextId) => planSessionCreationWith(client, input, nextId));
|
|
264
|
+
export const createSessionsEffect = (client, plan, options = {}) => withCrypto((nextId) => createSessionsWith(client, plan, { ...options, nextId }));
|
|
265
|
+
export const awaitSessionRunningEffect = (client, sessionId, deadlineMilliseconds) => withCrypto((nextId) => awaitSessionRunningWith(client, sessionId, {
|
|
266
|
+
deadlineMilliseconds,
|
|
267
|
+
nextId,
|
|
268
|
+
}));
|
|
269
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { awaitSessionRunning, createSessions, type NewIdentifier, planSessionCreation, } from "./session-creation.js";
|
|
2
|
+
export { MAX_SESSION_CREATION_TASKS, orderExecutionWorkspaces, type SessionCreationClient, type SessionCreationInput, type SessionCreationItem, type SessionCreationOperation, type SessionCreationOutcome, type SessionCreationPlan, type SessionCreationReceipts, type SessionCreationRefusal, type SessionCreationStage, type SessionCreationTemplate, } from "./tasks.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Session } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeClient } from "../client/index.js";
|
|
3
|
+
import type { SessionCreationClient, SessionCreationInput, SessionCreationOutcome, SessionCreationPlan } from "./tasks.js";
|
|
4
|
+
export type NewIdentifier = (prefix: "command" | "request") => string;
|
|
5
|
+
type FacadeOptions = {
|
|
6
|
+
readonly newId: NewIdentifier;
|
|
7
|
+
readonly signal?: AbortSignal;
|
|
8
|
+
};
|
|
9
|
+
export declare const planSessionCreation: (client: SessionCreationClient, input: SessionCreationInput, options: FacadeOptions) => Promise<SessionCreationPlan>;
|
|
10
|
+
export declare const createSessions: (client: SessionCreationClient, plan: SessionCreationPlan, options: FacadeOptions & {
|
|
11
|
+
readonly onProgress?: (outcomes: readonly SessionCreationOutcome[]) => void;
|
|
12
|
+
readonly previous?: readonly SessionCreationOutcome[];
|
|
13
|
+
}) => Promise<readonly SessionCreationOutcome[]>;
|
|
14
|
+
export declare const awaitSessionRunning: (client: Pick<LocalNodeClient, "showSession">, sessionId: string, options: FacadeOptions & {
|
|
15
|
+
readonly deadlineMilliseconds: number;
|
|
16
|
+
}) => Promise<Session>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=session-creation.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { awaitSessionRunningWith, createSessionsWith, fromPromiseClient, planSessionCreationWith, } from "./effect.js";
|
|
3
|
+
const run = (program, signal) => Effect.runPromise(program, signal === undefined ? undefined : { signal });
|
|
4
|
+
const nextId = (newId) => (prefix) => Effect.sync(() => newId(prefix));
|
|
5
|
+
export const planSessionCreation = (client, input, options) => run(planSessionCreationWith(fromPromiseClient(client), input, nextId(options.newId)), options.signal);
|
|
6
|
+
export const createSessions = (client, plan, options) => {
|
|
7
|
+
const { newId, onProgress, previous, signal } = options;
|
|
8
|
+
return run(createSessionsWith(fromPromiseClient(client), plan, {
|
|
9
|
+
nextId: nextId(newId),
|
|
10
|
+
...(previous === undefined ? {} : { previous }),
|
|
11
|
+
...(onProgress === undefined
|
|
12
|
+
? {}
|
|
13
|
+
: {
|
|
14
|
+
report: (outcomes) => Effect.ignore(Effect.try(() => {
|
|
15
|
+
onProgress(outcomes);
|
|
16
|
+
})),
|
|
17
|
+
}),
|
|
18
|
+
}), signal);
|
|
19
|
+
};
|
|
20
|
+
export const awaitSessionRunning = (client, sessionId, options) => run(awaitSessionRunningWith(fromPromiseClient(client), sessionId, {
|
|
21
|
+
deadlineMilliseconds: options.deadlineMilliseconds,
|
|
22
|
+
nextId: nextId(options.newId),
|
|
23
|
+
}), options.signal);
|
|
24
|
+
//# sourceMappingURL=session-creation.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type CommandReceipt, type FailureDetail, type SessionCreateParameters, type SessionStartParameters, type TurnSendParameters, type Workspace } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeClient } from "../client/index.js";
|
|
3
|
+
import type { MaiaError } from "../request/index.js";
|
|
4
|
+
export declare const MAX_SESSION_CREATION_TASKS = 32;
|
|
5
|
+
export type SessionCreationTemplate = Omit<SessionCreateParameters, "commandId" | "expectedRevision" | "workspaceId">;
|
|
6
|
+
export type SessionCreationInput = {
|
|
7
|
+
readonly projectId?: string;
|
|
8
|
+
readonly session: SessionCreationTemplate;
|
|
9
|
+
readonly split: "lines" | "whole";
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly workspaceId?: string;
|
|
12
|
+
};
|
|
13
|
+
export type SessionCreationItem = {
|
|
14
|
+
readonly commands: {
|
|
15
|
+
readonly create: string;
|
|
16
|
+
readonly send: string;
|
|
17
|
+
readonly start: string;
|
|
18
|
+
};
|
|
19
|
+
readonly index: number;
|
|
20
|
+
readonly line: number;
|
|
21
|
+
readonly task?: string;
|
|
22
|
+
};
|
|
23
|
+
export type SessionCreationRefusal = {
|
|
24
|
+
readonly line: number;
|
|
25
|
+
readonly reason: "over_batch_limit" | "too_long";
|
|
26
|
+
};
|
|
27
|
+
export type SessionCreationPlan = {
|
|
28
|
+
readonly items: readonly SessionCreationItem[];
|
|
29
|
+
readonly refusals: readonly SessionCreationRefusal[];
|
|
30
|
+
readonly session: SessionCreationTemplate;
|
|
31
|
+
readonly workspaceId: string;
|
|
32
|
+
};
|
|
33
|
+
export type SessionCreationStage = "created" | "pending" | "refused" | "running" | "sent" | "started" | "unknown";
|
|
34
|
+
export type SessionCreationOperation = "session.create" | "session.show" | "session.start" | "turn.send";
|
|
35
|
+
export type SessionCreationReceipts = {
|
|
36
|
+
readonly create?: CommandReceipt;
|
|
37
|
+
readonly send?: CommandReceipt;
|
|
38
|
+
readonly start?: CommandReceipt;
|
|
39
|
+
};
|
|
40
|
+
export type SessionCreationOutcome = {
|
|
41
|
+
readonly error?: MaiaError & {
|
|
42
|
+
readonly commandId?: string;
|
|
43
|
+
readonly failure?: FailureDetail;
|
|
44
|
+
readonly operationId: SessionCreationOperation;
|
|
45
|
+
};
|
|
46
|
+
readonly index: number;
|
|
47
|
+
readonly receipts: SessionCreationReceipts;
|
|
48
|
+
readonly sent: {
|
|
49
|
+
readonly create?: SessionCreateParameters;
|
|
50
|
+
readonly send?: TurnSendParameters;
|
|
51
|
+
readonly start?: SessionStartParameters;
|
|
52
|
+
};
|
|
53
|
+
readonly sessionId?: string;
|
|
54
|
+
readonly stage: SessionCreationStage;
|
|
55
|
+
readonly turnId?: string;
|
|
56
|
+
};
|
|
57
|
+
export type SessionCreationClient = Pick<LocalNodeClient, "createSession" | "listWorkspaces" | "sendTurn" | "showSession" | "startSession">;
|
|
58
|
+
export declare const orderExecutionWorkspaces: (workspaces: readonly Workspace[]) => readonly Workspace[];
|
|
59
|
+
type TaskLine = {
|
|
60
|
+
readonly line: number;
|
|
61
|
+
readonly task?: string;
|
|
62
|
+
};
|
|
63
|
+
export declare const splitTasks: (input: SessionCreationInput) => {
|
|
64
|
+
readonly accepted: readonly TaskLine[];
|
|
65
|
+
readonly refusals: readonly SessionCreationRefusal[];
|
|
66
|
+
};
|
|
67
|
+
export declare const sessionCreationSettled: (outcome: SessionCreationOutcome, item: SessionCreationItem) => boolean;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=tasks.d.ts.map
|