veryfront 0.1.297 → 0.1.299
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/src/agent/agent-service.d.ts +19 -2
- package/esm/src/agent/agent-service.d.ts.map +1 -1
- package/esm/src/agent/agent-service.js +75 -5
- package/esm/src/provider/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/provider/veryfront-cloud/provider.js +10 -2
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/src/agent/agent-service.ts +119 -7
- package/src/src/provider/veryfront-cloud/provider.ts +10 -4
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
|
@@ -18,6 +18,16 @@ export interface AgentServiceServerConfig {
|
|
|
18
18
|
basePath?: string;
|
|
19
19
|
cors?: boolean;
|
|
20
20
|
}
|
|
21
|
+
export interface AgentServiceRoute {
|
|
22
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
23
|
+
path: string;
|
|
24
|
+
handler: (request: Request, params: Record<string, string>) => Promise<Response> | Response;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentServiceRuntime<TStartInput = void, TRun = unknown, TEvent = unknown, TTerminalState = unknown> {
|
|
27
|
+
readonly contract: NormalizedAgentServiceContract<TStartInput, TRun, TEvent, TTerminalState>;
|
|
28
|
+
fetch(request: Request): Promise<Response>;
|
|
29
|
+
setShuttingDown(shuttingDown?: boolean): void;
|
|
30
|
+
}
|
|
21
31
|
export type AgentRegistry = Record<string, Agent>;
|
|
22
32
|
export interface AgentServiceContractBase<TStartInput = void, TRun = unknown, TEvent = unknown, TTerminalState = unknown> {
|
|
23
33
|
serviceName: string;
|
|
@@ -55,10 +65,17 @@ export interface NormalizedAgentServiceContract<TStartInput = void, TRun = unkno
|
|
|
55
65
|
*/
|
|
56
66
|
export interface AgentServiceDefinition<TStartInput = void, TRun = unknown, TEvent = unknown, TTerminalState = unknown> {
|
|
57
67
|
contract: NormalizedAgentServiceContract<TStartInput, TRun, TEvent, TTerminalState>;
|
|
68
|
+
createRuntime(options?: {
|
|
69
|
+
routes?: AgentServiceRoute[];
|
|
70
|
+
}): AgentServiceRuntime<TStartInput, TRun, TEvent, TTerminalState>;
|
|
58
71
|
}
|
|
59
72
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
73
|
+
* Define a hosted agent service and expose a policy-neutral runtime shell.
|
|
74
|
+
*
|
|
75
|
+
* The first implementation slice owns contract normalization plus standard
|
|
76
|
+
* health/readiness behavior. Hosts pass product-specific routes explicitly so
|
|
77
|
+
* auth, observability, durable sinks, and AG-UI execution policy can keep
|
|
78
|
+
* migrating in smaller additive seams.
|
|
62
79
|
*/
|
|
63
80
|
export declare function defineAgentService<TStartInput = void, TRun = unknown, TEvent = unknown, TTerminalState = unknown>(contract: AgentContract<TStartInput, TRun, TEvent, TTerminalState>): AgentServiceDefinition<TStartInput, TRun, TEvent, TTerminalState>;
|
|
64
81
|
//# sourceMappingURL=agent-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-service.d.ts","sourceRoot":"","sources":["../../../src/src/agent/agent-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,cAAc,CAC7B,WAAW,GAAG,IAAI,EAClB,IAAI,GAAG,OAAO,EACd,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO;IAExB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnD,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAChE,WAAW,CAAC,GAAG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AAM,EAAE,cAAc,CAAC;IAC3E,MAAM,EAAE,aAAa,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CACrC,WAAW,GAAG,IAAI,EAClB,IAAI,GAAG,OAAO,EACd,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO;IAExB,QAAQ,EAAE,8BAA8B,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IACpF,aAAa,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAA;KAAE,GAAG,mBAAmB,CAC5E,WAAW,EACX,IAAI,EACJ,MAAM,EACN,cAAc,CACf,CAAC;CACH;AAwHD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,GAAG,IAAI,EAClB,IAAI,GAAG,OAAO,EACd,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EAExB,QAAQ,EAAE,aAAa,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,GACjE,sBAAsB,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,CAQnE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const DEFINE_AGENT_SERVICE_STUB_ERROR = "defineAgentService() is a Phase 0 stub. The framework contract is reserved, but the hosted runtime implementation has not landed yet.";
|
|
2
1
|
function getSingleAgentDefaultId(contract) {
|
|
3
2
|
return contract.defaultAgentId ?? contract.agent.id ?? "default";
|
|
4
3
|
}
|
|
@@ -21,11 +20,82 @@ function normalizeAgentServiceContract(contract) {
|
|
|
21
20
|
durableRunSink: contract.durableRunSink,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
23
|
+
function normalizePath(path) {
|
|
24
|
+
if (path === "")
|
|
25
|
+
return "/";
|
|
26
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
27
|
+
}
|
|
28
|
+
function splitPath(path) {
|
|
29
|
+
const normalized = normalizePath(path);
|
|
30
|
+
if (normalized === "/")
|
|
31
|
+
return [];
|
|
32
|
+
return normalized.split("/").filter(Boolean);
|
|
33
|
+
}
|
|
34
|
+
function matchRoute(route, request) {
|
|
35
|
+
if (request.method.toUpperCase() !== route.method) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const routeParts = splitPath(route.path);
|
|
39
|
+
const requestParts = splitPath(new URL(request.url).pathname);
|
|
40
|
+
if (routeParts.length !== requestParts.length) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const params = {};
|
|
44
|
+
for (const [index, routePart] of routeParts.entries()) {
|
|
45
|
+
const requestPart = requestParts[index];
|
|
46
|
+
if (requestPart === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (routePart.startsWith(":")) {
|
|
50
|
+
params[routePart.slice(1)] = decodeURIComponent(requestPart);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (routePart !== requestPart) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return params;
|
|
58
|
+
}
|
|
59
|
+
function createAgentServiceRuntime(contract, options = {}) {
|
|
60
|
+
let shuttingDown = false;
|
|
61
|
+
const routes = options.routes ?? [];
|
|
62
|
+
return {
|
|
63
|
+
contract,
|
|
64
|
+
async fetch(request) {
|
|
65
|
+
const path = new URL(request.url).pathname;
|
|
66
|
+
if (request.method === "GET" && path === "/readiness") {
|
|
67
|
+
return shuttingDown ? new Response("Shutting down", { status: 503 }) : new Response("OK");
|
|
68
|
+
}
|
|
69
|
+
if (request.method === "GET" && path === "/liveness") {
|
|
70
|
+
return new Response("OK");
|
|
71
|
+
}
|
|
72
|
+
for (const route of routes) {
|
|
73
|
+
const params = matchRoute(route, request);
|
|
74
|
+
if (params) {
|
|
75
|
+
return await route.handler(request, params);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new Response("Not Found", { status: 404 });
|
|
79
|
+
},
|
|
80
|
+
setShuttingDown(next = true) {
|
|
81
|
+
shuttingDown = next;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
24
85
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
86
|
+
* Define a hosted agent service and expose a policy-neutral runtime shell.
|
|
87
|
+
*
|
|
88
|
+
* The first implementation slice owns contract normalization plus standard
|
|
89
|
+
* health/readiness behavior. Hosts pass product-specific routes explicitly so
|
|
90
|
+
* auth, observability, durable sinks, and AG-UI execution policy can keep
|
|
91
|
+
* migrating in smaller additive seams.
|
|
27
92
|
*/
|
|
28
93
|
export function defineAgentService(contract) {
|
|
29
|
-
|
|
30
|
-
|
|
94
|
+
const normalized = normalizeAgentServiceContract(contract);
|
|
95
|
+
return {
|
|
96
|
+
contract: normalized,
|
|
97
|
+
createRuntime(options) {
|
|
98
|
+
return createAgentServiceRuntime(normalized, options);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
31
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/src/provider/veryfront-cloud/provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/src/provider/veryfront-cloud/provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAiEvE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createError, toError } from "../../errors/veryfront-error.js";
|
|
2
|
-
import { createGoogleModelRuntime } from "../runtime-loader.js";
|
|
2
|
+
import { createAnthropicModelRuntime, createGoogleModelRuntime } from "../runtime-loader.js";
|
|
3
3
|
import { tryResolve } from "../../extensions/contracts.js";
|
|
4
4
|
import { AIProviderRegistryName } from "../../extensions/interfaces/index.js";
|
|
5
5
|
import { createVeryfrontCloudFetch, getVeryfrontCloudGatewayBaseUrl, parseVeryfrontCloudModelId, requireVeryfrontCloudBootstrap, } from "./shared.js";
|
|
@@ -21,7 +21,15 @@ export function createVeryfrontCloudModel(modelId) {
|
|
|
21
21
|
fetch,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
// Fall back to the built-in runtime-loader when the extension is not
|
|
25
|
+
// registered. Keeps Anthropic working until @veryfront/ext-anthropic is
|
|
26
|
+
// published to npm and adopted by all consumers.
|
|
27
|
+
return createAnthropicModelRuntime({
|
|
28
|
+
authToken: apiToken,
|
|
29
|
+
baseURL,
|
|
30
|
+
name: "veryfront-cloud",
|
|
31
|
+
fetch,
|
|
32
|
+
}, upstreamModelId);
|
|
25
33
|
}
|
|
26
34
|
case "google":
|
|
27
35
|
return createGoogleModelRuntime({
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.299";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -26,6 +26,23 @@ export interface AgentServiceServerConfig {
|
|
|
26
26
|
cors?: boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export interface AgentServiceRoute {
|
|
30
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
31
|
+
path: string;
|
|
32
|
+
handler: (request: Request, params: Record<string, string>) => Promise<Response> | Response;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AgentServiceRuntime<
|
|
36
|
+
TStartInput = void,
|
|
37
|
+
TRun = unknown,
|
|
38
|
+
TEvent = unknown,
|
|
39
|
+
TTerminalState = unknown,
|
|
40
|
+
> {
|
|
41
|
+
readonly contract: NormalizedAgentServiceContract<TStartInput, TRun, TEvent, TTerminalState>;
|
|
42
|
+
fetch(request: Request): Promise<Response>;
|
|
43
|
+
setShuttingDown(shuttingDown?: boolean): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
export type AgentRegistry = Record<string, Agent>;
|
|
30
47
|
|
|
31
48
|
export interface AgentServiceContractBase<
|
|
@@ -101,11 +118,14 @@ export interface AgentServiceDefinition<
|
|
|
101
118
|
TTerminalState = unknown,
|
|
102
119
|
> {
|
|
103
120
|
contract: NormalizedAgentServiceContract<TStartInput, TRun, TEvent, TTerminalState>;
|
|
121
|
+
createRuntime(options?: { routes?: AgentServiceRoute[] }): AgentServiceRuntime<
|
|
122
|
+
TStartInput,
|
|
123
|
+
TRun,
|
|
124
|
+
TEvent,
|
|
125
|
+
TTerminalState
|
|
126
|
+
>;
|
|
104
127
|
}
|
|
105
128
|
|
|
106
|
-
const DEFINE_AGENT_SERVICE_STUB_ERROR =
|
|
107
|
-
"defineAgentService() is a Phase 0 stub. The framework contract is reserved, but the hosted runtime implementation has not landed yet.";
|
|
108
|
-
|
|
109
129
|
function getSingleAgentDefaultId(contract: {
|
|
110
130
|
agent: Agent;
|
|
111
131
|
defaultAgentId?: string;
|
|
@@ -141,9 +161,96 @@ function normalizeAgentServiceContract<
|
|
|
141
161
|
};
|
|
142
162
|
}
|
|
143
163
|
|
|
164
|
+
function normalizePath(path: string): string {
|
|
165
|
+
if (path === "") return "/";
|
|
166
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function splitPath(path: string): string[] {
|
|
170
|
+
const normalized = normalizePath(path);
|
|
171
|
+
if (normalized === "/") return [];
|
|
172
|
+
return normalized.split("/").filter(Boolean);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function matchRoute(
|
|
176
|
+
route: AgentServiceRoute,
|
|
177
|
+
request: Request,
|
|
178
|
+
): Record<string, string> | undefined {
|
|
179
|
+
if (request.method.toUpperCase() !== route.method) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const routeParts = splitPath(route.path);
|
|
184
|
+
const requestParts = splitPath(new URL(request.url).pathname);
|
|
185
|
+
if (routeParts.length !== requestParts.length) {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const params: Record<string, string> = {};
|
|
190
|
+
for (const [index, routePart] of routeParts.entries()) {
|
|
191
|
+
const requestPart = requestParts[index];
|
|
192
|
+
if (requestPart === undefined) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (routePart.startsWith(":")) {
|
|
197
|
+
params[routePart.slice(1)] = decodeURIComponent(requestPart);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (routePart !== requestPart) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return params;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function createAgentServiceRuntime<
|
|
210
|
+
TStartInput = void,
|
|
211
|
+
TRun = unknown,
|
|
212
|
+
TEvent = unknown,
|
|
213
|
+
TTerminalState = unknown,
|
|
214
|
+
>(
|
|
215
|
+
contract: NormalizedAgentServiceContract<TStartInput, TRun, TEvent, TTerminalState>,
|
|
216
|
+
options: { routes?: AgentServiceRoute[] } = {},
|
|
217
|
+
): AgentServiceRuntime<TStartInput, TRun, TEvent, TTerminalState> {
|
|
218
|
+
let shuttingDown = false;
|
|
219
|
+
const routes = options.routes ?? [];
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
contract,
|
|
223
|
+
async fetch(request) {
|
|
224
|
+
const path = new URL(request.url).pathname;
|
|
225
|
+
if (request.method === "GET" && path === "/readiness") {
|
|
226
|
+
return shuttingDown ? new Response("Shutting down", { status: 503 }) : new Response("OK");
|
|
227
|
+
}
|
|
228
|
+
if (request.method === "GET" && path === "/liveness") {
|
|
229
|
+
return new Response("OK");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (const route of routes) {
|
|
233
|
+
const params = matchRoute(route, request);
|
|
234
|
+
if (params) {
|
|
235
|
+
return await route.handler(request, params);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return new Response("Not Found", { status: 404 });
|
|
240
|
+
},
|
|
241
|
+
setShuttingDown(next = true) {
|
|
242
|
+
shuttingDown = next;
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
144
247
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
248
|
+
* Define a hosted agent service and expose a policy-neutral runtime shell.
|
|
249
|
+
*
|
|
250
|
+
* The first implementation slice owns contract normalization plus standard
|
|
251
|
+
* health/readiness behavior. Hosts pass product-specific routes explicitly so
|
|
252
|
+
* auth, observability, durable sinks, and AG-UI execution policy can keep
|
|
253
|
+
* migrating in smaller additive seams.
|
|
147
254
|
*/
|
|
148
255
|
export function defineAgentService<
|
|
149
256
|
TStartInput = void,
|
|
@@ -153,6 +260,11 @@ export function defineAgentService<
|
|
|
153
260
|
>(
|
|
154
261
|
contract: AgentContract<TStartInput, TRun, TEvent, TTerminalState>,
|
|
155
262
|
): AgentServiceDefinition<TStartInput, TRun, TEvent, TTerminalState> {
|
|
156
|
-
|
|
157
|
-
|
|
263
|
+
const normalized = normalizeAgentServiceContract(contract);
|
|
264
|
+
return {
|
|
265
|
+
contract: normalized,
|
|
266
|
+
createRuntime(options) {
|
|
267
|
+
return createAgentServiceRuntime(normalized, options);
|
|
268
|
+
},
|
|
269
|
+
};
|
|
158
270
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createError, toError } from "../../errors/veryfront-error.js";
|
|
2
|
-
import { createGoogleModelRuntime } from "../runtime-loader.js";
|
|
2
|
+
import { createAnthropicModelRuntime, createGoogleModelRuntime } from "../runtime-loader.js";
|
|
3
3
|
import { tryResolve } from "../../extensions/contracts.js";
|
|
4
4
|
import type { AIProviderRegistry } from "../../extensions/interfaces/index.js";
|
|
5
5
|
import { AIProviderRegistryName } from "../../extensions/interfaces/index.js";
|
|
@@ -30,9 +30,15 @@ export function createVeryfrontCloudModel(modelId: string): ModelRuntime {
|
|
|
30
30
|
fetch,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Fall back to the built-in runtime-loader when the extension is not
|
|
34
|
+
// registered. Keeps Anthropic working until @veryfront/ext-anthropic is
|
|
35
|
+
// published to npm and adopted by all consumers.
|
|
36
|
+
return createAnthropicModelRuntime({
|
|
37
|
+
authToken: apiToken,
|
|
38
|
+
baseURL,
|
|
39
|
+
name: "veryfront-cloud",
|
|
40
|
+
fetch,
|
|
41
|
+
}, upstreamModelId);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
case "google":
|