extrait 0.7.1 → 0.7.3
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/README.md +2 -0
- package/dist/index.cjs +14 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -4
- package/dist/prompt.d.ts +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -658,6 +658,8 @@ type MCPCallToolParams = {
|
|
|
658
658
|
};
|
|
659
659
|
```
|
|
660
660
|
|
|
661
|
+
MCP toolsets may change between tool rounds. Providers call `listTools()` before each round, so a client can expose additional tools after a previous `callTool()` result, or remove tools that are no longer available.
|
|
662
|
+
|
|
661
663
|
Use `transformToolCallParams()` when you need to attach MCP-specific metadata, override the final remote tool name, or otherwise change the full request passed to `client.callTool()`. This hook is exported as `LLMToolCallParamsTransformer`.
|
|
662
664
|
|
|
663
665
|
### Timeouts
|
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ __export(exports_src, {
|
|
|
58
58
|
extractMarkdownCodeBlocks: () => extractMarkdownCodeBlocks,
|
|
59
59
|
extractJsonCandidates: () => extractJsonCandidates,
|
|
60
60
|
extractFirstMarkdownCode: () => extractFirstMarkdownCode,
|
|
61
|
+
dedent: () => dedent,
|
|
61
62
|
createProviderRegistry: () => createProviderRegistry,
|
|
62
63
|
createOpenAICompatibleAdapter: () => createOpenAICompatibleAdapter,
|
|
63
64
|
createModelAdapter: () => createModelAdapter,
|
|
@@ -1709,7 +1710,8 @@ function createOpenAICompatibleAdapter(options) {
|
|
|
1709
1710
|
async function streamWithChatCompletionsPassThrough(options, fetcher, path, request, callbacks) {
|
|
1710
1711
|
const response = await sendOpenAIRequest(options, fetcher, path, request, buildChatCompletionsBody(options, request, {
|
|
1711
1712
|
messages: buildMessages(request),
|
|
1712
|
-
stream: true
|
|
1713
|
+
stream: true,
|
|
1714
|
+
stream_options: streamUsageOptions(request)
|
|
1713
1715
|
}));
|
|
1714
1716
|
if (!response.ok) {
|
|
1715
1717
|
const message = await response.text();
|
|
@@ -1801,6 +1803,10 @@ async function completeOpenAIRequest(options, fetcher, chatPath, responsesPath,
|
|
|
1801
1803
|
function buildChatCompletionsBody(options, request, overrides) {
|
|
1802
1804
|
return buildOpenAIRequestBody(options, request, "max_tokens", overrides);
|
|
1803
1805
|
}
|
|
1806
|
+
function streamUsageOptions(request) {
|
|
1807
|
+
const userOptions = isRecord2(request.body?.stream_options) ? request.body.stream_options : undefined;
|
|
1808
|
+
return { include_usage: true, ...userOptions };
|
|
1809
|
+
}
|
|
1804
1810
|
function buildResponsesBody(options, request, overrides) {
|
|
1805
1811
|
return buildOpenAIRequestBody(options, request, "max_output_tokens", overrides);
|
|
1806
1812
|
}
|
|
@@ -2058,7 +2064,8 @@ async function streamWithChatCompletionsWithMCP(options, fetcher, path, request,
|
|
|
2058
2064
|
tools: transportTools,
|
|
2059
2065
|
tool_choice: request.toolChoice,
|
|
2060
2066
|
parallel_tool_calls: request.parallelToolCalls,
|
|
2061
|
-
stream: true
|
|
2067
|
+
stream: true,
|
|
2068
|
+
stream_options: streamUsageOptions(request)
|
|
2062
2069
|
}));
|
|
2063
2070
|
if (!response.ok) {
|
|
2064
2071
|
const message = await response.text();
|
|
@@ -5624,7 +5631,7 @@ function toPromptString(value) {
|
|
|
5624
5631
|
return String(value);
|
|
5625
5632
|
}
|
|
5626
5633
|
}
|
|
5627
|
-
var
|
|
5634
|
+
var outdent = createOutdent({
|
|
5628
5635
|
trimLeadingNewline: true,
|
|
5629
5636
|
trimTrailingNewline: true,
|
|
5630
5637
|
newline: `
|
|
@@ -5657,7 +5664,7 @@ function stripOuterBlankLines(text) {
|
|
|
5657
5664
|
`);
|
|
5658
5665
|
}
|
|
5659
5666
|
function renderPromptTemplate(strings, values) {
|
|
5660
|
-
return stripOuterBlankLines(
|
|
5667
|
+
return stripOuterBlankLines(outdent(strings, ...values.map(toPromptString)));
|
|
5661
5668
|
}
|
|
5662
5669
|
function isTemplateStringsArray(value) {
|
|
5663
5670
|
return Array.isArray(value) && "raw" in value;
|
|
@@ -5705,6 +5712,9 @@ class PromptMessageBuilderImpl {
|
|
|
5705
5712
|
function createPromptMessageBuilder() {
|
|
5706
5713
|
return new PromptMessageBuilderImpl;
|
|
5707
5714
|
}
|
|
5715
|
+
function dedent(strings, ...values) {
|
|
5716
|
+
return renderPromptTemplate(strings, values);
|
|
5717
|
+
}
|
|
5708
5718
|
function prompt(input, ...values) {
|
|
5709
5719
|
if (isTemplateStringsArray(input)) {
|
|
5710
5720
|
return renderPromptTemplate(input, values);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { formatZodIssues, parseLLMOutput } from "./parse";
|
|
|
8
8
|
export { createMCPClient, wrapMCPClient, type CreateMCPClientOptions, type MCPClientInfo, type MCPInMemoryTransportConfig, type MCPStdioTransportConfig, type MCPStreamableHTTPTransportConfig, type MCPTransportConfig, type ManagedMCPToolClient, } from "./mcp";
|
|
9
9
|
export { images, resizeImage, type ImageInput, type ImageSize } from "./image";
|
|
10
10
|
export { conversation, type ConversationEntry } from "./conversation";
|
|
11
|
-
export { prompt, type PromptMessageBuilder } from "./prompt";
|
|
11
|
+
export { dedent, prompt, type PromptMessageBuilder } from "./prompt";
|
|
12
12
|
export { s, inspectSchemaMetadata, inferSchemaExample } from "./schema-builder";
|
|
13
13
|
export { buildDefaultStructuredPrompt, DEFAULT_LOOSE_PARSE_OPTIONS, DEFAULT_SELF_HEAL_BY_MODE, DEFAULT_SELF_HEAL_CONTEXT_LABEL, DEFAULT_SELF_HEAL_FIX_INSTRUCTION, DEFAULT_SELF_HEAL_MAX_CONTEXT_CHARS, DEFAULT_SELF_HEAL_NO_ISSUES_MESSAGE, DEFAULT_SELF_HEAL_PROTOCOL, DEFAULT_SELF_HEAL_RAW_OUTPUT_LABEL, DEFAULT_SELF_HEAL_RETURN_INSTRUCTION, DEFAULT_SELF_HEAL_STOP_ON_NO_PROGRESS, DEFAULT_SELF_HEAL_VALIDATION_LABEL, DEFAULT_STRICT_PARSE_OPTIONS, DEFAULT_STRUCTURED_OBJECT_INSTRUCTION, DEFAULT_STRUCTURED_STYLE_INSTRUCTION, buildSelfHealPrompt, structured, StructuredParseError, type BuildDefaultStructuredPromptOptions, type SelfHealPromptTextOptions, } from "./structured";
|
|
14
14
|
export { createOpenAICompatibleAdapter, type OpenAICompatibleAdapterOptions, } from "./providers/openai-compatible";
|
package/dist/index.js
CHANGED
|
@@ -1619,7 +1619,8 @@ function createOpenAICompatibleAdapter(options) {
|
|
|
1619
1619
|
async function streamWithChatCompletionsPassThrough(options, fetcher, path, request, callbacks) {
|
|
1620
1620
|
const response = await sendOpenAIRequest(options, fetcher, path, request, buildChatCompletionsBody(options, request, {
|
|
1621
1621
|
messages: buildMessages(request),
|
|
1622
|
-
stream: true
|
|
1622
|
+
stream: true,
|
|
1623
|
+
stream_options: streamUsageOptions(request)
|
|
1623
1624
|
}));
|
|
1624
1625
|
if (!response.ok) {
|
|
1625
1626
|
const message = await response.text();
|
|
@@ -1711,6 +1712,10 @@ async function completeOpenAIRequest(options, fetcher, chatPath, responsesPath,
|
|
|
1711
1712
|
function buildChatCompletionsBody(options, request, overrides) {
|
|
1712
1713
|
return buildOpenAIRequestBody(options, request, "max_tokens", overrides);
|
|
1713
1714
|
}
|
|
1715
|
+
function streamUsageOptions(request) {
|
|
1716
|
+
const userOptions = isRecord2(request.body?.stream_options) ? request.body.stream_options : undefined;
|
|
1717
|
+
return { include_usage: true, ...userOptions };
|
|
1718
|
+
}
|
|
1714
1719
|
function buildResponsesBody(options, request, overrides) {
|
|
1715
1720
|
return buildOpenAIRequestBody(options, request, "max_output_tokens", overrides);
|
|
1716
1721
|
}
|
|
@@ -1968,7 +1973,8 @@ async function streamWithChatCompletionsWithMCP(options, fetcher, path, request,
|
|
|
1968
1973
|
tools: transportTools,
|
|
1969
1974
|
tool_choice: request.toolChoice,
|
|
1970
1975
|
parallel_tool_calls: request.parallelToolCalls,
|
|
1971
|
-
stream: true
|
|
1976
|
+
stream: true,
|
|
1977
|
+
stream_options: streamUsageOptions(request)
|
|
1972
1978
|
}));
|
|
1973
1979
|
if (!response.ok) {
|
|
1974
1980
|
const message = await response.text();
|
|
@@ -5538,7 +5544,7 @@ function toPromptString(value) {
|
|
|
5538
5544
|
return String(value);
|
|
5539
5545
|
}
|
|
5540
5546
|
}
|
|
5541
|
-
var
|
|
5547
|
+
var outdent = createOutdent({
|
|
5542
5548
|
trimLeadingNewline: true,
|
|
5543
5549
|
trimTrailingNewline: true,
|
|
5544
5550
|
newline: `
|
|
@@ -5571,7 +5577,7 @@ function stripOuterBlankLines(text) {
|
|
|
5571
5577
|
`);
|
|
5572
5578
|
}
|
|
5573
5579
|
function renderPromptTemplate(strings, values) {
|
|
5574
|
-
return stripOuterBlankLines(
|
|
5580
|
+
return stripOuterBlankLines(outdent(strings, ...values.map(toPromptString)));
|
|
5575
5581
|
}
|
|
5576
5582
|
function isTemplateStringsArray(value) {
|
|
5577
5583
|
return Array.isArray(value) && "raw" in value;
|
|
@@ -5619,6 +5625,9 @@ class PromptMessageBuilderImpl {
|
|
|
5619
5625
|
function createPromptMessageBuilder() {
|
|
5620
5626
|
return new PromptMessageBuilderImpl;
|
|
5621
5627
|
}
|
|
5628
|
+
function dedent(strings, ...values) {
|
|
5629
|
+
return renderPromptTemplate(strings, values);
|
|
5630
|
+
}
|
|
5622
5631
|
function prompt(input, ...values) {
|
|
5623
5632
|
if (isTemplateStringsArray(input)) {
|
|
5624
5633
|
return renderPromptTemplate(input, values);
|
|
@@ -5825,6 +5834,7 @@ export {
|
|
|
5825
5834
|
extractMarkdownCodeBlocks,
|
|
5826
5835
|
extractJsonCandidates,
|
|
5827
5836
|
extractFirstMarkdownCode,
|
|
5837
|
+
dedent,
|
|
5828
5838
|
createProviderRegistry,
|
|
5829
5839
|
createOpenAICompatibleAdapter,
|
|
5830
5840
|
createModelAdapter,
|
package/dist/prompt.d.ts
CHANGED
|
@@ -10,5 +10,19 @@ export interface PromptMessageBuilder extends StructuredPromptResolver {
|
|
|
10
10
|
assistant(content: LLMMessageContent): PromptMessageBuilder;
|
|
11
11
|
build(): StructuredPromptPayload;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Tagged template for formatting multi-line prompt strings: dedents the block
|
|
15
|
+
* and trims surrounding blank lines, so you can write readable indented
|
|
16
|
+
* templates instead of concatenating strings with `+`. Interpolated values are
|
|
17
|
+
* coerced the same way as in `prompt`. Returns a plain string — no role/message
|
|
18
|
+
* handling.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const instructions = dedent`
|
|
22
|
+
* You are a helpful assistant.
|
|
23
|
+
* Answer in ${language} and keep responses concise.
|
|
24
|
+
* `;
|
|
25
|
+
*/
|
|
26
|
+
export declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
13
27
|
export declare function prompt(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
14
28
|
export declare function prompt(): PromptMessageBuilder;
|