@supersolutions/super-chat-core 0.3.0 → 0.4.1

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.
@@ -1,6 +1,6 @@
1
- import { a as AnthropicStopReason, d as AnthropicResponse, e as AnthropicUsage } from './map-in-C5lFV2DR.js';
2
- export { f as AnthropicBuildOptions, g as AnthropicContentBlock, h as AnthropicDelta, i as AnthropicImageSource, j as AnthropicMessage, A as AnthropicProviderConfig, k as AnthropicRequest, l as AnthropicStreamEvent, m as AnthropicTool, n as AnthropicToolChoice, b as buildAnthropicRequest, c as createAnthropicProvider, o as dropOrphanToolUses, t as toAnthropicMessages } from './map-in-C5lFV2DR.js';
3
- import { F as FinishReason, C as ContentPart, U as Usage, S as StreamEvent } from './types-y3SK7HwA.js';
1
+ import { a as AnthropicStopReason, d as AnthropicResponse, e as AnthropicUsage } from './map-in-DM0YIl_X.js';
2
+ export { f as AnthropicBuildOptions, g as AnthropicContentBlock, h as AnthropicDelta, i as AnthropicImageSource, j as AnthropicMessage, A as AnthropicProviderConfig, k as AnthropicRequest, l as AnthropicStreamEvent, m as AnthropicTool, n as AnthropicToolChoice, b as buildAnthropicRequest, c as createAnthropicProvider, o as dropOrphanToolUses, t as toAnthropicMessages } from './map-in-DM0YIl_X.js';
3
+ import { F as FinishReason, C as ContentPart, U as Usage, S as StreamEvent } from './types-4pPC7-fh.js';
4
4
 
5
5
  declare function partsFromAnthropic(response: AnthropicResponse): ContentPart[];
6
6
  declare function finishFromAnthropic(reason: AnthropicStopReason | null | undefined): FinishReason;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as ContentPart, M as Message, a as MediaSource, b as MessageRole, T as ToolCallStatus, c as ToolFailureKind, d as TransportRequest, e as Transport, R as RetryPolicy, f as ModelInfo, P as ProviderCapabilities, g as Provider, h as CallOptions, J as JSONSchema, U as Usage, F as FinishReason, i as JobHandle, j as JobStatus, k as ToolSpec, N as NormalizedRequest, G as GenerateResult, l as ProviderFileRef } from './types-y3SK7HwA.js';
2
- export { D as DEFAULT_RETRY, m as FileUploadRequest, n as JobSnapshot, o as MultipartBody, p as ReasoningOptions, q as ResponseFormat, S as StreamEvent, r as ToolChoice, s as isMultipartBody } from './types-y3SK7HwA.js';
3
- export { J as JobStore, O as OpenAIDialect, a as OpenAIProviderConfig, R as ResumeResult, S as StoredJob, b as awaitJob, c as buildChatRequest, d as buildResponsesRequest, e as createLocalJobStore, f as createMemoryJobStore, g as createOpenAIProvider, i as isTerminal, r as reap, h as resumeJobs } from './map-in-CXwWaHl2.js';
4
- export { A as AnthropicProviderConfig, b as buildAnthropicRequest, c as createAnthropicProvider } from './map-in-C5lFV2DR.js';
1
+ import { C as ContentPart, M as Message, a as MediaSource, b as MessageRole, T as ToolCallStatus, c as ToolFailureKind, d as TransportRequest, e as Transport, R as RetryPolicy, f as ModelInfo, P as ProviderCapabilities, g as Provider, h as CallOptions, J as JSONSchema, U as Usage, F as FinishReason, i as JobHandle, j as JobStatus, k as ToolSpec, N as NormalizedRequest, G as GenerateResult, l as ProviderFileRef } from './types-4pPC7-fh.js';
2
+ export { D as DEFAULT_RETRY, m as FileUploadRequest, n as JobSnapshot, o as MultipartBody, p as ReasoningOptions, q as ResponseFormat, S as StreamEvent, r as ToolChoice, s as isMultipartBody } from './types-4pPC7-fh.js';
3
+ export { J as JobStore, O as OpenAIDialect, a as OpenAIProviderConfig, R as ResumeResult, S as StoredJob, b as awaitJob, c as buildChatRequest, d as buildResponsesRequest, e as createLocalJobStore, f as createMemoryJobStore, g as createOpenAIProvider, i as isTerminal, r as reap, h as resumeJobs } from './map-in-BhzgnLeg.js';
4
+ export { A as AnthropicProviderConfig, b as buildAnthropicRequest, c as createAnthropicProvider } from './map-in-DM0YIl_X.js';
5
5
 
6
6
  /**
7
7
  * Monotonic id. Deliberately not `crypto.randomUUID()` — ids show up in test
@@ -492,9 +492,23 @@ type CardSpec = BuiltinCard | ({
492
492
  kind: string;
493
493
  } & Record<string, unknown>);
494
494
  /** Envelope attached to a tool result, or returned by `visualize`. */
