veryfront 0.1.478 → 0.1.480

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,194 @@
1
+ import { agent } from "./factory.js";
2
+ import {
3
+ type AgentServiceRoute,
4
+ type AgentServiceRuntime,
5
+ defineAgentService,
6
+ } from "./agent-service.js";
7
+ import {
8
+ createDetachedRunShutdownLifecycle,
9
+ createDetachedRunTracker,
10
+ type DetachedRunShutdownLifecycle,
11
+ type DetachedRunTracker,
12
+ } from "./detached-run-tracker.js";
13
+ import {
14
+ createHostedAgentServiceRouteSet,
15
+ type HostedAgentServiceActiveSpanAttributes,
16
+ type HostedAgentServiceDetachedCleanupInput,
17
+ type HostedAgentServiceDetachedExecutionInput,
18
+ type HostedAgentServiceRouteSet,
19
+ type HostedAgentServiceStreamExecutionInput,
20
+ } from "./hosted-agent-service-routes.js";
21
+ import {
22
+ createHostedServiceAuth,
23
+ type HostedServiceAuth,
24
+ type HostedServiceAuthConfig,
25
+ } from "./hosted-service-auth.js";
26
+ import type { ParsedHostedChatRequest } from "./hosted-chat-request-parser.js";
27
+ import type { AgUiResumeValue } from "./ag-ui-tool-shared.js";
28
+ import type { RuntimeAgentMarkdownDefinition } from "./runtime-agent-definition.js";
29
+ import {
30
+ type NodeAgentServiceServer,
31
+ startNodeAgentServiceServer,
32
+ } from "./agent-service-server.js";
33
+ import type { VeryfrontServiceServerLogger } from "../server/service-server.js";
34
+
35
+ export type HostedAgentServiceRuntimeConfig = HostedServiceAuthConfig & {
36
+ PORT: number;
37
+ ALLOWED_ORIGINS: string[];
38
+ };
39
+
40
+ export type HostedAgentServiceRuntimeLogger = VeryfrontServiceServerLogger & {
41
+ info(message: string, metadata?: Record<string, unknown>): void;
42
+ error(message: string, metadata?: Record<string, unknown>): void;
43
+ };
44
+
45
+ export type HostedAgentServiceRuntimeTrace = <TResult>(
46
+ operationName: string,
47
+ operation: () => Promise<TResult>,
48
+ ) => Promise<TResult>;
49
+
50
+ export type CreateHostedAgentServiceRuntimeOptions<
51
+ TExecution extends object,
52
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
53
+ > = {
54
+ serviceName: string;
55
+ getConfig: () => TConfig;
56
+ getAgentConfig: () => RuntimeAgentMarkdownDefinition;
57
+ forwardedConfigNamespace?: string;
58
+ logger: HostedAgentServiceRuntimeLogger;
59
+ trace?: HostedAgentServiceRuntimeTrace;
60
+ setActiveSpanAttributes?: (attributes: HostedAgentServiceActiveSpanAttributes) => void;
61
+ prepareExecution: (req: ParsedHostedChatRequest) => Promise<TExecution>;
62
+ streamExecutionToAgUiResponse: (
63
+ input: HostedAgentServiceStreamExecutionInput<TExecution>,
64
+ ) => Promise<Response> | Response;
65
+ startDetachedExecution: (
66
+ input: HostedAgentServiceDetachedExecutionInput<TExecution>,
67
+ ) => Promise<void>;
68
+ cleanupExecution?: (
69
+ input: HostedAgentServiceDetachedCleanupInput<TExecution>,
70
+ ) => Promise<void>;
71
+ tracker?: DetachedRunTracker<AgUiResumeValue>;
72
+ drainTimeoutMs?: number;
73
+ };
74
+
75
+ export type HostedAgentServiceRuntimeBundle<
76
+ TExecution extends object,
77
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
78
+ > = {
79
+ config: TConfig;
80
+ tracker: DetachedRunTracker<AgUiResumeValue>;
81
+ auth: HostedServiceAuth;
82
+ routeSet: HostedAgentServiceRouteSet<TExecution>;
83
+ routes: AgentServiceRoute[];
84
+ lifecycle: DetachedRunShutdownLifecycle;
85
+ runtime: AgentServiceRuntime;
86
+ };
87
+
88
+ export type StartNodeHostedAgentServiceOptions<
89
+ TExecution extends object,
90
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
91
+ > = CreateHostedAgentServiceRuntimeOptions<TExecution, TConfig> & {
92
+ bindAddress?: string;
93
+ hardShutdownTimeoutMs?: number;
94
+ signals?: readonly NodeJS.Signals[];
95
+ };
96
+
97
+ export type StartNodeHostedAgentServiceResult<
98
+ TExecution extends object,
99
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
100
+ > = HostedAgentServiceRuntimeBundle<TExecution, TConfig> & {
101
+ nodeServer: NodeAgentServiceServer;
102
+ };
103
+
104
+ function defaultTrace<TResult>(
105
+ _operationName: string,
106
+ operation: () => Promise<TResult>,
107
+ ): Promise<TResult> {
108
+ return operation();
109
+ }
110
+
111
+ export function createHostedAgentServiceRuntime<
112
+ TExecution extends object,
113
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
114
+ >(
115
+ options: CreateHostedAgentServiceRuntimeOptions<TExecution, TConfig>,
116
+ ): HostedAgentServiceRuntimeBundle<TExecution, TConfig> {
117
+ const config = options.getConfig();
118
+ const tracker = options.tracker ?? createDetachedRunTracker<AgUiResumeValue>();
119
+ const trace = options.trace ?? defaultTrace;
120
+ const auth = createHostedServiceAuth({
121
+ getConfig: options.getConfig,
122
+ logger: options.logger,
123
+ trace,
124
+ });
125
+ const routeSet = createHostedAgentServiceRouteSet({
126
+ forwardedConfigNamespace: options.forwardedConfigNamespace,
127
+ authenticateRequest: auth.authenticateRequest,
128
+ verifyProjectAccess: (projectId, authToken) => auth.verifyProjectAccess(projectId, authToken),
129
+ tracker,
130
+ prepareExecution: options.prepareExecution,
131
+ streamExecutionToAgUiResponse: options.streamExecutionToAgUiResponse,
132
+ startDetachedExecution: options.startDetachedExecution,
133
+ cleanupExecution: options.cleanupExecution,
134
+ setActiveSpanAttributes: options.setActiveSpanAttributes,
135
+ trace,
136
+ logger: options.logger,
137
+ });
138
+ const agentConfig = options.getAgentConfig();
139
+ const service = defineAgentService({
140
+ serviceName: options.serviceName,
141
+ agent: agent({
142
+ id: agentConfig.id,
143
+ system: agentConfig.instructions,
144
+ model: agentConfig.model,
145
+ maxSteps: agentConfig.maxSteps,
146
+ }),
147
+ server: {
148
+ port: config.PORT,
149
+ cors: {
150
+ origins: config.ALLOWED_ORIGINS,
151
+ credentials: true,
152
+ },
153
+ },
154
+ });
155
+ const routes = routeSet.routes;
156
+
157
+ return {
158
+ config,
159
+ tracker,
160
+ auth,
161
+ routeSet,
162
+ routes,
163
+ lifecycle: createDetachedRunShutdownLifecycle({
164
+ tracker,
165
+ logger: options.logger,
166
+ drainTimeoutMs: options.drainTimeoutMs,
167
+ }),
168
+ runtime: service.createRuntime({ routes }),
169
+ };
170
+ }
171
+
172
+ export async function startNodeHostedAgentService<
173
+ TExecution extends object,
174
+ TConfig extends HostedAgentServiceRuntimeConfig = HostedAgentServiceRuntimeConfig,
175
+ >(
176
+ options: StartNodeHostedAgentServiceOptions<TExecution, TConfig>,
177
+ ): Promise<StartNodeHostedAgentServiceResult<TExecution, TConfig>> {
178
+ const bundle = createHostedAgentServiceRuntime(options);
179
+ const nodeServer = await startNodeAgentServiceServer({
180
+ runtime: bundle.runtime,
181
+ serviceName: options.serviceName,
182
+ lifecycle: bundle.lifecycle,
183
+ port: bundle.config.PORT,
184
+ bindAddress: options.bindAddress,
185
+ signals: options.signals,
186
+ logger: options.logger,
187
+ hardShutdownTimeoutMs: options.hardShutdownTimeoutMs,
188
+ });
189
+
190
+ return {
191
+ ...bundle,
192
+ nodeServer,
193
+ };
194
+ }
@@ -243,6 +243,17 @@ export {
243
243
  startNodeAgentServiceServer,
244
244
  type StartNodeAgentServiceServerOptions,
245
245
  } from "./agent-service-server.js";
