veryfront 0.1.321 → 0.1.323
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/esm/deno.js +1 -1
- package/esm/extensions/ext-jwt/src/index.d.ts +39 -0
- package/esm/extensions/ext-jwt/src/index.d.ts.map +1 -0
- package/esm/extensions/ext-jwt/src/index.js +103 -0
- package/esm/extensions/ext-openai/src/openai-provider.d.ts +29 -0
- package/esm/extensions/ext-openai/src/openai-provider.d.ts.map +1 -0
- package/esm/extensions/ext-openai/src/openai-provider.js +1095 -0
- package/esm/src/embedding/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/embedding/veryfront-cloud/provider.js +6 -1
- package/esm/src/provider/shared/index.d.ts +16 -0
- package/esm/src/provider/shared/index.d.ts.map +1 -0
- package/esm/src/provider/shared/index.js +18 -0
- package/esm/src/provider/veryfront-cloud/openai.d.ts +10 -0
- package/esm/src/provider/veryfront-cloud/openai.d.ts.map +1 -0
- package/esm/src/provider/veryfront-cloud/openai.js +18 -0
- package/esm/src/provider/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/provider/veryfront-cloud/provider.js +6 -1
- package/esm/src/proxy/main.js +3 -0
- package/esm/src/tool/host-tools.d.ts +15 -0
- package/esm/src/tool/host-tools.d.ts.map +1 -0
- package/esm/src/tool/host-tools.js +60 -0
- package/esm/src/tool/index.d.ts +2 -0
- package/esm/src/tool/index.d.ts.map +1 -1
- package/esm/src/tool/index.js +1 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +2 -1
- package/src/deno.js +1 -1
- package/src/extensions/ext-jwt/src/index.ts +173 -0
- package/src/extensions/ext-openai/src/openai-provider.ts +1481 -0
- package/src/src/embedding/veryfront-cloud/provider.ts +6 -3
- package/src/src/provider/shared/index.ts +62 -0
- package/src/src/provider/veryfront-cloud/openai.ts +34 -0
- package/src/src/provider/veryfront-cloud/provider.ts +6 -3
- package/src/src/proxy/main.ts +4 -0
- package/src/src/tool/host-tools.ts +92 -0
- package/src/src/tool/index.ts +2 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
parseVeryfrontCloudModelId,
|
|
8
8
|
requireVeryfrontCloudBootstrap,
|
|
9
9
|
} from "../../provider/veryfront-cloud/shared.js";
|
|
10
|
+
import { createVeryfrontCloudOpenAIEmbeddingModel } from "../../provider/veryfront-cloud/openai.js";
|
|
10
11
|
|
|
11
12
|
export function createVeryfrontCloudEmbeddingModel(modelId: string): EmbeddingRuntime {
|
|
12
13
|
const { provider, modelId: upstreamModelId } = parseVeryfrontCloudModelId(modelId, "embedding");
|
|
@@ -16,9 +17,11 @@ export function createVeryfrontCloudEmbeddingModel(modelId: string): EmbeddingRu
|
|
|
16
17
|
|
|
17
18
|
switch (provider) {
|
|
18
19
|
case "openai":
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return createVeryfrontCloudOpenAIEmbeddingModel(upstreamModelId, {
|
|
21
|
+
apiToken,
|
|
22
|
+
baseURL,
|
|
23
|
+
fetch,
|
|
24
|
+
});
|
|
22
25
|
|
|
23
26
|
case "google":
|
|
24
27
|
return createGoogleEmbeddingRuntime({
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared plumbing consumed by the `@veryfront/ext-*` provider extensions.
|
|
3
|
+
*
|
|
4
|
+
* This barrel is the stable public surface: implementations currently live
|
|
5
|
+
* in `runtime-loader.ts` and `runtime-loader/` subdirectory. Future PRs
|
|
6
|
+
* (post ext-anthropic / ext-google extraction) may move the implementations
|
|
7
|
+
* into this directory; extensions keep importing from here unchanged.
|
|
8
|
+
*
|
|
9
|
+
* @module provider/shared
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// URL builders
|
|
13
|
+
export {
|
|
14
|
+
getAnthropicMessagesUrl,
|
|
15
|
+
getGoogleEmbeddingUrl,
|
|
16
|
+
getGoogleGenerateContentUrl,
|
|
17
|
+
getGoogleStreamGenerateContentUrl,
|
|
18
|
+
getOpenAIChatCompletionsUrl,
|
|
19
|
+
getOpenAIEmbeddingUrl,
|
|
20
|
+
getOpenAIResponsesUrl,
|
|
21
|
+
} from "../runtime-loader/provider-endpoints.js";
|
|
22
|
+
|
|
23
|
+
// Request init builders
|
|
24
|
+
export {
|
|
25
|
+
createAnthropicRequestInit,
|
|
26
|
+
createGoogleRequestInit,
|
|
27
|
+
createOpenAIRequestInit,
|
|
28
|
+
} from "../runtime-loader/provider-request-init.js";
|
|
29
|
+
|
|
30
|
+
// Tool-input status transitions
|
|
31
|
+
export {
|
|
32
|
+
TOOL_INPUT_PENDING_THRESHOLD_MS,
|
|
33
|
+
withToolInputStatusTransitions,
|
|
34
|
+
} from "../runtime-loader/tool-input-status.js";
|
|
35
|
+
|
|
36
|
+
// Retry / error / HTTP plumbing (currently in runtime-loader.ts).
|
|
37
|
+
export {
|
|
38
|
+
buildProviderError,
|
|
39
|
+
createWarningCollector,
|
|
40
|
+
isNumberArray,
|
|
41
|
+
mergeUsage,
|
|
42
|
+
parseRetryAfterMs,
|
|
43
|
+
ProviderError,
|
|
44
|
+
ProviderOverloadedError,
|
|
45
|
+
ProviderQuotaError,
|
|
46
|
+
ProviderRateLimitError,
|
|
47
|
+
ProviderRequestError,
|
|
48
|
+
readProviderOptions,
|
|
49
|
+
readRecord,
|
|
50
|
+
readTextParts,
|
|
51
|
+
requestJson,
|
|
52
|
+
requestStream,
|
|
53
|
+
stringifyJsonValue,
|
|
54
|
+
toOpenAICompatibleMessages,
|
|
55
|
+
toOpenAICompatibleTools,
|
|
56
|
+
} from "../runtime-loader.js";
|
|
57
|
+
|
|
58
|
+
export type {
|
|
59
|
+
OpenAICompatibleChatMessage,
|
|
60
|
+
OpenAICompatibleChatRequest,
|
|
61
|
+
RuntimePromptMessage,
|
|
62
|
+
} from "../runtime-loader.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EmbeddingRuntime, ModelRuntime } from "../types.js";
|
|
2
|
+
import { OpenAIProvider } from "../../../extensions/ext-openai/src/openai-provider.js";
|
|
3
|
+
|
|
4
|
+
const openAIProvider = new OpenAIProvider();
|
|
5
|
+
|
|
6
|
+
interface VeryfrontCloudOpenAIConfig {
|
|
7
|
+
apiToken: string;
|
|
8
|
+
baseURL: string;
|
|
9
|
+
fetch: typeof globalThis.fetch;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createVeryfrontCloudOpenAIModel(
|
|
13
|
+
modelId: string,
|
|
14
|
+
config: VeryfrontCloudOpenAIConfig,
|
|
15
|
+
): ModelRuntime {
|
|
16
|
+
return openAIProvider.createModel(modelId, {
|
|
17
|
+
credential: config.apiToken,
|
|
18
|
+
baseURL: config.baseURL,
|
|
19
|
+
name: "veryfront-cloud",
|
|
20
|
+
fetch: config.fetch,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createVeryfrontCloudOpenAIEmbeddingModel(
|
|
25
|
+
modelId: string,
|
|
26
|
+
config: VeryfrontCloudOpenAIConfig,
|
|
27
|
+
): EmbeddingRuntime {
|
|
28
|
+
return openAIProvider.createEmbedding(modelId, {
|
|
29
|
+
credential: config.apiToken,
|
|
30
|
+
baseURL: config.baseURL,
|
|
31
|
+
name: "veryfront-cloud",
|
|
32
|
+
fetch: config.fetch,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
parseVeryfrontCloudModelId,
|
|
11
11
|
requireVeryfrontCloudBootstrap,
|
|
12
12
|
} from "./shared.js";
|
|
13
|
+
import { createVeryfrontCloudOpenAIModel } from "./openai.js";
|
|
13
14
|
|
|
14
15
|
export function createVeryfrontCloudModel(modelId: string): ModelRuntime {
|
|
15
16
|
const { provider, modelId: upstreamModelId } = parseVeryfrontCloudModelId(modelId, "language");
|
|
@@ -61,9 +62,11 @@ export function createVeryfrontCloudModel(modelId: string): ModelRuntime {
|
|
|
61
62
|
fetch,
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
return createVeryfrontCloudOpenAIModel(upstreamModelId, {
|
|
66
|
+
apiToken,
|
|
67
|
+
baseURL,
|
|
68
|
+
fetch,
|
|
69
|
+
});
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
default: {
|
package/src/src/proxy/main.ts
CHANGED
|
@@ -25,6 +25,8 @@ import * as dntShim from "../../_dnt.shims.js";
|
|
|
25
25
|
import { createProxyHandler, INTERNAL_PROXY_HEADERS, type ProxyConfig } from "./handler.js";
|
|
26
26
|
import { createCacheFromEnv } from "./cache/index.js";
|
|
27
27
|
import { isRetryableConnectionError } from "./retry.js";
|
|
28
|
+
import { register } from "../extensions/contracts.js";
|
|
29
|
+
import { createAuthProvider } from "../../extensions/ext-jwt/src/index.js";
|
|
28
30
|
import {
|
|
29
31
|
endSpan,
|
|
30
32
|
extractContext,
|
|
@@ -112,6 +114,8 @@ const VERYFRONT_SERVER_RETRY_DELAY_MS = parseInt(
|
|
|
112
114
|
getEnv("VERYFRONT_SERVER_RETRY_DELAY_MS") || String(DEFAULT_SERVER_RETRY_DELAY_MS),
|
|
113
115
|
);
|
|
114
116
|
|
|
117
|
+
register("AuthProvider", createAuthProvider({}));
|
|
118
|
+
|
|
115
119
|
// Initialize cache and proxy handler
|
|
116
120
|
const cache = await createCacheFromEnv();
|
|
117
121
|
const proxyHandler = createProxyHandler({
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { dynamicTool, tool } from "./factory.js";
|
|
4
|
+
import type { JsonSchema } from "./schema/json-schema.js";
|
|
5
|
+
import type { Tool, ToolConfig, ToolExecutionContext } from "./types.js";
|
|
6
|
+
|
|
7
|
+
export interface HostToolDefinition {
|
|
8
|
+
description: string;
|
|
9
|
+
inputSchema: z.ZodSchema<unknown>;
|
|
10
|
+
inputSchemaJson?: JsonSchema;
|
|
11
|
+
execute: (input: unknown, context: ToolExecutionContext) => Promise<unknown> | unknown;
|
|
12
|
+
mcp?: ToolConfig["mcp"];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface HostToolMaterializationOptions {
|
|
16
|
+
generateToolCallId?: (toolName: string) => string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
20
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isZodSchema(value: unknown): value is z.ZodSchema<unknown> {
|
|
24
|
+
if (!isRecord(value) || typeof value.parse !== "function") return false;
|
|
25
|
+
if (!isRecord(value._def)) return false;
|
|
26
|
+
return typeof value._def.typeName === "string" || typeof value._def.type === "string";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isHostToolDefinition(value: unknown): value is HostToolDefinition {
|
|
30
|
+
return (
|
|
31
|
+
isRecord(value) &&
|
|
32
|
+
typeof value.description === "string" &&
|
|
33
|
+
isZodSchema(value.inputSchema) &&
|
|
34
|
+
typeof value.execute === "function"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function defaultToolCallId(toolName: string): string {
|
|
39
|
+
return `${toolName}-${dntShim.crypto.randomUUID()}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeExecutionContext(
|
|
43
|
+
toolName: string,
|
|
44
|
+
context: ToolExecutionContext | undefined,
|
|
45
|
+
options: HostToolMaterializationOptions,
|
|
46
|
+
): ToolExecutionContext {
|
|
47
|
+
const toolCallId = typeof context?.toolCallId === "string" && context.toolCallId.length > 0
|
|
48
|
+
? context.toolCallId
|
|
49
|
+
: (options.generateToolCallId ?? defaultToolCallId)(toolName);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...(isRecord(context) ? context : {}),
|
|
53
|
+
toolCallId,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createToolsFromHostDefinitions(
|
|
58
|
+
definitions: Record<string, unknown>,
|
|
59
|
+
options: HostToolMaterializationOptions = {},
|
|
60
|
+
): Record<string, Tool<unknown, unknown>> {
|
|
61
|
+
const tools: Record<string, Tool<unknown, unknown>> = {};
|
|
62
|
+
|
|
63
|
+
for (const [toolName, definition] of Object.entries(definitions)) {
|
|
64
|
+
if (!isHostToolDefinition(definition)) continue;
|
|
65
|
+
|
|
66
|
+
const execute = async (input: unknown, context: ToolExecutionContext | undefined) =>
|
|
67
|
+
await definition.execute(input, normalizeExecutionContext(toolName, context, options));
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
tools[toolName] = definition.inputSchemaJson
|
|
71
|
+
? dynamicTool({
|
|
72
|
+
id: toolName,
|
|
73
|
+
description: definition.description,
|
|
74
|
+
inputSchema: definition.inputSchema,
|
|
75
|
+
inputSchemaJson: definition.inputSchemaJson,
|
|
76
|
+
execute,
|
|
77
|
+
mcp: definition.mcp,
|
|
78
|
+
})
|
|
79
|
+
: tool({
|
|
80
|
+
id: toolName,
|
|
81
|
+
description: definition.description,
|
|
82
|
+
inputSchema: definition.inputSchema,
|
|
83
|
+
execute,
|
|
84
|
+
mcp: definition.mcp,
|
|
85
|
+
});
|
|
86
|
+
} catch {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return tools;
|
|
92
|
+
}
|
package/src/src/tool/index.ts
CHANGED
|
@@ -60,6 +60,8 @@ export { createRemoteMCPToolSource } from "./remote-mcp.js";
|
|
|
60
60
|
export type { RemoteMCPToolSourceConfig } from "./remote-mcp.js";
|
|
61
61
|
export { createContext7ToolSource } from "./context7.js";
|
|
62
62
|
export type { Context7ToolSourceConfig } from "./context7.js";
|
|
63
|
+
export { createToolsFromHostDefinitions } from "./host-tools.js";
|
|
64
|
+
export type { HostToolDefinition, HostToolMaterializationOptions } from "./host-tools.js";
|
|
63
65
|
export {
|
|
64
66
|
createToolsFromRemoteDefinitions,
|
|
65
67
|
loadRemoteToolsFromSource,
|