@automatalabs/pi-acp 0.1.3 → 0.2.1

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.
@@ -1,14 +0,0 @@
1
- import type { AgentSession, ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- export declare const STRUCTURED_TOOL_NAME = "__acp_structured_output";
3
- export declare class StructuredOutputState {
4
- readonly tool: ToolDefinition;
5
- private readonly schemaHolder;
6
- private captured;
7
- private baseActive;
8
- constructor();
9
- install(session: AgentSession): void;
10
- arm(session: AgentSession, schema: unknown): string;
11
- disarm(session: AgentSession): void;
12
- takeJson(): string | undefined;
13
- }
14
- //# sourceMappingURL=structured-output.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAIpF,eAAO,MAAM,oBAAoB,4BAA4B,CAAC;AAE9D,qBAAa,qBAAqB;IAChC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,UAAU,CAAgB;;IAoBlC,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAQpC,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM;IAsBnD,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAKnC,QAAQ,IAAI,MAAM,GAAG,SAAS;CAQ/B"}
@@ -1,71 +0,0 @@
1
- import { Type } from "typebox";
2
- import { adapterError } from "./errors.js";
3
- export const STRUCTURED_TOOL_NAME = "__acp_structured_output";
4
- export class StructuredOutputState {
5
- tool;
6
- schemaHolder = Type.Any();
7
- captured;
8
- baseActive = [];
9
- constructor() {
10
- const tool = {
11
- name: STRUCTURED_TOOL_NAME,
12
- label: "Structured output",
13
- description: "Return the final response as structured data matching the requested schema.",
14
- parameters: this.schemaHolder,
15
- execute: async (_toolCallId, params) => {
16
- this.captured = params;
17
- return {
18
- content: [{ type: "text", text: "(structured output captured)" }],
19
- details: params,
20
- terminate: true,
21
- };
22
- },
23
- };
24
- this.tool = tool;
25
- }
26
- install(session) {
27
- if (!session.getToolDefinition(STRUCTURED_TOOL_NAME)) {
28
- throw adapterError("structured_tool_collision");
29
- }
30
- this.baseActive = session.getActiveToolNames().filter((name) => name !== STRUCTURED_TOOL_NAME);
31
- session.setActiveToolsByName(this.baseActive);
32
- }
33
- arm(session, schema) {
34
- if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
35
- throw adapterError("invalid_output_schema");
36
- }
37
- this.captured = undefined;
38
- const holder = this.schemaHolder;
39
- for (const key of Object.keys(holder))
40
- delete holder[key];
41
- Object.assign(holder, schema);
42
- try {
43
- session.setActiveToolsByName([...this.baseActive, STRUCTURED_TOOL_NAME]);
44
- }
45
- catch (error) {
46
- this.captured = undefined;
47
- try {
48
- session.setActiveToolsByName(this.baseActive);
49
- }
50
- catch (rollbackError) {
51
- console.error("pi-acp structured-output arm rollback error:", rollbackError);
52
- }
53
- throw error;
54
- }
55
- return "Finish by calling __acp_structured_output with a value conforming to the requested output schema.";
56
- }
57
- disarm(session) {
58
- session.setActiveToolsByName(this.baseActive);
59
- this.captured = undefined;
60
- }
61
- takeJson() {
62
- if (this.captured === undefined)
63
- return undefined;
64
- try {
65
- return JSON.stringify(this.captured);
66
- }
67
- catch {
68
- return undefined;
69
- }
70
- }
71
- }