@archastro/sdk 0.5.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +25 -0
  2. package/dist/app-session.d.ts +66 -0
  3. package/dist/app-session.d.ts.map +1 -0
  4. package/dist/app-session.js +158 -0
  5. package/dist/app-session.js.map +1 -0
  6. package/dist/channels/api_chat_channel.d.ts +4 -0
  7. package/dist/channels/api_chat_channel.d.ts.map +1 -1
  8. package/dist/channels/api_chat_channel.js +9 -1
  9. package/dist/channels/api_chat_channel.js.map +1 -1
  10. package/dist/client.d.ts +4 -0
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +6 -1
  13. package/dist/client.js.map +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.native.d.ts +14 -0
  19. package/dist/index.native.d.ts.map +1 -0
  20. package/dist/index.native.js +14 -0
  21. package/dist/index.native.js.map +1 -0
  22. package/dist/passwordless.d.ts +49 -0
  23. package/dist/passwordless.d.ts.map +1 -0
  24. package/dist/passwordless.js +70 -0
  25. package/dist/passwordless.js.map +1 -0
  26. package/dist/phx_channel/socket.d.ts.map +1 -1
  27. package/dist/phx_channel/socket.js +10 -22
  28. package/dist/phx_channel/socket.js.map +1 -1
  29. package/dist/phx_channel/websocket.d.ts +19 -0
  30. package/dist/phx_channel/websocket.d.ts.map +1 -0
  31. package/dist/phx_channel/websocket.js +28 -0
  32. package/dist/phx_channel/websocket.js.map +1 -0
  33. package/dist/phx_channel/websocket.native.d.ts +17 -0
  34. package/dist/phx_channel/websocket.native.d.ts.map +1 -0
  35. package/dist/phx_channel/websocket.native.js +16 -0
  36. package/dist/phx_channel/websocket.native.js.map +1 -0
  37. package/dist/platform-socket.d.ts +20 -0
  38. package/dist/platform-socket.d.ts.map +1 -0
  39. package/dist/platform-socket.js +25 -0
  40. package/dist/platform-socket.js.map +1 -0
  41. package/dist/runtime/http-client.d.ts +17 -0
  42. package/dist/runtime/http-client.d.ts.map +1 -1
  43. package/dist/runtime/http-client.js +123 -4
  44. package/dist/runtime/http-client.js.map +1 -1
  45. package/dist/runtime/url.d.ts +15 -0
  46. package/dist/runtime/url.d.ts.map +1 -0
  47. package/dist/runtime/url.js +34 -0
  48. package/dist/runtime/url.js.map +1 -0
  49. package/dist/types/ai.d.ts +271 -2
  50. package/dist/types/ai.d.ts.map +1 -1
  51. package/dist/types/ai.js +51 -1
  52. package/dist/types/ai.js.map +1 -1
  53. package/dist/types/chat.d.ts +142 -0
  54. package/dist/types/chat.d.ts.map +1 -1
  55. package/dist/types/common.d.ts +88 -27
  56. package/dist/types/common.d.ts.map +1 -1
  57. package/dist/types/common.js +12 -6
  58. package/dist/types/common.js.map +1 -1
  59. package/dist/types/config.d.ts +6 -6
  60. package/dist/types/teams.d.ts +12 -0
  61. package/dist/types/teams.d.ts.map +1 -1
  62. package/dist/types/threads.d.ts +10 -0
  63. package/dist/types/threads.d.ts.map +1 -1
  64. package/dist/v1/resources/activity_feed.d.ts +1 -0
  65. package/dist/v1/resources/activity_feed.d.ts.map +1 -1
  66. package/dist/v1/resources/activity_feed.js +1 -1
  67. package/dist/v1/resources/agents.d.ts +3 -1
  68. package/dist/v1/resources/agents.d.ts.map +1 -1
  69. package/dist/v1/resources/agents.js +3 -2
  70. package/dist/v1/resources/agents.js.map +1 -1
  71. package/dist/v1/resources/ai.d.ts +81 -3
  72. package/dist/v1/resources/ai.d.ts.map +1 -1
  73. package/dist/v1/resources/ai.js +26 -3
  74. package/dist/v1/resources/ai.js.map +1 -1
  75. package/dist/v1/resources/config.d.ts +8 -0
  76. package/dist/v1/resources/config.d.ts.map +1 -1
  77. package/dist/v1/resources/config.js +5 -1
  78. package/dist/v1/resources/config.js.map +1 -1
  79. package/dist/v1/resources/solutions.d.ts +11 -7
  80. package/dist/v1/resources/solutions.d.ts.map +1 -1
  81. package/dist/v1/resources/solutions.js +12 -8
  82. package/dist/v1/resources/solutions.js.map +1 -1
  83. package/dist/v1/resources/teams.d.ts +3 -0
  84. package/dist/v1/resources/teams.d.ts.map +1 -1
  85. package/dist/v1/resources/teams.js +1 -1
  86. package/dist/v1/resources/threads.d.ts +24 -4
  87. package/dist/v1/resources/threads.d.ts.map +1 -1
  88. package/dist/v1/resources/threads.js +37 -5
  89. package/dist/v1/resources/threads.js.map +1 -1
  90. package/dist/v1/resources/users.d.ts +2 -0
  91. package/dist/v1/resources/users.d.ts.map +1 -1
  92. package/dist/v1/resources/users.js +1 -1
  93. package/docs/authentication.md +91 -0
  94. package/docs/react-native.md +118 -0
  95. package/docs/scenarios.md +57 -0
  96. package/package.json +28 -6
