@sess.si/sdk 0.1.0-rc.5 → 0.1.0-rc.8

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/NOTICE +18 -0
  3. package/README.md +113 -19
  4. package/dist/ask.d.ts +162 -0
  5. package/dist/ask.d.ts.map +1 -0
  6. package/dist/ask.js +500 -0
  7. package/dist/ask.js.map +1 -0
  8. package/dist/cli/verify.d.ts +1 -1
  9. package/dist/cli/verify.d.ts.map +1 -1
  10. package/dist/cli/verify.js +49 -3
  11. package/dist/cli/verify.js.map +1 -1
  12. package/dist/client.d.ts +8 -0
  13. package/dist/client.d.ts.map +1 -1
  14. package/dist/client.js +10 -0
  15. package/dist/client.js.map +1 -1
  16. package/dist/errors.d.ts +18 -0
  17. package/dist/errors.d.ts.map +1 -1
  18. package/dist/errors.js +22 -1
  19. package/dist/errors.js.map +1 -1
  20. package/dist/generated/openapi.d.ts +6914 -1015
  21. package/dist/generated/openapi.d.ts.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/internal/decode.d.ts.map +1 -1
  26. package/dist/internal/decode.js +41 -1
  27. package/dist/internal/decode.js.map +1 -1
  28. package/dist/polling.d.ts +9 -0
  29. package/dist/polling.d.ts.map +1 -1
  30. package/dist/polling.js +78 -1
  31. package/dist/polling.js.map +1 -1
  32. package/dist/qr/encoder.d.ts +11 -0
  33. package/dist/qr/encoder.d.ts.map +1 -0
  34. package/dist/qr/encoder.js +344 -0
  35. package/dist/qr/encoder.js.map +1 -0
  36. package/dist/qr/index.d.ts +56 -0
  37. package/dist/qr/index.d.ts.map +1 -0
  38. package/dist/qr/index.js +151 -0
  39. package/dist/qr/index.js.map +1 -0
  40. package/dist/receipts/index.d.ts +3 -1
  41. package/dist/receipts/index.d.ts.map +1 -1
  42. package/dist/receipts/index.js +2 -1
  43. package/dist/receipts/index.js.map +1 -1
  44. package/dist/receipts/renderers.d.ts +58 -0
  45. package/dist/receipts/renderers.d.ts.map +1 -0
  46. package/dist/receipts/renderers.js +154 -0
  47. package/dist/receipts/renderers.js.map +1 -0
  48. package/dist/receipts/resource.d.ts.map +1 -1
  49. package/dist/receipts/resource.js +27 -0
  50. package/dist/receipts/resource.js.map +1 -1
  51. package/dist/receipts/verify.d.ts +24 -1
  52. package/dist/receipts/verify.d.ts.map +1 -1
  53. package/dist/receipts/verify.js +63 -17
  54. package/dist/receipts/verify.js.map +1 -1
  55. package/dist/sessions.d.ts.map +1 -1
  56. package/dist/sessions.js +7 -0
  57. package/dist/sessions.js.map +1 -1
  58. package/dist/transport.d.ts +2 -0
  59. package/dist/transport.d.ts.map +1 -1
  60. package/dist/transport.js +37 -3
  61. package/dist/transport.js.map +1 -1
  62. package/dist/types.d.ts +86 -6
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js.map +1 -1
  65. package/dist/webhooks/index.js +1 -1
  66. package/dist/webhooks/index.js.map +1 -1
  67. package/package.json +6 -2
  68. package/src/ask.ts +683 -0
  69. package/src/cli/verify.ts +61 -3
  70. package/src/client.ts +14 -0
  71. package/src/errors.ts +31 -0
  72. package/src/generated/openapi.ts +7168 -1160
  73. package/src/index.ts +1 -0
  74. package/src/internal/decode.ts +32 -1
  75. package/src/polling.ts +97 -1
  76. package/src/qr/encoder.ts +345 -0
  77. package/src/qr/index.ts +203 -0
  78. package/src/receipts/index.ts +3 -1
  79. package/src/receipts/renderers.ts +220 -0
  80. package/src/receipts/resource.ts +37 -0
  81. package/src/receipts/verify.ts +108 -22
  82. package/src/sessions.ts +11 -0
  83. package/src/transport.ts +45 -3
  84. package/src/types.ts +88 -4
  85. package/src/webhooks/index.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,103 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0-rc.8 — 2026-10-22 (prepared, unpublished)
