@proveanything/smartlinks 2.1.20 → 2.1.22

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.
@@ -37,6 +37,10 @@ and change them through change sets. The declarations make it *good* at your app
37
37
  The files sit in `public/assistant/` in your project and ship with every release like any other static
38
38
  file (they are read from the release's CDN folder, on the channel the collection runs your app on).
39
39
 
40
+ The same block also says **what your app's data means** to the assistant (`purpose`, `objects`, `words`,
41
+ `recipes`): which standard objects are what in your app, and which may only be changed through your
42
+ actions. See **[assistant-context.md](assistant-context.md)**.
43
+
40
44
  ### How they are loaded
41
45
 
42
46
  When an admin opens a chat, the assistant's box gets the **index** of every installed app's skills: one
@@ -0,0 +1,119 @@
1
+ # Telling the assistant what your app's data means
2
+
3
+ SmartLinks keeps a business's data in standard objects: work orders, containers and stock, bookings,
4
+ records, contacts, history. The assistant can read all of them. What it can't know is what they **mean in
5
+ your app**: that a work order is a job, that a container of type `drum` is a drum of juice, that a
6
+ booking with `data.event = "christmas-fair"` is a stall at the school fair.
7
+
8
+ Tell it, in the manifest's `assistant` block, beside any skills and knowledge files
9
+ ([assistant-apps.md](assistant-apps.md)). Four keys:
10
+
11
+ ```jsonc
12
+ // app.manifest.json
13
+ "assistant": {
14
+ "purpose": "Production manager for a fragrance filling and decorating factory: jobs from sales order to put-away.",
15
+ "objects": [
16
+ {
17
+ "object": "workOrder",
18
+ "where": { "appId": "accord-production" },
19
+ "means": "A job.",
20
+ "fields": {
21
+ "ref": "job number, from the sales order",
22
+ "kind": "job type: FillOnly, DecorateOnly, CompleteJob, PackagingOnly, Conversion",
23
+ "dueAt": "target date",
24
+ "data.stage": "the stage shown on screen",
25
+ "stages": "picking, then decoration, filling, packaging (\"boxing\" on screen), wrapping"
26
+ },
27
+ "write": "actions"
28
+ },
29
+ { "object": "container", "where": { "containerType": "drum" }, "means": "A drum of bulk juice; its ref is the batch number.", "write": "actions" },
30
+ { "object": "container", "where": { "containerType": "location" }, "means": "A place in the factory.", "write": "direct" },
31
+ { "object": "history", "where": { "type": "job.*" }, "means": "A job's timeline.", "write": "none" }
32
+ ],
33
+ "words": {
34
+ "GMP": "the batch manufacturing record printed for each job",
35
+ "the diary": "production runs by day"
36
+ },
37
+ "recipes": [
38
+ { "question": "What's on tomorrow?", "answer": "this app's work order stages planned for that day, by stage; show machine or crew" },
39
+ { "question": "Which jobs are late?", "answer": "use the action jobs.late: it applies the app's own rule for late" }
40
+ ]
41
+ }
42
+ ```
43
+
44
+ | Key | What it is | Limit |
45
+ |---|---|---|
46
+ | `purpose` | One line on what the app or site is for. The assistant always has it in view. | 200 characters |
47
+ | `objects` | What each standard object means here, and whether the assistant may change it. | 20 |
48
+ | `words` | The business's own terms. | 40 |
49
+ | `recipes` | How to answer the questions people actually ask. | 30 |
50
+
51
+ All four together: at most 6,000 characters. The assistant reads this every time a question touches your
52
+ app, so short wins. Anything malformed is left out and anything too long is cut (recipes first), without
53
+ an error: check what you wrote reads well.
54
+
55
+ ## Objects
56
+
57
+ - **`object`**: the standard object: `workOrder`, `workOrderStage`, `container`, `stock`, `booking`,
58
+ `record`, `contact`, `product`, `history`.
59
+ - **`where`**: which ones, with the filters the SDK takes (`appId`, `containerType`, `recordType`,
60
+ `data.<field>`).
61
+ - **`means`**: what it is here, in a sentence.
62
+ - **`fields`**: only the fields whose name doesn't say what they hold.
63
+ - **`write`**: may the assistant change it?
64
+
65
+ | `write` | Means |
66
+ |---|---|
67
+ | `direct` | Through the API, as a planned change the person applies. |
68
+ | `actions` | **Only through one of your app's actions**, never another way. |
69
+ | `none` | Never. |
70
+ | absent | Nothing is said; the platform's usual rules apply. |
71
+
72
+ **Record types you declared in the `data` block don't need repeating.** The assistant gets their titles
73
+ and fields from there ([admin-lists-and-pickers.md](admin-lists-and-pickers.md)); add an `objects`
74
+ entry only to say what one means or to set its `write` rule.
75
+
76
+ ## Actions, when changing something has rules
77
+
78
+ If creating or changing a thing involves rules that live in your code (a number from a counter, a check,
79
+ someone who must be told), don't describe the rules and hope: mark the object `"write": "actions"` and
80
+ give the assistant an **action** that does it. An action is one of your functions offered as a tool
81
+ ([agent-tools.md](agent-tools.md)):
82
+
83
+ ```jsonc
84
+ {
85
+ "name": "run.plan",
86
+ "trigger": { "type": "http", "methods": ["POST"] },
87
+ "agent": {
88
+ "tool": true,
89
+ "audience": ["assistant"],
90
+ "title": "Plan a production run",
91
+ "description": "Plan one stage of a job for a day, by hand or on a machine, with its crew.",
92
+ "input": { "type": "object", "properties": { "job": { "type": "string" }, "stage": { "type": "string" }, "date": { "type": "string" } }, "required": ["job", "stage", "date"] },
93
+ "approval": "require"
94
+ }
95
+ }
96
+ ```
97
+
98
+ Your rules then run in code every time. Keep actions few and coarse: one "find jobs" with filters, not
99
+ five narrow ones. Use `"approval": "require"` for anything that changes or sends something: the person
100
+ confirms it on a card.
101
+
102
+ ## A site speaks for the business
103
+
104
+ A site is the business's own app, so its description is about the **business**:
105
+
106
+ - its `purpose` leads the assistant's map of the business;
107
+ - it may describe objects that **other installed apps** keep. Narrow them with `where.appId`:
108
+
109
+ ```jsonc
110
+ { "object": "booking", "where": { "appId": "appointment-booking", "data.event": "christmas-fair" }, "means": "A stall at the Christmas fair." }
111
+ ```
112
+
113
+ - where the site and an app describe the same object, the site's meaning comes first.
114
+
115
+ So "how many bookings for the Christmas fair?" is answered from the right bookings.
116
+
117
+ ## Types
118
+
119
+ `AppAssistantDeclaration` (`purpose`, `objects`, `words`, `recipes`), `AssistantObject`, `AssistantRecipe`.
package/docs/realtime.md CHANGED
@@ -37,6 +37,26 @@ off()
37
37
  - **A change carries ids, never data.** Refetch through the normal API, which applies the normal
