Skip to content

Commit 04df142

Browse files
author
Erick Kinnee
committed
fix(plugin-sdk): expose async embedding batch runtime
1 parent 28ec823 commit 04df142

15 files changed

Lines changed: 117 additions & 28 deletions

‎docs/plugins/sdk-overview.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ is the generic embedding surface for reusable vector generation. Memory search
143143
consumes this generic provider surface. The older memory-specific registrar and
144144
manifest contract were removed after their August 2026 migration window.
145145

146-
Memory-specific providers that still expose a runtime `batchEmbed(...)` stay on
147-
the existing per-file batching contract unless their runtime explicitly sets
148-
`sourceWideBatchEmbed: true`. That opt-in lets the memory host submit chunks from
146+
Embedding providers that expose a runtime `batchEmbed(...)` stay on the
147+
existing per-file memory-index batching contract unless their runtime explicitly
148+
sets `sourceWideBatchEmbed: true`. Provider plugins can type that runtime through
149+
`openclaw/plugin-sdk/embedding-provider-runtime-contract`. That opt-in lets the
150+
memory host submit chunks from
149151
multiple dirty memory files and enabled sources in one `batchEmbed(...)` call up
150152
to the host batch limits. Batch adapters that upload JSONL request files must
151153
split provider jobs before their upload-size cap as well as their request-count

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ are private-local.
162162
| `plugin-sdk/provider-web-search-contract` | Private-local after July 2026; Narrow web-search config/credential contract helpers such as `createWebSearchProviderContractFields`, `enablePluginInConfig`, `resolveProviderWebSearchPluginConfig`, and scoped credential setters/getters |
163163
| `plugin-sdk/provider-web-search` | Private-local after July 2026; Web-search provider registration/cache/runtime helpers |
164164
| `plugin-sdk/embedding-providers` | Private-local after July 2026; General embedding provider types and read helpers, including `EmbeddingProviderAdapter`, `getEmbeddingProvider(...)`, and `listEmbeddingProviders(...)`; plugins register providers through `api.registerEmbeddingProvider(...)` so manifest ownership is enforced |
165+
| `plugin-sdk/embedding-provider-runtime-contract` | Typed contract for provider-owned text batching: `EmbeddingBatchChunk`, `EmbeddingBatchOptions`, and `EmbeddingProviderRuntime` with `batchEmbed(...)` and `sourceWideBatchEmbed` |
165166
| `plugin-sdk/provider-tools` | Private-local after July 2026; `ProviderToolCompatFamily`, `buildProviderToolCompatFamilyHooks`, and DeepSeek/Gemini/OpenAI schema cleanup + diagnostics |
166167
| `plugin-sdk/provider-usage` | Private-local after July 2026; Provider usage snapshot types, shared usage fetch helpers, and provider fetchers such as `fetchClaudeUsage` |
167168
| `plugin-sdk/provider-stream` | Private-local after July 2026; `ProviderStreamFamily`, `buildProviderStreamFamilyHooks`, `composeProviderStreamWrappers`, stream wrapper types, plain-text tool-call compat, and shared Anthropic/Google/Kilocode/MiniMax/Moonshot/OpenAI/OpenRouter/Z.AI wrapper helpers |

‎package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@
700700
"./plugin-sdk/embedding-providers": {
701701
"default": "./dist/plugin-sdk/embedding-providers.js"
702702
},
703+
"./plugin-sdk/embedding-provider-runtime-contract": {
704+
"types": "./dist/plugin-sdk/embedding-provider-runtime-contract.d.ts",
705+
"default": "./dist/plugin-sdk/embedding-provider-runtime-contract.js"
706+
},
703707
"./plugin-sdk/media-generation-runtime": {
704708
"default": "./dist/plugin-sdk/media-generation-runtime.js"
705709
},