495
+ /**
496
+ * Where a host shows a card: in the conversation (`inline`, the default), in its side panel
497
+ * (`panel`), or inside a document block (`document`). The same renderer draws it in every place.
498
+ * Structurally the same as super-protocol's `CardPlacement`; core has no dependencies, so it is
499
+ * repeated here. An interactive card is only ever inline.
500
+ */
501
+ type CardPlacement = "inline" | "panel" | "document";
502
+ declare const CARD_PLACEMENTS: readonly CardPlacement[];
503
+ declare const isCardPlacement: (value: unknown) => value is CardPlacement;
495
504
  type Card = {
496
505
  id: string;
497
506
  spec: CardSpec;
507
+ /**
508
+ * Where the agent or tool asked for the card to be shown. Absent means `inline`. A host with no
509
+ * side panel shows a `panel` card inline; it never drops it.
510
+ */
511
+ placement?: CardPlacement;
498
512
  /** Set when the payload was dropped from persisted history. */
499
513
  expired?: boolean;
500
514
  /** Tool call this card belongs to, for correlating an action back. */
@@ -525,7 +539,7 @@ type CardCarrier = {
525
539
  } & Record<string, unknown>;
526
540
  declare function isCardCarrier(value: unknown): value is CardCarrier;
527
541
  /** Attach a card to a tool result without disturbing the data the model reads. */
528
- declare function withCard<T extends Record<string, unknown>>(data: T, spec: CardSpec, id?: string): T & CardCarrier;
542
+ declare function withCard<T extends Record<string, unknown>>(data: T, spec: CardSpec, id?: string, placement?: CardPlacement): T & CardCarrier;
529
543
  /**
530
544
  * Remove a card payload from a tool output, leaving a note in its place.
531
545
  *
@@ -1256,6 +1270,11 @@ type ToolExecutionContext = {
1256
1270
  surfaceActionTools?: readonly string[];
1257
1271
  };
1258
1272
  type ToolResultExtras = {
1273
+ /**
1274
+ * Where the card should be shown: `inline` (the default) or `panel`, the host's side panel.
1275
+ * Ignored without a card; an interactive card stays inline whatever is asked.
1276
+ */
1277
+ placement?: "inline" | "panel";
1259
1278
  /**
1260
1279
  * Update an EXISTING card instead of minting a new one: the runtime reuses
1261
1280
  * this id, and the reducer's upsert replaces the old card in place.
@@ -1849,7 +1868,7 @@ declare class CardRegistry {
1849
1868
  /** Per-kind schemas, for hosts that prefer one tool per card kind. */
1850
1869
  schemas(): Record<string, JSONSchema>;
1851
1870
  }
1852
- declare function makeCard(spec: CardSpec, callId?: string, id?: string): Card;
1871
+ declare function makeCard(spec: CardSpec, callId?: string, id?: string, placement?: CardPlacement): Card;
1853
1872
 
1854
1873
  declare const CARD_REF_SCHEME = "ref";
