@codespar/sdk 0.0.1 → 0.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.
- package/README.md +79 -0
- package/dist/__tests__/codespar.test.d.ts +9 -0
- package/dist/__tests__/codespar.test.d.ts.map +1 -0
- package/dist/__tests__/codespar.test.js +135 -0
- package/dist/__tests__/codespar.test.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +15 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +307 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +255 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -1
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @codespar/sdk
|
|
2
|
+
|
|
3
|
+
Commerce SDK for AI agents — sessions, managed auth, Complete Loop orchestration for Latin American commercial APIs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @codespar/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { CodeSpar } from "@codespar/sdk";
|
|
15
|
+
|
|
16
|
+
const cs = new CodeSpar({ apiKey: "ak_..." });
|
|
17
|
+
|
|
18
|
+
const session = await cs.create("user_123", {
|
|
19
|
+
preset: "brazilian",
|
|
20
|
+
manageConnections: { waitForConnections: true },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Natural language
|
|
24
|
+
const result = await session.send("Charge R$150 via Pix and issue the NF-e");
|
|
25
|
+
|
|
26
|
+
// Direct tool execution
|
|
27
|
+
const charge = await session.execute("ZOOP_CREATE_CHARGE", {
|
|
28
|
+
amount: 150.0,
|
|
29
|
+
payment_type: "pix",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Complete Loop
|
|
33
|
+
const loop = await session.loop({
|
|
34
|
+
steps: [
|
|
35
|
+
{ server: "mcp-zoop", tool: "ZOOP_CREATE_CHARGE", params: { amount: 150, payment_type: "pix" } },
|
|
36
|
+
{ server: "mcp-nuvem-fiscal", tool: "NUVEMFISCAL_EMITIR_NFE", params: (prev) => ({ chargeId: prev[0].data }) },
|
|
37
|
+
{ server: "mcp-melhor-envio", tool: "MELHORENVIO_GENERATE_LABEL", params: {} },
|
|
38
|
+
{ server: "mcp-z-api", tool: "ZAPI_SEND_MESSAGE", params: { text: "Your order is on the way!" } },
|
|
39
|
+
],
|
|
40
|
+
onStepComplete: (step, result) => console.log(`✓ ${step.tool}`),
|
|
41
|
+
retryPolicy: { maxRetries: 3, backoff: "exponential" },
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### `new CodeSpar(config)`
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
|--------|------|---------|-------------|
|
|
51
|
+
| `apiKey` | `string` | `CODESPAR_API_KEY` env | Your API key |
|
|
52
|
+
| `baseUrl` | `string` | `https://api.codespar.dev` | API base URL |
|
|
53
|
+
| `managed` | `boolean` | `true` | Enable managed billing/logging |
|
|
54
|
+
|
|
55
|
+
### `cs.create(userId, config)`
|
|
56
|
+
|
|
57
|
+
| Option | Type | Description |
|
|
58
|
+
|--------|------|-------------|
|
|
59
|
+
| `servers` | `string[]` | MCP servers to connect |
|
|
60
|
+
| `preset` | `string` | `"brazilian"`, `"mexican"`, `"argentinian"`, `"colombian"`, `"all"` |
|
|
61
|
+
| `manageConnections.waitForConnections` | `boolean` | Block until all servers connected |
|
|
62
|
+
|
|
63
|
+
### Session Methods
|
|
64
|
+
|
|
65
|
+
| Method | Description |
|
|
66
|
+
|--------|-------------|
|
|
67
|
+
| `session.tools()` | Get all available tools |
|
|
68
|
+
| `session.findTools(intent)` | Search tools by description |
|
|
69
|
+
| `session.execute(tool, params)` | Execute a specific tool |
|
|
70
|
+
| `session.send(message)` | Send natural language message |
|
|
71
|
+
| `session.loop(config)` | Run Complete Loop workflow |
|
|
72
|
+
| `session.authorize(serverId)` | Start OAuth flow for a server |
|
|
73
|
+
| `session.connections()` | List connected servers |
|
|
74
|
+
| `session.mcp` | MCP transport URL and headers |
|
|
75
|
+
| `session.close()` | Close session |
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT — [codespar.dev](https://codespar.dev)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codespar/sdk basic tests.
|
|
3
|
+
*
|
|
4
|
+
* The 0.1.0 test suite assumed an older client-shaped API and has been
|
|
5
|
+
* replaced for 0.2.0. Comprehensive integration tests (mocking fetch
|
|
6
|
+
* against the api.codespar.dev contract) are tracked for a follow-up.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=codespar.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codespar.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/codespar.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codespar/sdk basic tests.
|
|
3
|
+
*
|
|
4
|
+
* The 0.1.0 test suite assumed an older client-shaped API and has been
|
|
5
|
+
* replaced for 0.2.0. Comprehensive integration tests (mocking fetch
|
|
6
|
+
* against the api.codespar.dev contract) are tracked for a follow-up.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
9
|
+
import { CodeSpar } from "../index.js";
|
|
10
|
+
import { SessionConfigSchema } from "../types.js";
|
|
11
|
+
describe("CodeSpar constructor", () => {
|
|
12
|
+
it("requires an API key", () => {
|
|
13
|
+
const prev = process.env.CODESPAR_API_KEY;
|
|
14
|
+
delete process.env.CODESPAR_API_KEY;
|
|
15
|
+
try {
|
|
16
|
+
expect(() => new CodeSpar({})).toThrow(/API key is required/);
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
if (prev)
|
|
20
|
+
process.env.CODESPAR_API_KEY = prev;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
it("accepts apiKey via constructor", () => {
|
|
24
|
+
const cs = new CodeSpar({ apiKey: "csk_live_test" });
|
|
25
|
+
expect(cs).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
it("accepts apiKey via env var", () => {
|
|
28
|
+
process.env.CODESPAR_API_KEY = "csk_live_envtest";
|
|
29
|
+
try {
|
|
30
|
+
const cs = new CodeSpar();
|
|
31
|
+
expect(cs).toBeDefined();
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
delete process.env.CODESPAR_API_KEY;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
it("defaults baseUrl to api.codespar.dev", () => {
|
|
38
|
+
process.env.CODESPAR_API_KEY = "csk_live_test";
|
|
39
|
+
process.env.CODESPAR_BASE_URL = "";
|
|
40
|
+
try {
|
|
41
|
+
const cs = new CodeSpar();
|
|
42
|
+
// baseUrl is private but the constructor logic verifies the default.
|
|
43
|
+
expect(cs).toBeDefined();
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
delete process.env.CODESPAR_API_KEY;
|
|
47
|
+
delete process.env.CODESPAR_BASE_URL;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe("SessionConfigSchema", () => {
|
|
52
|
+
it("accepts an empty config", () => {
|
|
53
|
+
expect(() => SessionConfigSchema.parse({})).not.toThrow();
|
|
54
|
+
});
|
|
55
|
+
it("accepts servers as a string array", () => {
|
|
56
|
+
expect(() => SessionConfigSchema.parse({ servers: ["zoop", "nuvem-fiscal"] })).not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
it("accepts known presets", () => {
|
|
59
|
+
expect(() => SessionConfigSchema.parse({ preset: "brazilian" })).not.toThrow();
|
|
60
|
+
expect(() => SessionConfigSchema.parse({ preset: "mexican" })).not.toThrow();
|
|
61
|
+
expect(() => SessionConfigSchema.parse({ preset: "all" })).not.toThrow();
|
|
62
|
+
});
|
|
63
|
+
it("rejects unknown presets", () => {
|
|
64
|
+
expect(() => SessionConfigSchema.parse({ preset: "klingon" })).toThrow();
|
|
65
|
+
});
|
|
66
|
+
it("accepts manageConnections options", () => {
|
|
67
|
+
expect(() => SessionConfigSchema.parse({
|
|
68
|
+
manageConnections: { waitForConnections: true, timeout: 5000 },
|
|
69
|
+
})).not.toThrow();
|
|
70
|
+
});
|
|
71
|
+
it("accepts metadata", () => {
|
|
72
|
+
expect(() => SessionConfigSchema.parse({ metadata: { source: "sandbox" } })).not.toThrow();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("CodeSpar.create wires fetch correctly", () => {
|
|
76
|
+
const originalFetch = globalThis.fetch;
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
globalThis.fetch = originalFetch;
|
|
79
|
+
});
|
|
80
|
+
it("POSTs to /v1/sessions with snake_case body", async () => {
|
|
81
|
+
const fetchMock = vi.fn().mockResolvedValue({
|
|
82
|
+
ok: true,
|
|
83
|
+
status: 201,
|
|
84
|
+
text: async () => "",
|
|
85
|
+
json: async () => ({
|
|
86
|
+
id: "ses_test123",
|
|
87
|
+
org_id: "org_test",
|
|
88
|
+
user_id: "user_42",
|
|
89
|
+
servers: ["zoop"],
|
|
90
|
+
status: "active",
|
|
91
|
+
created_at: new Date().toISOString(),
|
|
92
|
+
closed_at: null,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
globalThis.fetch = fetchMock;
|
|
96
|
+
const cs = new CodeSpar({
|
|
97
|
+
apiKey: "csk_live_test",
|
|
98
|
+
baseUrl: "https://api.example.com",
|
|
99
|
+
});
|
|
100
|
+
const session = await cs.create("user_42", { servers: ["zoop"] });
|
|
101
|
+
expect(session.id).toBe("ses_test123");
|
|
102
|
+
expect(session.userId).toBe("user_42");
|
|
103
|
+
expect(session.servers).toEqual(["zoop"]);
|
|
104
|
+
// Assert the request body uses snake_case keys (not userId)
|
|
105
|
+
const callArgs = fetchMock.mock.calls[0];
|
|
106
|
+
expect(callArgs[0]).toBe("https://api.example.com/v1/sessions");
|
|
107
|
+
const init = callArgs[1];
|
|
108
|
+
expect(init.method).toBe("POST");
|
|
109
|
+
expect(init.headers.Authorization).toBe("Bearer csk_live_test");
|
|
110
|
+
const body = JSON.parse(init.body);
|
|
111
|
+
expect(body.servers).toEqual(["zoop"]);
|
|
112
|
+
expect(body.user_id).toBe("user_42");
|
|
113
|
+
});
|
|
114
|
+
it("populates session.mcp as a placeholder", async () => {
|
|
115
|
+
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
116
|
+
ok: true,
|
|
117
|
+
status: 201,
|
|
118
|
+
text: async () => "",
|
|
119
|
+
json: async () => ({
|
|
120
|
+
id: "ses_mcp",
|
|
121
|
+
org_id: "org_test",
|
|
122
|
+
user_id: "user_1",
|
|
123
|
+
servers: [],
|
|
124
|
+
status: "active",
|
|
125
|
+
created_at: new Date().toISOString(),
|
|
126
|
+
closed_at: null,
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
const cs = new CodeSpar({ apiKey: "csk_live_test", baseUrl: "https://api.example.com" });
|
|
130
|
+
const session = await cs.create("user_1");
|
|
131
|
+
expect(session.mcp.url).toBe("https://api.example.com/v1/sessions/ses_mcp/mcp");
|
|
132
|
+
expect(session.mcp.headers.Authorization).toBe("Bearer csk_live_test");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=codespar.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codespar.test.js","sourceRoot":"","sources":["../../src/__tests__/codespar.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE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C,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codespar/sdk — Commerce SDK for AI agents
|
|
3
|
+
*
|
|
4
|
+
* Sessions, managed auth, Complete Loop orchestration for Latin American
|
|
5
|
+
* commercial APIs. Talks to api.codespar.dev — see the backend at
|
|
6
|
+
* codespar/codespar-enterprise (packages/api) for the wire contract.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { CodeSpar } from "@codespar/sdk";
|
|
11
|
+
*
|
|
12
|
+
* const cs = new CodeSpar({ apiKey: "csk_live_..." });
|
|
13
|
+
* const session = await cs.create("user_123", { preset: "brazilian" });
|
|
14
|
+
*
|
|
15
|
+
* // One-shot natural language
|
|
16
|
+
* const result = await session.send("Charge R$150 via Pix and issue the NF-e");
|
|
17
|
+
*
|
|
18
|
+
* // Or stream the agent's thinking + tool calls
|
|
19
|
+
* for await (const event of session.sendStream("Charge R$150 via Pix")) {
|
|
20
|
+
* if (event.type === "tool_result") console.log(event.toolCall);
|
|
21
|
+
* if (event.type === "assistant_text") console.log(event.content);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
export type { CodeSparConfig, Session, SessionConfig, Tool, ToolResult, LoopConfig, LoopStep, LoopResult, AuthConfig, AuthResult, ServerConnection, SendResult, ToolCallRecord, StreamEvent, } from "./types.js";
|
|
28
|
+
export { SessionConfigSchema } from "./types.js";
|
|
29
|
+
import type { CodeSparConfig, Session, SessionConfig } from "./types.js";
|
|
30
|
+
export declare class CodeSpar {
|
|
31
|
+
private readonly config;
|
|
32
|
+
constructor(config?: CodeSparConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Create a new session for a user.
|
|
35
|
+
*
|
|
36
|
+
* @param userId - Unique user identifier
|
|
37
|
+
* @param config - Session configuration (servers, preset, metadata)
|
|
38
|
+
*/
|
|
39
|
+
create(userId: string, config?: SessionConfig): Promise<Session>;
|
|
40
|
+
}
|
|
41
|
+
export default CodeSpar;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,YAAY,EACV,cAAc,EACd,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMzE,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;gBAEtC,MAAM,GAAE,cAAmB;IAcvC;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAO3E;AAED,eAAe,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codespar/sdk — Commerce SDK for AI agents
|
|
3
|
+
*
|
|
4
|
+
* Sessions, managed auth, Complete Loop orchestration for Latin American
|
|
5
|
+
* commercial APIs. Talks to api.codespar.dev — see the backend at
|
|
6
|
+
* codespar/codespar-enterprise (packages/api) for the wire contract.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { CodeSpar } from "@codespar/sdk";
|
|
11
|
+
*
|
|
12
|
+
* const cs = new CodeSpar({ apiKey: "csk_live_..." });
|
|
13
|
+
* const session = await cs.create("user_123", { preset: "brazilian" });
|
|
14
|
+
*
|
|
15
|
+
* // One-shot natural language
|
|
16
|
+
* const result = await session.send("Charge R$150 via Pix and issue the NF-e");
|
|
17
|
+
*
|
|
18
|
+
* // Or stream the agent's thinking + tool calls
|
|
19
|
+
* for await (const event of session.sendStream("Charge R$150 via Pix")) {
|
|
20
|
+
* if (event.type === "tool_result") console.log(event.toolCall);
|
|
21
|
+
* if (event.type === "assistant_text") console.log(event.content);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
export { SessionConfigSchema } from "./types.js";
|
|
28
|
+
import { SessionConfigSchema } from "./types.js";
|
|
29
|
+
import { createSession } from "./session.js";
|
|
30
|
+
const DEFAULT_BASE_URL = "https://api.codespar.dev";
|
|
31
|
+
export class CodeSpar {
|
|
32
|
+
config;
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
this.config = {
|
|
35
|
+
apiKey: config.apiKey || process.env.CODESPAR_API_KEY || "",
|
|
36
|
+
baseUrl: config.baseUrl || process.env.CODESPAR_BASE_URL || DEFAULT_BASE_URL,
|
|
37
|
+
};
|
|
38
|
+
if (!this.config.apiKey) {
|
|
39
|
+
throw new Error("CodeSpar API key is required. Pass { apiKey: '...' } or set CODESPAR_API_KEY env var.\n" +
|
|
40
|
+
"Get your key at https://codespar.dev/dashboard/settings?tab=api-keys");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a new session for a user.
|
|
45
|
+
*
|
|
46
|
+
* @param userId - Unique user identifier
|
|
47
|
+
* @param config - Session configuration (servers, preset, metadata)
|
|
48
|
+
*/
|
|
49
|
+
async create(userId, config = {}) {
|
|
50
|
+
SessionConfigSchema.parse(config);
|
|
51
|
+
return createSession(userId, config, {
|
|
52
|
+
baseUrl: this.config.baseUrl,
|
|
53
|
+
apiKey: this.config.apiKey,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default CodeSpar;
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAmBH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,MAAM,OAAO,QAAQ;IACF,MAAM,CAA2B;IAElD,YAAY,SAAyB,EAAE;QACrC,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;YAC3D,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,gBAAgB;SAC7E,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,yFAAyF;gBACvF,sEAAsE,CACzE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,SAAwB,EAAE;QACrD,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE;YACnC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session implementation — talks to api.codespar.dev backend.
|
|
3
|
+
*
|
|
4
|
+
* The shape of every request and response in this file matches what the
|
|
5
|
+
* backend (codespar-enterprise/packages/api) actually exposes. Do not edit
|
|
6
|
+
* one without the other.
|
|
7
|
+
*/
|
|
8
|
+
import type { Session, SessionConfig } from "./types.js";
|
|
9
|
+
interface SessionDeps {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createSession(userId: string, config: SessionConfig, deps: SessionDeps): Promise<Session>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EAUd,MAAM,YAAY,CAAC;AAEpB,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAiBD,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,OAAO,CAAC,CAkNlB"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session implementation — talks to api.codespar.dev backend.
|
|
3
|
+
*
|
|
4
|
+
* The shape of every request and response in this file matches what the
|
|
5
|
+
* backend (codespar-enterprise/packages/api) actually exposes. Do not edit
|
|
6
|
+
* one without the other.
|
|
7
|
+
*/
|
|
8
|
+
export async function createSession(userId, config, deps) {
|
|
9
|
+
const { baseUrl, apiKey } = deps;
|
|
10
|
+
const headers = {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
Authorization: `Bearer ${apiKey}`,
|
|
13
|
+
};
|
|
14
|
+
// Resolve servers from preset if not explicit. The backend doesn't know
|
|
15
|
+
// about presets — it expects an explicit array of server ids.
|
|
16
|
+
const servers = config.servers ?? presetToServers(config.preset);
|
|
17
|
+
const res = await fetch(`${baseUrl}/v1/sessions`, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers,
|
|
20
|
+
body: JSON.stringify({ servers, user_id: userId }),
|
|
21
|
+
});
|
|
22
|
+
if (!res.ok) {
|
|
23
|
+
const body = await res.text();
|
|
24
|
+
throw new Error(`createSession failed: ${res.status} ${body}`);
|
|
25
|
+
}
|
|
26
|
+
const data = (await res.json());
|
|
27
|
+
let cachedTools = null;
|
|
28
|
+
let cachedConnections = null;
|
|
29
|
+
const session = {
|
|
30
|
+
id: data.id,
|
|
31
|
+
userId: data.user_id,
|
|
32
|
+
servers: data.servers,
|
|
33
|
+
createdAt: new Date(data.created_at),
|
|
34
|
+
status: data.status,
|
|
35
|
+
// Placeholder MCP transport URL — runtime endpoint lands in Marco 3.
|
|
36
|
+
// Kept here so @codespar/mcp config helpers work today.
|
|
37
|
+
mcp: {
|
|
38
|
+
url: `${baseUrl}/v1/sessions/${data.id}/mcp`,
|
|
39
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
40
|
+
},
|
|
41
|
+
async tools() {
|
|
42
|
+
if (cachedTools)
|
|
43
|
+
return cachedTools;
|
|
44
|
+
await session.connections();
|
|
45
|
+
return cachedTools ?? [];
|
|
46
|
+
},
|
|
47
|
+
async findTools(intent) {
|
|
48
|
+
const all = await session.tools();
|
|
49
|
+
const q = intent.toLowerCase();
|
|
50
|
+
return all.filter((t) => t.name.toLowerCase().includes(q) ||
|
|
51
|
+
t.description.toLowerCase().includes(q));
|
|
52
|
+
},
|
|
53
|
+
async execute(toolName, params) {
|
|
54
|
+
const start = Date.now();
|
|
55
|
+
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/execute`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers,
|
|
58
|
+
body: JSON.stringify({ tool: toolName, input: params }),
|
|
59
|
+
});
|
|
60
|
+
if (!r.ok) {
|
|
61
|
+
const body = await r.text();
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
data: null,
|
|
65
|
+
error: `${r.status}: ${body}`,
|
|
66
|
+
duration: Date.now() - start,
|
|
67
|
+
server: "",
|
|
68
|
+
tool: toolName,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const result = (await r.json());
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
async loop(loopConfig) {
|
|
75
|
+
const start = Date.now();
|
|
76
|
+
const results = [];
|
|
77
|
+
const maxRetries = loopConfig.retryPolicy?.maxRetries ?? 0;
|
|
78
|
+
const abortOnError = loopConfig.abortOnError ?? true;
|
|
79
|
+
for (let i = 0; i < loopConfig.steps.length; i++) {
|
|
80
|
+
const step = loopConfig.steps[i];
|
|
81
|
+
if (step.when && !step.when(results))
|
|
82
|
+
continue;
|
|
83
|
+
const params = typeof step.params === "function" ? step.params(results) : step.params;
|
|
84
|
+
let lastError = null;
|
|
85
|
+
let result = null;
|
|
86
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
87
|
+
try {
|
|
88
|
+
result = await session.execute(step.tool, params);
|
|
89
|
+
if (result.success) {
|
|
90
|
+
lastError = null;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
lastError = new Error(result.error || "Tool execution failed");
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
97
|
+
}
|
|
98
|
+
if (attempt < maxRetries) {
|
|
99
|
+
const baseDelay = loopConfig.retryPolicy?.baseDelay ?? 1000;
|
|
100
|
+
const delay = loopConfig.retryPolicy?.backoff === "exponential"
|
|
101
|
+
? baseDelay * Math.pow(2, attempt)
|
|
102
|
+
: baseDelay * (attempt + 1);
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (lastError || !result?.success) {
|
|
107
|
+
if (loopConfig.onStepError) {
|
|
108
|
+
loopConfig.onStepError(step, lastError || new Error("Unknown error"), i);
|
|
109
|
+
}
|
|
110
|
+
if (result)
|
|
111
|
+
results.push(result);
|
|
112
|
+
if (abortOnError) {
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
results,
|
|
116
|
+
duration: Date.now() - start,
|
|
117
|
+
completedSteps: results.filter((r) => r.success).length,
|
|
118
|
+
totalSteps: loopConfig.steps.length,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
results.push(result);
|
|
124
|
+
if (loopConfig.onStepComplete) {
|
|
125
|
+
loopConfig.onStepComplete(step, result, i);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
success: results.every((r) => r.success),
|
|
130
|
+
results,
|
|
131
|
+
duration: Date.now() - start,
|
|
132
|
+
completedSteps: results.filter((r) => r.success).length,
|
|
133
|
+
totalSteps: loopConfig.steps.length,
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
async send(message) {
|
|
137
|
+
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: { ...headers, Accept: "application/json" },
|
|
140
|
+
body: JSON.stringify({ message }),
|
|
141
|
+
});
|
|
142
|
+
if (!r.ok) {
|
|
143
|
+
const body = await r.text();
|
|
144
|
+
throw new Error(`send failed: ${r.status} ${body}`);
|
|
145
|
+
}
|
|
146
|
+
return (await r.json());
|
|
147
|
+
},
|
|
148
|
+
async *sendStream(message) {
|
|
149
|
+
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
headers: { ...headers, Accept: "text/event-stream" },
|
|
152
|
+
body: JSON.stringify({ message }),
|
|
153
|
+
});
|
|
154
|
+
if (!r.ok || !r.body) {
|
|
155
|
+
const body = await r.text();
|
|
156
|
+
throw new Error(`sendStream failed: ${r.status} ${body}`);
|
|
157
|
+
}
|
|
158
|
+
yield* parseSseStream(r.body);
|
|
159
|
+
},
|
|
160
|
+
async authorize(_serverId, _config) {
|
|
161
|
+
return {
|
|
162
|
+
connected: false,
|
|
163
|
+
error: "session.authorize() is not implemented in @codespar/sdk@0.2.0 — coming in Marco 3. " +
|
|
164
|
+
"For now, configure auth via the dashboard at https://codespar.dev/dashboard/auth-configs",
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
async connections() {
|
|
168
|
+
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/connections`, {
|
|
169
|
+
headers,
|
|
170
|
+
});
|
|
171
|
+
if (!r.ok)
|
|
172
|
+
return cachedConnections ?? [];
|
|
173
|
+
const payload = (await r.json());
|
|
174
|
+
cachedConnections = payload.servers;
|
|
175
|
+
cachedTools = payload.tools;
|
|
176
|
+
return payload.servers;
|
|
177
|
+
},
|
|
178
|
+
async close() {
|
|
179
|
+
await fetch(`${baseUrl}/v1/sessions/${data.id}`, {
|
|
180
|
+
method: "DELETE",
|
|
181
|
+
headers,
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
if (config.manageConnections?.waitForConnections) {
|
|
186
|
+
const timeout = config.manageConnections.timeout ?? 30000;
|
|
187
|
+
const start = Date.now();
|
|
188
|
+
while (Date.now() - start < timeout) {
|
|
189
|
+
const conns = await session.connections();
|
|
190
|
+
if (conns.every((c) => c.connected))
|
|
191
|
+
break;
|
|
192
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return session;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Parse a Server-Sent Events stream into typed StreamEvent objects.
|
|
199
|
+
*
|
|
200
|
+
* The backend emits events shaped like:
|
|
201
|
+
* event: assistant_text
|
|
202
|
+
* data: {"content":"...","iteration":1}
|
|
203
|
+
*
|
|
204
|
+
* which we map to discriminated-union StreamEvent values that the SDK
|
|
205
|
+
* exports. We intentionally keep parsing tiny: split on double newlines,
|
|
206
|
+
* pick out `event:` and `data:` lines, JSON-parse the data.
|
|
207
|
+
*/
|
|
208
|
+
async function* parseSseStream(body) {
|
|
209
|
+
const reader = body.getReader();
|
|
210
|
+
const decoder = new TextDecoder();
|
|
211
|
+
let buffer = "";
|
|
212
|
+
try {
|
|
213
|
+
while (true) {
|
|
214
|
+
const { done, value } = await reader.read();
|
|
215
|
+
if (done)
|
|
216
|
+
break;
|
|
217
|
+
buffer += decoder.decode(value, { stream: true });
|
|
218
|
+
let sep;
|
|
219
|
+
while ((sep = buffer.indexOf("\n\n")) !== -1) {
|
|
220
|
+
const chunk = buffer.slice(0, sep);
|
|
221
|
+
buffer = buffer.slice(sep + 2);
|
|
222
|
+
const event = parseSseChunk(chunk);
|
|
223
|
+
if (event)
|
|
224
|
+
yield event;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (buffer.trim()) {
|
|
228
|
+
const event = parseSseChunk(buffer);
|
|
229
|
+
if (event)
|
|
230
|
+
yield event;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
reader.releaseLock();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function parseSseChunk(chunk) {
|
|
238
|
+
let eventName = "message";
|
|
239
|
+
let dataLine = "";
|
|
240
|
+
for (const line of chunk.split("\n")) {
|
|
241
|
+
if (line.startsWith("event:"))
|
|
242
|
+
eventName = line.slice(6).trim();
|
|
243
|
+
else if (line.startsWith("data:"))
|
|
244
|
+
dataLine += line.slice(5).trim();
|
|
245
|
+
}
|
|
246
|
+
if (!dataLine)
|
|
247
|
+
return null;
|
|
248
|
+
let data;
|
|
249
|
+
try {
|
|
250
|
+
data = JSON.parse(dataLine);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
switch (eventName) {
|
|
256
|
+
case "user_message":
|
|
257
|
+
return { type: "user_message", content: data.content };
|
|
258
|
+
case "assistant_text":
|
|
259
|
+
return {
|
|
260
|
+
type: "assistant_text",
|
|
261
|
+
content: data.content,
|
|
262
|
+
iteration: data.iteration,
|
|
263
|
+
};
|
|
264
|
+
case "tool_use":
|
|
265
|
+
return {
|
|
266
|
+
type: "tool_use",
|
|
267
|
+
id: data.id,
|
|
268
|
+
name: data.name,
|
|
269
|
+
input: data.input,
|
|
270
|
+
};
|
|
271
|
+
case "tool_result":
|
|
272
|
+
return { type: "tool_result", toolCall: data };
|
|
273
|
+
case "done":
|
|
274
|
+
return { type: "done", result: data };
|
|
275
|
+
case "error":
|
|
276
|
+
return {
|
|
277
|
+
type: "error",
|
|
278
|
+
error: data.error,
|
|
279
|
+
message: data.message,
|
|
280
|
+
};
|
|
281
|
+
default:
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const PRESET_SERVERS = {
|
|
286
|
+
brazilian: ["zoop", "nuvem-fiscal", "melhor-envio", "z-api", "omie"],
|
|
287
|
+
mexican: ["conekta", "facturapi", "skydropx"],
|
|
288
|
+
argentinian: ["afip", "andreani"],
|
|
289
|
+
colombian: ["wompi", "siigo", "coordinadora"],
|
|
290
|
+
all: [
|
|
291
|
+
"zoop",
|
|
292
|
+
"nuvem-fiscal",
|
|
293
|
+
"melhor-envio",
|
|
294
|
+
"z-api",
|
|
295
|
+
"omie",
|
|
296
|
+
"conekta",
|
|
297
|
+
"facturapi",
|
|
298
|
+
"afip",
|
|
299
|
+
"wompi",
|
|
300
|
+
],
|
|
301
|
+
};
|
|
302
|
+
function presetToServers(preset) {
|
|
303
|
+
if (!preset)
|
|
304
|
+
return ["zoop", "nuvem-fiscal"]; // sensible default for sandbox
|
|
305
|
+
return PRESET_SERVERS[preset];
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","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AS,EAAE,WAAW,EAAE,UAAU,CAAC;IAC7C,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;IACjC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC;IAC7C,GAAG,EAAE;QACH,MAAM;QACN,cAAc;QACd,cAAc;QACd,OAAO;QACP,MAAM;QACN,SAAS;QACT,WAAW;QACX,MAAM;QACN,OAAO;KACR;CACF,CAAC;AAEF,SAAS,eAAe,CAAC,MAA+B;IACtD,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,+BAA+B;IAC7E,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface CodeSparConfig {
|
|
3
|
+
/** API key for managed mode. Obtain from dashboard.codespar.dev */
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
/** Base URL for CodeSpar API. Defaults to https://api.codespar.dev */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SessionConfig {
|
|
9
|
+
/** MCP servers to connect, by id (e.g. "zoop", "nuvem-fiscal") */
|
|
10
|
+
servers?: string[];
|
|
11
|
+
/** Preset configurations. "brazilian" enables BR commerce servers. */
|
|
12
|
+
preset?: "brazilian" | "mexican" | "argentinian" | "colombian" | "all";
|
|
13
|
+
/** Connection management options */
|
|
14
|
+
manageConnections?: {
|
|
15
|
+
/** Block until all servers are connected */
|
|
16
|
+
waitForConnections?: boolean;
|
|
17
|
+
/** Timeout in ms for connection wait. Default: 30000 */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
};
|
|
20
|
+
/** Metadata attached to every tool call in this session */
|
|
21
|
+
metadata?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
export interface Session {
|
|
24
|
+
/** Unique session ID (e.g. "ses_HZb4d5yxIAxLawb4") */
|
|
25
|
+
id: string;
|
|
26
|
+
/** User ID that owns this session */
|
|
27
|
+
userId: string;
|
|
28
|
+
/** IDs of the servers attached to this session */
|
|
29
|
+
servers: string[];
|
|
30
|
+
/** Session creation timestamp */
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
/** Session status */
|
|
33
|
+
status: "active" | "closed" | "error";
|
|
34
|
+
/**
|
|
35
|
+
* MCP transport endpoint for this session. Pass to @codespar/mcp helpers
|
|
36
|
+
* (getClaudeDesktopConfig, getCursorConfig) to generate config files for
|
|
37
|
+
* MCP-compatible clients.
|
|
38
|
+
*
|
|
39
|
+
* Note: the runtime MCP endpoint is not yet implemented in the backend
|
|
40
|
+
* (planned for Marco 3). The URL is provided so config generators can
|
|
41
|
+
* produce the correct values today; runtime connection will work once
|
|
42
|
+
* the backend MCP transport ships.
|
|
43
|
+
*/
|
|
44
|
+
mcp: {
|
|
45
|
+
url: string;
|
|
46
|
+
headers: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Get tools available in this session. Loads from the backend on first
|
|
50
|
+
* call and caches. Call connections() to refresh.
|
|
51
|
+
*/
|
|
52
|
+
tools(): Promise<Tool[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Find tools by intent description. Loads tools first if not cached.
|
|
55
|
+
*/
|
|
56
|
+
findTools(intent: string): Promise<Tool[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Execute a specific tool by name. Tool calls are logged on the
|
|
59
|
+
* backend with input + output for billing and audit.
|
|
60
|
+
*/
|
|
61
|
+
execute(toolName: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
62
|
+
/** Run a Complete Loop workflow. */
|
|
63
|
+
loop(config: LoopConfig): Promise<LoopResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Send a natural-language message. Drives a Claude tool-use loop on
|
|
66
|
+
* the backend and returns the full transcript when done.
|
|
67
|
+
*/
|
|
68
|
+
send(message: string): Promise<SendResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Stream a natural-language message. Yields events as the agent
|
|
71
|
+
* runs (assistant text, tool_use, tool_result, done).
|
|
72
|
+
*/
|
|
73
|
+
sendStream(message: string): AsyncIterable<StreamEvent>;
|
|
74
|
+
/**
|
|
75
|
+
* Initiate OAuth flow for a server.
|
|
76
|
+
* @deprecated Not implemented in 0.2.0 — coming in Marco 3.
|
|
77
|
+
*/
|
|
78
|
+
authorize(serverId: string, config?: AuthConfig): Promise<AuthResult>;
|
|
79
|
+
/**
|
|
80
|
+
* List server connections + available tools. Refreshes the internal
|
|
81
|
+
* tools cache as a side effect.
|
|
82
|
+
*/
|
|
83
|
+
connections(): Promise<ServerConnection[]>;
|
|
84
|
+
/** Close session and release resources. */
|
|
85
|
+
close(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export interface Tool {
|
|
88
|
+
/** Tool name (e.g. "codespar_pay") */
|
|
89
|
+
name: string;
|
|
90
|
+
/** Human-readable description shown to LLMs */
|
|
91
|
+
description: string;
|
|
92
|
+
/** JSON Schema for tool inputs */
|
|
93
|
+
input_schema: Record<string, unknown>;
|
|
94
|
+
/** Server that provides this tool (for routing/billing). May be "codespar" for meta-tools. */
|
|
95
|
+
server: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ToolResult {
|
|
98
|
+
/** Whether the call succeeded */
|
|
99
|
+
success: boolean;
|
|
100
|
+
/** Tool output (varies by tool) */
|
|
101
|
+
data: unknown;
|
|
102
|
+
/** Error message if failed */
|
|
103
|
+
error: string | null;
|
|
104
|
+
/** Execution time in ms */
|
|
105
|
+
duration: number;
|
|
106
|
+
/** Server that executed the tool */
|
|
107
|
+
server: string;
|
|
108
|
+
/** Tool that was executed */
|
|
109
|
+
tool: string;
|
|
110
|
+
/** Backend tool-call id for cross-referencing logs */
|
|
111
|
+
tool_call_id?: string;
|
|
112
|
+
/** Timestamp the call was logged */
|
|
113
|
+
called_at?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface LoopStep {
|
|
116
|
+
/** Tool name to execute */
|
|
117
|
+
tool: string;
|
|
118
|
+
/** Tool parameters */
|
|
119
|
+
params: Record<string, unknown> | ((prevResults: ToolResult[]) => Record<string, unknown>);
|
|
120
|
+
/** Optional: skip this step if condition returns false */
|
|
121
|
+
when?: (prevResults: ToolResult[]) => boolean;
|
|
122
|
+
}
|
|
123
|
+
export interface LoopConfig {
|
|
124
|
+
/** Steps to execute in order */
|
|
125
|
+
steps: LoopStep[];
|
|
126
|
+
/** Called after each step completes */
|
|
127
|
+
onStepComplete?: (step: LoopStep, result: ToolResult, index: number) => void;
|
|
128
|
+
/** Called if a step fails */
|
|
129
|
+
onStepError?: (step: LoopStep, error: Error, index: number) => void;
|
|
130
|
+
/** Retry policy for failed steps */
|
|
131
|
+
retryPolicy?: {
|
|
132
|
+
maxRetries?: number;
|
|
133
|
+
backoff?: "linear" | "exponential";
|
|
134
|
+
baseDelay?: number;
|
|
135
|
+
};
|
|
136
|
+
/** Abort all remaining steps on first failure. Default: true */
|
|
137
|
+
abortOnError?: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface LoopResult {
|
|
140
|
+
success: boolean;
|
|
141
|
+
/** Results from each step, in order */
|
|
142
|
+
results: ToolResult[];
|
|
143
|
+
/** Total execution time in ms */
|
|
144
|
+
duration: number;
|
|
145
|
+
/** Number of steps completed */
|
|
146
|
+
completedSteps: number;
|
|
147
|
+
/** Total steps attempted */
|
|
148
|
+
totalSteps: number;
|
|
149
|
+
}
|
|
150
|
+
export interface AuthConfig {
|
|
151
|
+
/** API key for direct auth */
|
|
152
|
+
token?: string;
|
|
153
|
+
/** OAuth2 client credentials */
|
|
154
|
+
clientId?: string;
|
|
155
|
+
clientSecret?: string;
|
|
156
|
+
}
|
|
157
|
+
export interface AuthResult {
|
|
158
|
+
/** Whether auth was successful */
|
|
159
|
+
connected: boolean;
|
|
160
|
+
/** OAuth redirect URL (if OAuth flow required) */
|
|
161
|
+
redirectUrl?: string;
|
|
162
|
+
/** Error message if failed */
|
|
163
|
+
error?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface ServerConnection {
|
|
166
|
+
/** Server id (e.g. "zoop") */
|
|
167
|
+
id: string;
|
|
168
|
+
/** Display name */
|
|
169
|
+
name: string;
|
|
170
|
+
/** Category (payments, fiscal, ecommerce, etc.) */
|
|
171
|
+
category: string;
|
|
172
|
+
/** Country code (BR, MX, AR, CO, GLOBAL) */
|
|
173
|
+
country: string;
|
|
174
|
+
/** Auth method */
|
|
175
|
+
auth_type: "oauth" | "api_key" | "cert" | "none";
|
|
176
|
+
/** Whether the server is connected and tools are callable */
|
|
177
|
+
connected: boolean;
|
|
178
|
+
}
|
|
179
|
+
export interface SendResult {
|
|
180
|
+
/** Final agent message text */
|
|
181
|
+
message: string;
|
|
182
|
+
/** Tools called during the run, in order */
|
|
183
|
+
tool_calls: ToolCallRecord[];
|
|
184
|
+
/** How many model iterations the loop ran */
|
|
185
|
+
iterations: number;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Single tool-call record returned by send / sendStream.
|
|
189
|
+
* Mirrors the backend's session_tool_calls row shape.
|
|
190
|
+
*/
|
|
191
|
+
export interface ToolCallRecord {
|
|
192
|
+
id: string;
|
|
193
|
+
tool_name: string;
|
|
194
|
+
server_id: string;
|
|
195
|
+
status: "success" | "error";
|
|
196
|
+
duration_ms: number;
|
|
197
|
+
input: unknown;
|
|
198
|
+
output: unknown;
|
|
199
|
+
error_code: string | null;
|
|
200
|
+
}
|
|
201
|
+
export type StreamEvent = {
|
|
202
|
+
type: "user_message";
|
|
203
|
+
content: string;
|
|
204
|
+
} | {
|
|
205
|
+
type: "assistant_text";
|
|
206
|
+
content: string;
|
|
207
|
+
iteration: number;
|
|
208
|
+
} | {
|
|
209
|
+
type: "tool_use";
|
|
210
|
+
id: string;
|
|
211
|
+
name: string;
|
|
212
|
+
input: Record<string, unknown>;
|
|
213
|
+
} | {
|
|
214
|
+
type: "tool_result";
|
|
215
|
+
toolCall: ToolCallRecord;
|
|
216
|
+
} | {
|
|
217
|
+
type: "done";
|
|
218
|
+
result: SendResult;
|
|
219
|
+
} | {
|
|
220
|
+
type: "error";
|
|
221
|
+
error: string;
|
|
222
|
+
message?: string;
|
|
223
|
+
};
|
|
224
|
+
export declare const SessionConfigSchema: z.ZodObject<{
|
|
225
|
+
servers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
226
|
+
preset: z.ZodOptional<z.ZodEnum<["brazilian", "mexican", "argentinian", "colombian", "all"]>>;
|
|
227
|
+
manageConnections: z.ZodOptional<z.ZodObject<{
|
|
228
|
+
waitForConnections: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
230
|
+
}, "strip", z.ZodTypeAny, {
|
|
231
|
+
waitForConnections?: boolean | undefined;
|
|
232
|
+
timeout?: number | undefined;
|
|
233
|
+
}, {
|
|
234
|
+
waitForConnections?: boolean | undefined;
|
|
235
|
+
timeout?: number | undefined;
|
|
236
|
+
}>>;
|
|
237
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
servers?: string[] | undefined;
|
|
240
|
+
preset?: "brazilian" | "mexican" | "argentinian" | "colombian" | "all" | undefined;
|
|
241
|
+
manageConnections?: {
|
|
242
|
+
waitForConnections?: boolean | undefined;
|
|
243
|
+
timeout?: number | undefined;
|
|
244
|
+
} | undefined;
|
|
245
|
+
metadata?: Record<string, string> | undefined;
|
|
246
|
+
}, {
|
|
247
|
+
servers?: string[] | undefined;
|
|
248
|
+
preset?: "brazilian" | "mexican" | "argentinian" | "colombian" | "all" | undefined;
|
|
249
|
+
manageConnections?: {
|
|
250
|
+
waitForConnections?: boolean | undefined;
|
|
251
|
+
timeout?: number | undefined;
|
|
252
|
+
} | undefined;
|
|
253
|
+
metadata?: Record<string, string> | undefined;
|
|
254
|
+
}>;
|
|
255
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@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AE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAC9E;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAIvD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU9B,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/* ── Validation schemas ───────────────────────────────────────── */
|
|
3
|
+
export const SessionConfigSchema = z.object({
|
|
4
|
+
servers: z.array(z.string()).optional(),
|
|
5
|
+
preset: z.enum(["brazilian", "mexican", "argentinian", "colombian", "all"]).optional(),
|
|
6
|
+
manageConnections: z
|
|
7
|
+
.object({
|
|
8
|
+
waitForConnections: z.boolean().optional(),
|
|
9
|
+
timeout: z.number().optional(),
|
|
10
|
+
})
|
|
11
|
+
.optional(),
|
|
12
|
+
metadata: z.record(z.string()).optional(),
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqPxB,qEAAqE;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtF,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAC;QACN,kBAAkB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAC1C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC/B,CAAC;SACD,QAAQ,EAAE;IACb,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@codespar/sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Commerce SDK for AI agents — sessions, managed auth, Complete Loop orchestration for Latin American APIs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"ai-agent",
|
|
28
|
+
"commerce",
|
|
29
|
+
"mcp",
|
|
30
|
+
"pix",
|
|
31
|
+
"nfe",
|
|
32
|
+
"latam",
|
|
33
|
+
"sdk",
|
|
34
|
+
"codespar"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/codespar/codespar-core",
|
|
40
|
+
"directory": "packages/core"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://codespar.dev",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/codespar/codespar-core/issues"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"zod": "^3.24.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^25.6.0",
|
|
54
|
+
"typescript": "^5.8.0",
|
|
55
|
+
"vitest": "^3.1.0"
|
|
56
|
+
}
|
|
57
|
+
}
|