Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@codespar/sdk

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codespar/sdk - npm Package Compare versions

Comparing version
0.9.0
to
0.10.0
+10
dist/__tests__/base-url-resolution.test.d.ts
/**
* `CODESPAR_BASE_URL` env-var resolution for the TS client.
*
* The constructor cascade is: explicit `baseUrl` option, then the
* `CODESPAR_BASE_URL` env var, then the production default. The env
* var lets a caller point the same client wiring at a local OSS
* runtime or at `api.codespar.dev` without rebuilding the call sites.
*/
export {};
//# sourceMappingURL=base-url-resolution.test.d.ts.map
{"version":3,"file":"base-url-resolution.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/base-url-resolution.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
/**
* `CODESPAR_BASE_URL` env-var resolution for the TS client.
*
* The constructor cascade is: explicit `baseUrl` option, then the
* `CODESPAR_BASE_URL` env var, then the production default. The env
* var lets a caller point the same client wiring at a local OSS
* runtime or at `api.codespar.dev` without rebuilding the call sites.
*/
import { describe, it, expect } from "vitest";
import { CodeSpar } from "../index.js";
describe("CODESPAR_BASE_URL env-var fallback", () => {
it("uses CODESPAR_BASE_URL when no explicit baseUrl is passed", () => {
const prevBase = process.env.CODESPAR_BASE_URL;
const prevKey = process.env.CODESPAR_API_KEY;
process.env.CODESPAR_BASE_URL = "https://oss.codespar.local";
process.env.CODESPAR_API_KEY = "csk_live_test";
try {
const cs = new CodeSpar();
// baseUrl is private; the smoke test is that construction
// succeeds and the default does NOT override an env override.
// The behavior is exercised via createSession's URL prefix in
// the integration tests.
expect(cs).toBeDefined();
}
finally {
if (prevBase === undefined)
delete process.env.CODESPAR_BASE_URL;
else
process.env.CODESPAR_BASE_URL = prevBase;
if (prevKey === undefined)
delete process.env.CODESPAR_API_KEY;
else
process.env.CODESPAR_API_KEY = prevKey;
}
});
it("explicit baseUrl wins over CODESPAR_BASE_URL env var", () => {
const prev = process.env.CODESPAR_BASE_URL;
process.env.CODESPAR_BASE_URL = "https://oss.codespar.local";
try {
const cs = new CodeSpar({
apiKey: "csk_live_x",
baseUrl: "https://override.example.com",
});
// Smoke — construction succeeds with both set. The wire-level
// behavior is covered by createSession tests that fetch-mock
// the URL prefix directly.
expect(cs).toBeDefined();
}
finally {
if (prev === undefined)
delete process.env.CODESPAR_BASE_URL;
else
process.env.CODESPAR_BASE_URL = prev;
}
});
});
//# sourceMappingURL=base-url-resolution.test.js.map
{"version":3,"file":"base-url-resolution.test.js","sourceRoot":"","sources":["../../src/__tests__/base-url-resolution.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAClD,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,4BAA4B,CAAC;QAC7D,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAC/C,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC1B,0DAA0D;YAC1D,8DAA8D;YAC9D,8DAA8D;YAC9D,yBAAyB;YACzB,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;;gBAC5D,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,QAAQ,CAAC;YAC9C,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;;gBAC1D,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,4BAA4B,CAAC;QAC7D,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC;gBACtB,MAAM,EAAE,YAAY;gBACpB,OAAO,EAAE,8BAA8B;aACxC,CAAC,CAAC;YACH,8DAA8D;YAC9D,6DAA6D;YAC7D,2BAA2B;YAC3B,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,IAAI,IAAI,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;;gBACxD,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC5C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
/**
* Tests for CodesparApiError + the throwFromResponse helper that
* collapses all transport-failure throw sites in session.ts.
*
* Asserts:
* - Every transport throw site surfaces a CodesparApiError (not
* a plain Error) carrying status + code + body.
* - Network errors wrap fetch rejections into CodesparApiError
* with status: 0 and preserve the underlying cause.
* - The session.execute non-ok branch is untouched — it still
* returns ToolResult.success === false rather than throwing.
* - instanceof CodesparApiError works across realms (prototype
* chain is restored via Object.setPrototypeOf).
*/
export {};
//# sourceMappingURL=errors.test.d.ts.map
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/errors.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
/**
* Tests for CodesparApiError + the throwFromResponse helper that
* collapses all transport-failure throw sites in session.ts.
*
* Asserts:
* - Every transport throw site surfaces a CodesparApiError (not
* a plain Error) carrying status + code + body.
* - Network errors wrap fetch rejections into CodesparApiError
* with status: 0 and preserve the underlying cause.
* - The session.execute non-ok branch is untouched — it still
* returns ToolResult.success === false rather than throwing.
* - instanceof CodesparApiError works across realms (prototype
* chain is restored via Object.setPrototypeOf).
*/
import { describe, it, expect, vi, afterEach } from "vitest";
import { CodesparApiError } from "../errors.js";
import { CodeSpar } from "../index.js";
describe("CodesparApiError", () => {
it("constructs with status + message", () => {
const err = new CodesparApiError("boom", { status: 500 });
expect(err.status).toBe(500);
expect(err.message).toBe("boom");
expect(err.code).toBeUndefined();
expect(err.body).toBeUndefined();
});
it("carries the structured code + body + cause", () => {
const cause = new Error("underlying");
const err = new CodesparApiError("boom", {
status: 403,
code: "mocks_not_permitted",
body: { error: "mocks_not_permitted", message: "test mode key required" },
cause,
});
expect(err.status).toBe(403);
expect(err.code).toBe("mocks_not_permitted");
expect(err.body).toEqual({
error: "mocks_not_permitted",
message: "test mode key required",
});
expect(err.cause).toBe(cause);
});
it("instanceof CodesparApiError works after prototype-chain repair", () => {
const err = new CodesparApiError("x", { status: 1 });
expect(err instanceof CodesparApiError).toBe(true);
expect(err instanceof Error).toBe(true);
expect(err.name).toBe("CodesparApiError");
});
});
describe("session transport-failure call sites throw CodesparApiError", () => {
const originalFetch = globalThis.fetch;
afterEach(() => {
globalThis.fetch = originalFetch;
});
it("createSession throws CodesparApiError on 4xx with structured body", async () => {
globalThis.fetch = vi.fn().mockResolvedValue({
ok: false,
status: 403,
text: async () => JSON.stringify({
error: "mocks_not_permitted",
message: "csk_test_* key required",
}),
});
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
try {
await cs.create("user_42");
expect.fail("expected createSession to throw");
}
catch (err) {
expect(err).toBeInstanceOf(CodesparApiError);
const apiErr = err;
expect(apiErr.status).toBe(403);
expect(apiErr.code).toBe("mocks_not_permitted");
}
});
it("createSession wraps fetch rejection as CodesparApiError status 0", async () => {
const underlying = new TypeError("Network failure");
globalThis.fetch = vi
.fn()
.mockRejectedValue(underlying);
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
try {
await cs.create("user_42");
expect.fail("expected createSession to throw");
}
catch (err) {
expect(err).toBeInstanceOf(CodesparApiError);
const apiErr = err;
expect(apiErr.status).toBe(0);
expect(apiErr.cause).toBe(underlying);
}
});
it("send throws CodesparApiError on 5xx", async () => {
const sessionCreate = {
ok: true,
status: 201,
text: async () => "",
json: async () => ({
id: "ses_err",
org_id: "o",
user_id: "u",
servers: [],
status: "active",
created_at: new Date().toISOString(),
closed_at: null,
}),
};
const sendFail = {
ok: false,
status: 502,
text: async () => JSON.stringify({ code: "upstream_unavailable" }),
};
globalThis.fetch = vi
.fn()
.mockResolvedValueOnce(sessionCreate)
.mockResolvedValueOnce(sendFail);
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
const session = await cs.create("u");
await expect(session.send("hi")).rejects.toBeInstanceOf(CodesparApiError);
});
it("session.execute does NOT throw on non-ok — returns ToolResult.success=false", async () => {
const sessionCreate = {
ok: true,
status: 201,
text: async () => "",
json: async () => ({
id: "ses_ok",
org_id: "o",
user_id: "u",
servers: [],
status: "active",
created_at: new Date().toISOString(),
closed_at: null,
}),
};
const execFail = {
ok: false,
status: 422,
text: async () => "validation failed",
};
globalThis.fetch = vi
.fn()
.mockResolvedValueOnce(sessionCreate)
.mockResolvedValueOnce(execFail);
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
const session = await cs.create("u");
const result = await session.execute("asaas/create_payment", {});
expect(result.success).toBe(false);
expect(result.error).toContain("422");
});
});
//# sourceMappingURL=errors.test.js.map
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../src/__tests__/errors.test.ts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EAAE,EAAE,IAAI;YACR,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE;YACpB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;gBACjB,EAAE,EAAE,QAAQ;gBACZ,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,GAAG;gBACZ,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,QAAQ;gBAChB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACpC,SAAS,EAAE,IAAI;aAChB,CAAC;SACH,CAAC;QACF,MAAM,QAAQ,GAAG;YACf,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,mBAAmB;SACtC,CAAC;QACF,UAAU,CAAC,KAAK,GAAG,EAAE;aAClB,EAAE,EAAE;aACJ,qBAAqB,CAAC,aAAa,CAAC;aACpC,qBAAqB,CAAC,QAAQ,CAA4B,CAAC;QAE9D,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC;YACtB,MAAM,EAAE,eAAe;YACvB,OAAO,EAAE,yBAAyB;SACnC,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;QACjE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
/**
* Tests for the createSession body builder's `mocks` forwarding.
*
* Asserts:
* - Wire-neutrality: a cs.create without `mocks` produces a body
* byte-identical to today's shape (R18).
* - Forwarded shape: a cs.create with `mocks` includes the field
* verbatim — no SDK-side rewriting of canonical names.
* - Empty `mocks: {}` is forwarded (the backend accepts; strict-
* mode R3a activates only on non-empty maps).
* - Double-underscore key form reaches the backend unrewritten
* so the canonical-form rejection surfaces at the right layer.
*/
export {};
//# sourceMappingURL=forward-mocks.test.d.ts.map
{"version":3,"file":"forward-mocks.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/forward-mocks.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
/**
* Tests for the createSession body builder's `mocks` forwarding.
*
* Asserts:
* - Wire-neutrality: a cs.create without `mocks` produces a body
* byte-identical to today's shape (R18).
* - Forwarded shape: a cs.create with `mocks` includes the field
* verbatim — no SDK-side rewriting of canonical names.
* - Empty `mocks: {}` is forwarded (the backend accepts; strict-
* mode R3a activates only on non-empty maps).
* - Double-underscore key form reaches the backend unrewritten
* so the canonical-form rejection surfaces at the right layer.
*/
import { describe, it, expect, vi, afterEach } from "vitest";
import { CodeSpar } from "../index.js";
function mockSessionResponse() {
return {
ok: true,
status: 201,
text: async () => "",
json: async () => ({
id: "ses_demo",
org_id: "org_demo",
user_id: "user_demo",
servers: ["asaas"],
status: "active",
created_at: new Date().toISOString(),
closed_at: null,
}),
};
}
describe("createSession body builder forwards mocks", () => {
const originalFetch = globalThis.fetch;
afterEach(() => {
globalThis.fetch = originalFetch;
});
it("omits mocks key from the wire body when undefined (R18 wire-neutral)", async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce(mockSessionResponse());
globalThis.fetch = fetchMock;
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
await cs.create("user_demo", { servers: ["asaas"] });
const init = fetchMock.mock
.calls[0][1];
const body = JSON.parse(init.body);
expect("mocks" in body).toBe(false);
expect(body).toEqual({ servers: ["asaas"], user_id: "user_demo" });
});
it("forwards mocks verbatim when present", async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce(mockSessionResponse());
globalThis.fetch = fetchMock;
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
await cs.create("user_demo", {
servers: ["asaas"],
mocks: {
"asaas/create_payment": { id: "pay_test_42", status: "PENDING" },
},
});
const init = fetchMock.mock
.calls[0][1];
const body = JSON.parse(init.body);
expect(body.mocks).toEqual({
"asaas/create_payment": { id: "pay_test_42", status: "PENDING" },
});
});
it("accepts and forwards an empty mocks={} body", async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce(mockSessionResponse());
globalThis.fetch = fetchMock;
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
await cs.create("user_demo", { servers: ["asaas"], mocks: {} });
const init = fetchMock.mock
.calls[0][1];
const body = JSON.parse(init.body);
expect(body.mocks).toEqual({});
});
it("does NOT rewrite double-underscore keys — they reach the backend verbatim", async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce(mockSessionResponse());
globalThis.fetch = fetchMock;
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
await cs.create("user_demo", {
servers: ["asaas"],
mocks: { asaas__create_payment: { id: "pay_test_42" } },
});
const init = fetchMock.mock
.calls[0][1];
const body = JSON.parse(init.body);
const mocks = body.mocks;
expect(Object.keys(mocks)).toEqual(["asaas__create_payment"]);
});
it("matches the canonical fixture byte-for-byte when the same input lands", async () => {
// Same canonical body used by the Python parity test.
const fetchMock = vi
.fn()
.mockResolvedValueOnce(mockSessionResponse());
globalThis.fetch = fetchMock;
const cs = new CodeSpar({
apiKey: "csk_live_test",
baseUrl: "https://api.example.com",
});
await cs.create("user_demo", {
servers: ["asaas"],
mocks: {
"asaas/create_payment": { id: "pay_test_42", status: "PENDING" },
"asaas/get_payment": [
{ id: "pay_test_42", status: "PENDING" },
{ id: "pay_test_42", status: "CONFIRMED" },
],
},
});
const init = fetchMock.mock
.calls[0][1];
expect(init.body).toBe('{"servers":["asaas"],"user_id":"user_demo","mocks":{"asaas/create_payment":{"id":"pay_test_42","status":"PENDING"},"asaas/get_payment":[{"id":"pay_test_42","status":"PENDING"},{"id":"pay_test_42","status":"CONFIRMED"}]}}');
});
});
//# sourceMappingURL=forward-mocks.test.js.map
{"version":3,"file":"forward-mocks.test.js","sourceRoot":"","sources":["../../src/__tests__/forward-mocks.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,SAAS,mBAAmB;IAC1B,OAAO;QACL,EAAE,EAAE,IAAI;QACR,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE;QACpB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACjB,EAAE,EAAE,UAAU;YACd,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,QAAiB;YACzB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,SAAS,EAAE,IAAI;SAChB,CAAC;KACH,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACzD,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;IACvC,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,KAAK,GAAG,aAAa,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,SAAS,GAAG,EAAE;aACjB,EAAE,EAAE;aACJ,qBAAqB,CAAC,mBAAmB,EAAE,CAA4B,CAAC;QAC3E,UAAU,CAAC,KAAK,GAAG,SAAoC,CAAC;QAExD,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC;YACtB,MAAM,EAAE,eAAe;YACvB,OAAO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E,CAAC,CAAC,CAAqB,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CACpB,8NAA8N,CAC/N,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
/**
* Wire-shape parity test for the test-mode mocks field.
*
* Asserts that the TypeScript SessionConfig type carries the optional
* `mocks` field with the right shape, and that the serialized form
* matches the canonical fixture used by the Python SDK's parallel
* test. Both languages serialize the same example to byte-identical
* JSON; any drift here is a wire-contract break.
*
* The canonical fixture lives at packages/python/tests/_fixtures/
* mocks_canonical.json — kept in sync by hand. Future contributors
* MUST update both files together when extending the example.
*/
export {};
//# sourceMappingURL=mocks-wire-parity.test.d.ts.map
{"version":3,"file":"mocks-wire-parity.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/mocks-wire-parity.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
/**
* Wire-shape parity test for the test-mode mocks field.
*
* Asserts that the TypeScript SessionConfig type carries the optional
* `mocks` field with the right shape, and that the serialized form
* matches the canonical fixture used by the Python SDK's parallel
* test. Both languages serialize the same example to byte-identical
* JSON; any drift here is a wire-contract break.
*
* The canonical fixture lives at packages/python/tests/_fixtures/
* mocks_canonical.json — kept in sync by hand. Future contributors
* MUST update both files together when extending the example.
*/
import { describe, it, expect } from "vitest";
const CANONICAL_BODY = {
servers: ["asaas"],
user_id: "user_demo",
mocks: {
"asaas/create_payment": { id: "pay_test_42", status: "PENDING" },
"asaas/get_payment": [
{ id: "pay_test_42", status: "PENDING" },
{ id: "pay_test_42", status: "CONFIRMED" },
],
},
};
describe("MockObject + MockValue type aliases", () => {
it("accepts a plain dict as MockObject", () => {
const obj = { id: "pay_test_42", status: "PENDING" };
expect(obj.id).toBe("pay_test_42");
});
it("accepts a single MockObject as MockValue (static mock)", () => {
const v = { id: "pay_test_42", status: "PENDING" };
expect(v).toBeDefined();
});
it("accepts a MockObject array as MockValue (stateful mock)", () => {
const v = [
{ id: "pay_test_42", status: "PENDING" },
{ id: "pay_test_42", status: "CONFIRMED" },
];
expect(Array.isArray(v)).toBe(true);
});
});
describe("CreateSessionOptions carries optional mocks field", () => {
it("accepts a SessionConfig with no mocks (wire-neutral)", () => {
const cfg = { servers: ["asaas"] };
expect(cfg.mocks).toBeUndefined();
});
it("accepts a SessionConfig with canonical mocks shape", () => {
const cfg = {
servers: ["asaas"],
mocks: {
"asaas/create_payment": { id: "pay_test_42", status: "PENDING" },
"asaas/get_payment": [
{ id: "pay_test_42", status: "PENDING" },
{ id: "pay_test_42", status: "CONFIRMED" },
],
},
};
expect(cfg.mocks?.["asaas/create_payment"]).toBeDefined();
});
});
describe("Canonical body serializes to byte-identical JSON", () => {
it("matches the Python SDK fixture byte-for-byte", () => {
// The canonical body field order is preserved by the JSON.stringify
// contract used in createSession's body builder. If field ordering
// changes here, the Python side must change too.
const serialized = JSON.stringify(CANONICAL_BODY);
expect(serialized).toBe('{"servers":["asaas"],"user_id":"user_demo","mocks":{"asaas/create_payment":{"id":"pay_test_42","status":"PENDING"},"asaas/get_payment":[{"id":"pay_test_42","status":"PENDING"},{"id":"pay_test_42","status":"CONFIRMED"}]}}');
});
});
//# sourceMappingURL=mocks-wire-parity.test.js.map
{"version":3,"file":"mocks-wire-parity.test.js","sourceRoot":"","sources":["../../src/__tests__/mocks-wire-parity.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI9C,MAAM,cAAc,GAAG;IACrB,OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE;QACL,sBAAsB,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;QAChE,mBAAmB,EAAE;YACnB,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;YACxC,EAAE,EAAE,EA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EAAE,CAAC,OAAO,CAAC;YAClB,KAAK,EAAE;gBACL,sBAAsB,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;gBAChE,mBAAmB,EAAE;oBACnB,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;oBACxC,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE;iBAC3C;aACF;SACF,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAChE,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,oEAAoE;QACpE,mEAAmE;QACnE,iDAAiD;QACjD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAClD,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CACrB,8NAA8N,CAC/N,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
export {};
//# sourceMappingURL=testing.test.d.ts.map
{"version":3,"file":"testing.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/testing.test.ts"],"names":[],"mappings":""}
import { describe, it, expect } from "vitest";
import { fakeSession } from "../testing/index.js";
describe("@codespar/sdk/testing — exported surface", () => {
it("exports fakeSession and the ToolResult type from a single import", () => {
expect(typeof fakeSession).toBe("function");
// ToolResult is a type-only re-export; the assertion below proves it
// is usable in a value position via a typed identity function.
const passthrough = (r) => r;
const sample = {
success: true,
data: {},
error: null,
duration: 0,
server: "",
tool: "x",
};
expect(passthrough(sample)).toBe(sample);
});
});
describe("fakeSession — strict mode (default)", () => {
it("throws verbatim 'fakeSession: no response registered for tool <name>' on miss", async () => {
const session = fakeSession();
await expect(session.execute("asaas/create_payment", { value: 100 })).rejects.toThrow("fakeSession: no response registered for tool asaas/create_payment");
});
it("error message is byte-identical to the contract string", async () => {
const session = fakeSession();
let captured = null;
try {
await session.execute("foo/bar", {});
}
catch (err) {
captured = err;
}
expect(captured).toBeInstanceOf(Error);
expect(captured.message).toBe("fakeSession: no response registered for tool foo/bar");
});
});
describe("fakeSession — registered responses", () => {
it("returns the static ToolResult registered for a tool name", async () => {
const session = fakeSession({
"asaas/create_customer": {
success: true,
data: { id: "cus_test_1", name: "Maria" },
error: null,
duration: 0,
server: "asaas",
tool: "asaas/create_customer",
},
});
const result = await session.execute("asaas/create_customer", { name: "Maria" });
expect(result.success).toBe(true);
expect(result.data).toEqual({ id: "cus_test_1", name: "Maria" });
expect(result.tool).toBe("asaas/create_customer");
});
});
describe("fakeSession — per-tool function variant", () => {
it("invokes a sync response function with the call's params and returns its result", async () => {
const session = fakeSession({
"asaas/create_customer": (input) => ({
success: true,
data: { echoed: input },
error: null,
duration: 0,
server: "asaas",
tool: "asaas/create_customer",
}),
});
const result = await session.execute("asaas/create_customer", { name: "Joana" });
expect(result.data).toEqual({ echoed: { name: "Joana" } });
});
it("awaits a Promise-returning response function", async () => {
const session = fakeSession({
"asaas/create_customer": async (input) => ({
success: true,
data: { async_echoed: input },
error: null,
duration: 0,
server: "asaas",
tool: "asaas/create_customer",
}),
});
const result = await session.execute("asaas/create_customer", { name: "Joana" });
expect(result.data).toEqual({ async_echoed: { name: "Joana" } });
});
});
describe("fakeSession — lenient mode", () => {
it("returns {success:true, data:{}} for unregistered tools when lenient: true", async () => {
const session = fakeSession({}, { lenient: true });
const result = await session.execute("asaas/create_payment", { value: 100 });
expect(result.success).toBe(true);
expect(result.data).toEqual({});
expect(result.error).toBeNull();
expect(result.tool).toBe("asaas/create_payment");
});
it("does not override a registered failure response in lenient mode", async () => {
const session = fakeSession({
"asaas/create_payment": {
success: false,
data: null,
error: "boom",
duration: 0,
server: "asaas",
tool: "asaas/create_payment",
},
}, { lenient: true });
const result = await session.execute("asaas/create_payment", { value: 100 });
expect(result.success).toBe(false);
expect(result.error).toBe("boom");
});
});
describe("fakeSession — Session interface conformance", () => {
it("returns a value assignable to Session without casts", () => {
// Compile-time check: the literal annotation forces structural conformance.
// If this file compiles, the conformance check has passed.
const session = fakeSession();
expect(typeof session.execute).toBe("function");
expect(typeof session.send).toBe("function");
expect(typeof session.sendStream).toBe("function");
expect(typeof session.proxyExecute).toBe("function");
expect(typeof session.authorize).toBe("function");
expect(typeof session.connections).toBe("function");
expect(typeof session.close).toBe("function");
expect(typeof session.discover).toBe("function");
expect(typeof session.connectionWizard).toBe("function");
expect(typeof session.charge).toBe("function");
expect(typeof session.ship).toBe("function");
expect(typeof session.paymentStatus).toBe("function");
expect(typeof session.paymentStatusStream).toBe("function");
expect(typeof session.verificationStatus).toBe("function");
expect(typeof session.verificationStatusStream).toBe("function");
});
});
//# sourceMappingURL=testing.test.js.map
{"version":3,"file":"testing.test.js","sourceRoot":"","sources":["../../src/__tests__/testing.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AAGnE,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5C,qEAAqE;QACrE,+DAA+D;QAC/D,MAAM,WAAW,GAAG,CAAC,CAAa,EAAc,EAAE,CAAC,CAAC,CAAC;QACrD,MAAM,MAAM,GAAe;YACzB,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,GAAG;SACV,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC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AAC,UAAU,CAAC,CAAC;QACpD,MAAM,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,CAAC,OAAO,OAAO,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzD,MAAM,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7C,MAAM,CAAC,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtD,MAAM,CAAC,OAAO,OAAO,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,CAAC,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
/**
* Tool-result code guard tests.
*
* Asserts:
* - Positive + negative paths per guard.
* - Sibling-field-missing fixtures — a well-formed `code` with
* missing required siblings (e.g. `rule_id` for policy_denied)
* returns false. The guard does not narrow on the discriminant
* alone.
* - Unknown-code defense-in-depth — an unknown `code` value never
* narrows positive on any guard.
* - assertExhaustiveToolResult compiles when every variant is
* handled (the test below is the compile-time witness).
* - output.code vs error_code disagreement — guards key on the
* `code` field on the payload, ignoring sibling discrepancies.
*/
export {};
//# sourceMappingURL=tool-result-codes.test.d.ts.map
{"version":3,"file":"tool-result-codes.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/tool-result-codes.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
/**
* Tool-result code guard tests.
*
* Asserts:
* - Positive + negative paths per guard.
* - Sibling-field-missing fixtures — a well-formed `code` with
* missing required siblings (e.g. `rule_id` for policy_denied)
* returns false. The guard does not narrow on the discriminant
* alone.
* - Unknown-code defense-in-depth — an unknown `code` value never
* narrows positive on any guard.
* - assertExhaustiveToolResult compiles when every variant is
* handled (the test below is the compile-time witness).
* - output.code vs error_code disagreement — guards key on the
* `code` field on the payload, ignoring sibling discrepancies.
*/
import { describe, it, expect } from "vitest";
import { TOOL_RESULT_CODES, ToolResultCode, assertExhaustiveToolResult, isApprovalRequired, isMocksEngineError, isMocksExhausted, isPolicyDenied, isToolNotMocked, } from "../tool-result-codes.js";
describe("TOOL_RESULT_CODES set", () => {
it("includes the five canonical codes", () => {
expect(TOOL_RESULT_CODES).toContain("policy_denied");
expect(TOOL_RESULT_CODES).toContain("approval_required");
expect(TOOL_RESULT_CODES).toContain("mocks_exhausted");
expect(TOOL_RESULT_CODES).toContain("mocks_engine_error");
expect(TOOL_RESULT_CODES).toContain("tool_not_mocked");
});
});
describe("isPolicyDenied", () => {
it("returns true for a well-formed policy_denied output", () => {
const out = {
code: ToolResultCode.PolicyDenied,
rule_id: "spend_cap",
message: "exceeds tenant cap",
};
expect(isPolicyDenied(out)).toBe(true);
});
it("returns false when rule_id is missing", () => {
const out = {
code: ToolResultCode.PolicyDenied,
message: "missing rule",
};
expect(isPolicyDenied(out)).toBe(false);
});
it("returns false when message is missing", () => {
const out = {
code: ToolResultCode.PolicyDenied,
rule_id: "spend_cap",
};
expect(isPolicyDenied(out)).toBe(false);
});
it("returns false on a foreign discriminant", () => {
const out = {
code: "approval_required",
rule_id: "x",
message: "y",
};
expect(isPolicyDenied(out)).toBe(false);
});
it("returns false on an unknown code (defense in depth)", () => {
const out = {
code: "totally_made_up",
rule_id: "x",
message: "y",
};
expect(isPolicyDenied(out)).toBe(false);
});
it("returns false on null/undefined/non-object", () => {
expect(isPolicyDenied(null)).toBe(false);
expect(isPolicyDenied(undefined)).toBe(false);
expect(isPolicyDenied("policy_denied")).toBe(false);
});
});
describe("isApprovalRequired", () => {
it("returns true for a well-formed approval_required output", () => {
const out = {
code: ToolResultCode.ApprovalRequired,
approval_id: "apr_abc",
expires_at: "2026-12-01T00:00:00Z",
message: "approve the transfer",
};
expect(isApprovalRequired(out)).toBe(true);
});
it("returns false when approval_id is missing", () => {
const out = {
code: ToolResultCode.ApprovalRequired,
expires_at: "2026-12-01T00:00:00Z",
message: "x",
};
expect(isApprovalRequired(out)).toBe(false);
});
it("returns false when expires_at is missing", () => {
const out = {
code: ToolResultCode.ApprovalRequired,
approval_id: "apr_abc",
message: "x",
};
expect(isApprovalRequired(out)).toBe(false);
});
it("returns false when message is missing", () => {
const out = {
code: ToolResultCode.ApprovalRequired,
approval_id: "apr_abc",
expires_at: "x",
};
expect(isApprovalRequired(out)).toBe(false);
});
});
describe("isMocksExhausted and isMocksEngineError", () => {
it("isMocksExhausted: positive + sibling-missing", () => {
expect(isMocksExhausted({ code: ToolResultCode.MocksExhausted, message: "drained" })).toBe(true);
expect(isMocksExhausted({ code: ToolResultCode.MocksExhausted })).toBe(false);
});
it("isMocksEngineError: positive + sibling-missing", () => {
expect(isMocksEngineError({
code: ToolResultCode.MocksEngineError,
message: "consume failed",
})).toBe(true);
expect(isMocksEngineError({ code: ToolResultCode.MocksEngineError })).toBe(false);
});
});
describe("isToolNotMocked", () => {
it("returns true with tool_name + message", () => {
expect(isToolNotMocked({
code: ToolResultCode.ToolNotMocked,
tool_name: "asaas/create_payment",
message: "not in mocks map",
})).toBe(true);
});
it("returns false when tool_name is missing", () => {
expect(isToolNotMocked({ code: ToolResultCode.ToolNotMocked, message: "x" })).toBe(false);
});
});
describe("assertExhaustiveToolResult", () => {
it("compiles when every code variant is handled", () => {
// The test BODY here is the compile-time witness; runtime asserts
// the unreachable-default branch throws on a hostile cast.
function describe(value) {
switch (value.code) {
case ToolResultCode.PolicyDenied:
return "denied";
case ToolResultCode.ApprovalRequired:
return "approval";
case ToolResultCode.MocksExhausted:
return "exhausted";
case ToolResultCode.MocksEngineError:
return "engine";
case ToolResultCode.ToolNotMocked:
return "not_mocked";
default:
// If a 6th code lands without this branch being updated, TS
// fails: assertExhaustiveToolResult(value) would error at
// compile time on a non-never argument.
return assertExhaustiveToolResult(value);
}
}
expect(describe({
code: ToolResultCode.PolicyDenied,
rule_id: "x",
message: "y",
})).toBe("denied");
expect(() => assertExhaustiveToolResult({ code: "rogue" })).toThrow(/tool-result-codes/i);
});
});
//# sourceMappingURL=tool-result-codes.test.js.map
{"version":3,"file":"tool-result-codes.test.js","sourceRoot":"","sources":["../../src/__tests__/tool-result-codes.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,eAAe,GAEhB,MAAM,yBAAyB,CAAC;AAEjC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACrD,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QACvD,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC1D,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAA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AC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjB,MAAM,CAAC,GAAG,EAAE,CACV,0BAA0B,CAAC,EAAE,IAAI,EAAE,OAAgB,EAAW,CAAC,CAChE,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
/**
* Structured exception for every transport-failure path through the
* SDK. Replaces the old `throw new Error("send failed: 500 ...")`
* shape, so callers can branch on `e.code` rather than parsing
* `e.message` strings.
*
* The reserved code namespace covers the hosted-test-mode wire
* contract (tool-result codes + create-time envelope codes —
* see the README's "Reserved error codes" section). Customers
* extending CodesparApiError should prefix their own codes (e.g.
* `"myapp.policy_denied"`) to avoid collision with reserved values.
*
* `status: 0` is reserved for network errors that never reached the
* backend; the underlying `cause` carries the original `TypeError`
* or `DOMException` that `fetch` rejected with.
*/
export interface CodesparApiErrorOptions {
status: number;
code?: string;
body?: unknown;
cause?: unknown;
}
export declare class CodesparApiError extends Error {
readonly status: number;
readonly code?: string;
readonly body?: unknown;
constructor(message: string, options: CodesparApiErrorOptions);
}
/**
* Build the canonical error message + extract the structured code +
* preserve the parsed body. Centralised so every transport call site
* surfaces the same shape — a customer parsing `e.message` is
* already on the deprecated path; new code branches on `e.code`.
*/
export declare function throwFromResponse(response: Response, what: string): Promise<never>;
/**
* Convert a `fetch` rejection (network error, abort, DNS, TLS, etc.)
* into a CodesparApiError with `status: 0`. Preserves the underlying
* error as `cause` so callers debugging a transport failure can dig
* into the original `TypeError`.
*/
export declare function networkErrorToApiError(cause: unknown, what: string): CodesparApiError;
//# sourceMappingURL=errors.d.ts.map
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB;CAY9D;AAkCD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,CAAC,CAehB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAMrF"}
export class CodesparApiError extends Error {
status;
code;
body;
constructor(message, options) {
// ES2022 `cause` shape — supported by Node 20 + modern browsers.
super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
// Restore the prototype chain — without this, `instanceof
// CodesparApiError` returns false across some transpilers and
// realms (the classic ES5-target Error subclass trap).
Object.setPrototypeOf(this, CodesparApiError.prototype);
this.name = "CodesparApiError";
this.status = options.status;
this.code = options.code;
this.body = options.body;
}
}
function parseErrorPayload(raw) {
if (!raw)
return { body: undefined, parsed: {} };
try {
const body = JSON.parse(raw);
if (body && typeof body === "object" && !Array.isArray(body)) {
const obj = body;
const code = typeof obj.code === "string" ? obj.code : undefined;
// Legacy fallback: pre-PRD envelopes used `error` as the
// discriminant. `code` takes precedence; `error` honored only
// when `code` is missing.
const fallbackCode = code ?? (typeof obj.error === "string" ? obj.error : undefined);
const message = typeof obj.message === "string" ? obj.message : undefined;
return {
body,
parsed: { code: fallbackCode, message },
};
}
return { body, parsed: {} };
}
catch {
return { body: raw, parsed: {} };
}
}
/**
* Build the canonical error message + extract the structured code +
* preserve the parsed body. Centralised so every transport call site
* surfaces the same shape — a customer parsing `e.message` is
* already on the deprecated path; new code branches on `e.code`.
*/
export async function throwFromResponse(response, what) {
const raw = await response.text();
const { body, parsed } = parseErrorPayload(raw);
const suffix = parsed.message
? ` — ${parsed.message}`
: parsed.code
? ` — ${parsed.code}`
: raw
? ` ${raw}`
: "";
throw new CodesparApiError(`${what} failed: ${response.status}${suffix}`, {
status: response.status,
code: parsed.code,
body,
});
}
/**
* Convert a `fetch` rejection (network error, abort, DNS, TLS, etc.)
* into a CodesparApiError with `status: 0`. Preserves the underlying
* error as `cause` so callers debugging a transport failure can dig
* into the original `TypeError`.
*/
export function networkErrorToApiError(cause, what) {
const message = cause instanceof Error ? cause.message : String(cause);
return new CodesparApiError(`${what} network error: ${message}`, {
status: 0,
cause,
});
}
//# sourceMappingURL=errors.js.map
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAuBA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,MAAM,CAAS;IACf,IAAI,CAAU;IACd,IAAI,CAAW;IAExB,YAAY,OAAe,EAAE,OAAgC;QAC3D,iEAAiE;QACjE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACnF,0DAA0D;QAC1D,8DAA8D;QAC9D,uDAAuD;QACvD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF;AAOD,SAAS,iBAAiB,CAAC,GAAW;IAIpC,IAAI,CAAC,GAAG;QAAE,OAAO,E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AAiB,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;QAC3B,CAAC,CAAC,MAAM,MAAM,CAAC,OAAO,EAAE;QACxB,CAAC,CAAC,MAAM,CAAC,IAAI;YACX,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE;YACrB,CAAC,CAAC,GAAG;gBACH,CAAC,CAAC,IAAI,GAAG,EAAE;gBACX,CAAC,CAAC,EAAE,CAAC;IACX,MAAM,IAAI,gBAAgB,CAAC,GAAG,IAAI,YAAY,QAAQ,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE;QACxE,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI;KACL,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc,EAAE,IAAY;IACjE,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,IAAI,gBAAgB,CAAC,GAAG,IAAI,mBAAmB,OAAO,EAAE,EAAE;QAC/D,MAAM,EAAE,CAAC;QACT,KAAK;KACN,CAAC,CAAC;AACL,CAAC"}
import type { Session, ToolResult } from "@codespar/types";
export type { ToolResult };
export interface FakeSessionOptions {
/** When true, unregistered tool names resolve to {success:true,data:{}} instead of throwing. */
lenient?: boolean;
}
type FakeSessionResponse = ToolResult | ((input: Record<string, unknown>) => ToolResult | Promise<ToolResult>);
export declare function fakeSession(responses?: Record<string, FakeSessionResponse>, options?: FakeSessionOptions): Session;
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE3D,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,MAAM,WAAW,kBAAkB;IACjC,gGAAgG;IAChG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,mBAAmB,GACpB,UAAU,GACV,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;AAE3E,wBAAgB,WAAW,CACzB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAM,EACnD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CA+ET"}
// fakeSession v1 covers execute()-driven flows. send(), sendStream(),
// and channel mocking land when Layer 3 demos demand them.
export function fakeSession(responses = {}, options = {}) {
const session = {
id: "ses_fake",
status: "active",
mcp: { url: "https://example.invalid/mcp", headers: {} },
async execute(toolName, params) {
void params;
const entry = responses[toolName];
if (entry === undefined) {
if (options.lenient) {
return { success: true, data: {}, error: null, duration: 0, server: "", tool: toolName };
}
throw new Error(`fakeSession: no response registered for tool ${toolName}`);
}
return typeof entry === "function" ? await entry(params) : entry;
},
async send() {
return { message: "", tool_calls: [], iterations: 0 };
},
async *sendStream() {
// intentionally empty — fakeSession v1 does not synthesize stream events
},
async proxyExecute() {
return { status: 200, data: null, headers: {}, duration: 0 };
},
async authorize() {
return {
linkToken: "tok_test",
authorizeUrl: "https://provider.example.com/authorize",
expiresAt: new Date(Date.now() + 600_000).toISOString(),
};
},
async connections() {
return [];
},
async close() {
// noop
},
async discover(useCase) {
return { use_case: useCase, search_strategy: "empty", recommended: null, related: [], next_steps: [] };
},
async connectionWizard(opts) {
return { action: opts.action ?? "list", connections: [], status: null, initiate: null };
},
async charge(args) {
return { id: "chg_fake", status: "pending", amount: args.amount, currency: args.currency, method: args.method };
},
async ship(args) {
return { id: "shp_fake", status: args.action === "track" ? "in_transit" : "created" };
},
async paymentStatus(toolCallId) {
return { tool_call_id: toolCallId, payment_status: "pending", idempotency_key: null, original_status: "success", events: [] };
},
async paymentStatusStream(toolCallId) {
return { tool_call_id: toolCallId, payment_status: "pending", idempotency_key: null, original_status: "success", events: [] };
},
async verificationStatus(toolCallId) {
return { tool_call_id: toolCallId, verification_status: "pending", idempotency_key: null, original_status: "success", hosted_url: null, events: [] };
},
async verificationStatusStream(toolCallId) {
return { tool_call_id: toolCallId, verification_status: "pending", idempotency_key: null, original_status: "success", hosted_url: null, events: [] };
},
};
return session;
}
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,2DAA2D;AAe3D,MAAM,UAAU,WAAW,CACzB,YAAiD,EAAE,EACnD,UAA8B,EAAE;IAEhC,MAAM,OAAO,GAAY;QACvB,EAAE,EAAE,UAAU;QACd,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,EAAE,GAAG,EAAE,6BAA6B,EAAE,OAAO,EAAE,EAAE,EAAE;QAExD,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM;YAC5B,KAAK,MAAM,CAAC;YACZ,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;oBACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC3F,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,QAAQ,EAAE,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACnE,CAAC;QAED,KAAK,CAAC,IAAI;YAC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;QAClH,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI;YACb,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACxF,CAAC;QAED,KAAK,CAAC,aAAa,CAAC,UAAU;YAC5B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAChI,CAAC;QAED,KAAK,CAAC,mBAAmB,CAAC,UAAU;YAClC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAChI,CAAC;QAED,KAAK,CAAC,kBAAkB,CAAC,UAAU;YACjC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACvJ,CAAC;QAED,KAAK,CAAC,wBAAwB,CAAC,UAAU;YACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACvJ,CAAC;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
/**
* Tool-result code helpers — type-narrowed guards for the discriminated
* `tool_result.output` union surfaced on streamed `ToolCallRecord`
* values.
*
* The five variants are inert wire shapes — they only describe what the
* backend may stamp on `tool_result.output`. The guards turn `unknown`
* into one of the five `*Output` interfaces so callers can branch
* without casting.
*
* Each guard checks both the `code` discriminant against
* TOOL_RESULT_CODES AND its own required sibling fields — so a
* well-formed `code` with a missing sibling returns false rather
* than narrowing positive on the discriminant alone. The exhaustive-
* match utility (`assertExhaustiveToolResult`) makes a switch over
* ToolResultCode fail to compile if a sixth variant lands without
* the consumer updating their handler.
*/
import type { ToolCallRecord } from "@codespar/types";
export declare const ToolResultCode: {
readonly PolicyDenied: "policy_denied";
readonly ApprovalRequired: "approval_required";
readonly MocksExhausted: "mocks_exhausted";
readonly MocksEngineError: "mocks_engine_error";
readonly ToolNotMocked: "tool_not_mocked";
};
export type ToolResultCode = (typeof ToolResultCode)[keyof typeof ToolResultCode];
export declare const TOOL_RESULT_CODES: ReadonlySet<ToolResultCode>;
export interface PolicyDeniedOutput {
code: typeof ToolResultCode.PolicyDenied;
rule_id: string;
message: string;
}
export interface ApprovalRequiredOutput {
code: typeof ToolResultCode.ApprovalRequired;
approval_id: string;
expires_at: string;
message: string;
}
export interface MocksExhaustedOutput {
code: typeof ToolResultCode.MocksExhausted;
message: string;
}
export interface MocksEngineErrorOutput {
code: typeof ToolResultCode.MocksEngineError;
message: string;
}
export interface ToolNotMockedOutput {
code: typeof ToolResultCode.ToolNotMocked;
tool_name: string;
message: string;
}
export type ToolResultOutcome = PolicyDeniedOutput | ApprovalRequiredOutput | MocksExhaustedOutput | MocksEngineErrorOutput | ToolNotMockedOutput;
export type PolicyDeniedToolCall = ToolCallRecord & {
output: PolicyDeniedOutput;
};
export type ApprovalRequiredToolCall = ToolCallRecord & {
output: ApprovalRequiredOutput;
};
export type MocksExhaustedToolCall = ToolCallRecord & {
output: MocksExhaustedOutput;
};
export type MocksEngineErrorToolCall = ToolCallRecord & {
output: MocksEngineErrorOutput;
};
export type ToolNotMockedToolCall = ToolCallRecord & {
output: ToolNotMockedOutput;
};
export declare function isPolicyDenied(value: unknown): value is PolicyDeniedOutput;
export declare function isApprovalRequired(value: unknown): value is ApprovalRequiredOutput;
export declare function isMocksExhausted(value: unknown): value is MocksExhaustedOutput;
export declare function isMocksEngineError(value: unknown): value is MocksEngineErrorOutput;
export declare function isToolNotMocked(value: unknown): value is ToolNotMockedOutput;
/**
* Exhaustive-match witness. A `switch` over `ToolResultCode` should
* pass `value` here in the default branch — TS fails to compile if
* `value` isn't narrowed to `never`, i.e. if a code variant escaped
* the switch. The runtime body throws so a hostile cast at runtime
* doesn't silently swallow an unknown code.
*/
export declare function assertExhaustiveToolResult(value: never): never;
//# sourceMappingURL=tool-result-codes.d.ts.map
{"version":3,"file":"tool-result-codes.d.ts","sourceRoot":"","sources":["../src/tool-result-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAElF,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,cAAc,CAMxD,CAAC;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,cAAc,CAAC,YAAY,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,OAAO,cAAc,CAAC,gBAAgB,CAAC;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,cAAc,CAAC,cAAc,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,OAAO,cAAc,CAAC,gBAAgB,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,cAAc,CAAC,aAAa,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,GACzB,kBAAkB,GAClB,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,GACtB,mBAAmB,CAAC;AAIxB,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,MAAM,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,cAAc,GAAG;IACtD,MAAM,EAAE,sBAAsB,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG;IACpD,MAAM,EAAE,oBAAoB,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,cAAc,GAAG;IACtD,MAAM,EAAE,sBAAsB,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,MAAM,EAAE,mBAAmB,CAAC;CAC7B,CAAC;AAWF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAM1E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAOlF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAK9E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAKlF;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAM5E;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAI9D"}
/**
* Tool-result code helpers — type-narrowed guards for the discriminated
* `tool_result.output` union surfaced on streamed `ToolCallRecord`
* values.
*
* The five variants are inert wire shapes — they only describe what the
* backend may stamp on `tool_result.output`. The guards turn `unknown`
* into one of the five `*Output` interfaces so callers can branch
* without casting.
*
* Each guard checks both the `code` discriminant against
* TOOL_RESULT_CODES AND its own required sibling fields — so a
* well-formed `code` with a missing sibling returns false rather
* than narrowing positive on the discriminant alone. The exhaustive-
* match utility (`assertExhaustiveToolResult`) makes a switch over
* ToolResultCode fail to compile if a sixth variant lands without
* the consumer updating their handler.
*/
export const ToolResultCode = {
PolicyDenied: "policy_denied",
ApprovalRequired: "approval_required",
MocksExhausted: "mocks_exhausted",
MocksEngineError: "mocks_engine_error",
ToolNotMocked: "tool_not_mocked",
};
export const TOOL_RESULT_CODES = new Set([
ToolResultCode.PolicyDenied,
ToolResultCode.ApprovalRequired,
ToolResultCode.MocksExhausted,
ToolResultCode.MocksEngineError,
ToolResultCode.ToolNotMocked,
]);
function isObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function readStringField(obj, key) {
const v = obj[key];
return typeof v === "string" ? v : null;
}
export function isPolicyDenied(value) {
if (!isObject(value))
return false;
if (value.code !== ToolResultCode.PolicyDenied)
return false;
if (!TOOL_RESULT_CODES.has(value.code))
return false;
return readStringField(value, "rule_id") !== null
&& readStringField(value, "message") !== null;
}
export function isApprovalRequired(value) {
if (!isObject(value))
return false;
if (value.code !== ToolResultCode.ApprovalRequired)
return false;
if (!TOOL_RESULT_CODES.has(value.code))
return false;
return readStringField(value, "approval_id") !== null
&& readStringField(value, "expires_at") !== null
&& readStringField(value, "message") !== null;
}
export function isMocksExhausted(value) {
if (!isObject(value))
return false;
if (value.code !== ToolResultCode.MocksExhausted)
return false;
if (!TOOL_RESULT_CODES.has(value.code))
return false;
return readStringField(value, "message") !== null;
}
export function isMocksEngineError(value) {
if (!isObject(value))
return false;
if (value.code !== ToolResultCode.MocksEngineError)
return false;
if (!TOOL_RESULT_CODES.has(value.code))
return false;
return readStringField(value, "message") !== null;
}
export function isToolNotMocked(value) {
if (!isObject(value))
return false;
if (value.code !== ToolResultCode.ToolNotMocked)
return false;
if (!TOOL_RESULT_CODES.has(value.code))
return false;
return readStringField(value, "tool_name") !== null
&& readStringField(value, "message") !== null;
}
/**
* Exhaustive-match witness. A `switch` over `ToolResultCode` should
* pass `value` here in the default branch — TS fails to compile if
* `value` isn't narrowed to `never`, i.e. if a code variant escaped
* the switch. The runtime body throws so a hostile cast at runtime
* doesn't silently swallow an unknown code.
*/
export function assertExhaustiveToolResult(value) {
throw new Error(`tool-result-codes: unexpected output variant ${JSON.stringify(value)}`);
}
//# sourceMappingURL=tool-result-codes.js.map
{"version":3,"file":"tool-result-codes.js","sourceRoot":"","sources":["../src/tool-result-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,eAAe;IAC7B,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,iBAAiB;IACjC,gBAAgB,EAAE,oBAAoB;IACtC,aAAa,EAAE,iBAAiB;CACxB,CAAC;AAIX,MAAM,CAAC,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAC;IACpE,cAAc,CAAC,YAAY;IAC3B,cAAc,CAAC,gBAAgB;IAC/B,cAAc,CAAC,cAAc;IAC7B,cAAc,CAAC,gBAAgB;IAC/B,cAAc,CAAC,aAAa;CAC7B,CAAC,CAAC;AAwDH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,eAAe,CAAC,GAA4B,EAAE,GAAW;IAChE,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1C,CA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,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAsB,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,aAAa;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAsB,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI;WAC9C,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAY;IACrD,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACxE,CAAC;AACJ,CAAC"}
+4
-0

@@ -31,2 +31,6 @@ /**

export { tools, findTools } from "./tools.js";
export { CodesparApiError } from "./errors.js";
export type { CodesparApiErrorOptions } from "./errors.js";
export { TOOL_RESULT_CODES, ToolResultCode, assertExhaustiveToolResult, isApprovalRequired, isMocksEngineError, isMocksExhausted, isPolicyDenied, isToolNotMocked, } from "./tool-result-codes.js";
export type { ApprovalRequiredOutput, ApprovalRequiredToolCall, MocksEngineErrorOutput, MocksEngineErrorToolCall, MocksExhaustedOutput, MocksExhaustedToolCall, PolicyDeniedOutput, PolicyDeniedToolCall, ToolNotMockedOutput, ToolNotMockedToolCall, ToolResultOutcome, } from "./tool-result-codes.js";
import type { CodeSparConfig, SessionConfig } from "./types.js";

@@ -33,0 +37,0 @@ import type { Session } from "@codespar/types";

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,YAAY,EACV,cAAc,EACd,aAAa,EACb,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;gBAEtC,MAAM,GAAE,cAAmB;IAevC;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAS3E;AAED,eAAe,QAAQ,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,YAAY,EACV,cAAc,EACd,aAAa,EACb,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;gBAEtC,MAAM,GAAE,cAAmB;IAevC;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAS3E;AAED,eAAe,QAAQ,CAAC"}

@@ -30,2 +30,4 @@ /**

export { tools, findTools } from "./tools.js";
export { CodesparApiError } from "./errors.js";
export { TOOL_RESULT_CODES, ToolResultCode, assertExhaustiveToolResult, isApprovalRequired, isMocksEngineError, isMocksExhausted, isPolicyDenied, isToolNotMocked, } from "./tool-result-codes.js";
import { SessionConfigSchema } from "./types.js";

@@ -32,0 +34,0 @@ import { createSession } from "./session.js";

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"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CAAC,MAAM,CAAC,MAAc,EAAE,SAAwB,EAAE;QACrD,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC;QACzE,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE;YACnC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC1B,SAAS,EAAE,SAAS,IAAI,SAAS;SAClC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,QAAQ,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAQ,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EACV,OAAO,EAsBR,MAAM,iBAAiB,CAAC;AAEzB,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoBD,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,OAAO,CAAC,CAkWlB"}
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAQ,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EACV,OAAO,EAsBR,MAAM,iBAAiB,CAAC;AAEzB,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoCD,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,OAAO,CAAC,CAwZlB"}
/**
* Session implementation for the CodeSpar managed runtime.
*/
import { networkErrorToApiError, throwFromResponse } from "./errors.js";
// Wraps `fetch` so network rejections become CodesparApiError
// (status: 0) at the very edge of the SDK, rather than bubbling
// raw TypeError / DOMException up to the caller. Every transport
// site in this file goes through here.
async function safeFetch(input, init, what) {
try {
return await fetch(input, init);
}
catch (cause) {
throw networkErrorToApiError(cause, what);
}
}
// The concrete session object satisfies the Session interface and carries extra

@@ -21,10 +34,20 @@ // internal methods (tools, findTools) that the free functions in tools.ts access

};
const res = await fetch(`${baseUrl}/v1/sessions`, {
// Conditional spread keeps the wire body byte-identical to the
// pre-PRD shape when the caller omits mocks (R18 wire-neutrality).
// The field is forwarded verbatim — no canonical-name rewriting on
// the SDK side, so the double-underscore migration trap surfaces
// as the backend's mocks_invalid envelope rather than silent
// SDK-side normalization.
const wireBody = {
servers: req.servers,
user_id: userId,
...(config.mocks !== undefined ? { mocks: config.mocks } : {}),
};
const res = await safeFetch(`${baseUrl}/v1/sessions`, {
method: "POST",
headers,
body: JSON.stringify({ servers: req.servers, user_id: userId }),
});
body: JSON.stringify(wireBody),
}, "createSession");
if (!res.ok) {
const body = await res.text();
throw new Error(`createSession failed: ${res.status} ${body}`);
await throwFromResponse(res, "createSession");
}

@@ -63,7 +86,7 @@ const data = (await res.json());

const start = Date.now();
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/execute`, {
const r = await safeFetch(`${baseUrl}/v1/sessions/${data.id}/execute`, {
method: "POST",
headers,
body: JSON.stringify({ tool: toolName, input: params }),
});
}, "execute");
if (!r.ok) {

@@ -84,3 +107,3 @@ const body = await r.text();

async proxyExecute(request) {
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/proxy_execute`, {
const r = await safeFetch(`${baseUrl}/v1/sessions/${data.id}/proxy_execute`, {
method: "POST",

@@ -96,6 +119,5 @@ headers,

}),
});
}, "proxyExecute");
if (!r.ok) {
const body = await r.text();
throw new Error(`proxyExecute failed: ${r.status} ${body}`);
await throwFromResponse(r, "proxyExecute");
}

@@ -105,10 +127,9 @@ return (await r.json());

async send(message) {
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
const r = await safeFetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
method: "POST",
headers: { ...headers, Accept: "application/json" },
body: JSON.stringify({ message }),
});
}, "send");
if (!r.ok) {
const body = await r.text();
throw new Error(`send failed: ${r.status} ${body}`);
await throwFromResponse(r, "send");
}

@@ -118,11 +139,11 @@ return (await r.json());

async *sendStream(message) {
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
const r = await safeFetch(`${baseUrl}/v1/sessions/${data.id}/send`, {
method: "POST",
headers: { ...headers, Accept: "text/event-stream" },
body: JSON.stringify({ message }),
});
}, "sendStream");
if (!r.ok || !r.body) {
const body = await r.text();
throw new Error(`sendStream failed: ${r.status} ${body}`);
await throwFromResponse(r, "sendStream");
}
// Once we're past the !r.ok branch, r.body is guaranteed non-null.
yield* parseSseStream(r.body);

@@ -189,6 +210,5 @@ },

async paymentStatus(toolCallId) {
const r = await fetch(`${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/payment-status`, { headers });
const r = await safeFetch(`${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/payment-status`, { headers }, "paymentStatus");
if (!r.ok) {
const body = await r.text();
throw new Error(`paymentStatus failed: ${r.status} ${body}`);
await throwFromResponse(r, "paymentStatus");
}

@@ -198,6 +218,5 @@ return (await r.json());

async verificationStatus(toolCallId) {
const r = await fetch(`${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/verification-status`, { headers });
const r = await safeFetch(`${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/verification-status`, { headers }, "verificationStatus");
if (!r.ok) {
const body = await r.text();
throw new Error(`verificationStatus failed: ${r.status} ${body}`);
await throwFromResponse(r, "verificationStatus");
}

@@ -208,9 +227,10 @@ return (await r.json());

const url = `${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/payment-status/stream`;
const r = await fetch(url, {
const r = await safeFetch(url, {
headers: { ...headers, Accept: "text/event-stream" },
signal: options.signal,
});
}, "paymentStatusStream");
if (!r.ok || !r.body) {
const body = await r.text();
throw new Error(`paymentStatusStream failed: ${r.status} ${body}`);
await throwFromResponse(r, "paymentStatusStream");
// unreachable — throwFromResponse always throws
throw new Error("unreachable");
}

@@ -234,9 +254,10 @@ let last = null;

const url = `${baseUrl}/v1/tool-calls/${encodeURIComponent(toolCallId)}/verification-status/stream`;
const r = await fetch(url, {
const r = await safeFetch(url, {
headers: { ...headers, Accept: "text/event-stream" },
signal: options.signal,
});
}, "verificationStatusStream");
if (!r.ok || !r.body) {
const body = await r.text();
throw new Error(`verificationStatusStream failed: ${r.status} ${body}`);
await throwFromResponse(r, "verificationStatusStream");
// unreachable — throwFromResponse always throws
throw new Error("unreachable");
}

@@ -259,3 +280,3 @@ let last = null;

async authorize(serverId, config) {
const r = await fetch(`${baseUrl}/v1/connect/start`, {
const r = await safeFetch(`${baseUrl}/v1/connect/start`, {
method: "POST",

@@ -269,6 +290,5 @@ headers,

}),
});
}, "authorize");
if (!r.ok) {
const body = await r.text();
throw new Error(`authorize failed: ${r.status} ${body}`);
await throwFromResponse(r, "authorize");
}

@@ -283,17 +303,28 @@ const payload = (await r.json());

async connections() {
const r = await fetch(`${baseUrl}/v1/sessions/${data.id}/connections`, {
headers,
});
if (!r.ok)
// Best-effort — both transport failures (CodesparApiError from
// safeFetch) and non-2xx responses fall back to the cached
// payload so a transient blip doesn't crater the session.
try {
const r = await safeFetch(`${baseUrl}/v1/sessions/${data.id}/connections`, { headers }, "connections");
if (!r.ok)
return cachedConnections ?? [];
const payload = (await r.json());
cachedConnections = payload.servers;
cachedTools = payload.tools;
return payload.servers;
}
catch {
return cachedConnections ?? [];
const payload = (await r.json());
cachedConnections = payload.servers;
cachedTools = payload.tools;
return payload.servers;
}
},
async close() {
await fetch(`${baseUrl}/v1/sessions/${data.id}`, {
method: "DELETE",
headers,
});
// Best-effort — the backend reaps stale sessions on a timer,
// so a network failure here shouldn't surface to the caller.
try {
await safeFetch(`${baseUrl}/v1/sessions/${data.id}`, { method: "DELETE", headers }, "close");
}
catch {
// Intentional swallow — matches the previous fire-and-forget
// contract; close() never threw.
}
},

@@ -300,0 +331,0 @@ };

@@ -1,1 +0,1 @@

{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiDH,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,MAAqB,EACrB,IAAiB;IAEjB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACjC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IACrD,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;QAClC,aAAa,EAAE,UAAU,MAAM,EAAE;KAClC,CAAC;IACF,IAAI,SAAS;QAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;IAEzD,MAAM,GAAG,GAAyB;QAChC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;QACzD,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS;KAC9C,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,cAAc,EAAE;QAChD,MAAM,EAAE,MAAM;QACd,OAAO;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;KAChE,C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AE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzD,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED,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"}
import { z } from "zod";
import type { ToolResult } from "@codespar/types";
import type { MockValue, ToolResult } from "@codespar/types";
export interface CodeSparConfig {

@@ -27,2 +27,18 @@ /** API key for managed mode. Obtain from dashboard.codespar.dev */

projectId?: string;
/**
* Test-mode mocks. Map of canonical tool names (slash form,
* `^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9_-]*$` — e.g.
* `asaas/create_payment`) to mock responses. Values are either a
* single MockObject (static mock) or an array of MockObject
* (stateful mock, consumed in order).
*
* Requires a `csk_test_*` key against a `test`-environment project
* — the backend rejects with `mocks_not_permitted` otherwise.
* Forwarded verbatim to `POST /v1/sessions` so the OSS-runtime
* double-underscore form (`asaas__create_payment`) reaches the
* backend unrewritten and surfaces as `mocks_invalid`. An empty
* `{}` is accepted; strict-mode (R3a) activates only on non-empty
* maps.
*/
mocks?: Record<string, MockValue>;
}

@@ -89,2 +105,3 @@ export interface Tool {

projectId: z.ZodOptional<z.ZodString>;
mocks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">]>>>;
}, "strip", z.ZodTypeAny, {

@@ -99,2 +116,3 @@ servers?: string[] | undefined;

projectId?: string | undefined;
mocks?: Record<string, Record<string, unknown> | Record<string, unknown>[]> | undefined;
}, {

@@ -109,3 +127,4 @@ servers?: string[] | undefined;

projectId?: string | undefined;
mocks?: Record<string, Record<string, unknown> | Record<string, unknown>[]> | undefined;
}>;
//# sourceMappingURL=types.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,sEAAsE;IACtE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,KAAK,CAAC;IACvE,oCAAoC;IACpC,iBAAiB,CAAC,EAAE;QAClB,4CAA4C;QAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,wDAAwD;QACxD,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,WAAW,IAAI;IACnB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,8FAA8F;IAC9F,MAAM,EAAE,MAAM,C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AC;IACb,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3F,0DAA0D;IAC1D,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,KAAK,OAAO,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,uCAAuC;IACvC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,6BAA6B;IAC7B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpE,oCAAoC;IACpC,WAAW,CAAC,EAAE;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;QACnC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,gEAAgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AAYD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY9B,CAAC"}
import { z } from "zod";
/* ── Validation schemas ───────────────────────────────────────── */
// Mock values pass through verbatim — the backend owns the strict
// validation, so the client-side schema accepts any object shape
// rather than re-encoding the rules and risking drift.
const MockValueSchema = z.union([
z.record(z.unknown()),
z.array(z.record(z.unknown())),
]);
export const SessionConfigSchema = z.object({

@@ -14,3 +21,4 @@ servers: z.array(z.string()).optional(),

projectId: z.string().regex(/^prj_[A-Za-z0-9]{16}$/).optional(),
mocks: z.record(MockValueSchema).optional(),
});
//# sourceMappingURL=types.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuFxB,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;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE;CAChE,CAAC,CAAC"}
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuGxB,qEAAqE;AAErE,kEAAkE;AAClE,iEAAiE;AACjE,uDAAuD;AACvD,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACrB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;CAC/B,CAAC,CAAC;AAEH,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;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE;IAC/D,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE;CAC5C,CAAC,CAAC"}
{
"name": "@codespar/sdk",
"version": "0.9.0",
"version": "0.10.0",
"description": "Commerce SDK for AI agents — sessions, managed auth, Complete Loop orchestration for Latin American APIs",

@@ -12,2 +12,6 @@ "type": "module",

"types": "./dist/index.d.ts"
},
"./testing": {
"import": "./dist/testing/index.js",
"types": "./dist/testing/index.d.ts"
}

@@ -52,3 +56,3 @@ },

"zod": "^3.24.0",
"@codespar/types": "^0.1.0"
"@codespar/types": "^0.10.0"
},

@@ -55,0 +59,0 @@ "devDependencies": {

+166
-19

@@ -5,16 +5,32 @@ # @codespar/sdk

## What's new in 0.5.0
## What's new in 0.9.0
Typed wrappers for the F3.M2 meta-tool router:
Eight new typed methods on `Session`, grouped by capability:
- `session.discover(query, options?)` — find the right tool for a free-form use case (`codespar_discover`).
- `session.connectionWizard(options)` — surface the connect deep-link when a needed server is disconnected (`codespar_manage_connections`). Credentials never travel through this method.
- `session.paymentStatus(toolCallId)` — correlate webhook settlement back to the originating `codespar_pay` call via the response idempotency key.
**Meta-tool wrappers** — neutral input shape, typed payload back, same wire as `session.execute(...)`:
All three call into the same managed runtime as `session.execute(...)`; the wrappers just give you the typed payload shape without hand-rolling the meta-tool envelope.
- `session.charge(args)` — INBOUND charges (`codespar_charge`). Buyer pays merchant. Pix BRL via Asaas / MP / iugu / Stone; card USD via Stripe. Distinct from `codespar_pay` (outbound transfers).
- `session.ship(args)` — shipping (`codespar_ship`). One typed entry into Melhor Envio's 3 rails (`action: "label" | "quote" | "track"`).
### Crypto + KYC meta-tools (raw `execute()` only)
**Async settlement** — `codespar_charge` / `codespar_pay` return synchronously, but real settlement lands via webhook:
Two newer meta-tools — `codespar_crypto_pay` (USDC/USDT/BTC across mainnet + L2s) and `codespar_kyc` (Persona / Sift / etc identity + risk verification) — are callable today via raw `session.execute(...)`. Typed SDK wrappers will land in a future release once at least 2 transforms per meta-tool are live in prod.
- `session.paymentStatus(toolCallId)` — poll the latest known status (pending → succeeded / failed / refunded). Correlates via the response idempotency_key ↔ provider external_reference.
- `session.paymentStatusStream(toolCallId, { onUpdate?, signal? })` — SSE variant. Snapshot on open, an envelope per state change, heartbeat every 15s, auto-closes 5s after a terminal state. `signal` aborts from the caller side.
**Async verification** — `codespar_kyc` returns the inquiry id; the buyer finishes the hosted flow off-platform:
- `session.verificationStatus(toolCallId)` — poll the disposition (pending → approved / rejected / review / expired).
- `session.verificationStatusStream(toolCallId, { onUpdate?, signal? })` — SSE variant. Same lifecycle as `paymentStatusStream`.
**Tool discovery + connection wizard** (already in 0.4.0, restated for completeness):
- `session.discover(query, options?)` — semantic + lexical tool search across the catalog (`codespar_discover`, pgvector + pg_trgm).
- `session.connectionWizard(options)` — connect deep-link backend (`codespar_manage_connections`). Credentials never travel through this method.
All wrappers call into the same managed runtime as `session.execute(...)`; you get typed payloads instead of hand-rolling the meta-tool envelope.
### Crypto + KYC meta-tools
`codespar_crypto_pay` (Coinbase Commerce + Bitso) and `codespar_kyc` (Persona, Sift, Konduto, Truora) are routable today. The verification half now has a typed wrapper (`session.verificationStatus` / `verificationStatusStream`); a `session.cryptoPay(...)` typed wrapper is not in 0.9.0 — call via raw `session.execute("codespar_crypto_pay", {...})` for now.
```typescript

@@ -30,3 +46,3 @@ // Crypto: receive a USDC payment via Coinbase Commerce hosted checkout

// KYC: kick off a Persona identity verification
// KYC: kick off a Persona identity verification, then poll typed
const inquiry = await session.execute("codespar_kyc", {

@@ -36,3 +52,4 @@ buyer: { email: "alice@example.com", first_name: "Alice", last_name: "Smith" },

});
// inquiry.output.verification_id → poll for completion
const v = await session.verificationStatus(inquiry.tool_call_id);
// ^^ approved | rejected | review | expired | pending
```

@@ -63,5 +80,6 @@

// Direct tool execution
const charge = await session.execute("ZOOP_CREATE_CHARGE", {
amount: 150.0,
payment_type: "pix",
const charge = await session.execute("asaas/create_payment", {
customer: "cus_xxx",
billingType: "PIX",
value: 150,
});

@@ -77,6 +95,6 @@

steps: [
{ tool: "ZOOP_CREATE_CHARGE", params: { amount: 150, payment_type: "pix" } },
{ tool: "NUVEMFISCAL_EMITIR_NFE", params: (prev) => ({ chargeId: prev[0].data }) },
{ tool: "MELHORENVIO_GENERATE_LABEL", params: {} },
{ tool: "ZAPI_SEND_MESSAGE", params: { text: "Your order is on the way!" } },
{ tool: "codespar_charge", params: { amount: 150, currency: "BRL", method: "pix", buyer: { name, document: cpf } } },
{ tool: "codespar_invoice", params: (prev) => ({ rail: "nfe", company_id, payment_id: prev[0].data.id }) },
{ tool: "codespar_ship", params: { action: "label", origin, destination, items } },
{ tool: "codespar_notify", params: { recipient: phone, message: "Your order is on the way!" } },
],

@@ -95,3 +113,3 @@ onStepComplete: (step, r) => console.log(`✓ ${step.tool}`),

| `apiKey` | `string` | `CODESPAR_API_KEY` env | Your API key |
| `baseUrl` | `string` | `https://api.codespar.dev` | API base URL |
| `baseUrl` | `string` | `CODESPAR_BASE_URL` env, else `https://api.codespar.dev` | API base URL. Set `CODESPAR_BASE_URL=http://localhost:8000` to point the SDK at a [local OSS runtime](https://github.com/codespar/codespar); the managed backend is the default. |
| `managed` | `boolean` | `true` | Enable managed billing/logging |

@@ -108,2 +126,3 @@ | `projectId` | `string` | — | Optional `prj_<16alphanum>`. Client-wide default project; sent as `x-codespar-project`. Falls back to the org's default project when omitted. |

| `projectId` | `string` | Optional `prj_<16alphanum>`. Overrides the client-level `projectId`; falls back to the org's default project when both are unset. |
| `mocks` | `Record<string, MockValue>` | Optional test-mode mocks. See [Test-mode mocks](#test-mode-mocks). |

@@ -122,3 +141,8 @@ ### Session methods

| `session.connectionWizard(options)` | Connect deep-link via `codespar_manage_connections` (typed) |
| `session.paymentStatus(toolCallId)` | Async settlement status for a `codespar_pay` call |
| `session.charge(args)` | Inbound charge via `codespar_charge` (typed) — buyer pays merchant |
| `session.ship(args)` | Shipping via `codespar_ship` (typed) — `action: "label" \| "quote" \| "track"` |
| `session.paymentStatus(toolCallId)` | Async settlement status for a `codespar_charge` / `codespar_pay` call |
| `session.paymentStatusStream(toolCallId, opts)` | SSE variant of `paymentStatus`; resolves on terminal |
| `session.verificationStatus(toolCallId)` | Async KYC disposition for a `codespar_kyc` call |
| `session.verificationStatusStream(toolCallId, opts)` | SSE variant of `verificationStatus`; resolves on terminal |
| `session.mcp` | MCP transport URL and headers (when using managed runtime) |

@@ -178,2 +202,125 @@ | `session.close()` | Close session |

## Test-mode mocks
Skip live providers in tests by passing a `mocks` map to `cs.create`. Keys are canonical tool names in slash form (`asaas/create_payment`, `melhor-envio/calculate_shipping`, …). Values are either a single object — used as the response on every matching call — or an array of objects consumed in order, returning `mocks_exhausted` once the list drains.
```typescript
import { CodeSpar } from "@codespar/sdk";
const cs = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });
const session = await cs.create("user_test", {
servers: ["asaas"],
mocks: {
"asaas/create_payment": { id: "pay_test", status: "PENDING" },
},
});
const result = await session.execute("asaas/create_payment", { value: 100 });
// result.data === { id: "pay_test", status: "PENDING" }
```
Pass an array for stateful mocks:
```typescript
mocks: {
"asaas/create_payment": [
{ id: "pay_1", status: "PENDING" },
{ id: "pay_1", status: "RECEIVED" },
],
}
```
Mocks live behind the managed backend's test-mode gate — a `csk_test_*` API key against a `test`-environment project. Live keys against the same map return `mocks_not_permitted`. The SDK forwards keys verbatim; if you send the OSS double-underscore form (`asaas__create_payment`) the backend rejects with `mocks_invalid` rather than the SDK silently rewriting.
The OSS runtime accepts the same `mocks` shape on its session API (see [codespar/codespar#113](https://github.com/codespar/codespar/pull/113)), so the same test fixtures work whether you point at `api.codespar.dev` or a self-hosted instance via `CODESPAR_BASE_URL`. Self-hosted runtimes must additionally set `CODESPAR_TEST_MODE_ENABLED=true` on the server process; without it, the SDK receives `mocks_not_permitted` / HTTP 501 instead of fixture responses.
Storage shape differs by runtime — the wire contract does not. The managed backend persists mocks and per-tool consume counters; sessions and their fixtures survive restarts and multi-replica deployments. The OSS runtime holds both in process memory; they are scoped to the HTTP-session process and are lost on restart, and channel-bridge sessions (WhatsApp, Slack, Telegram, Discord) cannot carry mocks under the OSS shape. Response envelopes, status codes, sibling fields, and gate ordering are byte-identical between runtimes regardless. See [the test-mode concept doc](https://docs.codespar.dev/concepts/test-mode) for the full per-runtime split.
Test mode is a property of the runtime, not the session. On the managed backend it's `project.environment === 'test'`; on a self-hosted OSS runtime it's `CODESPAR_TEST_MODE_ENABLED=true` on the server process. When the runtime is in test mode, every external tool call your code or LLM dispatches must match a declared mock — unmatched calls return `tool_not_mocked` (HTTP 422 on the catalog-routed `/execute` path; a `tool_result` block on the chat-loop) and no upstream provider runs. The envelope covers three failure modes: the `mocks` map has no entry for the canonical name, the session was created with no `mocks` field, or the canonical name has an unknown server prefix. A session that doesn't declare `mocks` can't dispatch any tools in test mode; declare the mocks the test will exercise, or run the same code against a live-mode runtime where the real providers handle dispatch. Built-in metadata tools — `codespar_list_tools` on OSS, `codespar_discover` and `codespar_manage_connections` on the managed backend — bypass this gate.
### Type aliases
`MockObject` (`Record<string, unknown>`) and `MockValue` (`MockObject | MockObject[]`) ship from `@codespar/types` and re-export through `@codespar/sdk`. Use them when you want to define mock fixtures separately from the `create` call site.
```typescript
import type { MockValue } from "@codespar/sdk";
const fixtures: Record<string, MockValue> = {
"asaas/create_payment": { id: "pay_test", status: "PENDING" },
};
```
## Typed errors
Every transport failure from `createSession`, `proxyExecute`, `send`, `sendStream`, `paymentStatus(Stream)`, `verificationStatus(Stream)`, and `authorize` throws a `CodesparApiError` with a structured `code` field. The old `e.message.includes("foo")` pattern is gone — branch on `e.code` instead.
```typescript
import { CodesparApiError } from "@codespar/sdk";
try {
await cs.create("user_test", { mocks: { "asaas/create_payment": {} } });
} catch (err) {
if (err instanceof CodesparApiError) {
if (err.code === "mocks_not_permitted") {
// Live key against a mocks map. Swap to csk_test_*.
} else if (err.code === "mocks_invalid") {
// Backend rejected a tool-name key. Check the slash form.
} else if (err.status === 0) {
// Network never reached the backend; err.cause has the fetch rejection.
}
throw err;
}
}
```
`session.execute` keeps its returns-vs-throws asymmetry: tool failures come back as `ToolResult.success === false` with the body on `error`. Only transport-level failures throw.
### Tool-result guards
The five reserved tool-result codes (`policy_denied`, `approval_required`, `mocks_exhausted`, `mocks_engine_error`, `tool_not_mocked`) ship typed guards plus an exhaustive-match helper. Guards run against any `unknown` payload — both `ToolResult.data` from `session.execute` and `ToolCallRecord.output` from `send` / `sendStream`. Each guard checks the `code` discriminant AND the variant's required sibling fields, so a malformed payload returns false rather than narrowing positive on the code alone.
```typescript
import {
isApprovalRequired,
isMocksEngineError,
isMocksExhausted,
isPolicyDenied,
isToolNotMocked,
assertExhaustiveToolResult,
ToolResultCode,
} from "@codespar/sdk";
const result = await session.execute("asaas/create_payment", { value: 100 });
if (isPolicyDenied(result.data)) {
console.warn(`blocked by ${result.data.rule_id}: ${result.data.message}`);
} else if (isApprovalRequired(result.data)) {
console.log(`needs approval ${result.data.approval_id} by ${result.data.expires_at}`);
} else if (isMocksExhausted(result.data)) {
// Stateful mock array drained — pad it or extend the test.
} else if (isMocksEngineError(result.data)) {
// Backend-side mocks engine failure; usually a malformed fixture.
} else if (isToolNotMocked(result.data)) {
console.warn(`no mock for ${result.data.tool_name}`);
}
```
The same guards apply inside a `sendStream` loop against `event.toolCall.output`.
When a `switch` over `ToolResultCode` covers every variant, call `assertExhaustiveToolResult` in the default branch. TypeScript fails to compile if a sixth code lands without a matching arm.
```typescript
function handle(outcome: ToolResultOutcome): string {
switch (outcome.code) {
case ToolResultCode.PolicyDenied: return outcome.rule_id;
case ToolResultCode.ApprovalRequired: return outcome.approval_id;
case ToolResultCode.MocksExhausted: return "exhausted";
case ToolResultCode.MocksEngineError: return "engine";
case ToolResultCode.ToolNotMocked: return outcome.tool_name;
default: return assertExhaustiveToolResult(outcome);
}
}
```
## Need more?

@@ -180,0 +327,0 @@