memeloop 0.2.2 → 0.2.3

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.
@@ -1,5 +1,14 @@
1
1
  // src/llm/fetchProvider.ts
2
2
  import { generateText, streamText } from "ai";
3
+ function resolveFetchLLMCallSettings(body) {
4
+ return {
5
+ maxOutputTokens: body.maxOutputTokens ?? body.max_tokens,
6
+ temperature: body.temperature,
7
+ topP: body.topP,
8
+ providerOptions: body.providerOptions,
9
+ abortSignal: body.abortSignal
10
+ };
11
+ }
3
12
  function createFetchLLMProvider(config) {
4
13
  return {
5
14
  name: config.name,
@@ -24,9 +33,7 @@ function createFetchLLMProvider(config) {
24
33
  };
25
34
  });
26
35
  const system = body.system ?? (systemMessages.length > 0 ? systemMessages.join("\n\n") : void 0);
27
- const temperature = body.temperature;
28
- const abortSignal = body.abortSignal;
29
- const maxOutputTokens = body.max_tokens;
36
+ const { abortSignal, maxOutputTokens, providerOptions, temperature, topP } = resolveFetchLLMCallSettings(body);
30
37
  if (body.stream !== false) {
31
38
  let streamingError;
32
39
  const result2 = streamText({
@@ -35,6 +42,8 @@ function createFetchLLMProvider(config) {
35
42
  messages,
36
43
  maxOutputTokens,
37
44
  temperature,
45
+ topP,
46
+ providerOptions,
38
47
  abortSignal,
39
48
  onError: ({ error }) => {
40
49
  streamingError = error;
@@ -55,6 +64,8 @@ function createFetchLLMProvider(config) {
55
64
  messages,
56
65
  maxOutputTokens,
57
66
  temperature,
67
+ topP,
68
+ providerOptions,
58
69
  abortSignal
59
70
  });
60
71
  return result.text;
@@ -63,6 +74,7 @@ function createFetchLLMProvider(config) {
63
74
  }
64
75
 
65
76
  export {
77
+ resolveFetchLLMCallSettings,
66
78
  createFetchLLMProvider
67
79
  };
68
- //# sourceMappingURL=chunk-K6P63KD4.js.map
80
+ //# sourceMappingURL=chunk-HY3U3GLE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/llm/fetchProvider.ts"],"sourcesContent":["/**\n * Provider-agnostic LLM provider — wraps a current Vercel AI SDK LanguageModel.\n *\n * The core does NOT depend on @ai-sdk/openai or any specific provider.\n * Hosts inject their own `createModel` factory:\n *\n * import { createOpenAI } from '@ai-sdk/openai';\n * const openai = createOpenAI({ baseURL: '...', apiKey: '...' });\n * const provider = createFetchLLMProvider({\n * name: 'openai',\n * createModel: (id) => openai(id ?? 'gpt-4o-mini'),\n * });\n *\n * Or for Anthropic:\n * import { createAnthropic } from '@ai-sdk/anthropic';\n * const anthropic = createAnthropic({ apiKey: '...' });\n * const provider = createFetchLLMProvider({\n * name: 'claude',\n * createModel: (id) => anthropic(id ?? 'claude-3-5-sonnet-20241022'),\n * });\n *\n * Works with every @ai-sdk/* provider: openai, anthropic, google, deepseek,\n * cohere, mistral, azure, bedrock, groq, ollama, openrouter, together, etc.\n */\n\nimport type { JSONValue, LanguageModel } from 'ai';\nimport { generateText, streamText } from 'ai';\n\nimport type { ILLMProvider } from '../types.js';\n\nexport interface FetchLLMChatRequest {\n messages?: Array<{ role: string; content: string }>;\n model?: string;\n stream?: boolean;\n /** Legacy OpenAI-compatible spelling retained for host adapters. */\n max_tokens?: number;\n /** AI SDK spelling. Takes precedence over max_tokens. */\n maxOutputTokens?: number;\n temperature?: number;\n topP?: number;\n providerOptions?: Record<string, Record<string, JSONValue>>;\n system?: string;\n abortSignal?: AbortSignal;\n}\n\nexport function resolveFetchLLMCallSettings(body: FetchLLMChatRequest): {\n maxOutputTokens: number | undefined;\n temperature: number | undefined;\n topP: number | undefined;\n providerOptions: Record<string, Record<string, JSONValue>> | undefined;\n abortSignal: AbortSignal | undefined;\n} {\n return {\n maxOutputTokens: body.maxOutputTokens ?? body.max_tokens,\n temperature: body.temperature,\n topP: body.topP,\n providerOptions: body.providerOptions,\n abortSignal: body.abortSignal,\n };\n}\n\n// ─── Config ────────────────────────────────────────────────────────────\n\nexport interface FetchLLMProviderConfig {\n /** Display name. */\n name: string;\n /** Serializable default model identity for scheduling and audit records. */\n modelId?: string;\n /**\n * Factory: given an optional model id, return a LanguageModel from any @ai-sdk/* provider.\n * The factory is responsible for picking a default model when `modelId` is omitted.\n */\n createModel: (modelId?: string) => LanguageModel;\n}\n\n// ─── Factory ───────────────────────────────────────────────────────────\n\n/**\n * Create an `ILLMProvider` that delegates to the Vercel AI SDK.\n *\n * Provider-agnostic — hosts supply their own `createModel` factory.\n * Supports every @ai-sdk/* provider (OpenAI, Anthropic, Google, DeepSeek,\n * Groq, Ollama, OpenRouter, Together, Bedrock, Azure, Mistral, Cohere…).\n *\n * @example\n * ```ts\n * import { createOpenAI } from '@ai-sdk/openai';\n * const openai = createOpenAI({ baseURL: 'https://api.openai.com/v1', apiKey });\n * const provider = createFetchLLMProvider({\n * name: 'openai',\n * createModel: (modelId) => openai(modelId ?? 'gpt-4o-mini'),\n * });\n * ```\n */\nexport function createFetchLLMProvider(config: FetchLLMProviderConfig): ILLMProvider {\n return {\n name: config.name,\n ...(config.modelId !== undefined ? { modelId: config.modelId } : {}),\n // Store the factory so hosts can introspect or extend\n model: config.createModel as unknown as LanguageModel,\n async chat(request: unknown) {\n const body = (typeof request === 'object' && request !== null ? request : {}) as FetchLLMChatRequest;\n\n const model = config.createModel(body.model);\n const specificationVersion = (\n model as { specificationVersion?: unknown } | null\n )?.specificationVersion;\n if (\n model === null ||\n typeof model !== 'object' ||\n !['v2', 'v3', 'v4'].includes(String(specificationVersion))\n ) {\n throw new Error(\n `LLM provider '${config.name}' returned an incompatible AI SDK model for '${\n typeof body.model === 'string' ? body.model : (config.modelId ?? 'default')\n }' (expected specificationVersion v2, v3, or v4; received ${String(specificationVersion)})`,\n );\n }\n\n const systemMessages = (body.messages ?? [])\n .filter((message) => message.role === 'system')\n .map((message) => message.content);\n const messages = (body.messages ?? [])\n .filter((message) => message.role !== 'system')\n .map((message) => {\n // AI SDK model messages do not accept a bare textual tool role.\n // MemeLoop stores tool results as role='tool'; promote them to user\n // messages while preserving the result text in conversation history.\n const role = message.role === 'tool' ? 'user' : (message.role as 'user' | 'assistant');\n return {\n role,\n content: message.content,\n };\n });\n\n const system = body.system ?? (\n systemMessages.length > 0 ? systemMessages.join('\\n\\n') : undefined\n );\n const { abortSignal, maxOutputTokens, providerOptions, temperature, topP } = resolveFetchLLMCallSettings(body);\n\n if (body.stream !== false) {\n let streamingError: unknown;\n const result = streamText({\n model,\n instructions: system,\n messages,\n maxOutputTokens,\n temperature,\n topP,\n providerOptions,\n abortSignal,\n onError: ({ error }) => {\n streamingError = error;\n },\n });\n return (async function*() {\n for await (const chunk of result.textStream) {\n yield chunk;\n }\n if (streamingError !== undefined) {\n throw streamingError instanceof Error\n ? streamingError\n : new Error('The model stream failed', { cause: streamingError });\n }\n })();\n }\n\n const result = await generateText({\n model,\n instructions: system,\n messages,\n maxOutputTokens,\n temperature,\n topP,\n providerOptions,\n abortSignal,\n });\n return result.text;\n },\n };\n}\n"],"mappings":";AA0BA,SAAS,cAAc,kBAAkB;AAmBlC,SAAS,4BAA4B,MAM1C;AACA,SAAO;AAAA,IACL,iBAAiB,KAAK,mBAAmB,KAAK;AAAA,IAC9C,aAAa,KAAK;AAAA,IAClB,MAAM,KAAK;AAAA,IACX,iBAAiB,KAAK;AAAA,IACtB,aAAa,KAAK;AAAA,EACpB;AACF;AAmCO,SAAS,uBAAuB,QAA8C;AACnF,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,GAAI,OAAO,YAAY,SAAY,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;AAAA;AAAA,IAElE,OAAO,OAAO;AAAA,IACd,MAAM,KAAK,SAAkB;AAC3B,YAAM,OAAQ,OAAO,YAAY,YAAY,YAAY,OAAO,UAAU,CAAC;AAE3E,YAAM,QAAQ,OAAO,YAAY,KAAK,KAAK;AAC3C,YAAM,uBACJ,OACC;AACH,UACE,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,CAAC,MAAM,MAAM,IAAI,EAAE,SAAS,OAAO,oBAAoB,CAAC,GACzD;AACA,cAAM,IA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ACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,aAAO,OAAO;AAAA,IAChB;AAAA,EACF;AACF;","names":["result"]}
@@ -1,5 +1,5 @@
1
1
  import { i as AgentLoopStep, f as AgentLoopInput, e as AgentLoopGenerator, c as AgentInstanceState, A as AgentFrameworkContext, n as LoopProfile, k as ILLMProvider } from './scriptDeploymentPipeline-B1q-UhrO.js';
2
- import { LanguageModel } from 'ai';
2
+ import { JSONValue, LanguageModel } from 'ai';
3
3
 
4
4
  /**
5
5
  * AgentToolLoop runner — convenience API for driving a full loop turn.
@@ -58,6 +58,30 @@ declare function registerBuiltinLoopProfiles(): void;
58
58
  * cohere, mistral, azure, bedrock, groq, ollama, openrouter, together, etc.
59
59
  */
60
60
 
61
+ interface FetchLLMChatRequest {
62
+ messages?: Array<{
63
+ role: string;
64
+ content: string;
65
+ }>;
66
+ model?: string;
67
+ stream?: boolean;
68
+ /** Legacy OpenAI-compatible spelling retained for host adapters. */
69
+ max_tokens?: number;
70
+ /** AI SDK spelling. Takes precedence over max_tokens. */
71
+ maxOutputTokens?: number;
72
+ temperature?: number;
73
+ topP?: number;
74
+ providerOptions?: Record<string, Record<string, JSONValue>>;
75
+ system?: string;
76
+ abortSignal?: AbortSignal;
77
+ }
78
+ declare function resolveFetchLLMCallSettings(body: FetchLLMChatRequest): {
79
+ maxOutputTokens: number | undefined;
80
+ temperature: number | undefined;
81
+ topP: number | undefined;
82
+ providerOptions: Record<string, Record<string, JSONValue>> | undefined;
83
+ abortSignal: AbortSignal | undefined;
84
+ };
61
85
  interface FetchLLMProviderConfig {
62
86
  /** Display name. */
63
87
  name: string;
@@ -88,4 +112,4 @@ interface FetchLLMProviderConfig {
88
112
  */
89
113
  declare function createFetchLLMProvider(config: FetchLLMProviderConfig): ILLMProvider;
90
114
 
91
- export { type FetchLLMProviderConfig as F, type RunAgentToolLoopTurnCallbacks as R, type RunAgentToolLoopTurnResult as a, getBuiltinLoopProfiles as b, createFetchLLMProvider as c, runAgentToolLoopTurn as d, registerBuiltinLoopProfiles as e, getBuiltinLoopProfile as g, resolveAgentToolLoopTerminalState as r };
115
+ export { type FetchLLMChatRequest as F, type RunAgentToolLoopTurnCallbacks as R, type RunAgentToolLoopTurnResult as a, getBuiltinLoopProfiles as b, createFetchLLMProvider as c, runAgentToolLoopTurn as d, type FetchLLMProviderConfig as e, registerBuiltinLoopProfiles as f, getBuiltinLoopProfile as g, resolveFetchLLMCallSettings as h, resolveAgentToolLoopTerminalState as r };
@@ -1,5 +1,5 @@
1
1
  import { i as AgentLoopStep, f as AgentLoopInput, e as AgentLoopGenerator, c as AgentInstanceState, A as AgentFrameworkContext, n as LoopProfile, k as ILLMProvider } from './scriptDeploymentPipeline-XJzQyYys.cjs';
2
- import { LanguageModel } from 'ai';
2
+ import { JSONValue, LanguageModel } from 'ai';
3
3
 
4
4
  /**
5
5
  * AgentToolLoop runner — convenience API for driving a full loop turn.
@@ -58,6 +58,30 @@ declare function registerBuiltinLoopProfiles(): void;
58
58
  * cohere, mistral, azure, bedrock, groq, ollama, openrouter, together, etc.
59
59
  */
60
60
 
61
+ interface FetchLLMChatRequest {
62
+ messages?: Array<{
63
+ role: string;
64
+ content: string;
65
+ }>;
66
+ model?: string;
67
+ stream?: boolean;
68
+ /** Legacy OpenAI-compatible spelling retained for host adapters. */
69
+ max_tokens?: number;
70
+ /** AI SDK spelling. Takes precedence over max_tokens. */
71
+ maxOutputTokens?: number;
72
+ temperature?: number;
73
+ topP?: number;
74
+ providerOptions?: Record<string, Record<string, JSONValue>>;
75
+ system?: string;
76
+ abortSignal?: AbortSignal;
77
+ }
78
+ declare function resolveFetchLLMCallSettings(body: FetchLLMChatRequest): {
79
+ maxOutputTokens: number | undefined;
80
+ temperature: number | undefined;
81
+ topP: number | undefined;
82
+ providerOptions: Record<string, Record<string, JSONValue>> | undefined;
83
+ abortSignal: AbortSignal | undefined;
84
+ };
61
85
  interface FetchLLMProviderConfig {
62
86
  /** Display name. */
63
87
  name: string;
@@ -88,4 +112,4 @@ interface FetchLLMProviderConfig {
88
112
  */
89
113
  declare function createFetchLLMProvider(config: FetchLLMProviderConfig): ILLMProvider;
90
114
 
91
- export { type FetchLLMProviderConfig as F, type RunAgentToolLoopTurnCallbacks as R, type RunAgentToolLoopTurnResult as a, getBuiltinLoopProfiles as b, createFetchLLMProvider as c, runAgentToolLoopTurn as d, registerBuiltinLoopProfiles as e, getBuiltinLoopProfile as g, resolveAgentToolLoopTerminalState as r };
115
+ export { type FetchLLMChatRequest as F, type RunAgentToolLoopTurnCallbacks as R, type RunAgentToolLoopTurnResult as a, getBuiltinLoopProfiles as b, createFetchLLMProvider as c, runAgentToolLoopTurn as d, type FetchLLMProviderConfig as e, registerBuiltinLoopProfiles as f, getBuiltinLoopProfile as g, resolveFetchLLMCallSettings as h, resolveAgentToolLoopTerminalState as r };
package/dist/index.cjs CHANGED
@@ -26919,6 +26919,7 @@ __export(src_exports, {
26919
26919
  resolveCategory: () => resolveCategory,
26920
26920
  resolveExternalWorkloadResources: () => resolveExternalWorkloadResources,
26921
26921
  resolveExternalWorkloadRuntime: () => resolveExternalWorkloadRuntime,
26922
+ resolveFetchLLMCallSettings: () => resolveFetchLLMCallSettings,
26922
26923
  resolvePromptPluginMap: () => resolvePromptPluginMap,
26923
26924
  resolveQuestionAnswer: () => resolveQuestionAnswer,
26924
26925
  restoreArtifactManagementState: () => restoreArtifactManagementState,
@@ -28478,6 +28479,15 @@ var PromptPreviewController = class {
28478
28479
 
28479
28480
  // src/llm/fetchProvider.ts
28480
28481
  var import_ai = require("ai");
28482
+ function resolveFetchLLMCallSettings(body) {
28483
+ return {
28484
+ maxOutputTokens: body.maxOutputTokens ?? body.max_tokens,
28485
+ temperature: body.temperature,
28486
+ topP: body.topP,
28487
+ providerOptions: body.providerOptions,
28488
+ abortSignal: body.abortSignal
28489
+ };
28490
+ }
28481
28491
  function createFetchLLMProvider(config) {
28482
28492
  return {
28483
28493
  name: config.name,
@@ -28502,9 +28512,7 @@ function createFetchLLMProvider(config) {
28502
28512
  };
28503
28513
  });
28504
28514
  const system = body.system ?? (systemMessages.length > 0 ? systemMessages.join("\n\n") : void 0);
28505
- const temperature = body.temperature;
28506
- const abortSignal = body.abortSignal;
28507
- const maxOutputTokens = body.max_tokens;
28515
+ const { abortSignal, maxOutputTokens, providerOptions, temperature, topP } = resolveFetchLLMCallSettings(body);
28508
28516
  if (body.stream !== false) {
28509
28517
  let streamingError;
28510
28518
  const result2 = (0, import_ai.streamText)({
@@ -28513,6 +28521,8 @@ function createFetchLLMProvider(config) {
28513
28521
  messages,
28514
28522
  maxOutputTokens,
28515
28523
  temperature,
28524
+ topP,
28525
+ providerOptions,
28516
28526
  abortSignal,
28517
28527
  onError: ({ error: error2 }) => {
28518
28528
  streamingError = error2;
@@ -28533,6 +28543,8 @@ function createFetchLLMProvider(config) {
28533
28543
  messages,
28534
28544
  maxOutputTokens,
28535
28545
  temperature,
28546
+ topP,
28547
+ providerOptions,
28536
28548
  abortSignal
28537
28549
  });
28538
28550
  return result.text;
@@ -32192,6 +32204,7 @@ function getToolDefinition(toolId) {
32192
32204
  resolveCategory,
32193
32205
  resolveExternalWorkloadResources,
32194
32206
  resolveExternalWorkloadRuntime,
32207
+ resolveFetchLLMCallSettings,
32195
32208
  resolvePromptPluginMap,
32196
32209
  resolveQuestionAnswer,
32197
32210
  restoreArtifactManagementState,