veryfront 0.1.812 → 0.1.814

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.
Files changed (70) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/agent/conversation/durable-append-errors.d.ts +17 -0
  3. package/esm/src/agent/conversation/durable-append-errors.d.ts.map +1 -0
  4. package/esm/src/agent/conversation/durable-append-errors.js +49 -0
  5. package/esm/src/agent/conversation/durable.d.ts +1 -16
  6. package/esm/src/agent/conversation/durable.d.ts.map +1 -1
  7. package/esm/src/agent/conversation/durable.js +3 -49
  8. package/esm/src/agent/runtime/agent-runtime-step.d.ts +44 -0
  9. package/esm/src/agent/runtime/agent-runtime-step.d.ts.map +1 -0
  10. package/esm/src/agent/runtime/agent-runtime-step.js +23 -0
  11. package/esm/src/agent/runtime/index.d.ts.map +1 -1
  12. package/esm/src/agent/runtime/index.js +45 -62
  13. package/esm/src/agent/runtime/model-transport.d.ts +23 -0
  14. package/esm/src/agent/runtime/model-transport.d.ts.map +1 -0
  15. package/esm/src/agent/runtime/model-transport.js +26 -0
  16. package/esm/src/agent/runtime/streamed-assistant-message.d.ts +8 -0
  17. package/esm/src/agent/runtime/streamed-assistant-message.d.ts.map +1 -0
  18. package/esm/src/agent/runtime/streamed-assistant-message.js +29 -0
  19. package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts +19 -0
  20. package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts.map +1 -0
  21. package/esm/src/agent/streaming/fork-runtime-step-progress.js +53 -0
  22. package/esm/src/agent/streaming/fork-runtime-stream.d.ts +1 -4
  23. package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
  24. package/esm/src/agent/streaming/fork-runtime-stream.js +13 -52
  25. package/esm/src/cache/keys/builders/render.d.ts.map +1 -1
  26. package/esm/src/cache/keys/builders/render.js +3 -2
  27. package/esm/src/cache/request-cacheability.d.ts +3 -0
  28. package/esm/src/cache/request-cacheability.d.ts.map +1 -0
  29. package/esm/src/cache/request-cacheability.js +26 -0
  30. package/esm/src/html/hydration-script-builder/hydration-data-generator.d.ts.map +1 -1
  31. package/esm/src/html/hydration-script-builder/hydration-data-generator.js +1 -10
  32. package/esm/src/html/hydration-script-builder/templates/router.d.ts.map +1 -1
  33. package/esm/src/html/hydration-script-builder/templates/router.js +41 -10
  34. package/esm/src/observability/request-profiler.d.ts.map +1 -1
  35. package/esm/src/observability/request-profiler.js +1 -0
  36. package/esm/src/proxy/handler.d.ts.map +1 -1
  37. package/esm/src/proxy/handler.js +39 -29
  38. package/esm/src/proxy/main.js +35 -31
  39. package/esm/src/proxy/proxy-error-context.d.ts +20 -0
  40. package/esm/src/proxy/proxy-error-context.d.ts.map +1 -0
  41. package/esm/src/proxy/proxy-error-context.js +35 -0
  42. package/esm/src/proxy/request-lifecycle.d.ts +19 -0
  43. package/esm/src/proxy/request-lifecycle.d.ts.map +1 -0
  44. package/esm/src/proxy/request-lifecycle.js +27 -0
  45. package/esm/src/proxy/server-timing.d.ts +11 -0
  46. package/esm/src/proxy/server-timing.d.ts.map +1 -0
  47. package/esm/src/proxy/server-timing.js +61 -0
  48. package/esm/src/proxy/upstream-error-response.d.ts +5 -0
  49. package/esm/src/proxy/upstream-error-response.d.ts.map +1 -0
  50. package/esm/src/proxy/upstream-error-response.js +15 -0
  51. package/esm/src/release-assets/client-module-map.d.ts +3 -0
  52. package/esm/src/release-assets/client-module-map.d.ts.map +1 -0
  53. package/esm/src/release-assets/client-module-map.js +10 -0
  54. package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
  55. package/esm/src/rendering/orchestrator/module-loader/index.js +13 -49
  56. package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.d.ts +25 -0
  57. package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.d.ts.map +1 -0
  58. package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.js +69 -0
  59. package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
  60. package/esm/src/rendering/orchestrator/pipeline.js +9 -10
  61. package/esm/src/rendering/orchestrator/types.d.ts +2 -0
  62. package/esm/src/rendering/orchestrator/types.d.ts.map +1 -1
  63. package/esm/src/rendering/renderer.d.ts.map +1 -1
  64. package/esm/src/rendering/renderer.js +24 -19
  65. package/esm/src/server/handlers/request/module/page-data-endpoint-handler.d.ts +1 -0
  66. package/esm/src/server/handlers/request/module/page-data-endpoint-handler.d.ts.map +1 -1
  67. package/esm/src/server/handlers/request/module/page-data-endpoint-handler.js +98 -8
  68. package/esm/src/utils/version-constant.d.ts +1 -1
  69. package/esm/src/utils/version-constant.js +1 -1
  70. package/package.json +9 -9
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.812",
3
+ "version": "0.1.814",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": {
@@ -0,0 +1,17 @@
1
+ /** Error shape for append conversation run events. */
2
+ export declare class AppendConversationRunEventsError extends Error {
3
+ readonly status: number;
4
+ readonly detail: string | null;
5
+ constructor(input: {
6
+ status: number;
7
+ detail?: string | null;
8
+ statusText?: string;
9
+ });
10
+ }
11
+ /** Parses append conversation run events error body. */
12
+ export declare function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null;
13
+ /** Error shape for is ignorable conversation run append. */
14
+ export declare function isIgnorableConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
15
+ /** Error shape for is cursor mismatch conversation run append. */
16
+ export declare function isCursorMismatchConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
17
+ //# sourceMappingURL=durable-append-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-append-errors.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable-append-errors.ts"],"names":[],"mappings":"AAEA,sDAAsD;AACtD,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEnB,KAAK,EAAE;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAOF;AAED,wDAAwD;AACxD,wBAAgB,yCAAyC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAezF;AAED,4DAA4D;AAC5D,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gCAAgC,CAiB3C;AAED,kEAAkE;AAClE,wBAAgB,0CAA0C,CACxD,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gCAAgC,CAM3C"}
@@ -0,0 +1,49 @@
1
+ import { getConversationRunErrorSchema } from "./durable-contracts.js";
2
+ /** Error shape for append conversation run events. */
3
+ export class AppendConversationRunEventsError extends Error {
4
+ status;
5
+ detail;
6
+ constructor(input) {
7
+ const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
8
+ super(`Append conversation run events failed (${input.status}): ${detail}`);
9
+ this.name = "AppendConversationRunEventsError";
10
+ this.status = input.status;
11
+ this.detail = input.detail?.trim() || null;
12
+ }
13
+ }
14
+ /** Parses append conversation run events error body. */
15
+ export function parseAppendConversationRunEventsErrorBody(bodyText) {
16
+ if (!bodyText) {
17
+ return null;
18
+ }
19
+ try {
20
+ const parsed = getConversationRunErrorSchema().safeParse(JSON.parse(bodyText));
21
+ if (parsed.success) {
22
+ return parsed.data.detail ?? parsed.data.error ?? null;
23
+ }
24
+ }
25
+ catch {
26
+ return bodyText;
27
+ }
28
+ return bodyText;
29
+ }
30
+ /** Error shape for is ignorable conversation run append. */
31
+ export function isIgnorableConversationRunAppendError(error) {
32
+ if (!(error instanceof AppendConversationRunEventsError)) {
33
+ return false;
34
+ }
35
+ if (error.status === 404) {
36
+ return true;
37
+ }
38
+ if (error.status !== 400) {
39
+ return false;
40
+ }
41
+ return (error.detail === "Cannot append external events to a terminal run" ||
42
+ error.detail === "Cannot append external events while the run is waiting for a tool result");
43
+ }
44
+ /** Error shape for is cursor mismatch conversation run append. */
45
+ export function isCursorMismatchConversationRunAppendError(error) {
46
+ return (error instanceof AppendConversationRunEventsError &&
47
+ error.status === 400 &&
48
+ error.detail === "External run event cursor mismatch");
49
+ }
@@ -1,5 +1,6 @@
1
1
  import type { ActiveConversationRunStatus, AppendConversationRunEventsResponse, ConversationRunAppendCursorResyncResult, ConversationRunAppendFailureOutcome, ConversationRunAppendRecoveryOutcome, ConversationRunEventQueueController, ConversationRunProjection, CreateConversationAgentRunInput, FinalizeConversationAgentRunInput, TerminalConversationRunStatus } from "./durable-contracts.js";
