@pstdio/pocketcoder-sdk 0.7.0 → 0.9.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 +43 -3
- package/dist/index.d.ts +5450 -1840
- package/dist/index.js +1239 -436
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,6 +52,38 @@ Use `client.raw(path, init)` for endpoints not yet represented by a typed
|
|
|
52
52
|
resource client. API failures throw `PocketCoderError`; expired or deleted
|
|
53
53
|
conversation history throws the more specific `ConversationGoneError`.
|
|
54
54
|
|
|
55
|
+
## Managed sessions
|
|
56
|
+
|
|
57
|
+
Applications that use PocketCoder as their agent runtime work with logical sessions
|
|
58
|
+
and never name a workspace. PocketCoder places, replaces and stops compute itself.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const session = await client.sessions.create({ sessionId, profileId, profileRevision: 1 });
|
|
62
|
+
const file = await client.files.put(session.sessionId, { inputId, name: "notes.txt", mediaType: "text/plain", bytes });
|
|
63
|
+
// Store this body before sending it. After a lost reply, send the identical body again.
|
|
64
|
+
const body = { requestId, message: "Summarize the notes", attachments: [file.reference], dispatchDeadline };
|
|
65
|
+
await client.requests.submit(session.sessionId, body);
|
|
66
|
+
|
|
67
|
+
const { records, eventCursor } = await client.sessions.snapshot(session.sessionId);
|
|
68
|
+
for await (const event of client.sessions.events(session.sessionId, { after: eventCursor, signal })) {
|
|
69
|
+
// Delivered at least once: skip resource revisions you already applied, keep event.cursor.
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Resource | Methods |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `client.sessions` | `create`, `get`, `resume`, `close`, `history`, `snapshot`, `events`, `openPreview` |
|
|
76
|
+
| `client.requests` | `submit`, `get`, `cancel`, `collection` |
|
|
77
|
+
| `client.files` | `put`, `register`, `upload`, `get`, `exports`, `content` |
|
|
78
|
+
| `client.authority` | `grantScope`, `putPolicy`, `getPolicy`, `usage`, `putProfile`, `putCredentialBinding` |
|
|
79
|
+
|
|
80
|
+
`events` resumes after the last delivered cursor (also sent as `Last-Event-ID`) when a
|
|
81
|
+
stream ends. It throws `events.cursor_expired` when the cursor is no longer retained:
|
|
82
|
+
read a new snapshot and follow its `eventCursor`. `cancel` and `close` return a receipt
|
|
83
|
+
that stays `pending` until the stop has evidence; retry with the same `cancelId`.
|
|
84
|
+
Budgets cover physical capacity only; model usage belongs to the model gateway. See the
|
|
85
|
+
[reference consumer](../../examples/clients/managed-runtime/README.md).
|
|
86
|
+
|
|
55
87
|
## Resolve one user turn after preservation
|
|
56
88
|
|
|
57
89
|
Create one long-lived `WorkspaceTurnResolver` in a trusted backend. Call it
|
|
@@ -90,13 +122,21 @@ const resolver = new WorkspaceTurnResolver({
|
|
|
90
122
|
|
|
91
123
|
export async function handleTurn(sourceWorkspaceId: string, prompt: string) {
|
|
92
124
|
const { workspace } = await resolver.resolve(sourceWorkspaceId);
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
const conversationId = crypto.randomUUID();
|
|
126
|
+
let request = await client.workspaceRequests.submit(workspace.id, {
|
|
127
|
+
requestId: crypto.randomUUID(), conversationId, message: prompt, files: [],
|
|
128
|
+
});
|
|
129
|
+
while (!request.finalizedAt) {
|
|
130
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
131
|
+
request = await client.workspaceRequests.get(workspace.id, request.acceptance.execution.requestId, conversationId);
|
|
132
|
+
}
|
|
133
|
+
const history = await client.conversations.read(workspace.id, conversationId);
|
|
134
|
+
return { workspace_id: workspace.id, conversation_id: conversationId, messages: history.items };
|
|
95
135
|
}
|
|
96
136
|
```
|
|
97
137
|
|
|
98
138
|
The key needs `workspaces:read`; a callback that calls `resume()` also needs
|
|
99
|
-
`workspaces:restore`.
|
|
139
|
+
`workspaces:restore`. Native session requests and attachments need `services:relay` and
|
|
100
140
|
`attachments:write` respectively.
|
|
101
141
|
|
|
102
142
|
The resolver stores no A-to-B mapping. Return the resolved id through your
|