@dudousxd/nestjs-agent-opencode 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/dist/durable/index.cjs +3138 -0
- package/dist/durable/index.cjs.map +1 -0
- package/dist/durable/index.d.cts +75 -0
- package/dist/durable/index.d.ts +75 -0
- package/dist/durable/index.js +3109 -0
- package/dist/durable/index.js.map +1 -0
- package/dist/engine-C_WSZ0cZ.d.cts +846 -0
- package/dist/engine-C_WSZ0cZ.d.ts +846 -0
- package/dist/index.cjs +2938 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +124 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +2889 -0
- package/dist/index.js.map +1 -0
- package/package.json +93 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AgentEngine } from '@dudousxd/nestjs-agent';
|
|
2
|
+
import { O as OpenCodeTurns, a as OpenCodeEngineSettings, b as OpenCodeHost, c as OpenCodeEngineOptions } from '../engine-C_WSZ0cZ.js';
|
|
3
|
+
import { AgentRunner, AgentStore, AgentRunInput, AgentRunStartOptions, HumanReply } from '@dudousxd/nestjs-agent-core';
|
|
4
|
+
import { WorkflowService } from '@dudousxd/nestjs-durable';
|
|
5
|
+
import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
|
|
6
|
+
import '@nestjs/common';
|
|
7
|
+
import 'node:http';
|
|
8
|
+
import '@modelcontextprotocol/sdk/server/index.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runs OpenCode turns as `@dudousxd/nestjs-durable` workflows ({@link OpenCodeRunWorkflow}): a
|
|
12
|
+
* person's decision is a durable signal, so a turn waiting on one survives restarts and is resumed
|
|
13
|
+
* by whichever process receives it. Needs a cross-process `TokenStreamSink` when more than one
|
|
14
|
+
* process serves the agent.
|
|
15
|
+
*/
|
|
16
|
+
declare class DurableOpenCodeAgentRunner implements AgentRunner {
|
|
17
|
+
private readonly workflows;
|
|
18
|
+
private readonly runs;
|
|
19
|
+
private readonly turns;
|
|
20
|
+
private readonly settings;
|
|
21
|
+
private readonly host;
|
|
22
|
+
private readonly store;
|
|
23
|
+
private readonly logger;
|
|
24
|
+
constructor(workflows: WorkflowService, runs: RunGateway, turns: OpenCodeTurns, settings: OpenCodeEngineSettings, host: OpenCodeHost, store: AgentStore);
|
|
25
|
+
runIdFor(input: AgentRunInput): string;
|
|
26
|
+
start(input: AgentRunInput, options?: AgentRunStartOptions): Promise<{
|
|
27
|
+
runId: string;
|
|
28
|
+
}>;
|
|
29
|
+
isRunActive(runId: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Signal a person's reply into the run. Answers addressed at an approval (a call recorded with an
|
|
32
|
+
* approver; questions have none) are refused ({@link OpenCodeReplyMismatchError}, a 409) before
|
|
33
|
+
* they reach the workflow, which would otherwise spend its wait on them.
|
|
34
|
+
*/
|
|
35
|
+
signal(runId: string, toolCallId: string, reply: HumanReply): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Interrupt OpenCode, cancel the run in the runtime (a run parked on a person never runs its body
|
|
38
|
+
* again), and settle it here: the queue, the thread, the `cancelled` frame and the run row.
|
|
39
|
+
*/
|
|
40
|
+
cancel(runId: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare const OPENCODE_RUN_WORKFLOW = "agent.opencode.run";
|
|
44
|
+
/** The token a person's answer to `toolCallId` is signalled under — the library's own convention. */
|
|
45
|
+
declare function decisionToken(runId: string, toolCallId: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* An OpenCode turn as a durable workflow:
|
|
48
|
+
*
|
|
49
|
+
* begin → prompt → observe:0 → [ wait for a person (signal `tool:<run>:<call>`) → reply:n → observe:n+1 ]* → finish
|
|
50
|
+
*
|
|
51
|
+
* Every step is checkpointed. A turn parked on a person is a suspended run with a signal waiter: an
|
|
52
|
+
* API restart loses nothing, and the decision resumes it on whichever process takes it — replaying
|
|
53
|
+
* the steps from their checkpoints and replying to OpenCode from there (`OpenCodeTurns` rebuilds the
|
|
54
|
+
* live turn, and re-prompts a fresh session when OpenCode itself restarted meanwhile). A process
|
|
55
|
+
* that dies while OpenCode works re-runs that `observe` step, which catches up on what OpenCode
|
|
56
|
+
* asked while nobody listened.
|
|
57
|
+
*/
|
|
58
|
+
declare class OpenCodeRunWorkflow {
|
|
59
|
+
private readonly turns;
|
|
60
|
+
private readonly runs?;
|
|
61
|
+
constructor(turns: OpenCodeTurns, runs?: RunGateway | undefined);
|
|
62
|
+
run(ctx: WorkflowCtx, input: AgentRunInput): Promise<{
|
|
63
|
+
outcome: string;
|
|
64
|
+
}>;
|
|
65
|
+
private cancelled;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `openCode()` whose turns are durable workflows — `AgentModule.forRoot({ engine:
|
|
70
|
+
* openCodeDurable({ host }) })` next to a configured `DurableModule`. A turn waiting on a person
|
|
71
|
+
* survives restarts and is resumed by whichever process receives the decision.
|
|
72
|
+
*/
|
|
73
|
+
declare function openCodeDurable(options: OpenCodeEngineOptions): AgentEngine;
|
|
74
|
+
|
|
75
|
+
export { DurableOpenCodeAgentRunner, OPENCODE_RUN_WORKFLOW, OpenCodeRunWorkflow, decisionToken, openCodeDurable };
|