@slopus/happy-agent-client 0.0.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/README.md +17 -0
- package/dist/HappyAgentApiError.d.ts +41 -0
- package/dist/HappyAgentApiError.d.ts.map +1 -0
- package/dist/HappyAgentApiError.js +57 -0
- package/dist/HappyAgentApiError.js.map +1 -0
- package/dist/HappyAgentClient.d.ts +256 -0
- package/dist/HappyAgentClient.d.ts.map +1 -0
- package/dist/HappyAgentClient.js +739 -0
- package/dist/HappyAgentClient.js.map +1 -0
- package/dist/endpointUrl.d.ts +14 -0
- package/dist/endpointUrl.d.ts.map +1 -0
- package/dist/endpointUrl.js +27 -0
- package/dist/endpointUrl.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/agents.d.ts +116 -0
- package/dist/protocol/agents.d.ts.map +1 -0
- package/dist/protocol/agents.js +3 -0
- package/dist/protocol/agents.js.map +1 -0
- package/dist/protocol/bootstrap.d.ts +28 -0
- package/dist/protocol/bootstrap.d.ts.map +1 -0
- package/dist/protocol/bootstrap.js +3 -0
- package/dist/protocol/bootstrap.js.map +1 -0
- package/dist/protocol/common.d.ts +104 -0
- package/dist/protocol/common.d.ts.map +1 -0
- package/dist/protocol/common.js +92 -0
- package/dist/protocol/common.js.map +1 -0
- package/dist/protocol/daemon.d.ts +486 -0
- package/dist/protocol/daemon.d.ts.map +1 -0
- package/dist/protocol/daemon.js +210 -0
- package/dist/protocol/daemon.js.map +1 -0
- package/dist/protocol/events.d.ts +208 -0
- package/dist/protocol/events.d.ts.map +1 -0
- package/dist/protocol/events.js +9 -0
- package/dist/protocol/events.js.map +1 -0
- package/dist/protocol/files.d.ts +74 -0
- package/dist/protocol/files.d.ts.map +1 -0
- package/dist/protocol/files.js +8 -0
- package/dist/protocol/files.js.map +1 -0
- package/dist/protocol/git.d.ts +55 -0
- package/dist/protocol/git.d.ts.map +1 -0
- package/dist/protocol/git.js +3 -0
- package/dist/protocol/git.js.map +1 -0
- package/dist/protocol/messages.d.ts +210 -0
- package/dist/protocol/messages.d.ts.map +1 -0
- package/dist/protocol/messages.js +8 -0
- package/dist/protocol/messages.js.map +1 -0
- package/dist/protocol/processes.d.ts +26 -0
- package/dist/protocol/processes.d.ts.map +1 -0
- package/dist/protocol/processes.js +3 -0
- package/dist/protocol/processes.js.map +1 -0
- package/dist/protocol/profile.d.ts +40 -0
- package/dist/protocol/profile.d.ts.map +1 -0
- package/dist/protocol/profile.js +23 -0
- package/dist/protocol/profile.js.map +1 -0
- package/dist/protocol/projects.d.ts +377 -0
- package/dist/protocol/projects.d.ts.map +1 -0
- package/dist/protocol/projects.js +107 -0
- package/dist/protocol/projects.js.map +1 -0
- package/dist/protocol/questions.d.ts +54 -0
- package/dist/protocol/questions.d.ts.map +1 -0
- package/dist/protocol/questions.js +3 -0
- package/dist/protocol/questions.js.map +1 -0
- package/dist/protocol/terminals.d.ts +50 -0
- package/dist/protocol/terminals.d.ts.map +1 -0
- package/dist/protocol/terminals.js +3 -0
- package/dist/protocol/terminals.js.map +1 -0
- package/dist/protocol/usage.d.ts +27 -0
- package/dist/protocol/usage.d.ts.map +1 -0
- package/dist/protocol/usage.js +9 -0
- package/dist/protocol/usage.js.map +1 -0
- package/dist/protocol/workspaces.d.ts +216 -0
- package/dist/protocol/workspaces.d.ts.map +1 -0
- package/dist/protocol/workspaces.js +87 -0
- package/dist/protocol/workspaces.js.map +1 -0
- package/dist/readEventStream.d.ts +19 -0
- package/dist/readEventStream.d.ts.map +1 -0
- package/dist/readEventStream.js +46 -0
- package/dist/readEventStream.js.map +1 -0
- package/dist/readSseFrames.d.ts +20 -0
- package/dist/readSseFrames.d.ts.map +1 -0
- package/dist/readSseFrames.js +77 -0
- package/dist/readSseFrames.js.map +1 -0
- package/dist/requestOptions.d.ts +44 -0
- package/dist/requestOptions.d.ts.map +1 -0
- package/dist/requestOptions.js +9 -0
- package/dist/requestOptions.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminals.js","sourceRoot":"","sources":["../../sources/protocol/terminals.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage: what was consumed, never summarized across models.
|
|
3
|
+
*
|
|
4
|
+
* Tokens from different models are not comparable quantities, so the breakdown
|
|
5
|
+
* is always by provider and then by model; a client wanting a rollup computes
|
|
6
|
+
* its own.
|
|
7
|
+
*/
|
|
8
|
+
export interface ModelUsage {
|
|
9
|
+
input: number;
|
|
10
|
+
output: number;
|
|
11
|
+
cacheRead: number;
|
|
12
|
+
cacheWrite: number;
|
|
13
|
+
}
|
|
14
|
+
/** Provider key, then model ID, then the counts. */
|
|
15
|
+
export type UsageBreakdown = Record<string, Record<string, ModelUsage>>;
|
|
16
|
+
/** `GET /v0/agents/:agentId/usage` — the agent's whole life, subagents included. */
|
|
17
|
+
export interface AgentUsageResponse {
|
|
18
|
+
usage: UsageBreakdown;
|
|
19
|
+
}
|
|
20
|
+
/** `GET /v0/usage` — rolling windows ending now. */
|
|
21
|
+
export interface DaemonUsageResponse {
|
|
22
|
+
hour: UsageBreakdown;
|
|
23
|
+
day: UsageBreakdown;
|
|
24
|
+
week: UsageBreakdown;
|
|
25
|
+
month: UsageBreakdown;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../sources/protocol/usage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,oDAAoD;AACpD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAExE,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,cAAc,CAAC;CACzB;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;CACzB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage: what was consumed, never summarized across models.
|
|
3
|
+
*
|
|
4
|
+
* Tokens from different models are not comparable quantities, so the breakdown
|
|
5
|
+
* is always by provider and then by model; a client wanting a rollup computes
|
|
6
|
+
* its own.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../sources/protocol/usage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/** Workspaces: a checkout with its own folder, its own branch, and its place in a tree. */
|
|
2
|
+
import { type Static } from "@sinclair/typebox";
|
|
3
|
+
import type { Agent } from "./agents.js";
|
|
4
|
+
/** What the workspace was created from. */
|
|
5
|
+
export declare const workspaceBaseSchema: import("@sinclair/typebox").TObject<{
|
|
6
|
+
/** The commit the ref resolved to at creation time. */
|
|
7
|
+
commit: import("@sinclair/typebox").TString;
|
|
8
|
+
/** The ref the caller named. */
|
|
9
|
+
ref: import("@sinclair/typebox").TString;
|
|
10
|
+
}>;
|
|
11
|
+
export type WorkspaceBase = Static<typeof workspaceBaseSchema>;
|
|
12
|
+
/** The workspace object. A project's root workspace shares the project's ID. */
|
|
13
|
+
export declare const workspaceSchema: import("@sinclair/typebox").TObject<{
|
|
14
|
+
/** Ordered top-level agents rooted directly in this workspace. */
|
|
15
|
+
agents: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnsafe<Agent>>;
|
|
16
|
+
archivedAt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TNull]>;
|
|
17
|
+
/** `null` on a root workspace, which was not branched from anything. */
|
|
18
|
+
base: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
19
|
+
/** The commit the ref resolved to at creation time. */
|
|
20
|
+
commit: import("@sinclair/typebox").TString;
|
|
21
|
+
/** The ref the caller named. */
|
|
22
|
+
ref: import("@sinclair/typebox").TString;
|
|
23
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
24
|
+
compute: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
25
|
+
path: import("@sinclair/typebox").TString;
|
|
26
|
+
type: import("@sinclair/typebox").TLiteral<"host">;
|
|
27
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
28
|
+
image: import("@sinclair/typebox").TString;
|
|
29
|
+
type: import("@sinclair/typebox").TLiteral<"docker">;
|
|
30
|
+
}>]>;
|
|
31
|
+
createdAt: import("@sinclair/typebox").TInteger;
|
|
32
|
+
/** The agent that created this workspace; `null` when a person did. */
|
|
33
|
+
creatorAgentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
34
|
+
git: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
35
|
+
ahead: import("@sinclair/typebox").TInteger;
|
|
36
|
+
behind: import("@sinclair/typebox").TInteger;
|
|
37
|
+
branch: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
|
|
38
|
+
detached: import("@sinclair/typebox").TBoolean;
|
|
39
|
+
head: import("@sinclair/typebox").TString;
|
|
40
|
+
upstream: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
41
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
42
|
+
id: import("@sinclair/typebox").TString;
|
|
43
|
+
initialization: import("@sinclair/typebox").TObject<{
|
|
44
|
+
attempt: import("@sinclair/typebox").TInteger;
|
|
45
|
+
error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
46
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"initializing">, import("@sinclair/typebox").TLiteral<"ready">, import("@sinclair/typebox").TLiteral<"failed">]>;
|
|
47
|
+
}>;
|
|
48
|
+
/** How the checkout was made. */
|
|
49
|
+
kind: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"root">, import("@sinclair/typebox").TLiteral<"worktree">, import("@sinclair/typebox").TLiteral<"copy">]>;
|
|
50
|
+
/** The display name, which is also the branch name behind the checkout. */
|
|
51
|
+
name: import("@sinclair/typebox").TString;
|
|
52
|
+
nameSource: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"user">, import("@sinclair/typebox").TLiteral<"generated">]>;
|
|
53
|
+
/** Orders this workspace among the siblings sharing its parent. */
|
|
54
|
+
orderKey: import("@sinclair/typebox").TString;
|
|
55
|
+
/** `null` on the root workspace. */
|
|
56
|
+
parentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
57
|
+
/** The root of this workspace's tree. */
|
|
58
|
+
projectId: import("@sinclair/typebox").TString;
|
|
59
|
+
/** `"archiving"` is the window where the decision is durable but cleanup runs. */
|
|
60
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"active">, import("@sinclair/typebox").TLiteral<"archiving">, import("@sinclair/typebox").TLiteral<"archived">]>;
|
|
61
|
+
updatedAt: import("@sinclair/typebox").TInteger;
|
|
62
|
+
version: import("@sinclair/typebox").TString;
|
|
63
|
+
}>;
|
|
64
|
+
export type Workspace = Static<typeof workspaceSchema>;
|
|
65
|
+
/** `GET /v0/workspaces` — a flat array; clients build the tree from `parentId`. */
|
|
66
|
+
export declare const workspaceListResponseSchema: import("@sinclair/typebox").TObject<{
|
|
67
|
+
workspaces: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
68
|
+
/** Ordered top-level agents rooted directly in this workspace. */
|
|
69
|
+
agents: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnsafe<Agent>>;
|
|
70
|
+
archivedAt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TNull]>;
|
|
71
|
+
/** `null` on a root workspace, which was not branched from anything. */
|
|
72
|
+
base: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
73
|
+
/** The commit the ref resolved to at creation time. */
|
|
74
|
+
commit: import("@sinclair/typebox").TString;
|
|
75
|
+
/** The ref the caller named. */
|
|
76
|
+
ref: import("@sinclair/typebox").TString;
|
|
77
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
78
|
+
compute: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
79
|
+
path: import("@sinclair/typebox").TString;
|
|
80
|
+
type: import("@sinclair/typebox").TLiteral<"host">;
|
|
81
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
82
|
+
image: import("@sinclair/typebox").TString;
|
|
83
|
+
type: import("@sinclair/typebox").TLiteral<"docker">;
|
|
84
|
+
}>]>;
|
|
85
|
+
createdAt: import("@sinclair/typebox").TInteger;
|
|
86
|
+
/** The agent that created this workspace; `null` when a person did. */
|
|
87
|
+
creatorAgentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
88
|
+
git: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
89
|
+
ahead: import("@sinclair/typebox").TInteger;
|
|
90
|
+
behind: import("@sinclair/typebox").TInteger;
|
|
91
|
+
branch: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
|
|
92
|
+
detached: import("@sinclair/typebox").TBoolean;
|
|
93
|
+
head: import("@sinclair/typebox").TString;
|
|
94
|
+
upstream: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
95
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
96
|
+
id: import("@sinclair/typebox").TString;
|
|
97
|
+
initialization: import("@sinclair/typebox").TObject<{
|
|
98
|
+
attempt: import("@sinclair/typebox").TInteger;
|
|
99
|
+
error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
100
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"initializing">, import("@sinclair/typebox").TLiteral<"ready">, import("@sinclair/typebox").TLiteral<"failed">]>;
|
|
101
|
+
}>;
|
|
102
|
+
/** How the checkout was made. */
|
|
103
|
+
kind: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"root">, import("@sinclair/typebox").TLiteral<"worktree">, import("@sinclair/typebox").TLiteral<"copy">]>;
|
|
104
|
+
/** The display name, which is also the branch name behind the checkout. */
|
|
105
|
+
name: import("@sinclair/typebox").TString;
|
|
106
|
+
nameSource: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"user">, import("@sinclair/typebox").TLiteral<"generated">]>;
|
|
107
|
+
/** Orders this workspace among the siblings sharing its parent. */
|
|
108
|
+
orderKey: import("@sinclair/typebox").TString;
|
|
109
|
+
/** `null` on the root workspace. */
|
|
110
|
+
parentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
111
|
+
/** The root of this workspace's tree. */
|
|
112
|
+
projectId: import("@sinclair/typebox").TString;
|
|
113
|
+
/** `"archiving"` is the window where the decision is durable but cleanup runs. */
|
|
114
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"active">, import("@sinclair/typebox").TLiteral<"archiving">, import("@sinclair/typebox").TLiteral<"archived">]>;
|
|
115
|
+
updatedAt: import("@sinclair/typebox").TInteger;
|
|
116
|
+
version: import("@sinclair/typebox").TString;
|
|
117
|
+
}>>;
|
|
118
|
+
}>;
|
|
119
|
+
export type WorkspaceListResponse = Static<typeof workspaceListResponseSchema>;
|
|
120
|
+
/** Every single-workspace route answers with this. */
|
|
121
|
+
export declare const workspaceResponseSchema: import("@sinclair/typebox").TObject<{
|
|
122
|
+
workspace: import("@sinclair/typebox").TObject<{
|
|
123
|
+
/** Ordered top-level agents rooted directly in this workspace. */
|
|
124
|
+
agents: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnsafe<Agent>>;
|
|
125
|
+
archivedAt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TNull]>;
|
|
126
|
+
/** `null` on a root workspace, which was not branched from anything. */
|
|
127
|
+
base: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
128
|
+
/** The commit the ref resolved to at creation time. */
|
|
129
|
+
commit: import("@sinclair/typebox").TString;
|
|
130
|
+
/** The ref the caller named. */
|
|
131
|
+
ref: import("@sinclair/typebox").TString;
|
|
132
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
133
|
+
compute: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
134
|
+
path: import("@sinclair/typebox").TString;
|
|
135
|
+
type: import("@sinclair/typebox").TLiteral<"host">;
|
|
136
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
137
|
+
image: import("@sinclair/typebox").TString;
|
|
138
|
+
type: import("@sinclair/typebox").TLiteral<"docker">;
|
|
139
|
+
}>]>;
|
|
140
|
+
createdAt: import("@sinclair/typebox").TInteger;
|
|
141
|
+
/** The agent that created this workspace; `null` when a person did. */
|
|
142
|
+
creatorAgentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
143
|
+
git: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
144
|
+
ahead: import("@sinclair/typebox").TInteger;
|
|
145
|
+
behind: import("@sinclair/typebox").TInteger;
|
|
146
|
+
branch: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
|
|
147
|
+
detached: import("@sinclair/typebox").TBoolean;
|
|
148
|
+
head: import("@sinclair/typebox").TString;
|
|
149
|
+
upstream: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
150
|
+
}>, import("@sinclair/typebox").TNull]>;
|
|
151
|
+
id: import("@sinclair/typebox").TString;
|
|
152
|
+
initialization: import("@sinclair/typebox").TObject<{
|
|
153
|
+
attempt: import("@sinclair/typebox").TInteger;
|
|
154
|
+
error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
155
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"initializing">, import("@sinclair/typebox").TLiteral<"ready">, import("@sinclair/typebox").TLiteral<"failed">]>;
|
|
156
|
+
}>;
|
|
157
|
+
/** How the checkout was made. */
|
|
158
|
+
kind: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"root">, import("@sinclair/typebox").TLiteral<"worktree">, import("@sinclair/typebox").TLiteral<"copy">]>;
|
|
159
|
+
/** The display name, which is also the branch name behind the checkout. */
|
|
160
|
+
name: import("@sinclair/typebox").TString;
|
|
161
|
+
nameSource: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"user">, import("@sinclair/typebox").TLiteral<"generated">]>;
|
|
162
|
+
/** Orders this workspace among the siblings sharing its parent. */
|
|
163
|
+
orderKey: import("@sinclair/typebox").TString;
|
|
164
|
+
/** `null` on the root workspace. */
|
|
165
|
+
parentId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
166
|
+
/** The root of this workspace's tree. */
|
|
167
|
+
projectId: import("@sinclair/typebox").TString;
|
|
168
|
+
/** `"archiving"` is the window where the decision is durable but cleanup runs. */
|
|
169
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"active">, import("@sinclair/typebox").TLiteral<"archiving">, import("@sinclair/typebox").TLiteral<"archived">]>;
|
|
170
|
+
updatedAt: import("@sinclair/typebox").TInteger;
|
|
171
|
+
version: import("@sinclair/typebox").TString;
|
|
172
|
+
}>;
|
|
173
|
+
}>;
|
|
174
|
+
export type WorkspaceResponse = Static<typeof workspaceResponseSchema>;
|
|
175
|
+
/** `GET /v0/workspaces` query parameters. */
|
|
176
|
+
export declare const listWorkspacesQuerySchema: import("@sinclair/typebox").TObject<{
|
|
177
|
+
/** Archived and archiving workspaces are history; default `false`. */
|
|
178
|
+
includeArchived: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
179
|
+
/** Only this project's tree. */
|
|
180
|
+
projectId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
181
|
+
}>;
|
|
182
|
+
export type ListWorkspacesQuery = Static<typeof listWorkspacesQuerySchema>;
|
|
183
|
+
/** `POST /v0/workspaces` */
|
|
184
|
+
export declare const createWorkspaceRequestSchema: import("@sinclair/typebox").TObject<{
|
|
185
|
+
/** Records the creating agent as `creatorAgentId`. */
|
|
186
|
+
agentId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
187
|
+
/** The ref to branch from; defaults to the parent's current branch. */
|
|
188
|
+
baseRef: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
189
|
+
/** Optional client-supplied ID. */
|
|
190
|
+
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
191
|
+
mutationId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
192
|
+
/** The workspace name, which is also its branch name. */
|
|
193
|
+
name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
194
|
+
/** The workspace to nest under: a root workspace or any workspace in a tree. */
|
|
195
|
+
parentId: import("@sinclair/typebox").TString;
|
|
196
|
+
}>;
|
|
197
|
+
export type CreateWorkspaceRequest = Static<typeof createWorkspaceRequestSchema>;
|
|
198
|
+
/** `PATCH /v0/workspaces/:workspaceId` */
|
|
199
|
+
export declare const renameWorkspaceRequestSchema: import("@sinclair/typebox").TObject<{
|
|
200
|
+
mutationId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
201
|
+
name: import("@sinclair/typebox").TString;
|
|
202
|
+
}>;
|
|
203
|
+
export type RenameWorkspaceRequest = Static<typeof renameWorkspaceRequestSchema>;
|
|
204
|
+
/** `POST /v0/workspaces/:workspaceId/archive` */
|
|
205
|
+
export declare const archiveWorkspaceRequestSchema: import("@sinclair/typebox").TObject<{
|
|
206
|
+
mutationId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
207
|
+
}>;
|
|
208
|
+
export type ArchiveWorkspaceRequest = Static<typeof archiveWorkspaceRequestSchema>;
|
|
209
|
+
/** `POST /v0/workspaces/:workspaceId/reorder` */
|
|
210
|
+
export declare const reorderWorkspaceRequestSchema: import("@sinclair/typebox").TObject<{
|
|
211
|
+
/** The sibling to place this one after, or `null` to move it first. */
|
|
212
|
+
afterId: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
213
|
+
mutationId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
214
|
+
}>;
|
|
215
|
+
export type ReorderWorkspaceRequest = Static<typeof reorderWorkspaceRequestSchema>;
|
|
216
|
+
//# sourceMappingURL=workspaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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EAAmE;;QAEnE,oCAAoC;;QAEpC,yCAAyC;;QAEzC,kFAAkF;;;;;EAkBJ,CAAC;AACnF,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEvE,6CAA6C;AAC7C,eAAO,MAAM,yBAAyB;IAClC,sEAAsE;;IAEtE,gCAAgC;;EAElC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE3E,4BAA4B;AAC5B,eAAO,MAAM,4BAA4B;IACrC,sDAAsD;;IAEtD,uEAAuE;;IAEvE,mCAAmC;;;IAGnC,yDAAyD;;IAEzD,gFAAgF;;EAElF,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEjF,0CAA0C;AAC1C,eAAO,MAAM,4BAA4B;;;EAGvC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEjF,iDAAiD;AACjD,eAAO,MAAM,6BAA6B;;EAExC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEnF,iDAAiD;AACjD,eAAO,MAAM,6BAA6B;IACtC,uEAAuE;;;EAGzE,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,OAAO,6BAA6B,CAAC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Workspaces: a checkout with its own folder, its own branch, and its place in a tree. */
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { computeSchema, cuid2Schema, gitSummarySchema, initializationStateSchema, mutationIdSchema, Nullable, resourceVersionSchema, timestampSchema, } from "./common.js";
|
|
4
|
+
/** What the workspace was created from. */
|
|
5
|
+
export const workspaceBaseSchema = Type.Object({
|
|
6
|
+
/** The commit the ref resolved to at creation time. */
|
|
7
|
+
commit: Type.String(),
|
|
8
|
+
/** The ref the caller named. */
|
|
9
|
+
ref: Type.String(),
|
|
10
|
+
});
|
|
11
|
+
/** The workspace object. A project's root workspace shares the project's ID. */
|
|
12
|
+
export const workspaceSchema = Type.Object({
|
|
13
|
+
/** Ordered top-level agents rooted directly in this workspace. */
|
|
14
|
+
agents: Type.Array(Type.Unsafe({ type: "object" })),
|
|
15
|
+
archivedAt: Nullable(timestampSchema),
|
|
16
|
+
/** `null` on a root workspace, which was not branched from anything. */
|
|
17
|
+
base: Nullable(workspaceBaseSchema),
|
|
18
|
+
compute: computeSchema,
|
|
19
|
+
createdAt: timestampSchema,
|
|
20
|
+
/** The agent that created this workspace; `null` when a person did. */
|
|
21
|
+
creatorAgentId: Nullable(cuid2Schema),
|
|
22
|
+
git: Nullable(gitSummarySchema),
|
|
23
|
+
id: cuid2Schema,
|
|
24
|
+
initialization: initializationStateSchema,
|
|
25
|
+
/** How the checkout was made. */
|
|
26
|
+
kind: Type.Union([Type.Literal("root"), Type.Literal("worktree"), Type.Literal("copy")]),
|
|
27
|
+
/** The display name, which is also the branch name behind the checkout. */
|
|
28
|
+
name: Type.String(),
|
|
29
|
+
nameSource: Type.Union([Type.Literal("user"), Type.Literal("generated")]),
|
|
30
|
+
/** Orders this workspace among the siblings sharing its parent. */
|
|
31
|
+
orderKey: Type.String(),
|
|
32
|
+
/** `null` on the root workspace. */
|
|
33
|
+
parentId: Nullable(cuid2Schema),
|
|
34
|
+
/** The root of this workspace's tree. */
|
|
35
|
+
projectId: cuid2Schema,
|
|
36
|
+
/** `"archiving"` is the window where the decision is durable but cleanup runs. */
|
|
37
|
+
status: Type.Union([
|
|
38
|
+
Type.Literal("active"),
|
|
39
|
+
Type.Literal("archiving"),
|
|
40
|
+
Type.Literal("archived"),
|
|
41
|
+
]),
|
|
42
|
+
updatedAt: timestampSchema,
|
|
43
|
+
version: resourceVersionSchema,
|
|
44
|
+
});
|
|
45
|
+
/** `GET /v0/workspaces` — a flat array; clients build the tree from `parentId`. */
|
|
46
|
+
export const workspaceListResponseSchema = Type.Object({
|
|
47
|
+
workspaces: Type.Array(workspaceSchema),
|
|
48
|
+
});
|
|
49
|
+
/** Every single-workspace route answers with this. */
|
|
50
|
+
export const workspaceResponseSchema = Type.Object({ workspace: workspaceSchema });
|
|
51
|
+
/** `GET /v0/workspaces` query parameters. */
|
|
52
|
+
export const listWorkspacesQuerySchema = Type.Object({
|
|
53
|
+
/** Archived and archiving workspaces are history; default `false`. */
|
|
54
|
+
includeArchived: Type.Optional(Type.Boolean()),
|
|
55
|
+
/** Only this project's tree. */
|
|
56
|
+
projectId: Type.Optional(cuid2Schema),
|
|
57
|
+
});
|
|
58
|
+
/** `POST /v0/workspaces` */
|
|
59
|
+
export const createWorkspaceRequestSchema = Type.Object({
|
|
60
|
+
/** Records the creating agent as `creatorAgentId`. */
|
|
61
|
+
agentId: Type.Optional(cuid2Schema),
|
|
62
|
+
/** The ref to branch from; defaults to the parent's current branch. */
|
|
63
|
+
baseRef: Type.Optional(Type.String()),
|
|
64
|
+
/** Optional client-supplied ID. */
|
|
65
|
+
id: Type.Optional(cuid2Schema),
|
|
66
|
+
mutationId: Type.Optional(mutationIdSchema),
|
|
67
|
+
/** The workspace name, which is also its branch name. */
|
|
68
|
+
name: Type.Optional(Type.String()),
|
|
69
|
+
/** The workspace to nest under: a root workspace or any workspace in a tree. */
|
|
70
|
+
parentId: cuid2Schema,
|
|
71
|
+
});
|
|
72
|
+
/** `PATCH /v0/workspaces/:workspaceId` */
|
|
73
|
+
export const renameWorkspaceRequestSchema = Type.Object({
|
|
74
|
+
mutationId: Type.Optional(mutationIdSchema),
|
|
75
|
+
name: Type.String(),
|
|
76
|
+
});
|
|
77
|
+
/** `POST /v0/workspaces/:workspaceId/archive` */
|
|
78
|
+
export const archiveWorkspaceRequestSchema = Type.Object({
|
|
79
|
+
mutationId: Type.Optional(mutationIdSchema),
|
|
80
|
+
});
|
|
81
|
+
/** `POST /v0/workspaces/:workspaceId/reorder` */
|
|
82
|
+
export const reorderWorkspaceRequestSchema = Type.Object({
|
|
83
|
+
/** The sibling to place this one after, or `null` to move it first. */
|
|
84
|
+
afterId: Nullable(cuid2Schema),
|
|
85
|
+
mutationId: Type.Optional(mutationIdSchema),
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=workspaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../sources/protocol/workspaces.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAE3F,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EACH,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,QAAQ,EACR,qBAAqB,EACrB,eAAe,GAClB,MAAM,aAAa,CAAC;AAGrB,2CAA2C;AAC3C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3C,uDAAuD;IACvD,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;IACrB,gCAAgC;IAChC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC;AAGH,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,kEAAkE;IAClE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,UAAU,EAAE,QAAQ,CAAC,eAAe,CAAC;IACrC,wEAAwE;IACxE,IAAI,EAAE,QAAQ,CAAC,mBAAmB,CAAC;IACnC,OAAO,EAAE,aAAa;IACtB,SAAS,EAAE,eAAe;IAC1B,uEAAuE;IACvE,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC;IACrC,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IAC/B,EAAE,EAAE,WAAW;IACf,cAAc,E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
+
import type { EventStreamFrame } from "./protocol/events.js";
|
|
2
|
+
/** The stream said something this client cannot read as the documented contract. */
|
|
3
|
+
export declare class EventStreamProtocolError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Turns the event stream's bytes into typed frames.
|
|
8
|
+
*
|
|
9
|
+
* The stream opens with a `hello` frame naming the position it continues from
|
|
10
|
+
* and whether the requested cursor survived the journal window; after it, every
|
|
11
|
+
* frame is one event, its SSE `id:` carrying the event's cursor and its
|
|
12
|
+
* `event:` carrying the event's type.
|
|
13
|
+
*
|
|
14
|
+
* Nothing is validated beyond what the framing itself proves: this package has
|
|
15
|
+
* no runtime dependencies, so a parsed envelope is trusted to be what the
|
|
16
|
+
* specification says the daemon sends.
|
|
17
|
+
*/
|
|
18
|
+
export declare function readEventStream(body: ReadableStream<Uint8Array<ArrayBuffer>>): AsyncGenerator<EventStreamFrame>;
|
|
19
|
+
//# sourceMappingURL=readEventStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readEventStream.d.ts","sourceRoot":"","sources":["../sources/readEventStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAqC,MAAM,sBAAsB,CAAC;AAGhG,oFAAoF;AACpF,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACJ;AAED;;;;;;;;;;;GAWG;AACH,wBAAuB,eAAe,CAClC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAC9C,cAAc,CAAC,gBAAgB,CAAC,CAgBlC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readSseFrames } from "./readSseFrames.js";
|
|
2
|
+
/** The stream said something this client cannot read as the documented contract. */
|
|
3
|
+
export class EventStreamProtocolError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "EventStreamProtocolError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Turns the event stream's bytes into typed frames.
|
|
11
|
+
*
|
|
12
|
+
* The stream opens with a `hello` frame naming the position it continues from
|
|
13
|
+
* and whether the requested cursor survived the journal window; after it, every
|
|
14
|
+
* frame is one event, its SSE `id:` carrying the event's cursor and its
|
|
15
|
+
* `event:` carrying the event's type.
|
|
16
|
+
*
|
|
17
|
+
* Nothing is validated beyond what the framing itself proves: this package has
|
|
18
|
+
* no runtime dependencies, so a parsed envelope is trusted to be what the
|
|
19
|
+
* specification says the daemon sends.
|
|
20
|
+
*/
|
|
21
|
+
export async function* readEventStream(body) {
|
|
22
|
+
for await (const frame of readSseFrames(body)) {
|
|
23
|
+
const data = parseJson(frame.data);
|
|
24
|
+
if (frame.name === "hello") {
|
|
25
|
+
yield { kind: "hello", hello: data };
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const event = data;
|
|
29
|
+
// The envelope carries the cursor, and the SSE `id:` line repeats it for
|
|
30
|
+
// `Last-Event-ID`. Either one is the position; prefer the envelope's.
|
|
31
|
+
const cursor = typeof event.cursor === "string" ? event.cursor : frame.id;
|
|
32
|
+
if (cursor === undefined) {
|
|
33
|
+
throw new EventStreamProtocolError("An event arrived without a cursor.");
|
|
34
|
+
}
|
|
35
|
+
yield { kind: "event", event, cursor };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function parseJson(data) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(data);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new EventStreamProtocolError("An event frame did not carry JSON.");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=readEventStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readEventStream.js","sourceRoot":"","sources":["../sources/readEventStream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAA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frame read off a Server-Sent Events stream. */
|
|
2
|
+
export interface SseFrame {
|
|
3
|
+
/** The `event:` field, when the frame carried one. */
|
|
4
|
+
name: string | undefined;
|
|
5
|
+
/** The `id:` field, which on this API is the event's cursor. */
|
|
6
|
+
id: string | undefined;
|
|
7
|
+
/** The joined `data:` lines, still unparsed. */
|
|
8
|
+
data: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads Server-Sent Events out of a byte stream.
|
|
12
|
+
*
|
|
13
|
+
* Framing lives here rather than at the call site because the details are easy
|
|
14
|
+
* to get subtly wrong: a line may end with a carriage return, a newline, or
|
|
15
|
+
* both; a chunk may split a line ending in half; and comment frames — the
|
|
16
|
+
* heartbeats that keep the connection alive through proxies — carry no data and
|
|
17
|
+
* are dropped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readSseFrames(body: ReadableStream<Uint8Array<ArrayBuffer>>): AsyncGenerator<SseFrame>;
|
|
20
|
+
//# sourceMappingURL=readSseFrames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readSseFrames.d.ts","sourceRoot":"","sources":["../sources/readSseFrames.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,WAAW,QAAQ;IACrB,sDAAsD;IACtD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,gEAAgE;IAChE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAuB,aAAa,CAChC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAC9C,cAAc,CAAC,QAAQ,CAAC,CA6B1B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads Server-Sent Events out of a byte stream.
|
|
3
|
+
*
|
|
4
|
+
* Framing lives here rather than at the call site because the details are easy
|
|
5
|
+
* to get subtly wrong: a line may end with a carriage return, a newline, or
|
|
6
|
+
* both; a chunk may split a line ending in half; and comment frames — the
|
|
7
|
+
* heartbeats that keep the connection alive through proxies — carry no data and
|
|
8
|
+
* are dropped.
|
|
9
|
+
*/
|
|
10
|
+
export async function* readSseFrames(body) {
|
|
11
|
+
// The bytes are decoded here rather than piped through a TextDecoderStream
|
|
12
|
+
// so that a caller only ever has to hand over the response body it already
|
|
13
|
+
// holds, with no stream plumbing of its own.
|
|
14
|
+
const decoder = new TextDecoder();
|
|
15
|
+
const reader = body.getReader();
|
|
16
|
+
let buffer = "";
|
|
17
|
+
try {
|
|
18
|
+
for (;;) {
|
|
19
|
+
const { done, value } = await reader.read();
|
|
20
|
+
if (done) {
|
|
21
|
+
// A stream that ends without a trailing blank line still
|
|
22
|
+
// delivered a whole final frame.
|
|
23
|
+
const last = parseFrame(normalizeLineEndings(buffer));
|
|
24
|
+
if (last !== undefined)
|
|
25
|
+
yield last;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
buffer = holdBackSplitLineEnding(buffer + decoder.decode(value, { stream: true }));
|
|
29
|
+
for (;;) {
|
|
30
|
+
const boundary = buffer.indexOf("\n\n");
|
|
31
|
+
if (boundary < 0)
|
|
32
|
+
break;
|
|
33
|
+
const frame = parseFrame(buffer.slice(0, boundary));
|
|
34
|
+
buffer = buffer.slice(boundary + 2);
|
|
35
|
+
if (frame !== undefined)
|
|
36
|
+
yield frame;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
void reader.cancel().catch(() => undefined);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes line endings, keeping a trailing carriage return unresolved.
|
|
46
|
+
*
|
|
47
|
+
* The next chunk may begin with the newline that completes it, and deciding
|
|
48
|
+
* early would turn one line ending into two.
|
|
49
|
+
*/
|
|
50
|
+
function holdBackSplitLineEnding(buffer) {
|
|
51
|
+
if (!buffer.endsWith("\r"))
|
|
52
|
+
return normalizeLineEndings(buffer);
|
|
53
|
+
return `${normalizeLineEndings(buffer.slice(0, -1))}\r`;
|
|
54
|
+
}
|
|
55
|
+
function normalizeLineEndings(text) {
|
|
56
|
+
return text.replace(/\r\n?/gu, "\n");
|
|
57
|
+
}
|
|
58
|
+
function parseFrame(raw) {
|
|
59
|
+
if (raw.length === 0 || raw.startsWith(":"))
|
|
60
|
+
return undefined;
|
|
61
|
+
const lines = raw.split("\n");
|
|
62
|
+
const data = lines
|
|
63
|
+
.filter((line) => line.startsWith("data:"))
|
|
64
|
+
.map((line) => line.slice("data:".length).replace(/^ /u, ""));
|
|
65
|
+
if (data.length === 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
return {
|
|
68
|
+
data: data.join("\n"),
|
|
69
|
+
id: readField(lines, "id"),
|
|
70
|
+
name: readField(lines, "event"),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function readField(lines, field) {
|
|
74
|
+
const line = lines.find((candidate) => candidate.startsWith(`${field}:`));
|
|
75
|
+
return line?.slice(field.length + 1).replace(/^ /u, "");
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=readSseFrames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readSseFrames.js","sourceRoot":"","sources":["../sources/readSseFrames.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,aAAa,CAChC,IAA6C;IAE7C,2EAA2E;IAC3E,2EAA2E;IAC3E,6CAA6C;IAC7C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,CAAC;QACD,SAAS,CAAC;YACN,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C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;AAED,SAAS,UAAU,CAAC,GAAW;IAC3B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,KAAK;SACb,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IAClE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO;QACH,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACrB,EAAE,EAAE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;QAC1B,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC;KAClC,CAAC;AACN,CAAC;AAED,SAAS,SAAS,CAAC,KAAe,EAAE,KAAa;IAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a caller passes alongside a request, rather than over the wire.
|
|
3
|
+
*
|
|
4
|
+
* These carry `AbortSignal`s and raw bytes, which are runtime objects and not
|
|
5
|
+
* JSON, so they are declared as ordinary interfaces: there is no wire value
|
|
6
|
+
* here for a schema to validate.
|
|
7
|
+
*/
|
|
8
|
+
/** Options every request accepts. */
|
|
9
|
+
export interface RequestOptions {
|
|
10
|
+
/** Cancels the request; the rejection is the signal's abort reason. */
|
|
11
|
+
signal?: AbortSignal | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Options for a mutation the daemon guards with `If-Match`. */
|
|
14
|
+
export interface VersionedRequestOptions extends RequestOptions {
|
|
15
|
+
/** The `version` the client last saw, sent as the `If-Match` header. */
|
|
16
|
+
ifMatch: string;
|
|
17
|
+
}
|
|
18
|
+
/** Options for a mutation that honors `If-Match` without requiring it. */
|
|
19
|
+
export interface OptionallyVersionedRequestOptions extends RequestOptions {
|
|
20
|
+
/** The `version` the client last saw, sent as the `If-Match` header. */
|
|
21
|
+
ifMatch?: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Options for a read that may answer `304 Not Modified`. */
|
|
24
|
+
export interface ConditionalRequestOptions extends RequestOptions {
|
|
25
|
+
/** The `ETag` the client already holds, sent as `If-None-Match`. */
|
|
26
|
+
ifNoneMatch?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/** An image the daemon accepts as a picture. */
|
|
29
|
+
export type ImageMimeType = "image/png" | "image/jpeg" | "image/webp";
|
|
30
|
+
/** Bytes to upload, in whichever form the caller already holds them. */
|
|
31
|
+
export type BinaryData = ArrayBuffer | ArrayBufferView<ArrayBuffer>;
|
|
32
|
+
/** An image being uploaded. */
|
|
33
|
+
export interface ImageUpload {
|
|
34
|
+
contentType: ImageMimeType;
|
|
35
|
+
data: BinaryData;
|
|
36
|
+
}
|
|
37
|
+
/** Image bytes served by the daemon. */
|
|
38
|
+
export interface BinaryContent {
|
|
39
|
+
contentType: string;
|
|
40
|
+
data: ArrayBuffer;
|
|
41
|
+
/** The entity tag, when the endpoint serves conditional requests. */
|
|
42
|
+
etag: string | null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=requestOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestOptions.d.ts","sourceRoot":"","sources":["../sources/requestOptions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC3B,uEAAuE;IACvE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CACpC;AAED,gEAAgE;AAChE,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC3D,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,0EAA0E;AAC1E,MAAM,WAAW,iCAAkC,SAAQ,cAAc;IACrE,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,6DAA6D;AAC7D,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC7D,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;AAEtE,wEAAwE;AACxE,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;AAEpE,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IACxB,WAAW,EAAE,aAAa,CAAC;IAC3B,IAAI,EAAE,UAAU,CAAC;CACpB;AAED,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,qEAAqE;IACrE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a caller passes alongside a request, rather than over the wire.
|
|
3
|
+
*
|
|
4
|
+
* These carry `AbortSignal`s and raw bytes, which are runtime objects and not
|
|
5
|
+
* JSON, so they are declared as ordinary interfaces: there is no wire value
|
|
6
|
+
* here for a schema to validate.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=requestOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestOptions.js","sourceRoot":"","sources":["../sources/requestOptions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|