memeloop 0.2.3 → 0.2.4

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/index.cjs CHANGED
@@ -7143,6 +7143,112 @@ var init_identityAttestationManagement = __esm({
7143
7143
  }
7144
7144
  });
7145
7145
 
7146
+ // src/orchestration/drivers/modelProviderDriver.ts
7147
+ function classificationRank(value) {
7148
+ return CLASSIFICATION_ORDER[value];
7149
+ }
7150
+ function assertClassificationAllowed(policy, classification) {
7151
+ if (!policy?.maxInputClassification || !classification) return;
7152
+ if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
7153
+ throw new OrchestrationError({
7154
+ code: "FORBIDDEN",
7155
+ message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
7156
+ retryable: false,
7157
+ details: { classification, maxInputClassification: policy.maxInputClassification }
7158
+ });
7159
+ }
7160
+ }
7161
+ function modelClassNameForSpec(model) {
7162
+ return `${model.provider}-${model.model}`.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^-+|-+$/g, "") || "model";
7163
+ }
7164
+ function createModelProviderDriverFromLLMProvider(provider, options) {
7165
+ const inFlight = /* @__PURE__ */ new Map();
7166
+ const toLegacyRequest = options.toLegacyRequest ?? ((request) => {
7167
+ const candidates = options.models.filter(
7168
+ (model) => modelClassNameForSpec(model) === request.modelClassRef.name || model.model === request.modelClassRef.name
7169
+ );
7170
+ if (candidates.length !== 1) {
7171
+ throw new OrchestrationError({
7172
+ code: "INVALID",
7173
+ message: candidates.length === 0 ? `model class '${request.modelClassRef.name}' is not served by provider '${provider.name}'` : `model class '${request.modelClassRef.name}' is ambiguous for provider '${provider.name}'`,
7174
+ retryable: false
7175
+ });
7176
+ }
7177
+ return {
7178
+ model: candidates[0].model,
7179
+ messages: request.messages,
7180
+ max_tokens: request.maxOutputTokens,
7181
+ temperature: request.temperature,
7182
+ topP: request.topP,
7183
+ providerOptions: request.providerOptions,
7184
+ abortSignal: request.signal
7185
+ };
7186
+ });
7187
+ const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
7188
+ return {
7189
+ async listModels() {
7190
+ return options.models;
7191
+ },
7192
+ async getHealth() {
7193
+ return {
7194
+ healthy: true,
7195
+ detail: `legacy provider ${provider.name}`,
7196
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
7197
+ };
7198
+ },
7199
+ async *generate(request) {
7200
+ assertClassificationAllowed(options.dataPolicy, request.inputClassification);
7201
+ const controller = new AbortController();
7202
+ inFlight.set(request.callId, controller);
7203
+ const onExternalAbort = () => {
7204
+ controller.abort();
7205
+ };
7206
+ request.signal?.addEventListener("abort", onExternalAbort);
7207
+ try {
7208
+ const legacy = toLegacyRequest({ ...request, signal: controller.signal });
7209
+ const output = await provider.chat(legacy);
7210
+ if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
7211
+ for await (const chunk of output) {
7212
+ if (controller.signal.aborted) {
7213
+ yield {
7214
+ type: "error",
7215
+ error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
7216
+ };
7217
+ return;
7218
+ }
7219
+ const delta = toDelta(chunk);
7220
+ if (delta !== void 0) {
7221
+ yield { type: "delta", delta };
7222
+ }
7223
+ }
7224
+ } else if (typeof output === "string") {
7225
+ yield { type: "delta", delta: output };
7226
+ }
7227
+ yield { type: "done" };
7228
+ } finally {
7229
+ request.signal?.removeEventListener("abort", onExternalAbort);
7230
+ inFlight.delete(request.callId);
7231
+ }
7232
+ },
7233
+ async cancel(callId) {
7234
+ inFlight.get(callId)?.abort();
7235
+ }
7236
+ };
7237
+ }
7238
+ var CLASSIFICATION_ORDER;
7239
+ var init_modelProviderDriver = __esm({
7240
+ "src/orchestration/drivers/modelProviderDriver.ts"() {
7241
+ "use strict";
7242
+ init_errors();
7243
+ CLASSIFICATION_ORDER = {
7244
+ public: 0,
7245
+ internal: 1,
7246
+ confidential: 2,
7247
+ restricted: 3
7248
+ };
7249
+ }
7250
+ });
7251
+
7146
7252
  // src/orchestration/drivers/localModelRegistration.ts
