@prompty/core 2.0.0-alpha.4 → 2.0.0-alpha.5
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/dist/index.cjs +20 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +18 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4584,14 +4584,14 @@ var init_tool_dispatch = __esm({
|
|
|
4584
4584
|
async executeTool(tool, _args, _agent, _parentInputs) {
|
|
4585
4585
|
const name = tool.name ?? "unknown";
|
|
4586
4586
|
throw new Error(
|
|
4587
|
-
`Function tool '${name}' declared but no callable provided. Pass it via tools: { '${name}': fn } in
|
|
4587
|
+
`Function tool '${name}' declared but no callable provided. Pass it via tools: { '${name}': fn } in invokeAgent().`
|
|
4588
4588
|
);
|
|
4589
4589
|
}
|
|
4590
4590
|
};
|
|
4591
4591
|
PromptyToolHandler = class {
|
|
4592
4592
|
async executeTool(tool, args, agent, _parentInputs) {
|
|
4593
4593
|
const { load: load2 } = await Promise.resolve().then(() => (init_loader(), loader_exports));
|
|
4594
|
-
const { prepare: prepare2, run: run2,
|
|
4594
|
+
const { prepare: prepare2, run: run2, invokeAgent: invokeAgent2 } = await Promise.resolve().then(() => (init_pipeline(), pipeline_exports));
|
|
4595
4595
|
const parentPath = (agent.metadata ?? {}).__source_path;
|
|
4596
4596
|
if (!parentPath) {
|
|
4597
4597
|
return `Error: cannot resolve PromptyTool '${tool.name}': parent has no __source_path`;
|
|
@@ -4610,7 +4610,7 @@ var init_tool_dispatch = __esm({
|
|
|
4610
4610
|
child.metadata.__prompty_tool_stack = [...stack, parentPath];
|
|
4611
4611
|
const mode = tool.mode ?? "single";
|
|
4612
4612
|
if (mode === "agentic") {
|
|
4613
|
-
const result = await
|
|
4613
|
+
const result = await invokeAgent2(child, args);
|
|
4614
4614
|
return typeof result === "string" ? result : JSON.stringify(result);
|
|
4615
4615
|
} else {
|
|
4616
4616
|
const messages = await prepare2(child, args);
|
|
@@ -4648,15 +4648,14 @@ var init_tool_dispatch = __esm({
|
|
|
4648
4648
|
// src/core/pipeline.ts
|
|
4649
4649
|
var pipeline_exports = {};
|
|
4650
4650
|
__export(pipeline_exports, {
|
|
4651
|
-
|
|
4652
|
-
|
|
4651
|
+
invoke: () => invoke,
|
|
4652
|
+
invokeAgent: () => invokeAgent,
|
|
4653
4653
|
parse: () => parse,
|
|
4654
4654
|
prepare: () => prepare,
|
|
4655
4655
|
process: () => process2,
|
|
4656
4656
|
render: () => render,
|
|
4657
4657
|
resolveBindings: () => resolveBindings,
|
|
4658
4658
|
run: () => run,
|
|
4659
|
-
runAgent: () => runAgent,
|
|
4660
4659
|
validateInputs: () => validateInputs
|
|
4661
4660
|
});
|
|
4662
4661
|
function sanitizeNonces(value) {
|
|
@@ -4833,8 +4832,8 @@ async function run(agent, messages, options) {
|
|
|
4833
4832
|
return result;
|
|
4834
4833
|
});
|
|
4835
4834
|
}
|
|
4836
|
-
async function
|
|
4837
|
-
return traceSpan("
|
|
4835
|
+
async function invoke(prompt, inputs, options) {
|
|
4836
|
+
return traceSpan("invoke", async (emit) => {
|
|
4838
4837
|
const agent = typeof prompt === "string" ? await traceSpan("load", async (loadEmit) => {
|
|
4839
4838
|
loadEmit("signature", "prompty.load");
|
|
4840
4839
|
loadEmit("description", "Load a prompty file.");
|
|
@@ -4843,8 +4842,8 @@ async function execute(prompt, inputs, options) {
|
|
|
4843
4842
|
loadEmit("result", serializeAgent(loaded));
|
|
4844
4843
|
return loaded;
|
|
4845
4844
|
}) : prompt;
|
|
4846
|
-
emit("signature", "prompty.
|
|
4847
|
-
emit("description", "
|
|
4845
|
+
emit("signature", "prompty.invoke");
|
|
4846
|
+
emit("description", "Invoke a prompty");
|
|
4848
4847
|
emit("inputs", { prompt: serializeAgent(agent), inputs: inputs ?? {} });
|
|
4849
4848
|
const messages = await prepare(agent, inputs);
|
|
4850
4849
|
const result = await run(agent, messages, options);
|
|
@@ -4968,8 +4967,8 @@ async function buildToolMessagesFromCalls(toolCalls, textContent, tools, agent,
|
|
|
4968
4967
|
}
|
|
4969
4968
|
return messages;
|
|
4970
4969
|
}
|
|
4971
|
-
async function
|
|
4972
|
-
return traceSpan("
|
|
4970
|
+
async function invokeAgent(prompt, inputs, options) {
|
|
4971
|
+
return traceSpan("invokeAgent", async (emit) => {
|
|
4973
4972
|
const agent = typeof prompt === "string" ? await traceSpan("load", async (loadEmit) => {
|
|
4974
4973
|
loadEmit("signature", "prompty.load");
|
|
4975
4974
|
loadEmit("description", "Load a prompty file.");
|
|
@@ -4980,8 +4979,8 @@ async function executeAgent(prompt, inputs, options) {
|
|
|
4980
4979
|
}) : prompt;
|
|
4981
4980
|
const tools = options?.tools ?? {};
|
|
4982
4981
|
const maxIterations = options?.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
4983
|
-
emit("signature", "prompty.
|
|
4984
|
-
emit("description", "
|
|
4982
|
+
emit("signature", "prompty.invokeAgent");
|
|
4983
|
+
emit("description", "Invoke a prompty with tool calling");
|
|
4985
4984
|
emit("inputs", { prompt: serializeAgent(agent), tools: Object.keys(tools), inputs: inputs ?? {} });
|
|
4986
4985
|
const messages = await prepare(agent, inputs);
|
|
4987
4986
|
const parentInputs = inputs ?? {};
|
|
@@ -5004,7 +5003,7 @@ async function executeAgent(prompt, inputs, options) {
|
|
|
5004
5003
|
);
|
|
5005
5004
|
}
|
|
5006
5005
|
const toolMessages2 = await traceSpan("toolCalls", async (toolEmit) => {
|
|
5007
|
-
toolEmit("signature", "prompty.
|
|
5006
|
+
toolEmit("signature", "prompty.invokeAgent.toolCalls");
|
|
5008
5007
|
toolEmit("description", `Tool call round ${iteration}`);
|
|
5009
5008
|
const result2 = await buildToolMessagesFromCalls(toolCalls, content, tools, agent, parentInputs, toolEmit);
|
|
5010
5009
|
toolEmit("result", result2.map((m) => ({ role: m.role, content: m.parts.map((p) => p.value ?? "").join(""), metadata: m.metadata })));
|
|
@@ -5022,7 +5021,7 @@ async function executeAgent(prompt, inputs, options) {
|
|
|
5022
5021
|
);
|
|
5023
5022
|
}
|
|
5024
5023
|
const toolMessages = await traceSpan("toolCalls", async (toolEmit) => {
|
|
5025
|
-
toolEmit("signature", "prompty.
|
|
5024
|
+
toolEmit("signature", "prompty.invokeAgent.toolCalls");
|
|
5026
5025
|
toolEmit("description", `Tool call round ${iteration}`);
|
|
5027
5026
|
const result2 = await buildToolResultMessages(response, tools, agent, parentInputs, toolEmit);
|
|
5028
5027
|
toolEmit("result", result2.map((m) => ({ role: m.role, content: m.parts.map((p) => p.value ?? "").join(""), metadata: m.metadata })));
|
|
@@ -5261,7 +5260,7 @@ async function buildResponsesToolResultMessages(r, tools, agent, parentInputs, p
|
|
|
5261
5260
|
}
|
|
5262
5261
|
return messages;
|
|
5263
5262
|
}
|
|
5264
|
-
var DEFAULT_FORMAT, DEFAULT_PARSER, DEFAULT_PROVIDER, DEFAULT_MAX_ITERATIONS
|
|
5263
|
+
var DEFAULT_FORMAT, DEFAULT_PARSER, DEFAULT_PROVIDER, DEFAULT_MAX_ITERATIONS;
|
|
5265
5264
|
var init_pipeline = __esm({
|
|
5266
5265
|
"src/core/pipeline.ts"() {
|
|
5267
5266
|
"use strict";
|
|
@@ -5275,7 +5274,6 @@ var init_pipeline = __esm({
|
|
|
5275
5274
|
DEFAULT_PARSER = "prompty";
|
|
5276
5275
|
DEFAULT_PROVIDER = "openai";
|
|
5277
5276
|
DEFAULT_MAX_ITERATIONS = 10;
|
|
5278
|
-
runAgent = executeAgent;
|
|
5279
5277
|
}
|
|
5280
5278
|
});
|
|
5281
5279
|
|
|
@@ -5326,13 +5324,13 @@ __export(index_exports, {
|
|
|
5326
5324
|
consoleTracer: () => consoleTracer,
|
|
5327
5325
|
dictContentToPart: () => dictContentToPart,
|
|
5328
5326
|
dictToMessage: () => dictToMessage,
|
|
5329
|
-
execute: () => execute,
|
|
5330
|
-
executeAgent: () => executeAgent,
|
|
5331
5327
|
getConnection: () => getConnection,
|
|
5332
5328
|
getExecutor: () => getExecutor,
|
|
5333
5329
|
getParser: () => getParser,
|
|
5334
5330
|
getProcessor: () => getProcessor,
|
|
5335
5331
|
getRenderer: () => getRenderer,
|
|
5332
|
+
invoke: () => invoke,
|
|
5333
|
+
invokeAgent: () => invokeAgent,
|
|
5336
5334
|
load: () => load,
|
|
5337
5335
|
otelTracer: () => otelTracer,
|
|
5338
5336
|
parse: () => parse,
|
|
@@ -5346,7 +5344,6 @@ __export(index_exports, {
|
|
|
5346
5344
|
render: () => render,
|
|
5347
5345
|
resolveBindings: () => resolveBindings,
|
|
5348
5346
|
run: () => run,
|
|
5349
|
-
runAgent: () => runAgent,
|
|
5350
5347
|
sanitizeValue: () => sanitizeValue,
|
|
5351
5348
|
text: () => text,
|
|
5352
5349
|
textMessage: () => textMessage,
|
|
@@ -5816,13 +5813,13 @@ registerParser("prompty", new PromptyChatParser());
|
|
|
5816
5813
|
consoleTracer,
|
|
5817
5814
|
dictContentToPart,
|
|
5818
5815
|
dictToMessage,
|
|
5819
|
-
execute,
|
|
5820
|
-
executeAgent,
|
|
5821
5816
|
getConnection,
|
|
5822
5817
|
getExecutor,
|
|
5823
5818
|
getParser,
|
|
5824
5819
|
getProcessor,
|
|
5825
5820
|
getRenderer,
|
|
5821
|
+
invoke,
|
|
5822
|
+
invokeAgent,
|
|
5826
5823
|
load,
|
|
5827
5824
|
otelTracer,
|
|
5828
5825
|
parse,
|
|
@@ -5836,7 +5833,6 @@ registerParser("prompty", new PromptyChatParser());
|
|
|
5836
5833
|
render,
|
|
5837
5834
|
resolveBindings,
|
|
5838
5835
|
run,
|
|
5839
|
-
runAgent,
|
|
5840
5836
|
sanitizeValue,
|
|
5841
5837
|
text,
|
|
5842
5838
|
textMessage,
|