@roomle/embedding-lib 0.0.0-dev-a40887e → 0.0.0-dev-9d077e2

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 (30) hide show
  1. package/configurator.d.ts +2 -0
  2. package/configurator.js +119 -0
  3. package/configurator.min.js +117 -0
  4. package/hi.js +40 -138
  5. package/hi.min.js +39 -122
  6. package/package.json +8 -1
  7. package/packages/embedding-lib/src/configurator-agent/chat-recovery.d.ts +9 -0
  8. package/packages/embedding-lib/src/configurator-agent/configurator-mcp-tools.d.ts +11 -0
  9. package/packages/embedding-lib/src/configurator-agent/configurator-planning-assistant.d.ts +8 -0
  10. package/packages/embedding-lib/src/configurator.d.ts +3 -0
  11. package/packages/embedding-lib/src/hi.d.ts +1 -3
  12. package/packages/embedding-lib/src/homag-intelligence/hi-mcp-tools.d.ts +11 -11
  13. package/packages/embedding-lib/src/homag-intelligence/hi-planning-assistant.d.ts +5 -41
  14. package/packages/embedding-lib/src/planning-assistant/chat-model.d.ts +33 -0
  15. package/packages/embedding-lib/src/{homag-intelligence/hi-mcp/mcp-tool.d.ts → planning-assistant/mcp-tools.d.ts} +10 -27
  16. package/packages/embedding-lib/src/planning-assistant/planning-assistant.d.ts +23 -0
  17. package/planning-assistant-BW9fNGZO.mjs +158 -0
  18. package/planning-assistant-CyVA2uUX.mjs +143 -0
  19. package/roomle-embedding-lib.js +64 -55
  20. package/roomle-embedding-lib.min.js +9 -0
  21. package/hi-mcp-server-B4BAKDmw.mjs +0 -5288
  22. package/hi-mcp-server-DxIvpJmq.mjs +0 -4879
  23. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/agent-facing.d.ts +0 -35
  24. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/hi-mcp-server.d.ts +0 -3
  25. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/plan-history.d.ts +0 -33
  26. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/planner-api.d.ts +0 -32
  27. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/skills.d.ts +0 -23
  28. package/packages/embedding-lib/src/homag-intelligence/hi-mcp/tool-executors.d.ts +0 -4
  29. /package/{comlink-B2Kj_5Ge.mjs → comlink-BJnhpJa4.mjs} +0 -0
  30. /package/{comlink-B5lV2OWp.mjs → comlink-lSsogKgb.mjs} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "0.0.0-dev-a40887e",
3
+ "version": "0.0.0-dev-9d077e2",
4
4
  "description": "This is a small library which can be used to communicate with the Roomle Configurator. ES modules only (browser-compatible).",
5
5
  "type": "module",
6
6
  "main": "./roomle-embedding-lib.js",
@@ -29,6 +29,13 @@
29
29
  },
30
30
  "./plugins/min": {
31
31
  "import": "./embedding-plugins.min.js"
32
+ },
33
+ "./configurator": {
34
+ "import": "./configurator.js",
35
+ "types": "./configurator.d.ts"
36
+ },
37
+ "./configurator/min": {
38
+ "import": "./configurator.min.js"
32
39
  }
33
40
  },