38
38
  permissions, so realtime can never show someone data they couldn't read anyway.
39
39
 
40
+ ### Changes to what your app works on: `onStaffChange`
41
+
42
+ Work orders, containers and stock aren't public and aren't only for admins: the people on a production
43
+ floor or in a warehouse need to see them move. Those changes go to the app's **staff feed**:
44
+
45
+ ```ts
46
+ // Every screen of a production app refetches when a job, a container or stock changes.
47
+ const off = realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries())
48
+ ```
49
+
50
+ - **Types:** `workOrder` (`id`, `appId`), `container` (`id`, `kind` = its container type), `stock`
51
+ (`id` = the container, `productId`). Filter as with `onChange`: `{ type: 'workOrder', id }`.
52
+ - **What is sent:** a change to one of the app's work orders; a change to a container or stock made
53
+ **by the app's own server functions**; and a change to one of the app's own records (`type: 'record'`,
54
+ with `recordType`), except a person's private ones. Sent after the change is saved, each thing once.
55
+ - **Who hears it:** someone in one of the app's user groups, and collection admins. By default the
56
+ groups are the ones the app's server functions are limited to (`userGroups` on each function).
57
+ To say otherwise, name them: `"realtime": { "staff": ["manager", "warehouse-operative"] }`.
58
+ - **IDs only**, as always: refetch through your own functions, which apply your own rules.
59
+
40
60
  With React Query, invalidate on change:
41
61
 
