@supersolutions/super-chat-core 0.2.3 → 0.3.0
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.d.ts +87 -2
- package/dist/index.js +172 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -424,14 +424,16 @@ type FormCard = {
|
|
|
424
424
|
};
|
|
425
425
|
type ConfirmCard = {
|
|
426
426
|
kind: "confirm";
|
|
427
|
+
/** The one question the buttons answer, such as "Rename the report?". Shown last, above the buttons. */
|
|
427
428
|
title: string;
|
|
428
|
-
/** The consequential
|
|
429
|
+
/** The consequential details — amounts, targets, anything irreversible. May be empty when `description` already says all of it. */
|
|
429
430
|
summary: {
|
|
430
431
|
label: string;
|
|
431
432
|
value: string | number;
|
|
432
433
|
tone?: CardTone;
|
|
433
434
|
mono?: boolean;
|
|
434
435
|
}[];
|
|
436
|
+
/** What will happen, in a sentence or two. Shown first. */
|
|
435
437
|
description?: string;
|
|
436
438
|
confirmLabel?: string;
|
|
437
439
|
cancelLabel?: string;
|
|
@@ -1273,6 +1275,27 @@ type ToolResult = ToolResultExtras & {
|
|
|
1273
1275
|
card?: CardSpec;
|
|
1274
1276
|
failure?: "execution-error" | "denied" | "invalid-input" | "timeout" | "not-found";
|
|
1275
1277
|
};
|
|
1278
|
+
/**
|
|
1279
|
+
* How an approval card reads, in the words of the person approving. The card shows
|
|
1280
|
+
* `description`, then any `summary` rows, then `title` as the question above the buttons.
|
|
1281
|
+
*/
|
|
1282
|
+
type ToolApproval = {
|
|
1283
|
+
/** The one question the buttons answer, such as "Rename the report?". */
|
|
1284
|
+
title?: string;
|
|
1285
|
+
/** What will happen, in a sentence or two, such as "Your report will be titled “Q3 review”.". */
|
|
1286
|
+
description?: string;
|
|
1287
|
+
/** Exact details worth checking: amounts, targets, anything irreversible. Omit when the sentence says it all. */
|
|
1288
|
+
summary?: {
|
|
1289
|
+
label: string;
|
|
1290
|
+
value: string;
|
|
1291
|
+
}[];
|
|
1292
|
+
/** The verb on the approve button, such as "Rename". Defaults to "Allow". */
|
|
1293
|
+
confirmLabel?: string;
|
|
1294
|
+
/** Defaults to "Not now". */
|
|
1295
|
+
cancelLabel?: string;
|
|
1296
|
+
/** Marks an action that is hard to undo. */
|
|
1297
|
+
danger?: boolean;
|
|
1298
|
+
};
|
|
1276
1299
|
type ToolDefinition = {
|
|
1277
1300
|
name: string;
|
|
1278
1301
|
description: string;
|
|
@@ -1298,6 +1321,12 @@ type ToolDefinition = {
|
|
|
1298
1321
|
* saying so is asked about twice, which is the safe way for that to go wrong.
|
|
1299
1322
|
*/
|
|
1300
1323
|
confirmation?: "runtime" | "tool";
|
|
1324
|
+
/**
|
|
1325
|
+
* The approval card's wording, written for the person approving the action. Without
|
|
1326
|
+
* it the card shows the first sentence of `description` and the input's plain fields.
|
|
1327
|
+
* Never shown to the model.
|
|
1328
|
+
*/
|
|
1329
|
+
approval?: (input: unknown) => ToolApproval | undefined;
|
|
1301
1330
|
/** Ask the provider to enforce the schema (OpenAI strict mode). */
|
|
1302
1331
|
strict?: boolean;
|
|
1303
1332
|
/** Default card renderer key when the result carries no explicit card. */
|
|
@@ -1822,6 +1851,52 @@ declare class CardRegistry {
|
|
|
1822
1851
|
}
|
|
1823
1852
|
declare function makeCard(spec: CardSpec, callId?: string, id?: string): Card;
|
|
1824
1853
|
|
|
1854
|
+
declare const CARD_REF_SCHEME = "ref";
|
|
1855
|
+
declare const CARD_REF_LIMITS: Readonly<{
|
|
1856
|
+
/** The whole link, in UTF-16 code units. */
|
|
1857
|
+
length: 512;
|
|
1858
|
+
/** The target (the card's id). */
|
|
1859
|
+
target: 128;
|
|
1860
|
+
/** Distinct param names. */
|
|
1861
|
+
names: 16;
|
|
1862
|
+
/** Values of one param name (`key=a&key=b`). */
|
|
1863
|
+
values: 32;
|
|
1864
|
+
/** One param name. */
|
|
1865
|
+
name: 32;
|
|
1866
|
+
/** One decoded value, in UTF-16 code units. */
|
|
1867
|
+
value: 256;
|
|
1868
|
+
}>;
|
|
1869
|
+
/** A parsed reference. A repeated param is a list in order; values are decoded once, never split on commas. */
|
|
1870
|
+
interface CardRef {
|
|
1871
|
+
/** The `id` of the card this points into. */
|
|
1872
|
+
target: string;
|
|
1873
|
+
params: Record<string, string[]>;
|
|
1874
|
+
}
|
|
1875
|
+
/** What the reader did with the link: pointed at it, left it, or chose it (click, Enter, tap). */
|
|
1876
|
+
type CardRefEvent = "enter" | "leave" | "activate";
|
|
1877
|
+
/** What a card answers. `ok: false` lets the host show a stale reference as plain text, with the reason. */
|
|
1878
|
+
type CardRefResult = {
|
|
1879
|
+
ok: true;
|
|
1880
|
+
label?: string;
|
|
1881
|
+
} | {
|
|
1882
|
+
ok: false;
|
|
1883
|
+
code: string;
|
|
1884
|
+
reason: string;
|
|
1885
|
+
};
|
|
1886
|
+
type CardRefParse = {
|
|
1887
|
+
ok: true;
|
|
1888
|
+
ref: CardRef;
|
|
1889
|
+
} | {
|
|
1890
|
+
ok: false;
|
|
1891
|
+
error: string;
|
|
1892
|
+
};
|
|
1893
|
+
/** A host's side of references: hands one on to the card it points into. `null` clears everything shown. */
|
|
1894
|
+
interface CardRefHost {
|
|
1895
|
+
ref(ref: CardRef | null, event: CardRefEvent): CardRefResult;
|
|
1896
|
+
}
|
|
1897
|
+
/** Reads a `ref:` link. */
|
|
1898
|
+
declare function parseCardRef(href: unknown): CardRefParse;
|
|
1899
|
+
|
|
1825
1900
|
declare const tableCard: CardKindDefinition;
|
|
1826
1901
|
declare const statsCard: CardKindDefinition;
|
|
1827
1902
|
declare const chartCard: CardKindDefinition;
|
|
@@ -2430,6 +2505,16 @@ type A2uiMessage = {
|
|
|
2430
2505
|
/** The messages that would recreate this surface in an A2UI client. */
|
|
2431
2506
|
declare function toA2uiMessages(spec: SurfaceSpec): A2uiMessage[];
|
|
2432
2507
|
|
|
2508
|
+
/** "documentId" → "Document", "max_retry_count" → "Max retry count". */
|
|
2509
|
+
declare function humanizeFieldName(key: string): string;
|
|
2510
|
+
/**
|
|
2511
|
+
* The approval card for a tool call. A tool's own `approval` wording wins; without it
|
|
2512
|
+
* the card uses the first sentence of the description and the input's plain fields.
|
|
2513
|
+
*/
|
|
2514
|
+
declare function approvalCard(tool: Pick<ToolDefinition, "description" | "approval">, input: unknown, options?: {
|
|
2515
|
+
danger?: boolean;
|
|
2516
|
+
}): CardSpec;
|
|
2517
|
+
|
|
2433
2518
|
type RepairResult = {
|
|
2434
2519
|
value: unknown;
|
|
2435
2520
|
repaired: boolean;
|
|
@@ -3013,4 +3098,4 @@ declare function createMcpSkill(serverName: string, defs: readonly ToolDefinitio
|
|
|
3013
3098
|
*/
|
|
3014
3099
|
declare function elicitViaCard(requestCard: (spec: CardSpec) => Promise<unknown>): McpElicitHandler;
|
|
3015
3100
|
|
|
3016
|
-
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, CallOptions, type CalloutCard, type Card, type CardAction, type CardCarrier, type CardKindDefinition, 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 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, 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, 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, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -2119,14 +2119,14 @@ var CardRegistry = class {
|
|
|
2119
2119
|
if (!isObj(spec) || typeof spec["kind"] !== "string") return void 0;
|
|
2120
2120
|
const def = this.kinds.get(spec["kind"]);
|
|
2121
2121
|
if (!def?.partial || def.interactive) return void 0;
|
|
2122
|
-
let
|
|
2122
|
+
let preview;
|
|
2123
2123
|
try {
|
|
2124
|
-
|
|
2124
|
+
preview = def.partial(spec);
|
|
2125
2125
|
} catch {
|
|
2126
2126
|
return void 0;
|
|
2127
2127
|
}
|
|
2128
|
-
if (!isObj(
|
|
2129
|
-
return def.validate(
|
|
2128
|
+
if (!isObj(preview) || preview["kind"] !== def.kind) return void 0;
|
|
2129
|
+
return def.validate(preview).ok ? preview : void 0;
|
|
2130
2130
|
}
|
|
2131
2131
|
/** The catalogue text embedded in the `visualize` tool description. */
|
|
2132
2132
|
describe() {
|
|
@@ -2144,6 +2144,75 @@ function makeCard(spec, callId, id) {
|
|
|
2144
2144
|
return { id: `card_${Date.now().toString(36)}${cardCounter.toString(36)}`, spec, ...callId ? { callId } : {} };
|
|
2145
2145
|
}
|
|
2146
2146
|
|
|
2147
|
+
// src/cards/card-ref.ts
|
|
2148
|
+
var CARD_REF_SCHEME = "ref";
|
|
2149
|
+
var CARD_REF_LIMITS = Object.freeze({
|
|
2150
|
+
/** The whole link, in UTF-16 code units. */
|
|
2151
|
+
length: 512,
|
|
2152
|
+
/** The target (the card's id). */
|
|
2153
|
+
target: 128,
|
|
2154
|
+
/** Distinct param names. */
|
|
2155
|
+
names: 16,
|
|
2156
|
+
/** Values of one param name (`key=a&key=b`). */
|
|
2157
|
+
values: 32,
|
|
2158
|
+
/** One param name. */
|
|
2159
|
+
name: 32,
|
|
2160
|
+
/** One decoded value, in UTF-16 code units. */
|
|
2161
|
+
value: 256
|
|
2162
|
+
});
|
|
2163
|
+
var TARGET = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
2164
|
+
var NAME = /^[a-z][A-Za-z0-9_-]{0,31}$/;
|
|
2165
|
+
var RAW_VALUE = /^(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+$/;
|
|
2166
|
+
var hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
2167
|
+
function decodeValue(raw) {
|
|
2168
|
+
const bytes = [];
|
|
2169
|
+
for (let i = 0; i < raw.length; i++) {
|
|
2170
|
+
if (raw[i] === "%") {
|
|
2171
|
+
bytes.push(parseInt(raw.slice(i + 1, i + 3), 16));
|
|
2172
|
+
i += 2;
|
|
2173
|
+
} else bytes.push(raw.charCodeAt(i));
|
|
2174
|
+
}
|
|
2175
|
+
try {
|
|
2176
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));
|
|
2177
|
+
} catch {
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
function parseCardRef(href) {
|
|
2182
|
+
const fail = (error) => ({ ok: false, error });
|
|
2183
|
+
if (typeof href !== "string") return fail("a ref must be a string.");
|
|
2184
|
+
if (href.length > CARD_REF_LIMITS.length) return fail(`a ref is at most ${CARD_REF_LIMITS.length} characters.`);
|
|
2185
|
+
if (!href.startsWith(`${CARD_REF_SCHEME}:`)) return fail(`a ref starts with "${CARD_REF_SCHEME}:".`);
|
|
2186
|
+
const rest = href.slice(CARD_REF_SCHEME.length + 1);
|
|
2187
|
+
if (rest.includes("#")) return fail("a ref has no fragment.");
|
|
2188
|
+
const q = rest.indexOf("?");
|
|
2189
|
+
const target = q < 0 ? rest : rest.slice(0, q);
|
|
2190
|
+
if (!TARGET.test(target)) return fail("a ref target is 1 to 128 letters, digits, dot, underscore, colon or dash, starting with a letter or digit.");
|
|
2191
|
+
const params = {};
|
|
2192
|
+
if (q >= 0) {
|
|
2193
|
+
const query = rest.slice(q + 1);
|
|
2194
|
+
if (query === "") return fail("a ref query is empty.");
|
|
2195
|
+
for (const part of query.split("&")) {
|
|
2196
|
+
const eq = part.indexOf("=");
|
|
2197
|
+
if (eq < 0) return fail("each ref param is name=value.");
|
|
2198
|
+
const name = part.slice(0, eq);
|
|
2199
|
+
const raw = part.slice(eq + 1);
|
|
2200
|
+
if (!NAME.test(name)) return fail("a ref param name is 1 to 32 letters, digits, dash or underscore, starting with a lowercase letter.");
|
|
2201
|
+
if (!RAW_VALUE.test(raw)) return fail("a ref param value is not empty and uses letters, digits, dot, dash, underscore, tilde or %XX only.");
|
|
2202
|
+
const value = decodeValue(raw);
|
|
2203
|
+
if (value === null) return fail("a ref param value must be valid UTF-8.");
|
|
2204
|
+
if (value.length > CARD_REF_LIMITS.value) return fail(`a ref param value is at most ${CARD_REF_LIMITS.value} characters.`);
|
|
2205
|
+
if (!hasOwn(params, name)) {
|
|
2206
|
+
if (Object.keys(params).length >= CARD_REF_LIMITS.names) return fail(`a ref has at most ${CARD_REF_LIMITS.names} param names.`);
|
|
2207
|
+
params[name] = [];
|
|
2208
|
+
}
|
|
2209
|
+
if (params[name].length >= CARD_REF_LIMITS.values) return fail(`a ref param has at most ${CARD_REF_LIMITS.values} values.`);
|
|
2210
|
+
params[name].push(value);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
return { ok: true, ref: { target, params } };
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2147
2216
|
// src/cards/builtin.ts
|
|
2148
2217
|
var ok = { ok: true };
|
|
2149
2218
|
var arrived = (spec, field, ready) => {
|
|
@@ -3067,7 +3136,7 @@ var formCard = {
|
|
|
3067
3136
|
var confirmCard = {
|
|
3068
3137
|
kind: "confirm",
|
|
3069
3138
|
interactive: true,
|
|
3070
|
-
summary: "Get explicit approval before a consequential action. `
|
|
3139
|
+
summary: "Get explicit approval before a consequential action. `description` says what will happen in plain words, `summary` lists exact amounts, targets, and anything irreversible, and `title` is the one question the buttons answer.",
|
|
3071
3140
|
estimateTokens: tokensOf,
|
|
3072
3141
|
schema: {
|
|
3073
3142
|
type: "object",
|
|
@@ -3099,7 +3168,8 @@ var confirmCard = {
|
|
|
3099
3168
|
if (failed(s)) return s;
|
|
3100
3169
|
const o = s;
|
|
3101
3170
|
if (typeof o["title"] !== "string") return { ok: false, error: "confirm.title is required." };
|
|
3102
|
-
const
|
|
3171
|
+
const hasDescription = typeof o["description"] === "string" && o["description"].trim() !== "";
|
|
3172
|
+
const summary = check.arrayField(o, "summary", "confirm", hasDescription ? 0 : 1);
|
|
3103
3173
|
if (failed(summary)) return summary;
|
|
3104
3174
|
return ok;
|
|
3105
3175
|
}
|
|
@@ -4626,6 +4696,97 @@ var EventChannel = class {
|
|
|
4626
4696
|
}
|
|
4627
4697
|
};
|
|
4628
4698
|
|
|
4699
|
+
// src/tools/approval.ts
|
|
4700
|
+
var MAX_FIELDS = 6;
|
|
4701
|
+
var MAX_VALUE_CHARS = 160;
|
|
4702
|
+
var MAX_DESCRIPTION_CHARS = 240;
|
|
4703
|
+
var clip = (text3, max) => text3.length > max ? `${text3.slice(0, max - 1)}\u2026` : text3;
|
|
4704
|
+
function humanizeFieldName(key) {
|
|
4705
|
+
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_\-.]+/).filter(Boolean).map((word) => word.toLowerCase());
|
|
4706
|
+
if (words.length > 1 && (words[words.length - 1] === "id" || words[words.length - 1] === "ids")) words.pop();
|
|
4707
|
+
const text3 = words.join(" ");
|
|
4708
|
+
return text3 ? text3.charAt(0).toUpperCase() + text3.slice(1) : key;
|
|
4709
|
+
}
|
|
4710
|
+
function plainValue(value) {
|
|
4711
|
+
if (typeof value === "string") return value.trim() ? clip(value.trim(), MAX_VALUE_CHARS) : void 0;
|
|
4712
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
4713
|
+
if (typeof value === "boolean") return value ? "Yes" : "No";
|
|
4714
|
+
if (Array.isArray(value)) {
|
|
4715
|
+
const items = value.map(plainValue);
|
|
4716
|
+
if (value.length && items.every((item) => item !== void 0)) return clip(items.join(", "), MAX_VALUE_CHARS);
|
|
4717
|
+
return value.length === 1 ? "1 item" : `${value.length} items`;
|
|
4718
|
+
}
|
|
4719
|
+
return void 0;
|
|
4720
|
+
}
|
|
4721
|
+
function firstSentence(description) {
|
|
4722
|
+
const text3 = description.trim().replace(/\s+/g, " ");
|
|
4723
|
+
const end = text3.search(/[.!?](\s|$)/);
|
|
4724
|
+
return clip(end === -1 ? text3 : text3.slice(0, end + 1), MAX_DESCRIPTION_CHARS);
|
|
4725
|
+
}
|
|
4726
|
+
function fieldsOf(input) {
|
|
4727
|
+
if (input === void 0 || input === null) return [];
|
|
4728
|
+
if (typeof input !== "object" || Array.isArray(input)) {
|
|
4729
|
+
const value = plainValue(input);
|
|
4730
|
+
return value === void 0 ? [] : [{ label: "Details", value }];
|
|
4731
|
+
}
|
|
4732
|
+
const fields = [];
|
|
4733
|
+
for (const [key, raw] of Object.entries(input)) {
|
|
4734
|
+
const value = plainValue(raw);
|
|
4735
|
+
if (value !== void 0) fields.push({ label: humanizeFieldName(key), value });
|
|
4736
|
+
if (fields.length === MAX_FIELDS) break;
|
|
4737
|
+
}
|
|
4738
|
+
return fields;
|
|
4739
|
+
}
|
|
4740
|
+
var MAX_TITLE_CHARS = 120;
|
|
4741
|
+
var MAX_LABEL_CHARS = 40;
|
|
4742
|
+
var textOr = (value, max) => typeof value === "string" && value.trim() ? clip(value.trim().replace(/\s+/g, " "), max) : void 0;
|
|
4743
|
+
function customApproval(tool, input) {
|
|
4744
|
+
if (typeof tool.approval !== "function") return void 0;
|
|
4745
|
+
let raw;
|
|
4746
|
+
try {
|
|
4747
|
+
raw = tool.approval(input);
|
|
4748
|
+
} catch {
|
|
4749
|
+
return void 0;
|
|
4750
|
+
}
|
|
4751
|
+
if (typeof raw !== "object" || raw === null) return void 0;
|
|
4752
|
+
const r = raw;
|
|
4753
|
+
const title = textOr(r["title"], MAX_TITLE_CHARS);
|
|
4754
|
+
const description = textOr(r["description"], MAX_DESCRIPTION_CHARS);
|
|
4755
|
+
const confirmLabel = textOr(r["confirmLabel"], MAX_LABEL_CHARS);
|
|
4756
|
+
const cancelLabel = textOr(r["cancelLabel"], MAX_LABEL_CHARS);
|
|
4757
|
+
const summary = Array.isArray(r["summary"]) ? r["summary"].flatMap((row) => {
|
|
4758
|
+
const label = textOr(row?.label, MAX_LABEL_CHARS);
|
|
4759
|
+
const value = textOr(row?.value, MAX_VALUE_CHARS);
|
|
4760
|
+
return label && value ? [{ label, value }] : [];
|
|
4761
|
+
}).slice(0, MAX_FIELDS) : void 0;
|
|
4762
|
+
if (!title && !description) return void 0;
|
|
4763
|
+
return {
|
|
4764
|
+
...title ? { title } : {},
|
|
4765
|
+
...description ? { description } : {},
|
|
4766
|
+
...summary ? { summary } : {},
|
|
4767
|
+
...confirmLabel ? { confirmLabel } : {},
|
|
4768
|
+
...cancelLabel ? { cancelLabel } : {},
|
|
4769
|
+
...typeof r["danger"] === "boolean" ? { danger: r["danger"] } : {}
|
|
4770
|
+
};
|
|
4771
|
+
}
|
|
4772
|
+
function approvalCard(tool, input, options = {}) {
|
|
4773
|
+
const custom = customApproval(tool, input);
|
|
4774
|
+
let description = custom?.description ?? firstSentence(tool.description);
|
|
4775
|
+
let summary = custom ? custom.summary ?? [] : fieldsOf(input);
|
|
4776
|
+
if (!summary.length && !description) summary = [{ label: "Action", value: "Run a tool" }];
|
|
4777
|
+
description ||= void 0;
|
|
4778
|
+
const danger = custom?.danger ?? options.danger;
|
|
4779
|
+
return {
|
|
4780
|
+
kind: "confirm",
|
|
4781
|
+
title: custom?.title ?? "Allow this?",
|
|
4782
|
+
...description ? { description } : {},
|
|
4783
|
+
summary,
|
|
4784
|
+
confirmLabel: custom?.confirmLabel ?? "Allow",
|
|
4785
|
+
cancelLabel: custom?.cancelLabel ?? "Not now",
|
|
4786
|
+
...danger ? { danger: true } : {}
|
|
4787
|
+
};
|
|
4788
|
+
}
|
|
4789
|
+
|
|
4629
4790
|
// src/runtime/execute-tools.ts
|
|
4630
4791
|
var MAX_ERROR_CHARS = 400;
|
|
4631
4792
|
function compactError(e) {
|
|
@@ -4635,23 +4796,6 @@ function compactError(e) {
|
|
|
4635
4796
|
const message2 = e instanceof Error ? e.message : String(e);
|
|
4636
4797
|
return { error: message2.slice(0, MAX_ERROR_CHARS) || "Tool failed with no message." };
|
|
4637
4798
|
}
|
|
4638
|
-
var PREVIEW_CHARS = 200;
|
|
4639
|
-
var PREVIEW_FIELDS = 8;
|
|
4640
|
-
var preview = (value) => {
|
|
4641
|
-
const text3 = typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
4642
|
-
return text3.length > PREVIEW_CHARS ? `${text3.slice(0, PREVIEW_CHARS)}\u2026` : text3;
|
|
4643
|
-
};
|
|
4644
|
-
function approvalCard(tool, input) {
|
|
4645
|
-
const fields = typeof input === "object" && input !== null && !Array.isArray(input) ? Object.entries(input).slice(0, PREVIEW_FIELDS).map(([label, value]) => ({ label, value: preview(value), mono: true })) : input === void 0 || input === null ? [] : [{ label: "Input", value: preview(input), mono: true }];
|
|
4646
|
-
return {
|
|
4647
|
-
kind: "confirm",
|
|
4648
|
-
title: `Allow ${tool.name}?`,
|
|
4649
|
-
description: preview(tool.description),
|
|
4650
|
-
summary: fields.length ? fields : [{ label: "Tool", value: tool.name, mono: true }],
|
|
4651
|
-
confirmLabel: "Allow",
|
|
4652
|
-
cancelLabel: "Decline"
|
|
4653
|
-
};
|
|
4654
|
-
}
|
|
4655
4799
|
async function confirmationRefusal(tool, call, opts) {
|
|
4656
4800
|
if (!opts.requestCard) return `"${tool.name}" needs the user's approval and this host cannot ask for it.`;
|
|
4657
4801
|
if (tool.confirmation === "tool") return void 0;
|
|
@@ -6969,6 +7113,8 @@ export {
|
|
|
6969
7113
|
CARD_COMPONENT,
|
|
6970
7114
|
CARD_ENTRY_PREFIX,
|
|
6971
7115
|
CARD_KEY,
|
|
7116
|
+
CARD_REF_LIMITS,
|
|
7117
|
+
CARD_REF_SCHEME,
|
|
6972
7118
|
CardRegistry,
|
|
6973
7119
|
ContextBuilder,
|
|
6974
7120
|
DEFAULT_PRESETS,
|
|
@@ -7002,6 +7148,7 @@ export {
|
|
|
7002
7148
|
appendText,
|
|
7003
7149
|
applyEdits,
|
|
7004
7150
|
applySurfaceOperations,
|
|
7151
|
+
approvalCard,
|
|
7005
7152
|
assistantMessage,
|
|
7006
7153
|
authorizeSurfaceTool,
|
|
7007
7154
|
awaitJob,
|
|
@@ -7097,6 +7244,7 @@ export {
|
|
|
7097
7244
|
generatedMediaUrl,
|
|
7098
7245
|
getAt,
|
|
7099
7246
|
hasTurnOrder,
|
|
7247
|
+
humanizeFieldName,
|
|
7100
7248
|
hunksOf,
|
|
7101
7249
|
image,
|
|
7102
7250
|
importMcpTools,
|
|
@@ -7131,6 +7279,7 @@ export {
|
|
|
7131
7279
|
normalizeToolName,
|
|
7132
7280
|
outlineOf,
|
|
7133
7281
|
packByPriority,
|
|
7282
|
+
parseCardRef,
|
|
7134
7283
|
parsePartialJson,
|
|
7135
7284
|
parsePointer,
|
|
7136
7285
|
parseRetryAfter,
|