@dudousxd/nestjs-agent-opencode 0.2.1 → 0.4.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/dist/durable/index.cjs +52 -2
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -1
- package/dist/durable/index.d.ts +1 -1
- package/dist/durable/index.js +54 -4
- package/dist/durable/index.js.map +1 -1
- package/dist/{engine-0YkBLWZR.d.cts → engine-BNNxQAFV.d.cts} +22 -3
- package/dist/{engine-0YkBLWZR.d.ts → engine-BNNxQAFV.d.ts} +22 -3
- package/dist/index.cjs +52 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as OpenCodeClient, e as OpenCodeEvent, f as OpenCodeForm, g as OpenCodeFormValue, h as OpenCodeFormField, i as OpenCodeMcpEndpoint, O as OpenCodeTurns, a as OpenCodeEngineSettings } from './engine-
|
|
2
|
-
export { I as InMemoryOpenCodeSessionStore, M as Milestone, j as OpenCodeAmendment, k as OpenCodeCallContext, c as OpenCodeEngineOptions, b as OpenCodeHost, l as OpenCodeKeyValue, m as OpenCodeModelRef, n as OpenCodePermissionRequest, o as OpenCodePermissionRule, p as OpenCodeReplyMismatchError, q as OpenCodeRunResult, r as OpenCodeServer, s as OpenCodeSessionCreate, t as OpenCodeSessionRef, u as OpenCodeSessionStore, v as OpenCodeToolCall, w as OpenCodeToolRefusedError, x as OpenCodeToolsClaims, y as OpenCodeToolsOptions, z as OpenCodeToolsTokens, A as OpenCodeTurn, B as OpenCodeTurnContext, C as OpenCodeUsage, P as PendingAsk, S as SessionHandle, D as StepCost, E as StepModel, T as TurnOutcome, F as addUsage, G as emptyUsage, H as keyValueOpenCodeSessionStore, J as openCode, K as openCodeControllers, L as openCodeProviders, N as usageOf } from './engine-
|
|
1
|
+
import { d as OpenCodeClient, e as OpenCodeEvent, f as OpenCodeForm, g as OpenCodeFormValue, h as OpenCodeFormField, i as OpenCodeMcpEndpoint, O as OpenCodeTurns, a as OpenCodeEngineSettings } from './engine-BNNxQAFV.cjs';
|
|
2
|
+
export { I as InMemoryOpenCodeSessionStore, M as Milestone, j as OpenCodeAmendment, k as OpenCodeCallContext, c as OpenCodeEngineOptions, b as OpenCodeHost, l as OpenCodeKeyValue, m as OpenCodeModelRef, n as OpenCodePermissionRequest, o as OpenCodePermissionRule, p as OpenCodeReplyMismatchError, q as OpenCodeRunResult, r as OpenCodeServer, s as OpenCodeSessionCreate, t as OpenCodeSessionRef, u as OpenCodeSessionStore, v as OpenCodeToolCall, w as OpenCodeToolRefusedError, x as OpenCodeToolsClaims, y as OpenCodeToolsOptions, z as OpenCodeToolsTokens, A as OpenCodeTurn, B as OpenCodeTurnContext, C as OpenCodeUsage, P as PendingAsk, S as SessionHandle, D as StepCost, E as StepModel, T as TurnOutcome, F as addUsage, G as emptyUsage, H as keyValueOpenCodeSessionStore, J as openCode, K as openCodeControllers, L as openCodeProviders, N as usageOf } from './engine-BNNxQAFV.cjs';
|
|
3
3
|
import { ElicitationRequest, ElicitationQuestion, AgentRunner, AgentRunInput, AgentRunStartOptions, HumanReply } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import '@dudousxd/nestjs-agent';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as OpenCodeClient, e as OpenCodeEvent, f as OpenCodeForm, g as OpenCodeFormValue, h as OpenCodeFormField, i as OpenCodeMcpEndpoint, O as OpenCodeTurns, a as OpenCodeEngineSettings } from './engine-
|
|
2
|
-
export { I as InMemoryOpenCodeSessionStore, M as Milestone, j as OpenCodeAmendment, k as OpenCodeCallContext, c as OpenCodeEngineOptions, b as OpenCodeHost, l as OpenCodeKeyValue, m as OpenCodeModelRef, n as OpenCodePermissionRequest, o as OpenCodePermissionRule, p as OpenCodeReplyMismatchError, q as OpenCodeRunResult, r as OpenCodeServer, s as OpenCodeSessionCreate, t as OpenCodeSessionRef, u as OpenCodeSessionStore, v as OpenCodeToolCall, w as OpenCodeToolRefusedError, x as OpenCodeToolsClaims, y as OpenCodeToolsOptions, z as OpenCodeToolsTokens, A as OpenCodeTurn, B as OpenCodeTurnContext, C as OpenCodeUsage, P as PendingAsk, S as SessionHandle, D as StepCost, E as StepModel, T as TurnOutcome, F as addUsage, G as emptyUsage, H as keyValueOpenCodeSessionStore, J as openCode, K as openCodeControllers, L as openCodeProviders, N as usageOf } from './engine-
|
|
1
|
+
import { d as OpenCodeClient, e as OpenCodeEvent, f as OpenCodeForm, g as OpenCodeFormValue, h as OpenCodeFormField, i as OpenCodeMcpEndpoint, O as OpenCodeTurns, a as OpenCodeEngineSettings } from './engine-BNNxQAFV.js';
|
|
2
|
+
export { I as InMemoryOpenCodeSessionStore, M as Milestone, j as OpenCodeAmendment, k as OpenCodeCallContext, c as OpenCodeEngineOptions, b as OpenCodeHost, l as OpenCodeKeyValue, m as OpenCodeModelRef, n as OpenCodePermissionRequest, o as OpenCodePermissionRule, p as OpenCodeReplyMismatchError, q as OpenCodeRunResult, r as OpenCodeServer, s as OpenCodeSessionCreate, t as OpenCodeSessionRef, u as OpenCodeSessionStore, v as OpenCodeToolCall, w as OpenCodeToolRefusedError, x as OpenCodeToolsClaims, y as OpenCodeToolsOptions, z as OpenCodeToolsTokens, A as OpenCodeTurn, B as OpenCodeTurnContext, C as OpenCodeUsage, P as PendingAsk, S as SessionHandle, D as StepCost, E as StepModel, T as TurnOutcome, F as addUsage, G as emptyUsage, H as keyValueOpenCodeSessionStore, J as openCode, K as openCodeControllers, L as openCodeProviders, N as usageOf } from './engine-BNNxQAFV.js';
|
|
3
3
|
import { ElicitationRequest, ElicitationQuestion, AgentRunner, AgentRunInput, AgentRunStartOptions, HumanReply } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import '@dudousxd/nestjs-agent';
|
package/dist/index.js
CHANGED
|
@@ -143,14 +143,15 @@ OpenCodeMcpController = _ts_decorate([
|
|
|
143
143
|
|
|
144
144
|
// src/mcp.ts
|
|
145
145
|
import { createHash, createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
146
|
-
import { REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, ToolNotFoundError, rememberInputSchema, schemaExtensionOf } from "@dudousxd/nestjs-agent-core";
|
|
146
|
+
import { GenuiRunRecorder, REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, ToolNotFoundError, rememberInputSchema, schemaExtensionOf } from "@dudousxd/nestjs-agent-core";
|
|
147
|
+
import { turnChannel } from "@dudousxd/nestjs-agent-core/genui";
|
|
147
148
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
148
149
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
149
150
|
import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
|
|
150
151
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
151
152
|
|
|
152
153
|
// src/turn.ts
|
|
153
|
-
import { encodeStreamEvent, settleElicitation } from "@dudousxd/nestjs-agent-core";
|
|
154
|
+
import { encodeStreamEvent, resolveToolConfirmation, settleElicitation } from "@dudousxd/nestjs-agent-core";
|
|
154
155
|
import { ConflictException } from "@nestjs/common";
|
|
155
156
|
|
|
156
157
|
// src/forms.ts
|
|
@@ -1020,6 +1021,8 @@ ${delta}` : delta;
|
|
|
1020
1021
|
}
|
|
1021
1022
|
const ttlMs = requirement.ttlMs !== void 0 && Number.isFinite(requirement.ttlMs) && requirement.ttlMs > 0 ? Math.floor(requirement.ttlMs) : void 0;
|
|
1022
1023
|
const expiresAt = ttlMs !== void 0 ? new Date(Date.now() + ttlMs).toISOString() : void 0;
|
|
1024
|
+
const tool = this.a.approvalPresentation?.(action);
|
|
1025
|
+
const confirmation = tool !== void 0 ? resolveToolConfirmation(tool.name, args, tool.presentation) : void 0;
|
|
1023
1026
|
this.segment.calls.push({
|
|
1024
1027
|
id: req.id,
|
|
1025
1028
|
name: action,
|
|
@@ -1034,6 +1037,9 @@ ${delta}` : delta;
|
|
|
1034
1037
|
toolType: "action",
|
|
1035
1038
|
input: args,
|
|
1036
1039
|
status: "pending_approval",
|
|
1040
|
+
...confirmation !== void 0 ? {
|
|
1041
|
+
confirmation
|
|
1042
|
+
} : {},
|
|
1037
1043
|
runId: this.a.runId,
|
|
1038
1044
|
approver: requirement.approver,
|
|
1039
1045
|
...expiresAt !== void 0 ? {
|
|
@@ -1051,6 +1057,9 @@ ${delta}` : delta;
|
|
|
1051
1057
|
kind: "approval-requested",
|
|
1052
1058
|
id: req.id,
|
|
1053
1059
|
approver: requirement.approver,
|
|
1060
|
+
...confirmation !== void 0 ? {
|
|
1061
|
+
confirmation
|
|
1062
|
+
} : {},
|
|
1054
1063
|
...expiresAt !== void 0 ? {
|
|
1055
1064
|
expiresAt
|
|
1056
1065
|
} : {}
|
|
@@ -1456,6 +1465,8 @@ var OpenCodeMcpEndpoint2 = class {
|
|
|
1456
1465
|
}
|
|
1457
1466
|
turns;
|
|
1458
1467
|
tokens;
|
|
1468
|
+
/** Genui telemetry of the UI calls OpenCode makes (its code mode calls tools here, not in the loop). */
|
|
1469
|
+
genui = new GenuiRunRecorder();
|
|
1459
1470
|
constructor(turns, tokens) {
|
|
1460
1471
|
this.turns = turns;
|
|
1461
1472
|
this.tokens = tokens;
|
|
@@ -1587,7 +1598,7 @@ var OpenCodeMcpEndpoint2 = class {
|
|
|
1587
1598
|
if (spec.kind === "action" && !await this.turns.spendApproval(turn.runId, name, turn.input)) {
|
|
1588
1599
|
throw new OpenCodeToolRefusedError(`"${name}" is an action and nobody approved this call; ask for the permission first.`);
|
|
1589
1600
|
}
|
|
1590
|
-
|
|
1601
|
+
const invoke = /* @__PURE__ */ __name(() => registry.invoke(name, args ?? {}, {
|
|
1591
1602
|
actor,
|
|
1592
1603
|
threadId: turn.ctx.threadId,
|
|
1593
1604
|
runId: turn.runId,
|
|
@@ -1604,7 +1615,24 @@ var OpenCodeMcpEndpoint2 = class {
|
|
|
1604
1615
|
} : {}
|
|
1605
1616
|
}, this.turns.rolesPolicyFor(turn.input), allowed !== void 0 ? {
|
|
1606
1617
|
allowedTools: allowed
|
|
1607
|
-
} : {});
|
|
1618
|
+
} : {}), "invoke");
|
|
1619
|
+
return this.genui.track({
|
|
1620
|
+
store: this.turns.store,
|
|
1621
|
+
marker: spec.genui,
|
|
1622
|
+
runId: turn.runId,
|
|
1623
|
+
threadId: turn.ctx.threadId,
|
|
1624
|
+
actorRef: actor.id,
|
|
1625
|
+
...turn.input.agentName !== void 0 ? {
|
|
1626
|
+
agentName: turn.input.agentName
|
|
1627
|
+
} : {},
|
|
1628
|
+
channel: turnChannel(turn.input.pageContext),
|
|
1629
|
+
modelId: turn.input.model ?? "opencode",
|
|
1630
|
+
call: {
|
|
1631
|
+
id: `mcp:${turn.runId}:${requestId}`,
|
|
1632
|
+
name,
|
|
1633
|
+
input: args ?? {}
|
|
1634
|
+
}
|
|
1635
|
+
}, invoke);
|
|
1608
1636
|
}
|
|
1609
1637
|
/** `remember`: one fact, at the actor's own scope only — as the loop serves it. */
|
|
1610
1638
|
async remember(turn, args) {
|
|
@@ -1831,6 +1859,25 @@ var OpenCodeTurns = class {
|
|
|
1831
1859
|
get toolsServer() {
|
|
1832
1860
|
return this.settings.tools?.server ?? "aviary";
|
|
1833
1861
|
}
|
|
1862
|
+
/** The app tool an OpenCode permission `action` names, and its presentation — `undefined` for a built-in. */
|
|
1863
|
+
presentationOf(action) {
|
|
1864
|
+
if (this.settings.tools === void 0) return void 0;
|
|
1865
|
+
const server = this.toolsServer;
|
|
1866
|
+
for (const prefix of [
|
|
1867
|
+
`${server}.`,
|
|
1868
|
+
`${server}_`
|
|
1869
|
+
]) {
|
|
1870
|
+
if (!action.startsWith(prefix)) continue;
|
|
1871
|
+
const spec = this.registry.spec(action.slice(prefix.length));
|
|
1872
|
+
if (spec !== void 0) return {
|
|
1873
|
+
name: spec.name,
|
|
1874
|
+
...spec.presentation !== void 0 ? {
|
|
1875
|
+
presentation: spec.presentation
|
|
1876
|
+
} : {}
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
return void 0;
|
|
1880
|
+
}
|
|
1834
1881
|
/** The roles policy a turn's tools are gated by (the agent's own). */
|
|
1835
1882
|
rolesPolicyFor(input) {
|
|
1836
1883
|
return this.deps.forAgent(input.agentName).rolesPolicy;
|
|
@@ -2563,6 +2610,9 @@ ${body}
|
|
|
2563
2610
|
agentName: input.agentName
|
|
2564
2611
|
} : {}
|
|
2565
2612
|
}), "approvalFor"),
|
|
2613
|
+
// An app tool reaches OpenCode as `<server>.<name>` / `<server>_<name>`: its own presentation
|
|
2614
|
+
// words the approval card. OpenCode's built-ins (`bash`, `edit`) have none.
|
|
2615
|
+
approvalPresentation: /* @__PURE__ */ __name((action) => this.presentationOf(action), "approvalPresentation"),
|
|
2566
2616
|
modelLabel: input.model ?? "opencode",
|
|
2567
2617
|
priceStep: /* @__PURE__ */ __name((step) => this.priceStep(step), "priceStep"),
|
|
2568
2618
|
...spent !== void 0 ? {
|