@ai-matrx/chat 0.4.9 → 0.4.12
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/CHANGELOG.md +53 -0
- package/dist/agents/components/context-items/bodies/ContextInputBody.js +1 -1
- package/dist/agents/components/context-items/bodies/GenericBody.js +1 -1
- package/dist/agents/components/conversation-actions/conversation-verbs.js +1 -1
- package/dist/agents/components/inputs/smart-input/RunSkillPicker.js +1 -1
- package/dist/agents/components/live-run/LiveRunDisplay.js +1 -1
- package/dist/agents/components/live-run/LiveRunProgress.js +1 -1
- package/dist/agents/components/live-run/RunSetDisplay.js +1 -1
- package/dist/agents/components/messages-display/assistant/AgentAssistantMessage.js +2 -2
- package/dist/agents/components/messages-display/assistant/InPlaceAnswerEditor.js +1 -1
- package/dist/agents/components/messages-display/conversation-tools/find-in-conversation.js +1 -1
- package/dist/agents/components/messages-display/message-options/buildTaskSeedFromMessage.js +1 -1
- package/dist/agents/components/messages-display/user/AgentUserMessage.js +1 -1
- package/dist/agents/components/messages-display/user/FirstTurnVariables.js +1 -1
- package/dist/agents/components/run/AgentStatusIndicator.js +1 -1
- package/dist/agents/components/run/RunJobWorkingLine.js +1 -1
- package/dist/agents/components/shared/AgentNewRunButton.js +1 -1
- package/dist/agents/components/shared/AgentPlanningIndicator.js +1 -1
- package/dist/agents/conversation-export/conversation-transfer.js +1 -1
- package/dist/agents/conversation-export/document-markdown.js +1 -1
- package/dist/agents/hooks/useConversationRoutePromotion.js +1 -1
- package/dist/agents/hooks/useModelControls.js +1 -1
- package/dist/agents/redux/agent-definition/converters.js +1 -1
- package/dist/agents/redux/agent-definition/slice.js +1 -1
- package/dist/agents/redux/conversation-list/conversation-list.thunks.js +1 -1
- package/dist/agents/redux/execution-system/active-requests/active-requests.selectors.js +1 -1
- package/dist/agents/redux/execution-system/instance-context/sync-canvas-item-context.thunk.js +1 -1
- package/dist/agents/redux/execution-system/thunks/process-stream.js +1 -1
- package/dist/agents/redux/execution-system/thunks/resolve-base-url.js +17 -0
- package/dist/agents/redux/execution-system/thunks/run-ai-stream.d.ts +7 -0
- package/dist/agents/redux/execution-system/thunks/run-ai-stream.js +13 -0
- package/dist/agents/redux/execution-system/thunks/run-headless-agent-json.js +14 -2
- package/dist/agents/redux/execution-system/utils/assemble-cx-content-blocks.js +1 -1
- package/dist/agents/redux/execution-system/utils/normalize-content-blocks.js +1 -1
- package/dist/agents/redux/execution-system/utils/output-contract-guard.js +1 -1
- package/dist/agents/redux/execution-system/utils/stream-block-accumulator.js +8 -8
- package/dist/agents/routing/confidential-routing.d.ts +52 -0
- package/dist/agents/routing/confidential-routing.js +38 -0
- package/dist/agents/utils/canvasItemContext.js +1 -1
- package/dist/canvas/workspace/ChatPanelTitleMenu.js +1 -1
- package/dist/canvas/workspace/useCanvasWorkspaceConversation.js +1 -1
- package/dist/cx-chat/components/SsrSidebarChats.js +1 -1
- package/dist/cx-chat/components/core/ChatConversationClient.js +1 -1
- package/dist/cx-chat/components/messages/AssistantMessage.js +1 -1
- package/dist/cx-chat/hooks/useInstanceBootstrap.js +1 -1
- package/dist/cx-conversation/AssistantMessage.js +1 -1
- package/dist/host/configure.js +4 -1
- package/dist/host/contract.d.ts +14 -1
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/mandates/llm-params.d.ts +1 -1
- package/dist/mandates/output-contract.js +1 -1
- package/dist/mandates/service.d.ts +1 -1
- package/dist/mandates/service.js +1 -1
- package/dist/mandates/test-run-core.js +1 -1
- package/dist/public-chat/components/PublicMessageOptionsMenu.js +1 -1
- package/dist/surfaces/services/surface-config.service.js +1 -1
- package/dist/tool-call-visualization/components/ToolCallBatch.js +1 -1
- package/dist/tool-call-visualization/components/ToolCallVisualization.js +1 -1
- package/dist/tool-call-visualization/renderers/agent-call/AgentCallInline.js +1 -1
- package/dist/tool-call-visualization/renderers/agent-call/CollabCallCard.js +1 -1
- package/dist/tool-call-visualization/renderers/agent-call/collab-subtitle.js +3 -3
- package/dist/tool-call-visualization/renderers/skill/SkillInline.js +1 -1
- package/dist/tool-call-visualization/result-fields/KeyValueGrid.js +1 -1
- package/dist/tool-call-visualization/result-fields/ResultValue.js +1 -1
- package/dist/tool-call-visualization/result-fields/shape.js +1 -1
- package/dist/tool-call-visualization/utils/cxToolCallToLifecycleEntry.js +2 -2
- package/dist/tool-call-visualization/utils/human-copy.js +3 -3
- package/dist/ui/mandates-storage/provision-shapes.d.ts +1 -1
- package/dist/ui/mandates-storage/provision-shapes.js +1 -1
- package/dist/ui/markdown-stream/EnhancedChatMarkdown.js +1 -1
- package/dist/ui/treatment-shape.d.ts +1 -1
- package/dist/ui/treatment-shape.js +1 -1
- package/dist/voice-agent/relay/useVoiceRelaySession.js +1 -1
- package/package.json +26 -9
- package/dist/agents/hooks/useWarmAgent.d.ts +0 -8
- package/dist/agents/hooks/useWarmAgent.js +0 -25
- package/dist/agents/utils/artifactId.d.ts +0 -34
- package/dist/agents/utils/artifactId.js +0 -15
- package/dist/ui/ShimmerText.d.ts +0 -5
- package/dist/ui/ShimmerText.js +0 -21
- package/dist/ui/addressWithoutNavigating.d.ts +0 -68
- package/dist/ui/addressWithoutNavigating.js +0 -60
- package/dist/utils/content-ir/decision-answers-ids.d.ts +0 -3
- package/dist/utils/content-ir/decision-answers-ids.js +0 -6
- package/dist/utils/content-ir/envelope-parity.d.ts +0 -12
- package/dist/utils/content-ir/envelope-parity.js +0 -32
- package/dist/utils/content-ir/instance-title.d.ts +0 -26
- package/dist/utils/content-ir/instance-title.js +0 -39
- package/dist/utils/content-ir/kinds/kind-markdown-utils.d.ts +0 -84
- package/dist/utils/content-ir/kinds/kind-markdown-utils.js +0 -233
- package/dist/utils/content-ir/kinds/kind-value-markdown.d.ts +0 -5
- package/dist/utils/content-ir/kinds/kind-value-markdown.js +0 -17
- package/dist/utils/content-ir/legacy-quiz-envelope.d.ts +0 -3
- package/dist/utils/content-ir/legacy-quiz-envelope.js +0 -45
- package/dist/utils/content-ir/surfaces/embedded-kind-json.d.ts +0 -140
- package/dist/utils/content-ir/surfaces/embedded-kind-json.js +0 -527
- package/dist/utils/content-ir/surfaces/json-kind-signal.d.ts +0 -307
- package/dist/utils/content-ir/surfaces/json-kind-signal.js +0 -945
- package/dist/utils/content-ir/surfaces/kind-image-alt.d.ts +0 -27
- package/dist/utils/content-ir/surfaces/kind-image-alt.js +0 -117
- package/dist/utils/content-ir/surfaces/kind-one-line.d.ts +0 -67
- package/dist/utils/content-ir/surfaces/kind-one-line.js +0 -209
- package/dist/utils/content-ir/surfaces/kind-text-label.d.ts +0 -20
- package/dist/utils/content-ir/surfaces/kind-text-label.js +0 -50
- package/dist/utils/content-ir/surfaces/kind-text-to-markdown.d.ts +0 -47
- package/dist/utils/content-ir/surfaces/kind-text-to-markdown.js +0 -399
- package/dist/utils/content-ir/surfaces/markdown-escaped-kind.d.ts +0 -54
- package/dist/utils/content-ir/surfaces/markdown-escaped-kind.js +0 -128
- package/dist/utils/content-ir/surfaces/quoted-kind-lift.d.ts +0 -61
- package/dist/utils/content-ir/surfaces/quoted-kind-lift.js +0 -215
- package/dist/utils/inline-decision/decision-options.d.ts +0 -21
- package/dist/utils/inline-decision/decision-options.js +0 -32
- package/dist/utils/json.d.ts +0 -63
- package/dist/utils/json.js +0 -22
- package/dist/utils/markdown/plain-title.d.ts +0 -25
- package/dist/utils/markdown/plain-title.js +0 -51
- package/dist/utils/rendered-find.d.ts +0 -9
- package/dist/utils/rendered-find.js +0 -68
- package/dist/utils/rich-editor/core/caret-context.d.ts +0 -24
- package/dist/utils/rich-editor/core/caret-context.js +0 -73
- package/dist/utils/rich-editor/in-place/caret-handoff.d.ts +0 -3
- package/dist/utils/rich-editor/in-place/caret-handoff.js +0 -15
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A KIND AS AN IMAGE'S ALT TEXT (P9, round 4): ``. The
|
|
3
|
-
* prose split lifted the object out and left `!` and `(url)` behind as two
|
|
4
|
-
* stray prose blocks after reload (and live). The model meant the kind: the
|
|
5
|
-
* image wrapper is chrome — `` after it are
|
|
6
|
-
* dropped, the object stays where it was and renders as its kind. A kindless
|
|
7
|
-
* object in alt text (first key decided not `__kind`) is left as written.
|
|
8
|
-
*
|
|
9
|
-
* ONE transform, both hosts (like `quoted-kind-lift.ts`): the live accumulator
|
|
10
|
-
* pushes every delta through a `KindImageAltUnwrap`; the static splitter runs
|
|
11
|
-
* `unwrapKindImageAlt` on the whole text. Character-driven and chunk-invariant.
|
|
12
|
-
*/
|
|
13
|
-
export declare class KindImageAltUnwrap {
|
|
14
|
-
private mode;
|
|
15
|
-
/** Held: `!` / `. */
|
|
16
|
-
private held;
|
|
17
|
-
private depth;
|
|
18
|
-
private inString;
|
|
19
|
-
private escape;
|
|
20
|
-
push(text: string): string;
|
|
21
|
-
flush(): string;
|
|
22
|
-
/** Track JSON structure; returns true when the object just closed. */
|
|
23
|
-
private track;
|
|
24
|
-
private pushChar;
|
|
25
|
-
}
|
|
26
|
-
/** The whole-text form, for the static splitter (identical bytes to any streaming of `source`). */
|
|
27
|
-
export declare function unwrapKindImageAlt(source: string): string;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { jsonKindSignal } from "./json-kind-signal.js";
|
|
2
|
-
const HEAD_LIMIT = 2e3;
|
|
3
|
-
class KindImageAltUnwrap {
|
|
4
|
-
mode = "scan";
|
|
5
|
-
/** Held: `!` / `. */
|
|
6
|
-
held = "";
|
|
7
|
-
depth = 0;
|
|
8
|
-
inString = false;
|
|
9
|
-
escape = false;
|
|
10
|
-
push(text) {
|
|
11
|
-
let out = "";
|
|
12
|
-
for (const ch of text) out += this.pushChar(ch);
|
|
13
|
-
return out;
|
|
14
|
-
}
|
|
15
|
-
flush() {
|
|
16
|
-
const out = this.mode === "head" ? `![${this.held}` : this.held;
|
|
17
|
-
this.mode = "scan";
|
|
18
|
-
this.held = "";
|
|
19
|
-
this.depth = 0;
|
|
20
|
-
this.inString = false;
|
|
21
|
-
this.escape = false;
|
|
22
|
-
return out;
|
|
23
|
-
}
|
|
24
|
-
/** Track JSON structure; returns true when the object just closed. */
|
|
25
|
-
track(ch) {
|
|
26
|
-
if (this.escape) {
|
|
27
|
-
this.escape = false;
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (this.inString) {
|
|
31
|
-
if (ch === "\\") this.escape = true;
|
|
32
|
-
else if (ch === '"') this.inString = false;
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
if (ch === '"') this.inString = true;
|
|
36
|
-
else if (ch === "{" || ch === "[") this.depth += 1;
|
|
37
|
-
else if (ch === "}" || ch === "]") {
|
|
38
|
-
this.depth -= 1;
|
|
39
|
-
return this.depth === 0;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
pushChar(ch) {
|
|
44
|
-
switch (this.mode) {
|
|
45
|
-
case "scan": {
|
|
46
|
-
if (this.held === "" && ch === "!") {
|
|
47
|
-
this.held = "!";
|
|
48
|
-
return "";
|
|
49
|
-
}
|
|
50
|
-
if (this.held === "!" && ch === "[") {
|
|
51
|
-
this.held = "![";
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
if (this.held === "![" && ch === "{") {
|
|
55
|
-
this.mode = "head";
|
|
56
|
-
this.held = "{";
|
|
57
|
-
this.depth = 1;
|
|
58
|
-
this.inString = false;
|
|
59
|
-
this.escape = false;
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
if (this.held === "") return ch;
|
|
63
|
-
const out = this.held;
|
|
64
|
-
this.held = "";
|
|
65
|
-
return out + this.pushChar(ch);
|
|
66
|
-
}
|
|
67
|
-
case "head": {
|
|
68
|
-
this.held += ch;
|
|
69
|
-
const closed = this.track(ch);
|
|
70
|
-
const signal = jsonKindSignal(this.held);
|
|
71
|
-
if (signal === "kind") {
|
|
72
|
-
const out = this.held;
|
|
73
|
-
this.held = "";
|
|
74
|
-
if (closed) {
|
|
75
|
-
this.mode = "tail";
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
this.mode = "body";
|
|
79
|
-
return out;
|
|
80
|
-
}
|
|
81
|
-
if (signal === "not_kind" || closed || this.held.length > HEAD_LIMIT) {
|
|
82
|
-
const out = `![${this.held}`;
|
|
83
|
-
this.held = "";
|
|
84
|
-
this.mode = "scan";
|
|
85
|
-
return out;
|
|
86
|
-
}
|
|
87
|
-
return "";
|
|
88
|
-
}
|
|
89
|
-
case "body": {
|
|
90
|
-
if (this.track(ch)) this.mode = "tail";
|
|
91
|
-
return ch;
|
|
92
|
-
}
|
|
93
|
-
case "tail": {
|
|
94
|
-
this.held += ch;
|
|
95
|
-
if (/^\]\([^)\n]*\)$/.test(this.held)) {
|
|
96
|
-
this.held = "";
|
|
97
|
-
this.mode = "scan";
|
|
98
|
-
return "";
|
|
99
|
-
}
|
|
100
|
-
if (/^\](?:\([^)\n]*)?$/.test(this.held)) return "";
|
|
101
|
-
const out = this.held;
|
|
102
|
-
this.held = "";
|
|
103
|
-
this.mode = "scan";
|
|
104
|
-
return out;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function unwrapKindImageAlt(source) {
|
|
110
|
-
if (!source.includes("![{")) return source;
|
|
111
|
-
const transform = new KindImageAltUnwrap();
|
|
112
|
-
return transform.push(source) + transform.flush();
|
|
113
|
-
}
|
|
114
|
-
export {
|
|
115
|
-
KindImageAltUnwrap,
|
|
116
|
-
unwrapKindImageAlt
|
|
117
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE ONE-LINE FORM of a kind — what an INLINE surface shows where a kind
|
|
3
|
-
* region sits in its text (P6, round 4): a collapsed card preview, a
|
|
4
|
-
* notification body, an extraction cell, a table cell. An inline/preview level
|
|
5
|
-
* cannot mount a kind component, so a kind reads as its instance title and
|
|
6
|
-
* kind name (`**Cells** · Flashcard Set`), an unfinished one as its kind name
|
|
7
|
-
* alone, and an unreadable one as "Structured output". Never the JSON.
|
|
8
|
-
*
|
|
9
|
-
* LIGHT on purpose — the inline level must not pull the kind registry or the
|
|
10
|
-
* block pipeline: the region finder (`embedded-kind-json.ts`), the detector
|
|
11
|
-
* and the title derivation (`studio/instance-title.ts`) only.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* One line for a kind VALUE: `**Title** · Kind Name`, or the kind name alone.
|
|
15
|
-
* `plain` drops the markdown emphasis (`Title · Kind Name`) for slots that
|
|
16
|
-
* draw text as written — a tooltip, a `title` attribute, a clamped caption.
|
|
17
|
-
*/
|
|
18
|
-
export declare function kindOneLine(value: unknown, options?: {
|
|
19
|
-
plain?: boolean;
|
|
20
|
-
}): string;
|
|
21
|
-
/**
|
|
22
|
-
* The text with every kind region (complete, unfinished or unreadable) in
|
|
23
|
-
* prose replaced by its one-line form. Quoted source (inline code, non-JSON
|
|
24
|
-
* fences) stays as written. Text with no kind key comes back unchanged.
|
|
25
|
-
*/
|
|
26
|
-
export declare function inlineKindText(raw: string, options?: {
|
|
27
|
-
plain?: boolean;
|
|
28
|
-
}): string;
|
|
29
|
-
/**
|
|
30
|
-
* A complete JSON kind region whose `__kind` cannot name a kind (`{"__kind":
|
|
31
|
-
* ["x"], …}`, `{"__kind": 5}`) → the one-line unreadable note, the words the
|
|
32
|
-
* export writes (`UNREADABLE_KIND_NOTE`), instead of raw JSON (round 11, L2).
|
|
33
|
-
*/
|
|
34
|
-
export declare function unreadableKindsAsNote(text: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* CATALOG PROSE as a person reads it (ruling (a), round 6): a skill / agent /
|
|
37
|
-
* tool description that shows an example kind JSON (`emit a
|
|
38
|
-
* {"__kind": "math_problem"} block`) is documentation — the example reads as
|
|
39
|
-
* its kind's one-line label, never the JSON. Plain text out, for text AND
|
|
40
|
-
* attribute slots (`title`, tooltips). Display transform only: the stored
|
|
41
|
-
* description is never rewritten.
|
|
42
|
-
*/
|
|
43
|
-
export declare function catalogProseText(text: string | null | undefined): string;
|
|
44
|
-
/**
|
|
45
|
-
* THE PROSE LEAF's kind reading (round 10 boundary): a REAL JSON kind region
|
|
46
|
-
* the pipeline cannot lift — a settled object whose grammar BROKE in prose
|
|
47
|
-
* (`{"__kind":"note","title":"Hi" and then…`), or a markdown-escaped key
|
|
48
|
-
* (`"\_\_kind"`) — reads as its one-line label, then every character after
|
|
49
|
-
* its cut as written. A complete literal kind is the pipeline's (lifted).
|
|
50
|
-
* Every NON-JSON spelling (`{\"__kind\":…}` in prose, repr, a JS literal,
|
|
51
|
-
* typographic quotes, entities) is left EXACTLY as written — detection only.
|
|
52
|
-
* Called by the one prose leaf live and reloaded text both pass through, so
|
|
53
|
-
* live ≡ reload. One linear pass, memoized per text; text with no such region
|
|
54
|
-
* comes back as the same string.
|
|
55
|
-
*/
|
|
56
|
-
export declare function spelledKindsAsOneLine(text: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Round 10, detection-only spellings drawn EXACTLY as written: a non-JSON
|
|
59
|
-
* kind spelling in prose (`{\"__kind\":…}`, repr, a JS literal, typographic
|
|
60
|
-
* quotes, entities) becomes an inline code span, so markdown neither eats its
|
|
61
|
-
* backslashes nor decodes its entities — the screen shows the source byte for
|
|
62
|
-
* byte, as quoted source. Nothing outside a region changes; text with no such
|
|
63
|
-
* region comes back as the same string. One linear pass, memoized per text.
|
|
64
|
-
* (A markdown-escaping pass did the same job and hung the renderer on nested
|
|
65
|
-
* escapes — never reintroduce it.)
|
|
66
|
-
*/
|
|
67
|
-
export declare function nonJsonKindsAsCode(text: string): string;
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { humanizeIdentifier } from "@ai-matrx/kit/text-case";
|
|
2
|
-
import { deriveInstanceTitle } from "../instance-title.js";
|
|
3
|
-
import { UNREADABLE_KIND_NOTE } from "./kind-text-to-markdown.js";
|
|
4
|
-
import {
|
|
5
|
-
findBrokenKindJsonRegions,
|
|
6
|
-
findEmbeddedKindJsonRegions
|
|
7
|
-
} from "./embedded-kind-json.js";
|
|
8
|
-
import {
|
|
9
|
-
closedJson,
|
|
10
|
-
firstKindSlug,
|
|
11
|
-
hasKindKey,
|
|
12
|
-
kindGrammar,
|
|
13
|
-
mayHoldKindKey,
|
|
14
|
-
hasJsonKindKey,
|
|
15
|
-
normalizeKindSpellings,
|
|
16
|
-
quotedSourceRanges,
|
|
17
|
-
regionJson,
|
|
18
|
-
scanKindSpellingRegions
|
|
19
|
-
} from "./json-kind-signal.js";
|
|
20
|
-
const UNNAMED = "Structured output";
|
|
21
|
-
function kindName(slug) {
|
|
22
|
-
return slug && humanizeIdentifier(slug) || UNNAMED;
|
|
23
|
-
}
|
|
24
|
-
function kindOneLine(value, options = {}) {
|
|
25
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return UNNAMED;
|
|
26
|
-
const record = value;
|
|
27
|
-
const slug = typeof record.__kind === "string" ? record.__kind : null;
|
|
28
|
-
const title = deriveInstanceTitle(record);
|
|
29
|
-
const name = kindName(slug);
|
|
30
|
-
if (!(title && title !== name)) return name;
|
|
31
|
-
const clean = title.replace(/[*_`[\]]/g, "");
|
|
32
|
-
return options.plain ? `${clean} \xB7 ${name}` : `**${clean}** \xB7 ${name}`;
|
|
33
|
-
}
|
|
34
|
-
function inside(ranges, at) {
|
|
35
|
-
return ranges.some(([start, end]) => at >= start && at < end);
|
|
36
|
-
}
|
|
37
|
-
function inlineKindText(raw, options = {}) {
|
|
38
|
-
const source = raw ? normalizeKindSpellings(raw) : raw;
|
|
39
|
-
if (!source || !hasKindKey(source)) return source;
|
|
40
|
-
const spans = [];
|
|
41
|
-
for (const region of findEmbeddedKindJsonRegions(source, { excludeQuotedSource: true })) {
|
|
42
|
-
let value = null;
|
|
43
|
-
try {
|
|
44
|
-
value = JSON.parse(region.content);
|
|
45
|
-
} catch {
|
|
46
|
-
value = { __kind: region.kind };
|
|
47
|
-
}
|
|
48
|
-
spans.push({ start: region.start, end: region.end, line: kindOneLine(value, options) });
|
|
49
|
-
}
|
|
50
|
-
const quoted = quotedSourceRanges(source);
|
|
51
|
-
for (const region of findBrokenKindJsonRegions(source)) {
|
|
52
|
-
if (inside(quoted, region.start)) continue;
|
|
53
|
-
spans.push({ start: region.start, end: region.end, line: kindName(firstKindSlug(region.content)) });
|
|
54
|
-
}
|
|
55
|
-
spans.sort((a, b) => a.start - b.start);
|
|
56
|
-
let out = "";
|
|
57
|
-
let cursor = 0;
|
|
58
|
-
for (const span of spans) {
|
|
59
|
-
if (span.start < cursor) continue;
|
|
60
|
-
out += source.slice(cursor, span.start) + span.line;
|
|
61
|
-
cursor = span.end;
|
|
62
|
-
}
|
|
63
|
-
out += source.slice(cursor);
|
|
64
|
-
if (hasKindKey(out)) {
|
|
65
|
-
const key = out.search(/(?<!\\)"(?:__kind|\\u005[fF]_kind)"\s*:/);
|
|
66
|
-
const brace = key >= 0 ? out.lastIndexOf("{", key) : -1;
|
|
67
|
-
if (brace >= 0 && !inside(quotedSourceRanges(out), brace)) {
|
|
68
|
-
const verdict = kindGrammar(out, "json", brace);
|
|
69
|
-
const end = verdict.status === "prefix" ? out.length : verdict.status === "broken" && verdict.at > key ? verdict.cut : -1;
|
|
70
|
-
if (end > key) out = out.slice(0, brace) + kindName(firstKindSlug(out.slice(key, end))) + out.slice(end);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return unreadableKindsAsNote(out);
|
|
74
|
-
}
|
|
75
|
-
function holdsUnreadableKind(json) {
|
|
76
|
-
let value;
|
|
77
|
-
try {
|
|
78
|
-
value = JSON.parse(json);
|
|
79
|
-
} catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
83
|
-
if (!Object.prototype.hasOwnProperty.call(value, "__kind")) return false;
|
|
84
|
-
const kind = value.__kind;
|
|
85
|
-
if (typeof kind === "string") return false;
|
|
86
|
-
return !(typeof kind === "object" && kind !== null && !Array.isArray(kind));
|
|
87
|
-
}
|
|
88
|
-
function unreadableKindsAsNote(text) {
|
|
89
|
-
if (!text || !mayHoldKindKey(text) || !hasJsonKindKey(text)) return text;
|
|
90
|
-
let out = "";
|
|
91
|
-
let cursor = 0;
|
|
92
|
-
for (const region of scanKindSpellingRegions(text)) {
|
|
93
|
-
if (region.status !== "complete") continue;
|
|
94
|
-
const json = regionJson(region);
|
|
95
|
-
if (json === null || !holdsUnreadableKind(json)) continue;
|
|
96
|
-
out += text.slice(cursor, region.start) + UNREADABLE_KIND_NOTE;
|
|
97
|
-
cursor = region.end;
|
|
98
|
-
}
|
|
99
|
-
return cursor === 0 ? text : out + text.slice(cursor);
|
|
100
|
-
}
|
|
101
|
-
function catalogProseText(text) {
|
|
102
|
-
if (!text) return "";
|
|
103
|
-
return inlineKindText(text, { plain: true });
|
|
104
|
-
}
|
|
105
|
-
function regionOneLine(region) {
|
|
106
|
-
const json = region.status === "complete" ? regionJson(region) : region.status === "broken" ? closedJson(region) : null;
|
|
107
|
-
if (json !== null) {
|
|
108
|
-
try {
|
|
109
|
-
const value = JSON.parse(json);
|
|
110
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) return kindOneLine(value);
|
|
111
|
-
} catch {
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return kindName(firstKindSlug(json ?? region.decoded));
|
|
115
|
-
}
|
|
116
|
-
const ONE_LINE_CACHE = /* @__PURE__ */ new Map();
|
|
117
|
-
const ONE_LINE_CACHE_SIZE = 16;
|
|
118
|
-
function spelledKindsAsOneLine(text) {
|
|
119
|
-
if (!text || !mayHoldKindKey(text)) return text;
|
|
120
|
-
const cached = ONE_LINE_CACHE.get(text);
|
|
121
|
-
if (cached !== void 0) return cached;
|
|
122
|
-
const out = computeSpelledKindsAsOneLine(text);
|
|
123
|
-
if (ONE_LINE_CACHE.size >= ONE_LINE_CACHE_SIZE) ONE_LINE_CACHE.delete(ONE_LINE_CACHE.keys().next().value);
|
|
124
|
-
ONE_LINE_CACHE.set(text, out);
|
|
125
|
-
return out;
|
|
126
|
-
}
|
|
127
|
-
function computeSpelledKindsAsOneLine(text) {
|
|
128
|
-
let out = "";
|
|
129
|
-
let cursor = 0;
|
|
130
|
-
for (const region of scanKindSpellingRegions(text)) {
|
|
131
|
-
if (region.family === "lifted" && !region.markdown && region.status !== "broken") {
|
|
132
|
-
const json = region.status === "complete" ? regionJson(region) : null;
|
|
133
|
-
if (json === null || !holdsUnreadableKind(json)) continue;
|
|
134
|
-
out += text.slice(cursor, region.start) + UNREADABLE_KIND_NOTE;
|
|
135
|
-
cursor = region.end;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
out += text.slice(cursor, region.start) + regionOneLine(region);
|
|
139
|
-
cursor = region.end;
|
|
140
|
-
}
|
|
141
|
-
return cursor === 0 ? text : out + text.slice(cursor);
|
|
142
|
-
}
|
|
143
|
-
const AS_CODE_CACHE = /* @__PURE__ */ new Map();
|
|
144
|
-
function nonJsonKindsAsCode(text) {
|
|
145
|
-
if (!text || !mayHoldKindKey(text)) return text;
|
|
146
|
-
const cached = AS_CODE_CACHE.get(text);
|
|
147
|
-
if (cached !== void 0) return cached;
|
|
148
|
-
let out = "";
|
|
149
|
-
let cursor = 0;
|
|
150
|
-
let paragraphs = null;
|
|
151
|
-
let p = 0;
|
|
152
|
-
for (const region of scanKindSpellingRegions(text, { families: "all" })) {
|
|
153
|
-
if (region.family === "lifted" || region.family === "markdown") continue;
|
|
154
|
-
paragraphs ??= codeSpanParagraphs(text);
|
|
155
|
-
while (p < paragraphs.length - 1 && paragraphs[p].end <= region.start) p++;
|
|
156
|
-
const fence = safeCodeSpanFence(text, region.start, region.end, paragraphs[p]);
|
|
157
|
-
if (fence === null) continue;
|
|
158
|
-
out += text.slice(cursor, region.start) + fence + text.slice(region.start, region.end) + fence;
|
|
159
|
-
cursor = region.end;
|
|
160
|
-
}
|
|
161
|
-
const result = cursor === 0 ? text : out + text.slice(cursor);
|
|
162
|
-
if (AS_CODE_CACHE.size >= ONE_LINE_CACHE_SIZE) AS_CODE_CACHE.delete(AS_CODE_CACHE.keys().next().value);
|
|
163
|
-
AS_CODE_CACHE.set(text, result);
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
const HTML_TAG = /^ {0,3}<\/?[A-Za-z][A-Za-z0-9-]*(?:[\s/>]|$)/m;
|
|
167
|
-
const TABLE_ROW = /^[ \t]*\|/m;
|
|
168
|
-
function codeSpanParagraphs(text) {
|
|
169
|
-
const out = [];
|
|
170
|
-
const blank = /\n[ \t]*\n/g;
|
|
171
|
-
let start = 0;
|
|
172
|
-
for (; ; ) {
|
|
173
|
-
const m = blank.exec(text);
|
|
174
|
-
const end = m ? m.index + 1 : text.length;
|
|
175
|
-
const body = text.slice(start, end);
|
|
176
|
-
const runs = /* @__PURE__ */ new Set();
|
|
177
|
-
for (let i = 0; i < body.length; ) {
|
|
178
|
-
if (body[i] !== "`") {
|
|
179
|
-
i++;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
let n = 0;
|
|
183
|
-
while (body[i + n] === "`") n++;
|
|
184
|
-
runs.add(n);
|
|
185
|
-
i += n;
|
|
186
|
-
}
|
|
187
|
-
out.push({ start, end, html: HTML_TAG.test(body), table: TABLE_ROW.test(body), runs });
|
|
188
|
-
if (!m) break;
|
|
189
|
-
start = m.index + m[0].length - 1;
|
|
190
|
-
}
|
|
191
|
-
return out;
|
|
192
|
-
}
|
|
193
|
-
function safeCodeSpanFence(text, start, end, paragraph) {
|
|
194
|
-
const source = text.slice(start, end);
|
|
195
|
-
if (/\n[ \t]*\n/.test(source) || source.includes("`")) return null;
|
|
196
|
-
if (paragraph.html || paragraph.table && source.includes("|")) return null;
|
|
197
|
-
if (text[start - 1] === "`" || text[end] === "`") return null;
|
|
198
|
-
let ticks = 1;
|
|
199
|
-
while (paragraph.runs.has(ticks)) ticks++;
|
|
200
|
-
return "`".repeat(ticks);
|
|
201
|
-
}
|
|
202
|
-
export {
|
|
203
|
-
catalogProseText,
|
|
204
|
-
inlineKindText,
|
|
205
|
-
kindOneLine,
|
|
206
|
-
nonJsonKindsAsCode,
|
|
207
|
-
spelledKindsAsOneLine,
|
|
208
|
-
unreadableKindsAsNote
|
|
209
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Answer TEXT → ONE readable line, for a person's compact label (a card
|
|
3
|
-
* subtitle, a rule name, a link-preview description, a list row). A kind is
|
|
4
|
-
* never shown as raw JSON (Arman, 2026-09-30): a kind answer reads as
|
|
5
|
-
* "<Kind> · <instance title>" (`deriveInstanceTitle`, the derivation saved
|
|
6
|
-
* instances use); prose with a kind in it reads as the prose's first line;
|
|
7
|
-
* a kind that never completed reads as its one-line broken note.
|
|
8
|
-
* Kindless text is whitespace-collapsed and clipped, nothing else.
|
|
9
|
-
*
|
|
10
|
-
* Destination transform only — never call it on stored or machine-bound text.
|
|
11
|
-
*/
|
|
12
|
-
/** One line, at most `max` characters, never containing a `__kind` key. */
|
|
13
|
-
export declare function kindTextLabel(raw: string | null | undefined, max?: number): string;
|
|
14
|
-
/**
|
|
15
|
-
* A conversation TITLE as a person reads it (R4, round 6): a title that holds
|
|
16
|
-
* kind JSON reads as its one-line kind label; any other title — and null —
|
|
17
|
-
* comes back as it is. Read boundaries and title renderers call this; the
|
|
18
|
-
* stored title is never rewritten.
|
|
19
|
-
*/
|
|
20
|
-
export declare function conversationTitleText(title: string | null | undefined): string | null;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { humanizeKind } from "../kinds/kind-markdown-utils.js";
|
|
2
|
-
import { deriveInstanceTitle } from "../instance-title.js";
|
|
3
|
-
import { firstKindSlug, hasJsonKindKey, hasKindKey, normalizeKindSpellings } from "./json-kind-signal.js";
|
|
4
|
-
import { kindTextToMarkdown } from "./kind-text-to-markdown.js";
|
|
5
|
-
function clip(text, max) {
|
|
6
|
-
return text.length > max ? `${text.slice(0, Math.max(0, max - 1)).trimEnd()}\u2026` : text;
|
|
7
|
-
}
|
|
8
|
-
function wholeKindLabel(text) {
|
|
9
|
-
let body = text.trim();
|
|
10
|
-
const fence = body.match(/^(?:`{3,}|~{3,})[a-zA-Z0-9]*\s*\n([\s\S]*?)\n?(?:`{3,}|~{3,})$/);
|
|
11
|
-
if (fence) body = fence[1].trim();
|
|
12
|
-
if (!body.startsWith("{")) return null;
|
|
13
|
-
try {
|
|
14
|
-
const parsed = JSON.parse(body);
|
|
15
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
16
|
-
const record = parsed;
|
|
17
|
-
if (typeof record.__kind !== "string" || !record.__kind.trim()) return null;
|
|
18
|
-
const name = humanizeKind(record.__kind.trim());
|
|
19
|
-
const title = deriveInstanceTitle(record);
|
|
20
|
-
return title ? `${name} \xB7 ${title}` : name;
|
|
21
|
-
} catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function firstReadableLine(markdown) {
|
|
26
|
-
for (const raw of markdown.split("\n")) {
|
|
27
|
-
const line = raw.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/<\/?[A-Za-z][\w:-]*(\s[^<>]*)?\/?>/g, "").replace(/[*_`]+/g, "").replace(/\s+/g, " ").trim();
|
|
28
|
-
if (line) return line;
|
|
29
|
-
}
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
function kindTextLabel(raw, max = 90) {
|
|
33
|
-
if (!raw) return "";
|
|
34
|
-
const text = normalizeKindSpellings(raw);
|
|
35
|
-
if (!hasKindKey(text)) return clip(text.replace(/\s+/g, " ").trim(), max);
|
|
36
|
-
const whole = wholeKindLabel(text);
|
|
37
|
-
if (whole) return clip(whole, max);
|
|
38
|
-
const line = firstReadableLine(kindTextToMarkdown(text));
|
|
39
|
-
if (line) return clip(line, max);
|
|
40
|
-
const slug = firstKindSlug(text);
|
|
41
|
-
return clip(slug ? humanizeKind(slug) : "Structured output", max);
|
|
42
|
-
}
|
|
43
|
-
function conversationTitleText(title) {
|
|
44
|
-
if (title == null) return null;
|
|
45
|
-
return hasJsonKindKey(title) ? kindTextLabel(title, 200) : title;
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
conversationTitleText,
|
|
49
|
-
kindTextLabel
|
|
50
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Answer TEXT → the readable markdown a person meant, for DISPLAY and EXPORT
|
|
3
|
-
* destinations only (a note, a task, a file, a print, a clipboard copy, the
|
|
4
|
-
* speaker, a plain-text slot). Rule (Arman, 2026-09-30): a kind is never shown
|
|
5
|
-
* as raw JSON — every `{"__kind":…}` region in the text (bare, or the whole
|
|
6
|
-
* body of a ```json / unlabelled fence) becomes that kind's markdown through
|
|
7
|
-
* the ONE kind → markdown converter (`kindValueToMarkdown`: the registry's
|
|
8
|
-
* `toMarkdown` facet, else `genericKindMarkdown`).
|
|
9
|
-
*
|
|
10
|
-
* 🚨 Never call this on data that is STORED or PASSED to a machine: `__kind`
|
|
11
|
-
* is part of the data. This is a destination transform, the same as
|
|
12
|
-
* `unwrapKindEnvelopes`. Kindless text returns byte for byte.
|
|
13
|
-
*
|
|
14
|
-
* Regions come from the one embedded-kind region finder
|
|
15
|
-
* (`findEmbeddedKindJsonRegions`); the signal is the one detector
|
|
16
|
-
* (`hasKindKey`). Nobody writes a second one.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* The one-line broken state of a kind that never completed (≤60 chars) — the
|
|
20
|
-
* SAME words the compact preview shows (`AnswerTextPreview`), so an export of
|
|
21
|
-
* a cut-off answer says what the screen said.
|
|
22
|
-
*/
|
|
23
|
-
export declare function unfinishedKindLabel(kind: string | null): string;
|
|
24
|
-
/** The one-line note for structured output whose `__kind` cannot name a kind. */
|
|
25
|
-
export declare const UNREADABLE_KIND_NOTE = "Structured output could not be read";
|
|
26
|
-
/**
|
|
27
|
-
* The export transform. Kindless text returns byte for byte; every kind
|
|
28
|
-
* region becomes readable markdown, and a kind that can never complete (cut
|
|
29
|
-
* off, malformed) becomes its one-line "<Kind> did not finish" note — never
|
|
30
|
-
* the fragment.
|
|
31
|
-
*/
|
|
32
|
-
export declare function kindTextToMarkdown(raw: string | null | undefined): string;
|
|
33
|
-
export interface KindTextPreview {
|
|
34
|
-
/** The readable text: complete kinds as markdown, an arriving kind cut off. */
|
|
35
|
-
text: string;
|
|
36
|
-
/** The slug of a kind still arriving at the end of the text (its loader), else null. */
|
|
37
|
-
pendingKind: string | null;
|
|
38
|
-
/** True when a kind is arriving but its slug has not been read yet. */
|
|
39
|
-
pendingUnnamed: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A COMPACT, possibly still-streaming preview of answer text (a toast, a
|
|
43
|
-
* hover card, a list row): complete kinds read as their markdown; a kind
|
|
44
|
-
* still arriving is cut from the text and named in `pendingKind` so the
|
|
45
|
-
* caller shows that kind's loader — the raw JSON never shows mid-stream.
|
|
46
|
-
*/
|
|
47
|
-
export declare function kindTextPreview(raw: string | null | undefined): KindTextPreview;
|