@maiaos/sdk 0.1.0-canary.10
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 +62 -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/agents/agents.d.ts +11 -0
- package/dist/agents/agents.js +5 -0
- package/dist/agents/effect.d.ts +5 -0
- package/dist/agents/effect.js +59 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/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 +298 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/local-node-client.d.ts +106 -0
- package/dist/client/local-node-client.js +4 -0
- package/dist/connection/connection.d.ts +28 -0
- package/dist/connection/connection.js +5 -0
- package/dist/connection/effect.d.ts +5 -0
- package/dist/connection/effect.js +211 -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 +29 -0
- package/dist/index.js +24 -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 +55 -0
- package/dist/node/bridge.js +286 -0
- package/dist/node/deadlines.d.ts +5 -0
- package/dist/node/deadlines.js +32 -0
- package/dist/node/discovery.d.ts +192 -0
- package/dist/node/discovery.js +408 -0
- package/dist/node/effect.d.ts +10 -0
- package/dist/node/effect.js +10 -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 +270 -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 +29 -0
- package/dist/node/ssh.js +122 -0
- package/dist/node/transport.d.ts +52 -0
- package/dist/node/transport.js +211 -0
- package/dist/node-changes/change.d.ts +16 -0
- package/dist/node-changes/change.js +16 -0
- package/dist/node-changes/effect.d.ts +11 -0
- package/dist/node-changes/effect.js +62 -0
- package/dist/node-changes/index.d.ts +3 -0
- package/dist/node-changes/index.js +3 -0
- package/dist/node-changes/node-changes.d.ts +7 -0
- package/dist/node-changes/node-changes.js +8 -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 +83 -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 +14 -0
- package/dist/remote-node/remote-node.js +5 -0
- package/dist/request/classify.d.ts +15 -0
- package/dist/request/classify.js +97 -0
- package/dist/request/client-error.d.ts +11 -0
- package/dist/request/client-error.js +20 -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 +10 -0
- package/dist/request/options.js +2 -0
- package/dist/routine/effect.d.ts +5 -0
- package/dist/routine/effect.js +115 -0
- package/dist/routine/index.d.ts +2 -0
- package/dist/routine/index.js +2 -0
- package/dist/routine/routine.d.ts +17 -0
- package/dist/routine/routine.js +5 -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/team-workspace/effect.d.ts +5 -0
- package/dist/team-workspace/effect.js +25 -0
- package/dist/team-workspace/index.d.ts +2 -0
- package/dist/team-workspace/index.js +2 -0
- package/dist/team-workspace/team-workspace.d.ts +9 -0
- package/dist/team-workspace/team-workspace.js +5 -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,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
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MAX_TURN_INPUT_BYTES, } from "@maiaos/protocol";
|
|
2
|
+
export const MAX_SESSION_CREATION_TASKS = 32;
|
|
3
|
+
export const orderExecutionWorkspaces = (workspaces) => workspaces
|
|
4
|
+
.filter((workspace) => workspace.state === "ready")
|
|
5
|
+
.toSorted((left, right) => Number(right.kind === "local-main") -
|
|
6
|
+
Number(left.kind === "local-main") ||
|
|
7
|
+
left.name.localeCompare(right.name));
|
|
8
|
+
const utf8 = new TextEncoder();
|
|
9
|
+
const taskLines = (input) => {
|
|
10
|
+
if (input.split === "whole") {
|
|
11
|
+
const task = input.text.trim();
|
|
12
|
+
return [{ line: 1, ...(task === "" ? {} : { task }) }];
|
|
13
|
+
}
|
|
14
|
+
return input.text
|
|
15
|
+
.split(/\r?\n/u)
|
|
16
|
+
.map((text, index) => ({ line: index + 1, task: text.trim() }))
|
|
17
|
+
.filter((entry) => entry.task !== "");
|
|
18
|
+
};
|
|
19
|
+
const fits = (entry) => entry.task === undefined ||
|
|
20
|
+
utf8.encode(entry.task).byteLength <= MAX_TURN_INPUT_BYTES;
|
|
21
|
+
export const splitTasks = (input) => {
|
|
22
|
+
const lines = taskLines(input);
|
|
23
|
+
const fitting = lines.filter((entry) => fits(entry));
|
|
24
|
+
const refusals = [
|
|
25
|
+
...lines
|
|
26
|
+
.filter((entry) => !fits(entry))
|
|
27
|
+
.map((entry) => ({ line: entry.line, reason: "too_long" })),
|
|
28
|
+
...fitting.slice(MAX_SESSION_CREATION_TASKS).map((entry) => ({
|
|
29
|
+
line: entry.line,
|
|
30
|
+
reason: "over_batch_limit",
|
|
31
|
+
})),
|
|
32
|
+
].toSorted((left, right) => left.line - right.line);
|
|
33
|
+
return { accepted: fitting.slice(0, MAX_SESSION_CREATION_TASKS), refusals };
|
|
34
|
+
};
|
|
35
|
+
export const sessionCreationSettled = (outcome, item) => outcome.stage === "sent" ||
|
|
36
|
+
(outcome.stage === "started" && item.task === undefined);
|
|
37
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { initialSessionAttachView, isNewSessionRecord, MAX_SESSION_VIEW_TURN_ITEMS, MAX_SESSION_VIEW_TURNS, reduceSessionAttach, sessionAttachCursor, type SessionAttachView, sessionItemText, type SessionViewEnd, type SessionViewItem, type SessionViewTurn, } from "./view.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FailureDetail, SessionAttachFrame, SessionItem, SessionItemStatus, SessionStreamRecord, SessionTurnStatus } from "@maiaos/protocol";
|
|
2
|
+
export declare const MAX_SESSION_VIEW_TURNS = 64;
|
|
3
|
+
export declare const MAX_SESSION_VIEW_TURN_ITEMS = 256;
|
|
4
|
+
export type SessionViewItem = {
|
|
5
|
+
readonly item: SessionItem;
|
|
6
|
+
readonly itemId: string;
|
|
7
|
+
readonly sequence: number;
|
|
8
|
+
readonly status: "open" | SessionItemStatus;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly truncated: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type SessionViewTurn = {
|
|
13
|
+
readonly failure?: FailureDetail;
|
|
14
|
+
readonly items: readonly SessionViewItem[];
|
|
15
|
+
readonly status: "running" | SessionTurnStatus;
|
|
16
|
+
readonly turnId: string;
|
|
17
|
+
};
|
|
18
|
+
export type SessionViewEnd = {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly kind: "error";
|
|
21
|
+
readonly message: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "resync";
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
};
|
|
26
|
+
export type SessionAttachView = {
|
|
27
|
+
readonly end?: SessionViewEnd;
|
|
28
|
+
readonly epoch?: string;
|
|
29
|
+
readonly sequence: number;
|
|
30
|
+
readonly sessionId?: string;
|
|
31
|
+
readonly synchronized: boolean;
|
|
32
|
+
readonly turns: readonly SessionViewTurn[];
|
|
33
|
+
};
|
|
34
|
+
export declare const initialSessionAttachView: SessionAttachView;
|
|
35
|
+
export declare const sessionItemText: (item: SessionItem) => string;
|
|
36
|
+
export declare const isNewSessionRecord: (view: SessionAttachView, record: SessionStreamRecord) => boolean;
|
|
37
|
+
export declare const sessionAttachCursor: (view: SessionAttachView) => undefined | {
|
|
38
|
+
readonly epoch: string;
|
|
39
|
+
readonly sequence: number;
|
|
40
|
+
};
|
|
41
|
+
export declare const reduceSessionAttach: (view: SessionAttachView, frame: SessionAttachFrame) => SessionAttachView;
|
|
42
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export const MAX_SESSION_VIEW_TURNS = 64;
|
|
2
|
+
export const MAX_SESSION_VIEW_TURN_ITEMS = 256;
|
|
3
|
+
export const initialSessionAttachView = {
|
|
4
|
+
sequence: 0,
|
|
5
|
+
synchronized: false,
|
|
6
|
+
turns: [],
|
|
7
|
+
};
|
|
8
|
+
export const sessionItemText = (item) => {
|
|
9
|
+
switch (item.kind) {
|
|
10
|
+
case "message":
|
|
11
|
+
case "reasoning":
|
|
12
|
+
return item.text;
|
|
13
|
+
case "command":
|
|
14
|
+
case "tool_call":
|
|
15
|
+
return item.output ?? "";
|
|
16
|
+
case "approval_request":
|
|
17
|
+
return item.summary;
|
|
18
|
+
case "error":
|
|
19
|
+
return item.message;
|
|
20
|
+
case "file_change":
|
|
21
|
+
case "usage":
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const isTruncated = (item) => "truncated" in item && item.truncated === true;
|
|
26
|
+
export const isNewSessionRecord = (view, record) => record.sequence > view.sequence;
|
|
27
|
+
export const sessionAttachCursor = (view) => view.epoch === undefined
|
|
28
|
+
? undefined
|
|
29
|
+
: { epoch: view.epoch, sequence: view.sequence };
|
|
30
|
+
const withTurn = (turns, turnId, update) => {
|
|
31
|
+
const index = turns.findIndex((turn) => turn.turnId === turnId);
|
|
32
|
+
if (index !== -1)
|
|
33
|
+
return turns.map((turn, position) => position === index ? update(turn) : turn);
|
|
34
|
+
const added = update({ items: [], status: "running", turnId });
|
|
35
|
+
return [...turns, added].slice(-MAX_SESSION_VIEW_TURNS);
|
|
36
|
+
};
|
|
37
|
+
const withItem = (turn, itemId, update) => {
|
|
38
|
+
const index = turn.items.findIndex((item) => item.itemId === itemId);
|
|
39
|
+
const next = update(index === -1 ? undefined : turn.items[index]);
|
|
40
|
+
if (next === undefined)
|
|
41
|
+
return turn;
|
|
42
|
+
return {
|
|
43
|
+
...turn,
|
|
44
|
+
items: index === -1
|
|
45
|
+
? [...turn.items, next].slice(-MAX_SESSION_VIEW_TURN_ITEMS)
|
|
46
|
+
: turn.items.map((item, position) => position === index ? next : item),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const applyItemRecord = (turn, record) => withItem(turn, record.itemId, (current) => {
|
|
50
|
+
if (record.type === "item.delta")
|
|
51
|
+
return current === undefined
|
|
52
|
+
? undefined
|
|
53
|
+
: {
|
|
54
|
+
...current,
|
|
55
|
+
sequence: record.sequence,
|
|
56
|
+
text: current.text + record.delta,
|
|
57
|
+
};
|
|
58
|
+
const completed = record.type === "item.completed";
|
|
59
|
+
if (current !== undefined && current.status !== "open" && !completed)
|
|
60
|
+
return current;
|
|
61
|
+
return {
|
|
62
|
+
item: record.item,
|
|
63
|
+
itemId: record.itemId,
|
|
64
|
+
sequence: record.sequence,
|
|
65
|
+
status: completed ? record.status : "open",
|
|
66
|
+
text: sessionItemText(record.item),
|
|
67
|
+
truncated: isTruncated(record.item),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const applyRecord = (turns, record) => withTurn(turns, record.turnId, (turn) => {
|
|
71
|
+
if (record.type === "turn.started")
|
|
72
|
+
return turn;
|
|
73
|
+
if (record.type === "turn.completed")
|
|
74
|
+
return {
|
|
75
|
+
...turn,
|
|
76
|
+
...(record.failure === undefined ? {} : { failure: record.failure }),
|
|
77
|
+
status: record.status,
|
|
78
|
+
};
|
|
79
|
+
return applyItemRecord(turn, record);
|
|
80
|
+
});
|
|
81
|
+
const applyRecords = (view, records) => records.reduce((current, record) => isNewSessionRecord(current, record)
|
|
82
|
+
? {
|
|
83
|
+
...current,
|
|
84
|
+
sequence: record.sequence,
|
|
85
|
+
turns: applyRecord(current.turns, record),
|
|
86
|
+
}
|
|
87
|
+
: current, view);
|
|
88
|
+
const applySynchronized = (view, frame) => ({
|
|
89
|
+
...view,
|
|
90
|
+
sequence: Math.max(view.sequence, frame.data.sequence),
|
|
91
|
+
synchronized: true,
|
|
92
|
+
turns: frame.data.openItems.reduce((turns, open) => withTurn(turns, open.turnId, (turn) => withItem(turn, open.itemId, (current) => current === undefined
|
|
93
|
+
? undefined
|
|
94
|
+
: {
|
|
95
|
+
...current,
|
|
96
|
+
sequence: Math.max(current.sequence, open.sequence),
|
|
97
|
+
text: open.text,
|
|
98
|
+
truncated: current.truncated || open.truncated === true,
|
|
99
|
+
})), view.turns),
|
|
100
|
+
});
|
|
101
|
+
const applyAttached = (view, frame) => {
|
|
102
|
+
const restart = frame.data.mode === "snapshot" ||
|
|
103
|
+
frame.data.epoch !== view.epoch ||
|
|
104
|
+
frame.data.sessionId !== view.sessionId;
|
|
105
|
+
const base = restart ? initialSessionAttachView : view;
|
|
106
|
+
return {
|
|
107
|
+
epoch: frame.data.epoch,
|
|
108
|
+
sequence: base.sequence,
|
|
109
|
+
sessionId: frame.data.sessionId,
|
|
110
|
+
synchronized: false,
|
|
111
|
+
turns: base.turns,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export const reduceSessionAttach = (view, frame) => {
|
|
115
|
+
switch (frame.kind) {
|
|
116
|
+
case "attached":
|
|
117
|
+
return applyAttached(view, frame);
|
|
118
|
+
case "records":
|
|
119
|
+
return applyRecords(view, frame.data.records);
|
|
120
|
+
case "synchronized":
|
|
121
|
+
return applySynchronized(view, frame);
|
|
122
|
+
case "heartbeat":
|
|
123
|
+
return view;
|
|
124
|
+
case "resync":
|
|
125
|
+
return { ...view, end: { kind: "resync", reason: frame.data.reason } };
|
|
126
|
+
case "error":
|
|
127
|
+
return {
|
|
128
|
+
...view,
|
|
129
|
+
end: {
|
|
130
|
+
code: frame.data.error.code,
|
|
131
|
+
kind: "error",
|
|
132
|
+
message: frame.data.error.message,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ProtocolError } from "@maiaos/protocol";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import { MaiaClientError } from "../request/index.js";
|
|
6
|
+
import type { StreamRelay } from "./stream.js";
|
|
7
|
+
export type ResumeStep = {
|
|
8
|
+
readonly cursor?: string;
|
|
9
|
+
readonly kind: "frame";
|
|
10
|
+
} | {
|
|
11
|
+
readonly error: ProtocolError;
|
|
12
|
+
readonly kind: "error";
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "resnapshot";
|
|
15
|
+
};
|
|
16
|
+
export declare const RESNAPSHOT: {
|
|
17
|
+
readonly kind: "resnapshot";
|
|
18
|
+
};
|
|
19
|
+
export type Resumable<TSubscribe, TFrame> = {
|
|
20
|
+
readonly decode: (text: string, messageId: string) => Option.Option<TFrame>;
|
|
21
|
+
readonly nextId: (prefix: "request") => Effect.Effect<string>;
|
|
22
|
+
readonly relay: StreamRelay<TSubscribe>;
|
|
23
|
+
readonly step: (frame: TFrame) => ResumeStep;
|
|
24
|
+
readonly subscribe: (messageId: string, cursor?: string) => TSubscribe;
|
|
25
|
+
readonly terminal: (frame: TFrame) => boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare const MAX_BUFFERED_FRAMES = 256;
|
|
28
|
+
export declare const resumeStream: <TSubscribe, TFrame>(input: Resumable<TSubscribe, TFrame>) => Stream.Stream<TFrame | typeof RESNAPSHOT, MaiaClientError>;
|
|
29
|
+
//# sourceMappingURL=effect.d.ts.map
|