@inkeep/agents-core 0.48.3 → 0.48.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.
@@ -0,0 +1,117 @@
1
+ //#region src/utils/mock-provider.ts
2
+ function extractLastUserMessage(prompt) {
3
+ for (let i = prompt.length - 1; i >= 0; i--) {
4
+ const msg = prompt[i];
5
+ if (msg.role === "user") {
6
+ for (const part of msg.content) if (part.type === "text") return part.text.length > 200 ? `${part.text.slice(0, 200)}...` : part.text;
7
+ }
8
+ }
9
+ return "(no user message)";
10
+ }
11
+ function countInputChars(prompt) {
12
+ let chars = 0;
13
+ for (const msg of prompt) if ("content" in msg) {
14
+ if (typeof msg.content === "string") chars += msg.content.length;
15
+ else if (Array.isArray(msg.content)) {
16
+ for (const part of msg.content) if ("text" in part) chars += part.text.length;
17
+ }
18
+ }
19
+ return chars;
20
+ }
21
+ function buildMockResponse(modelName, prompt) {
22
+ const lastUserMessage = extractLastUserMessage(prompt);
23
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
24
+ return [
25
+ "Mock response.",
26
+ `Model: mock/${modelName}`,
27
+ `Input messages: ${prompt.length}`,
28
+ `Last user message: "${lastUserMessage}"`,
29
+ `Timestamp: ${timestamp}`
30
+ ].join("\n");
31
+ }
32
+ var MockLanguageModel = class {
33
+ specificationVersion = "v2";
34
+ defaultObjectGenerationMode = void 0;
35
+ supportsImageUrls = false;
36
+ supportedUrls = {};
37
+ provider = "mock";
38
+ modelId;
39
+ constructor(modelId) {
40
+ this.modelId = modelId;
41
+ }
42
+ async doGenerate(options) {
43
+ const responseText = buildMockResponse(this.modelId, options.prompt);
44
+ const inputTokens = Math.ceil(countInputChars(options.prompt) / 4);
45
+ const outputTokens = Math.ceil(responseText.length / 4);
46
+ return {
47
+ content: [{
48
+ type: "text",
49
+ text: responseText
50
+ }],
51
+ finishReason: "stop",
52
+ usage: {
53
+ inputTokens,
54
+ outputTokens,
55
+ totalTokens: inputTokens + outputTokens
56
+ },
57
+ rawCall: {
58
+ rawPrompt: options.prompt,
59
+ rawSettings: {}
60
+ },
61
+ warnings: []
62
+ };
63
+ }
64
+ async doStream(options) {
65
+ const responseText = buildMockResponse(this.modelId, options.prompt);
66
+ const lines = responseText.split("\n");
67
+ const inputTokens = Math.ceil(countInputChars(options.prompt) / 4);
68
+ const outputTokens = Math.ceil(responseText.length / 4);
69
+ return {
70
+ stream: new ReadableStream({ async start(controller) {
71
+ controller.enqueue({
72
+ type: "stream-start",
73
+ warnings: []
74
+ });
75
+ const textId = "mock-text-0";
76
+ controller.enqueue({
77
+ type: "text-start",
78
+ id: textId
79
+ });
80
+ for (let i = 0; i < lines.length; i++) {
81
+ const delta = i < lines.length - 1 ? `${lines[i]}\n` : lines[i];
82
+ controller.enqueue({
83
+ type: "text-delta",
84
+ id: textId,
85
+ delta
86
+ });
87
+ if (i < lines.length - 1) await new Promise((resolve) => setTimeout(resolve, 5));
88
+ }
89
+ controller.enqueue({
90
+ type: "text-end",
91
+ id: textId
92
+ });
93
+ controller.enqueue({
94
+ type: "finish",
95
+ finishReason: "stop",
96
+ usage: {
97
+ inputTokens,
98
+ outputTokens,
99
+ totalTokens: inputTokens + outputTokens
100
+ }
101
+ });
102
+ controller.close();
103
+ } }),
104
+ rawCall: {
105
+ rawPrompt: options.prompt,
106
+ rawSettings: {}
107
+ },
108
+ warnings: []
109
+ };
110
+ }
111
+ };
112
+ function createMockModel(modelId) {
113
+ return new MockLanguageModel(modelId);
114
+ }
115
+
116
+ //#endregion
117
+ export { MockLanguageModel, createMockModel };
@@ -1,4 +1,5 @@
1
1
  import { getLogger } from "./logger.js";
2
+ import { createMockModel } from "./mock-provider.js";
2
3
  import { anthropic, createAnthropic } from "@ai-sdk/anthropic";
3
4
  import { createAzure } from "@ai-sdk/azure";
4
5
  import { createGateway, gateway } from "@ai-sdk/gateway";
@@ -97,7 +98,7 @@ var ModelFactory = class ModelFactory {
97
98
  hasProviderOptions: !!modelSettings.providerOptions
98
99
  }, "Creating language model from config");
99
100
  const providerConfig = ModelFactory.extractProviderConfig(modelSettings.providerOptions);
100
- if (provider === "azure" || Object.keys(providerConfig).length > 0) {
101
+ if (provider !== "mock" && (provider === "azure" || Object.keys(providerConfig).length > 0)) {
101
102
  logger.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
102
103
  return ModelFactory.createProvider(provider, providerConfig).languageModel(modelName);
103
104
  }
@@ -108,6 +109,7 @@ var ModelFactory = class ModelFactory {
108
109
  case "openrouter": return openrouter(modelName);
109
110
  case "gateway": return gateway(modelName);
110
111
  case "nim": return nimDefault(modelName);
112
+ case "mock": return createMockModel(modelName);
111
113
  case "custom": throw new Error("Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL");
112
114
  default: throw new Error(`Unsupported provider: ${provider}. Supported providers are: ${ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`);
113
115
  }
@@ -123,7 +125,8 @@ var ModelFactory = class ModelFactory {
123
125
  "openrouter",
124
126
  "gateway",
125
127
  "nim",
126
- "custom"
128
+ "custom",
129
+ "mock"
127
130
  ];
128
131
  /**
129
132
  * Parse model string to extract provider and model name
@@ -1,10 +1,10 @@
1
1
  import { z } from "@hono/zod-openapi";
2
- import * as drizzle_zod361 from "drizzle-zod";
2
+ import * as drizzle_zod0 from "drizzle-zod";
3
3
  import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
4
4
 
5
5
  //#region src/validation/drizzle-schema-helpers.d.ts
6
- declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod361.BuildSchema<"select", T["_"]["columns"], drizzle_zod361.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
- declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod361.BuildSchema<"insert", T["_"]["columns"], drizzle_zod361.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
6
+ declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod0.BuildSchema<"select", T["_"]["columns"], drizzle_zod0.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
+ declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod0.BuildSchema<"insert", T["_"]["columns"], drizzle_zod0.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
8
8
  declare const createSelectSchema: typeof createSelectSchemaWithModifiers;
9
9
  declare const createInsertSchema: typeof createInsertSchemaWithModifiers;
10
10
  /**