1855
1874
  declare const CARD_REF_LIMITS: Readonly<{
@@ -2171,6 +2190,22 @@ type RunEvent = {
2171
2190
  runId: string;
2172
2191
  mode: RunMode;
2173
2192
  }
2193
+ /**
2194
+ * Everything the run has produced so far, replacing what the consumer holds.
2195
+ *
2196
+ * For a consumer that joins a run part-way, or lost part of its stream: a
2197
+ * turn that runs on a server, followed over a connection that dropped, where
2198
+ * replaying every event is not possible. `runAgent` never emits it. The run
2199
+ * is live after it — a card still waiting on the person is announced again
2200
+ * with `awaiting-user`.
2201
+ */
2202
+ | {
2203
+ type: "run-snapshot";
2204
+ parts: ContentPart[];
2205
+ cards: Card[];
2206
+ usage?: Usage;
2207
+ steps?: number;
2208
+ }
2174
2209
  /** Emitted before the first provider call — the whole "why did it send that" answer. */
2175
2210
  | {
2176
2211
  type: "context-built";
@@ -2574,10 +2609,18 @@ declare function parsePartialJson(text: string): {
2574
2609
  complete: boolean;
2575
2610
  };
2576
2611
 
2612
+ /** Where `visualize` may put a card. `document` is not the agent's to choose from a chat. */
2613
+ type VisualizePlacement = "inline" | "panel";
2577
2614
  type VisualizeToolOptions = {
2578
2615
  cards: CardRegistry;
2579
2616
  /** Restrict which kinds the agent may emit (a read-only chat may want no `confirm`). */
2580
2617
  kinds?: string[];
2618
+ /**
2619
+ * Where the agent may put a card. Default `["inline"]`: the tool is exactly as before. Add
2620
+ * `"panel"` when the host shows a side panel (super-chat-ui's `ChatPanel`): the agent can then open
2621
+ * a card beside the conversation, for a chart or a document worth room of its own.
2622
+ */
2623
+ placements?: readonly VisualizePlacement[];
2581
2624
  };
2582
2625
  /**
2583
2626
  * The generic visualization tool.
@@ -2610,6 +2653,7 @@ declare function createBuiltinTools(opts: {
2610
2653
  cards: CardRegistry;
2611
2654
  skills?: SkillRegistry;
2612
2655
  surfaces?: SurfaceCatalogue;
2656
+ placements?: readonly VisualizePlacement[];
2613
2657
  }): ToolDefinition[];
2614
2658
 
2615
2659
  type StopContext = {
@@ -3098,4 +3142,4 @@ declare function createMcpSkill(serverName: string, defs: readonly ToolDefinitio
3098
3142
  */
3099
3143
  declare function elicitViaCard(requestCard: (spec: CardSpec) => Promise<unknown>): McpElicitHandler;
3100
3144
 
3101
- export { A2UI_VERSION, type A2uiMessage, ANTHROPIC_OFFICIAL_PROFILE, AgentError, type AgentErrorKind, type AppAction, type AppStateBinding, type AppStateSourceOptions, type AppliedEdit, BUILTIN_CARDS, type BindingScope, type BudgetShares, type BuiltContext, type BuiltinCard, type BuiltinCardKind, CARD_COMPONENT, CARD_ENTRY_PREFIX, CARD_KEY, CARD_REF_LIMITS, CARD_REF_SCHEME, CallOptions, type CalloutCard, type Card, type CardAction, type CardCarrier, type CardKindDefinition, type CardRef, type CardRefEvent, type CardRefHost, type CardRefParse, type CardRefResult, CardRegistry, type CardSpec, type CardTone, type CardValidation, type CardValueFormat, type ChartAnnotation, type ChartCard, type ChartSeries, type ChecklistCard, type ChoiceCard, type CitationsCard, type CodeCard, type CompactionResult, type ComparisonCard, type ConfirmCard, ContentPart, ContextBuilder, type ContextBuilderOptions, type ContextLayer, type ContextSource, type ContextSourceInput, type ContextSourceResult, type ContextTrace, DEFAULT_PRESETS, DEFAULT_STOP_CONDITIONS, type DiffCard, type DirectTransportConfig, type DocumentCard, type DocumentEdit, type DocumentOutlineEntry, type DocumentQuoteRef, type DocumentSnapshot, type DocumentStore, type DocumentToolsOptions, type EditHunk, type EditRejection, type EditResult, type EditReviewCard, type EmailCard, type ExecuteToolOptions, type FileStore, FinishReason, type FormCard, type FormField, type FunnelCard, type GaugeCard, type GenerateImageToolOptions, GenerateResult, type GeneratedMedia, type GeneratedMediaKind, type ImageGenerationRequest, JSONSchema, JobHandle, JobStatus, type KeyValueCard, type LayerId, MAILTO_SAFE_LENGTH, MESSAGE_OVERHEAD_TOKENS, type MailtoLink, type MarkdownBlock, type MarkdownBlockKind, type MarkdownCard, type McpCallResult, McpClient, type McpClientConfig, type McpContent, type McpElicitHandler, type McpElicitRequest, type McpElicitResult, type McpImportOptions, McpRpcError, type McpServerInfo, type McpTool, type MediaCard, type MediaJobHandle, type MediaJobSnapshot, type MediaProvider, type MediaProviderCapabilities, MediaSource, type MemoryEntry, type MemorySourceOptions, type MemoryStore, Message, MessageRole, type MeterSink, type MeteringError, type MeteringRecord, type MeteringSource, type MeteringStatus, ModelInfo, NormalizedRequest, OPENAI_OFFICIAL_PROFILE, type OpenAIImageProviderConfig, PartialJsonParser, type PartialToolCall, type PresetName, type ProfileDirectTransportConfig, type ProgressCard, type ProgressStep, Provider, ProviderCapabilities, ProviderFileRef, type ProviderProfile, type ProviderProtocol, type ProxyEnvelope, type ProxyTransportConfig, QUOTES_METADATA_KEY, type QuoteDrift, type RepairResult, type ResolvedSkill, type RestThreadStoreConfig, type RetrievalDoc, type RetrievalSourceOptions, type RetrievedChunk, type Retriever, RetryPolicy, type RunConfig, type RunEvent, type RunMeteringRecord, type RunMode, type RunState, SSEDecoder, type SSEMessage, SURFACE_A2UI_CATALOG_ID, SURFACE_ARTIFACT_KIND, SURFACE_CARD_KIND, SURFACE_EVENT_METADATA_KEY, SURFACE_FORMAT_VERSION, SURFACE_GUIDE, SURFACE_LIMITS, SURFACE_PRIMITIVES, SURFACE_SKILL_ID, SURFACE_TOOL_NAMES, type SchemaCheckOptions, type SchemaProblem, type SerializedMultipartBody, type Skill, type SkillContext, type SkillMatch, type SkillMatcher, type SkillMode, SkillRegistry, type SkillRegistryOptions, type SkillSection, type SpeechGenerationRequest, type StatItem, type StatsCard, type StepMeteringRecord, type StopCondition, type StopContext, type StoredFile, type StoredThread, type Summarizer, type SurfaceAction, type SurfaceActivity, type SurfaceActivityState, type SurfaceAggregateOp, type SurfaceBinding, type SurfaceBuildContext, type SurfaceBuildResult, type SurfaceCardAnswer, SurfaceCatalogue, type SurfaceCatalogueOptions, type SurfaceComponent, type SurfaceComponentCategory, type SurfaceComponentDefinition, type SurfaceCondition, type SurfaceConditionOp, type SurfaceEventRecord, type SurfaceIssue, type SurfaceIssueCode, type SurfaceItemBinding, SurfaceLedger, type SurfaceOperation, type SurfacePathBinding, type SurfacePendingPart, type SurfaceQuery, type SurfaceQueryBinding, type SurfaceSpec, type SurfaceTemplateBinding, type SurfaceToolAuthorization, type SurfaceToolRunConfig, type SurfaceToolsOptions, type SurfaceValidationContext, type SurfaceWhere, type SurfaceWhereOp, THREAD_SCHEMA_VERSION, type TableCard, type TableColumn, type ThreadMeta, type ThreadStore, type TimelineCard, type TokenBudget, type TokenCounter, type ToolApproval, type ToolCallOutcome, type ToolCallRequest, ToolCallStatus, type ToolDefinition, type ToolExecutionContext, ToolFailureKind, type ToolLoading, type ToolLoadingHint, ToolRegistry, type ToolResolution, type ToolResult, type ToolResultExtras, type ToolSide, ToolSpec, type TraceEntry, type Transcript, type TranscriptionRequest, Transport, TransportRequest, type TreeCard, type TreeNode, type TurnLayoutOptions, type TurnSegment, type UnsafeFinding, Usage, type VideoGenerationRequest, afterTool, appendReasoning, appendText, applyEdits, applySurfaceOperations, approvalCard, assistantMessage, authorizeSurfaceTool, backoffDelay, base64ToBytes, bindingProblems, buildEml, buildMailto, buildSummaryPrompt, buildSurface, buildUrl, bytesToBase64, calloutCard, chartCard, check, checkQuoteDrift, checkSchema, checklistCard, childrenOf, choiceCard, citationsCard, codeCard, combineMeteringSources, compactError, compactHistory, comparisonCard, confirmCard, consecutiveFailures, countMessageTokens, countMessagesTokens, createAppActionTools, createAppStateSource, createBudget, createBuiltinTools, createDirectTransport, createDirectTransportForProfile, createDocumentTools, createEmailDraftTool, createGenerateImageTool, createHttpTransport, createKeywordRetriever, createLoadSkillTool, createLocalDocumentStore, createLocalFileStore, createLocalMemoryStore, createLocalThreadStore, createMcpSkill, createMemoryDocumentStore, createMemoryFileStore, createMemoryMemoryStore, createMemorySource, createMemoryThreadStore, createOpenAICompatibleProfile, createOpenAIImageProvider, createProviderFromProfile, createProxyTransport, createRememberTool, createRestThreadStore, createRetrievalSource, createSurfaceContextSource, createSurfaceSkill, createSurfaceTools, createUpdateCardTool, createVisualizeTool, deliverMetering, diffCard, documentCard, editReviewCard, elicitViaCard, emailCard, emlFilename, errorFromResponse, estimateJsonTokens, estimateTokens, evaluateSurfaceCondition, executeToolCall, executeToolCalls, file, findUnsafe, foldSurfaces, formCard, formatQuotes, formatTemplate, funnelCard, gaugeCard, generatedMediaUrl, getAt, hasTurnOrder, humanizeFieldName, hunksOf, image, importMcpTools, initialRunState, isAgentError, isCardCarrier, isScriptUrl, isSurfaceBinding, isSurfaceId, isSurfaceSpec, isTextPart, isToolCallPart, isToolResultPart, keyValueCard, kindFromStatus, lastUserText, latestLeaf, layoutTurn, linkLinear, makeCard, mapMcpResult, markdownCard, matchSkills, mediaCard, message, messageText, nextId, noToolCalls, normalizeProviderProfile, normalizeToolName, outlineOf, packByPriority, parseCardRef, parsePartialJson, parsePointer, parseRetryAfter, parseSSE, parseSSEJson, pathTo, previewSurface, progressCard, quoteDrift, quotesOf, reduceRunEvent, removeAt, renderSkill, repairToolArguments, resolvePartialCard, resolveSurfaceAction, resolveSurfaceValue, resolveToolLoading, runAgent, runSurfaceQuery, runSurfaceToolAction, safeCutIndex, safeSurfaceUrl, sanitizeSurfaceSpec, scoreSkill, searchBlocks, setAt, shouldStop, siblingsOf, spanOf, splitBlocks, statsCard, stepCountIs, stripCardPayload, stripUiOnlyParts, surfaceActionTools, surfaceCardId, tableCard, text, threadSnapshot, timelineCard, toA2uiMessages, toAgentError, tokenBudgetExceeded, tokenize, toolCall, toolCallsIn, toolResult, totalAllocated, treeCard, trimHistory, usageSource, userDeclined, userMessage, usesBinding, validateSurfaceAction, validateSurfaceComponent, validateSurfaceComponents, validateSurfaceGraph, withCard, withQuotes, withRetry };
3145
+ export { A2UI_VERSION, type A2uiMessage, ANTHROPIC_OFFICIAL_PROFILE, AgentError, type AgentErrorKind, type AppAction, type AppStateBinding, type AppStateSourceOptions, type AppliedEdit, BUILTIN_CARDS, type BindingScope, type BudgetShares, type BuiltContext, type BuiltinCard, type BuiltinCardKind, CARD_COMPONENT, CARD_ENTRY_PREFIX, CARD_KEY, CARD_PLACEMENTS, CARD_REF_LIMITS, CARD_REF_SCHEME, CallOptions, type CalloutCard, type Card, type CardAction, type CardCarrier, type CardKindDefinition, type CardPlacement, type CardRef, type CardRefEvent, type CardRefHost, type CardRefParse, type CardRefResult, CardRegistry, type CardSpec, type CardTone, type CardValidation, type CardValueFormat, type ChartAnnotation, type ChartCard, type ChartSeries, type ChecklistCard, type ChoiceCard, type CitationsCard, type CodeCard, type CompactionResult, type ComparisonCard, type ConfirmCard, ContentPart, ContextBuilder, type ContextBuilderOptions, type ContextLayer, type ContextSource, type ContextSourceInput, type ContextSourceResult, type ContextTrace, DEFAULT_PRESETS, DEFAULT_STOP_CONDITIONS, type DiffCard, type DirectTransportConfig, type DocumentCard, type DocumentEdit, type DocumentOutlineEntry, type DocumentQuoteRef, type DocumentSnapshot, type DocumentStore, type DocumentToolsOptions, type EditHunk, type EditRejection, type EditResult, type EditReviewCard, type EmailCard, type ExecuteToolOptions, type FileStore, FinishReason, type FormCard, type FormField, type FunnelCard, type GaugeCard, type GenerateImageToolOptions, GenerateResult, type GeneratedMedia, type GeneratedMediaKind, type ImageGenerationRequest, JSONSchema, JobHandle, JobStatus, type KeyValueCard, type LayerId, MAILTO_SAFE_LENGTH, MESSAGE_OVERHEAD_TOKENS, type MailtoLink, type MarkdownBlock, type MarkdownBlockKind, type MarkdownCard, type McpCallResult, McpClient, type McpClientConfig, type McpContent, type McpElicitHandler, type McpElicitRequest, type McpElicitResult, type McpImportOptions, McpRpcError, type McpServerInfo, type McpTool, type MediaCard, type MediaJobHandle, type MediaJobSnapshot, type MediaProvider, type MediaProviderCapabilities, MediaSource, type MemoryEntry, type MemorySourceOptions, type MemoryStore, Message, MessageRole, type MeterSink, type MeteringError, type MeteringRecord, type MeteringSource, type MeteringStatus, ModelInfo, NormalizedRequest, OPENAI_OFFICIAL_PROFILE, type OpenAIImageProviderConfig, PartialJsonParser, type PartialToolCall, type PresetName, type ProfileDirectTransportConfig, type ProgressCard, type ProgressStep, Provider, ProviderCapabilities, ProviderFileRef, type ProviderProfile, type ProviderProtocol, type ProxyEnvelope, type ProxyTransportConfig, QUOTES_METADATA_KEY, type QuoteDrift, type RepairResult, type ResolvedSkill, type RestThreadStoreConfig, type RetrievalDoc, type RetrievalSourceOptions, type RetrievedChunk, type Retriever, RetryPolicy, type RunConfig, type RunEvent, type RunMeteringRecord, type RunMode, type RunState, SSEDecoder, type SSEMessage, SURFACE_A2UI_CATALOG_ID, SURFACE_ARTIFACT_KIND, SURFACE_CARD_KIND, SURFACE_EVENT_METADATA_KEY, SURFACE_FORMAT_VERSION, SURFACE_GUIDE, SURFACE_LIMITS, SURFACE_PRIMITIVES, SURFACE_SKILL_ID, SURFACE_TOOL_NAMES, type SchemaCheckOptions, type SchemaProblem, type SerializedMultipartBody, type Skill, type SkillContext, type SkillMatch, type SkillMatcher, type SkillMode, SkillRegistry, type SkillRegistryOptions, type SkillSection, type SpeechGenerationRequest, type StatItem, type StatsCard, type StepMeteringRecord, type StopCondition, type StopContext, type StoredFile, type StoredThread, type Summarizer, type SurfaceAction, type SurfaceActivity, type SurfaceActivityState, type SurfaceAggregateOp, type SurfaceBinding, type SurfaceBuildContext, type SurfaceBuildResult, type SurfaceCardAnswer, SurfaceCatalogue, type SurfaceCatalogueOptions, type SurfaceComponent, type SurfaceComponentCategory, type SurfaceComponentDefinition, type SurfaceCondition, type SurfaceConditionOp, type SurfaceEventRecord, type SurfaceIssue, type SurfaceIssueCode, type SurfaceItemBinding, SurfaceLedger, type SurfaceOperation, type SurfacePathBinding, type SurfacePendingPart, type SurfaceQuery, type SurfaceQueryBinding, type SurfaceSpec, type SurfaceTemplateBinding, type SurfaceToolAuthorization, type SurfaceToolRunConfig, type SurfaceToolsOptions, type SurfaceValidationContext, type SurfaceWhere, type SurfaceWhereOp, THREAD_SCHEMA_VERSION, type TableCard, type TableColumn, type ThreadMeta, type ThreadStore, type TimelineCard, type TokenBudget, type TokenCounter, type ToolApproval, type ToolCallOutcome, type ToolCallRequest, ToolCallStatus, type ToolDefinition, type ToolExecutionContext, ToolFailureKind, type ToolLoading, type ToolLoadingHint, ToolRegistry, type ToolResolution, type ToolResult, type ToolResultExtras, type ToolSide, ToolSpec, type TraceEntry, type Transcript, type TranscriptionRequest, Transport, TransportRequest, type TreeCard, type TreeNode, type TurnLayoutOptions, type TurnSegment, type UnsafeFinding, Usage, type VideoGenerationRequest, type VisualizePlacement, type VisualizeToolOptions, afterTool, appendReasoning, appendText, applyEdits, applySurfaceOperations, approvalCard, assistantMessage, authorizeSurfaceTool, backoffDelay, base64ToBytes, bindingProblems, buildEml, buildMailto, buildSummaryPrompt, buildSurface, buildUrl, bytesToBase64, calloutCard, chartCard, check, checkQuoteDrift, checkSchema, checklistCard, childrenOf, choiceCard, citationsCard, codeCard, combineMeteringSources, compactError, compactHistory, comparisonCard, confirmCard, consecutiveFailures, countMessageTokens, countMessagesTokens, createAppActionTools, createAppStateSource, createBudget, createBuiltinTools, createDirectTransport, createDirectTransportForProfile, createDocumentTools, createEmailDraftTool, createGenerateImageTool, createHttpTransport, createKeywordRetriever, createLoadSkillTool, createLocalDocumentStore, createLocalFileStore, createLocalMemoryStore, createLocalThreadStore, createMcpSkill, createMemoryDocumentStore, createMemoryFileStore, createMemoryMemoryStore, createMemorySource, createMemoryThreadStore, createOpenAICompatibleProfile, createOpenAIImageProvider, createProviderFromProfile, createProxyTransport, createRememberTool, createRestThreadStore, createRetrievalSource, createSurfaceContextSource, createSurfaceSkill, createSurfaceTools, createUpdateCardTool, createVisualizeTool, deliverMetering, diffCard, documentCard, editReviewCard, elicitViaCard, emailCard, emlFilename, errorFromResponse, estimateJsonTokens, estimateTokens, evaluateSurfaceCondition, executeToolCall, executeToolCalls, file, findUnsafe, foldSurfaces, formCard, formatQuotes, formatTemplate, funnelCard, gaugeCard, generatedMediaUrl, getAt, hasTurnOrder, humanizeFieldName, hunksOf, image, importMcpTools, initialRunState, isAgentError, isCardCarrier, isCardPlacement, isScriptUrl, isSurfaceBinding, isSurfaceId, isSurfaceSpec, isTextPart, isToolCallPart, isToolResultPart, keyValueCard, kindFromStatus, lastUserText, latestLeaf, layoutTurn, linkLinear, makeCard, mapMcpResult, markdownCard, matchSkills, mediaCard, message, messageText, nextId, noToolCalls, normalizeProviderProfile, normalizeToolName, outlineOf, packByPriority, parseCardRef, parsePartialJson, parsePointer, parseRetryAfter, parseSSE, parseSSEJson, pathTo, previewSurface, progressCard, quoteDrift, quotesOf, reduceRunEvent, removeAt, renderSkill, repairToolArguments, resolvePartialCard, resolveSurfaceAction, resolveSurfaceValue, resolveToolLoading, runAgent, runSurfaceQuery, runSurfaceToolAction, safeCutIndex, safeSurfaceUrl, sanitizeSurfaceSpec, scoreSkill, searchBlocks, setAt, shouldStop, siblingsOf, spanOf, splitBlocks, statsCard, stepCountIs, stripCardPayload, stripUiOnlyParts, surfaceActionTools, surfaceCardId, tableCard, text, threadSnapshot, timelineCard, toA2uiMessages, toAgentError, tokenBudgetExceeded, tokenize, toolCall, toolCallsIn, toolResult, totalAllocated, treeCard, trimHistory, usageSource, userDeclined, userMessage, usesBinding, validateSurfaceAction, validateSurfaceComponent, validateSurfaceComponents, validateSurfaceGraph, withCard, withQuotes, withRetry };
package/dist/index.js CHANGED
@@ -1070,12 +1070,15 @@ var SkillRegistry = class {
1070
1070
  };
1071
1071
 
1072
1072
  // src/cards/types.ts
1073
+ var CARD_PLACEMENTS = ["inline", "panel", "document"];
1074
+ var isCardPlacement = (value) => CARD_PLACEMENTS.includes(value);
1073
1075
  var CARD_KEY = "$card";
1074
1076
  function isCardCarrier(value) {
1075
1077
  return typeof value === "object" && value !== null && CARD_KEY in value && typeof value[CARD_KEY] === "object";
1076
1078
  }
1077
- function withCard(data, spec, id) {
1078
- return { ...data, [CARD_KEY]: { id: id ?? `card_${Math.random().toString(36).slice(2, 10)}`, spec } };
1079
+ function withCard(data, spec, id, placement) {
1080
+ const card = { id: id ?? `card_${Math.random().toString(36).slice(2, 10)}`, spec, ...placement && placement !== "inline" ? { placement } : {} };
1081
+ return { ...data, [CARD_KEY]: card };
1079
1082
  }
1080
1083
  function stripCardPayload(output) {
1081
1084
  if (!isCardCarrier(output)) return output;
@@ -2138,10 +2141,11 @@ var CardRegistry = class {
2138
2141
  }
2139
2142
  };
2140
2143
  var cardCounter = 0;
2141
- function makeCard(spec, callId, id) {
2142
- if (id) return { id, spec, ...callId ? { callId } : {} };
2144
+ function makeCard(spec, callId, id, placement) {
2145
+ const where = placement && placement !== "inline" ? { placement } : {};
2146
+ if (id) return { id, spec, ...callId ? { callId } : {}, ...where };
2143
2147
  cardCounter += 1;
2144
- return { id: `card_${Date.now().toString(36)}${cardCounter.toString(36)}`, spec, ...callId ? { callId } : {} };
2148
+ return { id: `card_${Date.now().toString(36)}${cardCounter.toString(36)}`, spec, ...callId ? { callId } : {}, ...where };
2145
2149
  }
2146
2150
 
2147
2151
  // src/cards/card-ref.ts
@@ -4803,7 +4807,7 @@ async function confirmationRefusal(tool, call, opts) {
4803
4807
  if (opts.signal?.aborted) return "The run was stopped before this was approved.";
4804
4808
  return answer?.confirmed === true ? void 0 : "The user declined.";
4805
4809
  }
4806
- var isToolResult = (v) => typeof v === "object" && v !== null && "output" in v && Object.keys(v).every((k) => ["output", "card", "failure", "cardId", "unlockTools"].includes(k));
4810
+ var isToolResult = (v) => typeof v === "object" && v !== null && "output" in v && Object.keys(v).every((k) => ["output", "card", "failure", "cardId", "unlockTools", "placement"].includes(k));
4807
4811
  async function executeToolCall(call, opts) {
4808
4812
  const started = Date.now();
4809
4813
  const tool = opts.toolIndex ? opts.toolIndex.get(call.name) : opts.tools.find((t) => t.name === call.name);
@@ -4849,8 +4853,8 @@ async function executeToolCall(call, opts) {
4849
4853
  let card = emittedCard;
4850
4854
  let output = result.output;
4851
4855
  if (result.card) {
4852
- card = makeCard(result.card, call.callId, result.cardId);
4853
- output = withCard(asRecord(result.output), card.spec, card.id);
4856
+ card = makeCard(result.card, call.callId, result.cardId, result.placement === "panel" ? "panel" : void 0);
4857
+ output = withCard(asRecord(result.output), card.spec, card.id, card.placement);
4854
4858
  opts.onCard?.(card);
4855
4859
  } else if (isCardCarrier(result.output)) {
4856
4860
  const embedded = result.output[CARD_KEY];
@@ -5487,6 +5491,7 @@ function parsePartialJson(text3) {
5487
5491
  function createVisualizeTool(opts) {
5488
5492
  const { cards } = opts;
5489
5493
  const available = opts.kinds ? cards.list().filter((k) => opts.kinds.includes(k.kind)) : cards.list();
5494
+ const panel = (opts.placements ?? ["inline"]).includes("panel");
5490
5495
  const catalogue = available.map((k) => `- ${k.kind}${k.interactive ? " (interactive \u2014 the user replies)" : ""}: ${k.summary}`).join("\n");
5491
5496
  return {
5492
5497
  name: "visualize",
@@ -5502,13 +5507,19 @@ function createVisualizeTool(opts) {
5502
5507
  "- Put the data IN the card. Do not also repeat every row in your prose \u2014 say what it means instead.",
5503
5508
  "- Interactive kinds (choice, form, confirm) pause for the user's answer, which is returned to you as this tool's result. Use them instead of guessing.",
5504
5509
  "- Use `confirm` before anything consequential or irreversible.",
5505
- "- One card per distinct idea. Do not wrap a one-line answer in a card."
5510
+ "- One card per distinct idea. Do not wrap a one-line answer in a card.",
5511
+ ...panel ? [
5512
+ '- `placement: "panel"` opens the card in the side panel beside the chat, with room to explore: use it for a chart the user will work with or a long document. Keep small results (a few figures, a short table) inline, the default.',
5513
+ "- Interactive kinds are always inline."
5514
+ ] : []
5506
5515
  ].join("\n"),
5507
5516
  inputSchema: {
5508
5517
  type: "object",
5509
5518
  required: ["kind", "spec"],
5510
5519
  properties: {
5511
5520
  kind: { type: "string", enum: available.map((k) => k.kind), description: "Which card to render." },
5521
+ // Before `spec`, so it streams first: a panel card is not previewed in the chat.
5522
+ ...panel ? { placement: { type: "string", enum: ["inline", "panel"], description: "Where to show the card: in the chat (inline, default) or in the side panel." } } : {},
5512
5523
  spec: {
5513
5524
  type: "object",
5514
5525
  description: "The card body. Must match the schema for `kind`, and must include `kind` itself.",
@@ -5536,14 +5547,19 @@ function createVisualizeTool(opts) {
5536
5547
  // `cards.partial` refuses interactive kinds and anything its own validator
5537
5548
  // rejects; `execute` below stays the only path to a real card.
5538
5549
  partialCard: (input) => {
5539
- const { kind, spec } = input ?? {};
5550
+ const { kind, spec, placement } = input ?? {};
5540
5551
  if (typeof kind !== "string" || !isObj(spec)) return void 0;
5552
+ if (placement === "panel") return void 0;
5541
5553
  if (opts.kinds && !opts.kinds.includes(kind)) return void 0;
5542
5554
  return cards.partial({ ...spec, kind });
5543
5555
  },
5544
5556
  async execute(input, ctx) {
5545
- const { kind, spec } = input ?? {};
5557
+ const { kind, spec, placement } = input ?? {};
5546
5558
  if (!kind) return { output: { ok: false, error: "`kind` is required." }, failure: "invalid-input" };
5559
+ if (placement !== void 0 && placement !== "inline" && !(panel && placement === "panel")) {
5560
+ const allowed = panel ? '"inline" or "panel"' : '"inline" (this chat has no side panel)';
5561
+ return { output: { ok: false, error: `placement must be ${allowed}.` }, failure: "invalid-input" };
5562
+ }
5547
5563
  const full = { ...spec ?? {}, kind };
5548
5564
  const verdict = cards.validate(full);
5549
5565
  if (!verdict.ok) {
@@ -5555,10 +5571,14 @@ function createVisualizeTool(opts) {
5555
5571
  };
5556
5572
  }
5557
5573
  const def = cards.get(kind);
5574
+ if (placement === "panel" && def?.interactive) {
5575
+ return { output: { ok: false, error: `${kind} asks the user something, so it is shown in the chat: send it without placement.` }, failure: "invalid-input" };
5576
+ }
5558
5577
  if (def?.interactive && ctx.requestCard) {
5559
5578
  const answer = await ctx.requestCard(full);
5560
5579
  return { output: { ok: true, kind, response: answer } };
5561
5580
  }
5581
+ if (placement === "panel") return { output: { ok: true, kind, rendered: true, placement: "panel" }, card: full, placement: "panel" };
5562
5582
  return { output: { ok: true, kind, rendered: true }, card: full };
5563
5583
  }
5564
5584
  };
@@ -5624,7 +5644,7 @@ function createUpdateCardTool(cards) {
5624
5644
  };
5625
5645
  }
5626
5646
  function createBuiltinTools(opts) {
5627
- const tools = [createVisualizeTool({ cards: opts.cards }), createUpdateCardTool(opts.cards)];
5647
+ const tools = [createVisualizeTool({ cards: opts.cards, ...opts.placements ? { placements: opts.placements } : {} }), createUpdateCardTool(opts.cards)];
5628
5648
  if (opts.surfaces) tools.push(...createSurfaceTools({ catalogue: opts.surfaces }));
5629
5649
  if (opts.skills && opts.skills.list().some((s) => s.mode === "manual")) {
5630
5650
  tools.push(createLoadSkillTool(opts.skills));
@@ -5651,6 +5671,22 @@ function reduceRunEvent(state, event) {
5651
5671
  switch (event.type) {
5652
5672
  case "run-start":
5653
5673
  return { ...state, runId: event.runId, mode: event.mode, status: "running" };
5674
+ case "run-snapshot":
5675
+ return {
5676
+ ...state,
5677
+ status: "running",
5678
+ parts: event.parts,
5679
+ cards: event.cards,
5680
+ pendingCard: void 0,
5681
+ pendingTools: Object.fromEntries(
5682
+ event.parts.flatMap(
5683
+ (p) => p.type === "tool-call" && p.status === "running" ? [[p.callId, { callId: p.callId, name: p.name }]] : []
5684
+ )
5685
+ ),
5686
+ partialTools: {},
5687
+ ...event.usage ? { usage: event.usage } : {},
5688
+ ...event.steps != null ? { steps: event.steps } : {}
5689
+ };
5654
5690
  case "context-built":
5655
5691
  return { ...state, trace: event.trace, toolNames: event.toolNames };
5656
5692
  case "step-start":
@@ -5783,8 +5819,10 @@ function upsertCard(cards, card) {
5783
5819
  const i = cards.findIndex((c) => c.id === card.id);
5784
5820
  if (i === -1) return [...cards, card];
5785
5821
  const next = [...cards];
5786
- const home = cards[i].callId;
5787
- next[i] = home ? { ...card, callId: home } : card;
5822
+ const prev = cards[i];
5823
+ const home = prev.callId;
5824
+ const placement = card.placement ?? prev.placement;
5825
+ next[i] = { ...card, ...home ? { callId: home } : {}, ...placement ? { placement } : {} };
5788
5826
  return next;
5789
5827
  }
5790
5828
  function markCallDone(parts, callId, status) {
@@ -7113,6 +7151,7 @@ export {
7113
7151
  CARD_COMPONENT,
7114
7152
  CARD_ENTRY_PREFIX,
7115
7153
  CARD_KEY,
7154
+ CARD_PLACEMENTS,
7116
7155
  CARD_REF_LIMITS,
7117
7156
  CARD_REF_SCHEME,
7118
7157
  CardRegistry,
@@ -7251,6 +7290,7 @@ export {
7251
7290
  initialRunState,
7252
7291
  isAgentError,
7253
7292
  isCardCarrier,
7293
+ isCardPlacement,
7254
7294
  isMultipartBody,
7255
7295
  isScriptUrl,
7256
7296
  isSurfaceBinding,