diff --git a/CHANGELOG.md b/CHANGELOG.md index 478b4c0..b63bf21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ All notable changes to the Wraith Protocol SDK will be documented in this file. ### Fixed +- **Companion packages import the agent API from `@wraith-protocol/sdk-agent`** (issue #249): `@wraith-protocol/sdk-vue`, `@wraith-protocol/sdk-svelte` and `@wraith-protocol/sdk-solid` imported `Wraith`, `WraithAgent` and `Chain` from the core `@wraith-protocol/sdk`, but #193 moved those exports to `@wraith-protocol/sdk-agent`, so importing any of the three on the server threw `SyntaxError: The requested module '@wraith-protocol/sdk' does not provide an export named 'Chain'` before any code ran. Each companion now imports those names from `@wraith-protocol/sdk-agent` and declares it as a workspace dependency, and the framework SSR import smoke check no longer lists the three as known failures. - **Stellar `findStrictReceivePath` reads and validates real Horizon responses** (issue #236): the function now reads paths from Horizon's `_embedded.records` envelope instead of expecting a bare array, and sends the query parameters Horizon accepts (`source_assets` with `destination_asset_type` / `_code` / `_issuer`; the old `destination_asset` and dummy `source_account` made every live request fail with HTTP 400). - Every record is validated before use: amounts, asset type / code / issuer, that the source and destination assets and `destination_amount` match the request, and a path of at most 5 hops. The body is read as a stream and abandoned past 256 KiB; responses over 100 records are rejected. The cheapest valid record is returned. An invalid `destAmount` now throws before the request, and the request uses the Horizon client's default timeouts (`RPCTimeoutError`). - New `HorizonResponseError` (`WRAITH/NETWORK/HORIZON_RESPONSE`), exported from the package root, carries the URL and the rejected field. A non-2xx status now throws `RPCRequestError` instead of a plain `Error`. diff --git a/package.json b/package.json index 51b9a50..7bbd297 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "node": ">=20" }, "scripts": { - "build": "tsup", + "build": "tsup && pnpm --filter @wraith-protocol/sdk-agent build", "test": "vitest run --exclude 'test/chains/stellar/properties.test.ts' --exclude 'test/leaks/scan-leak.test.ts' --exclude 'test/leaks/heap-snapshot.test.ts' && pnpm --filter @wraith-protocol/sdk-svelte test", "docs": "typedoc", "test:exports": "node test/smoke/run.mjs", diff --git a/packages/sdk-solid/package.json b/packages/sdk-solid/package.json index a5231f6..5d4e595 100644 --- a/packages/sdk-solid/package.json +++ b/packages/sdk-solid/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@wraith-protocol/sdk": "workspace:*", + "@wraith-protocol/sdk-agent": "workspace:*", "solid-js": "^1.9.0" }, "peerDependencies": { diff --git a/packages/sdk-solid/src/primitives/createActivity.ts b/packages/sdk-solid/src/primitives/createActivity.ts index 048c186..99f5fe7 100644 --- a/packages/sdk-solid/src/primitives/createActivity.ts +++ b/packages/sdk-solid/src/primitives/createActivity.ts @@ -1,6 +1,6 @@ import { createSignal } from 'solid-js'; -import { Wraith, WraithAgent, Chain } from '@wraith-protocol/sdk'; -import type { WraithConfig, AgentConfig, AgentInfo, ChatResponse } from '@wraith-protocol/sdk'; +import { Wraith, WraithAgent, Chain } from '@wraith-protocol/sdk-agent'; +import type { WraithConfig, AgentConfig, AgentInfo, ChatResponse } from '@wraith-protocol/sdk-agent'; /** * Solid primitive for managing Wraith agent activity (chat, balance, agent lifecycle). diff --git a/packages/sdk-solid/test/createActivity.test.ts b/packages/sdk-solid/test/createActivity.test.ts index b2c6db5..0b058e6 100644 --- a/packages/sdk-solid/test/createActivity.test.ts +++ b/packages/sdk-solid/test/createActivity.test.ts @@ -23,7 +23,7 @@ const mockClient = vi.hoisted(() => ({ listAgents: vi.fn().mockResolvedValue([mockAgentInfo]), })); -vi.mock('@wraith-protocol/sdk', () => ({ +vi.mock('@wraith-protocol/sdk-agent', () => ({ Wraith: vi.fn().mockImplementation(() => mockClient), WraithAgent: vi.fn(), Chain: { @@ -34,7 +34,7 @@ vi.mock('@wraith-protocol/sdk', () => ({ })); // Grab mocked references once (safe because vi.mock hoists before imports) -import { Wraith as MockWraith } from '@wraith-protocol/sdk'; +import { Wraith as MockWraith } from '@wraith-protocol/sdk-agent'; describe('createActivity', () => { beforeEach(() => { diff --git a/packages/sdk-solid/tsup.config.ts b/packages/sdk-solid/tsup.config.ts index d238c1f..8ddcd2a 100644 --- a/packages/sdk-solid/tsup.config.ts +++ b/packages/sdk-solid/tsup.config.ts @@ -9,5 +9,5 @@ export default defineConfig({ splitting: true, clean: true, treeshake: true, - external: ['solid-js', '@wraith-protocol/sdk'], + external: ['solid-js', '@wraith-protocol/sdk', '@wraith-protocol/sdk-agent'], }); diff --git a/packages/sdk-svelte/package.json b/packages/sdk-svelte/package.json index 8e3c9ab..92a9e2d 100644 --- a/packages/sdk-svelte/package.json +++ b/packages/sdk-svelte/package.json @@ -22,7 +22,8 @@ "clean": "rm -rf dist" }, "dependencies": { - "@wraith-protocol/sdk": "workspace:*" + "@wraith-protocol/sdk": "workspace:*", + "@wraith-protocol/sdk-agent": "workspace:*" }, "peerDependencies": { "@stellar/stellar-sdk": "^13.1.0", diff --git a/packages/sdk-svelte/src/primitives/useWraith.ts b/packages/sdk-svelte/src/primitives/useWraith.ts index 35cddc7..e77c232 100644 --- a/packages/sdk-svelte/src/primitives/useWraith.ts +++ b/packages/sdk-svelte/src/primitives/useWraith.ts @@ -1,6 +1,6 @@ import { writable, readonly, get } from 'svelte/store'; -import { Wraith, WraithAgent, Chain } from '@wraith-protocol/sdk'; -import type { WraithConfig, AgentConfig, AgentInfo, ChatResponse } from '@wraith-protocol/sdk'; +import { Wraith, WraithAgent, Chain } from '@wraith-protocol/sdk-agent'; +import type { WraithConfig, AgentConfig, AgentInfo, ChatResponse } from '@wraith-protocol/sdk-agent'; export function useWraith(config?: WraithConfig) { const _client = writable(null); diff --git a/packages/sdk-svelte/test/useWraith.test.ts b/packages/sdk-svelte/test/useWraith.test.ts index 6210b5c..50df95d 100644 --- a/packages/sdk-svelte/test/useWraith.test.ts +++ b/packages/sdk-svelte/test/useWraith.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; -vi.mock('@wraith-protocol/sdk', () => { +vi.mock('@wraith-protocol/sdk-agent', () => { const mockAgent = { info: { id: 'agent-1', diff --git a/packages/sdk-svelte/tsup.config.ts b/packages/sdk-svelte/tsup.config.ts index ab927b6..3390cab 100644 --- a/packages/sdk-svelte/tsup.config.ts +++ b/packages/sdk-svelte/tsup.config.ts @@ -9,5 +9,5 @@ export default defineConfig({ splitting: true, clean: true, treeshake: true, - external: ['svelte', '@wraith-protocol/sdk'], + external: ['svelte', '@wraith-protocol/sdk', '@wraith-protocol/sdk-agent'], }); diff --git a/packages/sdk-vue/package.json b/packages/sdk-vue/package.json index 25642f1..9cf6c49 100644 --- a/packages/sdk-vue/package.json +++ b/packages/sdk-vue/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@wraith-protocol/sdk": "workspace:*", + "@wraith-protocol/sdk-agent": "workspace:*", "vue": "^3.5.0" }, "devDependencies": { diff --git a/packages/sdk-vue/src/composables/useWraith.ts b/packages/sdk-vue/src/composables/useWraith.ts index b7b5956..dc59a93 100644 --- a/packages/sdk-vue/src/composables/useWraith.ts +++ b/packages/sdk-vue/src/composables/useWraith.ts @@ -7,7 +7,7 @@ import { type AgentConfig, type AgentInfo, type ChatResponse, -} from '@wraith-protocol/sdk'; +} from '@wraith-protocol/sdk-agent'; export function useWraith(config?: WraithConfig) { const client: Ref = ref(null); diff --git a/packages/sdk-vue/test/useWraith.test.ts b/packages/sdk-vue/test/useWraith.test.ts index 961eabf..da86bff 100644 --- a/packages/sdk-vue/test/useWraith.test.ts +++ b/packages/sdk-vue/test/useWraith.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { useWraith } from '../src/composables/useWraith'; -vi.mock('@wraith-protocol/sdk', () => { +vi.mock('@wraith-protocol/sdk-agent', () => { const mockAgent = { info: { id: 'agent-1', name: 'test-agent', chains: [], addresses: {}, metaAddresses: {} }, chat: vi.fn(), diff --git a/packages/sdk-vue/tsup.config.ts b/packages/sdk-vue/tsup.config.ts index 2b5a8ab..84619fd 100644 --- a/packages/sdk-vue/tsup.config.ts +++ b/packages/sdk-vue/tsup.config.ts @@ -9,5 +9,5 @@ export default defineConfig({ splitting: true, clean: true, treeshake: true, - external: ['vue', '@wraith-protocol/sdk'], + external: ['vue', '@wraith-protocol/sdk', '@wraith-protocol/sdk-agent'], }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47c63e1..88976b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -594,6 +594,9 @@ importers: '@wraith-protocol/sdk': specifier: workspace:* version: link:../.. + '@wraith-protocol/sdk-agent': + specifier: workspace:* + version: link:../sdk-agent solid-js: specifier: ^1.9.0 version: 1.9.15 @@ -625,6 +628,9 @@ importers: '@wraith-protocol/sdk': specifier: workspace:* version: link:../.. + '@wraith-protocol/sdk-agent': + specifier: workspace:* + version: link:../sdk-agent devDependencies: '@stellar/stellar-sdk': specifier: ^13.1.0 @@ -659,6 +665,9 @@ importers: '@wraith-protocol/sdk': specifier: workspace:* version: link:../.. + '@wraith-protocol/sdk-agent': + specifier: workspace:* + version: link:../sdk-agent vue: specifier: ^3.5.0 version: 3.5.39(typescript@5.9.3) @@ -3251,6 +3260,7 @@ packages: '@wraith-protocol/sdk@file:': resolution: {directory: '', type: directory} + engines: {node: '>=20'} peerDependencies: '@solana/web3.js': ^1.95.0 '@stellar/stellar-sdk': ^13.1.0 diff --git a/scripts/compat/verify-ssr-imports.mjs b/scripts/compat/verify-ssr-imports.mjs index c949379..3ae4999 100644 --- a/scripts/compat/verify-ssr-imports.mjs +++ b/scripts/compat/verify-ssr-imports.mjs @@ -37,17 +37,14 @@ const SCENARIOS = { '@wraith-protocol/sdk-vue': 'vue', }; -// Companions whose server import is already broken, with the error it fails -// with. `Wraith`, `WraithAgent` and `Chain` moved from `@wraith-protocol/sdk` to -// `@wraith-protocol/sdk-agent` in #193, but these packages still import them -// from the core, so Node refuses to link them. An entry must keep failing with -// its message: once the import is fixed this check fails until the entry is -// removed, which turns the SSR render back on for that package. -const KNOWN_IMPORT_FAILURES = { - '@wraith-protocol/sdk-solid': /does not provide an export named '(Wraith|WraithAgent|Chain)'/, - '@wraith-protocol/sdk-svelte': /does not provide an export named '(Wraith|WraithAgent|Chain)'/, - '@wraith-protocol/sdk-vue': /does not provide an export named '(Wraith|WraithAgent|Chain)'/, -}; +// Companions whose server import is known to be broken, mapped to the error it +// fails with, so a pre-existing failure does not mask a new one. Empty today: +// the Vue, Svelte and Solid companions import `Wraith`, `WraithAgent` and +// `Chain` from `@wraith-protocol/sdk-agent` (where #193 moved them) and link +// cleanly again. An entry must keep failing with its message: once the import +// is fixed this check fails until the entry is removed, which turns the SSR +// render back on for that package. +const KNOWN_IMPORT_FAILURES = {}; let failed = 0;