7147
7253
  function sanitizeModelName(name) {
7148
7254
  return name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^-+|-+$/g, "") || "model";
@@ -7153,7 +7259,7 @@ async function describeLocalModelEndpoints(driver, options) {
7153
7259
  const modelClasses = [];
7154
7260
  const endpoints = [];
7155
7261
  for (const model of models) {
7156
- const baseName = sanitizeModelName(`${model.provider}-${model.model}`);
7262
+ const baseName = modelClassNameForSpec(model);
7157
7263
  modelClasses.push(createModelClassManifest(baseName, model));
7158
7264
  endpoints.push(createModelEndpointManifest(`${baseName}-${sanitizeModelName(options.nodeId)}`, {
7159
7265
  modelClassRef: { apiVersion: MODEL_CLASS_API_VERSION, kind: MODEL_CLASS_KIND, name: baseName },
@@ -7190,6 +7296,7 @@ var init_localModelRegistration = __esm({
7190
7296
  "src/orchestration/drivers/localModelRegistration.ts"() {
7191
7297
  "use strict";
7192
7298
  init_resources();
7299
+ init_modelProviderDriver();
7193
7300
  TRUST_RANK2 = {
7194
7301
  quarantine: 0,
7195
7302
  restricted: 1,
@@ -8952,95 +9059,6 @@ var init_managedLoopRuntimeAdapter = __esm({
8952
9059
  }
8953
9060
  });
8954
9061
 
8955
- // src/orchestration/drivers/modelProviderDriver.ts
8956
- function classificationRank(value) {
8957
- return CLASSIFICATION_ORDER[value];
8958
- }
8959
- function assertClassificationAllowed(policy, classification) {
8960
- if (!policy?.maxInputClassification || !classification) return;
8961
- if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
8962
- throw new OrchestrationError({
8963
- code: "FORBIDDEN",
8964
- message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
8965
- retryable: false,
8966
- details: { classification, maxInputClassification: policy.maxInputClassification }
8967
- });
8968
- }
8969
- }
8970
- function createModelProviderDriverFromLLMProvider(provider, options) {
8971
- const inFlight = /* @__PURE__ */ new Map();
8972
- const toLegacyRequest = options.toLegacyRequest ?? ((request) => ({
8973
- ...provider.modelId !== void 0 ? { model: provider.modelId } : {},
8974
- messages: request.messages,
8975
- max_tokens: request.maxOutputTokens,
8976
- temperature: request.temperature,
8977
- abortSignal: request.signal
8978
- }));
8979
- const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
8980
- return {
8981
- async listModels() {
8982
- return options.models;
8983
- },
8984
- async getHealth() {
8985
- return {
8986
- healthy: true,
8987
- detail: `legacy provider ${provider.name}`,
8988
- checkedAt: (/* @__PURE__ */ new Date()).toISOString()
8989
- };
8990
- },
8991
- async *generate(request) {
8992
- assertClassificationAllowed(options.dataPolicy, request.inputClassification);
8993
- const controller = new AbortController();
8994
- inFlight.set(request.callId, controller);
8995
- const onExternalAbort = () => {
8996
- controller.abort();
8997
- };
8998
- request.signal?.addEventListener("abort", onExternalAbort);
8999
- try {
9000
- const legacy = toLegacyRequest({ ...request, signal: controller.signal });
9001
- const output = await provider.chat(legacy);
9002
- if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
9003
- for await (const chunk of output) {
9004
- if (controller.signal.aborted) {
9005
- yield {
9006
- type: "error",
9007
- error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
9008
- };
9009
- return;
9010
- }
9011
- const delta = toDelta(chunk);
9012
- if (delta !== void 0) {
9013
- yield { type: "delta", delta };
9014
- }
9015
- }
9016
- } else if (typeof output === "string") {
9017
- yield { type: "delta", delta: output };
9018
- }
9019
- yield { type: "done" };
9020
- } finally {
9021
- request.signal?.removeEventListener("abort", onExternalAbort);
9022
- inFlight.delete(request.callId);
9023
- }
9024
- },
9025
- async cancel(callId) {
9026
- inFlight.get(callId)?.abort();
9027
- }
9028
- };
9029
- }
9030
- var CLASSIFICATION_ORDER;
9031
- var init_modelProviderDriver = __esm({
9032
- "src/orchestration/drivers/modelProviderDriver.ts"() {
9033
- "use strict";
9034
- init_errors();
9035
- CLASSIFICATION_ORDER = {
9036
- public: 0,
9037
- internal: 1,
9038
- confidential: 2,
9039
- restricted: 3
9040
- };
9041
- }
9042
- });
9043
-
9044
9062
  // src/orchestration/drivers/managedModelGatewayAdapter.ts
9045
9063
  function fail(code, message, retryable = false) {
9046
9064
  throw new OrchestrationError({ code, message, retryable });
@@ -13244,9 +13262,13 @@ function createGatewayMediatedLLMProvider(options) {
13244
13262
  const messages = Array.isArray(record2.messages) ? record2.messages : [];
13245
13263
  const runReference = options.runRefForRequest?.(request) ?? options.runRef;
13246
13264
  return (async function* () {
13247
- const handle = await options.broker.issueModelAccessHandle({
13265
+ const selectedModel = options.resolveModelForRequest?.(request) ?? {
13248
13266
  modelClassRef: options.modelClassRef,
13249
- ...options.modelDigest !== void 0 ? { modelDigest: options.modelDigest } : {},
13267
+ ...options.modelDigest !== void 0 ? { modelDigest: options.modelDigest } : {}
13268
+ };
13269
+ const handle = await options.broker.issueModelAccessHandle({
13270
+ modelClassRef: selectedModel.modelClassRef,
13271
+ ...selectedModel.modelDigest !== void 0 ? { modelDigest: selectedModel.modelDigest } : {},
13250
13272
  ...options.policyDigest !== void 0 ? { policyDigest: options.policyDigest } : {},
13251
13273
  ...runReference ? { runRef: runReference } : {},
13252
13274
  ...runReference && options.attempt !== void 0 ? { attempt: options.attempt } : {},
@@ -13257,12 +13279,18 @@ function createGatewayMediatedLLMProvider(options) {
13257
13279
  try {
13258
13280
  for await (const chunk of options.gateway.generate({
13259
13281
  callId,
13260
- modelClassRef: options.modelClassRef,
13261
- ...options.modelDigest !== void 0 ? { modelDigest: options.modelDigest } : {},
13282
+ modelClassRef: selectedModel.modelClassRef,
13283
+ ...selectedModel.modelDigest !== void 0 ? { modelDigest: selectedModel.modelDigest } : {},
13262
13284
  messages,
13285
+ ...typeof record2.maxOutputTokens === "number" ? { maxOutputTokens: record2.maxOutputTokens } : typeof record2.max_tokens === "number" ? { maxOutputTokens: record2.max_tokens } : {},
13286
+ ...typeof record2.temperature === "number" ? { temperature: record2.temperature } : {},
13287
+ ...typeof record2.topP === "number" ? { topP: record2.topP } : {},
13288
+ ...record2.providerOptions !== null && typeof record2.providerOptions === "object" ? {
13289
+ providerOptions: record2.providerOptions
13290
+ } : {},
13263
13291
  accessHandle: handle.token,
13264
13292
  ...options.workerKey !== void 0 ? { workerKey: options.workerKey } : {},
13265
- ...record2.signal !== void 0 ? { signal: record2.signal } : {}
13293
+ ...record2.abortSignal ?? record2.signal ? { signal: record2.abortSignal ?? record2.signal } : {}
13266
13294
  })) {
13267
13295
  if (chunk.type === "delta" && chunk.delta !== void 0) {
13268
13296
  yield chunk.delta;
@@ -26875,6 +26903,7 @@ __export(src_exports, {
26875
26903
  mcpForwardImpl: () => mcpForwardImpl,
26876
26904
  mergeAgentToolsIntoFrameworkConfig: () => mergeAgentToolsIntoFrameworkConfig,
26877
26905
  mergePermissionSets: () => mergePermissionSets,
26906
+ modelClassNameForSpec: () => modelClassNameForSpec,
26878
26907
  negotiateCapabilities: () => negotiateCapabilities,
26879
26908
  normalizeScript: () => normalizeScript,
26880
26909
  onApprovalRequest: () => onApprovalRequest,
@@ -32160,6 +32189,7 @@ function getToolDefinition(toolId) {
32160
32189
  mcpForwardImpl,
32161
32190
  mergeAgentToolsIntoFrameworkConfig,
32162
32191
  mergePermissionSets,
32192
+ modelClassNameForSpec,
32163
32193
  negotiateCapabilities,
32164
32194
  normalizeScript,
32165
32195
  onApprovalRequest,