@ellipsis-dev/sdk 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ellipsis Dev, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @ellipsis-dev/sdk
2
+
3
+ TypeScript SDK for the [Ellipsis](https://www.ellipsis.dev) agents platform.
4
+ Three subpath exports, all dependency-free at runtime:
5
+
6
+ - **`@ellipsis-dev/sdk`** — generated `/v1` REST types + `EllipsisClient`, a thin
7
+ typed client over an injected `fetchJson`.
8
+ - **`@ellipsis-dev/sdk/stream`** — the session stream WebSocket client
9
+ (`streamSession`): protocol negotiation, heartbeat liveness,
10
+ reconnect-with-backoff, and lossless resume via the `after_seq` record
11
+ cursor. Transport is an injected `openSocket`, so the same machinery runs in
12
+ a browser, a terminal, or a server.
13
+ - **`@ellipsis-dev/sdk/store`** — `SessionTranscriptStore`
14
+ (`subscribe`/`getSnapshot`, shaped for React's `useSyncExternalStore` but
15
+ framework-free) plus the pure shaping helpers that turn raw session records
16
+ into renderable transcript items and chat turns.
17
+
18
+ ## Types are generated, never hand-written
19
+
20
+ - `schema/frames.schema.json` — JSON Schema of the WebSocket frames, produced
21
+ from the server's frame models.
22
+ - `schema/openapi.v1.json` — the OpenAPI document for the SDK's REST surface.
23
+
24
+ `pnpm gen` derives `src/generated/` from those documents
25
+ (`json-schema-to-typescript` + `openapi-typescript`). CI regenerates and
26
+ diffs, and the server's own test suite pins the committed schema documents to
27
+ its models, so types cannot drift from the deployed API in either direction.
28
+
29
+ `test/fixtures/golden_stream.json` is a frame sequence recorded from the real
30
+ server stream loop (ids and timestamps normalized); the store's tests replay
31
+ it, so client behavior is validated against real emissions, not hand-written
32
+ examples.
33
+
34
+ ## Protocol
35
+
36
+ The stream protocol (frame taxonomy, delivery classes, resume/close-code
37
+ contract) is documented at https://www.ellipsis.dev/docs. The compatibility
38
+ rule clients must follow: **ignore unknown frame types and unknown
39
+ `source`/`record_type`/`kind` values** — additive server changes are not a
40
+ protocol break.
@@ -0,0 +1,22 @@
1
+ import { A as AgentSessionWire, L as ListSessionRecordsResponse, a as ListSessionTurnsResponse, S as SessionMessageWire } from './types-BRE4NMnS.js';
2
+ export { b as AgentSessionExitStatus, c as AgentSessionPr, d as AgentSessionSource, e as AgentSessionStatus, f as AgentTurn, g as AgentTurnStatus, h as AttributionType, B as BudgetSource, D as DefaultResolution, i as DeltaFrame, j as DoneFrame, E as ErrorFrame, G as GithubAccountSnippet, k as GithubAccountType, H as Harness, l as HeartbeatFrame, M as MessagesFrame, m as ModelTokensInfo, P as ParentKind, R as RecordsAppendFrame, n as SendSessionMessageRequest, o as SessionFrame, p as SessionLiveness, q as SessionMessageStatus, r as SessionRecordWire, s as SessionState, t as SessionStreamFrame, u as SessionSurface, v as SnapshotFrame, w as StreamFrame, T as TokensInfo, x as TurnTokensInfo, y as components, z as paths } from './types-BRE4NMnS.js';
3
+
4
+ type FetchJson = (path: string, init?: {
5
+ method?: string;
6
+ body?: unknown;
7
+ }) => Promise<unknown>;
8
+ declare class EllipsisClient {
9
+ private readonly fetchJson;
10
+ constructor(fetchJson: FetchJson);
11
+ getSession(sessionId: string): Promise<AgentSessionWire>;
12
+ getSessionRecords(sessionId: string, options?: {
13
+ afterSeq?: number;
14
+ limit?: number;
15
+ }): Promise<ListSessionRecordsResponse>;
16
+ getSessionTurns(sessionId: string): Promise<ListSessionTurnsResponse>;
17
+ sendSessionMessage(sessionId: string, message: string, options?: {
18
+ idempotencyKey?: string;
19
+ }): Promise<SessionMessageWire>;
20
+ }
21
+
22
+ export { AgentSessionWire, EllipsisClient, type FetchJson, ListSessionRecordsResponse, ListSessionTurnsResponse, SessionMessageWire };
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // src/client.ts
2
+ var EllipsisClient = class {
3
+ constructor(fetchJson) {
4
+ this.fetchJson = fetchJson;
5
+ }
6
+ fetchJson;
7
+ // The enriched public session (§4.1) — the same lean wire shape the
8
+ // stream's session frames carry.
9
+ async getSession(sessionId) {
10
+ return await this.fetchJson(
11
+ `/v1/sessions/${encodeURIComponent(sessionId)}`
12
+ );
13
+ }
14
+ // The record log + inbox messages (§4.3). Bare call = the full transcript;
15
+ // pass afterSeq/limit to page (limit max 1000, `has_more` signals more).
16
+ async getSessionRecords(sessionId, options = {}) {
17
+ const params = new URLSearchParams();
18
+ if (options.afterSeq != null)
19
+ params.set("after_seq", String(options.afterSeq));
20
+ if (options.limit != null) params.set("limit", String(options.limit));
21
+ const query = params.toString();
22
+ return await this.fetchJson(
23
+ `/v1/sessions/${encodeURIComponent(sessionId)}/records` + (query ? `?${query}` : "")
24
+ );
25
+ }
26
+ // The session's turns — the structural conversation history (message ->
27
+ // response exchanges with status/cost).
28
+ async getSessionTurns(sessionId) {
29
+ return await this.fetchJson(
30
+ `/v1/sessions/${encodeURIComponent(sessionId)}/turns`
31
+ );
32
+ }
33
+ // Send a message into the session's inbox (§4.2). Returns the created (or,
34
+ // on an idempotent retry, the original) inbox row — clients key optimistic
35
+ // echo chips on its id. `idempotencyKey` makes retries safe per
36
+ // (session, key); a closed or non-interactive session rejects with a 409
37
+ // (surface the server's curated copy).
38
+ async sendSessionMessage(sessionId, message, options = {}) {
39
+ return await this.fetchJson(
40
+ `/v1/sessions/${encodeURIComponent(sessionId)}/messages`,
41
+ {
42
+ method: "POST",
43
+ body: {
44
+ message,
45
+ ...options.idempotencyKey != null ? { idempotency_key: options.idempotencyKey } : {}
46
+ }
47
+ }
48
+ );
49
+ }
50
+ };
51
+ export {
52
+ EllipsisClient
53
+ };
@@ -0,0 +1,145 @@
1
+ import { r as SessionRecordWire, A as AgentSessionWire, S as SessionMessageWire, w as StreamFrame } from '../types-BRE4NMnS.js';
2
+
3
+ interface ChatToolNode {
4
+ key: string;
5
+ kind: 'tool';
6
+ name: string;
7
+ input: Record<string, unknown> | null;
8
+ summary: string;
9
+ result: string | null;
10
+ isError: boolean;
11
+ }
12
+ type ChatNode = {
13
+ key: string;
14
+ kind: 'assistant';
15
+ text: string;
16
+ } | {
17
+ key: string;
18
+ kind: 'thinking';
19
+ text: string;
20
+ } | {
21
+ key: string;
22
+ kind: 'user';
23
+ text: string;
24
+ } | {
25
+ key: string;
26
+ kind: 'lifecycle';
27
+ text: string;
28
+ recordType: string;
29
+ hook?: string;
30
+ } | ChatToolNode;
31
+ interface ChatTurn {
32
+ key: string;
33
+ role: 'assistant' | 'user' | 'lifecycle';
34
+ nodes: ChatNode[];
35
+ startedAt: string | null;
36
+ completedAt: string | null;
37
+ durationMs: number | null;
38
+ costUsd: number | null;
39
+ tokens: number | null;
40
+ resumed: boolean;
41
+ }
42
+ declare function groupRecordsToChatTurns(records: readonly SessionRecordWire[]): ChatTurn[];
43
+
44
+ declare function setupOutputHook(payload: Record<string, unknown>): string;
45
+ declare function setupOutputLine(payload: Record<string, unknown>): string | null;
46
+ declare function lifecycleText(recordType: string, payload: Record<string, unknown>): string | null;
47
+
48
+ interface CCContentBlock {
49
+ type?: string;
50
+ text?: string;
51
+ thinking?: string;
52
+ id?: string;
53
+ name?: string;
54
+ input?: Record<string, unknown>;
55
+ content?: unknown;
56
+ tool_use_id?: string;
57
+ is_error?: boolean;
58
+ }
59
+ interface CCEvent {
60
+ type?: string;
61
+ subtype?: string;
62
+ message?: {
63
+ role?: string;
64
+ content?: unknown;
65
+ };
66
+ result?: string;
67
+ duration_ms?: number;
68
+ total_cost_usd?: number;
69
+ num_turns?: number;
70
+ is_error?: boolean;
71
+ model?: string;
72
+ cwd?: string;
73
+ tools?: string[];
74
+ [key: string]: unknown;
75
+ }
76
+ type ItemKind = 'assistant' | 'thinking' | 'tool' | 'tool_result' | 'summary' | 'system' | 'user' | 'notice' | 'error';
77
+ interface TranscriptItem {
78
+ key: string;
79
+ kind: ItemKind;
80
+ text: string;
81
+ detail?: string;
82
+ gutter?: string;
83
+ spaceBefore?: boolean;
84
+ isError?: boolean;
85
+ tool?: {
86
+ name: string;
87
+ input?: Record<string, unknown>;
88
+ };
89
+ }
90
+ declare class LineBuffer {
91
+ private buf;
92
+ push(chunk: string): string[];
93
+ flush(): string[];
94
+ }
95
+ declare function parseEventLine(line: string): CCEvent | null;
96
+ declare function oneLine(text: string, max: number): string;
97
+ declare function summarizeToolInput(name: string, input: unknown): string;
98
+ declare function formatDuration(seconds: number): string;
99
+ interface EventToItemsOptions {
100
+ systemInitLine?: boolean;
101
+ }
102
+ declare function eventToItems(event: CCEvent, keyBase: string, options?: EventToItemsOptions): TranscriptItem[];
103
+ declare function recordToItems(record: SessionRecordWire, keyBase: string, options?: EventToItemsOptions): TranscriptItem[];
104
+ declare function isConnectVisibleRecord(record: SessionRecordWire): boolean;
105
+ declare function pendingToolCalls(items: TranscriptItem[]): TranscriptItem[];
106
+ declare function collapseToolRuns(items: TranscriptItem[]): TranscriptItem[];
107
+ declare function clampLines(text: string, maxLines: number): {
108
+ body: string;
109
+ more: number;
110
+ };
111
+ declare function resultCostUsd(event: CCEvent): number | null;
112
+ declare function foldCosts(events: CCEvent[]): {
113
+ total: number | null;
114
+ lastStep: number | null;
115
+ };
116
+ declare function statusActivityText(status: string): string | null;
117
+
118
+ declare function isConversationOver(session: AgentSessionWire): boolean;
119
+ interface SessionTranscriptSnapshot {
120
+ session: AgentSessionWire | null;
121
+ records: readonly SessionRecordWire[];
122
+ messages: readonly SessionMessageWire[];
123
+ acknowledgedMessageIds: ReadonlySet<string>;
124
+ historyTruncated: boolean;
125
+ liveText: string;
126
+ liveOutputTokens: number | null;
127
+ lastEventAt: number | null;
128
+ conversationOver: boolean;
129
+ }
130
+ declare function emptySessionTranscriptSnapshot(): SessionTranscriptSnapshot;
131
+ declare class SessionTranscriptStore {
132
+ private snapshot;
133
+ private listeners;
134
+ private acknowledged;
135
+ private cursorSeq;
136
+ private turnsFor;
137
+ private turnsCache;
138
+ get cursor(): number;
139
+ subscribe: (listener: () => void) => (() => void);
140
+ getSnapshot: () => SessionTranscriptSnapshot;
141
+ chatTurns: () => ChatTurn[];
142
+ ingest: (rawFrame: StreamFrame) => void;
143
+ }
144
+
145
+ export { type CCContentBlock, type CCEvent, type ChatNode, type ChatToolNode, type ChatTurn, type EventToItemsOptions, type ItemKind, LineBuffer, type SessionTranscriptSnapshot, SessionTranscriptStore, StreamFrame, type TranscriptItem, clampLines, collapseToolRuns, emptySessionTranscriptSnapshot, eventToItems, foldCosts, formatDuration, groupRecordsToChatTurns, isConnectVisibleRecord, isConversationOver, lifecycleText, oneLine, parseEventLine, pendingToolCalls, recordToItems, resultCostUsd, setupOutputHook, setupOutputLine, statusActivityText, summarizeToolInput };