42
62
  ```ts
package/openapi.yaml CHANGED
@@ -3223,6 +3223,70 @@ paths:
3223
3223
  application/json:
3224
3224
  schema:
3225
3225
  $ref: "#/components/schemas/ContactCreateRequest"
3226
+ /admin/collection/{collectionId}/contacts/duplicates:
3227
+ get:
3228
+ tags:
3229
+ - contact
3230
+ summary: "Admin: pairs of contacts that look like one person."
3231
+ operationId: contact_findDuplicates
3232
+ security:
3233
+ - bearerAuth: []
3234
+ parameters:
3235
+ - name: collectionId
3236
+ in: path
3237
+ required: true
3238
+ schema:
3239
+ type: string
3240
+ - name: limit
3241
+ in: query
3242
+ required: false
3243
+ schema:
3244
+ type: string
3245
+ - name: offset
3246
+ in: query
3247
+ required: false
3248
+ schema:
3249
+ type: string
3250
+ responses:
3251
+ 200:
3252
+ description: Success
3253
+ content:
3254
+ application/json:
3255
+ schema:
3256
+ $ref: "#/components/schemas/ContactDuplicatesResponse"
3257
+ 400:
3258
+ description: Bad request
3259
+ 401:
3260
+ description: Unauthorized
3261
+ 404:
3262
+ description: Not found
3263
+ /admin/collection/{collectionId}/contacts/link-login:
3264
+ post:
3265
+ tags:
3266
+ - contact
3267
+ summary: "Admin: the contact that carries a sign-in, attaching the sign-in first to the contact that already holds its verified email or phone."
3268
+ operationId: contact_linkLogin
3269
+ security:
3270
+ - bearerAuth: []
3271
+ parameters:
3272
+ - name: collectionId
3273
+ in: path
3274
+ required: true
3275
+ schema:
3276
+ type: string
3277
+ responses:
3278
+ 200:
3279
+ description: Success
3280
+ content:
3281
+ application/json:
3282
+ schema:
3283
+ $ref: "#/components/schemas/ContactLinkLoginResponse"
3284
+ 400:
3285
+ description: Bad request
3286
+ 401:
3287
+ description: Unauthorized
3288
+ 404:
3289
+ description: Not found
3226
3290
  /admin/collection/{collectionId}/contacts/lookup:
3227
3291
  get:
3228
3292
  tags:
@@ -3538,6 +3602,38 @@ paths:
3538
3602
  description: Unauthorized
3539
3603
  404:
3540
3604
  description: Not found
3605
+ /admin/collection/{collectionId}/contacts/{keepContactId}/merge:
3606
+ post:
3607
+ tags:
3608
+ - contact
3609
+ summary: "Admin: fold contact `fromContactId` INTO contact `keepContactId`."
3610
+ operationId: contact_merge
3611
+ security:
3612
+ - bearerAuth: []
3613
+ parameters:
3614
+ - name: collectionId
3615
+ in: path
3616
+ required: true
3617
+ schema:
3618
+ type: string
3619
+ - name: keepContactId
3620
+ in: path
3621
+ required: true
3622
+ schema:
3623
+ type: string
3624
+ responses:
3625
+ 200:
3626
+ description: Success
3627
+ content:
3628
+ application/json:
3629
+ schema:
3630
+ $ref: "#/components/schemas/ContactMergeResponse"
3631
+ 400:
3632
+ description: Bad request
3633
+ 401:
3634
+ description: Unauthorized
3635
+ 404:
3636
+ description: Not found
3541
3637
  /admin/collection/{collectionId}/containers:
3542
3638
  get:
3543
3639
  tags:
@@ -21669,6 +21765,8 @@ components:
21669
21765
  type: string
21670
21766
  admin:
21671
21767
  type: string
21768
+ adminPage:
21769
+ type: string
21672
21770
  widgets:
21673
21771
  $ref: "#/components/schemas/AppManifestWidgets"
21674
21772
  containers:
@@ -21699,6 +21797,14 @@ components:
21699
21797
  realtime:
21700
21798
  type: object
21701
21799
  additionalProperties: true
21800
+ channels:
21801
+ type: array
21802
+ items:
21803
+ $ref: "#/components/schemas/RealtimeChannelDeclaration"
21804
+ staff:
21805
+ type: array
21806
+ items:
21807
+ type: string
21702
21808
  adminCards:
21703
21809
  $ref: "#/components/schemas/AppManifestAdminCards"
21704
21810
  data:
@@ -21741,6 +21847,55 @@ components:
21741
21847
  $ref: "#/components/schemas/AppAssistantFile"
21742
21848
  preview:
21743
21849
  type: string
21850
+ purpose:
21851
+ type: string
21852
+ objects:
21853
+ type: array
21854
+ items:
21855
+ $ref: "#/components/schemas/AssistantObject"
21856
+ words:
21857
+ type: object
21858
+ additionalProperties:
21859
+ type: string
21860
+ recipes:
21861
+ type: array
21862
+ items:
21863
+ $ref: "#/components/schemas/AssistantRecipe"
21864
+ AssistantObject:
21865
+ type: object
21866
+ properties:
21867
+ object:
21868
+ type: string
21869
+ where:
21870
+ type: object
21871
+ additionalProperties:
21872
+ type: object
21873
+ additionalProperties: true
21874
+ means:
21875
+ type: string
21876
+ fields:
21877
+ type: object
21878
+ additionalProperties:
21879
+ type: string
21880
+ write:
21881
+ type: string
21882
+ enum:
21883
+ - direct
21884
+ - actions
21885
+ - none
21886
+ required:
21887
+ - object
21888
+ - means
21889
+ AssistantRecipe:
21890
+ type: object
21891
+ properties:
21892
+ question:
21893
+ type: string
21894
+ answer:
21895
+ type: string
21896
+ required:
21897
+ - question
21898
+ - answer
21744
21899
  ConnectorConnectionField:
21745
21900
  type: object
21746
21901
  properties:
@@ -28537,6 +28692,91 @@ components:
28537
28692
  - items
28538
28693
  - limit
28539
28694
  - offset
28695
+ ContactDuplicatePair:
28696
+ type: object
28697
+ properties:
28698
+ keep:
28699
+ $ref: "#/components/schemas/Contact"
28700
+ merge:
28701
+ $ref: "#/components/schemas/Contact"
28702
+ matchedOn:
28703
+ type: object
28704
+ additionalProperties: true
28705
+ required:
28706
+ - keep
28707
+ - merge
28708
+ - matchedOn
28709
+ ContactDuplicatesResponse:
28710
+ type: object
28711
+ properties:
28712
+ pairs:
28713
+ type: array
28714
+ items:
28715
+ $ref: "#/components/schemas/ContactDuplicatePair"
28716
+ scanned:
28717
+ type: number
28718
+ more:
28719
+ type: boolean
28720
+ required:
28721
+ - pairs
28722
+ - scanned
28723
+ - more
28724
+ ContactMergeResponse:
28725
+ type: object
28726
+ properties:
28727
+ contactId:
28728
+ type: string
28729
+ mergedFrom:
28730
+ type: string
28731
+ moved:
28732
+ type: object
28733
+ additionalProperties: true
28734
+ login:
28735
+ type: boolean
28736
+ identities:
28737
+ type: number
28738
+ records:
28739
+ type: number
28740
+ cases:
28741
+ type: number
28742
+ threads:
28743
+ type: number
28744
+ bookings:
28745
+ type: number
28746
+ loyaltyMembers:
28747
+ type: number
28748
+ assets:
28749
+ type: number
28750
+ uploadTokens:
28751
+ type: number
28752
+ aiSessions:
28753
+ type: number
28754
+ messages:
28755
+ type: number
28756
+ conversations:
28757
+ type: number
28758
+ contact:
28759
+ $ref: "#/components/schemas/Contact"
28760
+ required:
28761
+ - contactId
28762
+ - mergedFrom
28763
+ - moved
28764
+ - login
28765
+ - identities
28766
+ - contact
28767
+ ContactLinkLoginResponse:
28768
+ type: object
28769
+ properties:
28770
+ contactId:
28771
+ type: string
28772
+ linked:
28773
+ type: boolean
28774
+ contact:
28775
+ $ref: "#/components/schemas/Contact"
28776
+ required:
28777
+ - contactId
28778
+ - linked
28779
+ - contact
28540
28780
  ContactSearchParams:
28541
28781
  type: object
28542
28782
  properties:
@@ -28904,6 +29144,9 @@ components:
28904
29144
  $ref: "#/components/schemas/Contact"
28905
29145
  ContactUpdateRequest:
28906
29146
  $ref: "#/components/schemas/ContactCreateRequest"
29147
+ ContactMergeErrorCode:
29148
+ type: object
29149
+ additionalProperties: true
28907
29150
  PublicContactUpsertRequest:
28908
29151
  $ref: "#/components/schemas/Contact"
28909
29152
  ContactPatch:
@@ -35373,6 +35616,8 @@ components:
35373
35616
  type: string
35374
35617
  status:
35375
35618
  type: string
35619
+ kind:
35620
+ type: string
35376
35621
  at:
35377
35622
  type: number
35378
35623
  required:
@@ -35393,6 +35638,8 @@ components:
35393
35638
  type: string
35394
35639
  proofId:
35395
35640
  type: string
35641
+ kind:
35642
+ type: string
35396
35643
  RealtimeChannelDeclaration:
35397
35644
  type: object
35398
35645
  properties:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.1.20",
3
+ "version": "2.1.22",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",