@palai/sdk 0.1.0 → 0.3.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/CHANGELOG.md +111 -1
- package/README.md +44 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -1
- package/dist/client.js.map +1 -1
- package/dist/generated/types.d.ts +19 -0
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/model-routes.d.ts +31 -0
- package/dist/resources/model-routes.d.ts.map +1 -1
- package/dist/resources/model-routes.js +69 -0
- package/dist/resources/model-routes.js.map +1 -1
- package/dist/resources/reads.d.ts +122 -2
- package/dist/resources/reads.d.ts.map +1 -1
- package/dist/resources/reads.js +68 -4
- package/dist/resources/reads.js.map +1 -1
- package/dist/resources/responses.d.ts +16 -1
- package/dist/resources/responses.d.ts.map +1 -1
- package/dist/resources/responses.js +18 -1
- package/dist/resources/responses.js.map +1 -1
- package/dist/resources/sessions.d.ts +47 -2
- package/dist/resources/sessions.d.ts.map +1 -1
- package/dist/resources/sessions.js +32 -6
- package/dist/resources/sessions.js.map +1 -1
- package/dist/resources/workspaces.d.ts +94 -0
- package/dist/resources/workspaces.d.ts.map +1 -0
- package/dist/resources/workspaces.js +88 -0
- package/dist/resources/workspaces.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Session, Workspace, WorkspaceRepository } from "../generated/types.ts";
|
|
2
|
+
import type { Palai } from "../client.ts";
|
|
3
|
+
import { type CallOptions, type Page } from "./shared.ts";
|
|
4
|
+
/**
|
|
5
|
+
* WorkspaceCreateParams declares what a workspace holds.
|
|
6
|
+
*
|
|
7
|
+
* `mount_path` is what makes N repositories ONE workspace: `api` and `web` are two checkouts under a
|
|
8
|
+
* single allocation root that an agent can walk between in one sandbox — which is the whole reason a
|
|
9
|
+
* workspace holds more than one. Two entries cannot share a mount path; the server refuses the create
|
|
10
|
+
* and names the colliding path. `requested_ref` is optional and empty means the binding's own default
|
|
11
|
+
* branch.
|
|
12
|
+
*/
|
|
13
|
+
export interface WorkspaceCreateParams {
|
|
14
|
+
repositories: WorkspaceRepository[];
|
|
15
|
+
}
|
|
16
|
+
export interface WorkspaceManifest {
|
|
17
|
+
object: "workspace.manifest";
|
|
18
|
+
workspace_id: string;
|
|
19
|
+
tree_checksum: string;
|
|
20
|
+
entry_count: number;
|
|
21
|
+
size_bytes: number;
|
|
22
|
+
entries: {
|
|
23
|
+
path: string;
|
|
24
|
+
digest: string;
|
|
25
|
+
size: number;
|
|
26
|
+
mode: number;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}[];
|
|
29
|
+
exclusions: string[];
|
|
30
|
+
created_at: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The /v1/workspaces resource: open a workspace holding N repositories, read it back, and ask which
|
|
34
|
+
* sessions share its tree.
|
|
35
|
+
*
|
|
36
|
+
* ‼️ A WORKSPACE IS THE DURABLE THING AND A SESSION ATTACHES TO IT. That is the shape a caller has to
|
|
37
|
+
* hold: open one workspace, then open as many sessions on it as you have conversations to run, and all
|
|
38
|
+
* of them read and write ONE checkout on ONE machine. Opening a session per conversation without a
|
|
39
|
+
* workspace — which is what this SDK used to do — gives each one a tree of its own that the others
|
|
40
|
+
* cannot see, and a machine bill per conversation.
|
|
41
|
+
*
|
|
42
|
+
* Mirrors the `Sessions` resource shape: a class taking the client, each method with a trailing
|
|
43
|
+
* `options: CallOptions`.
|
|
44
|
+
*/
|
|
45
|
+
export declare class Workspaces {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(client: Palai);
|
|
48
|
+
/** Read the complete tenant-scoped immutable file manifest. */
|
|
49
|
+
manifest(manifestID: string, options?: CallOptions): Promise<WorkspaceManifest>;
|
|
50
|
+
/**
|
|
51
|
+
* create opens a workspace holding the declared repositories (201).
|
|
52
|
+
*
|
|
53
|
+
* ‼️ IT RETURNS BEFORE THE TREE EXISTS, and the clone is asynchronous because it takes as long as N
|
|
54
|
+
* clones take — a create that waited would make a five-repository workspace a request that times out.
|
|
55
|
+
*
|
|
56
|
+
* ‼️ DO NOT WAIT FOR `ready`. `status` is the workspace's PLACEMENT state, not its contents: `ready`
|
|
57
|
+
* means a machine holds it, so a workspace nothing has run on yet stays `requested` however complete
|
|
58
|
+
* its tree is. Measured on a live stack: a workspace whose two repositories were fully published sat
|
|
59
|
+
* at `requested` indefinitely until a session ran on it. Open a session and send a message — the
|
|
60
|
+
* first run places the workspace and pays no clone, which is the whole point of cloning at create.
|
|
61
|
+
*
|
|
62
|
+
* Like `sessions.create` it carries no idempotency key: creation is unkeyed, a retried create mints
|
|
63
|
+
* a NEW workspace, so a torn connection is left alone rather than retried into a duplicate tree.
|
|
64
|
+
*/
|
|
65
|
+
create(params: WorkspaceCreateParams, options?: CallOptions): Promise<Workspace>;
|
|
66
|
+
/**
|
|
67
|
+
* list answers which workspaces this project has, newest first, each with its repositories.
|
|
68
|
+
*
|
|
69
|
+
* ‼️ IT IS THE READ EVERY CALLER NEEDS FIRST AND THE ONE THIS SURFACE SHIPPED WITHOUT. `create` and
|
|
70
|
+
* `retrieve` let a caller open a workspace and read back the one they just made; neither answers "which
|
|
71
|
+
* do I have?" — and since a session is born ON a workspace, every screen that opens one has to offer a
|
|
72
|
+
* choice. Measured on production: `GET /v1/workspaces` answered 405, while the admin console had already
|
|
73
|
+
* been written against a fixture that served it.
|
|
74
|
+
*/
|
|
75
|
+
list(options?: CallOptions): Promise<Page<Workspace>>;
|
|
76
|
+
/**
|
|
77
|
+
* retrieve reads one workspace: its lifecycle state, the machine holding it if any, and its
|
|
78
|
+
* repositories at their mount paths, in the order genesis builds them.
|
|
79
|
+
*
|
|
80
|
+
* `machine_id` is null between runs and that is the ORDINARY state, not an error — the hold is
|
|
81
|
+
* released when every session on the tree goes idle and taken again on the next placement.
|
|
82
|
+
*/
|
|
83
|
+
retrieve(workspaceId: string, options?: CallOptions): Promise<Workspace>;
|
|
84
|
+
/**
|
|
85
|
+
* sessions lists the sessions sharing this workspace's tree, in creation order.
|
|
86
|
+
*
|
|
87
|
+
* THIS IS THE READ THAT MAKES THE SHARED TREE USABLE. Everything a caller can do to a session —
|
|
88
|
+
* steering it, reading its events, configuring it — is addressed by session id, so "which ids are on
|
|
89
|
+
* this workspace" is the question that turns one workspace into N conversations. An empty roster is
|
|
90
|
+
* an answer, not a miss: a workspace nobody has opened a session on yet still exists.
|
|
91
|
+
*/
|
|
92
|
+
sessions(workspaceId: string, options?: CallOptions): Promise<Page<Session>>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=workspaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../src/resources/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,mBAAmB,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,EAAE,CAAC;IAChG,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAU;;IAGrB,YAAY,MAAM,EAAE,KAAK,EAExB;IAED,+DAA+D;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAExF;IAED;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAWzF;IAED;;;;;;;;OAQG;IACG,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAG9D;IAED;;;;;;OAMG;IACG,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAOjF;IAED;;;;;;;OAOG;IACG,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAOrF;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { callArgs, enc } from "./shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* The /v1/workspaces resource: open a workspace holding N repositories, read it back, and ask which
|
|
4
|
+
* sessions share its tree.
|
|
5
|
+
*
|
|
6
|
+
* ‼️ A WORKSPACE IS THE DURABLE THING AND A SESSION ATTACHES TO IT. That is the shape a caller has to
|
|
7
|
+
* hold: open one workspace, then open as many sessions on it as you have conversations to run, and all
|
|
8
|
+
* of them read and write ONE checkout on ONE machine. Opening a session per conversation without a
|
|
9
|
+
* workspace — which is what this SDK used to do — gives each one a tree of its own that the others
|
|
10
|
+
* cannot see, and a machine bill per conversation.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors the `Sessions` resource shape: a class taking the client, each method with a trailing
|
|
13
|
+
* `options: CallOptions`.
|
|
14
|
+
*/
|
|
15
|
+
export class Workspaces {
|
|
16
|
+
#client;
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.#client = client;
|
|
19
|
+
}
|
|
20
|
+
/** Read the complete tenant-scoped immutable file manifest. */
|
|
21
|
+
async manifest(manifestID, options = {}) {
|
|
22
|
+
return (await this.#client.request("GET", `/v1/workspace-manifests/${enc(manifestID)}`, callArgs(options))).body;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* create opens a workspace holding the declared repositories (201).
|
|
26
|
+
*
|
|
27
|
+
* ‼️ IT RETURNS BEFORE THE TREE EXISTS, and the clone is asynchronous because it takes as long as N
|
|
28
|
+
* clones take — a create that waited would make a five-repository workspace a request that times out.
|
|
29
|
+
*
|
|
30
|
+
* ‼️ DO NOT WAIT FOR `ready`. `status` is the workspace's PLACEMENT state, not its contents: `ready`
|
|
31
|
+
* means a machine holds it, so a workspace nothing has run on yet stays `requested` however complete
|
|
32
|
+
* its tree is. Measured on a live stack: a workspace whose two repositories were fully published sat
|
|
33
|
+
* at `requested` indefinitely until a session ran on it. Open a session and send a message — the
|
|
34
|
+
* first run places the workspace and pays no clone, which is the whole point of cloning at create.
|
|
35
|
+
*
|
|
36
|
+
* Like `sessions.create` it carries no idempotency key: creation is unkeyed, a retried create mints
|
|
37
|
+
* a NEW workspace, so a torn connection is left alone rather than retried into a duplicate tree.
|
|
38
|
+
*/
|
|
39
|
+
async create(params, options = {}) {
|
|
40
|
+
if (!params.repositories || params.repositories.length === 0) {
|
|
41
|
+
// The server refuses this, and a local complaint beats a round trip for a call the caller could
|
|
42
|
+
// not have meant.
|
|
43
|
+
throw new TypeError("palai: workspaces.create requires at least one repository");
|
|
44
|
+
}
|
|
45
|
+
const result = await this.#client.request("POST", "/v1/workspaces", {
|
|
46
|
+
body: { repositories: params.repositories },
|
|
47
|
+
...callArgs(options),
|
|
48
|
+
});
|
|
49
|
+
return result.body;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* list answers which workspaces this project has, newest first, each with its repositories.
|
|
53
|
+
*
|
|
54
|
+
* ‼️ IT IS THE READ EVERY CALLER NEEDS FIRST AND THE ONE THIS SURFACE SHIPPED WITHOUT. `create` and
|
|
55
|
+
* `retrieve` let a caller open a workspace and read back the one they just made; neither answers "which
|
|
56
|
+
* do I have?" — and since a session is born ON a workspace, every screen that opens one has to offer a
|
|
57
|
+
* choice. Measured on production: `GET /v1/workspaces` answered 405, while the admin console had already
|
|
58
|
+
* been written against a fixture that served it.
|
|
59
|
+
*/
|
|
60
|
+
async list(options = {}) {
|
|
61
|
+
const result = await this.#client.request("GET", "/v1/workspaces", callArgs(options));
|
|
62
|
+
return result.body;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* retrieve reads one workspace: its lifecycle state, the machine holding it if any, and its
|
|
66
|
+
* repositories at their mount paths, in the order genesis builds them.
|
|
67
|
+
*
|
|
68
|
+
* `machine_id` is null between runs and that is the ORDINARY state, not an error — the hold is
|
|
69
|
+
* released when every session on the tree goes idle and taken again on the next placement.
|
|
70
|
+
*/
|
|
71
|
+
async retrieve(workspaceId, options = {}) {
|
|
72
|
+
const result = await this.#client.request("GET", `/v1/workspaces/${enc(workspaceId)}`, callArgs(options));
|
|
73
|
+
return result.body;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* sessions lists the sessions sharing this workspace's tree, in creation order.
|
|
77
|
+
*
|
|
78
|
+
* THIS IS THE READ THAT MAKES THE SHARED TREE USABLE. Everything a caller can do to a session —
|
|
79
|
+
* steering it, reading its events, configuring it — is addressed by session id, so "which ids are on
|
|
80
|
+
* this workspace" is the question that turns one workspace into N conversations. An empty roster is
|
|
81
|
+
* an answer, not a miss: a workspace nobody has opened a session on yet still exists.
|
|
82
|
+
*/
|
|
83
|
+
async sessions(workspaceId, options = {}) {
|
|
84
|
+
const result = await this.#client.request("GET", `/v1/workspaces/${enc(workspaceId)}/sessions`, callArgs(options));
|
|
85
|
+
return result.body;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=workspaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/resources/workspaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAA+B,MAAM,aAAa,CAAC;AA0BzE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,UAAU;IACrB,OAAO,CAAQ;IAEf,YAAY,MAAa;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,+DAA+D;IAC/D,KAAK,CAAC,QAAQ,CAAC,UAAkB,EAAE,OAAO,GAAgB,EAAE;QAC1D,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAoB,KAAK,EAAE,2BAA2B,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtI,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,CAAC,MAA6B,EAAE,OAAO,GAAgB,EAAE;QACnE,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7D,gGAAgG;YAChG,kBAAkB;YAClB,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAY,MAAM,EAAE,gBAAgB,EAAE;YAC7E,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE;YAC3C,GAAG,QAAQ,CAAC,OAAO,CAAC;SACrB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,OAAO,GAAgB,EAAE;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAkB,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QACvG,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,WAAmB,EAAE,OAAO,GAAgB,EAAE;QAC3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACvC,KAAK,EACL,kBAAkB,GAAG,CAAC,WAAW,CAAC,EAAE,EACpC,QAAQ,CAAC,OAAO,CAAC,CAClB,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CAAC,WAAmB,EAAE,OAAO,GAAgB,EAAE;QAC3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACvC,KAAK,EACL,kBAAkB,GAAG,CAAC,WAAW,CAAC,WAAW,EAC7C,QAAQ,CAAC,OAAO,CAAC,CAClB,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
|