@neutrome/open-ai-router 0.1.4 → 0.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutrome/open-ai-router",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -114,9 +114,6 @@ export function createRouterExecutionRuntime(
114
114
  if (options.executors) {
115
115
  runtimeOptions.executors = options.executors;
116
116
  }
117
- if (options.resolveExecutor) {
118
- runtimeOptions.resolveExecutor = options.resolveExecutor;
119
- }
120
117
  if (options.transforms) {
121
118
  runtimeOptions.transforms = options.transforms;
122
119
  }
@@ -130,9 +127,41 @@ export function createRouterExecutionRuntime(
130
127
  runtimeOptions.executionIdFactory = options.executionIdFactory;
131
128
  }
132
129
 
130
+ const userResolveExecutor = options.resolveExecutor;
131
+ runtimeOptions.resolveExecutor = (name) => {
132
+ if (userResolveExecutor) {
133
+ const result = userResolveExecutor(name);
134
+ if (result) return result;
135
+ }
136
+ return resolveNamespaceExecutor(runtime, name);
137
+ };
138
+
133
139
  return createExecutionRuntime(runtimeOptions);
134
140
  }
135
141
 
142
+ function resolveNamespaceExecutor(
143
+ runtime: RouterRuntime,
144
+ name: string,
145
+ ): Executor | null {
146
+ const executor = runtime.executors.get(name);
147
+ if (!executor) return null;
148
+
149
+ return {
150
+ async execute(request, ctx) {
151
+ const model = getModel(request);
152
+ if (!model) throw new ExecutionError("resolution", "Request is missing model for namespace executor resolution", { stage: "target_resolution" });
153
+ const resolved = resolveInvocationTarget(runtime, `${name}/${model}`);
154
+ return ctx.invoke(request, { target: resolved.target });
155
+ },
156
+ async *stream(request, ctx) {
157
+ const model = getModel(request);
158
+ if (!model) throw new ExecutionError("resolution", "Request is missing model for namespace executor resolution", { stage: "target_resolution" });
159
+ const resolved = resolveInvocationTarget(runtime, `${name}/${model}`);
160
+ yield* ctx.invokeStream(request, { target: resolved.target });
161
+ },
162
+ };
163
+ }
164
+
136
165
  export async function handleChatCompletions(
137
166
  options: HandleChatCompletionsOptions,
138
167
  ): Promise<Response> {