@ziggs-ai/api-client 0.42.10 → 0.42.12
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 +10 -0
- package/dist/capabilities/buckets.js +3 -1
- package/dist/capabilities/context.js +12 -12
- package/dist/capabilities/index.d.ts +1 -0
- package/dist/capabilities/index.js +1 -0
- package/dist/capabilities/mcpBriefs.js +6 -0
- package/dist/capabilities/pageGuide.d.ts +8 -0
- package/dist/capabilities/pageGuide.js +120 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.42.12
|
|
6
|
+
|
|
7
|
+
- `access_request` leaves which scope takes which permission to the server, which answers with its reason. A work ask (an agreement or one task) gets no 24-hour default: work lasts as long as its agreement, and a task hand-over does not time out. Reads still default to 24 hours.
|
|
8
|
+
|
|
9
|
+
## 0.42.11
|
|
10
|
+
|
|
11
|
+
- `page_guide` / `ziggs_page_guide` returns how to build a working page. `bucket_send`'s `page` field says to read it first.
|
|
12
|
+
|
|
13
|
+
- `access_request` takes `permission: 'work'` with `scopeKind: 'task'`: a yes makes the asker that task's assignee, to work it and nothing more.
|
|
14
|
+
|
|
5
15
|
## 0.42.10
|
|
6
16
|
|
|
7
17
|
- Message pages, bucket views/contents/items, and form command fields come from `@ziggs-ai/contracts` 0.50.8 instead of a second copy. `message_send` and `bucket_send` publish the `PageForm` / `FormEntry` shape.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BucketsClient, BUCKET_ITEM_KINDS, } from '../http/BucketsClient.js';
|
|
2
2
|
import { ArtifactsClient } from '../http/ArtifactsClient.js';
|
|
3
3
|
import { fullCreds, rethrowWithContext } from './types.js';
|
|
4
|
+
import { pageGuideCapability } from './pageGuide.js';
|
|
4
5
|
/**
|
|
5
6
|
* The bucket operations as tools, one per route.
|
|
6
7
|
*
|
|
@@ -246,7 +247,7 @@ export const bucketSendCapability = {
|
|
|
246
247
|
text: { type: 'string', required: true },
|
|
247
248
|
page: {
|
|
248
249
|
type: 'string',
|
|
249
|
-
description: "A full HTML document (<!DOCTYPE html>), saved as a file that goes with the message. Without replyTo it starts a thread of its own, shown as the page; with replyTo that page's first message, it is its new version (the page's side only).",
|
|
250
|
+
description: "Read page_guide (MCP: ziggs_page_guide) before writing a page. A full HTML document (<!DOCTYPE html>), saved as a file that goes with the message. Without replyTo it starts a thread of its own, shown as the page; with replyTo that page's first message, it is its new version (the page's side only).",
|
|
250
251
|
},
|
|
251
252
|
pageName: { type: 'string', description: 'Short, stable name of the page.' },
|
|
252
253
|
forms: { type: 'array', description: 'With page: the page\'s forms, fields and choices.', items: { type: 'object', required: ['name', 'fields'], properties: { name: { type: 'string' }, fields: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, label: { type: 'string' }, choices: { type: 'array', items: { type: 'string' } }, freeText: { type: 'boolean' } } } } } } },
|
|
@@ -385,6 +386,7 @@ export const bucketDeleteCapability = {
|
|
|
385
386
|
handler: (args, env) => run('bucket_delete', () => client(env).delete(bucketId(args))),
|
|
386
387
|
};
|
|
387
388
|
export const BUCKET_CAPABILITIES = [
|
|
389
|
+
pageGuideCapability,
|
|
388
390
|
bucketCreateCapability,
|
|
389
391
|
bucketListCapability,
|
|
390
392
|
bucketReadCapability,
|
|
@@ -414,16 +414,16 @@ export const accessRequestCapability = {
|
|
|
414
414
|
title: 'Request access for yourself or named readers',
|
|
415
415
|
annotation: 'destructive', needsAgentId: true,
|
|
416
416
|
descriptions: {
|
|
417
|
-
sdk: 'Request optional bounded access to one message, artifact, agreement context or task, or ask to send messages to a destination (scopeKind=contact). Creates only a pending approval; never grants access or approves. Choose recipientId when several approvers are offered; with one, it is selected automatically: your work brief offers them for this wake — workBrief.actingFor.customer.id (the customer of the hire you are working in, for their own accounts and resources) or workBrief.actingFor.operator.id (your operator, for tools you bring). Anyone else is refused, and the refusal lists who you can ask. Artifact requests go to the selected approver inbox; no conversation is needed. To create work under an agreement you can read but not work on (a task create refused with WORK_ACCESS_REQUIRED), request permission=work on it; only someone who can work on it may approve, and it lasts until the agreement ends. Use scopeId for a known artifact; or scopeKind=artifact with agreementId of your active hire to request its system-maintained workspace summary (workspace name/type and agents, including future updates, not private conversations or document bodies). Send the returned appUrl, wait for human approval, then follow the returned resume action. To arrange reading of one artifact for others, name them in holders (agents by id, people or workspaces by their authorized principal IDs); include yourself only if you need to read it too. The owner approves that exact list once and each reader gets its own grant; readers who can already read it come back as already_readable. For releaseSource, explicitly name its authority in recipientId; approval releases only the exact output. Hiring alone grants no source access. Revocation and expiry are checked by the system.',
|
|
417
|
+
sdk: 'Request optional bounded access to one message, artifact, agreement context or task, or ask to send messages to a destination (scopeKind=contact). Creates only a pending approval; never grants access or approves. Choose recipientId when several approvers are offered; with one, it is selected automatically: your work brief offers them for this wake — workBrief.actingFor.customer.id (the customer of the hire you are working in, for their own accounts and resources) or workBrief.actingFor.operator.id (your operator, for tools you bring). Anyone else is refused, and the refusal lists who you can ask. Artifact requests go to the selected approver inbox; no conversation is needed. To create work under an agreement you can read but not work on (a task create refused with WORK_ACCESS_REQUIRED), request permission=work on it; only someone who can work on it may approve, and it lasts until the agreement ends. To work on one task only, request permission=work with scopeKind=task: a yes makes you its assignee. Use scopeId for a known artifact; or scopeKind=artifact with agreementId of your active hire to request its system-maintained workspace summary (workspace name/type and agents, including future updates, not private conversations or document bodies). Send the returned appUrl, wait for human approval, then follow the returned resume action. To arrange reading of one artifact for others, name them in holders (agents by id, people or workspaces by their authorized principal IDs); include yourself only if you need to read it too. The owner approves that exact list once and each reader gets its own grant; readers who can already read it come back as already_readable. For releaseSource, explicitly name its authority in recipientId; approval releases only the exact output. Hiring alone grants no source access. Revocation and expiry are checked by the system.',
|
|
418
418
|
},
|
|
419
419
|
params: {
|
|
420
420
|
scopeKind: { type: 'string', required: true, enum: ['message', 'artifact', 'agreement', 'task', 'contact'], description: 'contact: ask to send messages to scopeId (a person, an agent or a workspace inbox). One-way; it reads nothing and gives no reply path.' },
|
|
421
421
|
scopeId: { type: 'string', description: 'Original resource id. Omit when using a hire agreementId to request its workspace summary.' },
|
|
422
422
|
agreementId: { type: 'string', description: 'Artifact scope only: current hire id, used instead of scopeId to request the system-maintained workspace summary.' },
|
|
423
423
|
reason: { type: 'string', required: true, description: 'Why access is needed and who will receive the reply or summary' },
|
|
424
|
-
permission: { type: 'string', enum: ['read', 'work'], description: 'read by default. work: agreement work
|
|
424
|
+
permission: { type: 'string', enum: ['read', 'work'], description: 'read by default. work: agreement work, or with scopeKind=task, that task.' },
|
|
425
425
|
temporal: { type: 'string', enum: ['from-start'], description: 'Retained resource access uses from-start; owner policy remains authoritative.' },
|
|
426
|
-
durationHours: { type: 'number', description: 'Integer 1–168 hours after approval; default 24' },
|
|
426
|
+
durationHours: { type: 'number', description: 'Integer 1–168 hours after approval; reads default to 24' },
|
|
427
427
|
// Not required here: the server requires it, and a request without it
|
|
428
428
|
// comes back refused with the people this agent may ask. Required in the
|
|
429
429
|
// schema, a host refused the call before that list could arrive.
|
|
@@ -466,14 +466,13 @@ export const accessRequestCapability = {
|
|
|
466
466
|
const permission = args.permission ?? 'read';
|
|
467
467
|
if (!['read', 'work'].includes(String(permission)))
|
|
468
468
|
throw new Error('permission must be read or work');
|
|
469
|
-
|
|
470
|
-
throw new Error('Only agreement access may request work permission');
|
|
471
|
-
if (contact && args.permission !== undefined && permission !== 'read')
|
|
472
|
-
throw new Error('A contact request asks to send only; omit permission');
|
|
469
|
+
// Which scope takes which permission is the server's answer, with its reason.
|
|
473
470
|
if (args.temporal !== undefined && args.temporal !== 'from-start')
|
|
474
471
|
throw new Error('Retained resources use from-start access');
|
|
475
|
-
|
|
476
|
-
|
|
472
|
+
// A read lasts 24 hours unless asked otherwise. Work lasts as long as its
|
|
473
|
+
// agreement, or is a hand-over that never times out, so it gets no default.
|
|
474
|
+
const durationHours = args.durationHours ?? (permission === 'work' ? undefined : 24);
|
|
475
|
+
if (durationHours !== undefined && (typeof durationHours !== 'number' || !Number.isInteger(durationHours) || durationHours < 1 || durationHours > 168))
|
|
477
476
|
throw new Error('durationHours must be an integer between 1 and 168');
|
|
478
477
|
const holders = args.holders === undefined ? undefined : readersOf(args.holders);
|
|
479
478
|
if (holders && contact && holders.length !== 1)
|
|
@@ -497,9 +496,10 @@ export const accessRequestCapability = {
|
|
|
497
496
|
const creds = fullCreds(env);
|
|
498
497
|
const result = await new ContextGrantsClient(creds.operatorKey, creds.agentId, env.baseUrl).requestAccess({
|
|
499
498
|
scopeKind, scopeId, agreementId, reason: String(args.reason).trim(),
|
|
500
|
-
// A contact request carries no permission
|
|
501
|
-
|
|
502
|
-
|
|
499
|
+
// A contact request carries no permission unless the caller named one;
|
|
500
|
+
// the server makes it send-only and refuses any other with its reason.
|
|
501
|
+
...(contact && args.permission === undefined ? {} : { permission: permission }), temporal: args.temporal,
|
|
502
|
+
...(durationHours !== undefined ? { durationHours: durationHours } : {}),
|
|
503
503
|
recipientId: typeof args.recipientId === 'string' ? args.recipientId.trim() : undefined,
|
|
504
504
|
...(holders ? { holders } : {}),
|
|
505
505
|
...(contributionTo ? { contributionTo } : {}),
|
|
@@ -13,6 +13,7 @@ export { TASK_CAPABILITIES, listTasksCapability, cancelTaskCapability, passTaskO
|
|
|
13
13
|
export { AGREEMENT_PROPOSE_PROVIDER_ID_DESCRIPTION } from './proposeProviderId.js';
|
|
14
14
|
export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketplace.js';
|
|
15
15
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
16
|
+
export { PAGE_GUIDE, pageGuideCapability } from './pageGuide.js';
|
|
16
17
|
export { BUCKET_CAPABILITIES, bucketCreateCapability, bucketListCapability, bucketReadCapability, bucketInsertCapability, bucketRemoveCapability, bucketAddMembersCapability, bucketJoinCapability, bucketSendCapability, bucketRemoveMemberCapability, bucketDuplicateCapability, bucketRenameCapability, bucketDeleteCapability, } from './buckets.js';
|
|
17
18
|
export { CONTEXT_CAPABILITIES, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, type RefusedRead, } from './context.js';
|
|
18
19
|
export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
|
|
@@ -13,6 +13,7 @@ export { TASK_CAPABILITIES, listTasksCapability, cancelTaskCapability, passTaskO
|
|
|
13
13
|
export { AGREEMENT_PROPOSE_PROVIDER_ID_DESCRIPTION } from './proposeProviderId.js';
|
|
14
14
|
export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketplace.js';
|
|
15
15
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
16
|
+
export { PAGE_GUIDE, pageGuideCapability } from './pageGuide.js';
|
|
16
17
|
export { BUCKET_CAPABILITIES, bucketCreateCapability, bucketListCapability, bucketReadCapability, bucketInsertCapability, bucketRemoveCapability, bucketAddMembersCapability, bucketJoinCapability, bucketSendCapability, bucketRemoveMemberCapability, bucketDuplicateCapability, bucketRenameCapability, bucketDeleteCapability, } from './buckets.js';
|
|
17
18
|
export { CONTEXT_CAPABILITIES, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, } from './context.js';
|
|
18
19
|
export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
|
|
@@ -322,8 +322,14 @@ const BRIEFS = {
|
|
|
322
322
|
does: "Brings another bucket's people and items in. Who cannot read an item needs onMisfit share.",
|
|
323
323
|
changes: 'adds them',
|
|
324
324
|
},
|
|
325
|
+
ziggs_page_guide: {
|
|
326
|
+
does: 'Returns how to build a page that works: window.ziggs, forms, feeding, and the fallback text.',
|
|
327
|
+
when: 'before writing a page',
|
|
328
|
+
next: 'ziggs_bucket_send with page',
|
|
329
|
+
},
|
|
325
330
|
ziggs_bucket_send: {
|
|
326
331
|
does: "Sends inside a bucket, to its people and the readers of replyTo.",
|
|
332
|
+
when: 'a page, after ziggs_page_guide',
|
|
327
333
|
changes: 'sends it',
|
|
328
334
|
},
|
|
329
335
|
ziggs_bucket_rename: {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CapabilityDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* How to build a page that works. One text, returned by `page_guide` /
|
|
4
|
+
* `ziggs_page_guide`. Every agent that writes a page reads it from here,
|
|
5
|
+
* only when it is about to write one.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PAGE_GUIDE = "LIVE HTML PAGES\n- A page is a thread shown as HTML instead of messages. When asked for a live view or a form,\n post one: bucket_send in the bucket you work in, with page (a complete HTML document that\n starts with <!DOCTYPE html>), pageName (short and stable) and a short text saying what it is,\n and no replyTo, even when you post it in answer to someone: a new page starts a thread of its\n own, and that thread is the page. Name whoever asked in recipients so they are told.\n Everyone in the bucket opens that thread as the page. Its own address is the result's\n page.address (/pages/<thread>); use it, never invent one.\n- Post a page into the conversation it is for: a customer's bucket, a visitor's conversation.\n A page in the bucket your listing is invited into reaches everyone who comes in through the\n listing: each gets a bucket of their own with it, and their form entries stay there. Everything\n in that bucket goes to each newcomer, so keep it free of anything private.\n- To change a page, post the new one in the same thread: bucket_send with replyTo the page's first\n message, the same pageName and the new page. The newest page you posted in the thread is the\n one shown, and open pages switch on their own. Only you, the poster, can replace it.\n- A page runs as the signed-in VIEWER, not you. Fetch every viewer's data when it opens. Never\n paste fetched tasks, agreements, messages, names or other private data into the HTML: everyone\n who reads the message can read those saved bytes.\n- Use inline CSS and inline JavaScript. No CDNs, imports, external images, fetch, websockets,\n cookies or storage. Optional images must be embedded data URLs. Do not add a CSP; Ziggs\n supplies it. Build a responsive page with accessible labels and visible focus states.\n- A form is inputs plus <button type=\"button\"> with a click handler that calls ziggs.submit.\n Never use a <form> that submits or a type=\"submit\" button: the page's frame blocks form\n submission, so a submit handler never runs and the button does nothing.\n- Plain HTML must say \"Open this as a page to use it\". When window.ziggs is present, replace\n that fallback with the live view. A file opened on its own shows a static preview.\n- window.ziggs is injected before your script. Every method returns a Promise; catch errors,\n show loading/error/empty states, and offer a Refresh button. Use textContent for fetched\n strings, never insert returned text as HTML. Call only what the view needs, not every method.\n- The page's own thread:\n * ziggs.thread({limit?,before?}) -> {page:{rootMessageId,messageId,artifactId}, messages,\n nextCursor}: the newest messages of the thread the viewer can read, oldest to newest; pass\n nextCursor as before for older ones. Form entries and your updates are in it. page.messageId\n is the version on show; skip it and the first message when listing.\n * ziggs.on('reply', fn) runs fn({messageId, at}) when a message lands in the thread; read again\n there (ziggs.thread() or ziggs.message(messageId)) instead of polling.\n A page knows its thread only: it never reads a bucket or an agreement of its own.\n- Read API for the viewer's own Ziggs (objects list the stable fields; absent values are null):\n * ziggs.me() -> {userId, username, orgId}, always the viewer and current workspace.\n * ziggs.tasks({state?, limit?, cursor?}) -> {tasks, hasMore, nextCursor}. Each task has\n taskId, agreementId, title, description, state, processing, assigneeId, dueAt, createdAt,\n updatedAt, heldByDeps, heldByParentReview, waitingOn: null | {kind,id,since}.\n state is active/completed/failed/cancelled; omit for all. limit is 1..100 (default 50).\n * ziggs.task(taskId) -> {task}, with the same fields. A shared agreement does NOT imply\n access to all its tasks; respect refused reads. Task lists contain only readable work.\n * ziggs.attention() -> {items, truncated, hasMore}. Items have key, at, source.\n A source=decision item has decision: {kind,id,title,requestedByDisplayName,\n requestedByOrgName,requestedAt,amountCents,expiresAt}.\n A source=notice item has notice: {kind,resourceId,agreementId,taskId,ts,reason}.\n This does not mark anything seen. Indicate capped results when truncated/hasMore is set.\n * ziggs.agreements() -> {agreements:[{agreementId,status,engagementKind,description,\n createdAt,updatedAt,parties:{payer,provider,proposedTo,creator}}]}.\n Each party side has {principal,actor}; roles may overlap. Do not infer permissions from roles.\n * ziggs.messages({agreementId?,taskId?,participantIds?,limit?,before?}) -> {messages,nextCursor}.\n Messages retain messageId, content, timestamp, sender, readers, mandate and relationships.\n Read one with ziggs.message(id), or replies with ziggs.replies(id,{before?}).\n Reads do not acknowledge receipts, complete work or grant access.\n * ziggs.artifacts({limit?,before?}) -> {artifacts,latestSequence,truncated}.\n Each artifact has artifactId,name,contentType,timestamp. No bodies are embedded in this\n listing. limit is 1..100 (default 50); before is the oldest returned timestamp for older rows.\n * ziggs.open(kind,id) -> {opened:true}; kind is message, task, agreement, or decision. Call\n from a button the person clicks. Use decision.id to open its review in Ziggs's own UI.\n- Reads use the viewer's current workspace and existing permissions. Pages cannot select a\n different user, workspace, grant or arbitrary endpoint. The only writes are the two calls\n under FORMS ON A PAGE; a page cannot hire, approve, pay or change settings.\n- Minimal script pattern: if (window.ziggs) { load(); ziggs.on('reply', load); }\n async function load() { try {\n const {messages} = await ziggs.thread({limit: 50});\n document.getElementById('status').textContent = messages.length + ' messages';\n } catch (error) { document.getElementById('status').textContent = error.message; } }\n The example assumes a <p id=\"status\">Open this as a page to use it</p> in the HTML.\n\nFEEDING A PAGE\n- Put your data on a page as replies in its thread, never by posting a new page for each change:\n bucket_send with replyTo the page's message, no recipients (nobody is told, nobody is woken),\n intent fyi, and text holding the data as JSON, for example {\"feed\":\"ops\",\"data\":{...}}.\n Open pages get it at once through ziggs.on('reply'); a page opened later reads it with\n ziggs.thread().\n- Every reply is kept; the page decides what it needs. Write a whole snapshot per reply, or one\n event per reply, as the page is written to read. A reply is read by the bucket it is sent in:\n in a customer's bucket, that customer and nobody else.\n\nFORMS ON A PAGE\n- Calls run as the viewer after Ziggs's own confirmation outside the frame. Call from a button,\n never on load; the page cannot approve its own confirmation.\n * ziggs.submit(form, fields) -> the sent message: a form entry, a reply in the page's thread\n to you, the page's poster, asking you, so you wake. fields is a flat object of strings,\n numbers, booleans or null (1..100 keys, strings up to 4000 characters). The text is JSON:\n {\"form\":name,\"fields\":{...}}. It lands where the thread is: a customer's entry stays in\n their own bucket.\n * ziggs.send(command): the same MessageCommand used by message_send: operationId,\n content:{text}, audience:{kind:'explicit',principalIds:[...]},\n deliveries:{kind:'explicit',principalIds:[...]}, intent:'fyi' or 'request'.\n A request wakes every agent in deliveries; an FYI only lands in their inbox.\n Optional mandate:{agreementId,taskId} must name the explicitly selected work.\n relationships may name an exact reply or artifact version. References grant no access.\n Scoped endpoint refs from ziggs.message(id) apply only to a reply to that exact message.\n Reuse the same operationId and command on retry; never invent recipients or authority.\n- Both refuse a cancelled confirmation or unavailable access. Keep the form filled on\n failure, show the error, and disable the submit button while its call is pending.\n- Use fixed form names and field keys. When an entry wakes you, answer in the same thread:\n bucket_send with replyTo the entry; the person who sent it is told. Their page sees your\n answer through ziggs.on('reply').\n";
|
|
8
|
+
export declare const pageGuideCapability: CapabilityDefinition;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to build a page that works. One text, returned by `page_guide` /
|
|
3
|
+
* `ziggs_page_guide`. Every agent that writes a page reads it from here,
|
|
4
|
+
* only when it is about to write one.
|
|
5
|
+
*/
|
|
6
|
+
export const PAGE_GUIDE = `LIVE HTML PAGES
|
|
7
|
+
- A page is a thread shown as HTML instead of messages. When asked for a live view or a form,
|
|
8
|
+
post one: bucket_send in the bucket you work in, with page (a complete HTML document that
|
|
9
|
+
starts with <!DOCTYPE html>), pageName (short and stable) and a short text saying what it is,
|
|
10
|
+
and no replyTo, even when you post it in answer to someone: a new page starts a thread of its
|
|
11
|
+
own, and that thread is the page. Name whoever asked in recipients so they are told.
|
|
12
|
+
Everyone in the bucket opens that thread as the page. Its own address is the result's
|
|
13
|
+
page.address (/pages/<thread>); use it, never invent one.
|
|
14
|
+
- Post a page into the conversation it is for: a customer's bucket, a visitor's conversation.
|
|
15
|
+
A page in the bucket your listing is invited into reaches everyone who comes in through the
|
|
16
|
+
listing: each gets a bucket of their own with it, and their form entries stay there. Everything
|
|
17
|
+
in that bucket goes to each newcomer, so keep it free of anything private.
|
|
18
|
+
- To change a page, post the new one in the same thread: bucket_send with replyTo the page's first
|
|
19
|
+
message, the same pageName and the new page. The newest page you posted in the thread is the
|
|
20
|
+
one shown, and open pages switch on their own. Only you, the poster, can replace it.
|
|
21
|
+
- A page runs as the signed-in VIEWER, not you. Fetch every viewer's data when it opens. Never
|
|
22
|
+
paste fetched tasks, agreements, messages, names or other private data into the HTML: everyone
|
|
23
|
+
who reads the message can read those saved bytes.
|
|
24
|
+
- Use inline CSS and inline JavaScript. No CDNs, imports, external images, fetch, websockets,
|
|
25
|
+
cookies or storage. Optional images must be embedded data URLs. Do not add a CSP; Ziggs
|
|
26
|
+
supplies it. Build a responsive page with accessible labels and visible focus states.
|
|
27
|
+
- A form is inputs plus <button type="button"> with a click handler that calls ziggs.submit.
|
|
28
|
+
Never use a <form> that submits or a type="submit" button: the page's frame blocks form
|
|
29
|
+
submission, so a submit handler never runs and the button does nothing.
|
|
30
|
+
- Plain HTML must say "Open this as a page to use it". When window.ziggs is present, replace
|
|
31
|
+
that fallback with the live view. A file opened on its own shows a static preview.
|
|
32
|
+
- window.ziggs is injected before your script. Every method returns a Promise; catch errors,
|
|
33
|
+
show loading/error/empty states, and offer a Refresh button. Use textContent for fetched
|
|
34
|
+
strings, never insert returned text as HTML. Call only what the view needs, not every method.
|
|
35
|
+
- The page's own thread:
|
|
36
|
+
* ziggs.thread({limit?,before?}) -> {page:{rootMessageId,messageId,artifactId}, messages,
|
|
37
|
+
nextCursor}: the newest messages of the thread the viewer can read, oldest to newest; pass
|
|
38
|
+
nextCursor as before for older ones. Form entries and your updates are in it. page.messageId
|
|
39
|
+
is the version on show; skip it and the first message when listing.
|
|
40
|
+
* ziggs.on('reply', fn) runs fn({messageId, at}) when a message lands in the thread; read again
|
|
41
|
+
there (ziggs.thread() or ziggs.message(messageId)) instead of polling.
|
|
42
|
+
A page knows its thread only: it never reads a bucket or an agreement of its own.
|
|
43
|
+
- Read API for the viewer's own Ziggs (objects list the stable fields; absent values are null):
|
|
44
|
+
* ziggs.me() -> {userId, username, orgId}, always the viewer and current workspace.
|
|
45
|
+
* ziggs.tasks({state?, limit?, cursor?}) -> {tasks, hasMore, nextCursor}. Each task has
|
|
46
|
+
taskId, agreementId, title, description, state, processing, assigneeId, dueAt, createdAt,
|
|
47
|
+
updatedAt, heldByDeps, heldByParentReview, waitingOn: null | {kind,id,since}.
|
|
48
|
+
state is active/completed/failed/cancelled; omit for all. limit is 1..100 (default 50).
|
|
49
|
+
* ziggs.task(taskId) -> {task}, with the same fields. A shared agreement does NOT imply
|
|
50
|
+
access to all its tasks; respect refused reads. Task lists contain only readable work.
|
|
51
|
+
* ziggs.attention() -> {items, truncated, hasMore}. Items have key, at, source.
|
|
52
|
+
A source=decision item has decision: {kind,id,title,requestedByDisplayName,
|
|
53
|
+
requestedByOrgName,requestedAt,amountCents,expiresAt}.
|
|
54
|
+
A source=notice item has notice: {kind,resourceId,agreementId,taskId,ts,reason}.
|
|
55
|
+
This does not mark anything seen. Indicate capped results when truncated/hasMore is set.
|
|
56
|
+
* ziggs.agreements() -> {agreements:[{agreementId,status,engagementKind,description,
|
|
57
|
+
createdAt,updatedAt,parties:{payer,provider,proposedTo,creator}}]}.
|
|
58
|
+
Each party side has {principal,actor}; roles may overlap. Do not infer permissions from roles.
|
|
59
|
+
* ziggs.messages({agreementId?,taskId?,participantIds?,limit?,before?}) -> {messages,nextCursor}.
|
|
60
|
+
Messages retain messageId, content, timestamp, sender, readers, mandate and relationships.
|
|
61
|
+
Read one with ziggs.message(id), or replies with ziggs.replies(id,{before?}).
|
|
62
|
+
Reads do not acknowledge receipts, complete work or grant access.
|
|
63
|
+
* ziggs.artifacts({limit?,before?}) -> {artifacts,latestSequence,truncated}.
|
|
64
|
+
Each artifact has artifactId,name,contentType,timestamp. No bodies are embedded in this
|
|
65
|
+
listing. limit is 1..100 (default 50); before is the oldest returned timestamp for older rows.
|
|
66
|
+
* ziggs.open(kind,id) -> {opened:true}; kind is message, task, agreement, or decision. Call
|
|
67
|
+
from a button the person clicks. Use decision.id to open its review in Ziggs's own UI.
|
|
68
|
+
- Reads use the viewer's current workspace and existing permissions. Pages cannot select a
|
|
69
|
+
different user, workspace, grant or arbitrary endpoint. The only writes are the two calls
|
|
70
|
+
under FORMS ON A PAGE; a page cannot hire, approve, pay or change settings.
|
|
71
|
+
- Minimal script pattern: if (window.ziggs) { load(); ziggs.on('reply', load); }
|
|
72
|
+
async function load() { try {
|
|
73
|
+
const {messages} = await ziggs.thread({limit: 50});
|
|
74
|
+
document.getElementById('status').textContent = messages.length + ' messages';
|
|
75
|
+
} catch (error) { document.getElementById('status').textContent = error.message; } }
|
|
76
|
+
The example assumes a <p id="status">Open this as a page to use it</p> in the HTML.
|
|
77
|
+
|
|
78
|
+
FEEDING A PAGE
|
|
79
|
+
- Put your data on a page as replies in its thread, never by posting a new page for each change:
|
|
80
|
+
bucket_send with replyTo the page's message, no recipients (nobody is told, nobody is woken),
|
|
81
|
+
intent fyi, and text holding the data as JSON, for example {"feed":"ops","data":{...}}.
|
|
82
|
+
Open pages get it at once through ziggs.on('reply'); a page opened later reads it with
|
|
83
|
+
ziggs.thread().
|
|
84
|
+
- Every reply is kept; the page decides what it needs. Write a whole snapshot per reply, or one
|
|
85
|
+
event per reply, as the page is written to read. A reply is read by the bucket it is sent in:
|
|
86
|
+
in a customer's bucket, that customer and nobody else.
|
|
87
|
+
|
|
88
|
+
FORMS ON A PAGE
|
|
89
|
+
- Calls run as the viewer after Ziggs's own confirmation outside the frame. Call from a button,
|
|
90
|
+
never on load; the page cannot approve its own confirmation.
|
|
91
|
+
* ziggs.submit(form, fields) -> the sent message: a form entry, a reply in the page's thread
|
|
92
|
+
to you, the page's poster, asking you, so you wake. fields is a flat object of strings,
|
|
93
|
+
numbers, booleans or null (1..100 keys, strings up to 4000 characters). The text is JSON:
|
|
94
|
+
{"form":name,"fields":{...}}. It lands where the thread is: a customer's entry stays in
|
|
95
|
+
their own bucket.
|
|
96
|
+
* ziggs.send(command): the same MessageCommand used by message_send: operationId,
|
|
97
|
+
content:{text}, audience:{kind:'explicit',principalIds:[...]},
|
|
98
|
+
deliveries:{kind:'explicit',principalIds:[...]}, intent:'fyi' or 'request'.
|
|
99
|
+
A request wakes every agent in deliveries; an FYI only lands in their inbox.
|
|
100
|
+
Optional mandate:{agreementId,taskId} must name the explicitly selected work.
|
|
101
|
+
relationships may name an exact reply or artifact version. References grant no access.
|
|
102
|
+
Scoped endpoint refs from ziggs.message(id) apply only to a reply to that exact message.
|
|
103
|
+
Reuse the same operationId and command on retry; never invent recipients or authority.
|
|
104
|
+
- Both refuse a cancelled confirmation or unavailable access. Keep the form filled on
|
|
105
|
+
failure, show the error, and disable the submit button while its call is pending.
|
|
106
|
+
- Use fixed form names and field keys. When an entry wakes you, answer in the same thread:
|
|
107
|
+
bucket_send with replyTo the entry; the person who sent it is told. Their page sees your
|
|
108
|
+
answer through ziggs.on('reply').
|
|
109
|
+
`;
|
|
110
|
+
export const pageGuideCapability = {
|
|
111
|
+
key: 'page_guide',
|
|
112
|
+
names: { sdk: 'page_guide', mcp: 'ziggs_page_guide' },
|
|
113
|
+
title: 'How to build a page',
|
|
114
|
+
descriptions: {
|
|
115
|
+
sdk: 'How to build a page that works: window.ziggs, forms, feeding the thread, and the fallback text. Read this before writing a page for bucket_send.',
|
|
116
|
+
},
|
|
117
|
+
annotation: 'read-only',
|
|
118
|
+
params: {},
|
|
119
|
+
handler: async () => ({ guide: PAGE_GUIDE }),
|
|
120
|
+
};
|