@theoremjs/web 0.3.4-next.596.g481e1de → 0.3.4-next.600.gb15be9a

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/client/index.d.ts CHANGED
@@ -25,7 +25,7 @@ export { type PageDispatchResult, withPageToolDispatch } from './page-dispatch.t
25
25
  export { sessionAfter, stampWorked } from './run-commit.ts';
26
26
  export { keepsConversation, type RunOutcome, resumeInterfaceTool, type StreamView, streamInterfaceDraftTurn, streamInterfaceTurn, } from './run-session.ts';
27
27
  export { blankRow, type JsonSchema, missingFields, type SchemaControl, type SchemaField, sampleFromSchema, schemaControl, schemaFields, withField, } from './schema-fields.ts';
28
- export { fieldLabel, fieldReading, humanize, isPlain, isProse, isRow, json, type ListRow, MAX_ROWS, type PlainReading, plainReading, type Row, rowHeading, type Section, type Shape, shapeOf, splitFields, unpacked, withUnit, } from './shaped-data.ts';
28
+ export { fieldLabel, fieldReading, humanize, isPart, isPlain, isProse, isRow, json, type ListRow, layoutChars, MAX_ROWS, type PlainReading, plainReading, type Row, rowHeading, type Section, type Shape, shapeOf, splitFields, unpacked, withUnit, } from './shaped-data.ts';
29
29
  export { citationsFromBlock, type SourceCitation, type SourceCitationBlock, } from './source-citations.ts';
30
30
  export type { QueryMatch } from './space-geometry.ts';
31
31
  export { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, type SpaceGeometry, spaceGeometry, } from './space-geometry.ts';
package/client/index.js CHANGED
@@ -21,7 +21,7 @@ export { withPageToolDispatch } from "./page-dispatch.js";
21
21
  export { sessionAfter, stampWorked } from "./run-commit.js";
22
22
  export { keepsConversation, resumeInterfaceTool, streamInterfaceDraftTurn, streamInterfaceTurn, } from "./run-session.js";
23
23
  export { blankRow, missingFields, sampleFromSchema, schemaControl, schemaFields, withField, } from "./schema-fields.js";
24
- export { fieldLabel, fieldReading, humanize, isPlain, isProse, isRow, json, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from "./shaped-data.js";
24
+ export { fieldLabel, fieldReading, humanize, isPart, isPlain, isProse, isRow, json, layoutChars, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from "./shaped-data.js";
25
25
  export { citationsFromBlock, } from "./source-citations.js";
26
26
  export { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, spaceGeometry, } from "./space-geometry.js";
27
27
  export { hasLead, layoutResult, returnedMedia, timeFormats, } from "./tool-result.js";
@@ -3,6 +3,7 @@
3
3
  * value takes, what a row is called, what a field's label and unit are. The
4
4
  * component only maps each decision to its Astryx part.
5
5
  */
6
+ import { type InteractionPart } from '@theoremjs/agents';
6
7
  export type Row = Record<string, unknown>;
7
8
  /** Rows shown before the rest are left to the JSON view. */
8
9
  export declare const MAX_ROWS = 50;
@@ -11,6 +12,13 @@ export declare function isRow(value: unknown): value is Row;
11
12
  export declare function isPlain(value: unknown): boolean;
12
13
  /** The value as indented JSON, whatever it holds. */
13
14
  export declare function json(value: unknown): string;
15
+ /** A part as the kernel declares one (`InteractionPart`): text, or media carried as base64 `data` or at a `uri`. */
16
+ export declare function isPart(value: unknown): value is InteractionPart;
17
+ /**
18
+ * How much text laying the value out draws: its JSON, without each part's
19
+ * base64 `data`, which is drawn as a picture or a player.
20
+ */
21
+ export declare function layoutChars(value: unknown): number;
14
22
  /** A string that holds a JSON object or list, parsed; anything else as it came. */
15
23
  export declare function unpacked(value: unknown): unknown;
16
24
  /** `country_code`, `countryCode` → "Country code". */
@@ -100,6 +108,9 @@ export type Shape = {
100
108
  } | {
101
109
  kind: 'fields';
102
110
  row: Row;
111
+ } | {
112
+ kind: 'parts';
113
+ parts: InteractionPart[];
103
114
  };
104
115
  /** How a value (already unpacked) at `depth` is drawn. */
105
116
  export declare function shapeOf(value: unknown, depth: number): Shape;
@@ -3,6 +3,7 @@
3
3
  * value takes, what a row is called, what a field's label and unit are. The
4
4
  * component only maps each decision to its Astryx part.
5
5
  */
6
+ import { MEDIA_INPUT_KIND_VALUES } from '@theoremjs/agents';
6
7
  /** Fields that name a row, in the order they're tried. */
7
8
  const TITLE_KEYS = ['name', 'title', 'label', 'headline', 'subject', 'id'];
8
9
  /** Fields that place or sort a row, shown as tokens beside its title. */
@@ -93,6 +94,30 @@ export function json(value) {
93
94
  return JSON.stringify(jsonSafe(value), null, 2) ?? String(value);
94
95
  }
95
96
  }
97
+ const MEDIA_KINDS = new Set(MEDIA_INPUT_KIND_VALUES);
98
+ /** A part as the kernel declares one (`InteractionPart`): text, or media carried as base64 `data` or at a `uri`. */
99
+ export function isPart(value) {
100
+ if (!isRow(value) || typeof value.type !== 'string')
101
+ return false;
102
+ if (value.type === 'text')
103
+ return typeof value.text === 'string';
104
+ return (MEDIA_KINDS.has(value.type) &&
105
+ typeof value.mimeType === 'string' &&
106
+ (typeof value.data === 'string' || typeof value.uri === 'string'));
107
+ }
108
+ /**
109
+ * How much text laying the value out draws: its JSON, without each part's
110
+ * base64 `data`, which is drawn as a picture or a player.
111
+ */
112
+ export function layoutChars(value) {
113
+ try {
114
+ const lean = JSON.stringify(value, (_key, item) => (isPart(item) && 'data' in item ? { ...item, data: '' } : item), 2);
115
+ return lean?.length ?? 0;
116
+ }
117
+ catch {
118
+ return json(value).length;
119
+ }
120
+ }
96
121
  /** A string that holds a JSON object or list, parsed; anything else as it came. */
97
122
  export function unpacked(value) {
98
123
  if (typeof value !== 'string')
@@ -278,6 +303,8 @@ function listShape(items) {
278
303
  return { kind: 'none' };
279
304
  if (items.every(isPlain))
280
305
  return { kind: 'tokens', items };
306
+ if (items.every(isPart))
307
+ return { kind: 'parts', parts: items };
281
308
  const listed = items.map(listRow);
282
309
  if (listed.every((row) => row !== undefined))
283
310
  return { kind: 'list', rows: listed };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.4-next.596.g481e1de",
3
+ "version": "0.3.4-next.600.gb15be9a",
4
4
  "description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^4.6.5",
28
- "@theoremjs/agents": "^0.3.4-next.596.g481e1de"
28
+ "@theoremjs/agents": "^0.3.4-next.600.gb15be9a"
29
29
  }
30
30
  }