@conciergeprotocol/client 0.1.0 → 0.1.2
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 +88 -0
- package/package.json +9 -1
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @conciergeprotocol/client
|
|
2
|
+
|
|
3
|
+
Call a [Concierge Agent Protocol](https://conciergeprotocol.org) front door from JavaScript. Give it a domain. It reads `agent.txt`, posts one message, and waits for the company's reply.
|
|
4
|
+
|
|
5
|
+
The protocol is at [conciergeprotocol.org](https://conciergeprotocol.org). Source is at [github.com/conciergeprotocol/js](https://github.com/conciergeprotocol/js).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @conciergeprotocol/client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Node.js 18 or newer.
|
|
14
|
+
|
|
15
|
+
## Ask
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { createClient } from '@conciergeprotocol/client'
|
|
19
|
+
|
|
20
|
+
const cap = createClient({ from: 'agent:my-assistant' })
|
|
21
|
+
|
|
22
|
+
const answer = await cap.ask('cosmicjs.com', 'Do you have a free plan?')
|
|
23
|
+
console.log(answer.reply)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`from` is `agent:` plus 1 to 64 letters, numbers, dots, underscores, or hyphens. It tells the company who is calling.
|
|
27
|
+
|
|
28
|
+
A follow-up sends only the new question. The company keeps the earlier turns.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const thread = cap.thread('cosmicjs.com')
|
|
32
|
+
await thread.ask('What is Cosmic?')
|
|
33
|
+
const price = await thread.ask('How much is the cheapest paid plan?')
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## When there is no front door
|
|
37
|
+
|
|
38
|
+
`discover` returns `null`. `ask` throws `NoDoorError`. That is the signal to browse the site instead.
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { createClient, NoDoorError } from '@conciergeprotocol/client'
|
|
42
|
+
|
|
43
|
+
const cap = createClient({ from: 'agent:my-assistant' })
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const answer = await cap.ask('example.com', 'What are your hours?')
|
|
47
|
+
console.log(answer.reply)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof NoDoorError) {
|
|
50
|
+
// Browse the site.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Still working
|
|
56
|
+
|
|
57
|
+
`ask` waits up to two minutes. If the company is still answering, the message comes back with `status: 'working'` and no `reply`. Read it again with `get`. Do not write a reply while the status is `working`.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const message = await cap.ask('example.com', 'What are your hours?')
|
|
61
|
+
if (message.status === 'working') {
|
|
62
|
+
const later = await cap.get('example.com', message.id)
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
A `failed` message is a result, including `login_required`. It is not thrown.
|
|
67
|
+
|
|
68
|
+
## Account questions
|
|
69
|
+
|
|
70
|
+
`login` opens the company's page. `finishLogin` stores the token for that door, and the next `ask` sends it. Pass your own token store to `createClient` when the token should outlive the process.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const cap = createClient({
|
|
74
|
+
from: 'agent:my-assistant',
|
|
75
|
+
tokens: {
|
|
76
|
+
async get(origin) {},
|
|
77
|
+
async set(origin, token) {},
|
|
78
|
+
async delete(origin) {}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
await cap.login('example.com')
|
|
83
|
+
await cap.finishLogin(callbackUrl)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Apache 2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conciergeprotocol/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Call any Concierge Agent Protocol front door.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"node": ">=18"
|
|
17
17
|
},
|
|
18
18
|
"license": "Apache-2.0",
|
|
19
|
+
"homepage": "https://conciergeprotocol.org",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"concierge",
|
|
22
|
+
"cap",
|
|
23
|
+
"agents",
|
|
24
|
+
"protocol",
|
|
25
|
+
"ai"
|
|
26
|
+
],
|
|
19
27
|
"repository": {
|
|
20
28
|
"type": "git",
|
|
21
29
|
"url": "git+https://github.com/conciergeprotocol/js.git",
|