@athenaintel/react 0.10.25 → 0.10.27

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment as Fragment$1, jsxs } from "react/jsx-runtime";
2
- import { bindExternalStoreMessage, getExternalStoreMessages, INTERNAL, useAssistantTransportRuntime, useAuiState, useAssistantRuntime, useThread, useThreadList, unstable_useRemoteThreadListRuntime, Tools, useAui, AssistantRuntimeProvider, useComposerRuntime, useScrollLock, ActionBarPrimitive, AuiIf, ActionBarMorePrimitive, MessagePrimitive, ThreadPrimitive, ComposerPrimitive, ErrorPrimitive, ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
2
+ import { bindExternalStoreMessage, getExternalStoreMessages, INTERNAL, useAssistantTransportRuntime, useAuiState, useAssistantRuntime, useThread, useThreadList, unstable_useRemoteThreadListRuntime, Tools, useAui, AssistantRuntimeProvider, useComposerRuntime, MessagePartPrimitive, MessagePrimitive, useScrollLock, ActionBarPrimitive, AuiIf, ActionBarMorePrimitive, ThreadPrimitive, ComposerPrimitive, ErrorPrimitive, ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
3
3
  import * as React from "react";
4
4
  import React__default, { useMemo, useState, useRef, useEffect, useLayoutEffect, useContext, createContext, useCallback, useDebugValue, forwardRef, createRef, memo, createElement, version as version$1, useImperativeHandle } from "react";
5
5
  import { A as AthenaAuthContext } from "./AthenaAuthContext-DQsdayH2.js";
@@ -3896,407 +3896,6 @@ function cn(...inputs) {
3896
3896
  function isRecord(value) {
3897
3897
  return typeof value === "object" && value !== null && !Array.isArray(value);
3898
3898
  }
3899
- const { fromThreadMessageLike, getAutoStatus } = INTERNAL;
3900
- const joinExternalMessages = (messages) => {
3901
- var _a2;
3902
- const assistantMessage = {
3903
- role: "assistant",
3904
- content: []
3905
- };
3906
- let firstAssistantId;
3907
- let lastAssistantId;
3908
- let assistantMessageCount = 0;
3909
- for (const output of messages) {
3910
- if (!output || !("role" in output)) {
3911
- continue;
3912
- }
3913
- if (output.role === "tool") {
3914
- const toolCallIdx = assistantMessage.content.findIndex(
3915
- (c) => c.type === "tool-call" && c.toolCallId === output.toolCallId
3916
- );
3917
- if (toolCallIdx !== -1) {
3918
- const toolCall = assistantMessage.content[toolCallIdx];
3919
- if (output.toolName != null) {
3920
- if (toolCall.toolName !== output.toolName)
3921
- console.error(
3922
- Error(
3923
- `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`
3924
- )
3925
- );
3926
- }
3927
- const { messages: existingMessages, ...toolCallRest } = toolCall;
3928
- const updatedToolCall = {
3929
- ...toolCallRest,
3930
- result: output.result,
3931
- artifact: output.artifact,
3932
- isError: output.isError,
3933
- ...(output.messages ?? existingMessages) !== void 0 && {
3934
- messages: output.messages ?? existingMessages
3935
- }
3936
- };
3937
- bindExternalStoreMessage(updatedToolCall, [
3938
- ...getExternalStoreMessages(toolCallRest),
3939
- output
3940
- ]);
3941
- assistantMessage.content[toolCallIdx] = updatedToolCall;
3942
- } else {
3943
- console.warn(
3944
- `Tool call ${output.toolCallId} ${output.toolName} not found in assistant message`
3945
- );
3946
- }
3947
- } else {
3948
- const role = output.role;
3949
- const rawContent = typeof output.content === "string" ? [{ type: "text", text: output.content }] : Array.isArray(output.content) ? output.content : [];
3950
- const content = rawContent.flatMap((c) => {
3951
- if (!c || typeof c !== "object") {
3952
- return [];
3953
- }
3954
- const mapped = { ...c };
3955
- bindExternalStoreMessage(mapped, output);
3956
- return [mapped];
3957
- });
3958
- switch (role) {
3959
- case "system":
3960
- case "user":
3961
- return {
3962
- ...output,
3963
- content
3964
- };
3965
- case "assistant":
3966
- if (output.id) {
3967
- lastAssistantId = output.id;
3968
- assistantMessageCount++;
3969
- }
3970
- if (assistantMessage.content.length === 0) {
3971
- firstAssistantId = output.id;
3972
- assistantMessage.createdAt ?? (assistantMessage.createdAt = output.createdAt);
3973
- assistantMessage.status ?? (assistantMessage.status = output.status);
3974
- if (output.attachments) {
3975
- assistantMessage.attachments = [
3976
- ...assistantMessage.attachments ?? [],
3977
- ...output.attachments
3978
- ];
3979
- }
3980
- if (output.metadata) {
3981
- assistantMessage.metadata ?? (assistantMessage.metadata = {});
3982
- if (output.metadata.unstable_state) {
3983
- assistantMessage.metadata.unstable_state = output.metadata.unstable_state;
3984
- }
3985
- if (output.metadata.unstable_annotations) {
3986
- assistantMessage.metadata.unstable_annotations = [
3987
- ...assistantMessage.metadata.unstable_annotations ?? [],
3988
- ...output.metadata.unstable_annotations
3989
- ];
3990
- }
3991
- if (output.metadata.unstable_data) {
3992
- assistantMessage.metadata.unstable_data = [
3993
- ...assistantMessage.metadata.unstable_data ?? [],
3994
- ...output.metadata.unstable_data
3995
- ];
3996
- }
3997
- if (output.metadata.steps) {
3998
- assistantMessage.metadata.steps = [
3999
- ...assistantMessage.metadata.steps ?? [],
4000
- ...output.metadata.steps
4001
- ];
4002
- }
4003
- if (output.metadata.custom) {
4004
- assistantMessage.metadata.custom = {
4005
- ...assistantMessage.metadata.custom ?? {},
4006
- ...output.metadata.custom
4007
- };
4008
- }
4009
- if (output.metadata.submittedFeedback) {
4010
- assistantMessage.metadata.submittedFeedback = output.metadata.submittedFeedback;
4011
- }
4012
- }
4013
- } else {
4014
- if ((_a2 = output.metadata) == null ? void 0 : _a2.custom) {
4015
- assistantMessage.metadata ?? (assistantMessage.metadata = {});
4016
- assistantMessage.metadata.custom = {
4017
- ...assistantMessage.metadata.custom ?? {},
4018
- ...output.metadata.custom
4019
- };
4020
- }
4021
- }
4022
- assistantMessage.content.push(...content);
4023
- break;
4024
- default: {
4025
- const unsupportedRole = role;
4026
- throw new Error(`Unknown message role: ${unsupportedRole}`);
4027
- }
4028
- }
4029
- }
4030
- }
4031
- assistantMessage.id = lastAssistantId ?? firstAssistantId;
4032
- if (assistantMessageCount > 1) {
4033
- assistantMessage.metadata ?? (assistantMessage.metadata = {});
4034
- assistantMessage.metadata.custom = {
4035
- ...assistantMessage.metadata.custom ?? {},
4036
- _firstMessageId: firstAssistantId,
4037
- _lastMessageId: lastAssistantId,
4038
- _joinedMessageCount: assistantMessageCount
4039
- };
4040
- }
4041
- return assistantMessage;
4042
- };
4043
- const chunkExternalMessages = (callbackResults, _joinStrategy) => {
4044
- var _a2;
4045
- const results = [];
4046
- let isAssistant = false;
4047
- let pendingNone = false;
4048
- let inputs = [];
4049
- let outputs = [];
4050
- const flush2 = () => {
4051
- if (outputs.length) {
4052
- results.push({
4053
- inputs,
4054
- outputs
4055
- });
4056
- }
4057
- inputs = [];
4058
- outputs = [];
4059
- isAssistant = false;
4060
- pendingNone = false;
4061
- };
4062
- for (const callbackResult of callbackResults) {
4063
- for (const output of callbackResult.outputs) {
4064
- if (!output || !("role" in output)) {
4065
- continue;
4066
- }
4067
- if (pendingNone && output.role !== "tool" || !isAssistant || output.role === "user" || output.role === "system") {
4068
- flush2();
4069
- }
4070
- isAssistant = output.role === "assistant" || output.role === "tool";
4071
- if (inputs.at(-1) !== callbackResult.input) {
4072
- inputs.push(callbackResult.input);
4073
- }
4074
- outputs.push(output);
4075
- if (output.role === "assistant" && (((_a2 = output.convertConfig) == null ? void 0 : _a2.joinStrategy) === "none" || _joinStrategy === "none")) {
4076
- pendingNone = true;
4077
- }
4078
- }
4079
- }
4080
- flush2();
4081
- return results;
4082
- };
4083
- const convertExternalMessages = (messages, callback, isRunning, metadata) => {
4084
- const callbackResults = [];
4085
- for (const message of messages) {
4086
- const output = callback(message, metadata);
4087
- const rawOutputs = Array.isArray(output) ? output : [output];
4088
- const outputs = rawOutputs.filter(
4089
- (candidate) => candidate != null
4090
- );
4091
- if (outputs.length === 0) {
4092
- continue;
4093
- }
4094
- const result = { input: message, outputs };
4095
- callbackResults.push(result);
4096
- }
4097
- const chunks = chunkExternalMessages(callbackResults);
4098
- return chunks.map((message, idx) => {
4099
- const isLast = idx === chunks.length - 1;
4100
- const joined = joinExternalMessages(message.outputs);
4101
- const hasPendingToolCalls = typeof joined.content === "object" && joined.content.some((c) => c.type === "tool-call" && c.result === void 0);
4102
- const autoStatus = getAutoStatus(isLast, isRunning, hasPendingToolCalls, hasPendingToolCalls);
4103
- const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
4104
- bindExternalStoreMessage(newMessage, message.inputs);
4105
- return newMessage;
4106
- });
4107
- };
4108
- const warnedMessagePartTypes = /* @__PURE__ */ new Set();
4109
- const warnForUnknownMessagePartType = (type) => {
4110
- if (warnedMessagePartTypes.has(type)) return;
4111
- warnedMessagePartTypes.add(type);
4112
- console.warn(`Unknown message part type: ${type}`);
4113
- };
4114
- const contentToParts = (content) => {
4115
- if (typeof content === "string") return [{ type: "text", text: content }];
4116
- return content.flatMap((part) => {
4117
- if (!part || typeof part !== "object" || !("type" in part)) {
4118
- return [];
4119
- }
4120
- const type = part.type;
4121
- switch (type) {
4122
- case "text":
4123
- return [{ type: "text", text: part.text }];
4124
- case "text_delta":
4125
- return [{ type: "text", text: part.text }];
4126
- case "image_url":
4127
- if (typeof part.image_url === "string") {
4128
- return [{ type: "image", image: part.image_url }];
4129
- }
4130
- return [{
4131
- type: "image",
4132
- image: part.image_url.url
4133
- }];
4134
- case "thinking":
4135
- return [{ type: "reasoning", text: part.thinking }];
4136
- case "reasoning":
4137
- return [{
4138
- type: "reasoning",
4139
- text: part.summary.map((s) => s.text).join("\n\n\n")
4140
- }];
4141
- case "tool_use":
4142
- return [];
4143
- case "input_json_delta":
4144
- return [];
4145
- default:
4146
- warnForUnknownMessagePartType(type);
4147
- return [];
4148
- }
4149
- });
4150
- };
4151
- const getNumberAtPath = (value, path) => {
4152
- let current = value;
4153
- for (const segment of path) {
4154
- if (!isRecord(current)) {
4155
- return void 0;
4156
- }
4157
- current = current[segment];
4158
- }
4159
- return typeof current === "number" && Number.isFinite(current) ? current : void 0;
4160
- };
4161
- const extractReasoningTokens = ({
4162
- usageMetadata,
4163
- responseMetadata
4164
- }) => {
4165
- const rawReasoningTokens = getNumberAtPath(usageMetadata, ["output_token_details", "reasoning"]) ?? getNumberAtPath(usageMetadata, ["output_token_details", "reasoning_tokens"]) ?? getNumberAtPath(usageMetadata, ["reasoning_tokens"]) ?? getNumberAtPath(responseMetadata, ["output_token_details", "reasoning"]) ?? getNumberAtPath(responseMetadata, ["output_token_details", "reasoning_tokens"]) ?? getNumberAtPath(responseMetadata, ["token_usage", "output_token_details", "reasoning"]) ?? getNumberAtPath(responseMetadata, ["token_usage", "output_token_details", "reasoning_tokens"]);
4166
- return rawReasoningTokens !== void 0 && rawReasoningTokens > 0 ? rawReasoningTokens : void 0;
4167
- };
4168
- const buildCustomMetadata = ({
4169
- additionalKwargs,
4170
- usageMetadata,
4171
- responseMetadata
4172
- }) => {
4173
- const customMetadata = additionalKwargs ? { ...additionalKwargs } : {};
4174
- const reasoningTokens = extractReasoningTokens({ usageMetadata, responseMetadata });
4175
- const existingAthenaMetadata = isRecord(customMetadata._athena) ? customMetadata._athena : void 0;
4176
- const athenaMetadata = {
4177
- ...existingAthenaMetadata ?? {}
4178
- };
4179
- if (usageMetadata) {
4180
- athenaMetadata.rawUsageMetadata = usageMetadata;
4181
- }
4182
- if (responseMetadata) {
4183
- athenaMetadata.rawResponseMetadata = responseMetadata;
4184
- }
4185
- if (reasoningTokens !== void 0) {
4186
- athenaMetadata.reasoningTokens = reasoningTokens;
4187
- }
4188
- if (Object.keys(athenaMetadata).length > 0) {
4189
- customMetadata._athena = athenaMetadata;
4190
- }
4191
- return Object.keys(customMetadata).length > 0 ? customMetadata : void 0;
4192
- };
4193
- const convertLangChainMessage = (message) => {
4194
- var _a2, _b, _c;
4195
- switch (message.type) {
4196
- case "system": {
4197
- const customMetadata = buildCustomMetadata({
4198
- additionalKwargs: message.additional_kwargs
4199
- });
4200
- return {
4201
- role: "system",
4202
- id: message.id,
4203
- content: [{ type: "text", text: message.content }],
4204
- ...customMetadata && {
4205
- metadata: {
4206
- custom: customMetadata
4207
- }
4208
- }
4209
- };
4210
- }
4211
- case "human": {
4212
- const customMetadata = buildCustomMetadata({
4213
- additionalKwargs: message.additional_kwargs
4214
- });
4215
- return {
4216
- role: "user",
4217
- id: message.id,
4218
- content: contentToParts(message.content),
4219
- ...customMetadata && {
4220
- metadata: {
4221
- custom: customMetadata
4222
- }
4223
- }
4224
- };
4225
- }
4226
- case "ai": {
4227
- const customMetadata = buildCustomMetadata({
4228
- additionalKwargs: message.additional_kwargs,
4229
- usageMetadata: message.usage_metadata,
4230
- responseMetadata: message.response_metadata
4231
- });
4232
- const toolCallParts = ((_a2 = message.tool_calls) == null ? void 0 : _a2.map((chunk) => {
4233
- var _a3, _b2;
4234
- let argsText;
4235
- if (typeof chunk.args === "string") {
4236
- argsText = chunk.args;
4237
- } else {
4238
- const rawString = chunk.partial_json ?? ((_b2 = (_a3 = message.tool_call_chunks) == null ? void 0 : _a3.find((c) => c.id === chunk.id)) == null ? void 0 : _b2.args) ?? JSON.stringify(chunk.args);
4239
- argsText = rawString;
4240
- }
4241
- return {
4242
- type: "tool-call",
4243
- toolCallId: chunk.id,
4244
- toolName: chunk.name,
4245
- args: typeof chunk.args === "string" ? parsePartialJsonObject(argsText) ?? {} : chunk.args,
4246
- argsText
4247
- };
4248
- })) ?? [];
4249
- const normalizedContent = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content;
4250
- const allContent = [
4251
- (_b = message.additional_kwargs) == null ? void 0 : _b.reasoning,
4252
- ...normalizedContent,
4253
- ...((_c = message.additional_kwargs) == null ? void 0 : _c.tool_outputs) ?? []
4254
- ].filter((c) => c != null);
4255
- return {
4256
- role: "assistant",
4257
- id: message.id,
4258
- content: [...contentToParts(allContent), ...toolCallParts],
4259
- ...message.status && { status: message.status },
4260
- ...customMetadata && {
4261
- metadata: {
4262
- custom: customMetadata
4263
- }
4264
- }
4265
- };
4266
- }
4267
- case "tool": {
4268
- return {
4269
- role: "tool",
4270
- toolName: message.name,
4271
- toolCallId: message.tool_call_id,
4272
- result: message.content,
4273
- artifact: message.artifact,
4274
- isError: message.status === "error"
4275
- };
4276
- }
4277
- default:
4278
- return null;
4279
- }
4280
- };
4281
- const convertLangChainToThreadMessages = (messages, isRunning = false, metadata = {}) => {
4282
- const validToolCallIds = /* @__PURE__ */ new Set();
4283
- for (const message of messages) {
4284
- if (message.type === "ai" && message.tool_calls) {
4285
- for (const tc of message.tool_calls) {
4286
- if (tc.id) {
4287
- validToolCallIds.add(tc.id);
4288
- }
4289
- }
4290
- }
4291
- }
4292
- const filteredMessages = messages.filter((message) => {
4293
- if (message.type === "tool" && message.tool_call_id && !validToolCallIds.has(message.tool_call_id)) {
4294
- return false;
4295
- }
4296
- return true;
4297
- });
4298
- return convertExternalMessages(filteredMessages, convertLangChainMessage, isRunning, metadata);
4299
- };
4300
3899
  function $constructor(name, initializer2, params) {
4301
3900
  function init2(inst, def) {
4302
3901
  if (!inst._zod) {
@@ -8464,6 +8063,451 @@ const parseLangGraphState = (state) => {
8464
8063
  }
8465
8064
  return result;
8466
8065
  };
8066
+ const { fromThreadMessageLike, getAutoStatus } = INTERNAL;
8067
+ const joinExternalMessages = (messages) => {
8068
+ var _a2;
8069
+ const assistantMessage = {
8070
+ role: "assistant",
8071
+ content: []
8072
+ };
8073
+ let firstAssistantId;
8074
+ let lastAssistantId;
8075
+ let assistantMessageCount = 0;
8076
+ for (const output of messages) {
8077
+ if (!output || !("role" in output)) {
8078
+ continue;
8079
+ }
8080
+ if (output.role === "tool") {
8081
+ const toolCallIdx = assistantMessage.content.findIndex(
8082
+ (c) => c.type === "tool-call" && c.toolCallId === output.toolCallId
8083
+ );
8084
+ if (toolCallIdx !== -1) {
8085
+ const toolCall = assistantMessage.content[toolCallIdx];
8086
+ if (output.toolName != null) {
8087
+ if (toolCall.toolName !== output.toolName)
8088
+ console.error(
8089
+ Error(
8090
+ `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`
8091
+ )
8092
+ );
8093
+ }
8094
+ const { messages: existingMessages, ...toolCallRest } = toolCall;
8095
+ const updatedToolCall = {
8096
+ ...toolCallRest,
8097
+ result: output.result,
8098
+ artifact: output.artifact,
8099
+ isError: output.isError,
8100
+ ...(output.messages ?? existingMessages) !== void 0 && {
8101
+ messages: output.messages ?? existingMessages
8102
+ }
8103
+ };
8104
+ bindExternalStoreMessage(updatedToolCall, [
8105
+ ...getExternalStoreMessages(toolCallRest),
8106
+ output
8107
+ ]);
8108
+ assistantMessage.content[toolCallIdx] = updatedToolCall;
8109
+ } else {
8110
+ console.warn(
8111
+ `Tool call ${output.toolCallId} ${output.toolName} not found in assistant message`
8112
+ );
8113
+ }
8114
+ } else {
8115
+ const role = output.role;
8116
+ const rawContent = typeof output.content === "string" ? [{ type: "text", text: output.content }] : Array.isArray(output.content) ? output.content : [];
8117
+ const content = rawContent.flatMap((c) => {
8118
+ if (!c || typeof c !== "object") {
8119
+ return [];
8120
+ }
8121
+ const mapped = { ...c };
8122
+ bindExternalStoreMessage(mapped, output);
8123
+ return [mapped];
8124
+ });
8125
+ switch (role) {
8126
+ case "system":
8127
+ case "user":
8128
+ return {
8129
+ ...output,
8130
+ content
8131
+ };
8132
+ case "assistant":
8133
+ if (output.id) {
8134
+ lastAssistantId = output.id;
8135
+ assistantMessageCount++;
8136
+ }
8137
+ if (assistantMessage.content.length === 0) {
8138
+ firstAssistantId = output.id;
8139
+ assistantMessage.createdAt ?? (assistantMessage.createdAt = output.createdAt);
8140
+ assistantMessage.status ?? (assistantMessage.status = output.status);
8141
+ if (output.attachments) {
8142
+ assistantMessage.attachments = [
8143
+ ...assistantMessage.attachments ?? [],
8144
+ ...output.attachments
8145
+ ];
8146
+ }
8147
+ if (output.metadata) {
8148
+ assistantMessage.metadata ?? (assistantMessage.metadata = {});
8149
+ if (output.metadata.unstable_state) {
8150
+ assistantMessage.metadata.unstable_state = output.metadata.unstable_state;
8151
+ }
8152
+ if (output.metadata.unstable_annotations) {
8153
+ assistantMessage.metadata.unstable_annotations = [
8154
+ ...assistantMessage.metadata.unstable_annotations ?? [],
8155
+ ...output.metadata.unstable_annotations
8156
+ ];
8157
+ }
8158
+ if (output.metadata.unstable_data) {
8159
+ assistantMessage.metadata.unstable_data = [
8160
+ ...assistantMessage.metadata.unstable_data ?? [],
8161
+ ...output.metadata.unstable_data
8162
+ ];
8163
+ }
8164
+ if (output.metadata.steps) {
8165
+ assistantMessage.metadata.steps = [
8166
+ ...assistantMessage.metadata.steps ?? [],
8167
+ ...output.metadata.steps
8168
+ ];
8169
+ }
8170
+ if (output.metadata.custom) {
8171
+ assistantMessage.metadata.custom = {
8172
+ ...assistantMessage.metadata.custom ?? {},
8173
+ ...output.metadata.custom
8174
+ };
8175
+ }
8176
+ if (output.metadata.submittedFeedback) {
8177
+ assistantMessage.metadata.submittedFeedback = output.metadata.submittedFeedback;
8178
+ }
8179
+ }
8180
+ } else {
8181
+ if ((_a2 = output.metadata) == null ? void 0 : _a2.custom) {
8182
+ assistantMessage.metadata ?? (assistantMessage.metadata = {});
8183
+ assistantMessage.metadata.custom = {
8184
+ ...assistantMessage.metadata.custom ?? {},
8185
+ ...output.metadata.custom
8186
+ };
8187
+ }
8188
+ }
8189
+ assistantMessage.content.push(...content);
8190
+ break;
8191
+ default: {
8192
+ const unsupportedRole = role;
8193
+ throw new Error(`Unknown message role: ${unsupportedRole}`);
8194
+ }
8195
+ }
8196
+ }
8197
+ }
8198
+ assistantMessage.id = lastAssistantId ?? firstAssistantId;
8199
+ if (assistantMessageCount > 1) {
8200
+ assistantMessage.metadata ?? (assistantMessage.metadata = {});
8201
+ assistantMessage.metadata.custom = {
8202
+ ...assistantMessage.metadata.custom ?? {},
8203
+ _firstMessageId: firstAssistantId,
8204
+ _lastMessageId: lastAssistantId,
8205
+ _joinedMessageCount: assistantMessageCount
8206
+ };
8207
+ }
8208
+ return assistantMessage;
8209
+ };
8210
+ const chunkExternalMessages = (callbackResults, _joinStrategy) => {
8211
+ var _a2;
8212
+ const results = [];
8213
+ let isAssistant = false;
8214
+ let pendingNone = false;
8215
+ let inputs = [];
8216
+ let outputs = [];
8217
+ const flush2 = () => {
8218
+ if (outputs.length) {
8219
+ results.push({
8220
+ inputs,
8221
+ outputs
8222
+ });
8223
+ }
8224
+ inputs = [];
8225
+ outputs = [];
8226
+ isAssistant = false;
8227
+ pendingNone = false;
8228
+ };
8229
+ for (const callbackResult of callbackResults) {
8230
+ for (const output of callbackResult.outputs) {
8231
+ if (!output || !("role" in output)) {
8232
+ continue;
8233
+ }
8234
+ if (pendingNone && output.role !== "tool" || !isAssistant || output.role === "user" || output.role === "system") {
8235
+ flush2();
8236
+ }
8237
+ isAssistant = output.role === "assistant" || output.role === "tool";
8238
+ if (inputs.at(-1) !== callbackResult.input) {
8239
+ inputs.push(callbackResult.input);
8240
+ }
8241
+ outputs.push(output);
8242
+ if (output.role === "assistant" && (((_a2 = output.convertConfig) == null ? void 0 : _a2.joinStrategy) === "none" || _joinStrategy === "none")) {
8243
+ pendingNone = true;
8244
+ }
8245
+ }
8246
+ }
8247
+ flush2();
8248
+ return results;
8249
+ };
8250
+ const convertExternalMessages = (messages, callback, isRunning, metadata) => {
8251
+ const callbackResults = [];
8252
+ for (const message of messages) {
8253
+ const output = callback(message, metadata);
8254
+ const rawOutputs = Array.isArray(output) ? output : [output];
8255
+ const outputs = rawOutputs.filter(
8256
+ (candidate) => candidate != null
8257
+ );
8258
+ if (outputs.length === 0) {
8259
+ continue;
8260
+ }
8261
+ const result = { input: message, outputs };
8262
+ callbackResults.push(result);
8263
+ }
8264
+ const chunks = chunkExternalMessages(callbackResults);
8265
+ return chunks.map((message, idx) => {
8266
+ const isLast = idx === chunks.length - 1;
8267
+ const joined = joinExternalMessages(message.outputs);
8268
+ const hasPendingToolCalls = typeof joined.content === "object" && joined.content.some((c) => c.type === "tool-call" && c.result === void 0);
8269
+ const autoStatus = getAutoStatus(isLast, isRunning, hasPendingToolCalls, hasPendingToolCalls);
8270
+ const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
8271
+ bindExternalStoreMessage(newMessage, message.inputs);
8272
+ return newMessage;
8273
+ });
8274
+ };
8275
+ const PTC_SUBCALL_DID_NOT_COMPLETE_MESSAGE = "Sub-call did not complete before the parent tool returned.";
8276
+ const autoCloseInFlightSubgraphMessages = (msgs) => {
8277
+ const beginIds = /* @__PURE__ */ new Set();
8278
+ const endIds = /* @__PURE__ */ new Set();
8279
+ for (const message of msgs) {
8280
+ if (!isRecord(message)) continue;
8281
+ if (message.type === "ai" && Array.isArray(message.tool_calls)) {
8282
+ for (const toolCall of message.tool_calls) {
8283
+ if (!isRecord(toolCall)) continue;
8284
+ const id = toolCall.id;
8285
+ if (typeof id === "string") beginIds.add(id);
8286
+ }
8287
+ } else if (message.type === "tool" && typeof message.tool_call_id === "string") {
8288
+ endIds.add(message.tool_call_id);
8289
+ }
8290
+ }
8291
+ const unmatchedIds = [...beginIds].filter((id) => !endIds.has(id));
8292
+ if (unmatchedIds.length === 0) return [...msgs];
8293
+ return [
8294
+ ...msgs,
8295
+ ...unmatchedIds.map((toolCallId) => ({
8296
+ type: "tool",
8297
+ tool_call_id: toolCallId,
8298
+ content: PTC_SUBCALL_DID_NOT_COMPLETE_MESSAGE,
8299
+ status: "error"
8300
+ }))
8301
+ ];
8302
+ };
8303
+ const warnedMessagePartTypes = /* @__PURE__ */ new Set();
8304
+ const warnForUnknownMessagePartType = (type) => {
8305
+ if (warnedMessagePartTypes.has(type)) return;
8306
+ warnedMessagePartTypes.add(type);
8307
+ console.warn(`Unknown message part type: ${type}`);
8308
+ };
8309
+ const contentToParts = (content) => {
8310
+ if (typeof content === "string") return [{ type: "text", text: content }];
8311
+ return content.flatMap((part) => {
8312
+ if (!part || typeof part !== "object" || !("type" in part)) {
8313
+ return [];
8314
+ }
8315
+ const type = part.type;
8316
+ switch (type) {
8317
+ case "text":
8318
+ return [{ type: "text", text: part.text }];
8319
+ case "text_delta":
8320
+ return [{ type: "text", text: part.text }];
8321
+ case "image_url":
8322
+ if (typeof part.image_url === "string") {
8323
+ return [{ type: "image", image: part.image_url }];
8324
+ }
8325
+ return [{
8326
+ type: "image",
8327
+ image: part.image_url.url
8328
+ }];
8329
+ case "thinking":
8330
+ return [{ type: "reasoning", text: part.thinking }];
8331
+ case "reasoning":
8332
+ return [{
8333
+ type: "reasoning",
8334
+ text: part.summary.map((s) => s.text).join("\n\n\n")
8335
+ }];
8336
+ case "tool_use":
8337
+ return [];
8338
+ case "input_json_delta":
8339
+ return [];
8340
+ default:
8341
+ warnForUnknownMessagePartType(type);
8342
+ return [];
8343
+ }
8344
+ });
8345
+ };
8346
+ const getNumberAtPath = (value, path) => {
8347
+ let current = value;
8348
+ for (const segment of path) {
8349
+ if (!isRecord(current)) {
8350
+ return void 0;
8351
+ }
8352
+ current = current[segment];
8353
+ }
8354
+ return typeof current === "number" && Number.isFinite(current) ? current : void 0;
8355
+ };
8356
+ const extractReasoningTokens = ({
8357
+ usageMetadata,
8358
+ responseMetadata
8359
+ }) => {
8360
+ const rawReasoningTokens = getNumberAtPath(usageMetadata, ["output_token_details", "reasoning"]) ?? getNumberAtPath(usageMetadata, ["output_token_details", "reasoning_tokens"]) ?? getNumberAtPath(usageMetadata, ["reasoning_tokens"]) ?? getNumberAtPath(responseMetadata, ["output_token_details", "reasoning"]) ?? getNumberAtPath(responseMetadata, ["output_token_details", "reasoning_tokens"]) ?? getNumberAtPath(responseMetadata, ["token_usage", "output_token_details", "reasoning"]) ?? getNumberAtPath(responseMetadata, ["token_usage", "output_token_details", "reasoning_tokens"]);
8361
+ return rawReasoningTokens !== void 0 && rawReasoningTokens > 0 ? rawReasoningTokens : void 0;
8362
+ };
8363
+ const buildCustomMetadata = ({
8364
+ additionalKwargs,
8365
+ usageMetadata,
8366
+ responseMetadata
8367
+ }) => {
8368
+ const customMetadata = additionalKwargs ? { ...additionalKwargs } : {};
8369
+ const reasoningTokens = extractReasoningTokens({ usageMetadata, responseMetadata });
8370
+ const existingAthenaMetadata = isRecord(customMetadata._athena) ? customMetadata._athena : void 0;
8371
+ const athenaMetadata = {
8372
+ ...existingAthenaMetadata ?? {}
8373
+ };
8374
+ if (usageMetadata) {
8375
+ athenaMetadata.rawUsageMetadata = usageMetadata;
8376
+ }
8377
+ if (responseMetadata) {
8378
+ athenaMetadata.rawResponseMetadata = responseMetadata;
8379
+ }
8380
+ if (reasoningTokens !== void 0) {
8381
+ athenaMetadata.reasoningTokens = reasoningTokens;
8382
+ }
8383
+ if (Object.keys(athenaMetadata).length > 0) {
8384
+ customMetadata._athena = athenaMetadata;
8385
+ }
8386
+ return Object.keys(customMetadata).length > 0 ? customMetadata : void 0;
8387
+ };
8388
+ const getSubgraphMessages = (artifact) => {
8389
+ if (!isRecord(artifact)) return void 0;
8390
+ const subgraphState = artifact.subgraph_state;
8391
+ if (!isRecord(subgraphState)) return void 0;
8392
+ const messages = subgraphState.messages;
8393
+ return Array.isArray(messages) && messages.length > 0 ? messages : void 0;
8394
+ };
8395
+ const convertLangChainMessage = (message) => {
8396
+ var _a2, _b, _c;
8397
+ switch (message.type) {
8398
+ case "system": {
8399
+ const customMetadata = buildCustomMetadata({
8400
+ additionalKwargs: message.additional_kwargs
8401
+ });
8402
+ return {
8403
+ role: "system",
8404
+ id: message.id,
8405
+ content: [{ type: "text", text: message.content }],
8406
+ ...customMetadata && {
8407
+ metadata: {
8408
+ custom: customMetadata
8409
+ }
8410
+ }
8411
+ };
8412
+ }
8413
+ case "human": {
8414
+ const customMetadata = buildCustomMetadata({
8415
+ additionalKwargs: message.additional_kwargs
8416
+ });
8417
+ return {
8418
+ role: "user",
8419
+ id: message.id,
8420
+ content: contentToParts(message.content),
8421
+ ...customMetadata && {
8422
+ metadata: {
8423
+ custom: customMetadata
8424
+ }
8425
+ }
8426
+ };
8427
+ }
8428
+ case "ai": {
8429
+ const customMetadata = buildCustomMetadata({
8430
+ additionalKwargs: message.additional_kwargs,
8431
+ usageMetadata: message.usage_metadata,
8432
+ responseMetadata: message.response_metadata
8433
+ });
8434
+ const toolCallParts = ((_a2 = message.tool_calls) == null ? void 0 : _a2.map((chunk) => {
8435
+ var _a3, _b2;
8436
+ let argsText;
8437
+ if (typeof chunk.args === "string") {
8438
+ argsText = chunk.args;
8439
+ } else {
8440
+ const rawString = chunk.partial_json ?? ((_b2 = (_a3 = message.tool_call_chunks) == null ? void 0 : _a3.find((c) => c.id === chunk.id)) == null ? void 0 : _b2.args) ?? JSON.stringify(chunk.args);
8441
+ argsText = rawString;
8442
+ }
8443
+ return {
8444
+ type: "tool-call",
8445
+ toolCallId: chunk.id,
8446
+ toolName: chunk.name,
8447
+ args: typeof chunk.args === "string" ? parsePartialJsonObject(argsText) ?? {} : chunk.args,
8448
+ argsText
8449
+ };
8450
+ })) ?? [];
8451
+ const normalizedContent = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content;
8452
+ const allContent = [
8453
+ (_b = message.additional_kwargs) == null ? void 0 : _b.reasoning,
8454
+ ...normalizedContent,
8455
+ ...((_c = message.additional_kwargs) == null ? void 0 : _c.tool_outputs) ?? []
8456
+ ].filter((c) => c != null);
8457
+ return {
8458
+ role: "assistant",
8459
+ id: message.id,
8460
+ content: [...contentToParts(allContent), ...toolCallParts],
8461
+ ...message.status && { status: message.status },
8462
+ ...customMetadata && {
8463
+ metadata: {
8464
+ custom: customMetadata
8465
+ }
8466
+ }
8467
+ };
8468
+ }
8469
+ case "tool": {
8470
+ const subgraphMessages = getSubgraphMessages(message.artifact);
8471
+ const parentEnded = message.content !== void 0 && message.content !== null;
8472
+ const nestedMessages = subgraphMessages !== void 0 ? convertLangChainToThreadMessages(
8473
+ parseMessages(
8474
+ parentEnded ? autoCloseInFlightSubgraphMessages(subgraphMessages) : subgraphMessages
8475
+ ),
8476
+ !parentEnded
8477
+ ) : void 0;
8478
+ return {
8479
+ role: "tool",
8480
+ toolName: message.name,
8481
+ toolCallId: message.tool_call_id,
8482
+ result: message.content,
8483
+ artifact: message.artifact,
8484
+ isError: message.status === "error",
8485
+ ...nestedMessages !== void 0 && { messages: nestedMessages }
8486
+ };
8487
+ }
8488
+ default:
8489
+ return null;
8490
+ }
8491
+ };
8492
+ const convertLangChainToThreadMessages = (messages, isRunning = false, metadata = {}) => {
8493
+ const validToolCallIds = /* @__PURE__ */ new Set();
8494
+ for (const message of messages) {
8495
+ if (message.type === "ai" && message.tool_calls) {
8496
+ for (const tc of message.tool_calls) {
8497
+ if (tc.id) {
8498
+ validToolCallIds.add(tc.id);
8499
+ }
8500
+ }
8501
+ }
8502
+ }
8503
+ const filteredMessages = messages.filter((message) => {
8504
+ if (message.type === "tool" && message.tool_call_id && !validToolCallIds.has(message.tool_call_id)) {
8505
+ return false;
8506
+ }
8507
+ return true;
8508
+ });
8509
+ return convertExternalMessages(filteredMessages, convertLangChainMessage, isRunning, metadata);
8510
+ };
8467
8511
  function getAuthHeaders(auth) {
8468
8512
  if (auth.token) {
8469
8513
  return { Authorization: `Bearer ${auth.token}` };
@@ -9053,12 +9097,12 @@ function useComposedRefs(...refs) {
9053
9097
  return React.useCallback(composeRefs(...refs), refs);
9054
9098
  }
9055
9099
  // @__NO_SIDE_EFFECTS__
9056
- function createSlot(ownerName) {
9057
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
9100
+ function createSlot$7(ownerName) {
9101
+ const SlotClone = /* @__PURE__ */ createSlotClone$7(ownerName);
9058
9102
  const Slot2 = React.forwardRef((props, forwardedRef) => {
9059
9103
  const { children, ...slotProps } = props;
9060
9104
  const childrenArray = React.Children.toArray(children);
9061
- const slottable = childrenArray.find(isSlottable);
9105
+ const slottable = childrenArray.find(isSlottable$7);
9062
9106
  if (slottable) {
9063
9107
  const newElement = slottable.props.children;
9064
9108
  const newChildren = childrenArray.map((child) => {
@@ -9076,14 +9120,13 @@ function createSlot(ownerName) {
9076
9120
  Slot2.displayName = `${ownerName}.Slot`;
9077
9121
  return Slot2;
9078
9122
  }
9079
- var Slot = /* @__PURE__ */ createSlot("Slot");
9080
9123
  // @__NO_SIDE_EFFECTS__
9081
- function createSlotClone(ownerName) {
9124
+ function createSlotClone$7(ownerName) {
9082
9125
  const SlotClone = React.forwardRef((props, forwardedRef) => {
9083
9126
  const { children, ...slotProps } = props;
9084
9127
  if (React.isValidElement(children)) {
9085
- const childrenRef = getElementRef$1(children);
9086
- const props2 = mergeProps(slotProps, children.props);
9128
+ const childrenRef = getElementRef$8(children);
9129
+ const props2 = mergeProps$7(slotProps, children.props);
9087
9130
  if (children.type !== React.Fragment) {
9088
9131
  props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9089
9132
  }
@@ -9094,21 +9137,11 @@ function createSlotClone(ownerName) {
9094
9137
  SlotClone.displayName = `${ownerName}.SlotClone`;
9095
9138
  return SlotClone;
9096
9139
  }
9097
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
9098
- // @__NO_SIDE_EFFECTS__
9099
- function createSlottable(ownerName) {
9100
- const Slottable2 = ({ children }) => {
9101
- return /* @__PURE__ */ jsx(Fragment$1, { children });
9102
- };
9103
- Slottable2.displayName = `${ownerName}.Slottable`;
9104
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
9105
- return Slottable2;
9140
+ var SLOTTABLE_IDENTIFIER$7 = Symbol("radix.slottable");
9141
+ function isSlottable$7(child) {
9142
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$7;
9106
9143
  }
9107
- var Slottable$1 = /* @__PURE__ */ createSlottable("Slottable");
9108
- function isSlottable(child) {
9109
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
9110
- }
9111
- function mergeProps(slotProps, childProps) {
9144
+ function mergeProps$7(slotProps, childProps) {
9112
9145
  const overrideProps = { ...childProps };
9113
9146
  for (const propName in childProps) {
9114
9147
  const slotPropValue = slotProps[propName];
@@ -9132,7 +9165,7 @@ function mergeProps(slotProps, childProps) {
9132
9165
  }
9133
9166
  return { ...slotProps, ...overrideProps };
9134
9167
  }
9135
- function getElementRef$1(element) {
9168
+ function getElementRef$8(element) {
9136
9169
  var _a2, _b;
9137
9170
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9138
9171
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9166,7 +9199,7 @@ var NODES$6 = [
9166
9199
  "ul"
9167
9200
  ];
9168
9201
  var Primitive$6 = NODES$6.reduce((primitive, node) => {
9169
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9202
+ const Slot2 = /* @__PURE__ */ createSlot$7(`Primitive.${node}`);
9170
9203
  const Node4 = React.forwardRef((props, forwardedRef) => {
9171
9204
  const { asChild, ...primitiveProps } = props;
9172
9205
  const Comp = asChild ? Slot2 : node;
@@ -9341,6 +9374,89 @@ function composeContextScopes$2(...scopes) {
9341
9374
  createScope.scopeName = baseScope.scopeName;
9342
9375
  return createScope;
9343
9376
  }
9377
+ // @__NO_SIDE_EFFECTS__
9378
+ function createSlot$6(ownerName) {
9379
+ const SlotClone = /* @__PURE__ */ createSlotClone$6(ownerName);
9380
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
9381
+ const { children, ...slotProps } = props;
9382
+ const childrenArray = React.Children.toArray(children);
9383
+ const slottable = childrenArray.find(isSlottable$6);
9384
+ if (slottable) {
9385
+ const newElement = slottable.props.children;
9386
+ const newChildren = childrenArray.map((child) => {
9387
+ if (child === slottable) {
9388
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
9389
+ return React.isValidElement(newElement) ? newElement.props.children : null;
9390
+ } else {
9391
+ return child;
9392
+ }
9393
+ });
9394
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
9395
+ }
9396
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9397
+ });
9398
+ Slot2.displayName = `${ownerName}.Slot`;
9399
+ return Slot2;
9400
+ }
9401
+ // @__NO_SIDE_EFFECTS__
9402
+ function createSlotClone$6(ownerName) {
9403
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
9404
+ const { children, ...slotProps } = props;
9405
+ if (React.isValidElement(children)) {
9406
+ const childrenRef = getElementRef$7(children);
9407
+ const props2 = mergeProps$6(slotProps, children.props);
9408
+ if (children.type !== React.Fragment) {
9409
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9410
+ }
9411
+ return React.cloneElement(children, props2);
9412
+ }
9413
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
9414
+ });
9415
+ SlotClone.displayName = `${ownerName}.SlotClone`;
9416
+ return SlotClone;
9417
+ }
9418
+ var SLOTTABLE_IDENTIFIER$6 = Symbol("radix.slottable");
9419
+ function isSlottable$6(child) {
9420
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$6;
9421
+ }
9422
+ function mergeProps$6(slotProps, childProps) {
9423
+ const overrideProps = { ...childProps };
9424
+ for (const propName in childProps) {
9425
+ const slotPropValue = slotProps[propName];
9426
+ const childPropValue = childProps[propName];
9427
+ const isHandler = /^on[A-Z]/.test(propName);
9428
+ if (isHandler) {
9429
+ if (slotPropValue && childPropValue) {
9430
+ overrideProps[propName] = (...args) => {
9431
+ const result = childPropValue(...args);
9432
+ slotPropValue(...args);
9433
+ return result;
9434
+ };
9435
+ } else if (slotPropValue) {
9436
+ overrideProps[propName] = slotPropValue;
9437
+ }
9438
+ } else if (propName === "style") {
9439
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9440
+ } else if (propName === "className") {
9441
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9442
+ }
9443
+ }
9444
+ return { ...slotProps, ...overrideProps };
9445
+ }
9446
+ function getElementRef$7(element) {
9447
+ var _a2, _b;
9448
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9449
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9450
+ if (mayWarn) {
9451
+ return element.ref;
9452
+ }
9453
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9454
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9455
+ if (mayWarn) {
9456
+ return element.props.ref;
9457
+ }
9458
+ return element.props.ref || element.ref;
9459
+ }
9344
9460
  var NODES$5 = [
9345
9461
  "a",
9346
9462
  "button",
@@ -9361,7 +9477,7 @@ var NODES$5 = [
9361
9477
  "ul"
9362
9478
  ];
9363
9479
  var Primitive$5 = NODES$5.reduce((primitive, node) => {
9364
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9480
+ const Slot2 = /* @__PURE__ */ createSlot$6(`Primitive.${node}`);
9365
9481
  const Node4 = React.forwardRef((props, forwardedRef) => {
9366
9482
  const { asChild, ...primitiveProps } = props;
9367
9483
  const Comp = asChild ? Slot2 : node;
@@ -9383,7 +9499,7 @@ var Presence = (props) => {
9383
9499
  const { present, children } = props;
9384
9500
  const presence = usePresence(present);
9385
9501
  const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
9386
- const ref = useComposedRefs(presence.ref, getElementRef(child));
9502
+ const ref = useComposedRefs(presence.ref, getElementRef$6(child));
9387
9503
  const forceMount = typeof children === "function";
9388
9504
  return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
9389
9505
  };
@@ -9482,7 +9598,7 @@ function usePresence(present) {
9482
9598
  function getAnimationName(styles) {
9483
9599
  return (styles == null ? void 0 : styles.animationName) || "none";
9484
9600
  }
9485
- function getElementRef(element) {
9601
+ function getElementRef$6(element) {
9486
9602
  var _a2, _b;
9487
9603
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9488
9604
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9635,6 +9751,89 @@ function getState(open) {
9635
9751
  return open ? "open" : "closed";
9636
9752
  }
9637
9753
  var Root$1 = Collapsible$1;
9754
+ // @__NO_SIDE_EFFECTS__
9755
+ function createSlot$5(ownerName) {
9756
+ const SlotClone = /* @__PURE__ */ createSlotClone$5(ownerName);
9757
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
9758
+ const { children, ...slotProps } = props;
9759
+ const childrenArray = React.Children.toArray(children);
9760
+ const slottable = childrenArray.find(isSlottable$5);
9761
+ if (slottable) {
9762
+ const newElement = slottable.props.children;
9763
+ const newChildren = childrenArray.map((child) => {
9764
+ if (child === slottable) {
9765
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
9766
+ return React.isValidElement(newElement) ? newElement.props.children : null;
9767
+ } else {
9768
+ return child;
9769
+ }
9770
+ });
9771
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
9772
+ }
9773
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9774
+ });
9775
+ Slot2.displayName = `${ownerName}.Slot`;
9776
+ return Slot2;
9777
+ }
9778
+ // @__NO_SIDE_EFFECTS__
9779
+ function createSlotClone$5(ownerName) {
9780
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
9781
+ const { children, ...slotProps } = props;
9782
+ if (React.isValidElement(children)) {
9783
+ const childrenRef = getElementRef$5(children);
9784
+ const props2 = mergeProps$5(slotProps, children.props);
9785
+ if (children.type !== React.Fragment) {
9786
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9787
+ }
9788
+ return React.cloneElement(children, props2);
9789
+ }
9790
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
9791
+ });
9792
+ SlotClone.displayName = `${ownerName}.SlotClone`;
9793
+ return SlotClone;
9794
+ }
9795
+ var SLOTTABLE_IDENTIFIER$5 = Symbol("radix.slottable");
9796
+ function isSlottable$5(child) {
9797
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$5;
9798
+ }
9799
+ function mergeProps$5(slotProps, childProps) {
9800
+ const overrideProps = { ...childProps };
9801
+ for (const propName in childProps) {
9802
+ const slotPropValue = slotProps[propName];
9803
+ const childPropValue = childProps[propName];
9804
+ const isHandler = /^on[A-Z]/.test(propName);
9805
+ if (isHandler) {
9806
+ if (slotPropValue && childPropValue) {
9807
+ overrideProps[propName] = (...args) => {
9808
+ const result = childPropValue(...args);
9809
+ slotPropValue(...args);
9810
+ return result;
9811
+ };
9812
+ } else if (slotPropValue) {
9813
+ overrideProps[propName] = slotPropValue;
9814
+ }
9815
+ } else if (propName === "style") {
9816
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9817
+ } else if (propName === "className") {
9818
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9819
+ }
9820
+ }
9821
+ return { ...slotProps, ...overrideProps };
9822
+ }
9823
+ function getElementRef$5(element) {
9824
+ var _a2, _b;
9825
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9826
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9827
+ if (mayWarn) {
9828
+ return element.ref;
9829
+ }
9830
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9831
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9832
+ if (mayWarn) {
9833
+ return element.props.ref;
9834
+ }
9835
+ return element.props.ref || element.ref;
9836
+ }
9638
9837
  var NODES$4 = [
9639
9838
  "a",
9640
9839
  "button",
@@ -9655,7 +9854,7 @@ var NODES$4 = [
9655
9854
  "ul"
9656
9855
  ];
9657
9856
  var Primitive$4 = NODES$4.reduce((primitive, node) => {
9658
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9857
+ const Slot2 = /* @__PURE__ */ createSlot$5(`Primitive.${node}`);
9659
9858
  const Node4 = React.forwardRef((props, forwardedRef) => {
9660
9859
  const { asChild, ...primitiveProps } = props;
9661
9860
  const Comp = asChild ? Slot2 : node;
@@ -9893,6 +10092,89 @@ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
9893
10092
  target.dispatchEvent(event);
9894
10093
  }
9895
10094
  }
10095
+ // @__NO_SIDE_EFFECTS__
10096
+ function createSlot$4(ownerName) {
10097
+ const SlotClone = /* @__PURE__ */ createSlotClone$4(ownerName);
10098
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
10099
+ const { children, ...slotProps } = props;
10100
+ const childrenArray = React.Children.toArray(children);
10101
+ const slottable = childrenArray.find(isSlottable$4);
10102
+ if (slottable) {
10103
+ const newElement = slottable.props.children;
10104
+ const newChildren = childrenArray.map((child) => {
10105
+ if (child === slottable) {
10106
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
10107
+ return React.isValidElement(newElement) ? newElement.props.children : null;
10108
+ } else {
10109
+ return child;
10110
+ }
10111
+ });
10112
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
10113
+ }
10114
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10115
+ });
10116
+ Slot2.displayName = `${ownerName}.Slot`;
10117
+ return Slot2;
10118
+ }
10119
+ // @__NO_SIDE_EFFECTS__
10120
+ function createSlotClone$4(ownerName) {
10121
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
10122
+ const { children, ...slotProps } = props;
10123
+ if (React.isValidElement(children)) {
10124
+ const childrenRef = getElementRef$4(children);
10125
+ const props2 = mergeProps$4(slotProps, children.props);
10126
+ if (children.type !== React.Fragment) {
10127
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10128
+ }
10129
+ return React.cloneElement(children, props2);
10130
+ }
10131
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
10132
+ });
10133
+ SlotClone.displayName = `${ownerName}.SlotClone`;
10134
+ return SlotClone;
10135
+ }
10136
+ var SLOTTABLE_IDENTIFIER$4 = Symbol("radix.slottable");
10137
+ function isSlottable$4(child) {
10138
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$4;
10139
+ }
10140
+ function mergeProps$4(slotProps, childProps) {
10141
+ const overrideProps = { ...childProps };
10142
+ for (const propName in childProps) {
10143
+ const slotPropValue = slotProps[propName];
10144
+ const childPropValue = childProps[propName];
10145
+ const isHandler = /^on[A-Z]/.test(propName);
10146
+ if (isHandler) {
10147
+ if (slotPropValue && childPropValue) {
10148
+ overrideProps[propName] = (...args) => {
10149
+ const result = childPropValue(...args);
10150
+ slotPropValue(...args);
10151
+ return result;
10152
+ };
10153
+ } else if (slotPropValue) {
10154
+ overrideProps[propName] = slotPropValue;
10155
+ }
10156
+ } else if (propName === "style") {
10157
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10158
+ } else if (propName === "className") {
10159
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10160
+ }
10161
+ }
10162
+ return { ...slotProps, ...overrideProps };
10163
+ }
10164
+ function getElementRef$4(element) {
10165
+ var _a2, _b;
10166
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10167
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10168
+ if (mayWarn) {
10169
+ return element.ref;
10170
+ }
10171
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10172
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10173
+ if (mayWarn) {
10174
+ return element.props.ref;
10175
+ }
10176
+ return element.props.ref || element.ref;
10177
+ }
9896
10178
  var NODES$3 = [
9897
10179
  "a",
9898
10180
  "button",
@@ -9913,7 +10195,7 @@ var NODES$3 = [
9913
10195
  "ul"
9914
10196
  ];
9915
10197
  var Primitive$3 = NODES$3.reduce((primitive, node) => {
9916
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
10198
+ const Slot2 = /* @__PURE__ */ createSlot$4(`Primitive.${node}`);
9917
10199
  const Node4 = React.forwardRef((props, forwardedRef) => {
9918
10200
  const { asChild, ...primitiveProps } = props;
9919
10201
  const Comp = asChild ? Slot2 : node;
@@ -9935,6 +10217,100 @@ var Portal$1 = React.forwardRef((props, forwardedRef) => {
9935
10217
  return container ? ReactDOM__default.createPortal(/* @__PURE__ */ jsx(Primitive$3.div, { ...portalProps, ref: forwardedRef }), container) : null;
9936
10218
  });
9937
10219
  Portal$1.displayName = PORTAL_NAME$1;
10220
+ // @__NO_SIDE_EFFECTS__
10221
+ function createSlot$3(ownerName) {
10222
+ const SlotClone = /* @__PURE__ */ createSlotClone$3(ownerName);
10223
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
10224
+ const { children, ...slotProps } = props;
10225
+ const childrenArray = React.Children.toArray(children);
10226
+ const slottable = childrenArray.find(isSlottable$3);
10227
+ if (slottable) {
10228
+ const newElement = slottable.props.children;
10229
+ const newChildren = childrenArray.map((child) => {
10230
+ if (child === slottable) {
10231
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
10232
+ return React.isValidElement(newElement) ? newElement.props.children : null;
10233
+ } else {
10234
+ return child;
10235
+ }
10236
+ });
10237
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
10238
+ }
10239
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10240
+ });
10241
+ Slot2.displayName = `${ownerName}.Slot`;
10242
+ return Slot2;
10243
+ }
10244
+ var Slot = /* @__PURE__ */ createSlot$3("Slot");
10245
+ // @__NO_SIDE_EFFECTS__
10246
+ function createSlotClone$3(ownerName) {
10247
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
10248
+ const { children, ...slotProps } = props;
10249
+ if (React.isValidElement(children)) {
10250
+ const childrenRef = getElementRef$3(children);
10251
+ const props2 = mergeProps$3(slotProps, children.props);
10252
+ if (children.type !== React.Fragment) {
10253
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10254
+ }
10255
+ return React.cloneElement(children, props2);
10256
+ }
10257
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
10258
+ });
10259
+ SlotClone.displayName = `${ownerName}.SlotClone`;
10260
+ return SlotClone;
10261
+ }
10262
+ var SLOTTABLE_IDENTIFIER$3 = Symbol("radix.slottable");
10263
+ // @__NO_SIDE_EFFECTS__
10264
+ function createSlottable$1(ownerName) {
10265
+ const Slottable2 = ({ children }) => {
10266
+ return /* @__PURE__ */ jsx(Fragment$1, { children });
10267
+ };
10268
+ Slottable2.displayName = `${ownerName}.Slottable`;
10269
+ Slottable2.__radixId = SLOTTABLE_IDENTIFIER$3;
10270
+ return Slottable2;
10271
+ }
10272
+ var Slottable$1 = /* @__PURE__ */ createSlottable$1("Slottable");
10273
+ function isSlottable$3(child) {
10274
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$3;
10275
+ }
10276
+ function mergeProps$3(slotProps, childProps) {
10277
+ const overrideProps = { ...childProps };
10278
+ for (const propName in childProps) {
10279
+ const slotPropValue = slotProps[propName];
10280
+ const childPropValue = childProps[propName];
10281
+ const isHandler = /^on[A-Z]/.test(propName);
10282
+ if (isHandler) {
10283
+ if (slotPropValue && childPropValue) {
10284
+ overrideProps[propName] = (...args) => {
10285
+ const result = childPropValue(...args);
10286
+ slotPropValue(...args);
10287
+ return result;
10288
+ };
10289
+ } else if (slotPropValue) {
10290
+ overrideProps[propName] = slotPropValue;
10291
+ }
10292
+ } else if (propName === "style") {
10293
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10294
+ } else if (propName === "className") {
10295
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10296
+ }
10297
+ }
10298
+ return { ...slotProps, ...overrideProps };
10299
+ }
10300
+ function getElementRef$3(element) {
10301
+ var _a2, _b;
10302
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10303
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10304
+ if (mayWarn) {
10305
+ return element.ref;
10306
+ }
10307
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10308
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10309
+ if (mayWarn) {
10310
+ return element.props.ref;
10311
+ }
10312
+ return element.props.ref || element.ref;
10313
+ }
9938
10314
  var shim$1 = { exports: {} };
9939
10315
  var useSyncExternalStoreShim_production = {};
9940
10316
  /**
@@ -12027,6 +12403,89 @@ const arrow$2 = (options, deps) => {
12027
12403
  options: [options, deps]
12028
12404
  };
12029
12405
  };
12406
+ // @__NO_SIDE_EFFECTS__
12407
+ function createSlot$2(ownerName) {
12408
+ const SlotClone = /* @__PURE__ */ createSlotClone$2(ownerName);
12409
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
12410
+ const { children, ...slotProps } = props;
12411
+ const childrenArray = React.Children.toArray(children);
12412
+ const slottable = childrenArray.find(isSlottable$2);
12413
+ if (slottable) {
12414
+ const newElement = slottable.props.children;
12415
+ const newChildren = childrenArray.map((child) => {
12416
+ if (child === slottable) {
12417
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
12418
+ return React.isValidElement(newElement) ? newElement.props.children : null;
12419
+ } else {
12420
+ return child;
12421
+ }
12422
+ });
12423
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
12424
+ }
12425
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12426
+ });
12427
+ Slot2.displayName = `${ownerName}.Slot`;
12428
+ return Slot2;
12429
+ }
12430
+ // @__NO_SIDE_EFFECTS__
12431
+ function createSlotClone$2(ownerName) {
12432
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
12433
+ const { children, ...slotProps } = props;
12434
+ if (React.isValidElement(children)) {
12435
+ const childrenRef = getElementRef$2(children);
12436
+ const props2 = mergeProps$2(slotProps, children.props);
12437
+ if (children.type !== React.Fragment) {
12438
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12439
+ }
12440
+ return React.cloneElement(children, props2);
12441
+ }
12442
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
12443
+ });
12444
+ SlotClone.displayName = `${ownerName}.SlotClone`;
12445
+ return SlotClone;
12446
+ }
12447
+ var SLOTTABLE_IDENTIFIER$2 = Symbol("radix.slottable");
12448
+ function isSlottable$2(child) {
12449
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$2;
12450
+ }
12451
+ function mergeProps$2(slotProps, childProps) {
12452
+ const overrideProps = { ...childProps };
12453
+ for (const propName in childProps) {
12454
+ const slotPropValue = slotProps[propName];
12455
+ const childPropValue = childProps[propName];
12456
+ const isHandler = /^on[A-Z]/.test(propName);
12457
+ if (isHandler) {
12458
+ if (slotPropValue && childPropValue) {
12459
+ overrideProps[propName] = (...args) => {
12460
+ const result = childPropValue(...args);
12461
+ slotPropValue(...args);
12462
+ return result;
12463
+ };
12464
+ } else if (slotPropValue) {
12465
+ overrideProps[propName] = slotPropValue;
12466
+ }
12467
+ } else if (propName === "style") {
12468
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12469
+ } else if (propName === "className") {
12470
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12471
+ }
12472
+ }
12473
+ return { ...slotProps, ...overrideProps };
12474
+ }
12475
+ function getElementRef$2(element) {
12476
+ var _a2, _b;
12477
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12478
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12479
+ if (mayWarn) {
12480
+ return element.ref;
12481
+ }
12482
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12483
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12484
+ if (mayWarn) {
12485
+ return element.props.ref;
12486
+ }
12487
+ return element.props.ref || element.ref;
12488
+ }
12030
12489
  var NODES$2 = [
12031
12490
  "a",
12032
12491
  "button",
@@ -12047,7 +12506,7 @@ var NODES$2 = [
12047
12506
  "ul"
12048
12507
  ];
12049
12508
  var Primitive$2 = NODES$2.reduce((primitive, node) => {
12050
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12509
+ const Slot2 = /* @__PURE__ */ createSlot$2(`Primitive.${node}`);
12051
12510
  const Node4 = React.forwardRef((props, forwardedRef) => {
12052
12511
  const { asChild, ...primitiveProps } = props;
12053
12512
  const Comp = asChild ? Slot2 : node;
@@ -12136,6 +12595,89 @@ function composeContextScopes$1(...scopes) {
12136
12595
  createScope.scopeName = baseScope.scopeName;
12137
12596
  return createScope;
12138
12597
  }
12598
+ // @__NO_SIDE_EFFECTS__
12599
+ function createSlot$1(ownerName) {
12600
+ const SlotClone = /* @__PURE__ */ createSlotClone$1(ownerName);
12601
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
12602
+ const { children, ...slotProps } = props;
12603
+ const childrenArray = React.Children.toArray(children);
12604
+ const slottable = childrenArray.find(isSlottable$1);
12605
+ if (slottable) {
12606
+ const newElement = slottable.props.children;
12607
+ const newChildren = childrenArray.map((child) => {
12608
+ if (child === slottable) {
12609
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
12610
+ return React.isValidElement(newElement) ? newElement.props.children : null;
12611
+ } else {
12612
+ return child;
12613
+ }
12614
+ });
12615
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
12616
+ }
12617
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12618
+ });
12619
+ Slot2.displayName = `${ownerName}.Slot`;
12620
+ return Slot2;
12621
+ }
12622
+ // @__NO_SIDE_EFFECTS__
12623
+ function createSlotClone$1(ownerName) {
12624
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
12625
+ const { children, ...slotProps } = props;
12626
+ if (React.isValidElement(children)) {
12627
+ const childrenRef = getElementRef$1(children);
12628
+ const props2 = mergeProps$1(slotProps, children.props);
12629
+ if (children.type !== React.Fragment) {
12630
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12631
+ }
12632
+ return React.cloneElement(children, props2);
12633
+ }
12634
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
12635
+ });
12636
+ SlotClone.displayName = `${ownerName}.SlotClone`;
12637
+ return SlotClone;
12638
+ }
12639
+ var SLOTTABLE_IDENTIFIER$1 = Symbol("radix.slottable");
12640
+ function isSlottable$1(child) {
12641
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$1;
12642
+ }
12643
+ function mergeProps$1(slotProps, childProps) {
12644
+ const overrideProps = { ...childProps };
12645
+ for (const propName in childProps) {
12646
+ const slotPropValue = slotProps[propName];
12647
+ const childPropValue = childProps[propName];
12648
+ const isHandler = /^on[A-Z]/.test(propName);
12649
+ if (isHandler) {
12650
+ if (slotPropValue && childPropValue) {
12651
+ overrideProps[propName] = (...args) => {
12652
+ const result = childPropValue(...args);
12653
+ slotPropValue(...args);
12654
+ return result;
12655
+ };
12656
+ } else if (slotPropValue) {
12657
+ overrideProps[propName] = slotPropValue;
12658
+ }
12659
+ } else if (propName === "style") {
12660
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12661
+ } else if (propName === "className") {
12662
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12663
+ }
12664
+ }
12665
+ return { ...slotProps, ...overrideProps };
12666
+ }
12667
+ function getElementRef$1(element) {
12668
+ var _a2, _b;
12669
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12670
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12671
+ if (mayWarn) {
12672
+ return element.ref;
12673
+ }
12674
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12675
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12676
+ if (mayWarn) {
12677
+ return element.props.ref;
12678
+ }
12679
+ return element.props.ref || element.ref;
12680
+ }
12139
12681
  var NODES$1 = [
12140
12682
  "a",
12141
12683
  "button",
@@ -12156,7 +12698,7 @@ var NODES$1 = [
12156
12698
  "ul"
12157
12699
  ];
12158
12700
  var Primitive$1 = NODES$1.reduce((primitive, node) => {
12159
- const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12701
+ const Slot2 = /* @__PURE__ */ createSlot$1(`Primitive.${node}`);
12160
12702
  const Node4 = React.forwardRef((props, forwardedRef) => {
12161
12703
  const { asChild, ...primitiveProps } = props;
12162
12704
  const Comp = asChild ? Slot2 : node;
@@ -12498,6 +13040,98 @@ function composeContextScopes(...scopes) {
12498
13040
  createScope.scopeName = baseScope.scopeName;
12499
13041
  return createScope;
12500
13042
  }
13043
+ // @__NO_SIDE_EFFECTS__
13044
+ function createSlot(ownerName) {
13045
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
13046
+ const Slot2 = React.forwardRef((props, forwardedRef) => {
13047
+ const { children, ...slotProps } = props;
13048
+ const childrenArray = React.Children.toArray(children);
13049
+ const slottable = childrenArray.find(isSlottable);
13050
+ if (slottable) {
13051
+ const newElement = slottable.props.children;
13052
+ const newChildren = childrenArray.map((child) => {
13053
+ if (child === slottable) {
13054
+ if (React.Children.count(newElement) > 1) return React.Children.only(null);
13055
+ return React.isValidElement(newElement) ? newElement.props.children : null;
13056
+ } else {
13057
+ return child;
13058
+ }
13059
+ });
13060
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
13061
+ }
13062
+ return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
13063
+ });
13064
+ Slot2.displayName = `${ownerName}.Slot`;
13065
+ return Slot2;
13066
+ }
13067
+ // @__NO_SIDE_EFFECTS__
13068
+ function createSlotClone(ownerName) {
13069
+ const SlotClone = React.forwardRef((props, forwardedRef) => {
13070
+ const { children, ...slotProps } = props;
13071
+ if (React.isValidElement(children)) {
13072
+ const childrenRef = getElementRef(children);
13073
+ const props2 = mergeProps(slotProps, children.props);
13074
+ if (children.type !== React.Fragment) {
13075
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
13076
+ }
13077
+ return React.cloneElement(children, props2);
13078
+ }
13079
+ return React.Children.count(children) > 1 ? React.Children.only(null) : null;
13080
+ });
13081
+ SlotClone.displayName = `${ownerName}.SlotClone`;
13082
+ return SlotClone;
13083
+ }
13084
+ var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
13085
+ // @__NO_SIDE_EFFECTS__
13086
+ function createSlottable(ownerName) {
13087
+ const Slottable2 = ({ children }) => {
13088
+ return /* @__PURE__ */ jsx(Fragment$1, { children });
13089
+ };
13090
+ Slottable2.displayName = `${ownerName}.Slottable`;
13091
+ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
13092
+ return Slottable2;
13093
+ }
13094
+ function isSlottable(child) {
13095
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
13096
+ }
13097
+ function mergeProps(slotProps, childProps) {
13098
+ const overrideProps = { ...childProps };
13099
+ for (const propName in childProps) {
13100
+ const slotPropValue = slotProps[propName];
13101
+ const childPropValue = childProps[propName];
13102
+ const isHandler = /^on[A-Z]/.test(propName);
13103
+ if (isHandler) {
13104
+ if (slotPropValue && childPropValue) {
13105
+ overrideProps[propName] = (...args) => {
13106
+ const result = childPropValue(...args);
13107
+ slotPropValue(...args);
13108
+ return result;
13109
+ };
13110
+ } else if (slotPropValue) {
13111
+ overrideProps[propName] = slotPropValue;
13112
+ }
13113
+ } else if (propName === "style") {
13114
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
13115
+ } else if (propName === "className") {
13116
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
13117
+ }
13118
+ }
13119
+ return { ...slotProps, ...overrideProps };
13120
+ }
13121
+ function getElementRef(element) {
13122
+ var _a2, _b;
13123
+ let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
13124
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13125
+ if (mayWarn) {
13126
+ return element.ref;
13127
+ }
13128
+ getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
13129
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13130
+ if (mayWarn) {
13131
+ return element.props.ref;
13132
+ }
13133
+ return element.props.ref || element.ref;
13134
+ }
12501
13135
  var NODES = [
12502
13136
  "a",
12503
13137
  "button",
@@ -13478,14 +14112,20 @@ const useAssetPanelStore = create()(
13478
14112
  const existing = s.tabs.find((t) => t.id === assetId);
13479
14113
  if (existing) {
13480
14114
  const tabs = meta ? s.tabs.map(
13481
- (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
14115
+ (t) => t.id === assetId ? {
14116
+ ...t,
14117
+ name: meta.name ?? t.name,
14118
+ type: meta.type ?? t.type,
14119
+ slideNumber: meta.slideNumber ?? t.slideNumber
14120
+ } : t
13482
14121
  ) : s.tabs;
13483
14122
  return { isOpen: true, tabs, activeTabId: assetId };
13484
14123
  }
13485
14124
  const newTab = {
13486
14125
  id: assetId,
13487
14126
  name: (meta == null ? void 0 : meta.name) ?? null,
13488
- type: (meta == null ? void 0 : meta.type) ?? "unknown"
14127
+ type: (meta == null ? void 0 : meta.type) ?? "unknown",
14128
+ slideNumber: meta == null ? void 0 : meta.slideNumber
13489
14129
  };
13490
14130
  return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
13491
14131
  }),
@@ -48886,6 +49526,43 @@ function CollapsibleTrigger({ ...props }) {
48886
49526
  function CollapsibleContent({ ...props }) {
48887
49527
  return /* @__PURE__ */ jsx(CollapsibleContent$1, { "data-slot": "collapsible-content", ...props });
48888
49528
  }
49529
+ const NestedPtcComponentsContext = createContext(null);
49530
+ const NestedPtcComponentsProvider = ({ components, children }) => /* @__PURE__ */ jsx(NestedPtcComponentsContext.Provider, { value: components, children });
49531
+ const useNestedPtcComponents = (fallback) => {
49532
+ const components = useContext(NestedPtcComponentsContext);
49533
+ return useMemo(() => {
49534
+ const standardComponents = components && "ChainOfThought" in components && components.ChainOfThought ? void 0 : components;
49535
+ return {
49536
+ ...standardComponents ?? {},
49537
+ tools: {
49538
+ ...(standardComponents == null ? void 0 : standardComponents.tools) ?? {},
49539
+ Fallback: fallback
49540
+ }
49541
+ };
49542
+ }, [components, fallback]);
49543
+ };
49544
+ const EmptyComponent = () => null;
49545
+ const NestedPtcMessages = ({
49546
+ components,
49547
+ messageClassName
49548
+ }) => {
49549
+ const propsRef = useRef({ components, messageClassName });
49550
+ propsRef.current = { components, messageClassName };
49551
+ const messageComponents = useMemo(() => {
49552
+ const NestedMessage = () => {
49553
+ const { components: components2, messageClassName: messageClassName2 } = propsRef.current;
49554
+ const parts = /* @__PURE__ */ jsx(
49555
+ MessagePrimitive.Parts,
49556
+ {
49557
+ components: { Empty: EmptyComponent, ...components2 }
49558
+ }
49559
+ );
49560
+ return messageClassName2 ? /* @__PURE__ */ jsx("div", { className: messageClassName2, children: parts }) : parts;
49561
+ };
49562
+ return { Message: NestedMessage };
49563
+ }, []);
49564
+ return /* @__PURE__ */ jsx(MessagePartPrimitive.Messages, { components: messageComponents });
49565
+ };
48889
49566
  const ANIMATION_DURATION = 200;
48890
49567
  function truncateLine(text2, max2 = 70) {
48891
49568
  const oneLine = text2.replace(/\s+/g, " ").trim();
@@ -49434,16 +50111,20 @@ const ToolFallbackImpl = ({
49434
50111
  status
49435
50112
  }) => {
49436
50113
  const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
50114
+ const nestedComponents = useNestedPtcComponents(ToolFallback);
49437
50115
  if (isAssetTool(toolName, result)) {
49438
- return /* @__PURE__ */ jsx(
49439
- AssetToolCard,
49440
- {
49441
- toolName,
49442
- argsText,
49443
- result,
49444
- status
49445
- }
49446
- );
50116
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
50117
+ /* @__PURE__ */ jsx(
50118
+ AssetToolCard,
50119
+ {
50120
+ toolName,
50121
+ argsText,
50122
+ result,
50123
+ status
50124
+ }
50125
+ ),
50126
+ /* @__PURE__ */ jsx(NestedPtcMessages, { components: nestedComponents })
50127
+ ] });
49447
50128
  }
49448
50129
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
49449
50130
  const resultAssetId = extractAssetId$1(result);
@@ -49468,6 +50149,7 @@ const ToolFallbackImpl = ({
49468
50149
  }
49469
50150
  ),
49470
50151
  !isCancelled && /* @__PURE__ */ jsx(ToolFallbackResult, { result }),
50152
+ /* @__PURE__ */ jsx(NestedPtcMessages, { components: nestedComponents }),
49471
50153
  !isCancelled && /* @__PURE__ */ jsx("div", { className: "flex justify-end px-3 pt-1", children: /* @__PURE__ */ jsx(CopyToolSpec, { toolName, argsText, result }) })
49472
50154
  ] })
49473
50155
  ]
@@ -50188,6 +50870,68 @@ function extractAssetId(result) {
50188
50870
  function resetAssetAutoOpen() {
50189
50871
  useAssetPanelStore.getState().resetAutoOpen();
50190
50872
  }
50873
+ function getStringField(source, keys2) {
50874
+ if (!source) return null;
50875
+ for (const key of keys2) {
50876
+ const value = source[key];
50877
+ if (typeof value === "string" && value.trim()) {
50878
+ return value;
50879
+ }
50880
+ }
50881
+ return null;
50882
+ }
50883
+ function getNumberField(source, keys2) {
50884
+ if (!source) return null;
50885
+ for (const key of keys2) {
50886
+ const value = source[key];
50887
+ if (typeof value === "number" && Number.isFinite(value)) {
50888
+ return value;
50889
+ }
50890
+ }
50891
+ return null;
50892
+ }
50893
+ function getStudioAssetId({
50894
+ args,
50895
+ result
50896
+ }) {
50897
+ const id = getStringField(result, ["asset_id", "assetId", "id"]) ?? getStringField(args, ["asset_id", "assetId", "id"]);
50898
+ return (id == null ? void 0 : id.startsWith("asset_")) ? id : null;
50899
+ }
50900
+ function getSlideNumber(args) {
50901
+ const explicit = getNumberField(args, ["slideNumber", "slide_number"]);
50902
+ if (explicit != null && Number.isInteger(explicit) && explicit >= 1) {
50903
+ return explicit;
50904
+ }
50905
+ const zeroBasedIndex = getNumberField(args, ["index", "slideIndex", "slide_index"]);
50906
+ if (zeroBasedIndex != null && Number.isInteger(zeroBasedIndex) && zeroBasedIndex >= 0) {
50907
+ return zeroBasedIndex + 1;
50908
+ }
50909
+ return void 0;
50910
+ }
50911
+ const completedStudioToolEffects = /* @__PURE__ */ new Set();
50912
+ const MAX_COMPLETED_STUDIO_TOOL_EFFECTS = 500;
50913
+ function markStudioToolEffect(key) {
50914
+ if (completedStudioToolEffects.has(key)) {
50915
+ return false;
50916
+ }
50917
+ if (completedStudioToolEffects.size >= MAX_COMPLETED_STUDIO_TOOL_EFFECTS) {
50918
+ const oldest = completedStudioToolEffects.values().next().value;
50919
+ if (oldest) completedStudioToolEffects.delete(oldest);
50920
+ }
50921
+ completedStudioToolEffects.add(key);
50922
+ return true;
50923
+ }
50924
+ function dispatchPresentationNavigate(assetId, slideNumber) {
50925
+ const targetSlide = slideNumber;
50926
+ if (typeof targetSlide !== "number" || !Number.isInteger(targetSlide) || targetSlide < 1) {
50927
+ return;
50928
+ }
50929
+ window.dispatchEvent(
50930
+ new CustomEvent("pptx-studio-navigate", {
50931
+ detail: { assetId, slideNumber: targetSlide }
50932
+ })
50933
+ );
50934
+ }
50191
50935
  function CreateAssetToolUIImpl({
50192
50936
  icon: Icon2,
50193
50937
  assetType,
@@ -50297,6 +51041,238 @@ const CreatePresentationToolUI = memo(
50297
51041
  CreatePresentationToolUIImpl
50298
51042
  );
50299
51043
  CreatePresentationToolUI.displayName = "CreatePresentationToolUI";
51044
+ function StudioPtcToolUI({
51045
+ config: config2,
51046
+ toolName,
51047
+ toolCallId,
51048
+ args,
51049
+ result,
51050
+ status
51051
+ }) {
51052
+ var _a2, _b;
51053
+ const typedArgs = args;
51054
+ const data = useMemo(() => normalizeResult(result), [result]);
51055
+ const slideNumber = (_a2 = config2.getSlideNumber) == null ? void 0 : _a2.call(config2, typedArgs);
51056
+ const assetId = getStudioAssetId({ args: typedArgs, result: data });
51057
+ const subtitle = (_b = config2.getSubtitle) == null ? void 0 : _b.call(config2, typedArgs, data, slideNumber);
51058
+ const isRunning = (status == null ? void 0 : status.type) === "running";
51059
+ const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
51060
+ const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
51061
+ const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? String(status.error ?? status.reason ?? "Tool failed") : null;
51062
+ const openAsset = useAssetPanelStore((s) => s.openAsset);
51063
+ const handleOpen = useCallback(() => {
51064
+ if (!assetId) return;
51065
+ openAsset(assetId, {
51066
+ type: config2.assetType,
51067
+ slideNumber
51068
+ });
51069
+ if (config2.assetType === "presentation") {
51070
+ dispatchPresentationNavigate(assetId, slideNumber);
51071
+ }
51072
+ }, [assetId, config2.assetType, openAsset, slideNumber]);
51073
+ useEffect(() => {
51074
+ if (!config2.autoOpen || !isComplete || isCancelled || !assetId) {
51075
+ return;
51076
+ }
51077
+ const effectKey = toolCallId ?? `${toolName ?? "studio-tool"}:${assetId}:${slideNumber ?? "asset"}`;
51078
+ if (!markStudioToolEffect(effectKey)) {
51079
+ return;
51080
+ }
51081
+ const store = useAssetPanelStore.getState();
51082
+ store.openAsset(assetId, {
51083
+ type: config2.assetType,
51084
+ slideNumber
51085
+ });
51086
+ if (config2.assetType === "presentation") {
51087
+ dispatchPresentationNavigate(assetId, slideNumber);
51088
+ }
51089
+ }, [
51090
+ assetId,
51091
+ config2.assetType,
51092
+ config2.autoOpen,
51093
+ isCancelled,
51094
+ isComplete,
51095
+ slideNumber,
51096
+ toolCallId,
51097
+ toolName
51098
+ ]);
51099
+ return /* @__PURE__ */ jsx(
51100
+ ToolCard,
51101
+ {
51102
+ icon: config2.icon,
51103
+ status: (status == null ? void 0 : status.type) ?? "complete",
51104
+ title: isRunning ? config2.runningLabel(typedArgs) : config2.doneLabel(typedArgs, slideNumber),
51105
+ subtitle,
51106
+ badge: config2.badge,
51107
+ toolName,
51108
+ args: typedArgs,
51109
+ result,
51110
+ error: errorMsg,
51111
+ children: assetId && isComplete && !isCancelled && /* @__PURE__ */ jsx("div", { className: "border-t border-border/40 px-4 py-2", children: /* @__PURE__ */ jsxs(
51112
+ "button",
51113
+ {
51114
+ type: "button",
51115
+ onClick: handleOpen,
51116
+ className: "flex items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
51117
+ children: [
51118
+ /* @__PURE__ */ jsx(ExternalLink, { className: "size-3" }),
51119
+ config2.openLabel(slideNumber)
51120
+ ]
51121
+ }
51122
+ ) })
51123
+ }
51124
+ );
51125
+ }
51126
+ function createStudioPtcToolUI(displayName, config2) {
51127
+ const Component = (props) => /* @__PURE__ */ jsx(StudioPtcToolUI, { config: config2, ...props });
51128
+ const Memoized = memo(Component);
51129
+ Memoized.displayName = displayName;
51130
+ return Memoized;
51131
+ }
51132
+ const getNameSubtitle = (args, result) => getStringField(result, ["title", "name", "asset_name"]) ?? getStringField(args, ["title", "name"]) ?? void 0;
51133
+ const getParagraphSubtitle = (args) => {
51134
+ const text2 = getStringField(args, ["text"]);
51135
+ return text2 ? truncate(text2, 80) : void 0;
51136
+ };
51137
+ const getSlideSubtitle = (args, _result, slideNumber) => {
51138
+ const layout = getStringField(args, ["layoutName", "layout_name"]) ?? getStringField(args, ["layoutPath", "layout_path"]);
51139
+ const slideLabel = slideNumber ? `Slide ${slideNumber}` : null;
51140
+ if (slideLabel && layout) return `${slideLabel} - ${truncate(layout, 48)}`;
51141
+ return slideLabel ?? (layout ? truncate(layout, 64) : void 0);
51142
+ };
51143
+ const StudioCreateWorkbookToolUI = createStudioPtcToolUI(
51144
+ "StudioCreateWorkbookToolUI",
51145
+ {
51146
+ icon: ChartColumn,
51147
+ assetType: "spreadsheet",
51148
+ badge: "Sheet",
51149
+ runningLabel: (args) => {
51150
+ const title = getStringField(args, ["title", "name"]);
51151
+ return title ? `Creating workbook "${title}"...` : "Creating workbook...";
51152
+ },
51153
+ doneLabel: () => "Workbook created",
51154
+ getSubtitle: getNameSubtitle,
51155
+ openLabel: () => "Open workbook",
51156
+ autoOpen: true
51157
+ }
51158
+ );
51159
+ const StudioAddSheetToolUI = createStudioPtcToolUI(
51160
+ "StudioAddSheetToolUI",
51161
+ {
51162
+ icon: ChartColumn,
51163
+ assetType: "spreadsheet",
51164
+ badge: "Sheet",
51165
+ runningLabel: (args) => {
51166
+ const name = getStringField(args, ["name", "sheetName", "sheet_name"]);
51167
+ return name ? `Adding sheet "${name}"...` : "Adding sheet...";
51168
+ },
51169
+ doneLabel: (args) => {
51170
+ const name = getStringField(args, ["name", "sheetName", "sheet_name"]);
51171
+ return name ? `Sheet added: ${name}` : "Sheet added";
51172
+ },
51173
+ getSubtitle: (args) => getStringField(args, ["name", "sheetName", "sheet_name"]) ?? void 0,
51174
+ openLabel: () => "Open workbook",
51175
+ autoOpen: true
51176
+ }
51177
+ );
51178
+ const StudioOpenWorkbookToolUI = createStudioPtcToolUI(
51179
+ "StudioOpenWorkbookToolUI",
51180
+ {
51181
+ icon: ChartColumn,
51182
+ assetType: "spreadsheet",
51183
+ badge: "Sheet",
51184
+ runningLabel: () => "Opening workbook...",
51185
+ doneLabel: () => "Workbook opened",
51186
+ openLabel: () => "Open workbook",
51187
+ autoOpen: true
51188
+ }
51189
+ );
51190
+ const StudioCreatePresentationToolUI = createStudioPtcToolUI(
51191
+ "StudioCreatePresentationToolUI",
51192
+ {
51193
+ icon: Presentation,
51194
+ assetType: "presentation",
51195
+ badge: "Deck",
51196
+ runningLabel: (args) => {
51197
+ const title = getStringField(args, ["title", "name"]);
51198
+ return title ? `Creating presentation "${title}"...` : "Creating presentation...";
51199
+ },
51200
+ doneLabel: () => "Presentation created",
51201
+ getSubtitle: getNameSubtitle,
51202
+ getSlideNumber: () => 1,
51203
+ openLabel: () => "Open presentation",
51204
+ autoOpen: true
51205
+ }
51206
+ );
51207
+ const StudioOpenPresentationToolUI = createStudioPtcToolUI(
51208
+ "StudioOpenPresentationToolUI",
51209
+ {
51210
+ icon: Presentation,
51211
+ assetType: "presentation",
51212
+ badge: "Deck",
51213
+ runningLabel: () => "Opening presentation...",
51214
+ doneLabel: () => "Presentation opened",
51215
+ getSlideNumber: () => 1,
51216
+ getSubtitle: (_args, _result, slideNumber) => slideNumber ? `Slide ${slideNumber}` : void 0,
51217
+ openLabel: () => "Open presentation",
51218
+ autoOpen: true
51219
+ }
51220
+ );
51221
+ const StudioAddSlideToolUI = createStudioPtcToolUI(
51222
+ "StudioAddSlideToolUI",
51223
+ {
51224
+ icon: Presentation,
51225
+ assetType: "presentation",
51226
+ badge: "Deck",
51227
+ runningLabel: () => "Adding slide...",
51228
+ doneLabel: (_args, slideNumber) => slideNumber ? `Slide ${slideNumber} added` : "Slide added",
51229
+ getSubtitle: getSlideSubtitle,
51230
+ getSlideNumber,
51231
+ openLabel: (slideNumber) => slideNumber ? `Open slide ${slideNumber}` : "Open presentation",
51232
+ autoOpen: true
51233
+ }
51234
+ );
51235
+ const StudioCreateDocumentToolUI = createStudioPtcToolUI(
51236
+ "StudioCreateDocumentToolUI",
51237
+ {
51238
+ icon: FileText,
51239
+ assetType: "document",
51240
+ badge: "Doc",
51241
+ runningLabel: (args) => {
51242
+ const title = getStringField(args, ["title", "name"]);
51243
+ return title ? `Creating document "${title}"...` : "Creating document...";
51244
+ },
51245
+ doneLabel: () => "Document created",
51246
+ getSubtitle: getNameSubtitle,
51247
+ openLabel: () => "Open document",
51248
+ autoOpen: true
51249
+ }
51250
+ );
51251
+ const StudioCreateParagraphToolUI = createStudioPtcToolUI(
51252
+ "StudioCreateParagraphToolUI",
51253
+ {
51254
+ icon: FileText,
51255
+ assetType: "document",
51256
+ badge: "Doc",
51257
+ runningLabel: () => "Adding paragraph...",
51258
+ doneLabel: () => "Paragraph added",
51259
+ getSubtitle: getParagraphSubtitle,
51260
+ openLabel: () => "Open document",
51261
+ autoOpen: true
51262
+ }
51263
+ );
51264
+ const StudioOpenDocumentToolUI = createStudioPtcToolUI(
51265
+ "StudioOpenDocumentToolUI",
51266
+ {
51267
+ icon: FileText,
51268
+ assetType: "document",
51269
+ badge: "Doc",
51270
+ runningLabel: () => "Opening document...",
51271
+ doneLabel: () => "Document opened",
51272
+ openLabel: () => "Open document",
51273
+ autoOpen: true
51274
+ }
51275
+ );
50300
51276
  const CreateEmailDraftToolUIImpl = ({
50301
51277
  toolName,
50302
51278
  args,
@@ -51740,6 +52716,16 @@ const TOOL_UI_REGISTRY = {
51740
52716
  create_new_sheet: CreateSheetToolUI,
51741
52717
  create_powerpoint_deck: CreatePresentationToolUI,
51742
52718
  create_new_notebook: CreateNotebookToolUI,
52719
+ // Studio SDK nested PTC tools
52720
+ CreateWorkbook: StudioCreateWorkbookToolUI,
52721
+ AddSheet: StudioAddSheetToolUI,
52722
+ OpenWorkbook: StudioOpenWorkbookToolUI,
52723
+ CreatePresentation: StudioCreatePresentationToolUI,
52724
+ OpenPresentation: StudioOpenPresentationToolUI,
52725
+ AddSlide: StudioAddSlideToolUI,
52726
+ CreateDocument: StudioCreateDocumentToolUI,
52727
+ OpenDocument: StudioOpenDocumentToolUI,
52728
+ CreateParagraph: StudioCreateParagraphToolUI,
51743
52729
  execute_presentation_code: ExecutePresentationCodeToolUI,
51744
52730
  run_python_code: RunPythonCodeToolUI,
51745
52731
  open_asset_in_workspace: OpenAssetToolUI,
@@ -52360,14 +53346,14 @@ const useAthenaChatDefaultComponents = () => {
52360
53346
  return value;
52361
53347
  };
52362
53348
  const AthenaDefaultAssistantMessage = () => {
52363
- const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent, ActionBarComponent } = useAthenaChatDefaultComponents();
53349
+ const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent: EmptyComponent2, ActionBarComponent } = useAthenaChatDefaultComponents();
52364
53350
  return /* @__PURE__ */ jsx(
52365
53351
  AthenaAssistantMessage,
52366
53352
  {
52367
53353
  toolUIs,
52368
53354
  TextComponent,
52369
53355
  ReasoningComponent,
52370
- EmptyComponent,
53356
+ EmptyComponent: EmptyComponent2,
52371
53357
  ActionBarComponent
52372
53358
  }
52373
53359
  );
@@ -52392,6 +53378,16 @@ const getReasoningTokensFromMetadata = (metadata) => {
52392
53378
  return typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) ? reasoningTokens : void 0;
52393
53379
  };
52394
53380
  const formatReasoningTokens = (reasoningTokens) => `${reasoningTokens.toLocaleString("en-US")} ${reasoningTokens === 1 ? "token" : "tokens"}`;
53381
+ const withNestedPtcMessages = (ToolUI) => {
53382
+ const ToolUIWithNestedPtcMessages = (props) => {
53383
+ const nestedComponents = useNestedPtcComponents(ToolFallback);
53384
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
53385
+ /* @__PURE__ */ jsx(ToolUI, { ...props }),
53386
+ /* @__PURE__ */ jsx(NestedPtcMessages, { components: nestedComponents })
53387
+ ] });
53388
+ };
53389
+ return ToolUIWithNestedPtcMessages;
53390
+ };
52395
53391
  const SuggestionCard = ({
52396
53392
  suggestion,
52397
53393
  index: index2
@@ -52747,10 +53743,29 @@ const AthenaAssistantMessage = ({
52747
53743
  toolUIs,
52748
53744
  TextComponent = TiptapText,
52749
53745
  ReasoningComponent,
52750
- EmptyComponent = AthenaAssistantMessageEmpty,
53746
+ EmptyComponent: EmptyComponent2 = AthenaAssistantMessageEmpty,
52751
53747
  ActionBarComponent = AthenaAssistantActionBar
52752
53748
  }) => {
52753
53749
  const effectiveReasoningComponent = ReasoningComponent ?? AthenaReasoningPart;
53750
+ const toolUIsWithNestedMessages = useMemo(() => {
53751
+ const wrappedToolUIs = {};
53752
+ for (const [toolName, ToolUI] of Object.entries(toolUIs)) {
53753
+ wrappedToolUIs[toolName] = withNestedPtcMessages(ToolUI);
53754
+ }
53755
+ return wrappedToolUIs;
53756
+ }, [toolUIs]);
53757
+ const partsComponents = useMemo(
53758
+ () => ({
53759
+ Text: TextComponent,
53760
+ Reasoning: effectiveReasoningComponent,
53761
+ tools: {
53762
+ Fallback: ToolFallback,
53763
+ by_name: toolUIsWithNestedMessages
53764
+ },
53765
+ Empty: EmptyComponent2
53766
+ }),
53767
+ [EmptyComponent2, TextComponent, effectiveReasoningComponent, toolUIsWithNestedMessages]
53768
+ );
52754
53769
  return /* @__PURE__ */ jsxs(
52755
53770
  MessagePrimitive.Root,
52756
53771
  {
@@ -52758,20 +53773,7 @@ const AthenaAssistantMessage = ({
52758
53773
  "data-role": "assistant",
52759
53774
  children: [
52760
53775
  /* @__PURE__ */ jsx(AthenaReasoningTextComponentContext.Provider, { value: TextComponent, children: /* @__PURE__ */ jsxs("div", { className: "aui-assistant-message-content wrap-break-word px-2 text-foreground leading-relaxed", children: [
52761
- /* @__PURE__ */ jsx(
52762
- MessagePrimitive.Parts,
52763
- {
52764
- components: {
52765
- Text: TextComponent,
52766
- Reasoning: effectiveReasoningComponent,
52767
- tools: {
52768
- Fallback: ToolFallback,
52769
- by_name: toolUIs
52770
- },
52771
- Empty: EmptyComponent
52772
- }
52773
- }
52774
- ),
53776
+ /* @__PURE__ */ jsx(NestedPtcComponentsProvider, { components: partsComponents, children: /* @__PURE__ */ jsx(MessagePrimitive.Parts, { components: partsComponents }) }),
52775
53777
  /* @__PURE__ */ jsx(MessageError, {})
52776
53778
  ] }) }),
52777
53779
  /* @__PURE__ */ jsx("div", { className: "aui-assistant-message-footer mt-1 ml-2 flex", children: /* @__PURE__ */ jsx(ActionBarComponent, {}) })
@@ -52908,6 +53910,26 @@ function useAssetEmbed(assetId, options = {
52908
53910
  }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
52909
53911
  return { embedUrl, isLoading, error: error2 };
52910
53912
  }
53913
+ const ABSOLUTE_URL_PATTERN = /^[a-zA-Z][a-zA-Z\d+\-.]*:/;
53914
+ function buildAssetIframeSrc({
53915
+ embedUrl,
53916
+ assetType,
53917
+ slideNumber
53918
+ }) {
53919
+ const targetSlide = slideNumber;
53920
+ if (assetType !== "presentation" || typeof targetSlide !== "number" || !Number.isInteger(targetSlide) || targetSlide < 1) {
53921
+ return embedUrl;
53922
+ }
53923
+ try {
53924
+ const isAbsolute = ABSOLUTE_URL_PATTERN.test(embedUrl);
53925
+ const url = new URL(embedUrl, "https://athena.local");
53926
+ url.searchParams.set("slide", String(targetSlide));
53927
+ return isAbsolute ? url.toString() : `${url.pathname}${url.search}${url.hash}`;
53928
+ } catch {
53929
+ const separator = embedUrl.includes("?") ? "&" : "?";
53930
+ return `${embedUrl}${separator}slide=${targetSlide}`;
53931
+ }
53932
+ }
52911
53933
  const ASSET_TYPE_CONFIG = {
52912
53934
  presentation: { icon: Presentation, label: "Presentation" },
52913
53935
  spreadsheet: { icon: FileSpreadsheet, label: "Spreadsheet" },
@@ -52916,13 +53938,21 @@ const ASSET_TYPE_CONFIG = {
52916
53938
  unknown: { icon: File$1, label: "Asset" }
52917
53939
  };
52918
53940
  const AssetIframe = memo(
52919
- ({ tabId, tabName }) => {
53941
+ ({ tab }) => {
52920
53942
  const { backendUrl, apiKey, token } = useAthenaConfig();
52921
- const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tabId, {
53943
+ const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tab.id, {
52922
53944
  backendUrl,
52923
53945
  apiKey,
52924
53946
  token
52925
53947
  });
53948
+ const iframeSrc = useMemo(
53949
+ () => embedUrl ? buildAssetIframeSrc({
53950
+ embedUrl,
53951
+ assetType: tab.type,
53952
+ slideNumber: tab.slideNumber
53953
+ }) : null,
53954
+ [embedUrl, tab.slideNumber, tab.type]
53955
+ );
52926
53956
  if (isLoading) {
52927
53957
  return /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
52928
53958
  /* @__PURE__ */ jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
@@ -52936,16 +53966,16 @@ const AssetIframe = memo(
52936
53966
  /* @__PURE__ */ jsx("p", { className: "mt-0.5 line-clamp-2 break-words text-[10px] text-muted-foreground", children: error2 })
52937
53967
  ] }) });
52938
53968
  }
52939
- if (!embedUrl) return null;
53969
+ if (!iframeSrc) return null;
52940
53970
  return /* @__PURE__ */ jsx(
52941
53971
  "iframe",
52942
53972
  {
52943
- src: embedUrl,
53973
+ src: iframeSrc,
52944
53974
  width: "100%",
52945
53975
  height: "100%",
52946
53976
  frameBorder: "0",
52947
53977
  allow: "fullscreen",
52948
- title: tabName ?? `Asset ${tabId}`,
53978
+ title: tab.name ?? `Asset ${tab.id}`,
52949
53979
  className: "h-full w-full"
52950
53980
  }
52951
53981
  );
@@ -53007,7 +54037,7 @@ const PanelContent = ({
53007
54037
  }
53008
54038
  )
53009
54039
  ] }),
53010
- /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name }) })
54040
+ /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(AssetIframe, { tab }) })
53011
54041
  ]
53012
54042
  },
53013
54043
  tab.id
@@ -53017,7 +54047,7 @@ const PanelContent = ({
53017
54047
  "div",
53018
54048
  {
53019
54049
  className: isActive2 ? "h-full w-full" : "hidden",
53020
- children: /* @__PURE__ */ jsx(AssetIframe, { tabId: tab.id, tabName: tab.name })
54050
+ children: /* @__PURE__ */ jsx(AssetIframe, { tab })
53021
54051
  },
53022
54052
  tab.id
53023
54053
  );
@@ -53279,7 +54309,9 @@ export {
53279
54309
  FileUploadButton,
53280
54310
  GetDatabaseTableSchemaToolUI,
53281
54311
  ListDatabaseTablesToolUI,
54312
+ NestedPtcMessages,
53282
54313
  OpenAssetToolUI,
54314
+ PTC_SUBCALL_DID_NOT_COMPLETE_MESSAGE,
53283
54315
  ReadAssetToolUI,
53284
54316
  RunPythonCodeToolUI,
53285
54317
  RunSqlToolUI,
@@ -53304,9 +54336,11 @@ export {
53304
54336
  UpdateSheetRangeToolUI,
53305
54337
  WebSearchToolUI,
53306
54338
  archiveThread,
54339
+ autoCloseInFlightSubgraphMessages,
53307
54340
  buttonVariants,
53308
54341
  clearAutoOpenedAssets,
53309
54342
  cn,
54343
+ convertLangChainToThreadMessages,
53310
54344
  createAssetToolUI,
53311
54345
  createThread,
53312
54346
  formatToolName,