@@ -0,0 +1,91 @@
1
+ ---
2
+ title: Authentication
3
+ group: Guides
4
+ ---
5
+
6
+ # Authentication
7
+
8
+ `@archastro/sdk` supports four auth shapes. Pick the one that matches who the
9
+ process is acting as.
10
+
11
+ ## Mobile / SPA durable app session
12
+
13
+ Use this for React Native or browser apps that sign users in (passwordless OTP
14
+ or other flows) and need access tokens to auto-refresh across restarts.
15
+
16
+ ```ts
17
+ import { PlatformClient, type SessionStorage } from "@archastro/sdk";
18
+
19
+ const client = PlatformClient.forApp({
20
+ publishableKey: process.env.ARCHASTRO_PUBLISHABLE_KEY ?? "",
21
+ baseUrl: process.env.ARCHASTRO_PLATFORM_BASE_URL, // optional
22
+ storage, // your SecureStore / AsyncStorage adapter
23
+ });
24
+
25
+ await client.restore();
26
+ // login → client.passwordless… → client.signIn(tokens, user)
27
+ const me = await client.users.me();
28
+ ```
29
+
30
+ On 401 the client exchanges the refresh token via `POST /api/v1/auth/refresh`,
31
+ updates storage, and retries. See [React Native](./react-native.md).
32
+
33
+ ## Static user access token
34
+
35
+ Use this when a user has already signed in elsewhere and your code only has a
36
+ publishable API key plus a short-lived access token (no durable refresh).
37
+
38
+ ```ts
39
+ import { PlatformClient } from "@archastro/sdk";
40
+
41
+ const client = PlatformClient.withToken(
42
+ process.env.ARCHASTRO_API_KEY ?? "",
43
+ process.env.ARCHASTRO_ACCESS_TOKEN ?? "",
44
+ );
45
+
46
+ const me = await client.users.me();
47
+ console.log(me.id, me.email);
48
+ ```
49
+
50
+ ## Org bot or worker
51
+
52
+ Use this when a backend process should act as an org-owned system user. The
53
+ token should be an app-scoped user token created for that bot or worker.
54
+
55
+ ```ts
56
+ import { PlatformClient } from "@archastro/sdk";
57
+
58
+ const client = new PlatformClient({
59
+ accessToken: process.env.ARCHASTRO_ACCESS_TOKEN,
60
+ });
61
+
62
+ const me = await client.users.me();
63
+ console.log(me.id);
64
+ ```
65
+
66
+ ## Email/password (scripts)
67
+
68
+ ```ts
69
+ const client = await PlatformClient.withCredentials(
70
+ publishableKey,
71
+ email,
72
+ password,
73
+ baseUrl,
74
+ );
75
+ ```
76
+
77
+ Wires in-memory refresh only — tokens are not persisted. Prefer `forApp` for
78
+ long-lived clients.
79
+
80
+ ## Local or staging targets
81
+
82
+ The SDK defaults to `https://platform.archastro.ai`. Override `baseUrl` only
83
+ when targeting local development, staging, or another non-production gateway.
84
+
85
+ ```ts
86
+ const client = PlatformClient.forApp({
87
+ publishableKey: process.env.ARCHASTRO_PUBLISHABLE_KEY ?? "",
88
+ baseUrl: process.env.ARCHASTRO_PLATFORM_BASE_URL,
89
+ storage,
90
+ });
91
+ ```
@@ -0,0 +1,118 @@
1
+ ---
2
+ title: React Native
3
+ group: Guides
4
+ ---
5
+
6
+ # React Native / Expo
7
+
8
+ `@archastro/sdk` works in React Native and Expo without Node polyfills
9
+ (`events`, `ws`, etc.). The package ships a Metro-resolved native entry and a
10
+ `.native` WebSocket factory that uses the global `WebSocket` only.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @archastro/sdk
16
+ ```
17
+
18
+ `zod` is a normal dependency and is resolved by Metro from the package. The
19
+ optional `ws` package is **Node-only** and is not required in RN (Metro loads
20
+ `phx_channel/websocket.native.js` instead).
21
+
22
+ ## One client: `PlatformClient.forApp`
23
+
24
+ Provide durable storage (Expo SecureStore or AsyncStorage) and a publishable
25
+ key. Session lifecycle, passwordless OTP, auto-refresh, and REST all live on
26
+ the same `PlatformClient` instance:
27
+
28
+ ```ts
29
+ import {
30
+ PlatformClient,
31
+ ApiChatChannel,
32
+ type SessionStorage,
33
+ type AppSession,
34
+ } from "@archastro/sdk";
35
+ import * as SecureStore from "expo-secure-store";
36
+
37
+ // Only SessionStorage is a public type you implement — OTP, refresh, and
38
+ // sockets are methods on the client returned by forApp.
39
+ const storage: SessionStorage = {
40
+ async load() {
41
+ const raw = await SecureStore.getItemAsync("archastro_session");
42
+ return raw ? (JSON.parse(raw) as AppSession) : null;
43
+ },
44
+ async save(session) {
45
+ await SecureStore.setItemAsync("archastro_session", JSON.stringify(session));
46
+ },
47
+ async clear() {
48
+ await SecureStore.deleteItemAsync("archastro_session");
49
+ },
50
+ };
51
+
52
+ const client = PlatformClient.forApp({
53
+ baseUrl: process.env.EXPO_PUBLIC_API_BASE_URL!,
54
+ publishableKey: process.env.EXPO_PUBLIC_PUBLISHABLE_KEY!,
55
+ storage,
56
+ });
57
+
58
+ await client.restore();
59
+
60
+ // Passwordless OTP (behind the client — not a free-standing auth class)
61
+ await client.passwordless.register({
62
+ email: "you@company.com",
63
+ full_name: "You",
64
+ alias: "you",
65
+ });
66
+ // or requestLoginCode on existing accounts
67
+
68
+ const { tokens, user } = await client.passwordless.verifyCode({
69
+ email: "you@company.com",
70
+ code: "123456",
71
+ });
72
+ await client.signIn(tokens, user as AppSession["user"]);
73
+
74
+ // Typed REST — 401 auto-refreshes using the stored refresh token
75
+ const me = await client.users.me();
76
+ const agents = await client.agents.list();
77
+ ```
78
+
79
+ ## Realtime chat
80
+
81
+ ```ts
82
+ const socket = client.createSocket(); // uses current access token + publishable key
83
+ await socket.connect();
84
+
85
+ const channel = await ApiChatChannel.joinUserThread(socket, threadId, {
86
+ limit: 50,
87
+ });
88
+ await channel.apiChatPostMessage({ content: "Hello" });
89
+ ```
90
+
91
+ ## What the SDK needs from RN
92
+
93
+ | Need | Source |
94
+ |---|---|
95
+ | HTTP | global `fetch` |
96
+ | WebSocket | global `WebSocket` |
97
+ | Token persistence | your `SessionStorage` |
98
+ | API base URL | e.g. `http://localhost:4005` (sim) or production |
99
+ | Publishable key | `x-archastro-api-key` header |
100
+
101
+ ## Local monorepo (file: link)
102
+
103
+ When developing against a local `archastro-js` checkout:
104
+
105
+ ```json
106
+ "@archastro/sdk": "file:../../../archastro-js/packages/sdk"
107
+ ```
108
+
109
+ Point Metro `watchFolders` at the SDK package and rebuild after SDK changes:
110
+
111
+ ```sh
112
+ cd packages/sdk && npm run build
113
+ ```
114
+
115
+ ## iOS simulator localhost
116
+
117
+ The iOS simulator can reach the host via `http://localhost:PORT`. Physical
118
+ devices need your machine LAN IP instead.
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: Integration Scenarios
3
+ group: Guides
4
+ ---
5
+
6
+ # Integration Scenarios
7
+
8
+ These examples show the SDK shape for common integrations. They were smoke-tested
9
+ against the local platform dev harness with org-user tokens.
10
+
11
+ ## Read The Current User
12
+
13
+ Use `users.me()` to validate that a token is usable and to discover the current
14
+ actor.
15
+
16
+ ```ts
17
+ import { PlatformClient } from "@archastro/sdk";
18
+
19
+ const client = PlatformClient.withToken(
20
+ process.env.ARCHASTRO_API_KEY ?? "",
21
+ process.env.ARCHASTRO_ACCESS_TOKEN ?? "",
22
+ );
23
+
24
+ const me = await client.users.me();
25
+ console.log(me.id, me.email);
26
+ ```
27
+
28
+ ## List Teams
29
+
30
+ Use resource collections directly from the client. List responses are typed and
31
+ follow the API response shape for that resource.
32
+
33
+ ```ts
34
+ const teams = await client.teams.list();
35
+ console.log(teams);
36
+ ```
37
+
38
+ ## Create An Agent
39
+
40
+ Use `agents.create()` to provision an agent owned by the current user, org, or
41
+ team context. Store the returned `id` if you need to fetch or update it later.
42
+
43
+ ```ts
44
+ const agent = await client.agents.create({
45
+ name: "Support triage",
46
+ identity: "You triage support requests and keep replies concise.",
47
+ });
48
+
49
+ console.log(agent.id, agent.name);
50
+ ```
51
+
52
+ For cleanup in tests and scripts:
53
+
54
+ ```ts
55
+ await client.agents.delete(agent.id);
56
+ ```
57
+
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@archastro/sdk",
3
- "version": "0.5.3",
4
- "description": "TypeScript SDK for the ArchAstro Platform API",
3
+ "version": "0.7.0",
4
+ "description": "TypeScript SDK for the ArchAstro Platform API (Node, browser, React Native)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "react-native": "dist/index.native.js",
9
+ "browser": "dist/index.js",
8
10
  "files": [
9
- "dist"
11
+ "dist",
12
+ "docs"
10
13
  ],
