@or3/intern-client 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/dist/index.js +1362 -0
- package/package.json +34 -0
- package/src/client.ts +676 -0
- package/src/errors.ts +131 -0
- package/src/index.ts +6 -0
- package/src/protocol.ts +692 -0
- package/src/redaction.ts +114 -0
- package/src/sse.ts +151 -0
- package/src/transport.ts +915 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# `@or3/intern-client`
|
|
2
|
+
|
|
3
|
+
Framework-free TypeScript contract and transport for the authenticated
|
|
4
|
+
`or3-intern service` API. The package uses only web-platform primitives and is
|
|
5
|
+
owned beside the Go service contract.
|
|
6
|
+
|
|
7
|
+
## Public boundaries
|
|
8
|
+
|
|
9
|
+
- `createInternTransport` provides generic JSON requests and SSE streams for
|
|
10
|
+
compatibility with any current service route.
|
|
11
|
+
- `createInternClient` provides typed health, readiness, capabilities, runner
|
|
12
|
+
discovery, runner-chat session listing/creation/turns, approval, artifact,
|
|
13
|
+
cancellation, and secure-pairing operations.
|
|
14
|
+
- Protocol parsers validate stable fields while retaining unknown response
|
|
15
|
+
fields for forward compatibility.
|
|
16
|
+
- `InternClientError`, `InternUnavailableError`, `toInternResult`, and
|
|
17
|
+
`requireInternCapability` provide typed failure boundaries.
|
|
18
|
+
|
|
19
|
+
Consumers inject the host URL, Fetch implementation, and asynchronous auth
|
|
20
|
+
resolver. Credentials are added only as headers, never as URL parameters.
|
|
21
|
+
Pairing explicitly disables auth resolution because its one-time secret belongs
|
|
22
|
+
in the JSON body.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const client = createInternClient({
|
|
26
|
+
baseUrl: () => selectedHost.baseUrl,
|
|
27
|
+
resolveAuth: async ({ method, path, requireAuth }) =>
|
|
28
|
+
requireAuth
|
|
29
|
+
? {
|
|
30
|
+
token: await credentials.tokenFor({ method, path }),
|
|
31
|
+
headers: { 'X-Or3-Auth-Method': 'paired-device' },
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`streamTurn` reconnects with bounded exponential backoff, resumes with
|
|
38
|
+
`after_seq`, and deduplicates replayed persisted events. Generic
|
|
39
|
+
`transport.stream` exposes configurable cursor, `Last-Event-ID`, terminal, and
|
|
40
|
+
dedupe hooks for other SSE routes.
|
|
41
|
+
|
|
42
|
+
Active sessions can be rehydrated without discovering unrelated host work:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const sessions = await client.listSessions({
|
|
46
|
+
appSessionKeyPrefix: `or3-chat:${workspaceScope}:`,
|
|
47
|
+
limit: 50,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The service matches this prefix literally, orders by `updated_at` descending,
|
|
52
|
+
and rejects limits above 100.
|
|
53
|
+
|
|
54
|
+
`client.listTurns(sessionId, { limit })` returns the newest bounded turn window
|
|
55
|
+
in chronological order, so rehydration retains the current/active tail without
|
|
56
|
+
reversing timeline rendering.
|
|
57
|
+
|
|
58
|
+
Runner-chat actions are fail-closed. Consumers should read the canonical
|
|
59
|
+
`chat_capabilities.cancel`, `chat_capabilities.approvalDecisions`, and
|
|
60
|
+
`chat_capabilities.customCwd` booleans. Approval decisions also require the
|
|
61
|
+
host capability report to advertise an enabled and available approval broker.
|
|
62
|
+
|
|
63
|
+
## Verification
|
|
64
|
+
|
|
65
|
+
From this directory:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bun test
|
|
69
|
+
bun build ./src/index.ts --target=browser --outdir=/tmp/or3-intern-client-build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The shared Go fixtures are checked from the repository root:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
go test ./cmd/or3-intern -run 'TestOr3NetCompatibilityFixtures|TestServiceRouteContracts_CurrentAppUsageRoutesStayRegistered'
|
|
76
|
+
```
|