Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
544 changes: 16 additions & 528 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/autogen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"directory": "packages/autogen"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/camel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"directory": "packages/camel"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/claude/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/claude"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"node": ">=20"
},
"dependencies": {
"@codespar/sdk": "^0.9.0",
"@codespar/sdk": "^0.10.0",
"commander": "^13.0.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# @codespar/sdk — CHANGELOG

## Unreleased
## 0.10.0

The hosted test-mode SDK surface lands across `@codespar/sdk`, `@codespar/types`, and the `codespar` Python package. See [codespar/codespar-core#54](https://github.com/codespar/codespar-core/pull/54).

### Added

- `cs.create(userId, { mocks: {...} })` (TypeScript) and `cs.create("u", mocks={...})` (Python). Keys are canonical tool names in slash form (`asaas/create_payment`); values are a `MockObject` for a static mock or a `MockObject[]` for a stateful mock consumed in order. Forwarded verbatim on `POST /v1/sessions` — the SDK does not rewrite tool names, so the OSS double-underscore form (`asaas__create_payment`) surfaces as `mocks_invalid` rather than being silently rewritten. Absent case stays wire-neutral (no `mocks` key on the body).
- `MockObject` and `MockValue` type aliases in `@codespar/types` (re-exported through `@codespar/sdk`) and in the `codespar` Python package. `SessionConfig` widens in both languages to accept the optional `mocks` field.
- `cs.create(userId, { mocks: {...} })`. Keys are canonical tool names in slash form (`asaas/create_payment`); values are a `MockObject` for a static mock or a `MockObject[]` for a stateful mock consumed in order. Forwarded verbatim on `POST /v1/sessions` — the SDK does not rewrite tool names, so the double-underscore form (`asaas__create_payment`) surfaces as `mocks_invalid` rather than being silently rewritten. Absent case stays wire-neutral (no `mocks` key on the body).
- `MockObject` and `MockValue` type aliases re-exported from `@codespar/types`. `SessionConfig` widens to accept the optional `mocks` field.
- `CodesparApiError` — structured exception class shared by every transport-failure throw site in `session.ts`. Constructor signature `new CodesparApiError(message, { status, code?, body?, cause? })`. Network errors that never reach the backend surface as `status: 0` with the underlying `fetch` rejection preserved as `cause`.
- Tool-result type-narrowed guards in `packages/core/src/tool-result-codes.ts` and `packages/python/src/codespar/tool_result_codes.py`. Five variants — `PolicyDenied`, `ApprovalRequired`, `MocksExhausted`, `MocksEngineError`, `ToolNotMocked` — plus matching `*Output` interfaces / dataclasses, narrowed `*ToolCall` aliases (TS), the `ToolResultCode` union, the `TOOL_RESULT_CODES` set, five predicate guards (`isPolicyDenied` / `is_policy_denied`, etc.), and an exhaustive-match helper (`assertExhaustiveToolResult` / `assert_exhaustive_tool_result`) that makes a `switch` over `ToolResultCode` fail to compile (TS) or trip at runtime (Python) when a sixth variant lands without a handler. Each guard checks the `code` discriminant AND its required sibling fields, so a payload with a well-formed `code` but a missing `rule_id` / `approval_id` / `tool_name` returns false rather than narrowing positive.
- `CODESPAR_BASE_URL` environment variable resolution. The TypeScript `CodeSpar` constructor already read the env var; the Python `CodeSpar` and `AsyncCodeSpar` constructors now do too. The cascade in both languages is explicit `baseUrl` / `base_url` option, then `CODESPAR_BASE_URL`, then `https://api.codespar.dev`. Point the same client wiring at a [local OSS runtime](https://github.com/codespar/codespar) without rebuilding call sites.
- `tool-result-codes` module (`packages/core/src/tool-result-codes.ts`). Five variants — `PolicyDenied`, `ApprovalRequired`, `MocksExhausted`, `MocksEngineError`, `ToolNotMocked` — plus matching `*Output` interfaces, narrowed `*ToolCall` aliases, the `ToolResultCode` union, the `TOOL_RESULT_CODES` set, five predicate guards (`isPolicyDenied`, `isApprovalRequired`, `isMocksExhausted`, `isMocksEngineError`, `isToolNotMocked`), and the `assertExhaustiveToolResult` helper that makes a `switch` over `ToolResultCode` fail to compile when a sixth variant lands without a handler. Each guard checks the `code` discriminant AND its required sibling fields, so a payload with a well-formed `code` but a missing `rule_id` / `approval_id` / `tool_name` returns false rather than narrowing positive.
- `CODESPAR_BASE_URL` environment variable resolved at client construction. Cascade: explicit `baseUrl` option, then `CODESPAR_BASE_URL`, then `https://api.codespar.dev`. Point the same client wiring at a [local OSS runtime](https://github.com/codespar/codespar) without rebuilding call sites.
- Bumped `@codespar/types` dependency range to `^0.10.0`.

### Changed

- **SemVer-minor break for callers parsing `e.message` strings.** The generic `throw new Error("send failed: 500 ...")` shape is gone — every transport call site (`createSession`, `proxyExecute`, `send`, `sendStream`, `paymentStatus(Stream)`, `verificationStatus(Stream)`, `authorize`) now throws `CodesparApiError`. Migration recipe: `e.message.includes("foo")` becomes `e.code === "foo"`.
- `session.execute(...)` keeps its existing returns-vs-throws asymmetry — non-ok responses still come back as `ToolResult.success === false` with the body in `error`. Only transport exceptions change shape.
- Python `_http.py` honors `code` over `error` when both are present on a non-success response body. The new test-mode envelopes (`mocks_not_permitted`, `mocks_invalid`, `mocks_payload_too_large`) carry `code`; pre-test-mode responses that only set `error` remain compatible.

## 0.9.0

Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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",
"type": "module",
"main": "./dist/index.js",
Expand Down Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"zod": "^3.24.0",
"@codespar/types": "*"
"@codespar/types": "^0.10.0"
},
"devDependencies": {
"@types/node": "^25.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/crewai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/crewai"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/google-genai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"directory": "packages/google-genai"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/langchain"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0",
"@codespar/sdk": "^0.10.0",
"zod": ">=3.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/letta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/letta"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/llama-index/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"directory": "packages/llama-index"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/mastra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/mastra"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"directory": "packages/mcp"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"directory": "packages/openai"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0"
"@codespar/sdk": "^0.10.0"
},
"devDependencies": {
"@codespar/sdk": "*",
Expand Down
56 changes: 56 additions & 0 deletions packages/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
# codespar (Python SDK) — CHANGELOG

## 0.10.0

The hosted test-mode SDK surface lands across the `codespar` Python
package alongside `@codespar/sdk` and `@codespar/types`. See
[codespar/codespar-core#54](https://github.com/codespar/codespar-core/pull/54).

### Added

- `cs.create("user", mocks={...})` — optional mocks map forwarded
verbatim on `POST /v1/sessions`. Keys are canonical tool names in
slash form (`asaas/create_payment`); values follow `MockValue` —
a single `MockObject` for a static mock or a `list[MockObject]`
for a stateful mock consumed in order, then `mocks_exhausted` once
the list is drained. Absent case stays wire-neutral (no `mocks`
key on the body). The SDK does not rewrite tool names, so the
double-underscore form (`asaas__create_payment`) surfaces as
`mocks_invalid` from the backend rather than being silently
rewritten.
- `MockObject` and `MockValue` type aliases re-exported from
`codespar`. `SessionConfig` widens to accept the optional
`mocks: dict[str, MockValue] | None` field.
- `CodesparApiError` exception (TypeScript parallel); Python's
`ApiError` retains its existing shape, and the new test-mode
envelopes (`mocks_not_permitted`, `mocks_invalid`,
`mocks_payload_too_large`) flow through it with the `code`
discriminant preserved.
- `tool_result_codes` module (`src/codespar/tool_result_codes.py`).
Five frozen dataclasses — `PolicyDeniedOutput`,
`ApprovalRequiredOutput`, `MocksExhaustedOutput`,
`MocksEngineErrorOutput`, `ToolNotMockedOutput` — plus the
`ToolResultCode` `Literal` union, the `TOOL_RESULT_CODES`
`frozenset`, five `TypeGuard` predicates (`is_policy_denied`,
`is_approval_required`, `is_mocks_exhausted`,
`is_mocks_engine_error`, `is_tool_not_mocked`), and
`assert_exhaustive_tool_result` for exhaustive `match` over the
union. Each guard checks the `code` discriminant AND its required
sibling fields, so a payload with a well-formed `code` but a
missing `rule_id` / `approval_id` / `tool_name` returns `False`
rather than narrowing positive.
- `CODESPAR_BASE_URL` environment variable resolved in both the
`CodeSpar` and `AsyncCodeSpar` constructors. Cascade: explicit
`base_url` option, then `CODESPAR_BASE_URL`, then
`https://api.codespar.dev`. Point the same client wiring at a
[local OSS runtime](https://github.com/codespar/codespar) without
rebuilding call sites.
- Test fixture `tests/_fixtures/mocks_canonical.json` for wire
parity between languages.

### Changed

- `_http.py` honors `code` over `error` when both are present on a
non-success response body. The new test-mode envelopes carry
`code`; pre-test-mode responses that only set `error` remain
compatible.
- User-Agent bumped to `codespar-python/0.10.0`.

## 0.9.0

- New: `AsyncSession.payment_status_stream(tool_call_id, *, on_update=None)`.
Expand Down
2 changes: 1 addition & 1 deletion packages/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "codespar"
version = "0.9.0"
version = "0.10.0"
description = "Python SDK for CodeSpar — commerce infrastructure for AI agents in Latin America."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion packages/python/src/codespar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
WizardAction,
)

__version__ = "0.9.0"
__version__ = "0.10.0"

__all__ = [
"APPROVAL_REQUIRED",
Expand Down
2 changes: 1 addition & 1 deletion packages/python/src/codespar/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def build_headers(
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
"User-Agent": "codespar-python/0.9.0",
"User-Agent": "codespar-python/0.10.0",
}
if project_id:
headers["x-codespar-project"] = project_id
Expand Down
18 changes: 18 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @codespar/types — CHANGELOG

## 0.10.0

- Added `MockObject` and `MockValue` type aliases for the hosted
test-mode surface. `MockObject` is a `Record<string, unknown>`
representing a single mock response payload; `MockValue` is a
`MockObject | MockObject[]` union — a single object is a static
mock (same response every call), an array is a stateful mock
consumed in order with `mocks_exhausted` once the list is drained.
- Widened `CreateSessionRequest` with an optional
`mocks?: Record<string, MockValue>` field. Keys are canonical tool
names in slash form (`asaas/create_payment`); the SDK forwards them
verbatim so the OSS double-underscore form
(`asaas__create_payment`) surfaces as `mocks_invalid` from the
backend rather than being silently rewritten.
- Note: 0.8.0 and 0.9.0 were not released; this jump aligns
`@codespar/types` with the `@codespar/sdk` and `codespar` Python
package versions.

## 0.7.0

- Added `Session.paymentStatusStream` and `Session.verificationStatusStream`
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codespar/types",
"version": "0.7.0",
"version": "0.10.0",
"description": "Shared session interface contract for codespar runtimes",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"directory": "packages/vercel"
},
"peerDependencies": {
"@codespar/sdk": "^0.9.0",
"@codespar/sdk": "^0.10.0",
"ai": ">=3.0.0"
},
"devDependencies": {
Expand Down
63 changes: 39 additions & 24 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ set -euo pipefail
# Versions — keep in sync with package.json / pyproject.toml. The script
# does NOT bump these; it asserts they match what's on disk before publishing.
# ---------------------------------------------------------------------------
TYPES_VERSION="0.7.0"
SDK_VERSION="0.9.0"
PYTHON_VERSION="0.9.0"
TYPES_VERSION="0.10.0"
SDK_VERSION="0.10.0"
PYTHON_VERSION="0.10.0"

# ---------------------------------------------------------------------------
# CLI flags — set by parse_args, consumed everywhere.
Expand Down Expand Up @@ -152,30 +152,45 @@ read_otp() {

generate_changelog() {
cat <<'EOF'
## codespar 0.9.0 (Python) / @codespar/sdk 0.9.0 / @codespar/types 0.7.0
## codespar 0.10.0 (Python) / @codespar/sdk 0.10.0 / @codespar/types 0.10.0

SSE streaming for async settlement + verification status, replacing
polling for long-running pending → settled flows.
Hosted test-mode SDK surface — mocks forwarding on session create,
structured `CodesparApiError`, five type-narrowed tool-result guards,
and `CODESPAR_BASE_URL` env-var resolution so the same client wiring
targets the managed backend or a self-hosted OSS runtime.

### Added
- `session.paymentStatusStream(toolCallId, { onUpdate?, signal? })` —
Server-Sent Events stream over `GET /v1/tool-calls/:id/payment-status/stream`.
Pushes initial snapshot + every state change; resolves on terminal.
AbortSignal cancels.
- `session.verificationStatusStream(toolCallId, { onUpdate?, signal? })`
— KYC sibling with the same lifecycle.
- Python paridade: `AsyncSession.payment_status_stream` /
`verification_status_stream` (sync wrappers on the blocking client).

### Types (@codespar/types 0.7.0)
- `PaymentStatusStreamOptions`, `VerificationStatusStreamOptions`.
- New `Session.paymentStatusStream` + `verificationStatusStream`
signatures.

### Compat
- Polling siblings (`paymentStatus` / `verificationStatus`) stay live
— additive change only. Adapter packages remain on `^0.3.0` ranges
for `@codespar/sdk` (method additions, no breaking changes).
- `cs.create(userId, { mocks })` (TS) and `cs.create("u", mocks=...)`
(Python). Keys are canonical tool names in slash form
(`asaas/create_payment`); values are a `MockObject` for a static
mock or a `MockObject[]` for a stateful mock consumed in order.
Forwarded verbatim — the SDK does not rewrite tool names.
- `CodesparApiError` (TS) — typed envelope for transport failures
carrying `{ status, code?, body?, cause? }`. Migration recipe for
callers parsing `e.message`: use `e.code === "foo"`.
- `tool-result-codes` module — `isPolicyDenied`, `isApprovalRequired`,
`isMocksExhausted`, `isMocksEngineError`, `isToolNotMocked`,
`ToolResultCode` union, `TOOL_RESULT_CODES` set, and
`assertExhaustiveToolResult` exhaustive-match helper. Each guard
checks the `code` discriminant AND its required sibling fields.
- `CODESPAR_BASE_URL` env-var resolution in the Python `CodeSpar` /
`AsyncCodeSpar` constructors (the TS constructor already did this).
Cascade: explicit option, then env var, then `https://api.codespar.dev`.

### Types (@codespar/types 0.10.0)
- `MockObject` and `MockValue` aliases; `CreateSessionRequest` widened
with optional `mocks` field.
- Note: 0.8.0 and 0.9.0 were not released for `@codespar/types`; this
jump aligns it with the SDK and Python package versions.

### Changed
- Every transport call site now throws `CodesparApiError` instead of
the legacy `Error("send failed: 500 ...")`. `session.execute(...)`
keeps its returns-vs-throws asymmetry — only transport exceptions
change shape.
- Python `_http.py` honors `code` over `error` when both are present
on a non-success response body.
- Python `User-Agent` bumped to `codespar-python/0.10.0`.
EOF
}

Expand Down
Loading