veryfront 0.1.458 → 0.1.460
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.d.ts +1 -24
- package/esm/deno.js +2 -25
- package/esm/src/agent/hosted-chat-preparation.d.ts +37 -1
- package/esm/src/agent/hosted-chat-preparation.d.ts.map +1 -1
- package/esm/src/agent/hosted-chat-preparation.js +46 -0
- package/esm/src/agent/hosted-service-auth.d.ts +64 -0
- package/esm/src/agent/hosted-service-auth.d.ts.map +1 -0
- package/esm/src/agent/hosted-service-auth.js +270 -0
- package/esm/src/agent/index.d.ts +2 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +2 -1
- 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 +2 -25
- package/src/src/agent/hosted-chat-preparation.ts +130 -0
- package/src/src/agent/hosted-service-auth.ts +397 -0
- package/src/src/agent/index.ts +23 -0
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ declare namespace _default {
|
|
|
128
128
|
"veryfront/extensions/bundler": string;
|
|
129
129
|
"veryfront/extensions/contracts": string;
|
|
130
130
|
"veryfront/extensions/interfaces": string;
|
|
131
|
+
jose: string;
|
|
131
132
|
"#veryfront": string;
|
|
132
133
|
"#veryfront/agent": string;
|
|
133
134
|
"#veryfront/agent/react": string;
|
|
@@ -247,37 +248,13 @@ declare namespace _default {
|
|
|
247
248
|
"@mdx-js/mdx": string;
|
|
248
249
|
"@mdx-js/react": string;
|
|
249
250
|
"@babel/parser": string;
|
|
250
|
-
"unist-util-visit": string;
|
|
251
|
-
"mdast-util-to-string": string;
|
|
252
|
-
"github-slugger": string;
|
|
253
|
-
"remark-parse": string;
|
|
254
|
-
"remark-gfm": string;
|
|
255
|
-
"remark-frontmatter": string;
|
|
256
|
-
"remark-rehype": string;
|
|
257
|
-
"rehype-highlight": string;
|
|
258
|
-
"rehype-starry-night": string;
|
|
259
|
-
"rehype-slug": string;
|
|
260
|
-
"rehype-raw": string;
|
|
261
|
-
"rehype-sanitize": string;
|
|
262
|
-
"rehype-stringify": string;
|
|
263
251
|
"gray-matter": string;
|
|
264
252
|
zod: string;
|
|
265
|
-
mdast: string;
|
|
266
|
-
hast: string;
|
|
267
|
-
unist: string;
|
|
268
253
|
unified: string;
|
|
269
|
-
vfile: string;
|
|
270
254
|
tailwindcss: string;
|
|
271
255
|
"tailwindcss/plugin": string;
|
|
272
256
|
"tailwindcss/defaultTheme": string;
|
|
273
257
|
"tailwindcss/colors": string;
|
|
274
|
-
"@opentelemetry/api": string;
|
|
275
|
-
"@opentelemetry/core": string;
|
|
276
|
-
"@opentelemetry/context-async-hooks": string;
|
|
277
|
-
"@opentelemetry/sdk-trace-base": string;
|
|
278
|
-
"@opentelemetry/exporter-trace-otlp-http": string;
|
|
279
|
-
"@opentelemetry/resources": string;
|
|
280
|
-
"@opentelemetry/semantic-conventions": string;
|
|
281
258
|
"class-variance-authority": string;
|
|
282
259
|
"tailwind-merge": string;
|
|
283
260
|
"veryfront/chat/conversation": string;
|
package/esm/deno.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.460",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"nodeModulesDir": "auto",
|
|
6
6
|
"workspace": [
|
|
@@ -151,6 +151,7 @@ export default {
|
|
|
151
151
|
"veryfront/extensions/bundler": "./src/extensions/bundler.ts",
|
|
152
152
|
"veryfront/extensions/contracts": "./src/extensions/contracts.ts",
|
|
153
153
|
"veryfront/extensions/interfaces": "./src/extensions/interfaces/index.ts",
|
|
154
|
+
"jose": "npm:jose@5.9.6",
|
|
154
155
|
"#veryfront": "./src/index.ts",
|
|
155
156
|
"#veryfront/agent": "./src/agent/index.ts",
|
|
156
157
|
"#veryfront/agent/react": "./src/agent/react/index.ts",
|
|
@@ -270,37 +271,13 @@ export default {
|
|
|
270
271
|
"@mdx-js/mdx": "npm:@mdx-js/mdx@3.1.1",
|
|
271
272
|
"@mdx-js/react": "npm:@mdx-js/react@3.1.1",
|
|
272
273
|
"@babel/parser": "npm:@babel/parser@7.29.2",
|
|
273
|
-
"unist-util-visit": "npm:unist-util-visit@5.1.0",
|
|
274
|
-
"mdast-util-to-string": "npm:mdast-util-to-string@4.0.0",
|
|
275
|
-
"github-slugger": "npm:github-slugger@2.0.0",
|
|
276
|
-
"remark-parse": "npm:remark-parse@11.0.0",
|
|
277
|
-
"remark-gfm": "npm:remark-gfm@4.0.1",
|
|
278
|
-
"remark-frontmatter": "npm:remark-frontmatter@5.0.0",
|
|
279
|
-
"remark-rehype": "npm:remark-rehype@11.1.2",
|
|
280
|
-
"rehype-highlight": "npm:rehype-highlight@7.0.2",
|
|
281
|
-
"rehype-starry-night": "npm:rehype-starry-night@2.2.0",
|
|
282
|
-
"rehype-slug": "npm:rehype-slug@6.0.0",
|
|
283
|
-
"rehype-raw": "npm:rehype-raw@7.0.0",
|
|
284
|
-
"rehype-sanitize": "npm:rehype-sanitize@6.0.0",
|
|
285
|
-
"rehype-stringify": "npm:rehype-stringify@10.0.1",
|
|
286
274
|
"gray-matter": "npm:gray-matter@4.0.3",
|
|
287
275
|
"zod": "npm:zod@4.3.6",
|
|
288
|
-
"mdast": "npm:@types/mdast@4.0.3",
|
|
289
|
-
"hast": "npm:@types/hast@3.0.3",
|
|
290
|
-
"unist": "npm:@types/unist@3.0.2",
|
|
291
276
|
"unified": "npm:unified@11.0.5",
|
|
292
|
-
"vfile": "npm:vfile@6.0.3",
|
|
293
277
|
"tailwindcss": "https://esm.sh/tailwindcss@4.2.2",
|
|
294
278
|
"tailwindcss/plugin": "https://esm.sh/tailwindcss@4.2.2/plugin",
|
|
295
279
|
"tailwindcss/defaultTheme": "https://esm.sh/tailwindcss@4.2.2/defaultTheme",
|
|
296
280
|
"tailwindcss/colors": "https://esm.sh/tailwindcss@4.2.2/colors",
|
|
297
|
-
"@opentelemetry/api": "npm:@opentelemetry/api@1.9.0",
|
|
298
|
-
"@opentelemetry/core": "npm:@opentelemetry/core@2.6.0",
|
|
299
|
-
"@opentelemetry/context-async-hooks": "npm:@opentelemetry/context-async-hooks@2.6.0",
|
|
300
|
-
"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@2.6.0",
|
|
301
|
-
"@opentelemetry/exporter-trace-otlp-http": "npm:@opentelemetry/exporter-trace-otlp-http@0.213.0",
|
|
302
|
-
"@opentelemetry/resources": "npm:@opentelemetry/resources@2.6.0",
|
|
303
|
-
"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@1.40.0",
|
|
304
281
|
"class-variance-authority": "npm:class-variance-authority@0.7.1",
|
|
305
282
|
"tailwind-merge": "npm:tailwind-merge@3.5.0",
|
|
306
283
|
"veryfront/chat/conversation": "./src/chat/conversation.ts",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ChatRequestContext, ChatSystemMessage, ChatUiMessage } from "../chat/types.js";
|
|
2
2
|
import type { AgentRuntimeMessage } from "./agent-runtime-message-adapter.js";
|
|
3
3
|
import type { ConversationRunEvent } from "./conversation-run-events.js";
|
|
4
|
-
import type { HostedChatRuntimeCreationOptions } from "./hosted-chat-runtime-contract.js";
|
|
4
|
+
import type { HostedChatRuntimeCreationOptions, HostedChatRuntimeCreationResult } from "./hosted-chat-runtime-contract.js";
|
|
5
5
|
import type { ParsedHostedChatRequest } from "./hosted-chat-request-parser.js";
|
|
6
|
+
import { type HostedConversationRootRunContext, type PrepareHostedConversationRootRunContextInput } from "./conversation-root-run-lifecycle.js";
|
|
6
7
|
import { type PrepareAgentRuntimeMessagesFromUiMessagesOptions } from "./runtime-message-preparation.js";
|
|
7
8
|
import type { RuntimeAgentThinkingConfig } from "./runtime-agent-definition.js";
|
|
8
9
|
import { type ResolvedHostedRuntimeRequestConfig } from "./hosted-runtime-request-config.js";
|
|
@@ -63,7 +64,42 @@ export type HostedChatRuntimeCreationPreparationResult<TRuntimeAgentDefinition>
|
|
|
63
64
|
};
|
|
64
65
|
runtimeConfig: ResolvedHostedRuntimeRequestConfig;
|
|
65
66
|
};
|
|
67
|
+
export type HostedChatExecutionPreparationRootRunOptions = Pick<PrepareHostedConversationRootRunContextInput, "implementationKind" | "persistLatestUserMessageOperation" | "missingUserMessageErrorMessage" | "onPersistLatestUserMessageFailure" | "instrumentation">;
|
|
68
|
+
export type HostedChatExecutionPreparationInput<TRuntimeAgentDefinition extends {
|
|
69
|
+
id: string;
|
|
70
|
+
model?: string;
|
|
71
|
+
thinking?: RuntimeAgentThinkingConfig;
|
|
72
|
+
maxSteps?: number;
|
|
73
|
+
}, TRuntimeResult extends HostedChatRuntimeCreationResult> = {
|
|
74
|
+
request: ParsedHostedChatRequest;
|
|
75
|
+
agentConfig: TRuntimeAgentDefinition;
|
|
76
|
+
apiUrl: string | URL;
|
|
77
|
+
abortSignal: AbortSignal;
|
|
78
|
+
rootRun?: HostedChatExecutionPreparationRootRunOptions;
|
|
79
|
+
resolveModelId: (modelId: string | undefined) => string | undefined;
|
|
80
|
+
resolveModelThinking?: (modelId: string | undefined) => RuntimeAgentThinkingConfig | undefined;
|
|
81
|
+
fetchSteering: (input: {
|
|
82
|
+
projectId: string | null;
|
|
83
|
+
authToken: string;
|
|
84
|
+
branchId?: string | null;
|
|
85
|
+
}) => Promise<HostedChatRuntimePreparationSteering>;
|
|
86
|
+
buildInstructions: (input: HostedChatRuntimeInstructionsInput<TRuntimeAgentDefinition>) => string | ChatSystemMessage[];
|
|
87
|
+
createRuntime: (options: HostedChatRuntimeCreationOptions<TRuntimeAgentDefinition, RuntimeAgentThinkingConfig>) => Promise<TRuntimeResult>;
|
|
88
|
+
};
|
|
89
|
+
export type HostedChatExecutionPreparationResult<TRuntimeAgentDefinition, TRuntimeResult extends HostedChatRuntimeCreationResult> = NormalizedHostedChatRequest & {
|
|
90
|
+
rootRunContext: HostedConversationRootRunContext;
|
|
91
|
+
runtime: TRuntimeResult;
|
|
92
|
+
finalMessages: AgentRuntimeMessage[];
|
|
93
|
+
steering: HostedChatRuntimeCreationPreparationResult<TRuntimeAgentDefinition>["steering"];
|
|
94
|
+
runtimeConfig: ResolvedHostedRuntimeRequestConfig;
|
|
95
|
+
};
|
|
66
96
|
export declare function normalizeParsedHostedChatRequest(request: ParsedHostedChatRequest): NormalizedHostedChatRequest;
|
|
67
97
|
export declare function prepareHostedChatRuntimeCreationOptions<TRuntimeAgentDefinition>(input: HostedChatRuntimeCreationPreparationInput<TRuntimeAgentDefinition>): Promise<HostedChatRuntimeCreationPreparationResult<TRuntimeAgentDefinition>>;
|
|
98
|
+
export declare function prepareHostedChatExecution<TRuntimeAgentDefinition extends {
|
|
99
|
+
id: string;
|
|
100
|
+
model?: string;
|
|
101
|
+
thinking?: RuntimeAgentThinkingConfig;
|
|
102
|
+
maxSteps?: number;
|
|
103
|
+
}, TRuntimeResult extends HostedChatRuntimeCreationResult>(input: HostedChatExecutionPreparationInput<TRuntimeAgentDefinition, TRuntimeResult>): Promise<HostedChatExecutionPreparationResult<TRuntimeAgentDefinition, TRuntimeResult>>;
|
|
68
104
|
export declare function prepareHostedChatRuntimeMessages(messages: readonly ChatUiMessage[], options?: PrepareHostedChatRuntimeMessagesOptions): Promise<AgentRuntimeMessage[]>;
|
|
69
105
|
//# sourceMappingURL=hosted-chat-preparation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-chat-preparation.d.ts","sourceRoot":"","sources":["../../../src/src/agent/hosted-chat-preparation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,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M,CAAC;CACnB,EACD,cAAc,SAAS,+BAA+B,EAEtD,KAAK,EAAE,mCAAmC,CACxC,uBAAuB,EACvB,cAAc,CACf,GACA,OAAO,CACR,oCAAoC,CAAC,uBAAuB,EAAE,cAAc,CAAC,CAC9E,CAmDA;AAED,wBAAsB,gCAAgC,CACpD,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,OAAO,GAAE,uCAA4C,GACpD,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAqBhC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareHostedConversationRootRunContext, } from "./conversation-root-run-lifecycle.js";
|
|
1
2
|
import { prepareAgentRuntimeMessagesFromUiMessages, } from "./runtime-message-preparation.js";
|
|
2
3
|
import { resolveHostedRuntimeRequestConfig, } from "./hosted-runtime-request-config.js";
|
|
3
4
|
import { getRuntimeUploadUrl } from "./runtime-upload-url-client.js";
|
|
@@ -88,6 +89,51 @@ export async function prepareHostedChatRuntimeCreationOptions(input) {
|
|
|
88
89
|
runtimeConfig,
|
|
89
90
|
};
|
|
90
91
|
}
|
|
92
|
+
export async function prepareHostedChatExecution(input) {
|
|
93
|
+
const normalized = normalizeParsedHostedChatRequest(input.request);
|
|
94
|
+
const rootRunContext = await prepareHostedConversationRootRunContext({
|
|
95
|
+
authToken: input.request.authToken,
|
|
96
|
+
apiUrl: input.apiUrl.toString(),
|
|
97
|
+
conversationId: input.request.conversationId,
|
|
98
|
+
projectId: input.request.projectId,
|
|
99
|
+
branchId: normalized.effectiveValidatedContext.branchId,
|
|
100
|
+
agentId: input.agentConfig.id,
|
|
101
|
+
messages: normalized.effectiveMessages,
|
|
102
|
+
parentRunId: input.request.parentRunId,
|
|
103
|
+
parentMessageId: normalized.parentMessageId,
|
|
104
|
+
providedRun: input.request.durableRootRun,
|
|
105
|
+
persistLatestUserMessageBeforeRun: input.request.persistLatestUserMessageBeforeDurableRun,
|
|
106
|
+
...input.rootRun,
|
|
107
|
+
}, { abortSignal: input.abortSignal });
|
|
108
|
+
const runtimePreparation = await prepareHostedChatRuntimeCreationOptions({
|
|
109
|
+
request: input.request,
|
|
110
|
+
agentConfig: input.agentConfig,
|
|
111
|
+
projectId: input.request.projectId,
|
|
112
|
+
authToken: input.request.authToken,
|
|
113
|
+
conversationId: input.request.conversationId,
|
|
114
|
+
branchId: normalized.effectiveValidatedContext.branchId,
|
|
115
|
+
environmentContext: normalized.effectiveValidatedContext.environmentContext,
|
|
116
|
+
rootRunContext,
|
|
117
|
+
resolveModelId: input.resolveModelId,
|
|
118
|
+
resolveModelThinking: input.resolveModelThinking,
|
|
119
|
+
fetchSteering: input.fetchSteering,
|
|
120
|
+
buildInstructions: input.buildInstructions,
|
|
121
|
+
});
|
|
122
|
+
const runtime = await input.createRuntime(runtimePreparation.creationOptions);
|
|
123
|
+
const finalMessages = await prepareHostedChatRuntimeMessages(normalized.effectiveMessages, {
|
|
124
|
+
authToken: input.request.authToken,
|
|
125
|
+
apiUrl: input.apiUrl,
|
|
126
|
+
projectId: input.request.projectId,
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
...normalized,
|
|
130
|
+
rootRunContext,
|
|
131
|
+
runtime,
|
|
132
|
+
finalMessages,
|
|
133
|
+
steering: runtimePreparation.steering,
|
|
134
|
+
runtimeConfig: runtimePreparation.runtimeConfig,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
91
137
|
export async function prepareHostedChatRuntimeMessages(messages, options = {}) {
|
|
92
138
|
if (!options.authToken || !options.apiUrl) {
|
|
93
139
|
return await prepareAgentRuntimeMessagesFromUiMessages({
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type HostedServiceAuthErrorCode = "UNAUTHENTICATED" | "FORBIDDEN" | "NOT_FOUND" | "SERVER_ERROR";
|
|
2
|
+
export declare class HostedServiceAuthError extends Error {
|
|
3
|
+
readonly statusCode: number;
|
|
4
|
+
readonly errorCode: HostedServiceAuthErrorCode;
|
|
5
|
+
constructor(statusCode: number, message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function isHostedServiceAuthError(error: unknown): error is HostedServiceAuthError;
|
|
8
|
+
export type HostedServiceAuthenticatedRequest = {
|
|
9
|
+
authToken: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
};
|
|
12
|
+
export type HostedServiceJwtError = {
|
|
13
|
+
statusCode: number;
|
|
14
|
+
errorCode: HostedServiceAuthErrorCode;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
export type HostedServiceJwtResult = {
|
|
18
|
+
success: true;
|
|
19
|
+
userId: string;
|
|
20
|
+
email: string;
|
|
21
|
+
token: string;
|
|
22
|
+
} | {
|
|
23
|
+
success: false;
|
|
24
|
+
error: HostedServiceJwtError;
|
|
25
|
+
};
|
|
26
|
+
export type HostedServiceProjectAccessError = {
|
|
27
|
+
statusCode: number;
|
|
28
|
+
errorCode: HostedServiceAuthErrorCode;
|
|
29
|
+
message: string;
|
|
30
|
+
};
|
|
31
|
+
export type HostedServiceProjectAccessResult = {
|
|
32
|
+
success: true;
|
|
33
|
+
projectId: string;
|
|
34
|
+
} | {
|
|
35
|
+
success: false;
|
|
36
|
+
error: HostedServiceProjectAccessError;
|
|
37
|
+
};
|
|
38
|
+
export type HostedServiceAuthConfig = {
|
|
39
|
+
OAUTH_PUBLIC_KEY?: string | null;
|
|
40
|
+
NODE_ENV?: string | null;
|
|
41
|
+
VERYFRONT_API_URL: string;
|
|
42
|
+
};
|
|
43
|
+
export type HostedServiceAuthLogger = {
|
|
44
|
+
debug?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
45
|
+
error?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
46
|
+
};
|
|
47
|
+
export type HostedServiceAuthTrace = <TResult>(operationName: string, operation: () => Promise<TResult>) => Promise<TResult>;
|
|
48
|
+
export type HostedServiceAuthFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
49
|
+
export type HostedServiceAuthOptions = {
|
|
50
|
+
getConfig: () => HostedServiceAuthConfig;
|
|
51
|
+
logger?: HostedServiceAuthLogger;
|
|
52
|
+
trace?: HostedServiceAuthTrace;
|
|
53
|
+
fetch?: HostedServiceAuthFetch;
|
|
54
|
+
projectAccessTimeoutMs?: number;
|
|
55
|
+
};
|
|
56
|
+
export type HostedServiceAuth = {
|
|
57
|
+
authenticateRequest: (request: Request) => Promise<HostedServiceAuthenticatedRequest | Response>;
|
|
58
|
+
getTokenFromRequest: typeof getHostedServiceTokenFromRequest;
|
|
59
|
+
verifyJwt: (token: string) => Promise<HostedServiceJwtResult>;
|
|
60
|
+
verifyProjectAccess: (projectId: string, token: string) => Promise<HostedServiceProjectAccessResult>;
|
|
61
|
+
};
|
|
62
|
+
export declare function getHostedServiceTokenFromRequest(request: Request): string | null;
|
|
63
|
+
export declare function createHostedServiceAuth(options: HostedServiceAuthOptions): HostedServiceAuth;
|
|
64
|
+
//# sourceMappingURL=hosted-service-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-service-auth.d.ts","sourceRoot":"","sources":["../../../src/src/agent/hosted-service-auth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAClC,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,cAAc,CAAC;AAEnB,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,0BAA0B,CAAC;gBAEnC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMhD;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,sBAAsB,CAEjC;AAED,MAAM,MAAM,iCAAiC,GAAG;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,0BAA0B,C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C,CAAC;AAEtB,MAAM,MAAM,sBAAsB,GAAG,CACnC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,MAAM,uBAAuB,CAAC;IACzC,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mBAAmB,EAAE,CACnB,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,iCAAiC,GAAG,QAAQ,CAAC,CAAC;IAC3D,mBAAmB,EAAE,OAAO,gCAAgC,CAAC;IAC7D,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC9D,mBAAmB,EAAE,CACnB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,gCAAgC,CAAC,CAAC;CAChD,CAAC;AA6BF,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAShF;AA8FD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CA4KnB"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { importSPKI, jwtVerify } from "jose";
|
|
2
|
+
export class HostedServiceAuthError extends Error {
|
|
3
|
+
statusCode;
|
|
4
|
+
errorCode;
|
|
5
|
+
constructor(statusCode, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "HostedServiceAuthError";
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.errorCode = statusCode === 401 ? "UNAUTHENTICATED" : "FORBIDDEN";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function isHostedServiceAuthError(error) {
|
|
13
|
+
return error instanceof HostedServiceAuthError;
|
|
14
|
+
}
|
|
15
|
+
let cachedPublicKeyInput;
|
|
16
|
+
let cachedPublicKeyPromise;
|
|
17
|
+
function defaultTrace(_operationName, operation) {
|
|
18
|
+
return operation();
|
|
19
|
+
}
|
|
20
|
+
function getFetch(options) {
|
|
21
|
+
return options.fetch ?? fetch;
|
|
22
|
+
}
|
|
23
|
+
function getProjectAccessTimeoutMs(options) {
|
|
24
|
+
return options.projectAccessTimeoutMs ?? 15_000;
|
|
25
|
+
}
|
|
26
|
+
function getPublicKey(publicKeyInput) {
|
|
27
|
+
if (cachedPublicKeyInput !== publicKeyInput || !cachedPublicKeyPromise) {
|
|
28
|
+
cachedPublicKeyInput = publicKeyInput;
|
|
29
|
+
cachedPublicKeyPromise = importSPKI(publicKeyInput, "RS256");
|
|
30
|
+
}
|
|
31
|
+
return cachedPublicKeyPromise;
|
|
32
|
+
}
|
|
33
|
+
export function getHostedServiceTokenFromRequest(request) {
|
|
34
|
+
const cookies = request.headers.get("cookie") || "";
|
|
35
|
+
const cookieMatch = cookies.match(/(?:^|;\s*)authToken=([^;]+)/);
|
|
36
|
+
if (cookieMatch?.[1])
|
|
37
|
+
return cookieMatch[1];
|
|
38
|
+
const authHeader = request.headers.get("authorization");
|
|
39
|
+
if (authHeader?.startsWith("Bearer "))
|
|
40
|
+
return authHeader.slice(7);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function makeUnauthenticatedError(message) {
|
|
44
|
+
return {
|
|
45
|
+
statusCode: 401,
|
|
46
|
+
errorCode: "UNAUTHENTICATED",
|
|
47
|
+
message,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function decodeBase64Url(input) {
|
|
51
|
+
const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
52
|
+
const paddingLength = (4 - (normalized.length % 4)) % 4;
|
|
53
|
+
const padded = `${normalized}${"=".repeat(paddingLength)}`;
|
|
54
|
+
if (typeof atob !== "function") {
|
|
55
|
+
throw new Error("Base64URL decoding is not available in this runtime");
|
|
56
|
+
}
|
|
57
|
+
const binary = atob(padded);
|
|
58
|
+
const bytes = new Uint8Array(binary.length);
|
|
59
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
60
|
+
bytes[index] = binary.charCodeAt(index);
|
|
61
|
+
}
|
|
62
|
+
return new TextDecoder().decode(bytes);
|
|
63
|
+
}
|
|
64
|
+
function isRecord(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
function parseJsonObject(json) {
|
|
68
|
+
const parsed = JSON.parse(json);
|
|
69
|
+
return isRecord(parsed) ? parsed : null;
|
|
70
|
+
}
|
|
71
|
+
function decodeHostedServiceJwtWithoutVerify(token) {
|
|
72
|
+
try {
|
|
73
|
+
const parts = token.split(".");
|
|
74
|
+
if (parts.length !== 3) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
error: makeUnauthenticatedError("Invalid token format"),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const payloadPart = parts[1];
|
|
81
|
+
if (!payloadPart) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
error: makeUnauthenticatedError("Invalid token format"),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const payload = parseJsonObject(decodeBase64Url(payloadPart));
|
|
88
|
+
if (!payload) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: makeUnauthenticatedError("Invalid token"),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (typeof payload.exp === "number" && payload.exp * 1000 < Date.now()) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: makeUnauthenticatedError("Token expired"),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const userId = typeof payload.userId === "string" ? payload.userId : null;
|
|
101
|
+
if (!userId) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
error: makeUnauthenticatedError("Invalid token: missing userId"),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
success: true,
|
|
109
|
+
userId,
|
|
110
|
+
email: typeof payload.email === "string" ? payload.email : "",
|
|
111
|
+
token,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: makeUnauthenticatedError("Invalid token"),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function createHostedServiceAuth(options) {
|
|
122
|
+
const trace = options.trace ?? defaultTrace;
|
|
123
|
+
async function verifyJwt(token) {
|
|
124
|
+
return await trace("auth.verifyJwt", async () => {
|
|
125
|
+
if (!token) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: makeUnauthenticatedError("Authentication token required"),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const config = options.getConfig();
|
|
132
|
+
if (!config.OAUTH_PUBLIC_KEY) {
|
|
133
|
+
if (config.NODE_ENV === "production") {
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
error: {
|
|
137
|
+
statusCode: 500,
|
|
138
|
+
errorCode: "SERVER_ERROR",
|
|
139
|
+
message: "JWT public key not configured",
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return decodeHostedServiceJwtWithoutVerify(token);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const publicKey = await getPublicKey(config.OAUTH_PUBLIC_KEY);
|
|
147
|
+
const { payload } = await jwtVerify(token, publicKey, {
|
|
148
|
+
algorithms: ["RS256"],
|
|
149
|
+
});
|
|
150
|
+
const userId = typeof payload.userId === "string" ? payload.userId : null;
|
|
151
|
+
if (!userId) {
|
|
152
|
+
return {
|
|
153
|
+
success: false,
|
|
154
|
+
error: makeUnauthenticatedError("Invalid token: missing userId"),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
userId,
|
|
160
|
+
email: typeof payload.email === "string" ? payload.email : "",
|
|
161
|
+
token,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
options.logger?.debug?.("JWT verification failed", {
|
|
166
|
+
error: error instanceof Error ? error.message : String(error),
|
|
167
|
+
});
|
|
168
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
169
|
+
if (errorMessage.includes("expired")) {
|
|
170
|
+
return {
|
|
171
|
+
success: false,
|
|
172
|
+
error: makeUnauthenticatedError("Token expired"),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
success: false,
|
|
177
|
+
error: makeUnauthenticatedError("Invalid token"),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
async function authenticateRequest(request) {
|
|
183
|
+
const token = getHostedServiceTokenFromRequest(request);
|
|
184
|
+
if (!token) {
|
|
185
|
+
return Response.json({ errorCode: "UNAUTHENTICATED" }, { status: 401 });
|
|
186
|
+
}
|
|
187
|
+
const auth = await verifyJwt(token);
|
|
188
|
+
if (!auth.success) {
|
|
189
|
+
return Response.json({ errorCode: auth.error.errorCode }, { status: 401 });
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
authToken: auth.token,
|
|
193
|
+
userId: auth.userId,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function verifyProjectAccess(projectId, token) {
|
|
197
|
+
return await trace("auth.verifyProjectAccess", async () => {
|
|
198
|
+
const config = options.getConfig();
|
|
199
|
+
try {
|
|
200
|
+
const apiUrl = new URL(config.VERYFRONT_API_URL);
|
|
201
|
+
const restUrl = new URL(`/projects/${projectId}`, apiUrl.origin);
|
|
202
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
203
|
+
if (token) {
|
|
204
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
205
|
+
}
|
|
206
|
+
const response = await getFetch(options)(restUrl.toString(), {
|
|
207
|
+
method: "GET",
|
|
208
|
+
headers,
|
|
209
|
+
signal: AbortSignal.timeout(getProjectAccessTimeoutMs(options)),
|
|
210
|
+
});
|
|
211
|
+
if (response.status === 404) {
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
error: {
|
|
215
|
+
statusCode: 404,
|
|
216
|
+
errorCode: "NOT_FOUND",
|
|
217
|
+
message: "Project not found",
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (response.status === 401 || response.status === 403) {
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
error: {
|
|
225
|
+
statusCode: 403,
|
|
226
|
+
errorCode: "FORBIDDEN",
|
|
227
|
+
message: "No access to project",
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
if (!response.ok) {
|
|
232
|
+
const errorText = await response.text();
|
|
233
|
+
options.logger?.error?.("Project access check failed", {
|
|
234
|
+
error: errorText,
|
|
235
|
+
projectId,
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
success: false,
|
|
239
|
+
error: {
|
|
240
|
+
statusCode: 403,
|
|
241
|
+
errorCode: "FORBIDDEN",
|
|
242
|
+
message: "No access to project",
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
success: true,
|
|
248
|
+
projectId,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
options.logger?.error?.("Project access check failed", { error, projectId });
|
|
253
|
+
return {
|
|
254
|
+
success: false,
|
|
255
|
+
error: {
|
|
256
|
+
statusCode: 403,
|
|
257
|
+
errorCode: "FORBIDDEN",
|
|
258
|
+
message: "No access to project",
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
authenticateRequest,
|
|
266
|
+
getTokenFromRequest: getHostedServiceTokenFromRequest,
|
|
267
|
+
verifyJwt,
|
|
268
|
+
verifyProjectAccess,
|
|
269
|
+
};
|
|
270
|
+
}
|
package/esm/src/agent/index.d.ts
CHANGED
|
@@ -144,7 +144,7 @@ export { formatChildRunStreamPartError, isChildRunAbortError, throwIfChildRunAbo
|
|
|
144
144
|
export { type AgentRuntimeMessage, AgentRuntimeMessageConversionError, type AgentRuntimeMessagePart, convertAgentRuntimeMessagesToProviderMessages, convertProviderMessagesToAgentRuntimeMessages, createToolResultPart, getAgentRuntimeTextPart, getAgentRuntimeToolCallPart, getAgentRuntimeToolResultPart, } from "./agent-runtime-message-adapter.js";
|
|
145
145
|
export { resolveRuntimeMessageFileUrls, type RuntimeFileUrlResolver, type RuntimeFileUrlResolverInput, } from "./runtime-message-file-url-refresh.js";
|
|
146
146
|
export { prepareAgentRuntimeMessagesFromUiMessages, type PrepareAgentRuntimeMessagesFromUiMessagesOptions, } from "./runtime-message-preparation.js";
|
|
147
|
-
export { type HostedChatRuntimeCreationPreparationInput, type HostedChatRuntimeCreationPreparationResult, type HostedChatRuntimeInstructionsInput, type HostedChatRuntimePreparationRootRunContext, type HostedChatRuntimePreparationSteering, type NormalizedHostedChatRequest, normalizeParsedHostedChatRequest, prepareHostedChatRuntimeCreationOptions, prepareHostedChatRuntimeMessages, type PrepareHostedChatRuntimeMessagesOptions, } from "./hosted-chat-preparation.js";
|
|
147
|
+
export { type HostedChatExecutionPreparationInput, type HostedChatExecutionPreparationResult, type HostedChatExecutionPreparationRootRunOptions, type HostedChatRuntimeCreationPreparationInput, type HostedChatRuntimeCreationPreparationResult, type HostedChatRuntimeInstructionsInput, type HostedChatRuntimePreparationRootRunContext, type HostedChatRuntimePreparationSteering, type NormalizedHostedChatRequest, normalizeParsedHostedChatRequest, prepareHostedChatExecution, prepareHostedChatRuntimeCreationOptions, prepareHostedChatRuntimeMessages, type PrepareHostedChatRuntimeMessagesOptions, } from "./hosted-chat-preparation.js";
|
|
148
148
|
export { getRuntimeUploadUrl, type RuntimeUploadUrlClientOptions, type RuntimeUploadUrlFetch, type RuntimeUploadUrlOptions, } from "./runtime-upload-url-client.js";
|
|
149
149
|
export { type ChildRunExecutionBufferCleanupInput, type ChildRunExecutionResourceFinalizeInput, closeChildRunExecutionBuffers, finalizeChildRunExecutionResources, } from "./child-run-execution-cleanup.js";
|
|
150
150
|
export { createHostedChildPendingToolLifecycle, createHostedChildPendingToolLifecycleLogger, type HostedChildPendingToolCallPhase, type HostedChildPendingToolCallState, type HostedChildPendingToolLifecycleCloseLog, type HostedChildPendingToolLifecycleCloseReason, type HostedChildPendingToolLifecycleInput, type HostedChildPendingToolLifecycleLogContext, type HostedChildPendingToolLifecycleLogger, type HostedChildPendingToolLifecycleLogWriter, type HostedChildPendingToolLifecycleUnknownToolLog, } from "./hosted-child-pending-tool-lifecycle.js";
|
|
@@ -198,4 +198,5 @@ export { buildInputRequestLifecycleDataEvent, createInputRequest, createInputReq
|
|
|
198
198
|
export { type DurableHumanInputFlowResult, executeDurableHumanInputFlow, type ExecuteDurableHumanInputFlowOptions, type HumanInputField, type HumanInputFieldInput, HumanInputFieldSchema, type HumanInputOption, HumanInputOptionSchema, type HumanInputPendingRequest, HumanInputPendingRequestSchema, type HumanInputRequest, type HumanInputRequestInput, HumanInputRequestSchema, type HumanInputResult, HumanInputResultSchema, HumanInputResumeError, type HumanInputResumeValue, InvalidHumanInputResultError, waitForDurableHumanInputResolution, type WaitForDurableHumanInputResolutionOptions, waitForHumanInput, type WaitForHumanInputOptions, } from "./human-input.js";
|
|
199
199
|
export { type ChatHandlerBeforeStream, type ChatHandlerBeforeStreamContext, type ChatHandlerBeforeStreamResult, type ChatHandlerConfigWithAgent, type ChatHandlerMessageInput, type ChatHandlerOptions, createChatHandler, } from "./chat-handler.js";
|
|
200
200
|
export { AgentRuntime, getProviderToolProfile, type ProviderToolCompatOptions, type ProviderToolCompatProvider, type ProviderToolProfile, RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, type RunResumeSessionManagerOptions, type RunSessionStatus, sanitizeProviderToolSchema, selectProviderCompatibleToolNames, selectProviderCompatibleTools, type SubmitResumeValueOutcome, WaitConflictError, WaitNotPendingError, } from "./runtime/index.js";
|
|
201
|
+
export { createHostedServiceAuth, getHostedServiceTokenFromRequest, type HostedServiceAuth, type HostedServiceAuthConfig, type HostedServiceAuthenticatedRequest, HostedServiceAuthError, type HostedServiceAuthErrorCode, type HostedServiceAuthFetch, type HostedServiceAuthLogger, type HostedServiceAuthOptions, type HostedServiceAuthTrace, type HostedServiceJwtError, type HostedServiceJwtResult, type HostedServiceProjectAccessError, type HostedServiceProjectAccessResult, isHostedServiceAuthError, } from "./hosted-service-auth.js";
|
|
201
202
|
//# sourceMappingURL=index.d.ts.map
|