@contractspec/lib.ai-agent 1.57.0 → 1.59.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/agent/agent-factory.d.ts +67 -71
- package/dist/agent/agent-factory.d.ts.map +1 -1
- package/dist/agent/agent-factory.js +658 -100
- package/dist/agent/agent.test.d.ts +2 -0
- package/dist/agent/agent.test.d.ts.map +1 -0
- package/dist/agent/contract-spec-agent.d.ts +48 -52
- package/dist/agent/contract-spec-agent.d.ts.map +1 -1
- package/dist/agent/contract-spec-agent.js +605 -146
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2102 -4
- package/dist/agent/json-runner.d.ts +15 -19
- package/dist/agent/json-runner.d.ts.map +1 -1
- package/dist/agent/json-runner.js +672 -57
- package/dist/agent/json-runner.test.d.ts +2 -0
- package/dist/agent/json-runner.test.d.ts.map +1 -0
- package/dist/agent/unified-agent.d.ts +132 -109
- package/dist/agent/unified-agent.d.ts.map +1 -1
- package/dist/agent/unified-agent.js +2011 -293
- package/dist/approval/index.d.ts +3 -2
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +128 -2
- package/dist/approval/workflow.d.ts +106 -110
- package/dist/approval/workflow.d.ts.map +1 -1
- package/dist/approval/workflow.js +126 -157
- package/dist/exporters/claude-agent-exporter.d.ts +50 -48
- package/dist/exporters/claude-agent-exporter.d.ts.map +1 -1
- package/dist/exporters/claude-agent-exporter.js +258 -203
- package/dist/exporters/index.d.ts +28 -4
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +737 -3
- package/dist/exporters/opencode-exporter.d.ts +47 -45
- package/dist/exporters/opencode-exporter.d.ts.map +1 -1
- package/dist/exporters/opencode-exporter.js +507 -191
- package/dist/exporters/types.d.ts +171 -169
- package/dist/exporters/types.d.ts.map +1 -1
- package/dist/exporters/types.js +1 -0
- package/dist/index.d.ts +15 -39
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3337 -32
- package/dist/interop/index.d.ts +48 -4
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +709 -3
- package/dist/interop/spec-consumer.d.ts +57 -53
- package/dist/interop/spec-consumer.d.ts.map +1 -1
- package/dist/interop/spec-consumer.js +302 -282
- package/dist/interop/tool-consumer.d.ts +57 -53
- package/dist/interop/tool-consumer.d.ts.map +1 -1
- package/dist/interop/tool-consumer.js +412 -213
- package/dist/interop/types.d.ts +173 -171
- package/dist/interop/types.d.ts.map +1 -1
- package/dist/interop/types.js +1 -0
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +66 -2
- package/dist/knowledge/injector.d.ts +16 -20
- package/dist/knowledge/injector.d.ts.map +1 -1
- package/dist/knowledge/injector.js +56 -47
- package/dist/memory/in-memory.d.ts +15 -19
- package/dist/memory/in-memory.d.ts.map +1 -1
- package/dist/memory/in-memory.js +152 -46
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +155 -3
- package/dist/memory/manager.d.ts +32 -36
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/manager.js +96 -70
- package/dist/memory/memory.test.d.ts +2 -0
- package/dist/memory/memory.test.d.ts.map +1 -0
- package/dist/node/agent/agent-factory.js +661 -0
- package/dist/node/agent/contract-spec-agent.js +607 -0
- package/dist/node/agent/index.js +2103 -0
- package/dist/node/agent/json-runner.js +684 -0
- package/dist/node/agent/unified-agent.js +2019 -0
- package/dist/node/approval/index.js +129 -0
- package/dist/node/approval/workflow.js +129 -0
- package/dist/node/exporters/claude-agent-exporter.js +265 -0
- package/dist/node/exporters/index.js +738 -0
- package/dist/node/exporters/opencode-exporter.js +516 -0
- package/dist/node/exporters/types.js +0 -0
- package/dist/node/index.js +3337 -0
- package/dist/node/interop/index.js +710 -0
- package/dist/node/interop/spec-consumer.js +307 -0
- package/dist/node/interop/tool-consumer.js +419 -0
- package/dist/node/interop/types.js +0 -0
- package/dist/node/knowledge/index.js +67 -0
- package/dist/node/knowledge/injector.js +67 -0
- package/dist/node/memory/in-memory.js +154 -0
- package/dist/node/memory/index.js +156 -0
- package/dist/node/memory/manager.js +105 -0
- package/dist/node/providers/claude-agent-sdk/adapter.js +624 -0
- package/dist/node/providers/claude-agent-sdk/index.js +673 -0
- package/dist/node/providers/claude-agent-sdk/session-bridge.js +149 -0
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +118 -0
- package/dist/node/providers/index.js +1261 -0
- package/dist/node/providers/opencode-sdk/adapter.js +669 -0
- package/dist/node/providers/opencode-sdk/agent-bridge.js +299 -0
- package/dist/node/providers/opencode-sdk/index.js +703 -0
- package/dist/node/providers/opencode-sdk/tool-bridge.js +141 -0
- package/dist/node/providers/registry.js +89 -0
- package/dist/node/providers/types.js +56 -0
- package/dist/node/schema/index.js +195 -0
- package/dist/node/schema/json-schema-to-zod.js +152 -0
- package/dist/node/schema/schema-output.js +190 -0
- package/dist/node/session/index.js +90 -0
- package/dist/node/session/store.js +90 -0
- package/dist/node/spec/index.js +85 -0
- package/dist/node/spec/registry.js +56 -0
- package/dist/node/spec/spec.js +44 -0
- package/dist/node/telemetry/adapter.js +85 -0
- package/dist/node/telemetry/index.js +86 -0
- package/dist/node/tools/index.js +345 -0
- package/dist/node/tools/knowledge-tool.js +74 -0
- package/dist/node/tools/mcp-client.js +47 -0
- package/dist/node/tools/mcp-server.js +205 -0
- package/dist/node/tools/tool-adapter.js +197 -0
- package/dist/node/types.js +0 -0
- package/dist/providers/claude-agent-sdk/adapter.d.ts +60 -52
- package/dist/providers/claude-agent-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +622 -304
- package/dist/providers/claude-agent-sdk/index.d.ts +22 -4
- package/dist/providers/claude-agent-sdk/index.d.ts.map +1 -0
- package/dist/providers/claude-agent-sdk/index.js +672 -4
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts +43 -40
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js +121 -130
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +63 -60
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js +104 -108
- package/dist/providers/index.d.ts +28 -7
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +1261 -8
- package/dist/providers/opencode-sdk/adapter.d.ts +56 -48
- package/dist/providers/opencode-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/adapter.js +667 -274
- package/dist/providers/opencode-sdk/agent-bridge.d.ts +62 -57
- package/dist/providers/opencode-sdk/agent-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/agent-bridge.js +289 -155
- package/dist/providers/opencode-sdk/index.d.ts +22 -4
- package/dist/providers/opencode-sdk/index.d.ts.map +1 -0
- package/dist/providers/opencode-sdk/index.js +702 -4
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +41 -42
- package/dist/providers/opencode-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/tool-bridge.js +121 -107
- package/dist/providers/registry.d.ts +10 -11
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +86 -49
- package/dist/providers/types.d.ts +169 -166
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +54 -42
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +194 -3
- package/dist/schema/json-schema-to-zod.d.ts +23 -26
- package/dist/schema/json-schema-to-zod.d.ts.map +1 -1
- package/dist/schema/json-schema-to-zod.js +138 -110
- package/dist/schema/schema-output.d.ts +29 -32
- package/dist/schema/schema-output.d.ts.map +1 -1
- package/dist/schema/schema-output.js +178 -53
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +89 -2
- package/dist/session/store.d.ts +51 -55
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +85 -74
- package/dist/spec/index.d.ts +3 -3
- package/dist/spec/index.d.ts.map +1 -0
- package/dist/spec/index.js +84 -3
- package/dist/spec/registry.d.ts +32 -36
- package/dist/spec/registry.d.ts.map +1 -1
- package/dist/spec/registry.js +51 -60
- package/dist/spec/spec.d.ts +80 -84
- package/dist/spec/spec.d.ts.map +1 -1
- package/dist/spec/spec.js +40 -26
- package/dist/telemetry/adapter.d.ts +33 -37
- package/dist/telemetry/adapter.d.ts.map +1 -1
- package/dist/telemetry/adapter.js +78 -96
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +85 -2
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +344 -5
- package/dist/tools/knowledge-tool.d.ts +4 -8
- package/dist/tools/knowledge-tool.d.ts.map +1 -1
- package/dist/tools/knowledge-tool.js +68 -48
- package/dist/tools/mcp-client.d.ts +17 -21
- package/dist/tools/mcp-client.d.ts.map +1 -1
- package/dist/tools/mcp-client.js +42 -53
- package/dist/tools/mcp-server.d.ts +14 -18
- package/dist/tools/mcp-server.d.ts.map +1 -1
- package/dist/tools/mcp-server.js +200 -64
- package/dist/tools/tool-adapter.d.ts +7 -11
- package/dist/tools/tool-adapter.d.ts.map +1 -1
- package/dist/tools/tool-adapter.js +187 -70
- package/dist/tools/tools.test.d.ts +2 -0
- package/dist/tools/tools.test.d.ts.map +1 -0
- package/dist/types.d.ts +108 -111
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +448 -90
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/agent/agent-factory.js.map +0 -1
- package/dist/agent/contract-spec-agent.js.map +0 -1
- package/dist/agent/json-runner.js.map +0 -1
- package/dist/agent/unified-agent.js.map +0 -1
- package/dist/approval/workflow.js.map +0 -1
- package/dist/exporters/claude-agent-exporter.js.map +0 -1
- package/dist/exporters/opencode-exporter.js.map +0 -1
- package/dist/interop/spec-consumer.js.map +0 -1
- package/dist/interop/tool-consumer.js.map +0 -1
- package/dist/knowledge/injector.js.map +0 -1
- package/dist/memory/in-memory.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/providers/claude-agent-sdk/adapter.js.map +0 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js.map +0 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/adapter.js.map +0 -1
- package/dist/providers/opencode-sdk/agent-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/registry.js.map +0 -1
- package/dist/providers/types.js.map +0 -1
- package/dist/schema/json-schema-to-zod.js.map +0 -1
- package/dist/schema/schema-output.js.map +0 -1
- package/dist/session/store.js.map +0 -1
- package/dist/spec/registry.js.map +0 -1
- package/dist/spec/spec.js.map +0 -1
- package/dist/telemetry/adapter.js.map +0 -1
- package/dist/tools/knowledge-tool.js.map +0 -1
- package/dist/tools/mcp-client.js.map +0 -1
- package/dist/tools/mcp-server.js.map +0 -1
- package/dist/tools/tool-adapter.js.map +0 -1
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Agent bridge for mapping between ContractSpec AgentSpec and OpenCode agent configuration.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode has four built-in agent types:
|
|
5
|
+
* - build: Primary agent with all tools enabled (default for code generation)
|
|
6
|
+
* - plan: Restricted agent for analysis/planning (file edits and bash in "ask" mode)
|
|
7
|
+
* - general: Subagent for complex questions and multi-step tasks
|
|
8
|
+
* - explore: Fast subagent for codebase exploration
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentSpec } from '../../spec/spec';
|
|
11
|
+
import type { OpenCodeAgentType } from '../types';
|
|
12
|
+
import { type OpenCodeTool } from './tool-bridge';
|
|
6
13
|
/**
|
|
7
14
|
* OpenCode agent configuration in JSON format.
|
|
8
15
|
*/
|
|
9
|
-
interface OpenCodeAgentJSON {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
export interface OpenCodeAgentJSON {
|
|
17
|
+
/** Agent name */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Agent version */
|
|
20
|
+
version?: string;
|
|
21
|
+
/** Agent description */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** System instructions */
|
|
24
|
+
instructions?: string;
|
|
25
|
+
/** Agent type */
|
|
26
|
+
agent_type: OpenCodeAgentType;
|
|
27
|
+
/** Available tools */
|
|
28
|
+
tools?: OpenCodeTool[];
|
|
29
|
+
/** Configuration options */
|
|
30
|
+
config?: OpenCodeAgentConfig;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* OpenCode agent configuration options.
|
|
27
34
|
*/
|
|
28
|
-
interface OpenCodeAgentConfig {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
export interface OpenCodeAgentConfig {
|
|
36
|
+
/** Maximum agentic iterations */
|
|
37
|
+
max_steps?: number;
|
|
38
|
+
/** Temperature for generation */
|
|
39
|
+
temperature?: number;
|
|
40
|
+
/** Model to use */
|
|
41
|
+
model?: string;
|
|
42
|
+
/** Tool permissions */
|
|
43
|
+
permissions?: Record<string, 'allow' | 'ask' | 'deny'>;
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* OpenCode agent markdown format (for .opencode/agent/*.md files).
|
|
40
47
|
*/
|
|
41
|
-
interface OpenCodeAgentMarkdown {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
export interface OpenCodeAgentMarkdown {
|
|
49
|
+
/** Frontmatter */
|
|
50
|
+
frontmatter: {
|
|
51
|
+
name: string;
|
|
52
|
+
type: OpenCodeAgentType;
|
|
53
|
+
version?: string;
|
|
54
|
+
model?: string;
|
|
55
|
+
temperature?: number;
|
|
56
|
+
max_steps?: number;
|
|
57
|
+
tools?: string[];
|
|
58
|
+
};
|
|
59
|
+
/** Body content */
|
|
60
|
+
body: string;
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
63
|
* Infer the appropriate OpenCode agent type from an AgentSpec.
|
|
@@ -60,34 +67,32 @@ interface OpenCodeAgentMarkdown {
|
|
|
60
67
|
* - Instructions content (planning keywords → plan)
|
|
61
68
|
* - Exploration keywords (search, find → explore)
|
|
62
69
|
*/
|
|
63
|
-
declare function inferAgentType(spec: AgentSpec): OpenCodeAgentType;
|
|
70
|
+
export declare function inferAgentType(spec: AgentSpec): OpenCodeAgentType;
|
|
64
71
|
/**
|
|
65
72
|
* Convert an AgentSpec to OpenCode agent JSON configuration.
|
|
66
73
|
*/
|
|
67
|
-
declare function specToOpenCodeConfig(spec: AgentSpec, options?: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
export declare function specToOpenCodeConfig(spec: AgentSpec, options?: {
|
|
75
|
+
agentType?: OpenCodeAgentType;
|
|
76
|
+
model?: string;
|
|
77
|
+
temperature?: number;
|
|
78
|
+
maxSteps?: number;
|
|
72
79
|
}): OpenCodeAgentJSON;
|
|
73
80
|
/**
|
|
74
81
|
* Convert an AgentSpec to OpenCode agent markdown format.
|
|
75
82
|
*/
|
|
76
|
-
declare function specToOpenCodeMarkdown(spec: AgentSpec, options?: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
export declare function specToOpenCodeMarkdown(spec: AgentSpec, options?: {
|
|
84
|
+
agentType?: OpenCodeAgentType;
|
|
85
|
+
model?: string;
|
|
86
|
+
temperature?: number;
|
|
87
|
+
maxSteps?: number;
|
|
81
88
|
}): OpenCodeAgentMarkdown;
|
|
82
89
|
/**
|
|
83
90
|
* Serialize OpenCode agent markdown to string.
|
|
84
91
|
*/
|
|
85
|
-
declare function serializeOpenCodeMarkdown(markdown: OpenCodeAgentMarkdown): string;
|
|
92
|
+
export declare function serializeOpenCodeMarkdown(markdown: OpenCodeAgentMarkdown): string;
|
|
86
93
|
/**
|
|
87
94
|
* Convert OpenCode agent configuration to partial AgentSpec.
|
|
88
95
|
* Note: This is a partial conversion as OpenCode config may not have all spec fields.
|
|
89
96
|
*/
|
|
90
|
-
declare function openCodeConfigToSpec(config: OpenCodeAgentJSON): Partial<AgentSpec>;
|
|
91
|
-
//#endregion
|
|
92
|
-
export { OpenCodeAgentConfig, OpenCodeAgentJSON, OpenCodeAgentMarkdown, inferAgentType, openCodeConfigToSpec, serializeOpenCodeMarkdown, specToOpenCodeConfig, specToOpenCodeMarkdown };
|
|
97
|
+
export declare function openCodeConfigToSpec(config: OpenCodeAgentJSON): Partial<AgentSpec>;
|
|
93
98
|
//# sourceMappingURL=agent-bridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-bridge.d.ts","
|
|
1
|
+
{"version":3,"file":"agent-bridge.d.ts","sourceRoot":"","sources":["../../../src/providers/opencode-sdk/agent-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAM5E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB;IACjB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,sBAAsB;IACtB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC,CAAC;CACxD;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,kBAAkB;IAClB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,iBAAiB,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,CAiDjE;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,iBAAiB,CAiBnB;AAuBD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,qBAAqB,CAevB;AAuDD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,qBAAqB,GAC9B,MAAM,CAoCR;AAMD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,SAAS,CAAC,CAuBpB"}
|
|
@@ -1,165 +1,299 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
var __require = import.meta.require;
|
|
2
14
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
// src/providers/opencode-sdk/tool-bridge.ts
|
|
16
|
+
function specToolToOpenCodeTool(tool) {
|
|
17
|
+
return {
|
|
18
|
+
name: tool.name,
|
|
19
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
20
|
+
parameters: normalizeToOpenCodeParameters(tool.schema),
|
|
21
|
+
permission: getPermissionLevel(tool)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function specToolsToOpenCodeTools(tools) {
|
|
25
|
+
return tools.map(specToolToOpenCodeTool);
|
|
26
|
+
}
|
|
27
|
+
function getPermissionLevel(tool) {
|
|
28
|
+
if (tool.requiresApproval) {
|
|
29
|
+
return "ask";
|
|
30
|
+
}
|
|
31
|
+
if (tool.automationSafe === false) {
|
|
32
|
+
return "ask";
|
|
33
|
+
}
|
|
34
|
+
return "allow";
|
|
35
|
+
}
|
|
36
|
+
function openCodeToolToSpecTool(openCodeTool) {
|
|
37
|
+
return {
|
|
38
|
+
name: openCodeTool.name,
|
|
39
|
+
description: openCodeTool.description,
|
|
40
|
+
schema: openCodeTool.parameters,
|
|
41
|
+
requiresApproval: openCodeTool.permission === "ask",
|
|
42
|
+
automationSafe: openCodeTool.permission === "allow"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function openCodeToolsToSpecTools(openCodeTools) {
|
|
46
|
+
return openCodeTools.map(openCodeToolToSpecTool);
|
|
47
|
+
}
|
|
48
|
+
function specToolToExternalToolForOpenCode(tool, handler, context) {
|
|
49
|
+
return {
|
|
50
|
+
name: tool.name,
|
|
51
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
52
|
+
inputSchema: tool.schema ?? { type: "object" },
|
|
53
|
+
requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
|
|
54
|
+
execute: handler ? async (input) => {
|
|
55
|
+
const fullContext = {
|
|
56
|
+
agentId: context?.agentId ?? "unknown",
|
|
57
|
+
sessionId: context?.sessionId ?? "unknown",
|
|
58
|
+
tenantId: context?.tenantId,
|
|
59
|
+
actorId: context?.actorId,
|
|
60
|
+
metadata: context?.metadata,
|
|
61
|
+
signal: context?.signal
|
|
62
|
+
};
|
|
63
|
+
return handler(input, fullContext);
|
|
64
|
+
} : undefined
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function normalizeToOpenCodeParameters(schema) {
|
|
68
|
+
if (!schema) {
|
|
69
|
+
return { type: "object" };
|
|
70
|
+
}
|
|
71
|
+
if (schema.type === "object") {
|
|
72
|
+
return {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: schema.properties,
|
|
75
|
+
required: schema.required
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
type: "object",
|
|
80
|
+
properties: {
|
|
81
|
+
value: convertToOpenCodeParameter(schema)
|
|
82
|
+
},
|
|
83
|
+
required: ["value"]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function convertToOpenCodeParameter(schema) {
|
|
87
|
+
const param = {
|
|
88
|
+
type: schema.type ?? "string"
|
|
89
|
+
};
|
|
90
|
+
if (schema.description) {
|
|
91
|
+
param.description = schema.description;
|
|
92
|
+
}
|
|
93
|
+
if (schema.enum) {
|
|
94
|
+
param.enum = schema.enum;
|
|
95
|
+
}
|
|
96
|
+
if (schema.default !== undefined) {
|
|
97
|
+
param.default = schema.default;
|
|
98
|
+
}
|
|
99
|
+
return param;
|
|
100
|
+
}
|
|
101
|
+
function createToolHandlerMap(tools) {
|
|
102
|
+
const handlers = new Map;
|
|
103
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
104
|
+
if (tool.execute) {
|
|
105
|
+
handlers.set(name, tool.execute);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return handlers;
|
|
109
|
+
}
|
|
110
|
+
async function executeToolCall(toolCall, handlers) {
|
|
111
|
+
const handler = handlers.get(toolCall.name);
|
|
112
|
+
if (!handler) {
|
|
113
|
+
return {
|
|
114
|
+
tool_call_id: toolCall.id,
|
|
115
|
+
output: `Error: Tool '${toolCall.name}' not found`,
|
|
116
|
+
is_error: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const result = await handler(toolCall.arguments);
|
|
121
|
+
return {
|
|
122
|
+
tool_call_id: toolCall.id,
|
|
123
|
+
output: typeof result === "string" ? result : JSON.stringify(result)
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return {
|
|
127
|
+
tool_call_id: toolCall.id,
|
|
128
|
+
output: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
129
|
+
is_error: true
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/providers/opencode-sdk/agent-bridge.ts
|
|
12
135
|
function inferAgentType(spec) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
136
|
+
const hasCodeTools = spec.tools.some((tool) => [
|
|
137
|
+
"write_file",
|
|
138
|
+
"edit_file",
|
|
139
|
+
"create_file",
|
|
140
|
+
"delete_file",
|
|
141
|
+
"bash",
|
|
142
|
+
"execute",
|
|
143
|
+
"run_command",
|
|
144
|
+
"terminal"
|
|
145
|
+
].includes(tool.name.toLowerCase()));
|
|
146
|
+
const instructionsLower = spec.instructions.toLowerCase();
|
|
147
|
+
const hasPlanningKeywords = /\b(plan|design|architect|strategy|analyze|review|assess|evaluate)\b/.test(instructionsLower);
|
|
148
|
+
const hasExplorationKeywords = /\b(search|find|explore|discover|locate|grep|pattern)\b/.test(instructionsLower);
|
|
149
|
+
const hasResearchKeywords = /\b(research|investigate|understand|learn|gather|collect)\b/.test(instructionsLower);
|
|
150
|
+
if (hasCodeTools) {
|
|
151
|
+
return "build";
|
|
152
|
+
}
|
|
153
|
+
if (hasPlanningKeywords && !hasCodeTools) {
|
|
154
|
+
return "plan";
|
|
155
|
+
}
|
|
156
|
+
if (hasExplorationKeywords && !hasResearchKeywords) {
|
|
157
|
+
return "explore";
|
|
158
|
+
}
|
|
159
|
+
return "general";
|
|
160
|
+
}
|
|
35
161
|
function specToOpenCodeConfig(spec, options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Build tool permissions from spec.
|
|
54
|
-
*/
|
|
162
|
+
const agentType = options?.agentType ?? inferAgentType(spec);
|
|
163
|
+
return {
|
|
164
|
+
name: spec.meta.key,
|
|
165
|
+
version: spec.meta.version,
|
|
166
|
+
description: spec.description ?? spec.meta.description,
|
|
167
|
+
instructions: spec.instructions,
|
|
168
|
+
agent_type: agentType,
|
|
169
|
+
tools: specToolsToOpenCodeTools(spec.tools),
|
|
170
|
+
config: {
|
|
171
|
+
max_steps: options?.maxSteps ?? spec.maxSteps ?? 10,
|
|
172
|
+
temperature: options?.temperature ?? 0.7,
|
|
173
|
+
model: options?.model,
|
|
174
|
+
permissions: buildPermissions(spec)
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
55
178
|
function buildPermissions(spec) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
179
|
+
const permissions = {};
|
|
180
|
+
for (const tool of spec.tools) {
|
|
181
|
+
if (tool.requiresApproval) {
|
|
182
|
+
permissions[tool.name] = "ask";
|
|
183
|
+
} else if (tool.automationSafe === false) {
|
|
184
|
+
permissions[tool.name] = "ask";
|
|
185
|
+
} else {
|
|
186
|
+
permissions[tool.name] = "allow";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return permissions;
|
|
190
|
+
}
|
|
65
191
|
function specToOpenCodeMarkdown(spec, options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Build markdown body content from spec.
|
|
82
|
-
*/
|
|
192
|
+
const agentType = options?.agentType ?? inferAgentType(spec);
|
|
193
|
+
return {
|
|
194
|
+
frontmatter: {
|
|
195
|
+
name: spec.meta.key,
|
|
196
|
+
type: agentType,
|
|
197
|
+
version: spec.meta.version,
|
|
198
|
+
model: options?.model,
|
|
199
|
+
temperature: options?.temperature ?? 0.7,
|
|
200
|
+
max_steps: options?.maxSteps ?? spec.maxSteps ?? 10,
|
|
201
|
+
tools: spec.tools.map((t) => t.name)
|
|
202
|
+
},
|
|
203
|
+
body: buildMarkdownBody(spec)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
83
206
|
function buildMarkdownBody(spec) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* Serialize OpenCode agent markdown to string.
|
|
117
|
-
*/
|
|
207
|
+
const lines = [];
|
|
208
|
+
lines.push(`# ${spec.meta.key}`);
|
|
209
|
+
lines.push("");
|
|
210
|
+
if (spec.description ?? spec.meta.description) {
|
|
211
|
+
lines.push(spec.description ?? spec.meta.description ?? "");
|
|
212
|
+
lines.push("");
|
|
213
|
+
}
|
|
214
|
+
lines.push("## Instructions");
|
|
215
|
+
lines.push("");
|
|
216
|
+
lines.push(spec.instructions);
|
|
217
|
+
lines.push("");
|
|
218
|
+
if (spec.tools.length > 0) {
|
|
219
|
+
lines.push("## Tools");
|
|
220
|
+
lines.push("");
|
|
221
|
+
for (const tool of spec.tools) {
|
|
222
|
+
const permission = tool.requiresApproval ? "(requires approval)" : tool.automationSafe === false ? "(ask mode)" : "";
|
|
223
|
+
lines.push(`- **${tool.name}**: ${tool.description ?? "No description"} ${permission}`.trim());
|
|
224
|
+
}
|
|
225
|
+
lines.push("");
|
|
226
|
+
}
|
|
227
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
228
|
+
lines.push("## Knowledge Sources");
|
|
229
|
+
lines.push("");
|
|
230
|
+
for (const k of spec.knowledge) {
|
|
231
|
+
const required = k.required ? "(required)" : "(optional)";
|
|
232
|
+
lines.push(`- ${k.key} ${required}`);
|
|
233
|
+
}
|
|
234
|
+
lines.push("");
|
|
235
|
+
}
|
|
236
|
+
return lines.join(`
|
|
237
|
+
`);
|
|
238
|
+
}
|
|
118
239
|
function serializeOpenCodeMarkdown(markdown) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
240
|
+
const lines = [];
|
|
241
|
+
lines.push("---");
|
|
242
|
+
lines.push(`name: ${markdown.frontmatter.name}`);
|
|
243
|
+
lines.push(`type: ${markdown.frontmatter.type}`);
|
|
244
|
+
if (markdown.frontmatter.version) {
|
|
245
|
+
lines.push(`version: ${markdown.frontmatter.version}`);
|
|
246
|
+
}
|
|
247
|
+
if (markdown.frontmatter.model) {
|
|
248
|
+
lines.push(`model: ${markdown.frontmatter.model}`);
|
|
249
|
+
}
|
|
250
|
+
if (markdown.frontmatter.temperature !== undefined) {
|
|
251
|
+
lines.push(`temperature: ${markdown.frontmatter.temperature}`);
|
|
252
|
+
}
|
|
253
|
+
if (markdown.frontmatter.max_steps !== undefined) {
|
|
254
|
+
lines.push(`max_steps: ${markdown.frontmatter.max_steps}`);
|
|
255
|
+
}
|
|
256
|
+
if (markdown.frontmatter.tools && markdown.frontmatter.tools.length > 0) {
|
|
257
|
+
lines.push(`tools:`);
|
|
258
|
+
for (const tool of markdown.frontmatter.tools) {
|
|
259
|
+
lines.push(` - ${tool}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
lines.push("---");
|
|
263
|
+
lines.push("");
|
|
264
|
+
lines.push(markdown.body);
|
|
265
|
+
return lines.join(`
|
|
266
|
+
`);
|
|
267
|
+
}
|
|
140
268
|
function openCodeConfigToSpec(config) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
269
|
+
return {
|
|
270
|
+
meta: {
|
|
271
|
+
key: config.name,
|
|
272
|
+
version: config.version ?? "1.0.0",
|
|
273
|
+
description: config.description ?? "",
|
|
274
|
+
stability: "experimental",
|
|
275
|
+
owners: [],
|
|
276
|
+
tags: []
|
|
277
|
+
},
|
|
278
|
+
description: config.description,
|
|
279
|
+
instructions: config.instructions ?? "",
|
|
280
|
+
tools: config.tools?.map((tool) => ({
|
|
281
|
+
name: tool.name,
|
|
282
|
+
description: tool.description,
|
|
283
|
+
schema: tool.parameters,
|
|
284
|
+
requiresApproval: tool.permission === "ask",
|
|
285
|
+
automationSafe: tool.permission === "allow"
|
|
286
|
+
})) ?? [],
|
|
287
|
+
maxSteps: config.config?.max_steps ?? 10
|
|
288
|
+
};
|
|
161
289
|
}
|
|
290
|
+
var init_agent_bridge = () => {};
|
|
291
|
+
init_agent_bridge();
|
|
162
292
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
293
|
+
export {
|
|
294
|
+
specToOpenCodeMarkdown,
|
|
295
|
+
specToOpenCodeConfig,
|
|
296
|
+
serializeOpenCodeMarkdown,
|
|
297
|
+
openCodeConfigToSpec,
|
|
298
|
+
inferAgentType
|
|
299
|
+
};
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode SDK provider for ContractSpec agents.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { OpenCodeSDKProvider } from '@contractspec/lib.ai-agent/providers/opencode-sdk';
|
|
7
|
+
*
|
|
8
|
+
* const provider = new OpenCodeSDKProvider({
|
|
9
|
+
* agentType: 'build',
|
|
10
|
+
* port: 4096,
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* if (provider.isAvailable()) {
|
|
14
|
+
* const context = await provider.createContext(agentSpec);
|
|
15
|
+
* const result = await provider.execute(context, { prompt: "..." });
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export { OpenCodeSDKProvider } from './adapter';
|
|
20
|
+
export * from './tool-bridge';
|
|
21
|
+
export * from './agent-bridge';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/opencode-sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|