11
14
  "scripts": {
12
15
  "build": "tsc",
@@ -24,16 +27,35 @@
24
27
  "directory": "packages/sdk"
25
28
  },
26
29
  "dependencies": {
27
- "ws": "^8.17.0",
28
30
  "zod": "^3.22.0"
29
31
  },
30
32
  "devDependencies": {
31
- "@archastro/channel-harness": "^0.1.0",
33
+ "@archastro/channel-harness": "^0.4.0",
32
34
  "@stoplight/prism-cli": "^5.14.2",
33
35
  "@types/node": "^22.0.0",
34
36
  "@types/ws": "^8.5.0",
35
37
  "typedoc": "^0.28.19",
36
38
  "typescript": "^5.4.0",
37
- "vitest": "^4.1.3"
39
+ "vitest": "^4.1.3",
40
+ "ws": "^8.17.0"
41
+ },
42
+ "keywords": [
43
+ "archastro",
44
+ "sdk",
45
+ "react-native",
46
+ "expo",
47
+ "phoenix",
48
+ "typescript"
49
+ ],
50
+ "optionalDependencies": {
51
+ "ws": "^8.17.0"
52
+ },
53
+ "peerDependencies": {
54
+ "ws": "^8.17.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "ws": {
58
+ "optional": true
59
+ }
38
60
  }
39
61
  }