2
2
  export { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, CreateConversationRunAcceptedSchema, getAppendConversationRunEventsResponseSchema, getCompleteConversationRunResponseSchema, getConversationRunProjectionSchema, getConversationRunStatusSchema, getConversationRunTargetsSchema, getCreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
3
+ export { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
3
4
  export type { ActiveConversationRunStatus, AppendConversationRunEventsResponse, ConversationAgentRunUsage, ConversationRunAppendCursorResyncResult, ConversationRunAppendExecutionOutcome, ConversationRunAppendFailureOutcome, ConversationRunAppendRecoveryOutcome, ConversationRunBatchFlushOutcome, ConversationRunEventQueueController, ConversationRunProjection, ConversationRunQueueFlushOutcome, ConversationRunTargets, CreateConversationAgentRunInput, FinalizeConversationAgentRunInput, TerminalConversationRunStatus, } from "./durable-contracts.js";
4
5
  /** Error shape for conversation run terminal state. */
5
6
  export declare class ConversationRunTerminalStateError extends Error {
@@ -7,22 +8,6 @@ export declare class ConversationRunTerminalStateError extends Error {
7
8
  readonly run: ConversationRunProjection;
8
9
  constructor(run: ConversationRunProjection, status: TerminalConversationRunStatus);
9
10
  }
10
- /** Error shape for append conversation run events. */
11
- export declare class AppendConversationRunEventsError extends Error {
12
- readonly status: number;
13
- readonly detail: string | null;
14
- constructor(input: {
15
- status: number;
16
- detail?: string | null;
17
- statusText?: string;
18
- });
19
- }
20
- /** Parses append conversation run events error body. */
21
- export declare function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null;
22
- /** Error shape for is ignorable conversation run append. */
23
- export declare function isIgnorableConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
24
- /** Error shape for is cursor mismatch conversation run append. */
25
- export declare function isCursorMismatchConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
26
11
  /** Check whether a conversation run status is active. */
27
12
  export declare function isActiveConversationRunStatus(status: ConversationRunProjection["status"]): status is ActiveConversationRunStatus;
28
13
  /** Check whether a conversation run projection can accept more events. */
@@ -1 +1 @@
1
- {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mCAAmC,EACnC,uCAAuC,EACvC,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,yBAAyB,EACzB,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC9B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,yCAAyC,EACzC,qCAAqC,EACrC,+BAA+B,EAC/B,2BAA2B,EAC3B,4BAA4B,EAC5B,mCAAmC,EACnC,4CAA4C,EAC5C,wCAAwC,EACxC,kCAAkC,EAClC,8BAA8B,EAC9B,+BAA+B,EAC/B,sCAAsC,EACtC,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,2BAA2B,EAC3B,mCAAmC,EACnC,yBAAyB,EACzB,uCAAuC,EACvC,qCAAqC,EACrC,mCAAmC,EACnC,oCAAoC,EACp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ED,8CAA8C;AAC9C,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
1
+ {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mCAAmC,EACnC,uCAAuC,EACvC,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,yBAAyB,EACzB,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC9B,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EACL,yCAAyC,EACzC,qCAAqC,EACrC,+BAA+B,EAC/B,2BAA2B,EAC3B,4BAA4B,EAC5B,mCAAmC,EACnC,4CAA4C,EAC5C,wCAAwC,EACxC,kCAAkC,EAClC,8BAA8B,EAC9B,+BAA+B,EAC/B,sCAAsC,EACtC,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gCAAgC,EAChC,0CAA0C,EAC1C,qCAAqC,EACrC,yCAAyC,GAC1C,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,2BAA2B,EAC3B,mCAAmC,EACnC,yBAAyB,EACzB,uCAAuC,EACvC,qCAAqC,EACrC,mCAAmC,EACnC,oCAAoC,EACpC,gCAAgC,EAChC,mCAAmC,EACnC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAkChC,uDAAuD;AACvD,qBAAa,iCAAkC,SAAQ,KAAK;IAC1D,QAAQ,CAAC,MAAM,EAAE,6BAA6B,CAAC;IAC/C,QAAQ,CAAC,GAAG,EAAE,yBAAyB,CAAC;gBAE5B,GAAG,EAAE,yBAAyB,EAAE,MAAM,EAAE,6BAA6B;CAMlF;AAED,yDAAyD;AACzD,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,yBAAyB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AC,EAAE,MAAM,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAyD/C;AAED,qCAAqC;AACrC,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,yBAAyB,CAAC,CA4DpC;AAED,8CAA8C;AAC9C,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
@@ -1,6 +1,8 @@
1
1
  import * as dntShim from "../../../_dnt.shims.js";
2
- import { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, CreateConversationRunAcceptedSchema, getConversationRunErrorSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
2
+ import { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, CreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
3
+ import { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
3
4
  export { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, CreateConversationRunAcceptedSchema, getAppendConversationRunEventsResponseSchema, getCompleteConversationRunResponseSchema, getConversationRunProjectionSchema, getConversationRunStatusSchema, getConversationRunTargetsSchema, getCreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
5
+ export { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
4
6
  const AGENT_RUN_API_TIMEOUT_MS = 15_000;
5
7
  function createTimedAbortSignal(timeoutMs, abortSignal) {
6
8
  const controller = new AbortController();
@@ -39,54 +41,6 @@ export class ConversationRunTerminalStateError extends Error {
39
41
  this.run = run;
40
42
  }
41
43
  }
42
- /** Error shape for append conversation run events. */
43
- export class AppendConversationRunEventsError extends Error {
44
- status;
45
- detail;
46
- constructor(input) {
47
- const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
48
- super(`Append conversation run events failed (${input.status}): ${detail}`);
49
- this.name = "AppendConversationRunEventsError";
50
- this.status = input.status;
51
- this.detail = input.detail?.trim() || null;
52
- }
53
- }
54
- /** Parses append conversation run events error body. */
55
- export function parseAppendConversationRunEventsErrorBody(bodyText) {
56
- if (!bodyText) {
57
- return null;
58
- }
59
- try {
60
- const parsed = getConversationRunErrorSchema().safeParse(JSON.parse(bodyText));
61
- if (parsed.success) {
62
- return parsed.data.detail ?? parsed.data.error ?? null;
63
- }
64
- }
65
- catch {
66
- return bodyText;
67
- }
68
- return bodyText;
69
- }
70
- /** Error shape for is ignorable conversation run append. */
71
- export function isIgnorableConversationRunAppendError(error) {
72
- if (!(error instanceof AppendConversationRunEventsError)) {
73
- return false;
74
- }
75
- if (error.status === 404) {
76
- return true;
77
- }
78
- if (error.status !== 400) {
79
- return false;
80
- }
81
- return (error.detail === "Cannot append external events to a terminal run" ||
82
- error.detail === "Cannot append external events while the run is waiting for a tool result");
83
- }
84
- /** Error shape for is cursor mismatch conversation run append. */
85
- export function isCursorMismatchConversationRunAppendError(error) {
86
- return (error instanceof AppendConversationRunEventsError &&
87
- error.status === 400 &&
88
- error.detail === "External run event cursor mismatch");
89
- }
90
44
  /** Check whether a conversation run status is active. */
91
45
  export function isActiveConversationRunStatus(status) {
92
46
  return status === "pending" || status === "running" || status === "waiting_for_tool";
@@ -0,0 +1,44 @@
1
+ import type { RemoteToolSource, ToolDefinition, ToolExecutionContext } from "../../tool/index.js";
2
+ import type { AgentConfig, Message } from "../types.js";
3
+ import type { ToolConfigEntry } from "./tool-helpers.js";
4
+ export type AgentRuntimeStepMode = "generate" | "stream";
5
+ export type RuntimeStepToolLoader = (toolsConfig: true | Record<string, ToolConfigEntry> | undefined, options?: {
6
+ includeSkillTools?: boolean;
7
+ includeIntegrationTools?: boolean;
8
+ allowedRemoteToolNames?: string[];
9
+ forwardedRemoteToolDefinitions?: ToolDefinition[];
10
+ remoteToolSources?: RemoteToolSource[];
11
+ remoteToolContext?: ToolExecutionContext;
12
+ callerAgentId?: string;
13
+ }) => Promise<ToolDefinition[]>;
14
+ export interface AgentRuntimeStepState {
15
+ systemPrompt: string;
16
+ context?: Record<string, unknown>;
17
+ }
18
+ export type RuntimeStepStateResolver = (messages: Message[], runtimeContext: Record<string, unknown> | undefined, mode: AgentRuntimeStepMode, step: number, systemPrompt: string) => Promise<AgentRuntimeStepState>;
19
+ export interface PrepareAgentRuntimeStepInput {
20
+ agentId: string;
21
+ activeSkillPolicy: string[] | undefined;
22
+ allowedRemoteToolNames: string[] | undefined;
23
+ config: AgentConfig;
24
+ forwardedRemoteToolDefinitions: ToolDefinition[] | undefined;
25
+ getAvailableTools: RuntimeStepToolLoader;
26
+ isLocalModel: boolean;
27
+ messages: Message[];
28
+ mode: AgentRuntimeStepMode;
29
+ remoteToolSources: RemoteToolSource[] | undefined;
30
+ resolveRuntimeState: RuntimeStepStateResolver;
31
+ runtimeContext: Record<string, unknown> | undefined;
32
+ step: number;
33
+ systemPrompt: string;
34
+ toolContextBase: ToolExecutionContext | undefined;
35
+ }
36
+ export interface PreparedAgentRuntimeStep {
37
+ runtimeContext: Record<string, unknown> | undefined;
38
+ systemPrompt: string;
39
+ toolContext: ToolExecutionContext;
40
+ tools: ToolDefinition[];
41
+ }
42
+ /** Resolve per-step runtime state and the tools visible for that step. */
43
+ export declare function prepareAgentRuntimeStep(input: PrepareAgentRuntimeStepInput): Promise<PreparedAgentRuntimeStep>;
44
+ //# sourceMappingURL=agent-runtime-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-runtime-step.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/agent-runtime-step.ts"],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AAC;IACxC,sBAAsB,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,WAAW,CAAC;IACpB,8BAA8B,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IAC7D,iBAAiB,EAAE,qBAAqB,CAAC;IACzC,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,iBAAiB,EAAE,gBAAgB,EAAE,GAAG,SAAS,CAAC;IAClD,mBAAmB,EAAE,wBAAwB,CAAC;IAC9C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,oBAAoB,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,oBAAoB,CAAC;IAClC,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED,0EAA0E;AAC1E,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,4BAA4B,GAClC,OAAO,CAAC,wBAAwB,CAAC,CA6BnC"}
@@ -0,0 +1,23 @@
1
+ import { filterToolsForSkill } from "../../skill/allowed-tools.js";
2
+ /** Resolve per-step runtime state and the tools visible for that step. */
3
+ export async function prepareAgentRuntimeStep(input) {
4
+ const runtimeState = await input.resolveRuntimeState(input.messages, input.runtimeContext, input.mode, input.step, input.systemPrompt);
5
+ const toolContext = { ...input.toolContextBase, ...runtimeState.context };
6
+ let tools = input.isLocalModel ? [] : await input.getAvailableTools(input.config.tools, {
7
+ callerAgentId: input.agentId,
8
+ includeSkillTools: Boolean(input.config.skills),
9
+ allowedRemoteToolNames: input.allowedRemoteToolNames,
10
+ forwardedRemoteToolDefinitions: input.forwardedRemoteToolDefinitions,
11
+ remoteToolSources: input.remoteToolSources,
12
+ remoteToolContext: toolContext,
13
+ });
14
+ if (input.activeSkillPolicy) {
15
+ tools = filterToolsForSkill(tools, input.activeSkillPolicy);
16
+ }
17
+ return {
18
+ runtimeContext: runtimeState.context,
19
+ systemPrompt: runtimeState.systemPrompt,
20
+ toolContext,
21
+ tools,
22
+ };
23
+ }
@@ -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,EAGZ,KAAK,QAAQ,EAGd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAqB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmDpE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,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,EACL,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,0BAA0B,EAC1B,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;A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@@ -19,7 +19,6 @@ import { serverLogger } from "../../utils/index.js";
19
19
  import { addSpanEvent, setSpanAttributes, withSpan, } from "../../observability/tracing/index.js";
20
20
  import { convertToTextGenerationRuntimeMessages } from "./text-generation-runtime-message-converter.js";
21
21
  import { convertToolsToRuntimeTools } from "./model-tool-converter.js";
22
- import { resolveProviderOptionsWithDefaults } from "./default-provider-options.js";
23
22
  import { getRuntimeRemoteToolSources } from "./mcp-server-tool-sources.js";
24
23
  import { createStreamState, processStream, } from "./chat-stream-handler.js";
25
24
  import { repairToolCall } from "./repair-tool-call.js";
@@ -30,6 +29,8 @@ import { generateText, streamText } from "../../runtime/runtime-bridge.js";
30
29
  import { captureStreamedToolCallInput, collectFinalStreamToolResults, collectGeneratedToolResults, createToolErrorMessage, createToolResultMessage, getProviderExecutedToolNames, getToolResultError, isRecoverablePlaceholderToolCall, isStreamedToolCallIncomplete, materializeStreamedToolCall, shouldContinueAfterStreamStep, } from "./tool-result-continuation.js";
31
30
  import { enforceSkillPolicy, extractSkillId, extractSkillPolicy, hasSubmittedFormInputResult, hydrateActiveSkillStateFromMessages, LOAD_SKILL_TOOL_ID, removeFormInputAfterSubmission, } from "./skill-policy-enforcement.js";
32
31
  import { getRuntimeAllowedRemoteTools, getRuntimeForwardedIntegrationToolDefs, getRuntimeProviderTools, } from "./runtime-tool-config.js";
32
+ import { prepareAgentRuntimeStep } from "./agent-runtime-step.js";
33
+ import { buildStreamedAssistantMessage } from "./streamed-assistant-message.js";
33
34
  // Re-export from submodules
34
35
  export { closeSSEStream, generateMessageId, sendSSE } from "./sse-utils.js";
35
36
  export { RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./resume-session.js";
@@ -44,11 +45,11 @@ import { DEFAULT_MAX_TOKENS, DEFAULT_TEMPERATURE, getModelMaxOutputTokens } from
44
45
  import { closeSSEStream, generateMessageId, sendSSE } from "./sse-utils.js";
45
46
  import { executeConfiguredTool, getAvailableTools, isDynamicTool } from "./tool-helpers.js";
46
47
  import { accumulateUsage, getMaxSteps, normalizeInput } from "./input-utils.js";
47
- import { filterToolsForSkill } from "../../skill/allowed-tools.js";
48
- import { resolveConfiguredAgentModel, resolveRuntimeModel } from "./model-resolution.js";
48
+ import { resolveRuntimeModel } from "./model-resolution.js";
49
49
  import { stringifyToolError, throwIfAborted } from "./error-utils.js";
50
50
  import { supportsTemperatureParameter } from "./model-capabilities.js";
51
51
  import { applySkillDelegationOverridesToToolInput, extractSkillDelegationOverrides, } from "./skill-delegation-overrides.js";
52
+ import { resolveAgentModelTransport } from "./model-transport.js";
52
53
  const logger = serverLogger.component("agent");
53
54
  function isAbortError(error, abortSignal) {
54
55
  if (abortSignal?.aborted && error === abortSignal.reason) {
@@ -92,22 +93,13 @@ export class AgentRuntime {
92
93
  return persisted.length > 0 ? persisted : inputMessages;
93
94
  }
94
95
  async resolveModelTransport(context, modelOverride, mode) {
95
- const requestedModel = resolveConfiguredAgentModel(modelOverride || this.config.model);
96
- const resolvedModelString = resolveRuntimeModel(modelOverride || this.config.model);
97
- const transport = await this.config.resolveModelTransport?.({
96
+ return await resolveAgentModelTransport({
98
97
  agentId: this.id,
99
- requestedModel,
100
- resolvedModel: resolvedModelString,
98
+ config: this.config,
101
99
  context,
100
+ modelOverride,
102
101
  mode,
103
102
  });
104
- return {
105
- requestedModel,
106
- resolvedModelString,
107
- languageModel: transport?.model ?? resolveModel(resolvedModelString),
108
- headers: transport?.headers,
109
- providerOptions: resolveProviderOptionsWithDefaults(resolvedModelString, transport?.providerOptions),
110
- };
111
103
  }
112
104
  async resolveRuntimeState(messages, context, mode, step, systemPrompt) {
113
105
  const refreshed = await this.config.resolveRuntimeState?.({
@@ -317,22 +309,27 @@ export class AgentRuntime {
317
309
  for (let step = 0; step < maxSteps; step++) {
318
310
  this.status = "thinking";
319
311
  addSpanEvent(loopSpan, "step_start", { step });
320
- const runtimeState = await this.resolveRuntimeState(currentMessages, currentRuntimeContext, "generate", step, currentSystemPrompt);
321
- currentSystemPrompt = runtimeState.systemPrompt;
322
- currentRuntimeContext = runtimeState.context;
323
- const toolContext = { ...toolContextBase, ...currentRuntimeContext };
324
- let tools = isLocal ? [] : await getAvailableTools(this.config.tools, {
325
- callerAgentId: this.id,
326
- includeSkillTools: Boolean(this.config.skills),
312
+ const preparedStep = await prepareAgentRuntimeStep({
313
+ agentId: this.id,
314
+ activeSkillPolicy,
327
315
  allowedRemoteToolNames,
316
+ config: this.config,
328
317
  forwardedRemoteToolDefinitions,
318
+ getAvailableTools,
319
+ isLocalModel: isLocal,
320
+ messages: currentMessages,
321
+ mode: "generate",
329
322
  remoteToolSources,
330
- remoteToolContext: toolContext,
323
+ resolveRuntimeState: this.resolveRuntimeState.bind(this),
324
+ runtimeContext: currentRuntimeContext,
325
+ step,
326
+ systemPrompt: currentSystemPrompt,
327
+ toolContextBase,
331
328
  });
332
- // Layer 1: Filter tools based on active skill policy (planning-time)
333
- if (activeSkillPolicy) {
334
- tools = filterToolsForSkill(tools, activeSkillPolicy);
335
- }
329
+ currentSystemPrompt = preparedStep.systemPrompt;
330
+ currentRuntimeContext = preparedStep.runtimeContext;
331
+ const toolContext = preparedStep.toolContext;
332
+ const tools = preparedStep.tools;
336
333
  const temperature = this.resolveTemperature(temperatureModelString ?? effectiveModel);
337
334
  const response = await withSpan("agent.generate_text", async (span) => {
338
335
  setSpanAttributes(span, {
@@ -549,22 +546,27 @@ export class AgentRuntime {
549
546
  throwIfAborted(abortSignal);
550
547
  sendSSE(controller, encoder, { type: "step-start" });
551
548
  const currentStepToolResults = new Map();
552
- const runtimeState = await this.resolveRuntimeState(currentMessages, currentRuntimeContext, "stream", step, currentSystemPrompt);
553
- currentSystemPrompt = runtimeState.systemPrompt;
554
- currentRuntimeContext = runtimeState.context;
555
- const toolContext = { ...toolContextBase, ...currentRuntimeContext };
556
- let tools = isLocalStreaming ? [] : await getAvailableTools(this.config.tools, {
557
- callerAgentId: this.id,
558
- includeSkillTools: Boolean(this.config.skills),
549
+ const preparedStep = await prepareAgentRuntimeStep({
550
+ agentId: this.id,
551
+ activeSkillPolicy,
559
552
  allowedRemoteToolNames,
553
+ config: this.config,
560
554
  forwardedRemoteToolDefinitions,
555
+ getAvailableTools,
556
+ isLocalModel: isLocalStreaming,
557
+ messages: currentMessages,
558
+ mode: "stream",
561
559
  remoteToolSources,
562
- remoteToolContext: toolContext,
560
+ resolveRuntimeState: this.resolveRuntimeState.bind(this),
561
+ runtimeContext: currentRuntimeContext,
562
+ step,
563
+ systemPrompt: currentSystemPrompt,
564
+ toolContextBase,
563
565
  });
564
- // Layer 1: Filter tools based on active skill policy (planning-time)
565
- if (activeSkillPolicy) {
566
- tools = filterToolsForSkill(tools, activeSkillPolicy);
567
- }
566
+ currentSystemPrompt = preparedStep.systemPrompt;
567
+ currentRuntimeContext = preparedStep.runtimeContext;
568
+ const toolContext = preparedStep.toolContext;
569
+ const tools = preparedStep.tools;
568
570
  const runtimeTools = convertToolsToRuntimeTools(tools, {
569
571
  model: effectiveModel,
570
572
  providerTools,
@@ -590,25 +592,12 @@ export class AgentRuntime {
590
592
  }, abortSignal);
591
593
  throwIfAborted(abortSignal);
592
594
  finalFinishReason = state.finishReason ?? finalFinishReason;
593
- const streamParts = [];
594
- for (const reasoningPart of state.reasoningParts) {
595
- if (reasoningPart.text.length === 0 &&
596
- !reasoningPart.signature &&
597
- !reasoningPart.redactedData) {
598
- continue;
599
- }
600
- streamParts.push({
601
- type: "reasoning",
602
- ...(reasoningPart.text.length > 0 ? { text: reasoningPart.text } : {}),
603
- ...(reasoningPart.signature ? { signature: reasoningPart.signature } : {}),
604
- ...(reasoningPart.redactedData ? { redactedData: reasoningPart.redactedData } : {}),
605
- });
606
- }
607
- if (state.accumulatedText)
608
- streamParts.push({ type: "text", text: state.accumulatedText });
595
+ const assistantMessage = buildStreamedAssistantMessage(state, {
596
+ id: `msg_${Date.now()}_${step}`,
597
+ timestamp: Date.now(),
598
+ });
609
599
  for (const tc of state.toolCalls.values()) {
610
600
  const materialized = materializeStreamedToolCall(tc);
611
- streamParts.push(materialized.part);
612
601
  if (materialized.kind === "incomplete" && isRecoverablePlaceholderToolCall(tc)) {
613
602
  // Provisional empty-object placeholder that never finalized. The
614
603
  // model never committed arguments; the loop will recover by
@@ -646,12 +635,6 @@ export class AgentRuntime {
646
635
  });
647
636
  }
648
637
  }
649
- const assistantMessage = {
650
- id: `msg_${Date.now()}_${step}`,
651
- role: "assistant",
652
- parts: streamParts,
653
- timestamp: Date.now(),
654
- };
655
638
  latestAssistantText = getTextFromParts(assistantMessage.parts);
656
639
  currentMessages.push(assistantMessage);
657
640
  await this.memory.add(assistantMessage);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Model transport resolution for the agent runtime.
3
+ *
4
+ * @module agent/runtime/model-transport
5
+ */
6
+ import { type AgentConfig } from "../types.js";
7
+ import { type ModelRuntime } from "../../provider/index.js";
8
+ export type ResolvedModelTransport = {
9
+ requestedModel: string;
10
+ resolvedModelString: string;
11
+ languageModel: ModelRuntime;
12
+ headers?: HeadersInit;
13
+ providerOptions?: Record<string, unknown>;
14
+ };
15
+ export interface ResolveAgentModelTransportInput {
16
+ agentId: string;
17
+ config: AgentConfig;
18
+ context: Record<string, unknown> | undefined;
19
+ modelOverride: string | undefined;
20
+ mode: "generate" | "stream";
21
+ }
22
+ export declare function resolveAgentModelTransport(input: ResolveAgentModelTransportInput): Promise<ResolvedModelTransport>;
23
+ //# sourceMappingURL=model-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-transport.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/model-transport.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,yBAAyB,CAAC;AAI1E,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,YAAY,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC7B;AAED,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,sBAAsB,CAAC,CAqBjC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Model transport resolution for the agent runtime.
3
+ *
4
+ * @module agent/runtime/model-transport
5
+ */
6
+ import { resolveModel } from "../../provider/index.js";
7
+ import { resolveProviderOptionsWithDefaults } from "./default-provider-options.js";
8
+ import { resolveConfiguredAgentModel, resolveRuntimeModel } from "./model-resolution.js";
9
+ export async function resolveAgentModelTransport(input) {
10
+ const requestedModel = resolveConfiguredAgentModel(input.modelOverride || input.config.model);
11
+ const resolvedModelString = resolveRuntimeModel(input.modelOverride || input.config.model);
12
+ const transport = await input.config.resolveModelTransport?.({
13
+ agentId: input.agentId,
14
+ requestedModel,
15
+ resolvedModel: resolvedModelString,
16
+ context: input.context,
17
+ mode: input.mode,
18
+ });
19
+ return {
20
+ requestedModel,
21
+ resolvedModelString,
22
+ languageModel: transport?.model ?? resolveModel(resolvedModelString),
23
+ headers: transport?.headers,
24
+ providerOptions: resolveProviderOptionsWithDefaults(resolvedModelString, transport?.providerOptions),
25
+ };
26
+ }
@@ -0,0 +1,8 @@
1
+ import type { Message } from "../types.js";
2
+ import type { ChatStreamState } from "./chat-stream-handler.js";
3
+ export interface StreamedAssistantMessageIdentity {
4
+ id: string;
5
+ timestamp: number;
6
+ }
7
+ export declare function buildStreamedAssistantMessage(state: Pick<ChatStreamState, "accumulatedText" | "reasoningParts" | "toolCalls">, identity: StreamedAssistantMessageIdentity): Message;
8
+ //# sourceMappingURL=streamed-assistant-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamed-assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/streamed-assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,MAAM,WAAW,gCAAgC;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,WAAW,CAAC,EAChF,QAAQ,EAAE,gCAAgC,GACzC,OAAO,CAiCT"}
@@ -0,0 +1,29 @@
1
+ import { materializeStreamedToolCall } from "./tool-result-continuation.js";
2
+ export function buildStreamedAssistantMessage(state, identity) {
3
+ const parts = [];
4
+ for (const reasoningPart of state.reasoningParts) {
5
+ if (reasoningPart.text.length === 0 &&
6
+ !reasoningPart.signature &&
7
+ !reasoningPart.redactedData) {
8
+ continue;
9
+ }
10
+ parts.push({
11
+ type: "reasoning",
12
+ ...(reasoningPart.text.length > 0 ? { text: reasoningPart.text } : {}),
13
+ ...(reasoningPart.signature ? { signature: reasoningPart.signature } : {}),
14
+ ...(reasoningPart.redactedData ? { redactedData: reasoningPart.redactedData } : {}),
15
+ });
16
+ }
17
+ if (state.accumulatedText) {
18
+ parts.push({ type: "text", text: state.accumulatedText });
19
+ }
20
+ for (const toolCall of state.toolCalls.values()) {
21
+ parts.push(materializeStreamedToolCall(toolCall).part);
22
+ }
23
+ return {
24
+ id: identity.id,
25
+ role: "assistant",
26
+ parts,
27
+ timestamp: identity.timestamp,
28
+ };
29
+ }
@@ -0,0 +1,19 @@
1
+ import type { AgentResponse, Message as AgentMessage } from "../schemas/index.js";
2
+ import type { ForkRuntimeStep } from "./fork-runtime-stream.js";
3
+ export interface ForkRuntimeProgress {
4
+ steps: ForkRuntimeStep[];
5
+ currentMessages: AgentMessage[];
6
+ accumulatedInputTokens: number;
7
+ accumulatedOutputTokens: number;
8
+ }
9
+ /** Build a fork runtime step from an agent response. */
10
+ export declare function buildForkRuntimeStepFromResponse(response: AgentResponse): ForkRuntimeStep;
11
+ /** Should continue fork runtime step helper. */
12
+ export declare function shouldContinueForkRuntimeStep(step: ForkRuntimeStep, response: AgentResponse): boolean;
13
+ export declare function createForkRuntimeProgress(currentMessages: AgentMessage[]): ForkRuntimeProgress;
14
+ export declare function commitForkRuntimeStep(progress: ForkRuntimeProgress, response: AgentResponse): ForkRuntimeStep;
15
+ export declare function getForkRuntimeProgressUsage(progress: ForkRuntimeProgress): {
16
+ inputTokens: number;
17
+ outputTokens: number;
18
+ };
19
+ //# sourceMappingURL=fork-runtime-step-progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fork-runtime-step-progress.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-step-progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,eAAe,EAAE,YAAY,EAAE,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,wDAAwD;AACxD,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,aAAa,GAAG,eAAe,CA2BzF;AAED,gDAAgD;AAChD,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAGT;AAED,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,EAAE,GAC9B,mBAAmB,CAOrB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,mBAAmB,EAC7B,QAAQ,EAAE,aAAa,GACtB,eAAe,CAOjB;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,mBAAmB,GAC5B;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAK/C"}