@shivaedev/agent-codex 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +47 -1
- package/dist/adapters/Request.d.ts +4 -0
- package/dist/adapters/Request.d.ts.map +1 -0
- package/dist/adapters/Request.js +2 -0
- package/dist/adapters/Request.js.map +1 -0
- package/dist/adapters/UserMessageItem.d.ts +22 -0
- package/dist/adapters/UserMessageItem.d.ts.map +1 -0
- package/dist/adapters/UserMessageItem.js +24 -0
- package/dist/adapters/UserMessageItem.js.map +1 -0
- package/dist/adapters/attributed.d.ts +6 -0
- package/dist/adapters/attributed.d.ts.map +1 -0
- package/dist/adapters/attributed.js +17 -0
- package/dist/adapters/attributed.js.map +1 -0
- package/dist/adapters/backend.d.ts +5 -0
- package/dist/adapters/backend.d.ts.map +1 -0
- package/dist/adapters/backend.js +23 -0
- package/dist/adapters/backend.js.map +1 -0
- package/dist/adapters/census.d.ts +4 -0
- package/dist/adapters/census.d.ts.map +1 -0
- package/dist/adapters/census.js +10 -0
- package/dist/adapters/census.js.map +1 -0
- package/dist/adapters/codexFailure.d.ts +3 -0
- package/dist/adapters/codexFailure.d.ts.map +1 -0
- package/dist/adapters/codexFailure.js +5 -0
- package/dist/adapters/codexFailure.js.map +1 -0
- package/dist/adapters/configuredBackend.d.ts +6 -0
- package/dist/adapters/configuredBackend.d.ts.map +1 -0
- package/dist/adapters/configuredBackend.js +3 -0
- package/dist/adapters/configuredBackend.js.map +1 -0
- package/dist/adapters/connect.d.ts +11 -0
- package/dist/adapters/connect.d.ts.map +1 -0
- package/dist/adapters/connect.js +100 -0
- package/dist/adapters/connect.js.map +1 -0
- package/dist/adapters/delivery.d.ts +18 -0
- package/dist/adapters/delivery.d.ts.map +1 -0
- package/dist/adapters/delivery.js +115 -0
- package/dist/adapters/delivery.js.map +1 -0
- package/dist/adapters/deliveryState.d.ts +31 -0
- package/dist/adapters/deliveryState.d.ts.map +1 -0
- package/dist/adapters/deliveryState.js +29 -0
- package/dist/adapters/deliveryState.js.map +1 -0
- package/dist/adapters/engine.d.ts +8 -0
- package/dist/adapters/engine.d.ts.map +1 -0
- package/dist/adapters/engine.js +9 -0
- package/dist/adapters/engine.js.map +1 -0
- package/dist/adapters/features.d.ts +726 -0
- package/dist/adapters/features.d.ts.map +1 -0
- package/dist/adapters/features.js +46 -0
- package/dist/adapters/features.js.map +1 -0
- package/dist/adapters/handshake.d.ts +5 -0
- package/dist/adapters/handshake.d.ts.map +1 -0
- package/dist/adapters/handshake.js +30 -0
- package/dist/adapters/handshake.js.map +1 -0
- package/dist/adapters/initializeCodex.d.ts +770 -0
- package/dist/adapters/initializeCodex.d.ts.map +1 -0
- package/dist/adapters/initializeCodex.js +8 -0
- package/dist/adapters/initializeCodex.js.map +1 -0
- package/dist/adapters/initializeEngine.d.ts +774 -0
- package/dist/adapters/initializeEngine.d.ts.map +1 -0
- package/dist/adapters/initializeEngine.js +63 -0
- package/dist/adapters/initializeEngine.js.map +1 -0
- package/dist/adapters/items.d.ts +7 -0
- package/dist/adapters/items.d.ts.map +1 -0
- package/dist/adapters/items.js +105 -0
- package/dist/adapters/items.js.map +1 -0
- package/dist/adapters/mapping.d.ts +9 -0
- package/dist/adapters/mapping.d.ts.map +1 -0
- package/dist/adapters/mapping.js +57 -0
- package/dist/adapters/mapping.js.map +1 -0
- package/dist/adapters/process.d.ts +15 -0
- package/dist/adapters/process.d.ts.map +1 -0
- package/dist/adapters/process.js +55 -0
- package/dist/adapters/process.js.map +1 -0
- package/dist/adapters/protocol.d.ts +178 -0
- package/dist/adapters/protocol.d.ts.map +1 -0
- package/dist/adapters/protocol.js +97 -0
- package/dist/adapters/protocol.js.map +1 -0
- package/dist/adapters/protocolItems.d.ts +89 -0
- package/dist/adapters/protocolItems.d.ts.map +1 -0
- package/dist/adapters/protocolItems.js +100 -0
- package/dist/adapters/protocolItems.js.map +1 -0
- package/dist/adapters/rateLimits.d.ts +7 -0
- package/dist/adapters/rateLimits.d.ts.map +1 -0
- package/dist/adapters/rateLimits.js +40 -0
- package/dist/adapters/rateLimits.js.map +1 -0
- package/dist/adapters/reads.d.ts +324 -0
- package/dist/adapters/reads.d.ts.map +1 -0
- package/dist/adapters/reads.js +83 -0
- package/dist/adapters/reads.js.map +1 -0
- package/dist/adapters/recovery.d.ts +324 -0
- package/dist/adapters/recovery.d.ts.map +1 -0
- package/dist/adapters/recovery.js +39 -0
- package/dist/adapters/recovery.js.map +1 -0
- package/dist/adapters/residualApproval.d.ts +4 -0
- package/dist/adapters/residualApproval.d.ts.map +1 -0
- package/dist/adapters/residualApproval.js +21 -0
- package/dist/adapters/residualApproval.js.map +1 -0
- package/dist/adapters/rpc.d.ts +8 -0
- package/dist/adapters/rpc.d.ts.map +1 -0
- package/dist/adapters/rpc.js +2 -0
- package/dist/adapters/rpc.js.map +1 -0
- package/dist/adapters/rpcProtocol.d.ts +11 -0
- package/dist/adapters/rpcProtocol.d.ts.map +1 -0
- package/dist/adapters/rpcProtocol.js +29 -0
- package/dist/adapters/rpcProtocol.js.map +1 -0
- package/dist/adapters/server.d.ts +30 -0
- package/dist/adapters/server.d.ts.map +1 -0
- package/dist/adapters/server.js +68 -0
- package/dist/adapters/server.js.map +1 -0
- package/dist/adapters/session.d.ts +312 -0
- package/dist/adapters/session.d.ts.map +1 -0
- package/dist/adapters/session.js +45 -0
- package/dist/adapters/session.js.map +1 -0
- package/dist/adapters/subagentItems.d.ts +16 -0
- package/dist/adapters/subagentItems.d.ts.map +1 -0
- package/dist/adapters/subagentItems.js +58 -0
- package/dist/adapters/subagentItems.js.map +1 -0
- package/dist/adapters/tellCliVersionOnce.d.ts +5 -0
- package/dist/adapters/tellCliVersionOnce.d.ts.map +1 -0
- package/dist/adapters/tellCliVersionOnce.js +13 -0
- package/dist/adapters/tellCliVersionOnce.js.map +1 -0
- package/dist/adapters/threadClaims.d.ts +8 -0
- package/dist/adapters/threadClaims.d.ts.map +1 -0
- package/dist/adapters/threadClaims.js +20 -0
- package/dist/adapters/threadClaims.js.map +1 -0
- package/dist/adapters/threadSweep.d.ts +15 -0
- package/dist/adapters/threadSweep.d.ts.map +1 -0
- package/dist/adapters/threadSweep.js +57 -0
- package/dist/adapters/threadSweep.js.map +1 -0
- package/dist/adapters/threadTree.d.ts +8 -0
- package/dist/adapters/threadTree.d.ts.map +1 -0
- package/dist/adapters/threadTree.js +125 -0
- package/dist/adapters/threadTree.js.map +1 -0
- package/dist/adapters/turnRequests.d.ts +13 -0
- package/dist/adapters/turnRequests.d.ts.map +1 -0
- package/dist/adapters/turnRequests.js +27 -0
- package/dist/adapters/turnRequests.js.map +1 -0
- package/dist/adapters/userMessageEvent.d.ts +7 -0
- package/dist/adapters/userMessageEvent.d.ts.map +1 -0
- package/dist/adapters/userMessageEvent.js +19 -0
- package/dist/adapters/userMessageEvent.js.map +1 -0
- package/dist/codex.d.ts +10 -1
- package/dist/codex.d.ts.map +1 -1
- package/dist/codex.js +15 -1
- package/dist/codex.js.map +1 -1
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +4 -0
- package/dist/config.js.map +1 -0
- package/package.json +23 -6
- package/src/adapters/Request.ts +3 -0
- package/src/adapters/UserMessageItem.ts +28 -0
- package/src/adapters/attributed.ts +21 -0
- package/src/adapters/backend.ts +29 -0
- package/src/adapters/census.ts +17 -0
- package/src/adapters/codexFailure.ts +4 -0
- package/src/adapters/configuredBackend.ts +6 -0
- package/src/adapters/connect.ts +129 -0
- package/src/adapters/delivery.ts +137 -0
- package/src/adapters/deliveryState.ts +43 -0
- package/src/adapters/engine.ts +11 -0
- package/src/adapters/features.ts +62 -0
- package/src/adapters/handshake.ts +35 -0
- package/src/adapters/initializeCodex.ts +8 -0
- package/src/adapters/initializeEngine.ts +75 -0
- package/src/adapters/items.ts +133 -0
- package/src/adapters/mapping.ts +66 -0
- package/src/adapters/process.ts +69 -0
- package/src/adapters/protocol.ts +125 -0
- package/src/adapters/protocolItems.ts +113 -0
- package/src/adapters/rateLimits.ts +55 -0
- package/src/adapters/reads.ts +93 -0
- package/src/adapters/recovery.ts +44 -0
- package/src/adapters/residualApproval.ts +23 -0
- package/src/adapters/rpc.ts +8 -0
- package/src/adapters/rpcProtocol.ts +28 -0
- package/src/adapters/server.ts +96 -0
- package/src/adapters/session.ts +71 -0
- package/src/adapters/subagentItems.ts +73 -0
- package/src/adapters/tellCliVersionOnce.ts +20 -0
- package/src/adapters/threadClaims.ts +26 -0
- package/src/adapters/threadSweep.ts +79 -0
- package/src/adapters/threadTree.ts +149 -0
- package/src/adapters/turnRequests.ts +45 -0
- package/src/adapters/userMessageEvent.ts +22 -0
- package/src/codex.ts +15 -1
- package/src/config.ts +17 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ProtocolFailure } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
import { itemCompleted, itemStarted } from "#adapters/items.ts";
|
|
4
|
+
import { rawOf } from "#adapters/mapping.ts";
|
|
5
|
+
import { AppServer } from "#adapters/server.ts";
|
|
6
|
+
export const Item = Schema.Struct({ clientId: Schema.optional(Schema.NullOr(Schema.String)), id: Schema.String, type: Schema.String });
|
|
7
|
+
export const Turn = Schema.Struct({
|
|
8
|
+
id: Schema.String,
|
|
9
|
+
items: Schema.Array(Schema.Unknown),
|
|
10
|
+
status: Schema.Literals(["inProgress", "completed", "failed", "interrupted"]),
|
|
11
|
+
});
|
|
12
|
+
const Turns = Schema.Struct({ data: Schema.Array(Turn), nextCursor: Schema.NullOr(Schema.String) });
|
|
13
|
+
const Items = Schema.Struct({ data: Schema.Array(Schema.Struct({ item: Schema.Unknown })), nextCursor: Schema.NullOr(Schema.String) });
|
|
14
|
+
export function decode(schema, value) {
|
|
15
|
+
return Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => new ProtocolFailure({ backend: "codex", message: "Incompatible Codex response" })));
|
|
16
|
+
}
|
|
17
|
+
export const readRequest = Effect.fn("Codex.readRequest")(function* (method, params) {
|
|
18
|
+
const server = yield* AppServer;
|
|
19
|
+
return yield* server.request(method, params).pipe(Effect.mapError((error) => error._tag === "BackendUnavailable" || error._tag === "ProtocolFailure"
|
|
20
|
+
? error
|
|
21
|
+
: new ProtocolFailure({
|
|
22
|
+
backend: "codex",
|
|
23
|
+
message: error.message,
|
|
24
|
+
...(error.providerCode === undefined ? {} : { providerCode: error.providerCode }),
|
|
25
|
+
})));
|
|
26
|
+
});
|
|
27
|
+
export const turns = Effect.fn("Codex.turns")(function* (threadId) {
|
|
28
|
+
const found = [];
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
let cursor = null;
|
|
31
|
+
do {
|
|
32
|
+
const page = yield* readRequest("thread/turns/list", {
|
|
33
|
+
cursor,
|
|
34
|
+
itemsView: "full",
|
|
35
|
+
limit: 100,
|
|
36
|
+
sortDirection: "desc",
|
|
37
|
+
threadId,
|
|
38
|
+
}).pipe(Effect.flatMap((value) => decode(Turns, value)));
|
|
39
|
+
found.push(...page.data);
|
|
40
|
+
cursor = page.nextCursor;
|
|
41
|
+
if (cursor !== null && seen.has(cursor)) {
|
|
42
|
+
return yield* new ProtocolFailure({ backend: "codex", message: "Repeated turn cursor" });
|
|
43
|
+
}
|
|
44
|
+
if (cursor !== null) {
|
|
45
|
+
seen.add(cursor);
|
|
46
|
+
}
|
|
47
|
+
} while (cursor !== null);
|
|
48
|
+
return found;
|
|
49
|
+
});
|
|
50
|
+
export function observe(receipt) {
|
|
51
|
+
return turns(receipt.session?.value ?? "").pipe(Effect.map((values) => {
|
|
52
|
+
const turn = values.find((candidate) => candidate.id === receipt.reference.value);
|
|
53
|
+
return turn === undefined
|
|
54
|
+
? { reason: "The accepted turn is not observable; absence does not authorize replay", type: "missing" }
|
|
55
|
+
: { state: turn.status === "inProgress" ? "running" : turn.status, type: "known" };
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
export const transcript = Effect.fn("Codex.transcript")(function* (receipt) {
|
|
59
|
+
const events = [];
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
let cursor = null;
|
|
62
|
+
do {
|
|
63
|
+
const page = yield* readRequest("thread/items/list", {
|
|
64
|
+
cursor,
|
|
65
|
+
limit: 100,
|
|
66
|
+
sortDirection: "asc",
|
|
67
|
+
threadId: receipt.session?.value,
|
|
68
|
+
turnId: receipt.reference.value,
|
|
69
|
+
}).pipe(Effect.flatMap((value) => decode(Items, value)));
|
|
70
|
+
for (const { item } of page.data) {
|
|
71
|
+
events.push(...itemStarted(rawOf("thread/items/list", item), item), ...itemCompleted(rawOf("thread/items/list", item), item));
|
|
72
|
+
}
|
|
73
|
+
cursor = page.nextCursor;
|
|
74
|
+
if (cursor !== null && seen.has(cursor)) {
|
|
75
|
+
return yield* new ProtocolFailure({ backend: "codex", message: "Repeated item cursor" });
|
|
76
|
+
}
|
|
77
|
+
if (cursor !== null) {
|
|
78
|
+
seen.add(cursor);
|
|
79
|
+
}
|
|
80
|
+
} while (cursor !== null);
|
|
81
|
+
return { completeness: events.some((event) => event.type === "raw") ? "partial" : "complete", events };
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=reads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reads.js","sourceRoot":"","sources":["../../src/adapters/reads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,eAAe,EAAoB,MAAM,8BAA8B,CAAC;AAEjF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,M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AAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAE,SAAmB,CAAC,CAAC,CAAE,UAAoB,EAAE,MAAM,EAAE,CAAC;AAC9H,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ReadFailure } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
import type { Receipt } from "@shivaedev/agent/run.ts";
|
|
4
|
+
import { AppServer } from "#adapters/server.ts";
|
|
5
|
+
export declare function receiptOf(operationId: string, threadId: string, turnId: string): Receipt;
|
|
6
|
+
export declare const recovery: (sessions: Map<string, {
|
|
7
|
+
driver: {
|
|
8
|
+
interrupt: (turnId: string) => Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
9
|
+
queue: (input: import("@shivaedev/agent/run.ts").Input) => Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
10
|
+
recovered: (turnId: string, running: boolean) => Effect.Effect<void, never, never>;
|
|
11
|
+
start: (input: import("@shivaedev/agent/run.ts").ImageInput, operationId: string) => Effect.Effect<string, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
12
|
+
steer: (expected: string, input: import("@shivaedev/agent/run.ts").Input) => Effect.Effect<undefined, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
13
|
+
track: (notification: import("./rpc.ts").RpcNotification) => Effect.Effect<void, never, never>;
|
|
14
|
+
};
|
|
15
|
+
events: import("effect/PubSub").PubSub<{
|
|
16
|
+
readonly origin?: {
|
|
17
|
+
readonly node?: string | undefined;
|
|
18
|
+
readonly parentNode?: string | undefined;
|
|
19
|
+
readonly spawnedBy: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
readonly raw?: {
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly payload: string;
|
|
24
|
+
readonly source: string;
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly receipt: {
|
|
27
|
+
readonly backend: string;
|
|
28
|
+
readonly operationId: string;
|
|
29
|
+
readonly reference: {
|
|
30
|
+
readonly value: string;
|
|
31
|
+
readonly version: number;
|
|
32
|
+
};
|
|
33
|
+
readonly session?: {
|
|
34
|
+
readonly value: string;
|
|
35
|
+
readonly version: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
};
|
|
38
|
+
readonly type: "acknowledged";
|
|
39
|
+
} | {
|
|
40
|
+
readonly origin?: {
|
|
41
|
+
readonly node?: string | undefined;
|
|
42
|
+
readonly parentNode?: string | undefined;
|
|
43
|
+
readonly spawnedBy: string;
|
|
44
|
+
} | undefined;
|
|
45
|
+
readonly raw?: {
|
|
46
|
+
readonly kind: string;
|
|
47
|
+
readonly payload: string;
|
|
48
|
+
readonly source: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
readonly state: "accepted" | "awaiting-input" | "completed" | "failed" | "interrupted" | "running";
|
|
51
|
+
readonly type: "execution";
|
|
52
|
+
} | {
|
|
53
|
+
readonly origin?: {
|
|
54
|
+
readonly node?: string | undefined;
|
|
55
|
+
readonly parentNode?: string | undefined;
|
|
56
|
+
readonly spawnedBy: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
readonly raw?: {
|
|
59
|
+
readonly kind: string;
|
|
60
|
+
readonly payload: string;
|
|
61
|
+
readonly source: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
readonly reference: string;
|
|
64
|
+
readonly type: "session.opened";
|
|
65
|
+
} | {
|
|
66
|
+
readonly origin?: {
|
|
67
|
+
readonly node?: string | undefined;
|
|
68
|
+
readonly parentNode?: string | undefined;
|
|
69
|
+
readonly spawnedBy: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
readonly raw?: {
|
|
72
|
+
readonly kind: string;
|
|
73
|
+
readonly payload: string;
|
|
74
|
+
readonly source: string;
|
|
75
|
+
} | undefined;
|
|
76
|
+
readonly inputId?: string | undefined;
|
|
77
|
+
readonly parts: readonly ({
|
|
78
|
+
readonly text: string;
|
|
79
|
+
readonly type: "text";
|
|
80
|
+
} | {
|
|
81
|
+
readonly mediaType: string;
|
|
82
|
+
readonly path: string;
|
|
83
|
+
readonly type: "image";
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: string;
|
|
86
|
+
readonly payload: string;
|
|
87
|
+
readonly type: "native";
|
|
88
|
+
})[];
|
|
89
|
+
readonly role: "agent" | "user";
|
|
90
|
+
readonly type: "message";
|
|
91
|
+
} | {
|
|
92
|
+
readonly origin?: {
|
|
93
|
+
readonly node?: string | undefined;
|
|
94
|
+
readonly parentNode?: string | undefined;
|
|
95
|
+
readonly spawnedBy: string;
|
|
96
|
+
} | undefined;
|
|
97
|
+
readonly raw?: {
|
|
98
|
+
readonly kind: string;
|
|
99
|
+
readonly payload: string;
|
|
100
|
+
readonly source: string;
|
|
101
|
+
} | undefined;
|
|
102
|
+
readonly text: string;
|
|
103
|
+
readonly type: "thinking";
|
|
104
|
+
} | {
|
|
105
|
+
readonly origin?: {
|
|
106
|
+
readonly node?: string | undefined;
|
|
107
|
+
readonly parentNode?: string | undefined;
|
|
108
|
+
readonly spawnedBy: string;
|
|
109
|
+
} | undefined;
|
|
110
|
+
readonly raw?: {
|
|
111
|
+
readonly kind: string;
|
|
112
|
+
readonly payload: string;
|
|
113
|
+
readonly source: string;
|
|
114
|
+
} | undefined;
|
|
115
|
+
readonly input: string;
|
|
116
|
+
readonly name: string;
|
|
117
|
+
readonly providerName?: string | undefined;
|
|
118
|
+
readonly toolId: string;
|
|
119
|
+
readonly type: "tool.started";
|
|
120
|
+
} | {
|
|
121
|
+
readonly origin?: {
|
|
122
|
+
readonly node?: string | undefined;
|
|
123
|
+
readonly parentNode?: string | undefined;
|
|
124
|
+
readonly spawnedBy: string;
|
|
125
|
+
} | undefined;
|
|
126
|
+
readonly raw?: {
|
|
127
|
+
readonly kind: string;
|
|
128
|
+
readonly payload: string;
|
|
129
|
+
readonly source: string;
|
|
130
|
+
} | undefined;
|
|
131
|
+
readonly ok: boolean;
|
|
132
|
+
readonly output: string;
|
|
133
|
+
readonly toolId: string;
|
|
134
|
+
readonly type: "tool.completed";
|
|
135
|
+
} | {
|
|
136
|
+
readonly origin?: {
|
|
137
|
+
readonly node?: string | undefined;
|
|
138
|
+
readonly parentNode?: string | undefined;
|
|
139
|
+
readonly spawnedBy: string;
|
|
140
|
+
} | undefined;
|
|
141
|
+
readonly raw?: {
|
|
142
|
+
readonly kind: string;
|
|
143
|
+
readonly payload: string;
|
|
144
|
+
readonly source: string;
|
|
145
|
+
} | undefined;
|
|
146
|
+
readonly approvalId: string;
|
|
147
|
+
readonly description: string;
|
|
148
|
+
readonly toolId?: string | undefined;
|
|
149
|
+
readonly type: "approval.requested";
|
|
150
|
+
} | {
|
|
151
|
+
readonly origin?: {
|
|
152
|
+
readonly node?: string | undefined;
|
|
153
|
+
readonly parentNode?: string | undefined;
|
|
154
|
+
readonly spawnedBy: string;
|
|
155
|
+
} | undefined;
|
|
156
|
+
readonly raw?: {
|
|
157
|
+
readonly kind: string;
|
|
158
|
+
readonly payload: string;
|
|
159
|
+
readonly source: string;
|
|
160
|
+
} | undefined;
|
|
161
|
+
readonly type: "usage";
|
|
162
|
+
readonly cacheReadTokens?: number | undefined;
|
|
163
|
+
readonly cacheWriteTokens?: number | undefined;
|
|
164
|
+
readonly inputTokens?: number | undefined;
|
|
165
|
+
readonly model?: string | undefined;
|
|
166
|
+
readonly outputTokens?: number | undefined;
|
|
167
|
+
readonly scope: "cumulative" | "delta";
|
|
168
|
+
readonly unit: "run" | "session" | "turn";
|
|
169
|
+
} | {
|
|
170
|
+
readonly origin?: {
|
|
171
|
+
readonly node?: string | undefined;
|
|
172
|
+
readonly parentNode?: string | undefined;
|
|
173
|
+
readonly spawnedBy: string;
|
|
174
|
+
} | undefined;
|
|
175
|
+
readonly raw?: {
|
|
176
|
+
readonly kind: string;
|
|
177
|
+
readonly payload: string;
|
|
178
|
+
readonly source: string;
|
|
179
|
+
} | undefined;
|
|
180
|
+
readonly type: "cost";
|
|
181
|
+
readonly amount: number;
|
|
182
|
+
readonly currency: string;
|
|
183
|
+
readonly model?: string | undefined;
|
|
184
|
+
readonly scope: "cumulative" | "delta";
|
|
185
|
+
readonly source: "estimated" | "provider";
|
|
186
|
+
readonly unit: "run" | "session" | "turn";
|
|
187
|
+
} | {
|
|
188
|
+
readonly origin?: {
|
|
189
|
+
readonly node?: string | undefined;
|
|
190
|
+
readonly parentNode?: string | undefined;
|
|
191
|
+
readonly spawnedBy: string;
|
|
192
|
+
} | undefined;
|
|
193
|
+
readonly raw?: {
|
|
194
|
+
readonly kind: string;
|
|
195
|
+
readonly payload: string;
|
|
196
|
+
readonly source: string;
|
|
197
|
+
} | undefined;
|
|
198
|
+
readonly model: string;
|
|
199
|
+
readonly reason?: string | undefined;
|
|
200
|
+
readonly type: "model.changed";
|
|
201
|
+
} | {
|
|
202
|
+
readonly origin?: {
|
|
203
|
+
readonly node?: string | undefined;
|
|
204
|
+
readonly parentNode?: string | undefined;
|
|
205
|
+
readonly spawnedBy: string;
|
|
206
|
+
} | undefined;
|
|
207
|
+
readonly raw?: {
|
|
208
|
+
readonly kind: string;
|
|
209
|
+
readonly payload: string;
|
|
210
|
+
readonly source: string;
|
|
211
|
+
} | undefined;
|
|
212
|
+
readonly charter?: string | undefined;
|
|
213
|
+
readonly childRef: string;
|
|
214
|
+
readonly label?: string | undefined;
|
|
215
|
+
readonly parentRef?: string | undefined;
|
|
216
|
+
readonly spawnedBy: string;
|
|
217
|
+
readonly type: "child.opened";
|
|
218
|
+
} | {
|
|
219
|
+
readonly origin?: {
|
|
220
|
+
readonly node?: string | undefined;
|
|
221
|
+
readonly parentNode?: string | undefined;
|
|
222
|
+
readonly spawnedBy: string;
|
|
223
|
+
} | undefined;
|
|
224
|
+
readonly raw?: {
|
|
225
|
+
readonly kind: string;
|
|
226
|
+
readonly payload: string;
|
|
227
|
+
readonly source: string;
|
|
228
|
+
} | undefined;
|
|
229
|
+
readonly childRef: string;
|
|
230
|
+
readonly outcome: "completed" | "failed" | "interrupted" | "unknown";
|
|
231
|
+
readonly summary?: string | undefined;
|
|
232
|
+
readonly type: "child.ended";
|
|
233
|
+
} | {
|
|
234
|
+
readonly origin?: {
|
|
235
|
+
readonly node?: string | undefined;
|
|
236
|
+
readonly parentNode?: string | undefined;
|
|
237
|
+
readonly spawnedBy: string;
|
|
238
|
+
} | undefined;
|
|
239
|
+
readonly raw?: {
|
|
240
|
+
readonly kind: string;
|
|
241
|
+
readonly payload: string;
|
|
242
|
+
readonly source: string;
|
|
243
|
+
} | undefined;
|
|
244
|
+
readonly status: "allowed" | "rejected" | "unknown" | "warning";
|
|
245
|
+
readonly type: "rate.limit";
|
|
246
|
+
readonly windows: readonly {
|
|
247
|
+
readonly durationMinutes?: number | undefined;
|
|
248
|
+
readonly model?: string | undefined;
|
|
249
|
+
readonly resetsAt?: number | undefined;
|
|
250
|
+
readonly usedPercent: number;
|
|
251
|
+
}[];
|
|
252
|
+
} | {
|
|
253
|
+
readonly origin?: {
|
|
254
|
+
readonly node?: string | undefined;
|
|
255
|
+
readonly parentNode?: string | undefined;
|
|
256
|
+
readonly spawnedBy: string;
|
|
257
|
+
} | undefined;
|
|
258
|
+
readonly raw?: {
|
|
259
|
+
readonly kind: string;
|
|
260
|
+
readonly payload: string;
|
|
261
|
+
readonly source: string;
|
|
262
|
+
} | undefined;
|
|
263
|
+
readonly tasks: readonly {
|
|
264
|
+
readonly description: string;
|
|
265
|
+
readonly id: string;
|
|
266
|
+
readonly kind: string;
|
|
267
|
+
}[];
|
|
268
|
+
readonly type: "session.background";
|
|
269
|
+
} | {
|
|
270
|
+
readonly origin?: {
|
|
271
|
+
readonly node?: string | undefined;
|
|
272
|
+
readonly parentNode?: string | undefined;
|
|
273
|
+
readonly spawnedBy: string;
|
|
274
|
+
} | undefined;
|
|
275
|
+
readonly raw?: {
|
|
276
|
+
readonly kind: string;
|
|
277
|
+
readonly payload: string;
|
|
278
|
+
readonly source: string;
|
|
279
|
+
} | undefined;
|
|
280
|
+
readonly type: "gap";
|
|
281
|
+
readonly detail: string;
|
|
282
|
+
readonly kind: string;
|
|
283
|
+
} | {
|
|
284
|
+
readonly origin?: {
|
|
285
|
+
readonly node?: string | undefined;
|
|
286
|
+
readonly parentNode?: string | undefined;
|
|
287
|
+
readonly spawnedBy: string;
|
|
288
|
+
} | undefined;
|
|
289
|
+
readonly raw: {
|
|
290
|
+
readonly kind: string;
|
|
291
|
+
readonly payload: string;
|
|
292
|
+
readonly source: string;
|
|
293
|
+
};
|
|
294
|
+
readonly type: "raw";
|
|
295
|
+
}>;
|
|
296
|
+
threadId: string;
|
|
297
|
+
}>) => Effect.Effect<{
|
|
298
|
+
operations: Map<string, string | undefined>;
|
|
299
|
+
reconcile: (operationId: string) => Effect.Effect<{
|
|
300
|
+
readonly receipt: {
|
|
301
|
+
readonly backend: string;
|
|
302
|
+
readonly operationId: string;
|
|
303
|
+
readonly reference: {
|
|
304
|
+
readonly value: string;
|
|
305
|
+
readonly version: number;
|
|
306
|
+
};
|
|
307
|
+
readonly session?: {
|
|
308
|
+
readonly value: string;
|
|
309
|
+
readonly version: number;
|
|
310
|
+
} | undefined;
|
|
311
|
+
};
|
|
312
|
+
readonly type: "accepted";
|
|
313
|
+
} | {
|
|
314
|
+
readonly evidence: string;
|
|
315
|
+
readonly operationId: string;
|
|
316
|
+
readonly type: "not-accepted";
|
|
317
|
+
} | {
|
|
318
|
+
readonly operationId: string;
|
|
319
|
+
readonly reason: string;
|
|
320
|
+
readonly type: "uncertain";
|
|
321
|
+
}, ReadFailure, never>;
|
|
322
|
+
refusals: Map<string, string>;
|
|
323
|
+
}, never, AppServer>;
|
|
324
|
+
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/adapters/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAExF;AACD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAiC0B,MAAM;;;;;;;;;;;;;;;;;;;;;;;;oBACnD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Item, turns } from "#adapters/reads.ts";
|
|
3
|
+
import { AppServer } from "#adapters/server.ts";
|
|
4
|
+
export function receiptOf(operationId, threadId, turnId) {
|
|
5
|
+
return { backend: "codex", operationId, reference: { value: turnId, version: 1 }, session: { value: threadId, version: 1 } };
|
|
6
|
+
}
|
|
7
|
+
export const recovery = Effect.fn("Codex.recovery")(function* (sessions) {
|
|
8
|
+
const server = yield* AppServer;
|
|
9
|
+
const operations = new Map();
|
|
10
|
+
const refusals = new Map();
|
|
11
|
+
const reconcile = Effect.fn("Codex.reconcile")(function* (operationId) {
|
|
12
|
+
const refusal = refusals.get(operationId);
|
|
13
|
+
if (refusal !== undefined) {
|
|
14
|
+
return { evidence: refusal, operationId, type: "not-accepted" };
|
|
15
|
+
}
|
|
16
|
+
const threadId = operations.get(operationId);
|
|
17
|
+
if (threadId === undefined) {
|
|
18
|
+
return { operationId, reason: "No local thread association; recover the session reference in the application", type: "uncertain" };
|
|
19
|
+
}
|
|
20
|
+
const matches = (yield* turns(threadId)).filter((turn) => turn.items.some((item) => {
|
|
21
|
+
const decoded = Schema.decodeUnknownOption(Item)(item);
|
|
22
|
+
return decoded._tag === "Some" && decoded.value.type === "userMessage" && decoded.value.clientId === operationId;
|
|
23
|
+
}));
|
|
24
|
+
const found = matches[0];
|
|
25
|
+
if (matches.length !== 1 || found === undefined) {
|
|
26
|
+
return {
|
|
27
|
+
operationId,
|
|
28
|
+
reason: matches.length > 1
|
|
29
|
+
? "Multiple turns match this operation; preserve ownership"
|
|
30
|
+
: "No matching turn is observable; absence does not authorize replay",
|
|
31
|
+
type: "uncertain",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
yield* sessions.get(threadId)?.driver.recovered(found.id, found.status === "inProgress") ?? Effect.void;
|
|
35
|
+
return { receipt: receiptOf(operationId, threadId, found.id), type: "accepted" };
|
|
36
|
+
});
|
|
37
|
+
return { operations, reconcile: (operationId) => reconcile(operationId).pipe(Effect.provideService(AppServer, server)), refusals };
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.js","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,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;AAC5I,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"residualApproval.d.ts","sourceRoot":"","sources":["../../src/adapters/residualApproval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAiBlF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
const DECLINED = "No approval consumer is configured";
|
|
3
|
+
export function residualApproval(request) {
|
|
4
|
+
switch (request.method) {
|
|
5
|
+
case "item/commandExecution/requestApproval":
|
|
6
|
+
case "item/fileChange/requestApproval":
|
|
7
|
+
return Option.some({ decision: "decline" });
|
|
8
|
+
case "item/permissions/requestApproval":
|
|
9
|
+
return Option.some({ permissions: {}, scope: "turn" });
|
|
10
|
+
case "item/tool/requestUserInput":
|
|
11
|
+
return Option.some({ answers: {} });
|
|
12
|
+
case "mcpServer/elicitation/request":
|
|
13
|
+
return Option.some({ "_meta": null, action: "decline", content: null });
|
|
14
|
+
case "execCommandApproval":
|
|
15
|
+
case "applyPatchApproval":
|
|
16
|
+
return Option.some({ decision: { denied: { rejection: DECLINED } } });
|
|
17
|
+
default:
|
|
18
|
+
return Option.none();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=residualApproval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"residualApproval.js","sourceRoot":"","sources":["../../src/adapters/residualApproval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM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@@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/adapters/rpc.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ProtocolFailure, Rejected } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
export declare const Envelope: Schema.Struct<{
|
|
4
|
+
readonly error: Schema.optional<Schema.Unknown>;
|
|
5
|
+
readonly id: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.String]>>;
|
|
6
|
+
readonly method: Schema.optional<Schema.String>;
|
|
7
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
8
|
+
readonly result: Schema.optional<Schema.Unknown>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function rejected(value: unknown): ProtocolFailure | Rejected;
|
|
11
|
+
//# sourceMappingURL=rpcProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpcProtocol.d.ts","sourceRoot":"","sources":["../../src/adapters/rpcProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACzE,eAAO,MAAM,QAAQ;;;;;;EAMnB,CAAC;AAOH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,8BAYtC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ProtocolFailure, Rejected } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
export const Envelope = Schema.Struct({
|
|
4
|
+
error: Schema.optional(Schema.Unknown),
|
|
5
|
+
id: Schema.optional(Schema.Union([Schema.Number, Schema.String])),
|
|
6
|
+
method: Schema.optional(Schema.String),
|
|
7
|
+
params: Schema.optional(Schema.Unknown),
|
|
8
|
+
result: Schema.optional(Schema.Unknown),
|
|
9
|
+
});
|
|
10
|
+
const RpcError = Schema.Struct({
|
|
11
|
+
code: Schema.optional(Schema.Number),
|
|
12
|
+
data: Schema.optional(Schema.Struct({ codexErrorInfo: Schema.optional(Schema.Unknown) })),
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
});
|
|
15
|
+
const Capacity = Schema.Literals(["rateLimitExceeded", "flexUnavailable", "serverOverloaded", "usageLimitExceeded"]);
|
|
16
|
+
export function rejected(value) {
|
|
17
|
+
const error = Schema.decodeUnknownOption(RpcError)(value);
|
|
18
|
+
if (error._tag === "None") {
|
|
19
|
+
return new ProtocolFailure({ backend: "codex", message: "Invalid Codex rejection" });
|
|
20
|
+
}
|
|
21
|
+
const capacity = Schema.decodeUnknownOption(Capacity)(error.value.data?.codexErrorInfo);
|
|
22
|
+
const code = error.value.code === -32_001 ? "session-queue-full" : String(error.value.code ?? "rejected");
|
|
23
|
+
return new Rejected({
|
|
24
|
+
backend: "codex",
|
|
25
|
+
message: error.value.message,
|
|
26
|
+
providerCode: capacity._tag === "Some" ? capacity.value : code,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=rpcProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpcProtocol.js","sourceRoot":"","sources":["../../src/adapters/rpcProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACjE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAA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G,OAAO,IAAI,QAAQ,CAAC;QACnB,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;QAC5B,YAAY,EAAE,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;KAC9D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Effect, PubSub, type Scope } from "effect";
|
|
2
|
+
import { BackendUnavailable } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
import { type LineProcess } from "#adapters/process.ts";
|
|
4
|
+
import type { RpcNotification } from "#adapters/rpc.ts";
|
|
5
|
+
import type { CodexConfiguration } from "#config.ts";
|
|
6
|
+
export declare const openServer: (config: CodexConfiguration, spawn?: (() => LineProcess) | undefined) => Effect.Effect<{
|
|
7
|
+
deny: (id: number | string) => void;
|
|
8
|
+
notify: (method: string, params: unknown) => void;
|
|
9
|
+
request: (method: string, params: unknown, operationId?: string) => Effect.Effect<unknown, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
10
|
+
respond: (id: number | string, result: unknown) => void;
|
|
11
|
+
claims: import("#adapters/threadClaims.ts").ThreadClaims;
|
|
12
|
+
exited: Effect.Effect<void, never, never>;
|
|
13
|
+
notifications: PubSub.PubSub<RpcNotification>;
|
|
14
|
+
registrations: Map<string, Scope.Scope>;
|
|
15
|
+
}, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, Scope.Scope>;
|
|
16
|
+
export type CodexServer = Effect.Success<ReturnType<typeof openServer>>;
|
|
17
|
+
declare const AppServer_base: Context.ServiceClass<AppServer, "@shivaedev/agent-codex/AppServer", {
|
|
18
|
+
deny: (id: number | string) => void;
|
|
19
|
+
notify: (method: string, params: unknown) => void;
|
|
20
|
+
request: (method: string, params: unknown, operationId?: string) => Effect.Effect<unknown, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
21
|
+
respond: (id: number | string, result: unknown) => void;
|
|
22
|
+
claims: import("#adapters/threadClaims.ts").ThreadClaims;
|
|
23
|
+
exited: Effect.Effect<void, never, never>;
|
|
24
|
+
notifications: PubSub.PubSub<RpcNotification>;
|
|
25
|
+
registrations: Map<string, Scope.Scope>;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class AppServer extends AppServer_base {
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/adapters/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAAY,MAAM,EAAuB,MAAM,EAAiB,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAG1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,eAAO,MAAM,UAAU,8CAAsF,WAAW;;;;;;;;;yMAgFtH,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC;;;;;;;;;;;AAExE,qBAAa,SAAU,SAAQ,cAA6E;CAAG"}
|