langfx.js 0.1.0-alpha.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.
Files changed (104) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +107 -0
  4. package/dist/agentic.d.ts +128 -0
  5. package/dist/agentic.js +265 -0
  6. package/dist/agentic.js.map +1 -0
  7. package/dist/cache.d.ts +32 -0
  8. package/dist/cache.js +135 -0
  9. package/dist/cache.js.map +1 -0
  10. package/dist/cancellation.d.ts +9 -0
  11. package/dist/cancellation.js +70 -0
  12. package/dist/cancellation.js.map +1 -0
  13. package/dist/errors.d.ts +40 -0
  14. package/dist/errors.js +44 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/index.d.ts +18 -0
  17. package/dist/index.js +15 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/json-stream.d.ts +73 -0
  20. package/dist/json-stream.js +222 -0
  21. package/dist/json-stream.js.map +1 -0
  22. package/dist/langfunc.d.ts +20 -0
  23. package/dist/langfunc.js +28 -0
  24. package/dist/langfunc.js.map +1 -0
  25. package/dist/language-model.d.ts +78 -0
  26. package/dist/language-model.js +218 -0
  27. package/dist/language-model.js.map +1 -0
  28. package/dist/llms/anthropic.d.ts +30 -0
  29. package/dist/llms/anthropic.js +365 -0
  30. package/dist/llms/anthropic.js.map +1 -0
  31. package/dist/llms/gemini.d.ts +34 -0
  32. package/dist/llms/gemini.js +380 -0
  33. package/dist/llms/gemini.js.map +1 -0
  34. package/dist/llms/images.d.ts +10 -0
  35. package/dist/llms/images.js +43 -0
  36. package/dist/llms/images.js.map +1 -0
  37. package/dist/llms/index.d.ts +7 -0
  38. package/dist/llms/index.js +4 -0
  39. package/dist/llms/index.js.map +1 -0
  40. package/dist/llms/openai.d.ts +30 -0
  41. package/dist/llms/openai.js +398 -0
  42. package/dist/llms/openai.js.map +1 -0
  43. package/dist/llms/transport.d.ts +4 -0
  44. package/dist/llms/transport.js +90 -0
  45. package/dist/llms/transport.js.map +1 -0
  46. package/dist/mapping.d.ts +71 -0
  47. package/dist/mapping.js +190 -0
  48. package/dist/mapping.js.map +1 -0
  49. package/dist/message.d.ts +56 -0
  50. package/dist/message.js +86 -0
  51. package/dist/message.js.map +1 -0
  52. package/dist/python-preview.d.ts +24 -0
  53. package/dist/python-preview.js +368 -0
  54. package/dist/python-preview.js.map +1 -0
  55. package/dist/python-stream.d.ts +15 -0
  56. package/dist/python-stream.js +29 -0
  57. package/dist/python-stream.js.map +1 -0
  58. package/dist/python.d.ts +85 -0
  59. package/dist/python.js +728 -0
  60. package/dist/python.js.map +1 -0
  61. package/dist/query.d.ts +31 -0
  62. package/dist/query.js +151 -0
  63. package/dist/query.js.map +1 -0
  64. package/dist/retry.d.ts +12 -0
  65. package/dist/retry.js +56 -0
  66. package/dist/retry.js.map +1 -0
  67. package/dist/schema/zod.d.ts +4 -0
  68. package/dist/schema/zod.js +7 -0
  69. package/dist/schema/zod.js.map +1 -0
  70. package/dist/schema.d.ts +10 -0
  71. package/dist/schema.js +7 -0
  72. package/dist/schema.js.map +1 -0
  73. package/dist/template.d.ts +14 -0
  74. package/dist/template.js +75 -0
  75. package/dist/template.js.map +1 -0
  76. package/dist/testing/index.d.ts +33 -0
  77. package/dist/testing/index.js +56 -0
  78. package/dist/testing/index.js.map +1 -0
  79. package/dist/tool-call.d.ts +27 -0
  80. package/dist/tool-call.js +16 -0
  81. package/dist/tool-call.js.map +1 -0
  82. package/dist/tools.d.ts +43 -0
  83. package/dist/tools.js +155 -0
  84. package/dist/tools.js.map +1 -0
  85. package/docs/ANTHROPIC.md +43 -0
  86. package/docs/API_DESIGN.md +200 -0
  87. package/docs/GEMINI.md +68 -0
  88. package/docs/IMPLEMENTATION_STATUS.md +77 -0
  89. package/docs/LIVE_TESTING.md +24 -0
  90. package/docs/MAPPING.md +54 -0
  91. package/docs/OPENAI.md +40 -0
  92. package/docs/PORTING_PLAN.md +135 -0
  93. package/docs/PROMPT_PARITY.md +379 -0
  94. package/docs/PYTHON_PROTOCOL.md +109 -0
  95. package/docs/PYTHON_PROTOCOL_PARITY.md +964 -0
  96. package/docs/PYTHON_SCHEMA_EVALUATION.md +93 -0
  97. package/docs/PYTHON_STREAMING_PARITY.md +59 -0
  98. package/docs/RELEASING.md +25 -0
  99. package/docs/RETRIES_AND_CACHE.md +56 -0
  100. package/docs/SESSION_EVENTS.md +40 -0
  101. package/docs/SOURCE_AUDIT.md +133 -0
  102. package/docs/STREAMING.md +76 -0
  103. package/docs/TOOL_STREAMING.md +31 -0
  104. package/package.json +95 -0
