@opencode-compat/host-promise-v2 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/README.md +40 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +264 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @opencode-compat/host-promise-v2
|
|
2
|
+
|
|
3
|
+
Shared Promise v2 aisdk host kit wired from the OCP layer.
|
|
4
|
+
|
|
5
|
+
Matches OpenCode `@opencode-ai/plugin/v2/promise` shape:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
createPromiseV2Host,
|
|
10
|
+
define,
|
|
11
|
+
} from "@opencode-compat/host-promise-v2"
|
|
12
|
+
|
|
13
|
+
const plugin = define({
|
|
14
|
+
id: "demo",
|
|
15
|
+
async setup(ctx) {
|
|
16
|
+
await ctx.aisdk.sdk(async (event) => {
|
|
17
|
+
// event.sdk = …
|
|
18
|
+
})
|
|
19
|
+
await ctx.aisdk.language(async (event) => {
|
|
20
|
+
// event.language = LanguageModelV3
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const host = createPromiseV2Host()
|
|
26
|
+
await host.register(plugin)
|
|
27
|
+
const { language, sdk } = await host.resolveProvider({
|
|
28
|
+
providerID: "demo",
|
|
29
|
+
modelID: "m1",
|
|
30
|
+
package: "demo-pkg",
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Adapter helper: `wirePromiseV2()` from `@opencode-compat/adapter` / `@opencode-compat/ocp`.
|
|
35
|
+
|
|
36
|
+
On MiMo/Kilo there is **no** native in-process aisdk emit yet — operators call `resolveProvider` from an external sidecar after Layer A setup. See [`docs/hosts/mimo.md`](../../docs/hosts/mimo.md) §3 (copy-paste smoke + success criteria).
|
|
37
|
+
|
|
38
|
+
**License:** MPL-2.0
|
|
39
|
+
|
|
40
|
+
See the monorepo [README](../../README.md) and [OCP 0.1](../../docs/ocp/0.1.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Promise v2 aisdk host kit — wired from the OCP layer
|
|
3
|
+
* (operator overrides / sidecar / host-kit helpers).
|
|
4
|
+
*
|
|
5
|
+
* API shape matches `@opencode-ai/plugin/v2/promise` (OpenCode 1.18.x):
|
|
6
|
+
* `await ctx.aisdk.sdk(cb)` / `await ctx.aisdk.language(cb)`.
|
|
7
|
+
*
|
|
8
|
+
* OCP 0.1 T3 bar: `ctx.aisdk` language (+ ideally sdk) hooks.
|
|
9
|
+
* Other domains loud-stub in the same ship.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PKG: "@opencode-compat/host-promise-v2";
|
|
12
|
+
export declare const VERSION: "0.1.0";
|
|
13
|
+
export type Registration = {
|
|
14
|
+
readonly dispose: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export type Reload = {
|
|
17
|
+
readonly reload: () => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/** Minimal LanguageModelV3-shaped stand-in for conformance (not a full AI SDK type). */
|
|
20
|
+
export type LanguageModelV3Like = {
|
|
21
|
+
specificationVersion: "v3";
|
|
22
|
+
provider: string;
|
|
23
|
+
modelId: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Minimal ModelV2Info stand-in (OpenCode sdk/v2). Full upstream type is large;
|
|
28
|
+
* plugins typically read `providerID`, `id`, and `api.id`.
|
|
29
|
+
*/
|
|
30
|
+
export type ModelV2InfoLike = {
|
|
31
|
+
id: string;
|
|
32
|
+
providerID: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
api: {
|
|
35
|
+
id: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
export type SdkEvent = {
|
|
41
|
+
readonly model: ModelV2InfoLike;
|
|
42
|
+
readonly package: string;
|
|
43
|
+
readonly options: Record<string, unknown>;
|
|
44
|
+
sdk?: unknown;
|
|
45
|
+
};
|
|
46
|
+
export type LanguageEvent = {
|
|
47
|
+
readonly model: ModelV2InfoLike;
|
|
48
|
+
readonly sdk: unknown;
|
|
49
|
+
readonly options: Record<string, unknown>;
|
|
50
|
+
language?: LanguageModelV3Like | unknown;
|
|
51
|
+
};
|
|
52
|
+
type HookCallback<E> = (event: E) => void | Promise<void>;
|
|
53
|
+
export type AisdkHooks = {
|
|
54
|
+
/** Register an aisdk `sdk` hook (OpenCode Promise v2 shape). */
|
|
55
|
+
sdk: (callback: HookCallback<SdkEvent>) => Promise<Registration>;
|
|
56
|
+
/** Register an aisdk `language` hook (OpenCode Promise v2 shape). */
|
|
57
|
+
language: (callback: HookCallback<LanguageEvent>) => Promise<Registration>;
|
|
58
|
+
/** Host diagnostics: number of listeners for a named hook. */
|
|
59
|
+
listenerCount(event: "sdk" | "language"): number;
|
|
60
|
+
/** Host diagnostics: events that currently have listeners. */
|
|
61
|
+
events(): Array<"sdk" | "language">;
|
|
62
|
+
};
|
|
63
|
+
export type Plugin = {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
readonly setup: (context: PluginContext) => Promise<void> | void;
|
|
66
|
+
};
|
|
67
|
+
/** @deprecated Prefer `Plugin` (OpenCode name). */
|
|
68
|
+
export type PromisePlugin = Plugin;
|
|
69
|
+
export type PluginDomain = {
|
|
70
|
+
readonly add: (plugin: Plugin) => Promise<void>;
|
|
71
|
+
readonly remove: (id: string) => Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
export type PluginContext = {
|
|
74
|
+
readonly options: Record<string, unknown>;
|
|
75
|
+
readonly aisdk: AisdkHooks;
|
|
76
|
+
readonly plugin: PluginDomain & {
|
|
77
|
+
id?: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
};
|
|
80
|
+
/** Loud stubs for T4 domains until wired */
|
|
81
|
+
readonly agent: LoudDomain & Reload;
|
|
82
|
+
readonly catalog: LoudDomain & Reload;
|
|
83
|
+
readonly command: LoudDomain & Reload;
|
|
84
|
+
readonly skill: LoudDomain & Reload;
|
|
85
|
+
readonly reference: LoudDomain & Reload;
|
|
86
|
+
readonly integration: LoudDomain & Reload;
|
|
87
|
+
};
|
|
88
|
+
type LoudDomain = {
|
|
89
|
+
[key: string]: (...args: unknown[]) => never;
|
|
90
|
+
};
|
|
91
|
+
export type LanguageModelInput = {
|
|
92
|
+
providerID: string;
|
|
93
|
+
modelID: string;
|
|
94
|
+
package?: string;
|
|
95
|
+
options?: Record<string, unknown>;
|
|
96
|
+
sdk?: unknown;
|
|
97
|
+
model?: Partial<ModelV2InfoLike>;
|
|
98
|
+
[key: string]: unknown;
|
|
99
|
+
};
|
|
100
|
+
export type PromiseV2Host = {
|
|
101
|
+
readonly ctx: PluginContext;
|
|
102
|
+
/** Register + run `setup` for a Promise v2 plugin. */
|
|
103
|
+
register(plugin: Plugin): Promise<Plugin>;
|
|
104
|
+
/** Remove a previously registered plugin by id. */
|
|
105
|
+
remove(id: string): Promise<void>;
|
|
106
|
+
/** Provider-resolve: run sdk then language hooks; return mutated fields. */
|
|
107
|
+
resolveProvider(input: LanguageModelInput): Promise<{
|
|
108
|
+
language?: unknown;
|
|
109
|
+
sdk: unknown;
|
|
110
|
+
model: ModelV2InfoLike;
|
|
111
|
+
}>;
|
|
112
|
+
/** List plugin ids currently registered via `plugin.add` / `register`. */
|
|
113
|
+
plugins(): string[];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Create an OCP-layer Promise v2 host.
|
|
117
|
+
* Call `register` for each v2 plugin, then `resolveProvider` at provider-resolve time.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createPromiseV2Host(options?: Record<string, unknown>): PromiseV2Host;
|
|
120
|
+
/** @deprecated Prefer `createPromiseV2Host().ctx.aisdk`. */
|
|
121
|
+
export declare function createAisdkBus(): AisdkHooks;
|
|
122
|
+
/** Create a PluginContext for the OCP layer / hosts that wire this kit. */
|
|
123
|
+
export declare function createPluginContext(options?: Record<string, unknown>, plugin?: {
|
|
124
|
+
id?: string;
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
}): PluginContext;
|
|
127
|
+
/**
|
|
128
|
+
* Promise v2 `define()` — identity + validation (OpenCode-compatible).
|
|
129
|
+
* The OCP layer / host must `register` / invoke `setup` at load time.
|
|
130
|
+
*/
|
|
131
|
+
export declare function define(plugin: Plugin): Plugin;
|
|
132
|
+
export declare function isPromisePlugin(value: unknown): value is Plugin;
|
|
133
|
+
/** Run plugin setup against a fresh OCP-layer host (conformance helper). */
|
|
134
|
+
export declare function runPromisePlugin(plugin: Plugin, init?: {
|
|
135
|
+
options?: Record<string, unknown>;
|
|
136
|
+
}): Promise<{
|
|
137
|
+
host: PromiseV2Host;
|
|
138
|
+
ctx: PluginContext;
|
|
139
|
+
plugin: Plugin;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Host provider-resolve helper: emit `sdk` then `language` against ctx listeners.
|
|
143
|
+
* Prefer `createPromiseV2Host().resolveProvider` when you own the host.
|
|
144
|
+
*/
|
|
145
|
+
export declare function injectLanguageModel(ctx: PluginContext, input?: LanguageModelInput): Promise<{
|
|
146
|
+
language?: unknown;
|
|
147
|
+
sdk?: unknown;
|
|
148
|
+
}>;
|
|
149
|
+
/** Emit `aisdk` `sdk` hook (optional T3 companion). */
|
|
150
|
+
export declare function injectSdk(ctx: PluginContext, input?: LanguageModelInput, seed?: {
|
|
151
|
+
sdk?: unknown;
|
|
152
|
+
}): Promise<{
|
|
153
|
+
sdk?: unknown;
|
|
154
|
+
}>;
|
|
155
|
+
/** Full host resolve path: language + sdk hooks on an existing ctx. */
|
|
156
|
+
export declare function resolveProvider(ctx: PluginContext, input: LanguageModelInput): Promise<{
|
|
157
|
+
language?: unknown;
|
|
158
|
+
sdk: unknown;
|
|
159
|
+
}>;
|
|
160
|
+
export {};
|
|
161
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Promise v2 aisdk host kit — wired from the OCP layer
|
|
3
|
+
* (operator overrides / sidecar / host-kit helpers).
|
|
4
|
+
*
|
|
5
|
+
* API shape matches `@opencode-ai/plugin/v2/promise` (OpenCode 1.18.x):
|
|
6
|
+
* `await ctx.aisdk.sdk(cb)` / `await ctx.aisdk.language(cb)`.
|
|
7
|
+
*
|
|
8
|
+
* OCP 0.1 T3 bar: `ctx.aisdk` language (+ ideally sdk) hooks.
|
|
9
|
+
* Other domains loud-stub in the same ship.
|
|
10
|
+
*/
|
|
11
|
+
export const PKG = "@opencode-compat/host-promise-v2";
|
|
12
|
+
export const VERSION = "0.1.0";
|
|
13
|
+
const ctxInternal = new WeakMap();
|
|
14
|
+
function loudDomain(name) {
|
|
15
|
+
const reload = async () => {
|
|
16
|
+
throw new Error(`${PKG}: Promise v2 domain "${name}" reload is not implemented. See docs/ocp/0.1.md §7.`);
|
|
17
|
+
};
|
|
18
|
+
return new Proxy({ reload }, {
|
|
19
|
+
get(target, prop) {
|
|
20
|
+
if (prop === "reload")
|
|
21
|
+
return target.reload;
|
|
22
|
+
if (prop === Symbol.toStringTag)
|
|
23
|
+
return `LoudDomain(${name})`;
|
|
24
|
+
return (..._args) => {
|
|
25
|
+
throw new Error(`${PKG}: Promise v2 domain "${name}" is not implemented (called: ${String(prop)}). See docs/ocp/0.1.md §7.`);
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function createAisdkInternal() {
|
|
31
|
+
const sdkHandlers = new Set();
|
|
32
|
+
const languageHandlers = new Set();
|
|
33
|
+
const hooks = {
|
|
34
|
+
async sdk(callback) {
|
|
35
|
+
sdkHandlers.add(callback);
|
|
36
|
+
return {
|
|
37
|
+
async dispose() {
|
|
38
|
+
sdkHandlers.delete(callback);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
async language(callback) {
|
|
43
|
+
languageHandlers.add(callback);
|
|
44
|
+
return {
|
|
45
|
+
async dispose() {
|
|
46
|
+
languageHandlers.delete(callback);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
listenerCount(event) {
|
|
51
|
+
return event === "sdk" ? sdkHandlers.size : languageHandlers.size;
|
|
52
|
+
},
|
|
53
|
+
events() {
|
|
54
|
+
const out = [];
|
|
55
|
+
if (sdkHandlers.size > 0)
|
|
56
|
+
out.push("sdk");
|
|
57
|
+
if (languageHandlers.size > 0)
|
|
58
|
+
out.push("language");
|
|
59
|
+
return out;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
hooks,
|
|
64
|
+
async emitSdk(event) {
|
|
65
|
+
for (const handler of [...sdkHandlers]) {
|
|
66
|
+
await handler(event);
|
|
67
|
+
}
|
|
68
|
+
return event;
|
|
69
|
+
},
|
|
70
|
+
async emitLanguage(event) {
|
|
71
|
+
for (const handler of [...languageHandlers]) {
|
|
72
|
+
await handler(event);
|
|
73
|
+
}
|
|
74
|
+
return event;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function modelFromInput(input) {
|
|
79
|
+
const providerID = String(input.providerID ?? input.model?.providerID ?? "");
|
|
80
|
+
const modelID = String(input.modelID ?? input.model?.id ?? "");
|
|
81
|
+
return {
|
|
82
|
+
id: modelID,
|
|
83
|
+
providerID,
|
|
84
|
+
name: input.model?.name ?? modelID,
|
|
85
|
+
api: { id: modelID, ...(input.model?.api ?? {}) },
|
|
86
|
+
...input.model,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function buildHost(options) {
|
|
90
|
+
const aisdk = createAisdkInternal();
|
|
91
|
+
const plugins = new Map();
|
|
92
|
+
const state = {
|
|
93
|
+
plugins,
|
|
94
|
+
aisdk,
|
|
95
|
+
options,
|
|
96
|
+
ctx: null,
|
|
97
|
+
};
|
|
98
|
+
const pluginDomain = {
|
|
99
|
+
async add(plugin) {
|
|
100
|
+
await registerOnHost(state, plugin);
|
|
101
|
+
},
|
|
102
|
+
async remove(id) {
|
|
103
|
+
state.plugins.delete(id);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const ctx = {
|
|
107
|
+
options,
|
|
108
|
+
aisdk: aisdk.hooks,
|
|
109
|
+
plugin: pluginDomain,
|
|
110
|
+
agent: loudDomain("agent"),
|
|
111
|
+
catalog: loudDomain("catalog"),
|
|
112
|
+
command: loudDomain("command"),
|
|
113
|
+
skill: loudDomain("skill"),
|
|
114
|
+
reference: loudDomain("reference"),
|
|
115
|
+
integration: loudDomain("integration"),
|
|
116
|
+
};
|
|
117
|
+
state.ctx = ctx;
|
|
118
|
+
ctxInternal.set(ctx, aisdk);
|
|
119
|
+
return state;
|
|
120
|
+
}
|
|
121
|
+
async function registerOnHost(state, plugin) {
|
|
122
|
+
const defined = define(plugin);
|
|
123
|
+
state.plugins.set(defined.id, defined);
|
|
124
|
+
state.ctx.plugin.id = defined.id;
|
|
125
|
+
await defined.setup(state.ctx);
|
|
126
|
+
return defined;
|
|
127
|
+
}
|
|
128
|
+
async function resolveOnHost(state, input) {
|
|
129
|
+
const model = modelFromInput(input);
|
|
130
|
+
const pkg = String(input.package ?? "");
|
|
131
|
+
const opts = { ...(input.options ?? {}) };
|
|
132
|
+
const sdkEvent = {
|
|
133
|
+
model,
|
|
134
|
+
package: pkg,
|
|
135
|
+
options: opts,
|
|
136
|
+
sdk: input.sdk,
|
|
137
|
+
};
|
|
138
|
+
await state.aisdk.emitSdk(sdkEvent);
|
|
139
|
+
const languageEvent = {
|
|
140
|
+
model,
|
|
141
|
+
sdk: sdkEvent.sdk,
|
|
142
|
+
options: opts,
|
|
143
|
+
language: undefined,
|
|
144
|
+
};
|
|
145
|
+
await state.aisdk.emitLanguage(languageEvent);
|
|
146
|
+
return {
|
|
147
|
+
language: languageEvent.language,
|
|
148
|
+
sdk: sdkEvent.sdk,
|
|
149
|
+
model,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create an OCP-layer Promise v2 host.
|
|
154
|
+
* Call `register` for each v2 plugin, then `resolveProvider` at provider-resolve time.
|
|
155
|
+
*/
|
|
156
|
+
export function createPromiseV2Host(options = {}) {
|
|
157
|
+
const state = buildHost(options);
|
|
158
|
+
return {
|
|
159
|
+
ctx: state.ctx,
|
|
160
|
+
async register(plugin) {
|
|
161
|
+
return registerOnHost(state, plugin);
|
|
162
|
+
},
|
|
163
|
+
async remove(id) {
|
|
164
|
+
state.plugins.delete(id);
|
|
165
|
+
},
|
|
166
|
+
async resolveProvider(input) {
|
|
167
|
+
return resolveOnHost(state, input);
|
|
168
|
+
},
|
|
169
|
+
plugins() {
|
|
170
|
+
return [...state.plugins.keys()];
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** @deprecated Prefer `createPromiseV2Host().ctx.aisdk`. */
|
|
175
|
+
export function createAisdkBus() {
|
|
176
|
+
return createAisdkInternal().hooks;
|
|
177
|
+
}
|
|
178
|
+
/** Create a PluginContext for the OCP layer / hosts that wire this kit. */
|
|
179
|
+
export function createPluginContext(options = {}, plugin = {}) {
|
|
180
|
+
const host = createPromiseV2Host(options);
|
|
181
|
+
if (plugin.id)
|
|
182
|
+
host.ctx.plugin.id = plugin.id;
|
|
183
|
+
for (const [key, value] of Object.entries(plugin)) {
|
|
184
|
+
if (key === "id")
|
|
185
|
+
continue;
|
|
186
|
+
host.ctx.plugin[key] = value;
|
|
187
|
+
}
|
|
188
|
+
return host.ctx;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Promise v2 `define()` — identity + validation (OpenCode-compatible).
|
|
192
|
+
* The OCP layer / host must `register` / invoke `setup` at load time.
|
|
193
|
+
*/
|
|
194
|
+
export function define(plugin) {
|
|
195
|
+
if (!plugin || typeof plugin.setup !== "function") {
|
|
196
|
+
throw new Error(`${PKG}: define() requires { id, setup(ctx) }`);
|
|
197
|
+
}
|
|
198
|
+
if (typeof plugin.id !== "string" || plugin.id.length === 0) {
|
|
199
|
+
throw new Error(`${PKG}: define() requires a non-empty string id`);
|
|
200
|
+
}
|
|
201
|
+
return plugin;
|
|
202
|
+
}
|
|
203
|
+
export function isPromisePlugin(value) {
|
|
204
|
+
return (typeof value === "object" &&
|
|
205
|
+
value !== null &&
|
|
206
|
+
typeof value.setup === "function" &&
|
|
207
|
+
typeof value.id === "string");
|
|
208
|
+
}
|
|
209
|
+
/** Run plugin setup against a fresh OCP-layer host (conformance helper). */
|
|
210
|
+
export async function runPromisePlugin(plugin, init) {
|
|
211
|
+
const host = createPromiseV2Host(init?.options ?? {});
|
|
212
|
+
const defined = await host.register(plugin);
|
|
213
|
+
return { host, ctx: host.ctx, plugin: defined };
|
|
214
|
+
}
|
|
215
|
+
function requireInternal(ctx) {
|
|
216
|
+
const internal = ctxInternal.get(ctx);
|
|
217
|
+
if (!internal) {
|
|
218
|
+
throw new Error(`${PKG}: PluginContext was not created by this host kit. ` +
|
|
219
|
+
"Use createPromiseV2Host() / runPromisePlugin() / createPluginContext().");
|
|
220
|
+
}
|
|
221
|
+
return internal;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Host provider-resolve helper: emit `sdk` then `language` against ctx listeners.
|
|
225
|
+
* Prefer `createPromiseV2Host().resolveProvider` when you own the host.
|
|
226
|
+
*/
|
|
227
|
+
export async function injectLanguageModel(ctx, input = { providerID: "", modelID: "" }) {
|
|
228
|
+
const internal = requireInternal(ctx);
|
|
229
|
+
const model = modelFromInput(input);
|
|
230
|
+
const opts = { ...(input.options ?? {}) };
|
|
231
|
+
const sdkEvent = {
|
|
232
|
+
model,
|
|
233
|
+
package: String(input.package ?? ""),
|
|
234
|
+
options: opts,
|
|
235
|
+
sdk: input.sdk,
|
|
236
|
+
};
|
|
237
|
+
await internal.emitSdk(sdkEvent);
|
|
238
|
+
const languageEvent = {
|
|
239
|
+
model,
|
|
240
|
+
sdk: sdkEvent.sdk,
|
|
241
|
+
options: opts,
|
|
242
|
+
};
|
|
243
|
+
await internal.emitLanguage(languageEvent);
|
|
244
|
+
return { language: languageEvent.language, sdk: sdkEvent.sdk };
|
|
245
|
+
}
|
|
246
|
+
/** Emit `aisdk` `sdk` hook (optional T3 companion). */
|
|
247
|
+
export async function injectSdk(ctx, input = { providerID: "", modelID: "" }, seed = {}) {
|
|
248
|
+
const internal = requireInternal(ctx);
|
|
249
|
+
const model = modelFromInput(input);
|
|
250
|
+
const sdkEvent = {
|
|
251
|
+
model,
|
|
252
|
+
package: String(input.package ?? ""),
|
|
253
|
+
options: { ...(input.options ?? {}) },
|
|
254
|
+
sdk: seed.sdk ?? input.sdk,
|
|
255
|
+
};
|
|
256
|
+
await internal.emitSdk(sdkEvent);
|
|
257
|
+
return { sdk: sdkEvent.sdk };
|
|
258
|
+
}
|
|
259
|
+
/** Full host resolve path: language + sdk hooks on an existing ctx. */
|
|
260
|
+
export async function resolveProvider(ctx, input) {
|
|
261
|
+
const out = await injectLanguageModel(ctx, input);
|
|
262
|
+
return { language: out.language, sdk: out.sdk };
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opencode-compat/host-promise-v2",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared Promise v2 aisdk host kit wired from the OCP layer",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"author": "oakimov",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/oakimov/opencode-plugin-compat.git",
|
|
11
|
+
"directory": "packages/host-promise-v2"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"README.md",
|
|
28
|
+
"!dist/**/*.map"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "bunx tsc -p tsconfig.json",
|
|
32
|
+
"typecheck": "bunx tsc -p tsconfig.json --noEmit",
|
|
33
|
+
"prepack": "bunx tsc -p tsconfig.json"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.8.3"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/oakimov/opencode-plugin-compat/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/oakimov/opencode-plugin-compat/tree/main/packages/host-promise-v2#readme",
|
|
42
|
+
"keywords": [
|
|
43
|
+
"opencode",
|
|
44
|
+
"ocp",
|
|
45
|
+
"aisdk",
|
|
46
|
+
"promise-v2"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.2.0"
|
|
50
|
+
}
|
|
51
|
+
}
|