‎packages/plugin-sdk/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
"types": "./dist/src/plugin-sdk/delivery-queue-runtime.d.ts",
6565
"default": "./src/delivery-queue-runtime.ts"
6666
},
67+
"./embedding-provider-runtime-contract": {
68+
"types": "./dist/src/plugin-sdk/embedding-provider-runtime-contract.d.ts",
69+
"default": "./src/embedding-provider-runtime-contract.ts"
70+
},
6771
"./error-runtime": {
6872
"types": "./dist/src/plugin-sdk/error-runtime.d.ts",
6973
"default": "./src/error-runtime.ts"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Public package facade for provider-owned embedding batch contracts.
2+
3+
export * from "../../../src/plugin-sdk/embedding-provider-runtime-contract.js";

‎scripts/check-plugin-sdk-exports.mts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,26 @@ let missing = 0;
6969
join(consumerRoot, "index.ts"),
7070
`import { buildChannelConfigSchema, DmPolicySchema } from "openclaw/plugin-sdk/channel-config-schema";
7171
import { defineChannelPluginEntry } from "openclaw/plugin-sdk/core";
72+
import type {
73+
EmbeddingBatchOptions,
74+
EmbeddingProviderRuntime,
75+
} from "openclaw/plugin-sdk/embedding-provider-runtime-contract";
7276
import { createPluginRuntimeStore, type PluginRuntime } from "openclaw/plugin-sdk/runtime-store";
7377
import { z } from "zod";
7478
7579
const runtimeStore = createPluginRuntimeStore<PluginRuntime>({
7680
pluginId: "package-consumer",
7781
errorMessage: "package consumer runtime not initialized",
7882
});
83+
const embeddingRuntime = {
84+
id: "package-consumer",
85+
sourceWideBatchEmbed: true,
86+
batchEmbed: async (options: EmbeddingBatchOptions) => options.chunks.map(() => [1]),
87+
} satisfies EmbeddingProviderRuntime;
7988
export const configSchema = buildChannelConfigSchema(
8089
z.object({ dmPolicy: DmPolicySchema.optional() }),
8190
);
91+
void embeddingRuntime;
8292
8393
declare const plugin: Parameters<typeof defineChannelPluginEntry>[0]["plugin"];
8494
export default defineChannelPluginEntry({

‎scripts/lib/plugin-sdk-entrypoints.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"media-store",
8686
"media-mime",
8787
"embedding-providers",
88+
"embedding-provider-runtime-contract",
8889
"media-generation-runtime",
8990
"conversation-binding-runtime",
9091
"conversation-runtime",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Public SDK contract for provider-owned asynchronous embedding batches. */
2+
export type {
3+
EmbeddingBatchChunk,
4+
EmbeddingBatchOptions,
5+
EmbeddingProviderRuntime,
6+
} from "../plugins/embedding-provider-runtime-types.js";

‎src/plugin-sdk/embedding-providers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export {
77
} from "../plugins/embedding-provider-runtime.js";
88

99
export type {
10+
EmbeddingBatchChunk,
11+
EmbeddingBatchOptions,
1012
EmbeddingInput,
1113
EmbeddingProvider,
1214
EmbeddingProviderAdapter,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** One text chunk submitted through a provider-owned asynchronous embedding batch. */
2+
export type EmbeddingBatchChunk = {
3+
text: string;
4+
};
5+
6+
/** Host-controlled execution parameters for an asynchronous embedding batch. */
7+
export type EmbeddingBatchOptions = {
8+
agentId: string;
9+
chunks: EmbeddingBatchChunk[];
10+
wait: boolean;
11+
concurrency: number;
12+
pollIntervalMs: number;
13+
timeoutMs: number;
14+
debug: (message: string, data?: Record<string, unknown>) => void;
15+
};
16+
17+
/** Runtime metadata returned with a created embedding provider. */
18+
export type EmbeddingProviderRuntime = {
19+
id: string;
20+
cacheKeyData?: Record<string, unknown>;
21+
/** Prior persisted model/cache identities that are equivalent to the current identity. */
22+
indexIdentityAliases?: Array<{
23+
model: string;
24+
cacheKeyData: Record<string, unknown>;
25+
}>;
26+
inlineQueryTimeoutMs?: number;
27+
inlineBatchTimeoutMs?: number;
28+
/** Lets the provider batch chunks from multiple dirty memory files in one request. */
29+
sourceWideBatchEmbed?: boolean;
30+
/** Runs the provider-owned asynchronous batch lifecycle, returning one vector per chunk. */
31+
batchEmbed?: (options: EmbeddingBatchOptions) => Promise<number[][] | null>;
32+
};

0 commit comments

Comments
 (0)