veryfront 0.1.132 → 0.1.136
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/cli/commands/build/handler.js +2 -0
- package/esm/cli/commands/deploy/command.d.ts.map +1 -1
- package/esm/cli/commands/deploy/command.js +2 -0
- package/esm/cli/commands/files/command.d.ts.map +1 -1
- package/esm/cli/commands/files/command.js +1 -0
- package/esm/cli/commands/uploads/command.d.ts.map +1 -1
- package/esm/cli/commands/uploads/command.js +1 -0
- package/esm/cli/help/tips.d.ts +3 -0
- package/esm/cli/help/tips.d.ts.map +1 -1
- package/esm/cli/help/tips.js +15 -1
- package/esm/cli/router.d.ts.map +1 -1
- package/esm/cli/router.js +4 -0
- package/esm/cli/shared/animation.d.ts +3 -0
- package/esm/cli/shared/animation.d.ts.map +1 -0
- package/esm/cli/shared/animation.js +23 -0
- package/esm/cli/templates/manifest.d.ts +6 -0
- package/esm/cli/templates/manifest.js +12 -6
- package/esm/cli/ui/progress.d.ts.map +1 -1
- package/esm/cli/ui/progress.js +13 -1
- package/esm/deno.js +1 -1
- package/esm/src/agent/index.d.ts +1 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/ai-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/ai-stream-handler.js +56 -5
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +4 -1
- package/esm/src/agent/runtime/model-tool-converter.d.ts +5 -1
- package/esm/src/agent/runtime/model-tool-converter.d.ts.map +1 -1
- package/esm/src/agent/runtime/model-tool-converter.js +35 -4
- package/esm/src/agent/types.d.ts +19 -0
- package/esm/src/agent/types.d.ts.map +1 -1
- package/esm/src/channels/control-plane.d.ts +67 -0
- package/esm/src/channels/control-plane.d.ts.map +1 -1
- package/esm/src/channels/control-plane.js +27 -0
- package/esm/src/discovery/handlers/tool-handler.d.ts.map +1 -1
- package/esm/src/discovery/handlers/tool-handler.js +12 -2
- package/esm/src/html/html-injection.d.ts +2 -0
- package/esm/src/html/html-injection.d.ts.map +1 -1
- package/esm/src/html/html-injection.js +4 -0
- package/esm/src/html/nonce-injection.d.ts +1 -0
- package/esm/src/html/nonce-injection.d.ts.map +1 -1
- package/esm/src/html/nonce-injection.js +147 -2
- package/esm/src/internal-agents/ag-ui-sse.d.ts +1 -0
- package/esm/src/internal-agents/ag-ui-sse.d.ts.map +1 -1
- package/esm/src/internal-agents/ag-ui-sse.js +18 -0
- package/esm/src/platform/adapters/fs/veryfront/proxy-manager.d.ts +1 -0
- package/esm/src/platform/adapters/fs/veryfront/proxy-manager.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/proxy-manager.js +15 -1
- package/esm/src/platform/adapters/fs/veryfront/types.d.ts +2 -0
- package/esm/src/platform/adapters/fs/veryfront/types.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager.js +2 -0
- package/esm/src/proxy/handler.d.ts.map +1 -1
- package/esm/src/proxy/handler.js +25 -5
- package/esm/src/react/components/Head.d.ts +9 -0
- package/esm/src/react/components/Head.d.ts.map +1 -1
- package/esm/src/react/components/Head.js +9 -0
- package/esm/src/react/context/index.d.ts +9 -0
- package/esm/src/react/context/index.d.ts.map +1 -1
- package/esm/src/react/context/index.js +9 -0
- package/esm/src/react/router/index.d.ts +9 -0
- package/esm/src/react/router/index.d.ts.map +1 -1
- package/esm/src/react/router/index.js +9 -0
- package/esm/src/rendering/orchestrator/html.d.ts +1 -0
- package/esm/src/rendering/orchestrator/html.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/html.js +83 -5
- package/esm/src/server/handlers/dev/framework-candidates.generated.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/framework-candidates.generated.js +9 -0
- package/esm/src/server/handlers/request/ssr/ssr-response-builder.d.ts.map +1 -1
- package/esm/src/server/handlers/request/ssr/ssr-response-builder.js +3 -7
- package/esm/src/tool/factory.d.ts.map +1 -1
- package/esm/src/tool/factory.js +14 -4
- package/esm/src/tool/types.d.ts +2 -0
- package/esm/src/tool/types.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/constants.d.ts +1 -0
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/constants.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/constants.js +3 -0
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.js +4 -2
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.d.ts +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.js +10 -9
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/path-resolver.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/path-resolver.js +3 -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/cli/commands/build/handler.ts +3 -0
- package/src/cli/commands/deploy/command.ts +3 -0
- package/src/cli/commands/files/command.ts +1 -0
- package/src/cli/commands/uploads/command.ts +3 -0
- package/src/cli/help/tips.ts +18 -1
- package/src/cli/router.ts +5 -0
- package/src/cli/shared/animation.ts +25 -0
- package/src/cli/templates/manifest.js +12 -6
- package/src/cli/ui/progress.ts +13 -1
- package/src/deno.js +1 -1
- package/src/src/agent/index.ts +2 -0
- package/src/src/agent/runtime/ai-stream-handler.ts +64 -6
- package/src/src/agent/runtime/index.ts +4 -1
- package/src/src/agent/runtime/model-tool-converter.ts +47 -3
- package/src/src/agent/types.ts +23 -0
- package/src/src/channels/control-plane.ts +31 -0
- package/src/src/discovery/handlers/tool-handler.ts +13 -2
- package/src/src/html/html-injection.ts +7 -0
- package/src/src/html/nonce-injection.ts +172 -1
- package/src/src/internal-agents/ag-ui-sse.ts +20 -0
- package/src/src/platform/adapters/fs/veryfront/proxy-manager.ts +29 -3
- package/src/src/platform/adapters/fs/veryfront/types.ts +2 -0
- package/src/src/platform/adapters/fs/veryfront/websocket-manager.ts +2 -0
- package/src/src/proxy/handler.ts +43 -5
- package/src/src/react/components/Head.tsx +10 -0
- package/src/src/react/context/index.tsx +10 -0
- package/src/src/react/router/index.tsx +10 -0
- package/src/src/rendering/orchestrator/html.ts +132 -5
- package/src/src/server/handlers/dev/framework-candidates.generated.ts +9 -0
- package/src/src/server/handlers/request/ssr/ssr-response-builder.ts +7 -11
- package/src/src/tool/factory.ts +17 -4
- package/src/src/tool/types.ts +2 -0
- package/src/src/transforms/pipeline/stages/ssr-vf-modules/constants.ts +4 -0
- package/src/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.ts +4 -2
- package/src/src/transforms/pipeline/stages/ssr-vf-modules/index.ts +18 -15
- package/src/src/transforms/pipeline/stages/ssr-vf-modules/path-resolver.ts +4 -1
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -12,6 +12,32 @@ import { isDynamicTool } from "./tool-helpers.js";
|
|
|
12
12
|
import { serverLogger } from "../../utils/index.js";
|
|
13
13
|
import { setActiveSpanAttributes, withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
14
14
|
const logger = serverLogger.component("agent");
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function normalizeToolInputString(input) {
|
|
19
|
+
if (typeof input === "string") {
|
|
20
|
+
return input;
|
|
21
|
+
}
|
|
22
|
+
return JSON.stringify(input ?? null) ?? "null";
|
|
23
|
+
}
|
|
24
|
+
function normalizeToolInputObject(input) {
|
|
25
|
+
if (isRecord(input)) {
|
|
26
|
+
return input;
|
|
27
|
+
}
|
|
28
|
+
if (typeof input === "string") {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(input);
|
|
31
|
+
if (isRecord(parsed)) {
|
|
32
|
+
return parsed;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
15
41
|
function createAbortError(reason) {
|
|
16
42
|
if (reason instanceof Error) {
|
|
17
43
|
return reason;
|
|
@@ -23,6 +49,17 @@ function throwIfAborted(abortSignal) {
|
|
|
23
49
|
throw createAbortError(abortSignal.reason);
|
|
24
50
|
}
|
|
25
51
|
}
|
|
52
|
+
function stringifyToolError(output) {
|
|
53
|
+
if (typeof output === "string" && output.length > 0) {
|
|
54
|
+
return output;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(output);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return String(output);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
26
63
|
export function createStreamState() {
|
|
27
64
|
return {
|
|
28
65
|
accumulatedText: "",
|
|
@@ -91,17 +128,14 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
91
128
|
case "tool-call": {
|
|
92
129
|
// tool-call fires when the full tool call is available
|
|
93
130
|
const toolId = part.toolCallId;
|
|
94
|
-
const inputStr =
|
|
131
|
+
const inputStr = normalizeToolInputString(part.input);
|
|
95
132
|
state.toolCalls.set(toolId, {
|
|
96
133
|
id: toolId,
|
|
97
134
|
name: part.toolName,
|
|
98
135
|
arguments: inputStr,
|
|
99
136
|
});
|
|
100
137
|
const dynamic = isDynamicTool(part.toolName);
|
|
101
|
-
|
|
102
|
-
const inputObj = (part.input && typeof part.input === "object" && !Array.isArray(part.input))
|
|
103
|
-
? part.input
|
|
104
|
-
: {};
|
|
138
|
+
const inputObj = normalizeToolInputObject(part.input);
|
|
105
139
|
sendSSE(controller, encoder, {
|
|
106
140
|
type: "tool-input-available",
|
|
107
141
|
toolCallId: toolId,
|
|
@@ -111,6 +145,23 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
111
145
|
});
|
|
112
146
|
break;
|
|
113
147
|
}
|
|
148
|
+
case "tool-result": {
|
|
149
|
+
const isError = "isError" in part && part.isError === true;
|
|
150
|
+
if (isError) {
|
|
151
|
+
sendSSE(controller, encoder, {
|
|
152
|
+
type: "tool-output-error",
|
|
153
|
+
toolCallId: part.toolCallId,
|
|
154
|
+
errorText: stringifyToolError(part.output),
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
sendSSE(controller, encoder, {
|
|
159
|
+
type: "tool-output-available",
|
|
160
|
+
toolCallId: part.toolCallId,
|
|
161
|
+
output: part.output,
|
|
162
|
+
});
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
114
165
|
case "finish": {
|
|
115
166
|
state.finishReason = part.finishReason;
|
|
116
167
|
if (part.totalUsage) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAGlB,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAgB/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,YAAY,EA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IAsHtC;;OAEG;YACW,gBAAgB;IAuO9B;;;;OAIG;YACW,yBAAyB;IAiPvC;;OAEG;YACW,eAAe;IAqC7B;;OAEG;YACW,mBAAmB;IAOjC;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,sBAAsB;IAY9B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC;IAI5B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC;QAC9B,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAIF;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnC"}
|
|
@@ -502,7 +502,10 @@ export class AgentRuntime {
|
|
|
502
502
|
model: languageModel,
|
|
503
503
|
system: systemPrompt,
|
|
504
504
|
messages: convertToModelMessages(currentMessages),
|
|
505
|
-
tools: convertToolsToAISDK(tools
|
|
505
|
+
tools: convertToolsToAISDK(tools, {
|
|
506
|
+
model: effectiveModel,
|
|
507
|
+
allowedToolNames: allowedRemoteToolNames,
|
|
508
|
+
}),
|
|
506
509
|
maxOutputTokens: this.resolveMaxOutputTokens(maxOutputTokensOverride),
|
|
507
510
|
temperature: DEFAULT_TEMPERATURE,
|
|
508
511
|
abortSignal,
|
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ToolSet } from "ai";
|
|
10
10
|
import type { ToolDefinition } from "../../tool/index.js";
|
|
11
|
+
export interface ConvertToolsToAISDKOptions {
|
|
12
|
+
model?: string;
|
|
13
|
+
allowedToolNames?: string[];
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* Convert veryfront tool definitions to AI SDK ToolSet.
|
|
13
17
|
*
|
|
14
18
|
* The AI SDK tool() function wraps each tool with its schema.
|
|
15
19
|
* We don't provide `execute` — the agent runtime handles execution.
|
|
16
20
|
*/
|
|
17
|
-
export declare function convertToolsToAISDK(tools: ToolDefinition[]): ToolSet | undefined;
|
|
21
|
+
export declare function convertToolsToAISDK(tools: ToolDefinition[], options?: ConvertToolsToAISDKOptions): ToolSet | undefined;
|
|
18
22
|
//# sourceMappingURL=model-tool-converter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-tool-converter.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/model-tool-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"model-tool-converter.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/model-tool-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAgCD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,GAAG,SAAS,CAoBrB"}
|
|
@@ -7,15 +7,38 @@
|
|
|
7
7
|
* @module ai/agent/runtime/model-tool-converter
|
|
8
8
|
*/
|
|
9
9
|
import { jsonSchema, tool } from "ai";
|
|
10
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
11
|
+
function resolveHostedProvider(model) {
|
|
12
|
+
if (!model)
|
|
13
|
+
return undefined;
|
|
14
|
+
const [provider, second] = model.split("/", 3);
|
|
15
|
+
if (!provider)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (provider === "veryfront-cloud") {
|
|
18
|
+
return second || undefined;
|
|
19
|
+
}
|
|
20
|
+
return provider;
|
|
21
|
+
}
|
|
22
|
+
function resolveProviderNativeTools(options) {
|
|
23
|
+
if (!options?.allowedToolNames?.includes("web_search")) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
if (resolveHostedProvider(options.model) !== "anthropic") {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
web_search: anthropic.tools.webSearch_20250305({
|
|
31
|
+
maxUses: 5,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
10
35
|
/**
|
|
11
36
|
* Convert veryfront tool definitions to AI SDK ToolSet.
|
|
12
37
|
*
|
|
13
38
|
* The AI SDK tool() function wraps each tool with its schema.
|
|
14
39
|
* We don't provide `execute` — the agent runtime handles execution.
|
|
15
40
|
*/
|
|
16
|
-
export function convertToolsToAISDK(tools) {
|
|
17
|
-
if (!tools.length)
|
|
18
|
-
return undefined;
|
|
41
|
+
export function convertToolsToAISDK(tools, options) {
|
|
19
42
|
const toolSet = {};
|
|
20
43
|
for (const def of tools) {
|
|
21
44
|
toolSet[def.name] = tool({
|
|
@@ -23,5 +46,13 @@ export function convertToolsToAISDK(tools) {
|
|
|
23
46
|
inputSchema: jsonSchema(def.parameters),
|
|
24
47
|
});
|
|
25
48
|
}
|
|
26
|
-
|
|
49
|
+
const providerNativeTools = resolveProviderNativeTools(options);
|
|
50
|
+
if (providerNativeTools) {
|
|
51
|
+
for (const [name, providerTool] of Object.entries(providerNativeTools)) {
|
|
52
|
+
if (!Object.hasOwn(toolSet, name)) {
|
|
53
|
+
toolSet[name] = providerTool;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Object.keys(toolSet).length > 0 ? toolSet : undefined;
|
|
27
58
|
}
|
package/esm/src/agent/types.d.ts
CHANGED
|
@@ -12,6 +12,24 @@ import type { Message, MessagePart, ToolCall, ToolCallPart, ToolCallPartWithArgs
|
|
|
12
12
|
*/
|
|
13
13
|
export type ModelString = string;
|
|
14
14
|
import type { EdgeConfig, MemoryConfig } from "./schemas/index.js";
|
|
15
|
+
export type AgentSuggestion = {
|
|
16
|
+
id: string;
|
|
17
|
+
type: "prompt";
|
|
18
|
+
title: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
prompt: string;
|
|
21
|
+
} | {
|
|
22
|
+
id: string;
|
|
23
|
+
type: "task";
|
|
24
|
+
title: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
task: string;
|
|
27
|
+
prompt?: string;
|
|
28
|
+
};
|
|
29
|
+
export interface AgentSuggestions {
|
|
30
|
+
welcomeMessage?: string;
|
|
31
|
+
suggestions: AgentSuggestion[];
|
|
32
|
+
}
|
|
15
33
|
export interface AgentConfig {
|
|
16
34
|
id?: string;
|
|
17
35
|
/**
|
|
@@ -45,6 +63,7 @@ export interface AgentConfig {
|
|
|
45
63
|
* and registers the skill tools.
|
|
46
64
|
*/
|
|
47
65
|
skills?: true | string[];
|
|
66
|
+
suggestions?: AgentSuggestions;
|
|
48
67
|
/** Set to false to disable the default security middleware */
|
|
49
68
|
security?: false;
|
|
50
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/agent/types.ts"],"names":[],"mappings":"AAAA;;4BAE4B;AAC5B,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAG/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAG3D,YAAY,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EACV,OAAO,EAC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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,qGAAqG;QACrG,KAAK,CAAC,EAAE,WAAW,CAAC;QACpB,iEAAiE;QACjE,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE3B,MAAM,CAAC,KAAK,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,qGAAqG;QACrG,KAAK,CAAC,EAAE,WAAW,CAAC;QACpB,iEAAiE;QACjE,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;QAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACnC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE/B,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7D,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAE7B,cAAc,IAAI,OAAO,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IAEH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
|
|
@@ -24,6 +24,37 @@ export declare const RuntimeAgentSkillSchema: z.ZodObject<{
|
|
|
24
24
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
25
|
examples: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
26
|
}, z.core.$strip>;
|
|
27
|
+
export declare const RuntimeAgentSuggestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
type: z.ZodLiteral<"prompt">;
|
|
30
|
+
title: z.ZodString;
|
|
31
|
+
description: z.ZodOptional<z.ZodString>;
|
|
32
|
+
prompt: z.ZodString;
|
|
33
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
type: z.ZodLiteral<"task">;
|
|
36
|
+
title: z.ZodString;
|
|
37
|
+
description: z.ZodOptional<z.ZodString>;
|
|
38
|
+
task: z.ZodString;
|
|
39
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
40
|
+
}, z.core.$strip>], "type">;
|
|
41
|
+
export declare const RuntimeAgentSuggestionsSchema: z.ZodObject<{
|
|
42
|
+
welcomeMessage: z.ZodOptional<z.ZodString>;
|
|
43
|
+
suggestions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
type: z.ZodLiteral<"prompt">;
|
|
46
|
+
title: z.ZodString;
|
|
47
|
+
description: z.ZodOptional<z.ZodString>;
|
|
48
|
+
prompt: z.ZodString;
|
|
49
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
type: z.ZodLiteral<"task">;
|
|
52
|
+
title: z.ZodString;
|
|
53
|
+
description: z.ZodOptional<z.ZodString>;
|
|
54
|
+
task: z.ZodString;
|
|
55
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
56
|
+
}, z.core.$strip>], "type">>;
|
|
57
|
+
}, z.core.$strip>;
|
|
27
58
|
export declare const RuntimeAgentSchema: z.ZodObject<{
|
|
28
59
|
id: z.ZodString;
|
|
29
60
|
name: z.ZodString;
|
|
@@ -37,6 +68,23 @@ export declare const RuntimeAgentSchema: z.ZodObject<{
|
|
|
37
68
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
38
69
|
examples: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
39
70
|
}, z.core.$strip>>>;
|
|
71
|
+
suggestions: z.ZodOptional<z.ZodObject<{
|
|
72
|
+
welcomeMessage: z.ZodOptional<z.ZodString>;
|
|
73
|
+
suggestions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
type: z.ZodLiteral<"prompt">;
|
|
76
|
+
title: z.ZodString;
|
|
77
|
+
description: z.ZodOptional<z.ZodString>;
|
|
78
|
+
prompt: z.ZodString;
|
|
79
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
type: z.ZodLiteral<"task">;
|
|
82
|
+
title: z.ZodString;
|
|
83
|
+
description: z.ZodOptional<z.ZodString>;
|
|
84
|
+
task: z.ZodString;
|
|
85
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>], "type">>;
|
|
87
|
+
}, z.core.$strip>>;
|
|
40
88
|
}, z.core.$strip>;
|
|
41
89
|
export declare const RuntimeAgentListResponseSchema: z.ZodObject<{
|
|
42
90
|
agents: z.ZodArray<z.ZodObject<{
|
|
@@ -52,6 +100,23 @@ export declare const RuntimeAgentListResponseSchema: z.ZodObject<{
|
|
|
52
100
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
101
|
examples: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
54
102
|
}, z.core.$strip>>>;
|
|
103
|
+
suggestions: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
welcomeMessage: z.ZodOptional<z.ZodString>;
|
|
105
|
+
suggestions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
106
|
+
id: z.ZodString;
|
|
107
|
+
type: z.ZodLiteral<"prompt">;
|
|
108
|
+
title: z.ZodString;
|
|
109
|
+
description: z.ZodOptional<z.ZodString>;
|
|
110
|
+
prompt: z.ZodString;
|
|
111
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
112
|
+
id: z.ZodString;
|
|
113
|
+
type: z.ZodLiteral<"task">;
|
|
114
|
+
title: z.ZodString;
|
|
115
|
+
description: z.ZodOptional<z.ZodString>;
|
|
116
|
+
task: z.ZodString;
|
|
117
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
118
|
+
}, z.core.$strip>], "type">>;
|
|
119
|
+
}, z.core.$strip>>;
|
|
55
120
|
}, z.core.$strip>>;
|
|
56
121
|
}, z.core.$strip>;
|
|
57
122
|
declare const dispatchClaimsSchema: z.ZodObject<{
|
|
@@ -82,6 +147,8 @@ declare const controlPlaneClaimsSchema: z.ZodObject<{
|
|
|
82
147
|
export type ControlPlaneSurface = z.infer<typeof ControlPlaneSurfaceSchema>;
|
|
83
148
|
export type ControlPlaneAgentsListRequest = z.infer<typeof ControlPlaneAgentsListRequestSchema>;
|
|
84
149
|
export type RuntimeAgentSkill = z.infer<typeof RuntimeAgentSkillSchema>;
|
|
150
|
+
export type RuntimeAgentSuggestion = z.infer<typeof RuntimeAgentSuggestionSchema>;
|
|
151
|
+
export type RuntimeAgentSuggestions = z.infer<typeof RuntimeAgentSuggestionsSchema>;
|
|
85
152
|
export type RuntimeAgent = z.infer<typeof RuntimeAgentSchema>;
|
|
86
153
|
export type RuntimeAgentListResponse = z.infer<typeof RuntimeAgentListResponseSchema>;
|
|
87
154
|
export type DispatchClaims = z.infer<typeof dispatchClaimsSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-plane.d.ts","sourceRoot":"","sources":["../../../src/src/channels/control-plane.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,yBAAyB;;;;;EAA+C,CAAC;AAEtF,eAAO,MAAM,mCAAmC;;;;;;;;;iBAI9C,CAAC;AAEH,eA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AC,EAAE,mBAAmB,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB,GACA,OAAO,CAAC,kBAAkB,CAAC,CAmB7B"}
|
|
@@ -21,6 +21,27 @@ export const RuntimeAgentSkillSchema = z.object({
|
|
|
21
21
|
tags: z.array(z.string()).optional(),
|
|
22
22
|
examples: z.array(z.string()).optional(),
|
|
23
23
|
});
|
|
24
|
+
export const RuntimeAgentSuggestionSchema = z.discriminatedUnion("type", [
|
|
25
|
+
z.object({
|
|
26
|
+
id: z.string().min(1),
|
|
27
|
+
type: z.literal("prompt"),
|
|
28
|
+
title: z.string().min(1),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
prompt: z.string().min(1),
|
|
31
|
+
}),
|
|
32
|
+
z.object({
|
|
33
|
+
id: z.string().min(1),
|
|
34
|
+
type: z.literal("task"),
|
|
35
|
+
title: z.string().min(1),
|
|
36
|
+
description: z.string().optional(),
|
|
37
|
+
task: z.string().min(1),
|
|
38
|
+
prompt: z.string().min(1).optional(),
|
|
39
|
+
}),
|
|
40
|
+
]);
|
|
41
|
+
export const RuntimeAgentSuggestionsSchema = z.object({
|
|
42
|
+
welcomeMessage: z.string().min(1).optional(),
|
|
43
|
+
suggestions: z.array(RuntimeAgentSuggestionSchema),
|
|
44
|
+
});
|
|
24
45
|
export const RuntimeAgentSchema = z.object({
|
|
25
46
|
id: z.string().min(1),
|
|
26
47
|
name: z.string().min(1),
|
|
@@ -28,6 +49,7 @@ export const RuntimeAgentSchema = z.object({
|
|
|
28
49
|
model: z.string().nullable().optional(),
|
|
29
50
|
version: z.string().nullable().optional(),
|
|
30
51
|
skills: z.array(RuntimeAgentSkillSchema).optional(),
|
|
52
|
+
suggestions: RuntimeAgentSuggestionsSchema.optional(),
|
|
31
53
|
});
|
|
32
54
|
export const RuntimeAgentListResponseSchema = z.object({
|
|
33
55
|
agents: z.array(RuntimeAgentSchema),
|
|
@@ -150,6 +172,10 @@ function resolveAgentSkills(agent) {
|
|
|
150
172
|
}
|
|
151
173
|
function getRuntimeAgentMetadata(id, agent) {
|
|
152
174
|
const rawConfig = agent.config;
|
|
175
|
+
const suggestionsParseResult = rawConfig.suggestions === undefined
|
|
176
|
+
? null
|
|
177
|
+
: RuntimeAgentSuggestionsSchema.safeParse(rawConfig.suggestions);
|
|
178
|
+
const suggestions = suggestionsParseResult?.success ? suggestionsParseResult.data : undefined;
|
|
153
179
|
return RuntimeAgentSchema.parse({
|
|
154
180
|
id,
|
|
155
181
|
name: typeof rawConfig.name === "string" && rawConfig.name.trim().length > 0
|
|
@@ -159,6 +185,7 @@ function getRuntimeAgentMetadata(id, agent) {
|
|
|
159
185
|
model: agent.config.model ?? null,
|
|
160
186
|
version: typeof rawConfig.version === "string" ? rawConfig.version : null,
|
|
161
187
|
skills: resolveAgentSkills(agent),
|
|
188
|
+
...(suggestions === undefined ? {} : { suggestions }),
|
|
162
189
|
});
|
|
163
190
|
}
|
|
164
191
|
export async function listRuntimeAgents(ctx, deps) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/discovery/handlers/tool-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/discovery/handlers/tool-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQpD,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,IAAI,CAiB9C,CAAC"}
|
|
@@ -3,12 +3,22 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { registerTool } from "../../mcp/index.js";
|
|
5
5
|
import { filenameToId } from "../discovery-utils.js";
|
|
6
|
+
function hasGeneratedToolId(tool) {
|
|
7
|
+
return typeof tool.__veryfrontGeneratedId === "string" &&
|
|
8
|
+
tool.id === tool.__veryfrontGeneratedId;
|
|
9
|
+
}
|
|
6
10
|
export const toolHandler = {
|
|
7
11
|
typeName: "tool",
|
|
8
12
|
validate: (item) => item !== null && typeof item === "object" && typeof item.execute === "function",
|
|
9
|
-
getId: (
|
|
13
|
+
getId: (tool, file) => {
|
|
14
|
+
return typeof tool.id === "string" &&
|
|
15
|
+
tool.id.trim().length > 0 &&
|
|
16
|
+
!hasGeneratedToolId(tool)
|
|
17
|
+
? tool.id
|
|
18
|
+
: filenameToId(file);
|
|
19
|
+
},
|
|
10
20
|
register: (id, tool) => {
|
|
11
|
-
const toolWithId = { ...tool, id };
|
|
21
|
+
const toolWithId = tool.id === id ? tool : { ...tool, id };
|
|
12
22
|
registerTool(id, toolWithId);
|
|
13
23
|
return toolWithId;
|
|
14
24
|
},
|
|
@@ -27,6 +27,8 @@ export interface InjectHTMLContentOptions {
|
|
|
27
27
|
yjsGuid?: string;
|
|
28
28
|
/** Pre-built import map JSON for ESM module resolution (injected into <head>) */
|
|
29
29
|
importMapJson?: string;
|
|
30
|
+
/** Framework-generated project stylesheet for production shells */
|
|
31
|
+
projectStylesheetHref?: string;
|
|
30
32
|
}
|
|
31
33
|
export declare function injectHTMLContent(template: string, content: string, metadata: HTMLMetadata, options: InjectHTMLContentOptions): string;
|
|
32
34
|
//# sourceMappingURL=html-injection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injection.d.ts","sourceRoot":"","sources":["../../../src/src/html/html-injection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAkB/D,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACvC,+DAA+D;IAC/D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"html-injection.d.ts","sourceRoot":"","sources":["../../../src/src/html/html-injection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAkB/D,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACvC,+DAA+D;IAC/D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAgBD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAwGR"}
|
|
@@ -37,6 +37,10 @@ export function injectHTMLContent(template, content, metadata, options) {
|
|
|
37
37
|
const importMapTag = `<script type="importmap"${nonceAttr}>\n${options.importMapJson}\n</script>`;
|
|
38
38
|
html = html.replace(/<\/head>/i, `${importMapTag}\n</head>`);
|
|
39
39
|
}
|
|
40
|
+
if (options.projectStylesheetHref && /<\/head>/i.test(html) && !hasProjectStylesheet(html)) {
|
|
41
|
+
const projectStylesheetTag = `<link rel="stylesheet" href="${options.projectStylesheetHref}">`;
|
|
42
|
+
html = html.replace(/<\/head>/i, `${projectStylesheetTag}\n</head>`);
|
|
43
|
+
}
|
|
40
44
|
const shouldUsePreviewStylesheet = options.mode === "development" ||
|
|
41
45
|
options.environment === "preview";
|
|
42
46
|
if (shouldUsePreviewStylesheet && /<\/head>/i.test(html) && !hasProjectStylesheet(html)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nonce-injection.d.ts","sourceRoot":"","sources":["../../../src/src/html/nonce-injection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nonce-injection.d.ts","sourceRoot":"","sources":["../../../src/src/html/nonce-injection.ts"],"names":[],"mappings":"AAgIA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CA6DvE;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,CAAC,UAAU,CAAC,CAyG5B"}
|
|
@@ -41,9 +41,62 @@ function findRawTextClosingTagStart(lowerHtml, tagName, fromIndex) {
|
|
|
41
41
|
}
|
|
42
42
|
return -1;
|
|
43
43
|
}
|
|
44
|
+
function findAttribute(tag, attributeName) {
|
|
45
|
+
const closeIndex = tag.lastIndexOf(">");
|
|
46
|
+
if (closeIndex <= 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
let index = 1;
|
|
49
|
+
while (index < closeIndex && !/\s|\/|>/u.test(tag[index] ?? ""))
|
|
50
|
+
index++;
|
|
51
|
+
while (index < closeIndex) {
|
|
52
|
+
while (index < closeIndex && /\s/u.test(tag[index] ?? ""))
|
|
53
|
+
index++;
|
|
54
|
+
if (index >= closeIndex)
|
|
55
|
+
break;
|
|
56
|
+
const char = tag[index];
|
|
57
|
+
if (char === "/" || char === ">")
|
|
58
|
+
break;
|
|
59
|
+
const start = index;
|
|
60
|
+
while (index < closeIndex && !/[\s=/>]/u.test(tag[index] ?? ""))
|
|
61
|
+
index++;
|
|
62
|
+
const name = tag.slice(start, index);
|
|
63
|
+
while (index < closeIndex && /\s/u.test(tag[index] ?? ""))
|
|
64
|
+
index++;
|
|
65
|
+
let value = null;
|
|
66
|
+
if (tag[index] === "=") {
|
|
67
|
+
index++;
|
|
68
|
+
while (index < closeIndex && /\s/u.test(tag[index] ?? ""))
|
|
69
|
+
index++;
|
|
70
|
+
const quote = tag[index];
|
|
71
|
+
if (quote === '"' || quote === "'") {
|
|
72
|
+
index++;
|
|
73
|
+
const valueStart = index;
|
|
74
|
+
while (index < closeIndex && tag[index] !== quote)
|
|
75
|
+
index++;
|
|
76
|
+
value = tag.slice(valueStart, index);
|
|
77
|
+
if (index < closeIndex)
|
|
78
|
+
index++;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const valueStart = index;
|
|
82
|
+
while (index < closeIndex && !/[\s>]/u.test(tag[index] ?? ""))
|
|
83
|
+
index++;
|
|
84
|
+
value = tag.slice(valueStart, index);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (name.toLowerCase() === attributeName) {
|
|
88
|
+
return { name, start, end: index, value };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
44
93
|
function injectNonceIntoOpeningTag(tag, escapedNonce) {
|
|
45
|
-
|
|
46
|
-
|
|
94
|
+
const existingNonce = findAttribute(tag, "nonce");
|
|
95
|
+
if (existingNonce) {
|
|
96
|
+
if (existingNonce.value?.trim())
|
|
97
|
+
return tag;
|
|
98
|
+
return `${tag.slice(0, existingNonce.start)}nonce="${escapedNonce}"${tag.slice(existingNonce.end)}`;
|
|
99
|
+
}
|
|
47
100
|
const closeIndex = tag.lastIndexOf(">");
|
|
48
101
|
if (closeIndex === -1)
|
|
49
102
|
return tag;
|
|
@@ -102,3 +155,95 @@ export function addNonceToHtmlTags(html, nonce) {
|
|
|
102
155
|
}
|
|
103
156
|
return result;
|
|
104
157
|
}
|
|
158
|
+
export function addNonceToHtmlStream(stream, nonce) {
|
|
159
|
+
if (!nonce)
|
|
160
|
+
return stream;
|
|
161
|
+
const escapedNonce = escapeHtml(nonce);
|
|
162
|
+
const decoder = new TextDecoder();
|
|
163
|
+
const encoder = new TextEncoder();
|
|
164
|
+
let buffer = "";
|
|
165
|
+
let rawTextTag = null;
|
|
166
|
+
function transformBuffer(flush) {
|
|
167
|
+
let result = "";
|
|
168
|
+
let index = 0;
|
|
169
|
+
const lowerBuffer = buffer.toLowerCase();
|
|
170
|
+
while (index < buffer.length) {
|
|
171
|
+
if (rawTextTag) {
|
|
172
|
+
const closingIndex = findRawTextClosingTagStart(lowerBuffer, rawTextTag, index);
|
|
173
|
+
if (closingIndex === -1) {
|
|
174
|
+
if (flush) {
|
|
175
|
+
result += buffer.slice(index);
|
|
176
|
+
index = buffer.length;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
const retainLength = `</${rawTextTag}`.length;
|
|
180
|
+
const safeEnd = Math.max(index, buffer.length - retainLength);
|
|
181
|
+
result += buffer.slice(index, safeEnd);
|
|
182
|
+
index = safeEnd;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
result += buffer.slice(index, closingIndex);
|
|
186
|
+
index = closingIndex;
|
|
187
|
+
rawTextTag = null;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (buffer.startsWith("<!--", index)) {
|
|
191
|
+
const commentEnd = buffer.indexOf("-->", index + 4);
|
|
192
|
+
if (commentEnd === -1) {
|
|
193
|
+
if (flush) {
|
|
194
|
+
result += buffer.slice(index);
|
|
195
|
+
index = buffer.length;
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
const endIndex = commentEnd + 3;
|
|
200
|
+
result += buffer.slice(index, endIndex);
|
|
201
|
+
index = endIndex;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (buffer[index] !== "<") {
|
|
205
|
+
const nextTagIndex = buffer.indexOf("<", index);
|
|
206
|
+
const endIndex = nextTagIndex === -1 ? buffer.length : nextTagIndex;
|
|
207
|
+
result += buffer.slice(index, endIndex);
|
|
208
|
+
index = endIndex;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const tagEnd = findTagEnd(buffer, index);
|
|
212
|
+
if (tagEnd === -1) {
|
|
213
|
+
if (flush) {
|
|
214
|
+
result += buffer.slice(index);
|
|
215
|
+
index = buffer.length;
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
const tag = buffer.slice(index, tagEnd + 1);
|
|
220
|
+
const tagName = getOpeningTagName(tag);
|
|
221
|
+
if (!tagName) {
|
|
222
|
+
result += tag;
|
|
223
|
+
index = tagEnd + 1;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
result += injectNonceIntoOpeningTag(tag, escapedNonce);
|
|
227
|
+
index = tagEnd + 1;
|
|
228
|
+
if (!/\/\s*>$/u.test(tag)) {
|
|
229
|
+
rawTextTag = tagName;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
buffer = buffer.slice(index);
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
return stream.pipeThrough(new TransformStream({
|
|
236
|
+
transform(chunk, controller) {
|
|
237
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
238
|
+
const transformed = transformBuffer(false);
|
|
239
|
+
if (transformed)
|
|
240
|
+
controller.enqueue(encoder.encode(transformed));
|
|
241
|
+
},
|
|
242
|
+
flush(controller) {
|
|
243
|
+
buffer += decoder.decode();
|
|
244
|
+
const transformed = transformBuffer(true);
|
|
245
|
+
if (transformed)
|
|
246
|
+
controller.enqueue(encoder.encode(transformed));
|
|
247
|
+
},
|
|
248
|
+
}));
|
|
249
|
+
}
|