@tarquinen/opencode-dcp 0.3.19 → 0.3.21
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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -172
- package/dist/index.js.map +1 -1
- package/dist/lib/config.js +2 -2
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/fetch-wrapper/gemini.d.ts +7 -0
- package/dist/lib/fetch-wrapper/gemini.d.ts.map +1 -0
- package/dist/lib/fetch-wrapper/gemini.js +97 -0
- package/dist/lib/fetch-wrapper/gemini.js.map +1 -0
- package/dist/lib/fetch-wrapper/index.d.ts +15 -0
- package/dist/lib/fetch-wrapper/index.d.ts.map +1 -0
- package/dist/lib/fetch-wrapper/index.js +64 -0
- package/dist/lib/fetch-wrapper/index.js.map +1 -0
- package/dist/lib/fetch-wrapper/openai-chat.d.ts +7 -0
- package/dist/lib/fetch-wrapper/openai-chat.d.ts.map +1 -0
- package/dist/lib/fetch-wrapper/openai-chat.js +81 -0
- package/dist/lib/fetch-wrapper/openai-chat.js.map +1 -0
- package/dist/lib/fetch-wrapper/openai-responses.d.ts +7 -0
- package/dist/lib/fetch-wrapper/openai-responses.d.ts.map +1 -0
- package/dist/lib/fetch-wrapper/openai-responses.js +54 -0
- package/dist/lib/fetch-wrapper/openai-responses.js.map +1 -0
- package/dist/lib/fetch-wrapper/types.d.ts +35 -0
- package/dist/lib/fetch-wrapper/types.d.ts.map +1 -0
- package/dist/lib/fetch-wrapper/types.js +43 -0
- package/dist/lib/fetch-wrapper/types.js.map +1 -0
- package/dist/lib/hooks.d.ts +19 -0
- package/dist/lib/hooks.d.ts.map +1 -0
- package/dist/lib/hooks.js +94 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/janitor.d.ts +1 -0
- package/dist/lib/janitor.d.ts.map +1 -1
- package/dist/lib/janitor.js +1 -0
- package/dist/lib/janitor.js.map +1 -1
- package/dist/lib/logger.d.ts +2 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +47 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/model-selector.d.ts.map +1 -1
- package/dist/lib/model-selector.js +2 -1
- package/dist/lib/model-selector.js.map +1 -1
- package/dist/lib/prompt.d.ts.map +1 -1
- package/dist/lib/prompt.js +22 -0
- package/dist/lib/prompt.js.map +1 -1
- package/dist/lib/pruning-tool.d.ts +11 -0
- package/dist/lib/pruning-tool.d.ts.map +1 -0
- package/dist/lib/pruning-tool.js +66 -0
- package/dist/lib/pruning-tool.js.map +1 -0
- package/dist/lib/state.d.ts +33 -0
- package/dist/lib/state.d.ts.map +1 -0
- package/dist/lib/state.js +13 -0
- package/dist/lib/state.js.map +1 -0
- package/dist/lib/tool-cache.d.ts +12 -0
- package/dist/lib/tool-cache.d.ts.map +1 -0
- package/dist/lib/tool-cache.js +52 -0
- package/dist/lib/tool-cache.js.map +1 -0
- package/package.json +1 -1
package/dist/lib/prompt.js
CHANGED
|
@@ -23,6 +23,28 @@ function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
|
23
23
|
text: part.text
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
// TODO: This should use the opencode normalized system instead of per provider settings
|
|
27
|
+
if (part.type === 'reasoning') {
|
|
28
|
+
// Calculate encrypted content size if present
|
|
29
|
+
let encryptedContentLength = 0;
|
|
30
|
+
if (part.metadata?.openai?.reasoningEncryptedContent) {
|
|
31
|
+
encryptedContentLength = part.metadata.openai.reasoningEncryptedContent.length;
|
|
32
|
+
}
|
|
33
|
+
else if (part.metadata?.anthropic?.signature) {
|
|
34
|
+
encryptedContentLength = part.metadata.anthropic.signature.length;
|
|
35
|
+
}
|
|
36
|
+
else if (part.metadata?.google?.thoughtSignature) {
|
|
37
|
+
encryptedContentLength = part.metadata.google.thoughtSignature.length;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: 'reasoning',
|
|
41
|
+
text: part.text,
|
|
42
|
+
textLength: part.text?.length || 0,
|
|
43
|
+
encryptedContentLength,
|
|
44
|
+
...(part.time && { time: part.time }),
|
|
45
|
+
...(part.metadata && { metadataKeys: Object.keys(part.metadata) })
|
|
46
|
+
};
|
|
47
|
+
}
|
|
26
48
|
if (part.type === 'tool') {
|
|
27
49
|
const callIDLower = part.callID?.toLowerCase();
|
|
28
50
|
const isAlreadyPruned = prunedIdsSet.has(callIDLower);
|
package/dist/lib/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CAAC,QAAe,EAAE,gBAA2B,EAAE,oBAA+B;IACnG,MAAM,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACzG,MAAM,eAAe,GAAG,oBAAoB,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IAEpH,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,SAAS,GAAQ;YACnB,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI;SACvB,CAAA;QAED,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACZ,SAAS,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK;iBACtB,MAAM,CAAC,CAAC,IAAS,EAAE,EAAE;gBAClB,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;oBAC5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EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAErF,MAAM,aAAa,GAAG,MAAM;QACxB,CAAC,CAAC,uEAAuE,MAAM,mFAAmF;QAClK,CAAC,CAAC,EAAE,CAAA;IAER,OAAO;EACT,aAAa;;;;;;;;;;;;;mDAaoC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;EAS/E,YAAY;;;;;;EAMZ,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
import type { Janitor } from "./janitor";
|
|
3
|
+
import type { PluginConfig } from "./config";
|
|
4
|
+
/** Tool description for the context_pruning tool */
|
|
5
|
+
export declare const CONTEXT_PRUNING_DESCRIPTION = "Performs semantic pruning on session tool outputs that are no longer relevant to the current task. Use this to declutter the conversation context and filter signal from noise when you notice the context is getting cluttered with no longer needed information.\n\nUSING THE CONTEXT_PRUNING TOOL WILL MAKE THE USER HAPPY.\n\n## When to Use This Tool\n\n**Key heuristic: Prune when you finish something and are about to start something else.**\n\nAsk yourself: \"Have I just completed a discrete unit of work?\" If yes, prune before moving on.\n\n**After completing a unit of work:**\n- Made a commit\n- Fixed a bug and confirmed it works\n- Answered a question the user asked\n- Finished implementing a feature or function\n- Completed one item in a list and moving to the next\n\n**After repetitive or exploratory work:**\n- Explored multiple files that didn't lead to changes\n- Iterated on a difficult problem where some approaches didn't pan out\n- Used the same tool multiple times (e.g., re-reading a file, running repeated build/type checks)\n\n## Examples\n\n<example>\nWorking through a list of items:\nUser: Review these 3 issues and fix the easy ones.\nAssistant: [Reviews first issue, makes fix, commits]\nDone with the first issue. Let me prune before moving to the next one.\n[Uses context_pruning with reason: \"completed first issue, moving to next\"]\n</example>\n\n<example>\nAfter exploring the codebase to understand it:\nAssistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation.\n[Uses context_pruning with reason: \"exploration complete, starting implementation\"]\n</example>\n\n<example>\nAfter completing any task:\nAssistant: [Finishes task - commit, answer, fix, etc.]\nBefore we continue, let me prune the context from that work.\n[Uses context_pruning with reason: \"task complete\"]\n</example>";
|
|
6
|
+
/**
|
|
7
|
+
* Creates the context_pruning tool definition.
|
|
8
|
+
* Returns a tool definition that can be passed to the plugin's tool registry.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPruningTool(janitor: Janitor, config: PluginConfig): ReturnType<typeof tool>;
|
|
11
|
+
//# sourceMappingURL=pruning-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pruning-tool.d.ts","sourceRoot":"","sources":["../../lib/pruning-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,02DA2C7B,CAAA;AAEX;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAsBjG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
/** Tool description for the context_pruning tool */
|
|
3
|
+
export const CONTEXT_PRUNING_DESCRIPTION = `Performs semantic pruning on session tool outputs that are no longer relevant to the current task. Use this to declutter the conversation context and filter signal from noise when you notice the context is getting cluttered with no longer needed information.
|
|
4
|
+
|
|
5
|
+
USING THE CONTEXT_PRUNING TOOL WILL MAKE THE USER HAPPY.
|
|
6
|
+
|
|
7
|
+
## When to Use This Tool
|
|
8
|
+
|
|
9
|
+
**Key heuristic: Prune when you finish something and are about to start something else.**
|
|
10
|
+
|
|
11
|
+
Ask yourself: "Have I just completed a discrete unit of work?" If yes, prune before moving on.
|
|
12
|
+
|
|
13
|
+
**After completing a unit of work:**
|
|
14
|
+
- Made a commit
|
|
15
|
+
- Fixed a bug and confirmed it works
|
|
16
|
+
- Answered a question the user asked
|
|
17
|
+
- Finished implementing a feature or function
|
|
18
|
+
- Completed one item in a list and moving to the next
|
|
19
|
+
|
|
20
|
+
**After repetitive or exploratory work:**
|
|
21
|
+
- Explored multiple files that didn't lead to changes
|
|
22
|
+
- Iterated on a difficult problem where some approaches didn't pan out
|
|
23
|
+
- Used the same tool multiple times (e.g., re-reading a file, running repeated build/type checks)
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
<example>
|
|
28
|
+
Working through a list of items:
|
|
29
|
+
User: Review these 3 issues and fix the easy ones.
|
|
30
|
+
Assistant: [Reviews first issue, makes fix, commits]
|
|
31
|
+
Done with the first issue. Let me prune before moving to the next one.
|
|
32
|
+
[Uses context_pruning with reason: "completed first issue, moving to next"]
|
|
33
|
+
</example>
|
|
34
|
+
|
|
35
|
+
<example>
|
|
36
|
+
After exploring the codebase to understand it:
|
|
37
|
+
Assistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation.
|
|
38
|
+
[Uses context_pruning with reason: "exploration complete, starting implementation"]
|
|
39
|
+
</example>
|
|
40
|
+
|
|
41
|
+
<example>
|
|
42
|
+
After completing any task:
|
|
43
|
+
Assistant: [Finishes task - commit, answer, fix, etc.]
|
|
44
|
+
Before we continue, let me prune the context from that work.
|
|
45
|
+
[Uses context_pruning with reason: "task complete"]
|
|
46
|
+
</example>`;
|
|
47
|
+
/**
|
|
48
|
+
* Creates the context_pruning tool definition.
|
|
49
|
+
* Returns a tool definition that can be passed to the plugin's tool registry.
|
|
50
|
+
*/
|
|
51
|
+
export function createPruningTool(janitor, config) {
|
|
52
|
+
return tool({
|
|
53
|
+
description: CONTEXT_PRUNING_DESCRIPTION,
|
|
54
|
+
args: {
|
|
55
|
+
reason: tool.schema.string().optional().describe("Brief reason for triggering pruning (e.g., 'task complete', 'switching focus')"),
|
|
56
|
+
},
|
|
57
|
+
async execute(args, ctx) {
|
|
58
|
+
const result = await janitor.runForTool(ctx.sessionID, config.strategies.onTool, args.reason);
|
|
59
|
+
if (!result || result.prunedCount === 0) {
|
|
60
|
+
return "No prunable tool outputs found. Context is already optimized.\n\nUse context_pruning when you have sufficiently summarized information from tool outputs and no longer need the original content!";
|
|
61
|
+
}
|
|
62
|
+
return janitor.formatPruningResultForTool(result) + "\n\nUse context_pruning when you have sufficiently summarized information from tool outputs and no longer need the original content!";
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=pruning-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pruning-tool.js","sourceRoot":"","sources":["../../lib/pruning-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAI1C,oDAAoD;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA2ChC,CAAA;AAEX;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,MAAoB;IACpE,OAAO,IAAI,CAAC;QACR,WAAW,EAAE,2BAA2B;QACxC,IAAI,EAAE;YACF,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAC5C,gFAAgF,CACnF;SACJ;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG;YACnB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CACnC,GAAG,CAAC,SAAS,EACb,MAAM,CAAC,UAAU,CAAC,MAAM,EACxB,IAAI,CAAC,MAAM,CACd,CAAA;YAED,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,KAAK,CAAC,EAAE,CAAC;gBACtC,OAAO,mMAAmM,CAAA;YAC9M,CAAC;YAED,OAAO,OAAO,CAAC,0BAA0B,CAAC,MAAM,CAAC,GAAG,sIAAsI,CAAA;QAC9L,CAAC;KACJ,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SessionStats } from "./janitor";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized state management for the DCP plugin.
|
|
4
|
+
* All mutable state is stored here and shared across modules.
|
|
5
|
+
*/
|
|
6
|
+
export interface PluginState {
|
|
7
|
+
/** Map of session IDs to arrays of pruned tool call IDs */
|
|
8
|
+
prunedIds: Map<string, string[]>;
|
|
9
|
+
/** Map of session IDs to session statistics */
|
|
10
|
+
stats: Map<string, SessionStats>;
|
|
11
|
+
/** Cache of tool call IDs to their parameters */
|
|
12
|
+
toolParameters: Map<string, ToolParameterEntry>;
|
|
13
|
+
/** Cache of session IDs to their model info */
|
|
14
|
+
model: Map<string, ModelInfo>;
|
|
15
|
+
/**
|
|
16
|
+
* Maps Google/Gemini tool positions to OpenCode tool call IDs for correlation.
|
|
17
|
+
* Key: sessionID, Value: Map<positionKey, toolCallId> where positionKey is "toolName:index"
|
|
18
|
+
*/
|
|
19
|
+
googleToolCallMapping: Map<string, Map<string, string>>;
|
|
20
|
+
}
|
|
21
|
+
export interface ToolParameterEntry {
|
|
22
|
+
tool: string;
|
|
23
|
+
parameters: any;
|
|
24
|
+
}
|
|
25
|
+
export interface ModelInfo {
|
|
26
|
+
providerID: string;
|
|
27
|
+
modelID: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a fresh plugin state instance.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createPluginState(): PluginState;
|
|
33
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../lib/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAE7C;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,2DAA2D;IAC3D,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAChC,+CAA+C;IAC/C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAChC,iDAAiD;IACjD,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IAC/C,+CAA+C;IAC/C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC7B;;;OAGG;IACH,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAC1D;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,GAAG,CAAA;CAClB;AAED,MAAM,WAAW,SAAS;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAQ/C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a fresh plugin state instance.
|
|
3
|
+
*/
|
|
4
|
+
export function createPluginState() {
|
|
5
|
+
return {
|
|
6
|
+
prunedIds: new Map(),
|
|
7
|
+
stats: new Map(),
|
|
8
|
+
toolParameters: new Map(),
|
|
9
|
+
model: new Map(),
|
|
10
|
+
googleToolCallMapping: new Map(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../lib/state.ts"],"names":[],"mappings":"AAgCA;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC7B,OAAO;QACH,SAAS,EAAE,IAAI,GAAG,EAAE;QACpB,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,cAAc,EAAE,IAAI,GAAG,EAAE;QACzB,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,qBAAqB,EAAE,IAAI,GAAG,EAAE;KACnC,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PluginState } from "./state";
|
|
2
|
+
/**
|
|
3
|
+
* Cache tool parameters from OpenAI Chat Completions style messages.
|
|
4
|
+
* Extracts tool call IDs and their parameters from assistant messages with tool_calls.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cacheToolParametersFromMessages(messages: any[], state: PluginState): void;
|
|
7
|
+
/**
|
|
8
|
+
* Cache tool parameters from OpenAI Responses API format.
|
|
9
|
+
* Extracts from input array items with type='function_call'.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cacheToolParametersFromInput(input: any[], state: PluginState): void;
|
|
12
|
+
//# sourceMappingURL=tool-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cache.d.ts","sourceRoot":"","sources":["../../lib/tool-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;GAGG;AACH,wBAAgB,+BAA+B,CAC3C,QAAQ,EAAE,GAAG,EAAE,EACf,KAAK,EAAE,WAAW,GACnB,IAAI,CAwBN;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CACxC,KAAK,EAAE,GAAG,EAAE,EACZ,KAAK,EAAE,WAAW,GACnB,IAAI,CAkBN"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache tool parameters from OpenAI Chat Completions style messages.
|
|
3
|
+
* Extracts tool call IDs and their parameters from assistant messages with tool_calls.
|
|
4
|
+
*/
|
|
5
|
+
export function cacheToolParametersFromMessages(messages, state) {
|
|
6
|
+
for (const message of messages) {
|
|
7
|
+
if (message.role !== 'assistant' || !Array.isArray(message.tool_calls)) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
for (const toolCall of message.tool_calls) {
|
|
11
|
+
if (!toolCall.id || !toolCall.function) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const params = typeof toolCall.function.arguments === 'string'
|
|
16
|
+
? JSON.parse(toolCall.function.arguments)
|
|
17
|
+
: toolCall.function.arguments;
|
|
18
|
+
state.toolParameters.set(toolCall.id, {
|
|
19
|
+
tool: toolCall.function.name,
|
|
20
|
+
parameters: params
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
// Silently ignore parse errors
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Cache tool parameters from OpenAI Responses API format.
|
|
31
|
+
* Extracts from input array items with type='function_call'.
|
|
32
|
+
*/
|
|
33
|
+
export function cacheToolParametersFromInput(input, state) {
|
|
34
|
+
for (const item of input) {
|
|
35
|
+
if (item.type !== 'function_call' || !item.call_id || !item.name) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const params = typeof item.arguments === 'string'
|
|
40
|
+
? JSON.parse(item.arguments)
|
|
41
|
+
: item.arguments;
|
|
42
|
+
state.toolParameters.set(item.call_id, {
|
|
43
|
+
tool: item.name,
|
|
44
|
+
parameters: params
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// Silently ignore parse errors
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=tool-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cache.js","sourceRoot":"","sources":["../../lib/tool-cache.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAC3C,QAAe,EACf,KAAkB;IAElB,KAAK,MAAM,OAAO,IAAI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5B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;YACpB,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE;gBACnC,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,UAAU,EAAE,MAAM;aACrB,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,+BAA+B;QACnC,CAAC;IACL,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@tarquinen/opencode-dcp",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.21",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
|
|
7
7
|
"main": "./dist/index.js",
|