246
+ export {
247
+ createHostedAgentServiceRuntime,
248
+ type CreateHostedAgentServiceRuntimeOptions,
249
+ type HostedAgentServiceRuntimeBundle,
250
+ type HostedAgentServiceRuntimeConfig,
251
+ type HostedAgentServiceRuntimeLogger,
252
+ type HostedAgentServiceRuntimeTrace,
253
+ startNodeHostedAgentService,
254
+ type StartNodeHostedAgentServiceOptions,
255
+ type StartNodeHostedAgentServiceResult,
256
+ } from "./hosted-agent-service-runtime.js";
246
257
  export {
247
258
  type AgentServiceBootstrapExit,
248
259
  type AgentServiceTraceContext,
@@ -811,6 +822,21 @@ export {
811
822
  type CreateHostedChildInvokeToolOptions,
812
823
  type HostedChildInvokeFailure,
813
824
  } from "./hosted-child-invoke-tool.js";
825
+ export {
826
+ createDefaultHostedInvokeAgentTool,
827
+ type DefaultHostedInvokeAgentConfig,
828
+ type DefaultHostedInvokeAgentContext,
829
+ type DefaultHostedInvokeAgentInput,
830
+ defaultHostedInvokeAgentInputSchema,
831
+ type DefaultHostedInvokeAgentLogger,
832
+ type DefaultHostedInvokeAgentProjectRefresh,
833
+ defaultHostedInvokeAgentSelectionSchema,
834
+ type DefaultHostedInvokeAgentToolOptions,
835
+ type DefaultHostedInvokeAgentToolResult,
836
+ type DefaultHostedInvokeAgentTrace,
837
+ type DefaultHostedInvokeAgentTraceAttributes,
838
+ executeDefaultHostedInvokeAgentTool,
839
+ } from "./default-hosted-invoke-agent-tool.js";
814
840
  export {
815
841
  buildDefaultHostedChildForkToolSet,
816
842
  buildHostedChildToolDescription,
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.478";
3
+ export const VERSION = "0.1.480";