4
+
5
+ - Link timing (Decision 0009 Amendment 10). On an interactive Sess link of 20 hours or less the
6
+ person may ask for more time, up to ten times, never past a fixed horizon. Session reads carry
7
+ `link_state` (`live`, `lapsed` or `expired`), `action_expires_horizon`, `extensions_used` and the
8
+ `extensions` history; the Session log (`listEvents()`) lists the same records as
9
+ `link_extensions`, beside the Events, whose shape is unchanged. New types `LinkState` and
10
+ `LinkExtension`. These fields are checked when present; a runtime without link timing omits them
11
+ and is read as before.
12
+ - `waitForResponse()` and `answer()` treat a lapsed link as still open: they keep waiting until the
13
+ horizon and end with `wait_ended` `LINK_EXPIRED` only once a read shows the link expired (two
14
+ seconds past its end on the runtime clock, or, when the end cannot be placed, such as a
15
+ revocation, a later read at least the grace after the first expired read; a short `intervalMs`
16
+ reads again sooner but never ends the wait inside the grace). A live read never ends the wait. Without `link_state` the
17
+ deadline stays final, as in rc.7.
18
+ - Contract snapshot from Sess runtime commit `2f8500e` (w1991e/sess master, PR #431's merge commit;
19
+ see `contract/contract-lock.json`). Besides link timing it carries what Sess master already
20
+ describes: the interactive text limits with `field`, `limit` and `length` on a length error,
21
+ `progress`, the receipt `format` and the renderer identities list. The generated wire types gain
22
+ them; the SDK's public types and behavior in this change are link timing only.
23
+ - Renderer identities (Decision 0009 Amendment 13). A receipt's `surface.renderer_version` now
24
+ verifies when it is an identity this release bundles (`sess-html-form-1`, `sess-html-form-2`;
25
+ `BUNDLED_RENDERER_IDENTITIES`) or one on the issuer's renderer list whose signature verifies
26
+ under the same trusted keys and issuer, so a later Sess page change needs no SDK update. Every
27
+ receipt that verified before still verifies, offline, with no list.
28
+ - `verifyResponse()` (and so `sess.ask()`'s `answer()`) fetch the list from the API origin
29
+ (`/.well-known/sess-renderer-identities.json`) only for an identity this release does not
30
+ bundle. `verifyDecisionReceipt` takes it as `rendererIdentities`; `verifyRendererIdentities`
31
+ verifies a list on its own. A forged, unsigned, re-typed, foreign or malformed list fails with
32
+ `INVALID_RENDERER_LIST`; an identity on no verified list fails with `UNSUPPORTED_RENDERER`, as
33
+ before. New types `RendererIdentitiesDocument`, `RendererIdentity` and `RendererList`.
34
+ `ReceiptClaims`' `surface.renderer_version` is now `string`.
35
+ - Renderer list editions. A list carries a signed `seq` (its edition, higher in every later
36
+ published edition) and `iat` (when that copy was signed); `verifyRendererIdentities` returns
37
+ `{ seq, iat, identities }`. `newerRendererList` orders two authentic lists by `seq`, with
38
+ containment as the cross-check, and refuses lists that disagree (`INVALID_RENDERER_LIST`);
39
+ `BUNDLED_RENDERER_LIST` is the bundled edition 1, and a verified list must agree with it. An
40
+ older list proves the identities it holds, never their absence: an identity it does not hold is
41
+ `UNSUPPORTED_RENDERER`, never accepted by fallback. Each online verification fetches the list
42
+ afresh (the endpoint is served `no-store`); nothing is cached.
43
+ - `sess verify --renderers <file>`: with the issuer's signed list (verified under `--keys` and
44
+ `--issuer`; a list that does not verify exits 2), the bundle's renderer identity must be known
45
+ or listed (otherwise invalid, exit 1). Without it, bundle verification is unchanged.
46
+ - The receipt-v1 specification copy is from Sess commit `a60ca69` (§10, renderer identities with
47
+ `seq` and `iat`; Sess PR #444's merge commit).
48
+ - Sess's length limits, in Unicode code points and never truncated: title 80, description 280,
49
+ heading 60, field and option labels 60, field description 160, action label 24, record caption
50
+ 200, record key 40 and string value 200, text 4,000; at most 5 actions. The types' JSDoc gives each field its
51
+ purpose, style and limit.
52
+ - `sess.ask()` checks them before anything is sent: `question` 80, `submit_label` 24, field
53
+ labels and options 60 (were 200).
54
+ - A length error carries `field` (a JSON pointer), `limit` and `length` on `SessError`, from
55
+ `sess.ask()` (`INVALID_QUESTION`) and from Sess (400 `INVALID_SCHEMA`), and its message is
56
+ Sess's own fix. The README and the quickstart show catching it, shortening the value and asking again.
57
+ Surfaces stored before these limits still read as before.
58
+
59
+ ## 0.1.0-rc.7 — 2026-10-18 (prepared, unpublished)
60
+
61
+ Includes everything in the unpublished 0.1.0-rc.6 below, which is not published on its own.
62
+
63
+ - Advanced: a link lifetime. `sessions.create()` and `sess.ask()` take an optional `expires_in`, in
64
+ whole seconds from creation: from 30 up to your plan's link lifetime (Sess checks the ceiling).
65
+ Values below 30 or not whole are refused before anything is sent. Absent: the plan's lifetime,
66
+ as before.
67
+ - The create response carries the link's expiry as `action_expires_at`; `sess.ask()` handles expose
68
+ it as `expiresAt`. Nothing moves it later: not reading, not completing.
69
+ - `waitForResponse()` (and `answer()`) observe the expiry. Once the runtime clock (the response's
70
+ HTTP `Date`, else this machine's) is two seconds past `action_expires_at`, one final read decides:
71
+ an answer accepted before the expiry is returned as the result; otherwise the wait ends with
72
+ `wait_ended`, code `LINK_EXPIRED`. The SDK never completes a Session on its own.
73
+ - `ResponseMeta.serverDate`: the response's HTTP `Date`, when the runtime sends one.
74
+ - Contract snapshot from Sess runtime commit `b48e8e7` (see `contract/contract-lock.json`), with
75
+ `expires_in`, `action_expires_at` on create and the target's `default_expires_in`.
76
+ - `@sess.si/sdk/qr` (S-07): `qr(url, { format: 'svg' | 'png' | 'terminal' })` draws a Sess link as a
77
+ QR code locally (error correction level M, 4-module quiet zone, deterministic, no network call), and
78
+ `printQr(url)` prints "Scan to answer on your phone" and the code on an interactive terminal only:
79
+ never without a TTY, in CI or with `NODE_ENV=production`; `--no-qr` or `{ qr: false }` turn it off
80
+ and `NO_COLOR` draws it without colour. The SVG is one exact tree with the accessible title "QR code
81
+ for this Sess link". The encoder is the Sess renderer's, after Project Nayuki's QR Code generator
82
+ (MIT; see NOTICE). No new dependency; every existing export is unchanged.
83
+
84
+ ## 0.1.0-rc.6 — 2026-10-15
85
+
86
+ - `sess.ask({ question, fields })`: one question with simple typed fields (the MCP `sess_ask`
87
+ shape). It validates locally, creates the Session once and returns its private link before
88
+ waiting. `answer()` verifies the receipt and exact Surface, checks that the answer is still
89
+ current, completes the Session and returns values typed from the field definitions and checked at
90
+ runtime. New types `AskInput`, `AskField`, `AskAnswer`, `AskHandle`, `AskOptions` and
91
+ `AskAnswerOptions`. Every existing export, `verifyDecisionReceipt` and the advanced API are
92
+ unchanged.
93
+ - The README opens with `sess.ask()`; the full Surface API is under "Advanced", unchanged.
94
+ - Wording only: the README's guide list and closing note, and the `0.1.0-rc.3` entry below, no
95
+ longer refer to internal processes or unreleased work.
96
+ - Wording only: the README, the package description and four error messages say "Sess" in plain
97
+ sentences. The README drops the stale manual-refresh caveat (the hosted page now advances between
98
+ rounds by itself) and notes that Sess supplies the trusted workspace for verification. Error
99
+ `kind`, `code` and every other field are unchanged.
100
+
3
101
  ## 0.1.0-rc.5 — 2026-10-15
4
102
 
5
103
  - `verifyDecisionBundle` in `@sess.si/sdk/receipts`: offline verification of a bundle-v1 decision
@@ -21,7 +119,7 @@ printed before waiting) and points to this changelog and the registry's dist-tag
21
119
 
22
120
  ## 0.1.0-rc.3 — 2026-10-13
23
121
 
24
- Unpublished R2 corrective candidate, now named `@sess.si/sdk` by the owner's superseding distribution decision. Earlier candidates and their recorded hashes retain their historical `@sess/sdk` identity; no alias is created. Inherit and validate polling operation budgets, dispose cancelled polling/backoff listeners, and match the runtime replay-key alphabet in transport and durable examples. Extend tracked-source and retained-history scanning with pinned tooling and synthetic controls.
122
+ Unpublished corrective candidate, the first named `@sess.si/sdk`. Earlier candidates and their recorded hashes keep their historical `@sess/sdk` name; no alias is created. Inherit and validate polling operation budgets, dispose cancelled polling/backoff listeners, and match the runtime replay-key alphabet in transport and durable examples. Extend tracked-source and retained-history scanning with pinned tooling and synthetic controls.
25
123
 
26
124
  ## 0.1.0-rc.2 — 2026-10-13
27
125
 
package/NOTICE CHANGED
@@ -7,3 +7,21 @@ The hosted SESS runtime and renderer are not included.
7
7
 
8
8
  Runtime dependencies retain their own notices and licenses: jose (MIT),
9
9
  canonicalize (Apache-2.0), and standardwebhooks (MIT). They are not bundled.
10
+
11
+ The QR Code encoder in src/qr/encoder.ts is structured after Project Nayuki's QR Code generator
12
+ library (https://www.nayuki.io/page/qr-code-generator-library), used under the MIT License:
13
+
14
+ Copyright (c) Project Nayuki. (MIT License)
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
17
+ associated documentation files (the "Software"), to deal in the Software without restriction,
18
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
19
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+ - The above copyright notice and this permission notice shall be included in all copies or
22
+ substantial portions of the Software.
23
+ - The Software is provided "as is", without warranty of any kind, express or implied, including
24
+ but not limited to the warranties of merchantability, fitness for a particular purpose and
25
+ noninfringement. In no event shall the authors or copyright holders be liable for any claim,
26
+ damages or other liability, whether in an action of contract, tort or otherwise, arising from,
27
+ out of or in connection with the Software or the use or other dealings in the Software.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # SESS SDK
1
+ # Sess SDK
2
2
 
3
3
  Ask a person a question from your server and continue with their verified answer. `@sess.si/sdk`
4
- creates a hosted SESS page, waits for the answer on the exact Surface revision, verifies its signed
5
- receipt, and continues the same Session.
4
+ creates a hosted Sess page, waits for the answer, checks its signed receipt and continues the same
5
+ Session.
6
6
 
7
7
  **Install** from npm:
8
8
 
@@ -13,19 +13,95 @@ npm install --save-exact @sess.si/sdk@next
13
13
  **Run** the [plain-Node quickstart](examples/quickstart-node/README.md), a complete program that
14
14
  needs only `SESS_API_KEY`.
15
15
 
16
- **What you'll see:** a private human link, printed before the program starts waiting. Open it on any
16
+ **What you'll see:** a Sess link, printed before the program starts waiting. Open it on any
17
17
  device and answer; the program prints the verified answer and completes the Session.
18
18
 
19
+ ## Ask a person
20
+
21
+ Use a developer API key from [the Sess developer portal](https://app.sess.si). Keep it on the server.
22
+ The [hosted no-signup demo](https://sess.si) is a separate trial flow; a Sess link or trial credential
23
+ is not an owner API key. You need no LLM, agent framework, Docker or Sess source checkout.
24
+
25
+ <!-- example:ask -->
26
+
27
+ ```ts
28
+ import { Sess } from '@sess.si/sdk';
29
+ const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
30
+ const question = await sess.ask({
31
+ question: 'Approve the synthetic refund?',
32
+ fields: [
33
+ { name: 'approved', label: 'Approve it', type: 'boolean' },
34
+ { name: 'amount', label: 'Refund amount', type: 'number', minimum: 0 },
35
+ ],
36
+ });
37
+ console.log(`Send this Sess link to the person: ${question.link}`);
38
+ const { approved, amount } = await question.answer(); // verified; the Session is now complete
39
+ if (approved) console.log(`Refund of ${amount.toFixed(2)} approved.`);
40
+ ```
41
+
42
+ <!-- /example:ask -->
43
+
44
+ `sess.ask()` checks the question locally, creates the Session once and returns its Sess link
45
+ before anything waits. The link is a bearer capability: deliver it only to the person, never to
46
+ logs or analytics. `answer()` waits for the person (ten minutes by default), verifies the signed
47
+ receipt against the exact question, checks that the answer is still the current step, completes the
48
+ Session and returns the values typed from your fields. Completion closes the Session: the link no
49
+ longer accepts answers. Field types are `text`, `number`, `integer`, `boolean`, `choice` and
50
+ `multi_choice` ([API reference](docs/api.md#ask-one-question)).
51
+
52
+ If the wait times out (`wait_ended`, code `WAIT_TIMEOUT`) or you abort it, nothing changes remotely:
53
+ call `answer()` again on the same handle. An error with `outcome: "unknown"` means completion is not
54
+ confirmed; calling `answer()` again replays the same completion. The handle lives in memory only. To
55
+ resume after a restart, persist `sessionId` and `revision` and continue with the API below
56
+ ([Integration](docs/integration.md#one-question-with-sessask)).
57
+
58
+ ## Keep it short
59
+
60
+ A person reads the page on a phone, so Sess keeps every piece of it short. Lengths count
61
+ characters (Unicode code points), and Sess never truncates:
62
+
63
+ | What | Style | At most |
64
+ | --------------------------- | ------------------------------ | -------- |
65
+ | Title (`question`) | A question or a task, about 40 | 80 |
66
+ | Button (`submit_label`) | A verb, 1–3 words | 24 |
67
+ | Field label, option | Short | 60 |
68
+ | Help (field `description`) | One hint | 160 |
69
+ | Description under the title | One or two sentences | 280 |
70
+ | Heading | Short | 60 |
71
+ | Record caption | A few words | 200 |
72
+ | Record key / string value | As written | 40 / 200 |
73
+ | Text (`details`) | Plain text | 4,000 |
74
+
75
+ There are at most 5 buttons. A value over its limit fails with a `SessError` that names it:
76
+ `field` is a JSON pointer such as `/question`, `limit` is the most it may have and `length` is
77
+ what it has. The message says how to fix it: "The title can be at most 80 characters. Keep it
78
+ to a short heading, about 40." for the title, and for anything else, for example
79
+ "/fields/0/label is 72 characters; the limit is 60. Shorten it to at most 60 characters." Nothing
80
+ was created (`outcome` is `not_sent` or `rejected`), so shorten the value and ask again:
81
+
82
+ ```ts
83
+ import { Sess, SessError } from '@sess.si/sdk';
84
+ declare function shorten(text: string, max: number): Promise<string>; // e.g. your model rewrites it
85
+
86
+ const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
87
+ const fields = [{ name: 'approved', label: 'Approve it', type: 'boolean' }] as const;
88
+ async function askShort(question: string) {
89
+ try {
90
+ return await sess.ask({ question, fields });
91
+ } catch (error) {
92
+ if (!(error instanceof SessError) || error.field !== '/question' || error.limit === undefined)
93
+ throw error;
94
+ return sess.ask({ question: await shorten(question, error.limit), fields });
95
+ }
96
+ }
97
+ ```
98
+
19
99
  **Release status:** every SDK release so far is a `0.1.0` release candidate, served under the `next`
20
100
  dist-tag. There is no stable release yet: do not install the bare name, whose `latest` tag points at a
21
101
  deprecated `0.0.0-stage` placeholder. The [changelog](CHANGELOG.md) describes each version;
22
102
  `npm view @sess.si/sdk dist-tags` shows what the registry serves now.
23
103
 
24
- ## Create and verify an interaction
25
-
26
- Use a developer API key from [the SESS developer portal](https://app.sess.si). Keep it on the server.
27
- The [hosted no-signup demo](https://sess.si) is a separate trial flow; a human link or trial credential
28
- is not an owner API key. No LLM, agent framework, Docker or SESS source checkout is needed by consumers.
104
+ ## Advanced: the full Surface API
29
105
 
30
106
  <!-- example:quickstart -->
31
107
 
@@ -72,11 +148,10 @@ if (typeof amount !== 'number' || !Number.isFinite(amount)) {
72
148
 
73
149
  <!-- /example:quickstart -->
74
150
 
75
- Full verification needs a trusted workspace audience. A runtime supporting the authenticated
76
- `Sess-Workspace-Id` header supplies it. On an older runtime, configure `expectedWorkspaceId` from
77
- trusted deployment settings. Otherwise verification fails with `VERIFICATION_CONTEXT_MISSING`;
78
- the SDK never learns a trusted audience from the unverified receipt. The runtime companion change
79
- is under review and is not a claim about the currently deployed service.
151
+ Verification checks that the receipt was issued for your workspace. Sess names your workspace on
152
+ authenticated responses (the `Sess-Workspace-Id` header), so you set nothing. If a runtime does not
153
+ send it, set `expectedWorkspaceId` from trusted deployment settings; otherwise verification fails
154
+ with `VERIFICATION_CONTEXT_MISSING`. The SDK never takes the workspace from the unverified receipt.
80
155
 
81
156
  The [quickstart function](examples/quickstart.ts) includes a private delivery callback.
82
157
  [Three-round continuation](examples/multi-round.ts) persists mutation intent and checks that an
@@ -102,6 +177,27 @@ result. Nothing is sent anywhere. In code, use `verifyDecisionBundle` from `@ses
102
177
  ([Security](docs/security.md#decision-bundles)). Formats: [receipt-v1](docs/spec/receipt-v1.md) and
103
178
  [bundle-v1](docs/spec/bundle-v1.md).
104
179
 
180
+ ## Show the link as a QR code
181
+
182
+ When the person is at a laptop and would answer on their phone, draw the link as a QR code, locally,
183
+ with no network call:
184
+
185
+ ```ts
186
+ import { printQr, qr } from '@sess.si/sdk/qr';
187
+
188
+ const link = 'https://sess.si/s/synthetic-link'; // the link sess.ask() returned
189
+ console.log(link);
190
+ printQr(link); // prints "Scan to answer on your phone" and the code, on an interactive terminal only
191
+ const svg = qr(link, { format: 'svg' }); // also 'png' (bytes) and 'terminal' (text)
192
+ ```
193
+
194
+ Use it where a person sees a screen but not their phone: a desktop chat window, a dashboard, a kiosk,
195
+ print. Skip it in SMS, or when the person is already on their phone. Sess never shows or sends the
196
+ code; your agent chooses. `printQr` prints nothing without a TTY, in CI (`CI` set), in production
197
+ (`NODE_ENV=production`), with `--no-qr` or with `{ qr: false }`, and draws without colour under
198
+ `NO_COLOR`. The code is the private link in another form: keep it wherever you keep the link, and
199
+ never in logs, analytics or a URL.
200
+
105
201
  ## Runtime and imports
106
202
 
107
203
  Supported: maintained Node 22 releases at or above 22.14, and Node 24 (recommended).
@@ -109,7 +205,7 @@ TypeScript consumer declarations target 5.9 and current stable. JavaScript consu
109
205
  The package contains one ESM build. CommonJS applications use `await import('@sess.si/sdk')`, as in the
110
206
  [CommonJS example](examples/commonjs.cjs); synchronous `require` is not a supported contract.
111
207
 
112
- Entry points are `@sess.si/sdk`, `@sess.si/sdk/receipts` and `@sess.si/sdk/webhooks`. Importing or constructing
208
+ Entry points are `@sess.si/sdk`, `@sess.si/sdk/receipts`, `@sess.si/sdk/webhooks` and `@sess.si/sdk/qr`. Importing or constructing
113
209
  the SDK does not contact a service, start a server, read credential files or log data.
114
210
 
115
211
  ## Errors and retries
@@ -146,11 +242,9 @@ contract is served at [OpenAPI](https://api.sess.si/openapi.json).
146
242
  - [Integration](docs/integration.md): authoring, lifecycle, validation, durability and future boundaries.
147
243
  - [Security](docs/security.md) and [receipt example](examples/receipt-verification.ts).
148
244
  - [Webhooks](docs/webhooks.md) and [Node receiver with a durable-inbox boundary](examples/webhook-receiver.ts).
149
- - [Compatibility](docs/compatibility.md), [testbed migration](docs/migration.md) and [release runbook](docs/releasing.md).
245
+ - [Compatibility](docs/compatibility.md), [migrating to the registry package](docs/migration.md) and [release runbook](docs/releasing.md).
150
246
  - [Plain-Node quickstart](examples/quickstart-node/README.md): a complete program, from the first call to the verified answer.
151
247
 
152
- The present runtime can require manual browser refresh between rounds. Owner polling in this
153
- SDK does not change that browser behavior. Appearance configuration and front-door invocation
154
- helpers remain conditional future work, with no placeholder exports.
248
+ Sess renders the page the person sees; this SDK has no appearance settings.
155
249
 
156
250
  [Contribute](CONTRIBUTING.md) · [Security reporting](SECURITY.md) · [Apache-2.0](LICENSE)
package/dist/ask.d.ts ADDED
@@ -0,0 +1,162 @@
1
+ import type { ReceiptResource } from './receipts/resource.js';
2
+ import type { Sessions } from './sessions.js';
3
+ import type { InteractiveInteraction, RequestOptions } from './types.js';
4
+ interface AskFieldBase {
5
+ /** Key of this field in the answer: `^[a-z][a-z0-9_]{0,63}$`. */
6
+ readonly name: string;
7
+ /** What the field asks for: short, a few words; at most 60. Example: `Refund amount` */
8
+ readonly label: string;
9
+ /** Default `true`, except boolean fields (default `false`). */
10
+ readonly required?: boolean;
11
+ }
12
+ /**
13
+ * One simple field of a single question. Each kind compiles to the ordinary interactive field
14
+ * with the runtime names, limits and schema semantics. `default` is a proposal the person can
15
+ * correct; it must itself be a valid value.
16
+ */
17
+ export type AskField = (AskFieldBase & {
18
+ readonly type: 'text';
19
+ readonly multiline?: boolean;
20
+ readonly default?: string;
21
+ }) | (AskFieldBase & {
22
+ readonly type: 'number' | 'integer';
23
+ readonly minimum?: number;
24
+ readonly maximum?: number;
25
+ readonly default?: number;
26
+ }) | (AskFieldBase & {
27
+ readonly type: 'boolean';
28
+ readonly default?: boolean;
29
+ }) | (AskFieldBase & {
30
+ readonly type: 'choice';
31
+ /** 1–100 choices. The words shown for one choice: short; at most 60. Example: `Next Monday` */
32
+ readonly options: readonly [string, ...string[]];
33
+ readonly default?: string;
34
+ }) | (AskFieldBase & {
35
+ readonly type: 'multi_choice';
36
+ /** 1–100 choices. The words shown for one choice: short; at most 60. Example: `Next Monday` */
37
+ readonly options: readonly [string, ...string[]];
38
+ readonly default?: readonly string[];
39
+ });
40
+ /**
41
+ * A question plus typed fields: the same shape as the MCP `sess_ask` tool input. Lengths are in
42
+ * Unicode code points and are never truncated: a value over its limit throws a `SessError` whose
43
+ * `field`, `limit` and `length` say which value to shorten and to what.
44
+ */
45
+ export interface AskInput<F extends readonly AskField[] = readonly AskField[]> {
46
+ /**
47
+ * The page's heading: a question or a task, about 40 characters; at most 80.
48
+ * Examples: `Approve the refund?`, `Pick a delivery date`
49
+ */
50
+ readonly question: string;
51
+ /** Optional plain-text context shown above the fields, at most 4,000 characters. */
52
+ readonly details?: string;
53
+ /** A button: a verb, 1–3 words; at most 24. Default `Send`. Examples: `Approve`, `Send refund` */
54
+ readonly submit_label?: string;
55
+ /** One to twelve fields with unique names. */
56
+ readonly fields: F;
57
+ /**
58
+ * Advanced: how long the link stays open, in whole seconds from creation: from 30 up to your
59
+ * plan's link lifetime (Sess checks the ceiling). Absent: the plan's lifetime.
60
+ */
61
+ readonly expires_in?: number;
62
+ }
63
+ type AskValue<T> = T extends {
64
+ type: 'text';
65
+ } ? string : T extends {
66
+ type: 'number' | 'integer';
67
+ } ? number : T extends {
68
+ type: 'boolean';
69
+ } ? boolean : T extends {
70
+ type: 'choice';
71
+ options: readonly (infer O extends string)[];
72
+ } ? O : T extends {
73
+ type: 'multi_choice';
74
+ options: readonly (infer O extends string)[];
75
+ } ? readonly O[] : never;
76
+ /** A checkbox and a multiple choice always have a value; other fields only when required. */
77
+ type AlwaysPresent<T> = T extends {
78
+ type: 'boolean' | 'multi_choice';
79
+ } ? true : T extends {
80
+ required: false;
81
+ } ? false : T extends {
82
+ required: true;
83
+ } ? true : T extends {
84
+ required: boolean;
85
+ } ? false : true;
86
+ type Simplify<T> = {
87
+ [K in keyof T]: T[K];
88
+ } & {};
89
+ /** The verified answer type inferred from the field definitions (and checked at runtime). */
90
+ export type AskAnswer<F extends readonly AskField[]> = Simplify<{
91
+ readonly [P in F[number] as AlwaysPresent<P> extends true ? P['name'] : never]: AskValue<P>;
92
+ } & {
93
+ readonly [P in F[number] as AlwaysPresent<P> extends true ? never : P['name']]?: AskValue<P>;
94
+ }>;
95
+ export interface AskOptions extends RequestOptions {
96
+ /** Trusted expected receipt audience for this question; defaults to the client configuration. */
97
+ expectedWorkspaceId?: string;
98
+ }
99
+ export interface AskAnswerOptions {
100
+ /** Total local wait for the person, default ten minutes. Ending it never closes the Session. */
101
+ timeoutMs?: number;
102
+ /** Polling interval, default 1,500 ms plus jitter, minimum 1,000 ms. */
103
+ intervalMs?: number;
104
+ /** Ends the local wait of this call only. */
105
+ signal?: AbortSignal;
106
+ }
107
+ /** One question: its private link now, its verified answer later. */
108
+ export interface AskHandle<T> {
109
+ /** Private bearer link for the person. Deliver it only to them; keep it out of logs. */
110
+ readonly link: string;
111
+ readonly sessionId: string;
112
+ /** The Surface revision of the question, for recovery through the advanced API. */
113
+ readonly revision: number;
114
+ /**
115
+ * When the link stops taking answers (`action_expires_at`, ISO 8601), as created. On a link of
116
+ * 20 hours or less the person may ask for more time, which moves it forward up to a fixed
117
+ * horizon; while the link is lapsed (past it, still extendable) `answer()` keeps waiting. An
118
+ * answer accepted before the end is still returned after it; with none, `answer()` ends with
119
+ * `wait_ended` code `LINK_EXPIRED` once the link has expired. Null only from a runtime that
120
+ * does not report it.
121
+ */
122
+ readonly expiresAt: string | null;
123
+ /**
124
+ * Waits for the answer, verifies its signed receipt and exact bindings, checks that it is still
125
+ * the current step, completes (closes) the Session, then returns the typed answer.
126
+ */
127
+ answer(options?: AskAnswerOptions): Promise<T>;
128
+ }
129
+ declare const TYPES: readonly ["text", "number", "integer", "boolean", "choice", "multi_choice"];
130
+ type AskType = (typeof TYPES)[number];
131
+ /** Internal compiled field: what an accepted answer is checked against. */
132
+ interface CompiledField {
133
+ name: string;
134
+ type: AskType;
135
+ required: boolean;
136
+ options?: readonly string[];
137
+ minimum?: number;
138
+ maximum?: number;
139
+ }
140
+ export interface CompiledAsk {
141
+ interaction: InteractiveInteraction;
142
+ fields: readonly CompiledField[];
143
+ /** The link lifetime in seconds, when the question set one. */
144
+ expiresIn?: number;
145
+ }
146
+ /** The shortest link lifetime Sess accepts, in seconds (the ceiling is the plan's). */
147
+ export declare const LINK_LIFETIME_FLOOR_SECONDS = 30;
148
+ /**
149
+ * The one deterministic simple-field compiler: validates a question locally, without network,
150
+ * credential or clock access, and expands it into the ordinary interactive Surface.
151
+ */
152
+ export declare function compileAsk(input: unknown): CompiledAsk;
153
+ /**
154
+ * Checks verified answer data against the compiled fields and returns a frozen copy in field
155
+ * order. It follows the runtime decoding: a checkbox is always present, a multiple choice is
156
+ * always a list, and an empty optional value is absent.
157
+ */
158
+ export declare function checkAnswer(fields: readonly CompiledField[], data: unknown): Readonly<Record<string, unknown>>;
159
+ /** Validates locally, creates once (the link is available before any wait) and returns the handle. */
160
+ export declare function ask<T>(sessions: Sessions, receipts: ReceiptResource, input: unknown, options?: AskOpt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