@aparte/core 1.1.2 → 1.2.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.
@@ -189,6 +189,10 @@ const APARTE_DEFAULT_LOCALE = {
189
189
  loading: "Loading…",
190
190
  download: "Download",
191
191
  openArtifact: "Open",
192
+ closeArtifact: "Close",
193
+ artifactVersion: "Version {n} of {total}",
194
+ previousVersion: "Previous version",
195
+ nextVersion: "Next version",
192
196
  modelContextWindow: "{n} context",
193
197
  previewPending: "Press Preview to run this artifact.",
194
198
  sandboxError: "The sandbox failed during generation.",
@@ -5936,9 +5940,15 @@ class AparteConfig {
5936
5940
  * system message after the app's own ({@link AparteConfig.resolveSystemPrompt | resolveSystemPrompt()});
5937
5941
  * a request you assemble yourself should send them the same way, or the model loses the
5938
5942
  * tools' instructions.
5939
- */
5940
- resolveToolSystemPrompts() {
5941
- const prompts = Array.from(this._tools.values()).map((entry) => entry.tool.systemPrompt?.trim()).filter((prompt) => Boolean(prompt));
5943
+ *
5944
+ * Pass the tools the request actually carries, and only theirs come back: an instruction
5945
+ * to use a tool the model was not given (a model without `function_calling`, a turn sent
5946
+ * with `toolChoice: 'none'`) has it describe a call it cannot make. Without the argument,
5947
+ * every registered tool's.
5948
+ */
5949
+ resolveToolSystemPrompts(tools) {
5950
+ const sent = tools ? new Set(tools.map((tool) => tool.name)) : null;
5951
+ const prompts = Array.from(this._tools.values()).filter((entry) => !sent || sent.has(entry.tool.name)).map((entry) => entry.tool.systemPrompt?.trim()).filter((prompt) => Boolean(prompt));
5942
5952
  return prompts.length ? prompts.join("\n\n") : null;
5943
5953
  }
5944
5954
  /** Get the handler for a tool by name */
@@ -8744,7 +8754,10 @@ ${fence}`);
8744
8754
  } else if (segment.type === "thinking" || segment.type === "tool_call" || segment.type === "error") {
8745
8755
  continue;
8746
8756
  } else if (typeof content === "string" && content) {
8747
- parts.push(content);
8757
+ const wire = segment.wire;
8758
+ const before = wire && typeof wire.before === "string" ? wire.before : "";
8759
+ const after = wire && typeof wire.after === "string" ? wire.after : "";
8760
+ parts.push(`${before}${content}${after}`);
8748
8761
  } else {
8749
8762
  const fallback = segment.fallback;
8750
8763
  if (fallback) parts.push(fallback);
@@ -8833,8 +8846,9 @@ function nextRequestTokens(reply, k) {
8833
8846
  function measureContext(input) {
8834
8847
  const { messages, config } = input;
8835
8848
  const view = historyFromCheckpoint(messages);
8836
- const system = estimateTokens(config.resolveSystemPrompt()) + estimateTokens(config.resolveToolSystemPrompts());
8837
- const declared = toolsForCurrentModel(config).map((t) => ({ name: t.name, description: t.description, inputSchema: t.inputSchema }));
8849
+ const sent = toolsForCurrentModel(config);
8850
+ const system = estimateTokens(config.resolveSystemPrompt()) + estimateTokens(config.resolveToolSystemPrompts(sent));
8851
+ const declared = sent.map((t) => ({ name: t.name, description: t.description, inputSchema: t.inputSchema }));
8838
8852
  const tools = declared.length ? estimateJson(declared) : 0;
8839
8853
  const summary = view.summary === void 0 ? 0 : estimateTokens(underPreamble(view.summary));
8840
8854
  const parts = { system, tools, summary, messages: estimateWireTokens(view.messages) };
@@ -9779,7 +9793,12 @@ class AparteClient {
9779
9793
  built = await this.options.requestInterceptor(built);
9780
9794
  }
9781
9795
  if (built.toolChoice === "none") {
9782
- built = { ...built, tools: void 0 };
9796
+ const toolPrompts = this._config.resolveToolSystemPrompts(registeredTools);
9797
+ built = {
9798
+ ...built,
9799
+ tools: void 0,
9800
+ messages: toolPrompts ? built.messages.filter((m) => !(m.role === "system" && m.content === toolPrompts)) : built.messages
9801
+ };
9783
9802
  }
9784
9803
  return built;
9785
9804
  };
@@ -10016,7 +10035,7 @@ class AparteClient {
10016
10035
  const messages = [];
10017
10036
  const appPrompt = this._config.resolveSystemPrompt();
10018
10037
  if (appPrompt) messages.push({ role: "system", content: appPrompt });
10019
- const toolPrompts = this._config.resolveToolSystemPrompts();
10038
+ const toolPrompts = this._config.resolveToolSystemPrompts(this._toolsForCurrentModel());
10020
10039
  if (toolPrompts) messages.push({ role: "system", content: toolPrompts });
10021
10040
  return messages;
10022
10041
  }
@@ -11516,4 +11535,4 @@ export {
11516
11535
  collectRendererStyles as y,
11517
11536
  contentToText as z
11518
11537
  };
11519
- //# sourceMappingURL=defer-hydration-BBdqAZej.js.map
11538
+ //# sourceMappingURL=defer-hydration-Oh04ScDm.js.map