34
41
  "scripts": {
@@ -0,0 +1,9 @@
1
+ import { AgentMcpTools } from '../planning-assistant/mcp-tools';
2
+ /**
3
+ * Records tool execution independently of whether the model finishes its
4
+ * step, so an interrupted reply can say what the tools changed.
5
+ */
6
+ export declare const createChatRecovery: (tools: AgentMcpTools) => {
7
+ tools: AgentMcpTools;
8
+ summary: () => string;
9
+ };
@@ -0,0 +1,11 @@
1
+ import { AgentToolDefinition, McpToolResult } from '../../../web-sdk/packages';
2
+ export interface ConfiguratorAgentApi {
3
+ getConfiguratorAgentTools(): Promise<AgentToolDefinition[]>;
4
+ callConfiguratorAgentTool(name: string, input: unknown): Promise<McpToolResult>;
5
+ getConfiguratorAgentPrompts(): Promise<{
6
+ systemPrompt: string;
7
+ imagePrompt: string;
8
+ }>;
9
+ }
10
+ /** The native configurator's agent tools forwarded through the embedding bridge. */
11
+ export declare const createConfiguratorMcpTools: (api: ConfiguratorAgentApi) => Promise<import('../hi').HiMcpTools>;
@@ -0,0 +1,8 @@
1
+ import { AssistantWindow } from '../planning-assistant/planning-assistant';
2
+ import { PlanningAssistantConfig } from '../planning-assistant/chat-model';
3
+ import { ConfiguratorAgentApi } from './configurator-mcp-tools';
4
+ /** Runs a native configurator assistant, with its window supplied separately for planner isolation. */
5
+ export declare const startConfiguratorPlanningAssistant: (endpoints: {
6
+ configurator: ConfiguratorAgentApi;
7
+ window: AssistantWindow;
8
+ }, config: PlanningAssistantConfig, signal: AbortSignal) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ export { createConfiguratorMcpTools, type ConfiguratorAgentApi, } from './configurator-agent/configurator-mcp-tools';
2
+ export { startConfiguratorPlanningAssistant } from './configurator-agent/configurator-planning-assistant';
3
+ export { loadChatModel, type PlanningAssistantConfig, } from './planning-assistant/chat-model';
@@ -14,9 +14,7 @@ export { createHiLibraryCallbacks } from './homag-intelligence/hi-callbacks';
14
14
  export { libLoadArticleCatalog, libLoadMasterData, libLoadCalcScript, registerLegacyUrlFormat, unregisterLegacyUrlFormat, } from './homag-intelligence/hi-requests';
15
15
  export { omPostRequest, omGetRequest, } from './homag-intelligence/hi-order-manager';
16
16
  export { setupHi, cleanupHi } from './homag-intelligence/hi-setup';
17
- export { createHiMcpTools } from './homag-intelligence/hi-mcp-tools';
18
- export type { HiMcpTool, HiMcpTools, } from './homag-intelligence/hi-mcp/mcp-tool';
19
- export type { HiMcpPlannerApi } from './homag-intelligence/hi-mcp/planner-api';
17
+ export { createHiMcpTools, type HiMcpTool, type HiMcpTools, type HiMcpPlannerApi, } from './homag-intelligence/hi-mcp-tools';
20
18
  export { loadChatModel, startPlanningAssistant, type PlanningAssistantConfig, type PlanningAssistantPlannerApi, } from './homag-intelligence/hi-planning-assistant';
21
19
  export { type ExternalObjectSnapshotSaveResult, type HiContextAction, } from '../../web-sdk/packages';
22
20
  export { HI_PANEL_ACTION, type HiPanelActionType, type HiOrderHeader, type HiOrder, type HiOrderData, type HiPriceData, type HiCallbacks, } from '../../common/src/hi/hi-types';
@@ -1,11 +1,11 @@
1
- import { HiMcpTools } from './hi-mcp/mcp-tool';
2
- import { HiMcpPlannerApi } from './hi-mcp/planner-api';
3
- /**
4
- * Creates the HI MCP tools for an AI agent that plans in the planner of this
5
- * page: the tools of the HI MCP server as an AI SDK tool set, without the MCP
6
- * protocol. The host passes the tool set as `tools` to its own `streamText`.
7
- * The tools call the planner through `roomDesignerApi.extended` and chain its
8
- * `onHistoryChange` callback; a host that sets its own handler sets it before.
9
- * The tool code is loaded on the first call.
10
- */
11
- export declare const createHiMcpTools: (roomDesignerApi: HiMcpPlannerApi) => Promise<HiMcpTools>;
1
+ import { HiAgentToolDefinition, McpToolResult } from '../../../web-sdk/packages';
2
+ export { mcpToModelOutput } from '../planning-assistant/mcp-tools';
3
+ export type { AgentMcpTool as HiMcpTool, AgentMcpTools as HiMcpTools, AgentMcpModelOutput as HiMcpModelOutput, AgentMcpInputSchema as HiMcpInputSchema, } from '../planning-assistant/mcp-tools';
4
+ export interface HiMcpPlannerApi {
5
+ extended: {
6
+ getExternalObjectAgentTools(): Promise<HiAgentToolDefinition[]>;
7
+ callExternalObjectAgentTool(name: string, input: unknown): Promise<McpToolResult>;
8
+ };
9
+ }
10
+ /** The planner's HI agent tools, forwarded through the embedding bridge. */
11
+ export declare const createHiMcpTools: ({ extended }: HiMcpPlannerApi) => Promise<import('./hi-mcp-tools').HiMcpTools>;
@@ -1,25 +1,7 @@
1
1
  import { PlanningAssistantOutput, PlanningAssistantPrompt } from '../../../web-sdk/packages';
2
- import { HiMcpPlannerApi } from './hi-mcp/planner-api';
3
- /**
4
- * The model of the AI Planning Assistant as a JSON object: everything
5
- * `loadChatModel` and `startPlanningAssistant` need to reach it.
6
- */
7
- export interface PlanningAssistantConfig {
8
- /** `azure` for a deployment on an Azure AI Foundry resource, else the provider of the model. */
9
- provider: 'azure' | 'mistral' | 'anthropic' | 'google';
10
- /** The model id at the provider; for `azure` the name of the deployment. */
11
- model: string;
12
- /** The API key of the provider; for `azure` the key of the Foundry resource. */
13
- apiKey: string;
14
- /** `azure` only: the OpenAI v1 endpoint of the Foundry resource, e.g. `https://<resource>.services.ai.azure.com/openai/v1`. */
15
- baseUrl?: string;
16
- /** `azure` only: call the deployment through the Chat Completions API instead of the Responses API. */
17
- chatCompletions?: boolean;
18
- /** `azure` only: the reasoning effort of the deployment; its default when unset. */
19
- reasoningEffort?: string;
20
- /** Whether the model reads images: the window offers the image drop only then. */
21
- readsImages: boolean;
22
- }
2
+ import { HiMcpPlannerApi } from './hi-mcp-tools';
3
+ import { PlanningAssistantConfig } from '../planning-assistant/chat-model';
4
+ export { loadChatModel, type PlanningAssistantConfig, } from '../planning-assistant/chat-model';
23
5
  /** The planner the planning assistant runs in: the HI MCP tools' planner API, the agent prompts and the window. */
24
6
  export type PlanningAssistantPlannerApi = HiMcpPlannerApi & {
25
7
  extended: {
@@ -33,23 +15,5 @@ export type PlanningAssistantPlannerApi = HiMcpPlannerApi & {
33
15
  };
34
16
  };
35
17
  };
36
- /** The AI SDK language model of the config and the provider options `streamText` takes with it. */
37
- export declare const loadChatModel: ({ provider, model, apiKey, baseUrl, chatCompletions, reasoningEffort, }: PlanningAssistantConfig) => Promise<{
38
- languageModel: any;
39
- providerOptions: {
40
- azure: {
41
- reasoningEffort: string;
42
- };
43
- };
44
- } | {
45
- languageModel: any;
46
- providerOptions?: undefined;
47
- }>;
48
- /**
49
- * Runs the planning agent of the AI Planning Assistant window
50
- * (featureFlags.planningAssistant) in this page: the window hands every
51
- * message to "onPlanningAssistantPrompt", the agent calls the HI MCP tools,
52
- * the tools call the planner of this page, and the agent's output goes to
53
- * "planningAssistantOutput". Aborting the signal ends a running turn.
54
- */
55
- export declare const startPlanningAssistant: (roomDesignerApi: PlanningAssistantPlannerApi, config: PlanningAssistantConfig, signal: AbortSignal) => Promise<void>;
18
+ /** Runs the HI planning assistant in the host page. */
19
+ export declare const startPlanningAssistant: (api: PlanningAssistantPlannerApi, config: PlanningAssistantConfig, signal: AbortSignal) => Promise<void>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The model of the AI Planning Assistant as a JSON object: everything
3
+ * `loadChatModel` and `startPlanningAssistant` need to reach it.
4
+ */
5
+ export interface PlanningAssistantConfig {
6
+ /** `azure` for a deployment on an Azure AI Foundry resource, else the provider of the model. */
7
+ provider: 'azure' | 'mistral' | 'anthropic' | 'google';
8
+ /** The model id at the provider; for `azure` the name of the deployment. */
9
+ model: string;
10
+ /** The API key of the provider; for `azure` the key of the Foundry resource. */
11
+ apiKey: string;
12
+ /** `azure` only: the OpenAI v1 endpoint of the Foundry resource, e.g. `https://<resource>.services.ai.azure.com/openai/v1`. */
13
+ baseUrl?: string;
14
+ /** `azure` only: call the deployment through the Chat Completions API instead of the Responses API. */
15
+ chatCompletions?: boolean;
16
+ /** `azure` only: the reasoning effort of the deployment; its default when unset. */
17
+ reasoningEffort?: string;
18
+ /** Whether the model reads images: the window offers the image drop only then. */
19
+ readsImages: boolean;
20
+ }
21
+ export declare const esm: (module: string) => string;
22
+ /** The AI SDK language model of the config and the provider options `streamText` takes with it. */
23
+ export declare const loadChatModel: ({ provider, model, apiKey, baseUrl, chatCompletions, reasoningEffort, }: PlanningAssistantConfig) => Promise<{
24
+ languageModel: any;
25
+ providerOptions: {
26
+ azure: {
27
+ reasoningEffort: string;
28
+ };
29
+ };
30
+ } | {
31
+ languageModel: any;
32
+ providerOptions?: undefined;
33
+ }>;
@@ -1,18 +1,6 @@
1
- import { z } from 'zod';
2
- /** The result of a tool as an MCP server answers `tools/call`. */
3
- export interface McpToolResult {
4
- content: ({
5
- type: 'text';
6
- text: string;
7
- } | {
8
- type: 'image';
9
- data: string;
10
- mimeType: string;
11
- })[];
12
- isError?: boolean;
13
- }
1
+ import { AgentToolDefinition, McpToolResult } from '../../../web-sdk/packages';
14
2
  /** What the model gets of a tool result, as `@ai-sdk/mcp` hands it to the AI SDK. */
15
- export interface HiMcpModelOutput {
3
+ export interface AgentMcpModelOutput {
16
4
  type: 'content';
17
5
  value: ({
18
6
  type: 'text';
@@ -27,7 +15,7 @@ export interface HiMcpModelOutput {
27
15
  })[];
28
16
  }
29
17
  /** The input schema of a tool as a Standard Schema with its JSON Schema. */
30
- export interface HiMcpInputSchema {
18
+ export interface AgentMcpInputSchema {
31
19
  '~standard': {
32
20
  version: 1;
33
21
  vendor: string;
@@ -45,25 +33,20 @@ export interface HiMcpInputSchema {
45
33
  };
46
34
  }
47
35
  /** A tool of the HI MCP tool set, in the shape of an AI SDK dynamic tool. */
48
- export interface HiMcpTool {
36
+ export interface AgentMcpTool {
49
37
  type: 'dynamic';
38
+ annotations?: AgentToolDefinition['annotations'];
50
39
  description: string;
51
- inputSchema: HiMcpInputSchema;
40
+ inputSchema: AgentMcpInputSchema;
52
41
  execute: (input: unknown) => Promise<McpToolResult>;
53
42
  toModelOutput: (options: {
54
43
  output: McpToolResult;
55
- }) => HiMcpModelOutput;
44
+ }) => AgentMcpModelOutput;
56
45
  }
57
46
  /** The HI MCP tools by name, the tool set an AI SDK `streamText` takes. */
58
- export type HiMcpTools = Record<string, HiMcpTool>;
47
+ export type AgentMcpTools = Record<string, AgentMcpTool>;
59
48
  /** The tool result as `@ai-sdk/mcp` passes it to the model: text parts and images as file parts. */
60
49
  export declare const mcpToModelOutput: ({ output, }: {
61
50
  output: McpToolResult;
62
- }) => HiMcpModelOutput;
63
- /**
64
- * A tool as an MCP server registers it and an MCP client hands it to the AI
65
- * SDK: the JSON Schema the MCP SDK serves, which the AI SDK does not validate;
66
- * the input validated here, an invalid input and a thrown error answered as
67
- * MCP error results, which the model reads like any other result.
68
- */
69
- export declare const mcpTool: (name: string, description: string, shape: z.ZodRawShape, handler: (args: any) => Promise<McpToolResult>) => HiMcpTool;
51
+ }) => AgentMcpModelOutput;
52
+ export declare const createAgentMcpTools: (definitions: AgentToolDefinition[], call: (name: string, input: unknown) => Promise<McpToolResult>, vendor: string) => AgentMcpTools;
@@ -0,0 +1,23 @@
1
+ import { PlanningAssistantOutput, PlanningAssistantPrompt } from '../../../web-sdk/packages';
2
+ import { PlanningAssistantConfig } from './chat-model';
3
+ import { AgentMcpTools } from './mcp-tools';
4
+ export interface AssistantWindow {
5
+ planningAssistantOutput(part: PlanningAssistantOutput): unknown;
6
+ callbacks: {
7
+ onPlanningAssistantPrompt?: (prompt: PlanningAssistantPrompt) => Promise<void>;
8
+ };
9
+ }
10
+ /** Runs a browser agent with the tools and prompts supplied by its SDK domain. */
11
+ export declare const startAssistant: (windowApi: AssistantWindow, config: PlanningAssistantConfig, signal: AbortSignal, setupDomain: () => Promise<{
12
+ prompts: {
13
+ systemPrompt: string;
14
+ imagePrompt: string;
15
+ };
16
+ tools: AgentMcpTools;
17
+ }>, turnPolicy?: {
18
+ timeoutMs: number;
19
+ recovery: (tools: AgentMcpTools) => {
20
+ tools: AgentMcpTools;
21
+ summary(): string;
22
+ };
23
+ }) => Promise<void>;
@@ -0,0 +1,158 @@
1
+ //#region packages/embedding-lib/src/planning-assistant/mcp-tools.ts
2
+ var e = ({ output: e }) => ({
3
+ type: "content",
4
+ value: e.content.map((e) => e.type === "text" ? {
5
+ type: "text",
6
+ text: e.text
7
+ } : {
8
+ type: "file",
9
+ mediaType: e.mimeType,
10
+ data: {
11
+ type: "data",
12
+ data: e.data
13
+ }
14
+ })
15
+ }), t = (t, n, r) => Object.fromEntries(t.map(({ name: t, description: i, inputSchema: a, annotations: o }) => {
16
+ let s = () => a;
17
+ return [t, {
18
+ type: "dynamic",
19
+ ...o && { annotations: o },
20
+ description: i,
21
+ inputSchema: { "~standard": {
22
+ version: 1,
23
+ vendor: r,
24
+ validate: (e) => ({ value: e }),
25
+ jsonSchema: {
26
+ input: s,
27
+ output: s
28
+ }
29
+ } },
30
+ execute: (e) => n(t, e).catch((e) => ({
31
+ content: [{
32
+ type: "text",
33
+ text: e instanceof Error ? e.message : String(e)
34
+ }],
35
+ isError: !0
36
+ })),
37
+ toModelOutput: e
38
+ }];
39
+ })), n = (e) => `https://esm.sh/${e}?deps=zod@4.6.5`, r = async ({ provider: e, model: t, apiKey: r, baseUrl: i, chatCompletions: a, reasoningEffort: o }) => {
40
+ switch (e) {
41
+ case "azure": {
42
+ let { createAzure: e } = await import(
43
+ /* @vite-ignore */
44
+ n("@ai-sdk/azure@4.0.85")
45
+ ), s = e({
46
+ apiKey: r,
47
+ baseURL: i
48
+ });
49
+ return {
50
+ languageModel: a ? s.chat(t) : s(t),
51
+ providerOptions: o ? { azure: { reasoningEffort: o } } : void 0
52
+ };
53
+ }
54
+ case "mistral": {
55
+ let { createMistral: e } = await import(
56
+ /* @vite-ignore */
57
+ n("@ai-sdk/mistral@4.0.54")
58
+ );
59
+ return { languageModel: e({ apiKey: r })(t) };
60
+ }
61
+ case "anthropic": {
62
+ let { createAnthropic: e } = await import(
63
+ /* @vite-ignore */
64
+ n("@ai-sdk/anthropic@4.0.68")
65
+ );
66
+ return { languageModel: e({
67
+ apiKey: r,
68
+ headers: { "anthropic-dangerous-direct-browser-access": "true" }
69
+ })(t) };
70
+ }
71
+ case "google": {
72
+ let { createGoogleGenerativeAI: e } = await import(
73
+ /* @vite-ignore */
74
+ n("@ai-sdk/google@4.0.85")
75
+ );
76
+ return { languageModel: e({ apiKey: r })(t) };
77
+ }
78
+ default: throw Error(`Unknown provider "${e}" - supported: azure, mistral, anthropic, google`);
79
+ }
80
+ }, i = async (e, t, i, a, o) => {
81
+ let s = (t) => e.planningAssistantOutput(t), c;
82
+ try {
83
+ c = await Promise.all([
84
+ import(
85
+ /* @vite-ignore */
86
+ n("ai@7.0.122")
87
+ ),
88
+ r(t),
89
+ a()
90
+ ]);
91
+ } catch (e) {
92
+ s({
93
+ type: "availability",
94
+ available: !1,
95
+ text: String(e)
96
+ });
97
+ return;
98
+ }
99
+ let [{ streamText: l, stepCountIs: u }, d, { prompts: f, tools: p }] = c, m = [];
100
+ e.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: t }) => {
101
+ let n = {
102
+ role: "user",
103
+ content: [{
104
+ type: "text",
105
+ text: e || f.imagePrompt
106
+ }, ...t.map((e) => ({
107
+ type: "file",
108
+ data: e,
109
+ mediaType: "image/jpeg"
110
+ }))]
111
+ }, r = o?.recovery(p), a = new AbortController(), c = () => a.abort(i.reason);
112
+ i.addEventListener("abort", c, { once: !0 }), i.aborted && c();
113
+ let h = o ? setTimeout(() => a.abort(/* @__PURE__ */ Error("The configurator assistant turn exceeded five minutes.")), o.timeoutMs) : void 0;
114
+ try {
115
+ let e = l({
116
+ model: d.languageModel,
117
+ providerOptions: d.providerOptions,
118
+ instructions: f.systemPrompt,
119
+ messages: [...m, n],
120
+ tools: r?.tools ?? p,
121
+ stopWhen: u(16),
122
+ abortSignal: o ? a.signal : i,
123
+ prepareStep: ({ stepNumber: e }) => e === 15 ? { toolChoice: "none" } : void 0
124
+ });
125
+ for await (let t of e.stream) if (t.type === "text-delta") s({
126
+ type: "text",
127
+ text: t.text
128
+ });
129
+ else if (t.type === "tool-call") s({
130
+ type: "activity",
131
+ text: t.toolName
132
+ });
133
+ else if (t.type === "error") throw t.error;
134
+ else if (t.type === "abort" && o) throw a.signal.reason ?? /* @__PURE__ */ Error("Turn aborted");
135
+ if (o && a.signal.aborted) throw a.signal.reason;
136
+ m.push(n, ...await e.responseMessages), s({ type: "done" });
137
+ } catch (e) {
138
+ let t = r?.summary();
139
+ t && m.push(n, {
140
+ role: "assistant",
141
+ content: t
142
+ }), s({
143
+ type: "error",
144
+ text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}${t ? `\n\n${t}` : ""}`
145
+ });
146
+ } finally {
147
+ clearTimeout(h), i.removeEventListener("abort", c);
148
+ }
149
+ }, s({
150
+ type: "images",
151
+ enabled: t.readsImages
152
+ }), s({
153
+ type: "availability",
154
+ available: !0
155
+ });
156
+ };
157
+ //#endregion
158
+ export { r as n, t as r, i as t };
@@ -0,0 +1,143 @@
1
+ var e = ({ output: e }) => ({
2
+ type: "content",
3
+ value: e.content.map((e) => e.type === "text" ? {
4
+ type: "text",
5
+ text: e.text
6
+ } : {
7
+ type: "file",
8
+ mediaType: e.mimeType,
9
+ data: {
10
+ type: "data",
11
+ data: e.data
12
+ }
13
+ })
14
+ }), t = (t, n, r) => Object.fromEntries(t.map(({ name: t, description: i, inputSchema: a, annotations: o }) => {
15
+ let s = () => a;
16
+ return [t, {
17
+ type: "dynamic",
18
+ ...o && { annotations: o },
19
+ description: i,
20
+ inputSchema: { "~standard": {
21
+ version: 1,
22
+ vendor: r,
23
+ validate: (e) => ({ value: e }),
24
+ jsonSchema: {
25
+ input: s,
26
+ output: s
27
+ }
28
+ } },
29
+ execute: (e) => n(t, e).catch((e) => ({
30
+ content: [{
31
+ type: "text",
32
+ text: e instanceof Error ? e.message : String(e)
33
+ }],
34
+ isError: !0
35
+ })),
36
+ toModelOutput: e
37
+ }];
38
+ })), n = (e) => `https://esm.sh/${e}?deps=zod@4.6.5`, r = async ({ provider: e, model: t, apiKey: r, baseUrl: i, chatCompletions: a, reasoningEffort: o }) => {
39
+ switch (e) {
40
+ case "azure": {
41
+ let { createAzure: e } = await import(n("@ai-sdk/azure@4.0.85")), s = e({
42
+ apiKey: r,
43
+ baseURL: i
44
+ });
45
+ return {
46
+ languageModel: a ? s.chat(t) : s(t),
47
+ providerOptions: o ? { azure: { reasoningEffort: o } } : void 0
48
+ };
49
+ }
50
+ case "mistral": {
51
+ let { createMistral: e } = await import(n("@ai-sdk/mistral@4.0.54"));
52
+ return { languageModel: e({ apiKey: r })(t) };
53
+ }
54
+ case "anthropic": {
55
+ let { createAnthropic: e } = await import(n("@ai-sdk/anthropic@4.0.68"));
56
+ return { languageModel: e({
57
+ apiKey: r,
58
+ headers: { "anthropic-dangerous-direct-browser-access": "true" }
59
+ })(t) };
60
+ }
61
+ case "google": {
62
+ let { createGoogleGenerativeAI: e } = await import(n("@ai-sdk/google@4.0.85"));
63
+ return { languageModel: e({ apiKey: r })(t) };
64
+ }
65
+ default: throw Error(`Unknown provider "${e}" - supported: azure, mistral, anthropic, google`);
66
+ }
67
+ }, i = async (e, t, i, a, o) => {
68
+ let s = (t) => e.planningAssistantOutput(t), c;
69
+ try {
70
+ c = await Promise.all([
71
+ import(n("ai@7.0.122")),
72
+ r(t),
73
+ a()
74
+ ]);
75
+ } catch (e) {
76
+ s({
77
+ type: "availability",
78
+ available: !1,
79
+ text: String(e)
80
+ });
81
+ return;
82
+ }
83
+ let [{ streamText: l, stepCountIs: u }, d, { prompts: f, tools: p }] = c, m = [];
84
+ e.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: t }) => {
85
+ let n = {
86
+ role: "user",
87
+ content: [{
88
+ type: "text",
89
+ text: e || f.imagePrompt
90
+ }, ...t.map((e) => ({
91
+ type: "file",
92
+ data: e,
93
+ mediaType: "image/jpeg"
94
+ }))]
95
+ }, r = o?.recovery(p), a = new AbortController(), c = () => a.abort(i.reason);
96
+ i.addEventListener("abort", c, { once: !0 }), i.aborted && c();
97
+ let h = o ? setTimeout(() => a.abort(/* @__PURE__ */ Error("The configurator assistant turn exceeded five minutes.")), o.timeoutMs) : void 0;
98
+ try {
99
+ let e = l({
100
+ model: d.languageModel,
101
+ providerOptions: d.providerOptions,
102
+ instructions: f.systemPrompt,
103
+ messages: [...m, n],
104
+ tools: r?.tools ?? p,
105
+ stopWhen: u(16),
106
+ abortSignal: o ? a.signal : i,
107
+ prepareStep: ({ stepNumber: e }) => e === 15 ? { toolChoice: "none" } : void 0
108
+ });
109
+ for await (let t of e.stream) if (t.type === "text-delta") s({
110
+ type: "text",
111
+ text: t.text
112
+ });
113
+ else if (t.type === "tool-call") s({
114
+ type: "activity",
115
+ text: t.toolName
116
+ });
117
+ else {
118
+ if (t.type === "error") throw t.error;
119
+ if (t.type === "abort" && o) throw a.signal.reason ?? /* @__PURE__ */ Error("Turn aborted");
120
+ }
121
+ if (o && a.signal.aborted) throw a.signal.reason;
122
+ m.push(n, ...await e.responseMessages), s({ type: "done" });
123
+ } catch (e) {
124
+ let t = r?.summary();
125
+ t && m.push(n, {
126
+ role: "assistant",
127
+ content: t
128
+ }), s({
129
+ type: "error",
130
+ text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}${t ? `\n\n${t}` : ""}`
131
+ });
132
+ } finally {
133
+ clearTimeout(h), i.removeEventListener("abort", c);
134
+ }
135
+ }, s({
136
+ type: "images",
137
+ enabled: t.readsImages
138
+ }), s({
139
+ type: "availability",
140
+ available: !0
141
+ });
142
+ };
143
+ export { r as n, t as r, i as t };