@@ -0,0 +1,190 @@
1
+ import * as python from './python.js';
2
+ import { OutputValidationError } from './errors.js';
3
+ import { LangFunc } from './langfunc.js';
4
+ import { AIMessage, ComplexMessage, Message, Modality, SystemMessage, UserMessage } from './message.js';
5
+ import { resolveSchema } from './schema.js';
6
+ import { Template, renderPrompt } from './template.js';
7
+ export class MappingError extends OutputValidationError {
8
+ lmResponse;
9
+ /** A failed eviction must not hide the original mapping failure. */
10
+ cacheInvalidationError;
11
+ constructor(lmResponse, cause) {
12
+ super('Model output did not satisfy the response mapping.', { cause });
13
+ this.lmResponse = lmResponse;
14
+ }
15
+ }
16
+ export class MappingExample {
17
+ input;
18
+ output;
19
+ schema;
20
+ context;
21
+ metadata;
22
+ hasOutput;
23
+ constructor(options) {
24
+ this.input = options.input;
25
+ this.output = options.output;
26
+ this.schema = options.schema;
27
+ this.context = options.context;
28
+ this.metadata = Object.freeze({ ...options.metadata });
29
+ this.hasOutput = Object.hasOwn(options, 'output');
30
+ }
31
+ }
32
+ /** Reusable JSON mapping pipeline. Local rendering/parsing hooks stay synchronous. */
33
+ export class Mapping extends LangFunc {
34
+ static templateStr = '{{instructions}}{{request}}';
35
+ preambleOverride;
36
+ input;
37
+ protocol;
38
+ schema;
39
+ examples;
40
+ systemMessage;
41
+ constructor(options) {
42
+ super(options.templateStr, options);
43
+ this.protocol = options.protocol ?? 'python';
44
+ if (!['json', 'python'].includes(this.protocol))
45
+ throw new TypeError('Unsupported mapping protocol.');
46
+ this.preambleOverride = options.preamble;
47
+ this.input = options.input;
48
+ this.schema = resolveSchema(options.schema);
49
+ if (this.protocol === 'python')
50
+ python.schemaText(this.schema);
51
+ this.examples = Object.freeze([...(options.examples ?? [])]);
52
+ this.systemMessage = options.systemMessage;
53
+ }
54
+ get mappingRequest() { return new MappingExample({ input: this.input, schema: this.schema }); }
55
+ get preamble() { return this.preambleOverride ?? new Template(''); }
56
+ get inputTitle() { return 'INPUT'; }
57
+ get outputTitle() { return 'OUTPUT'; }
58
+ get schemaTitle() { return 'SCHEMA'; }
59
+ renderWith(variables, stack) {
60
+ const vars = { ...this.variables, ...variables, inputTitle: this.inputTitle, outputTitle: this.outputTitle, schemaTitle: this.schemaTitle };
61
+ const instructionParts = [];
62
+ const preamble = this.preamble.render(vars);
63
+ if (preamble.text.trim())
64
+ instructionParts.push(preamble);
65
+ const examples = this.examples.flatMap(example => this.renderExample(example, vars));
66
+ const multimodal = examples.some(example => example.sections.some(section => section.parts.some(part => part instanceof Modality)));
67
+ // Providers require image data in user turns. Keep text-only prompt parity.
68
+ if (!multimodal)
69
+ instructionParts.push(...examples);
70
+ instructionParts.push(new UserMessage(`${this.schemaTitle}:\n${indent(this.protocol === 'python' ? python.schemaText(this.schema) : JSON.stringify(this.schema.jsonSchema))}`));
71
+ if (this.systemMessage !== undefined)
72
+ instructionParts.push(renderPrompt(this.systemMessage, vars));
73
+ const turns = [...renderPrompt(this.mappingRequest.input, vars).sections];
74
+ while (turns[0]?.role === 'system')
75
+ instructionParts.push(turns.shift());
76
+ const instructions = new SystemMessage(joinData(instructionParts));
77
+ const input = new UserMessage([`${this.inputTitle}:\n `, ...indentParts(turns), `\n\n${this.outputTitle}:`]);
78
+ const request = multimodal ? new ComplexMessage([...examples, input]) : input;
79
+ return super.renderWith({ ...vars, instructions, request }, stack);
80
+ }
81
+ renderExample(example, variables = {}) {
82
+ if (!example.hasOutput)
83
+ throw new TypeError('Few-shot examples require an output.');
84
+ const schema = resolveSchema(example.schema ?? this.schema);
85
+ const text = this.protocol === 'python' ? python.formatExample(schema, example.output) : JSON.stringify(example.output, (_key, value) => {
86
+ if (value === undefined || ['function', 'symbol', 'bigint'].includes(typeof value) || (typeof value === 'number' && !Number.isFinite(value)))
87
+ throw new TypeError('Example output must be JSON data.');
88
+ return value;
89
+ });
90
+ if (this.protocol === 'python')
91
+ python.parse(schema, text);
92
+ else
93
+ schema.parse(JSON.parse(text));
94
+ const input = typeof example.input === 'string' ? new UserMessage(example.input) : renderPrompt(example.input, variables);
95
+ return [new UserMessage([
96
+ `${this.schemaTitle}:\n${indent(this.protocol === 'python' ? python.schemaText(schema) : JSON.stringify(schema.jsonSchema))}\n\n`,
97
+ ...(example.context === undefined ? [] : [`CONTEXT:\n${indent(example.context)}\n\n`]),
98
+ `${this.inputTitle}:\n `, ...indentParts(input.sections),
99
+ `\n\n${this.outputTitle}:\n${indent(text)}`,
100
+ ])];
101
+ }
102
+ postprocessResponse(response) { return response; }
103
+ parseResult(response) { return this.protocol === 'python' ? python.parse(this.schema, response.text) : this.schema.parse(JSON.parse(response.text)); }
104
+ postprocessResult(result) { return result; }
105
+ transformOutput(response) {
106
+ try {
107
+ const processed = this.postprocessResponse(response);
108
+ const result = this.postprocessResult(this.parseResult(processed));
109
+ return new AIMessage(processed.parts, { result, source: response, metadata: { ...response.metadata, ...processed.metadata } });
110
+ }
111
+ catch (cause) {
112
+ throw new MappingError(response, cause);
113
+ }
114
+ }
115
+ async call(options = {}) {
116
+ const { lm = this.lm, vars, ...sampling } = options;
117
+ if (!lm)
118
+ throw new TypeError('Mapping.call requires a LanguageModel.');
119
+ const response = await lm.call(this.transformInput(this.render(vars)), sampling);
120
+ try {
121
+ return this.transformOutput(response);
122
+ }
123
+ catch (cause) {
124
+ return failMapping(lm, response, cause);
125
+ }
126
+ }
127
+ }
128
+ /** Query specialization for JSON and restricted Python constructor protocols. */
129
+ export class LfQuery extends Mapping {
130
+ get inputTitle() { return this.protocol === 'python' ? 'REQUEST' : 'INPUT_OBJECT'; }
131
+ get outputTitle() { return this.protocol === 'python' ? 'OUTPUT PYTHON OBJECT' : 'JSON'; }
132
+ get schemaTitle() { return this.protocol === 'python' ? 'OUTPUT PYTHON TYPE' : 'SCHEMA'; }
133
+ get preamble() {
134
+ if (this.protocol === 'python')
135
+ return this.preambleOverride ?? new Template(`Please respond to the last {{inputTitle}} with {{outputTitle}} only according to {{schemaTitle}}.
136
+
137
+ {{schemaTitle}}:
138
+ Answer
139
+
140
+ \`\`\`python
141
+ class Answer:
142
+ final_answer: int
143
+ \`\`\`
144
+
145
+ {{inputTitle}}:
146
+ 1 + 1 =
147
+
148
+ {{outputTitle}}:
149
+ \`\`\`python
150
+ output = Answer(
151
+ final_answer=2
152
+ )
153
+ \`\`\``);
154
+ return this.preambleOverride ?? new Template(`Please respond to the last {{inputTitle}} with {{outputTitle}} according to {{schemaTitle}}:
155
+
156
+ INSTRUCTIONS:
157
+ 1. Return only JSON matching the JSON Schema, without Markdown fences or a result wrapper.
158
+ 2. Use null only when the schema permits it; do not invent missing facts.
159
+
160
+ {{schemaTitle}}:
161
+ {{exampleSchema}}
162
+
163
+ {{inputTitle}}:
164
+ 1 + 1 =
165
+
166
+ {{outputTitle}}:
167
+ {{exampleOutput}}`, {
168
+ exampleSchema: JSON.stringify({ type: 'object', properties: { final_answer: { type: 'integer' } }, required: ['final_answer'] }),
169
+ exampleOutput: JSON.stringify({ final_answer: 2 }),
170
+ });
171
+ }
172
+ }
173
+ function indent(text) { return text.split('\n').map(line => line ? ` ${line}` : '').join('\n'); }
174
+ function indentParts(messages) {
175
+ return messages.flatMap(message => message.sections.flatMap(section => section.parts.map(part => typeof part === 'string' ? part.replace(/\n/g, '\n ') : part)));
176
+ }
177
+ function joinData(messages) {
178
+ return messages.flatMap((message, index) => [...(index ? ['\n\n'] : []), ...message.sections.flatMap(section => [...section.parts])]);
179
+ }
180
+ export async function failMapping(lm, response, cause) {
181
+ const error = cause instanceof MappingError ? cause : new MappingError(response, cause);
182
+ try {
183
+ await lm.invalidateCache(response);
184
+ }
185
+ catch (cleanupError) {
186
+ error.cacheInvalidationError = cleanupError;
187
+ }
188
+ throw error;
189
+ }
190
+ //# sourceMappingURL=mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.js","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGvD,MAAM,OAAO,YAAa,SAAQ,qBAAqB;IAGhC,UAAU;IAF/B,oEAAoE;IACpE,sBAAsB,CAAW;IACjC,YAAqB,UAAmB,EAAE,KAAc;QACtD,KAAK,CAAC,oDAAoD,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;0BADpD,UAAU;IAE/B,CAAC;CACF;AASD,MAAM,OAAO,cAAc;IAChB,KAAK,CAAS;IACd,MAAM,CAAU;IAChB,MAAM,CAAkC;IACxC,OAAO,CAAqB;IAC5B,QAAQ,CAAoC;IAC5C,SAAS,CAAU;IAC5B,YAAY,OAA8B;QACxC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACvF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAAC,IAAI,CAAC,QAAQ,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;AACpK,CAAC;AACD,SAAS,QAAQ,CAAC,QAA4B;IAC5C,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxI,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAiB,EAAE,QAAiB,EAAE,KAAc;IACpF,MAAM,KAAK,GAAG,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxF,IAAI,CAAC;QAAC,MAAM,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAAC,CAAC;IAC3C,OAAO,YAAY,EAAE,CAAC;QAAC,KAAK,CAAC,sBAAsB,GAAG,YAAY,CAAC;IAAC,CAAC;IACrE,MAAM,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { ToolCall } from './tool-call.js';
2
+ export type Role = 'user' | 'assistant' | 'system' | 'tool';
3
+ export type MediaSource = {
4
+ readonly kind: 'uri';
5
+ readonly uri: string;
6
+ } | {
7
+ readonly kind: 'bytes';
8
+ readonly bytes: Uint8Array;
9
+ } | {
10
+ readonly kind: 'blob';
11
+ readonly blob: Blob;
12
+ };
13
+ export declare class Modality {
14
+ readonly mimeType: string;
15
+ readonly source: MediaSource;
16
+ constructor(mimeType: string, source: MediaSource);
17
+ }
18
+ export declare class Image extends Modality {
19
+ static fromUri(uri: string, mimeType?: string): Image;
20
+ static fromBytes(bytes: Uint8Array, mimeType: string): Image;
21
+ static fromFile(file: Blob): Image;
22
+ }
23
+ export type MessagePart = string | Modality | Message;
24
+ export interface MessageOptions<T = unknown> {
25
+ readonly result?: T;
26
+ readonly metadata?: Readonly<Record<string, unknown>>;
27
+ readonly source?: Message;
28
+ }
29
+ export declare class Message<T = unknown> {
30
+ readonly role: Role;
31
+ readonly parts: readonly MessagePart[];
32
+ readonly result: T;
33
+ readonly metadata: Readonly<Record<string, unknown>>;
34
+ readonly source: Message | undefined;
35
+ constructor(content: string | readonly MessagePart[], role?: Role, options?: MessageOptions<T>);
36
+ get toolCalls(): readonly ToolCall[];
37
+ get text(): string;
38
+ /** Flatten embedded role-scoped turns without changing their order. */
39
+ get sections(): readonly Message[];
40
+ }
41
+ export declare class UserMessage<T = unknown> extends Message<T> {
42
+ constructor(content: string | readonly MessagePart[], options?: MessageOptions<T>);
43
+ }
44
+ export declare class AIMessage<T = unknown> extends Message<T> {
45
+ constructor(content: string | readonly MessagePart[], options?: MessageOptions<T>);
46
+ }
47
+ export declare class SystemMessage extends Message {
48
+ constructor(content: string | readonly MessagePart[], options?: MessageOptions);
49
+ }
50
+ export declare class ToolMessage extends Message {
51
+ readonly toolCallId: string;
52
+ constructor(content: string | readonly MessagePart[], toolCallId: string, options?: MessageOptions);
53
+ }
54
+ export declare class ComplexMessage extends Message {
55
+ constructor(messages: readonly Message[]);
56
+ }
@@ -0,0 +1,86 @@
1
+ export class Modality {
2
+ mimeType;
3
+ source;
4
+ constructor(mimeType, source) {
5
+ this.mimeType = mimeType;
6
+ if (!mimeType)
7
+ throw new TypeError('A MIME type is required.');
8
+ this.source = Object.freeze(source.kind === 'bytes'
9
+ ? { kind: 'bytes', bytes: source.bytes.slice() } : { ...source });
10
+ }
11
+ }
12
+ export class Image extends Modality {
13
+ static fromUri(uri, mimeType = 'image/*') {
14
+ return new Image(mimeType, { kind: 'uri', uri });
15
+ }
16
+ static fromBytes(bytes, mimeType) {
17
+ return new Image(mimeType, { kind: 'bytes', bytes });
18
+ }
19
+ static fromFile(file) {
20
+ if (!file.type.startsWith('image/'))
21
+ throw new TypeError('Expected an image MIME type.');
22
+ return new Image(file.type, { kind: 'blob', blob: file });
23
+ }
24
+ }
25
+ export class Message {
26
+ role;
27
+ parts;
28
+ result;
29
+ metadata;
30
+ source;
31
+ constructor(content, role = 'user', options = {}) {
32
+ this.role = role;
33
+ this.parts = Object.freeze(typeof content === 'string' ? [content] : [...content]);
34
+ this.result = options.result;
35
+ this.metadata = Object.freeze({ ...options.metadata });
36
+ this.source = options.source;
37
+ }
38
+ get toolCalls() {
39
+ return this.metadata['toolCalls'] ?? [];
40
+ }
41
+ get text() {
42
+ return this.parts.map(part => typeof part === 'string' ? part : part instanceof Message ? part.text : '').join('');
43
+ }
44
+ /** Flatten embedded role-scoped turns without changing their order. */
45
+ get sections() {
46
+ if (!this.parts.some(part => part instanceof Message))
47
+ return [this];
48
+ const sections = [];
49
+ let buffer = [];
50
+ const flush = () => {
51
+ if (buffer.length)
52
+ sections.push(new Message(buffer, this.role, { metadata: this.metadata }));
53
+ buffer = [];
54
+ };
55
+ for (const part of this.parts) {
56
+ if (part instanceof Message) {
57
+ flush();
58
+ sections.push(...part.sections);
59
+ }
60
+ else
61
+ buffer.push(part);
62
+ }
63
+ flush();
64
+ return sections;
65
+ }
66
+ }
67
+ export class UserMessage extends Message {
68
+ constructor(content, options = {}) { super(content, 'user', options); }
69
+ }
70
+ export class AIMessage extends Message {
71
+ constructor(content, options = {}) { super(content, 'assistant', options); }
72
+ }
73
+ export class SystemMessage extends Message {
74
+ constructor(content, options = {}) { super(content, 'system', options); }
75
+ }
76
+ export class ToolMessage extends Message {
77
+ toolCallId;
78
+ constructor(content, toolCallId, options = {}) {
79
+ super(content, 'tool', { ...options, metadata: { ...options.metadata, toolCallId } });
80
+ this.toolCallId = toolCallId;
81
+ }
82
+ }
83
+ export class ComplexMessage extends Message {
84
+ constructor(messages) { super(messages); }
85
+ }
86
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"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ADzB,UAAU;IAEzE,CAAC;CACF;AACD,MAAM,OAAO,cAAe,SAAQ,OAAO;IACzC,YAAY,QAA4B,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,24 @@
1
+ import type { JsonStreamEvent } from './json-stream.js';
2
+ /** Best-effort, factory-free previews. The complete Python parser remains authoritative. */
3
+ export declare class PythonPreview {
4
+ private readonly maxDepth;
5
+ private buffer;
6
+ private scan;
7
+ private literal;
8
+ private stopped;
9
+ private current;
10
+ private readonly reader;
11
+ constructor(maxDepth: number);
12
+ feed(text: string, final?: boolean): Generator<JsonStreamEvent>;
13
+ private token;
14
+ /** Consume each string code unit once; incomplete escapes remain buffered. */
15
+ private stringToken;
16
+ private advance;
17
+ private expect;
18
+ private root;
19
+ private value;
20
+ /** Delay ambiguous first-element events until a comma or colon resolves the syntax. */
21
+ private capture;
22
+ private sequence;
23
+ private object;
24
+ }