digital-tools 2.1.3 → 2.4.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +2 -0
- package/dist/client.d.ts +109 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/define.d.ts +2 -2
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +21 -11
- package/dist/define.js.map +1 -1
- package/dist/function-ref.d.ts +229 -0
- package/dist/function-ref.d.ts.map +1 -0
- package/dist/function-ref.js +28 -0
- package/dist/function-ref.js.map +1 -0
- package/dist/function-sugar.d.ts +57 -0
- package/dist/function-sugar.d.ts.map +1 -0
- package/dist/function-sugar.js +79 -0
- package/dist/function-sugar.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/dist/providers/analytics/mixpanel.d.ts.map +1 -1
- package/dist/providers/analytics/mixpanel.js +21 -18
- package/dist/providers/analytics/mixpanel.js.map +1 -1
- package/dist/providers/calendar/cal-com.d.ts.map +1 -1
- package/dist/providers/calendar/cal-com.js +10 -10
- package/dist/providers/calendar/cal-com.js.map +1 -1
- package/dist/providers/calendar/google-calendar.d.ts.map +1 -1
- package/dist/providers/calendar/google-calendar.js +4 -4
- package/dist/providers/calendar/google-calendar.js.map +1 -1
- package/dist/providers/crm/hubspot.d.ts.map +1 -1
- package/dist/providers/crm/hubspot.js +107 -85
- package/dist/providers/crm/hubspot.js.map +1 -1
- package/dist/providers/development/github.d.ts.map +1 -1
- package/dist/providers/development/github.js +40 -43
- package/dist/providers/development/github.js.map +1 -1
- package/dist/providers/ecommerce/shopify.d.ts.map +1 -1
- package/dist/providers/ecommerce/shopify.js +79 -62
- package/dist/providers/ecommerce/shopify.js.map +1 -1
- package/dist/providers/email/resend.d.ts.map +1 -1
- package/dist/providers/email/resend.js +20 -16
- package/dist/providers/email/resend.js.map +1 -1
- package/dist/providers/email/sendgrid.d.ts.map +1 -1
- package/dist/providers/email/sendgrid.js +12 -9
- package/dist/providers/email/sendgrid.js.map +1 -1
- package/dist/providers/finance/stripe.d.ts.map +1 -1
- package/dist/providers/finance/stripe.js +44 -42
- package/dist/providers/finance/stripe.js.map +1 -1
- package/dist/providers/forms/typeform.d.ts.map +1 -1
- package/dist/providers/forms/typeform.js +68 -58
- package/dist/providers/forms/typeform.js.map +1 -1
- package/dist/providers/knowledge/notion.d.ts.map +1 -1
- package/dist/providers/knowledge/notion.js +75 -41
- package/dist/providers/knowledge/notion.js.map +1 -1
- package/dist/providers/marketing/mailchimp.d.ts.map +1 -1
- package/dist/providers/marketing/mailchimp.js +74 -61
- package/dist/providers/marketing/mailchimp.js.map +1 -1
- package/dist/providers/media/cloudinary.d.ts.map +1 -1
- package/dist/providers/media/cloudinary.js +30 -28
- package/dist/providers/media/cloudinary.js.map +1 -1
- package/dist/providers/messaging/slack.d.ts.map +1 -1
- package/dist/providers/messaging/slack.js +75 -58
- package/dist/providers/messaging/slack.js.map +1 -1
- package/dist/providers/messaging/twilio-sms.d.ts.map +1 -1
- package/dist/providers/messaging/twilio-sms.js +33 -15
- package/dist/providers/messaging/twilio-sms.js.map +1 -1
- package/dist/providers/project-management/linear.d.ts.map +1 -1
- package/dist/providers/project-management/linear.js +31 -27
- package/dist/providers/project-management/linear.js.map +1 -1
- package/dist/providers/spreadsheet/google-sheets.d.ts.map +1 -1
- package/dist/providers/spreadsheet/google-sheets.js +21 -18
- package/dist/providers/spreadsheet/google-sheets.js.map +1 -1
- package/dist/providers/spreadsheet/xlsx.d.ts.map +1 -1
- package/dist/providers/spreadsheet/xlsx.js +4 -4
- package/dist/providers/spreadsheet/xlsx.js.map +1 -1
- package/dist/providers/storage/index.js +1 -0
- package/dist/providers/storage/index.js.map +1 -1
- package/dist/providers/storage/s3.d.ts.map +1 -1
- package/dist/providers/storage/s3.js +36 -27
- package/dist/providers/storage/s3.js.map +1 -1
- package/dist/providers/support/zendesk.d.ts.map +1 -1
- package/dist/providers/support/zendesk.js +24 -25
- package/dist/providers/support/zendesk.js.map +1 -1
- package/dist/providers/tasks/todoist.d.ts.map +1 -1
- package/dist/providers/tasks/todoist.js +18 -18
- package/dist/providers/tasks/todoist.js.map +1 -1
- package/dist/providers/video-conferencing/google-meet.d.ts.map +1 -1
- package/dist/providers/video-conferencing/google-meet.js +11 -11
- package/dist/providers/video-conferencing/google-meet.js.map +1 -1
- package/dist/providers/video-conferencing/jitsi.js +14 -14
- package/dist/providers/video-conferencing/jitsi.js.map +1 -1
- package/dist/providers/video-conferencing/teams.d.ts.map +1 -1
- package/dist/providers/video-conferencing/teams.js +9 -7
- package/dist/providers/video-conferencing/teams.js.map +1 -1
- package/dist/providers/video-conferencing/zoom.d.ts.map +1 -1
- package/dist/providers/video-conferencing/zoom.js +26 -24
- package/dist/providers/video-conferencing/zoom.js.map +1 -1
- package/dist/tools/data.d.ts.map +1 -1
- package/dist/tools/data.js +5 -12
- package/dist/tools/data.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/system.d.ts +289 -0
- package/dist/tools/system.d.ts.map +1 -0
- package/dist/tools/system.js +752 -0
- package/dist/tools/system.js.map +1 -0
- package/dist/tools/web.d.ts.map +1 -1
- package/dist/tools/web.js +22 -10
- package/dist/tools/web.js.map +1 -1
- package/dist/track-record.d.ts +101 -0
- package/dist/track-record.d.ts.map +1 -0
- package/dist/track-record.js +17 -0
- package/dist/track-record.js.map +1 -0
- package/dist/types.d.ts +210 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/verb-registration.d.ts +122 -0
- package/dist/verb-registration.d.ts.map +1 -0
- package/dist/verb-registration.js +176 -0
- package/dist/verb-registration.js.map +1 -0
- package/dist/worker.d.ts +93 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +315 -0
- package/dist/worker.js.map +1 -0
- package/dist/wrap.d.ts +89 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +225 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +31 -14
- package/src/client.ts +136 -0
- package/src/define.ts +30 -24
- package/src/function-ref.ts +264 -0
- package/src/function-sugar.ts +134 -0
- package/src/index.ts +132 -10
- package/src/providers/analytics/mixpanel.ts +19 -18
- package/src/providers/calendar/cal-com.ts +29 -18
- package/src/providers/calendar/google-calendar.ts +20 -14
- package/src/providers/crm/hubspot.ts +225 -99
- package/src/providers/development/github.ts +206 -135
- package/src/providers/ecommerce/shopify.ts +250 -89
- package/src/providers/email/resend.ts +101 -28
- package/src/providers/email/sendgrid.ts +12 -9
- package/src/providers/finance/stripe.ts +128 -49
- package/src/providers/forms/typeform.ts +74 -58
- package/src/providers/knowledge/notion.ts +340 -88
- package/src/providers/marketing/mailchimp.ts +86 -70
- package/src/providers/media/cloudinary.ts +99 -41
- package/src/providers/messaging/slack.ts +283 -85
- package/src/providers/messaging/twilio-sms.ts +35 -15
- package/src/providers/project-management/linear.ts +143 -55
- package/src/providers/spreadsheet/google-sheets.ts +222 -56
- package/src/providers/spreadsheet/xlsx.ts +47 -16
- package/src/providers/storage/s3.ts +119 -47
- package/src/providers/support/zendesk.ts +196 -46
- package/src/providers/tasks/todoist.ts +20 -26
- package/src/providers/video-conferencing/google-meet.ts +17 -20
- package/src/providers/video-conferencing/jitsi.ts +14 -14
- package/src/providers/video-conferencing/teams.ts +14 -13
- package/src/providers/video-conferencing/zoom.ts +54 -49
- package/src/tools/data.ts +6 -16
- package/src/tools/index.ts +1 -0
- package/src/tools/system.ts +887 -0
- package/src/tools/web.ts +22 -10
- package/src/track-record.ts +106 -0
- package/src/types.ts +241 -13
- package/src/verb-registration.ts +197 -0
- package/src/worker.ts +370 -0
- package/src/wrap.ts +260 -0
- package/test/client.test.ts +146 -0
- package/test/communication-tools-extended.test.ts +734 -0
- package/test/data-tools-extended.test.ts +743 -0
- package/test/define-extended.test.ts +819 -0
- package/test/define.test.ts +150 -41
- package/test/entities.test.ts +623 -0
- package/test/extended-entities.test.ts +1228 -0
- package/test/provider-implementations.test.ts +725 -0
- package/test/provider-registry-extended.test.ts +583 -0
- package/test/providers/google-sheets.test.ts +851 -0
- package/test/providers/helpers.ts +554 -0
- package/test/providers/hubspot.test.ts +576 -0
- package/test/providers/slack.test.ts +932 -0
- package/test/providers/stripe.test.ts +701 -0
- package/test/providers.test.ts +578 -0
- package/test/system-tools-extended.test.ts +632 -0
- package/test/system.test.ts +673 -0
- package/test/tools.test.ts +15 -11
- package/test/types.test.ts +402 -0
- package/test/verb-registration.test.ts +395 -0
- package/test/web-tools.test.ts +553 -0
- package/test/worker-extended.test.ts +699 -0
- package/test/worker.test.ts +576 -0
- package/test/wrap.test.ts +366 -0
- package/tsconfig.json +3 -13
- package/vitest.config.ts +37 -0
- package/wrangler.jsonc +9 -0
- package/LICENSE +0 -21
- package/dist/providers/voice/vapi.d.ts +0 -27
- package/dist/providers/voice/vapi.d.ts.map +0 -1
- package/dist/providers/voice/vapi.js +0 -440
- package/dist/providers/voice/vapi.js.map +0 -1
- package/src/define.js +0 -259
- package/src/entities/advertising.js +0 -999
- package/src/entities/ai.js +0 -756
- package/src/entities/analytics.js +0 -1588
- package/src/entities/automation.js +0 -601
- package/src/entities/communication.js +0 -1150
- package/src/entities/crm.js +0 -1386
- package/src/entities/design.js +0 -546
- package/src/entities/development.js +0 -2212
- package/src/entities/document.js +0 -874
- package/src/entities/ecommerce.js +0 -1429
- package/src/entities/experiment.js +0 -1039
- package/src/entities/finance.js +0 -3478
- package/src/entities/forms.js +0 -1892
- package/src/entities/hr.js +0 -661
- package/src/entities/identity.js +0 -997
- package/src/entities/index.js +0 -282
- package/src/entities/infrastructure.js +0 -1153
- package/src/entities/knowledge.js +0 -1438
- package/src/entities/marketing.js +0 -1610
- package/src/entities/media.js +0 -1634
- package/src/entities/notification.js +0 -1199
- package/src/entities/presentation.js +0 -1274
- package/src/entities/productivity.js +0 -1317
- package/src/entities/project-management.js +0 -1136
- package/src/entities/recruiting.js +0 -736
- package/src/entities/shipping.js +0 -509
- package/src/entities/signature.js +0 -1102
- package/src/entities/site.js +0 -222
- package/src/entities/spreadsheet.js +0 -1341
- package/src/entities/storage.js +0 -1198
- package/src/entities/support.js +0 -1166
- package/src/entities/video-conferencing.js +0 -1750
- package/src/entities/video.js +0 -950
- package/src/entities.js +0 -1663
- package/src/index.js +0 -74
- package/src/providers/analytics/index.js +0 -17
- package/src/providers/analytics/mixpanel.js +0 -255
- package/src/providers/calendar/cal-com.js +0 -303
- package/src/providers/calendar/google-calendar.js +0 -335
- package/src/providers/calendar/index.js +0 -20
- package/src/providers/crm/hubspot.js +0 -566
- package/src/providers/crm/index.js +0 -17
- package/src/providers/development/github.js +0 -472
- package/src/providers/development/index.js +0 -17
- package/src/providers/ecommerce/index.js +0 -17
- package/src/providers/ecommerce/shopify.js +0 -378
- package/src/providers/email/index.js +0 -20
- package/src/providers/email/resend.js +0 -258
- package/src/providers/email/sendgrid.js +0 -161
- package/src/providers/finance/index.js +0 -17
- package/src/providers/finance/stripe.js +0 -549
- package/src/providers/forms/index.js +0 -17
- package/src/providers/forms/typeform.js +0 -500
- package/src/providers/index.js +0 -123
- package/src/providers/knowledge/index.js +0 -17
- package/src/providers/knowledge/notion.js +0 -389
- package/src/providers/marketing/index.js +0 -17
- package/src/providers/marketing/mailchimp.js +0 -443
- package/src/providers/media/cloudinary.js +0 -318
- package/src/providers/media/index.js +0 -17
- package/src/providers/messaging/index.js +0 -20
- package/src/providers/messaging/slack.js +0 -393
- package/src/providers/messaging/twilio-sms.js +0 -249
- package/src/providers/project-management/index.js +0 -17
- package/src/providers/project-management/linear.js +0 -575
- package/src/providers/registry.js +0 -86
- package/src/providers/spreadsheet/google-sheets.js +0 -375
- package/src/providers/spreadsheet/index.js +0 -20
- package/src/providers/spreadsheet/xlsx.js +0 -423
- package/src/providers/storage/index.js +0 -24
- package/src/providers/storage/s3.js +0 -419
- package/src/providers/support/index.js +0 -17
- package/src/providers/support/zendesk.js +0 -373
- package/src/providers/tasks/index.js +0 -17
- package/src/providers/tasks/todoist.js +0 -286
- package/src/providers/types.js +0 -9
- package/src/providers/video-conferencing/google-meet.js +0 -286
- package/src/providers/video-conferencing/index.js +0 -31
- package/src/providers/video-conferencing/jitsi.js +0 -254
- package/src/providers/video-conferencing/teams.js +0 -270
- package/src/providers/video-conferencing/zoom.js +0 -332
- package/src/registry.js +0 -128
- package/src/tools/communication.js +0 -184
- package/src/tools/data.js +0 -205
- package/src/tools/index.js +0 -11
- package/src/tools/web.js +0 -137
- package/src/types.js +0 -10
- package/test/define.test.js +0 -306
- package/test/registry.test.js +0 -357
- package/test/tools.test.js +0 -363
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `wrapTool()` — broker-aware HTTP wrapping for Tools.
|
|
3
|
+
*
|
|
4
|
+
* We use structural fakes for `AuthBroker` and `PaymentBroker` rather
|
|
5
|
+
* than `AuthBrokerImpl` / `PaymentBrokerImpl` so the suite stays
|
|
6
|
+
* portable and doesn't pull DO/HTTP plumbing into the worker bundle.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from 'vitest'
|
|
10
|
+
import type {
|
|
11
|
+
AuthBroker,
|
|
12
|
+
AuthDecision,
|
|
13
|
+
Identity,
|
|
14
|
+
PaymentBroker,
|
|
15
|
+
PaymentInstrument,
|
|
16
|
+
PaymentOutcome,
|
|
17
|
+
PaymentReceipt,
|
|
18
|
+
PaymentSession,
|
|
19
|
+
SessionRequired,
|
|
20
|
+
} from 'id.org.ai'
|
|
21
|
+
import { defineTool, wrapTool, type Tool } from '../src/index.js'
|
|
22
|
+
import { __toIdAuthRequirement, __toIdPaymentRequired } from '../src/wrap.js'
|
|
23
|
+
|
|
24
|
+
// ---------- Test helpers --------------------------------------------------
|
|
25
|
+
|
|
26
|
+
/** Minimal Identity for fakes — fills the L0/L1 anonymous shape. */
|
|
27
|
+
const fakeIdentity = (over: Partial<Identity> = {}): Identity => ({
|
|
28
|
+
id: 'agent:alice',
|
|
29
|
+
type: 'agent',
|
|
30
|
+
name: 'Alice',
|
|
31
|
+
verified: true,
|
|
32
|
+
level: 1,
|
|
33
|
+
claimStatus: 'claimed',
|
|
34
|
+
scopes: ['email:send'],
|
|
35
|
+
...over,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/** Builds an AuthBroker that always grants. */
|
|
39
|
+
function fakeAuthBrokerOk(identity = fakeIdentity()): AuthBroker {
|
|
40
|
+
return {
|
|
41
|
+
async gate(): Promise<AuthDecision> {
|
|
42
|
+
return { ok: true, identity }
|
|
43
|
+
},
|
|
44
|
+
async identify() {
|
|
45
|
+
return identity
|
|
46
|
+
},
|
|
47
|
+
check(id): AuthDecision {
|
|
48
|
+
return { ok: true, identity: id }
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Builds an AuthBroker that always denies. */
|
|
54
|
+
function fakeAuthBrokerDeny(): AuthBroker {
|
|
55
|
+
return {
|
|
56
|
+
async gate(): Promise<AuthDecision> {
|
|
57
|
+
// Pre-baked denial response — wrapTool returns it directly.
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
identity: null,
|
|
61
|
+
reason: 'unauthenticated',
|
|
62
|
+
response: new Response(
|
|
63
|
+
JSON.stringify({
|
|
64
|
+
error: 'unauthenticated',
|
|
65
|
+
error_description: 'No credential presented',
|
|
66
|
+
reason: 'unauthenticated',
|
|
67
|
+
}),
|
|
68
|
+
{
|
|
69
|
+
status: 401,
|
|
70
|
+
headers: { 'content-type': 'application/json' },
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async identify() {
|
|
76
|
+
return fakeIdentity({ level: 0, verified: false })
|
|
77
|
+
},
|
|
78
|
+
check(): AuthDecision {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
identity: null,
|
|
82
|
+
reason: 'unauthenticated',
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Builds a PaymentBroker that always settles successfully. */
|
|
89
|
+
function fakePaymentBrokerOk(): PaymentBroker {
|
|
90
|
+
const receipt: PaymentReceipt = {
|
|
91
|
+
ok: true,
|
|
92
|
+
rail: { protocol: 'x402', method: 'exact', asset: 'USDC' },
|
|
93
|
+
amount: '0.01',
|
|
94
|
+
asset: 'USDC',
|
|
95
|
+
txRef: '0xdeadbeef',
|
|
96
|
+
settledAt: 1700000000,
|
|
97
|
+
responseHeader: ['PAYMENT-RESPONSE', 'eyJzdGF0dXMiOiJzZXR0bGVkIn0='],
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
async settle(): Promise<PaymentOutcome> {
|
|
101
|
+
return receipt
|
|
102
|
+
},
|
|
103
|
+
async session(_id, _req: SessionRequired): Promise<PaymentSession> {
|
|
104
|
+
throw new Error('not used in these tests')
|
|
105
|
+
},
|
|
106
|
+
async instrumentsFor(): Promise<PaymentInstrument[]> {
|
|
107
|
+
return []
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Builds a PaymentBroker that always rejects. */
|
|
113
|
+
function fakePaymentBrokerDeny(): PaymentBroker {
|
|
114
|
+
return {
|
|
115
|
+
async settle(): Promise<PaymentOutcome> {
|
|
116
|
+
return {
|
|
117
|
+
ok: false,
|
|
118
|
+
reason: 'no-payment',
|
|
119
|
+
response: new Response(JSON.stringify({ error: 'payment_required' }), {
|
|
120
|
+
status: 402,
|
|
121
|
+
headers: {
|
|
122
|
+
'content-type': 'application/json',
|
|
123
|
+
'WWW-Authenticate': 'Payment realm="test"',
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
async session(_id, _req: SessionRequired): Promise<PaymentSession> {
|
|
129
|
+
throw new Error('not used in these tests')
|
|
130
|
+
},
|
|
131
|
+
async instrumentsFor(): Promise<PaymentInstrument[]> {
|
|
132
|
+
return []
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ---------- Tests --------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
describe('wrapTool', () => {
|
|
140
|
+
it('passes through tools without auth or pricing', async () => {
|
|
141
|
+
const tool = defineTool({
|
|
142
|
+
id: 'svo.passthrough',
|
|
143
|
+
name: 'Passthrough',
|
|
144
|
+
description: 'No auth, no pricing',
|
|
145
|
+
category: 'data',
|
|
146
|
+
input: { type: 'object', properties: { x: { type: 'number' } } },
|
|
147
|
+
handler: async (input: { x: number }) => ({ doubled: input.x * 2 }),
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const handler = wrapTool(undefined, undefined, tool)
|
|
151
|
+
const req = new Request('https://example.com/tool', {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
headers: { 'content-type': 'application/json' },
|
|
154
|
+
body: JSON.stringify({ x: 21 }),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const res = await handler(req)
|
|
158
|
+
expect(res.status).toBe(200)
|
|
159
|
+
const body = (await res.json()) as { doubled: number }
|
|
160
|
+
expect(body).toEqual({ doubled: 42 })
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('calls AuthBroker.gate() and threads Identity into ctx on success', async () => {
|
|
164
|
+
const tool = defineTool({
|
|
165
|
+
id: 'svo.auth.ok',
|
|
166
|
+
name: 'Auth OK',
|
|
167
|
+
description: 'Tool with auth that succeeds',
|
|
168
|
+
category: 'communication',
|
|
169
|
+
auth: { scopes: ['email:send'], required: 'oauth' },
|
|
170
|
+
input: { type: 'object', properties: {} },
|
|
171
|
+
handler: async (_input, ctx) => {
|
|
172
|
+
// Identity should be the full Identity record from the broker
|
|
173
|
+
const id = ctx?.identity
|
|
174
|
+
if (typeof id === 'string') {
|
|
175
|
+
throw new Error('expected Identity object, got string')
|
|
176
|
+
}
|
|
177
|
+
return { caller: id?.id, verified: id?.verified }
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const handler = wrapTool(fakeAuthBrokerOk(), undefined, tool)
|
|
182
|
+
const req = new Request('https://example.com/tool', { method: 'POST' })
|
|
183
|
+
const res = await handler(req)
|
|
184
|
+
expect(res.status).toBe(200)
|
|
185
|
+
const body = (await res.json()) as { caller: string; verified: boolean }
|
|
186
|
+
expect(body).toEqual({ caller: 'agent:alice', verified: true })
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('returns the broker denial response when auth fails', async () => {
|
|
190
|
+
const tool = defineTool({
|
|
191
|
+
id: 'svo.auth.deny',
|
|
192
|
+
name: 'Auth Deny',
|
|
193
|
+
description: 'Tool with auth that fails',
|
|
194
|
+
category: 'communication',
|
|
195
|
+
auth: { scopes: ['email:send'], required: 'oauth' },
|
|
196
|
+
input: { type: 'object', properties: {} },
|
|
197
|
+
handler: async () => {
|
|
198
|
+
throw new Error('handler should not be called')
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
const handler = wrapTool(fakeAuthBrokerDeny(), undefined, tool)
|
|
203
|
+
const req = new Request('https://example.com/tool', { method: 'POST' })
|
|
204
|
+
const res = await handler(req)
|
|
205
|
+
expect(res.status).toBe(401)
|
|
206
|
+
const body = (await res.json()) as { error: string; reason: string }
|
|
207
|
+
expect(body.reason).toBe('unauthenticated')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('returns 500 when auth is declared but no broker is provided', async () => {
|
|
211
|
+
const tool = defineTool({
|
|
212
|
+
id: 'svo.auth.misconfig',
|
|
213
|
+
name: 'Auth Misconfigured',
|
|
214
|
+
description: 'Auth declared without broker',
|
|
215
|
+
category: 'data',
|
|
216
|
+
auth: { scopes: ['x'], required: 'oauth' },
|
|
217
|
+
input: { type: 'object', properties: {} },
|
|
218
|
+
handler: async () => ({}),
|
|
219
|
+
})
|
|
220
|
+
const handler = wrapTool(undefined, undefined, tool)
|
|
221
|
+
const res = await handler(new Request('https://example.com/x', { method: 'POST' }))
|
|
222
|
+
expect(res.status).toBe(500)
|
|
223
|
+
const body = (await res.json()) as { error: string }
|
|
224
|
+
expect(body.error).toBe('configuration_error')
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it('calls PaymentBroker.settle() and threads PaymentReceipt into ctx + response header', async () => {
|
|
228
|
+
const tool = defineTool({
|
|
229
|
+
id: 'svo.pay.ok',
|
|
230
|
+
name: 'Paid Tool',
|
|
231
|
+
description: 'Tool with pricing that succeeds',
|
|
232
|
+
category: 'data',
|
|
233
|
+
auth: { scopes: [], required: 'apiKey' },
|
|
234
|
+
pricing: {
|
|
235
|
+
$type: 'PaymentRequired',
|
|
236
|
+
amount: '0.01',
|
|
237
|
+
currency: 'USDC',
|
|
238
|
+
accepts: ['x402'],
|
|
239
|
+
recipient: '0xfeed',
|
|
240
|
+
},
|
|
241
|
+
input: { type: 'object', properties: {} },
|
|
242
|
+
handler: async (_input, ctx) => {
|
|
243
|
+
const receipt = ctx?.paymentReceipt
|
|
244
|
+
return { settled: receipt?.ok, txRef: receipt?.txRef }
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
const handler = wrapTool(fakeAuthBrokerOk(), fakePaymentBrokerOk(), tool)
|
|
249
|
+
const res = await handler(new Request('https://example.com/x', { method: 'POST' }))
|
|
250
|
+
expect(res.status).toBe(200)
|
|
251
|
+
// The receipt's responseHeader should be stamped onto the response.
|
|
252
|
+
expect(res.headers.get('PAYMENT-RESPONSE')).toBe('eyJzdGF0dXMiOiJzZXR0bGVkIn0=')
|
|
253
|
+
const body = (await res.json()) as { settled: boolean; txRef: string }
|
|
254
|
+
expect(body).toEqual({ settled: true, txRef: '0xdeadbeef' })
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('returns the broker 402 response when payment fails', async () => {
|
|
258
|
+
const tool = defineTool({
|
|
259
|
+
id: 'svo.pay.deny',
|
|
260
|
+
name: 'Paid Tool',
|
|
261
|
+
description: 'Tool with pricing that fails',
|
|
262
|
+
category: 'data',
|
|
263
|
+
auth: { scopes: [], required: 'apiKey' },
|
|
264
|
+
pricing: {
|
|
265
|
+
$type: 'PaymentRequired',
|
|
266
|
+
amount: '0.01',
|
|
267
|
+
currency: 'USDC',
|
|
268
|
+
accepts: ['x402', 'mpp'],
|
|
269
|
+
recipient: '0xfeed',
|
|
270
|
+
},
|
|
271
|
+
input: { type: 'object', properties: {} },
|
|
272
|
+
handler: async () => {
|
|
273
|
+
throw new Error('handler should not be called')
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
const handler = wrapTool(fakeAuthBrokerOk(), fakePaymentBrokerDeny(), tool)
|
|
278
|
+
const res = await handler(new Request('https://example.com/x', { method: 'POST' }))
|
|
279
|
+
expect(res.status).toBe(402)
|
|
280
|
+
expect(res.headers.get('WWW-Authenticate')).toContain('Payment')
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
it('returns 500 when pricing is declared but no PaymentBroker is provided', async () => {
|
|
284
|
+
const tool = defineTool({
|
|
285
|
+
id: 'svo.pay.misconfig',
|
|
286
|
+
name: 'Paid Misconfigured',
|
|
287
|
+
description: 'Pricing declared without broker',
|
|
288
|
+
category: 'data',
|
|
289
|
+
pricing: {
|
|
290
|
+
$type: 'PaymentRequired',
|
|
291
|
+
amount: '0.01',
|
|
292
|
+
currency: 'USDC',
|
|
293
|
+
accepts: ['x402'],
|
|
294
|
+
recipient: '0xfeed',
|
|
295
|
+
},
|
|
296
|
+
input: { type: 'object', properties: {} },
|
|
297
|
+
handler: async () => ({}),
|
|
298
|
+
})
|
|
299
|
+
// Only auth broker provided (none required for this tool — no `auth`),
|
|
300
|
+
// but the payment broker is missing.
|
|
301
|
+
const handler = wrapTool(undefined, undefined, tool)
|
|
302
|
+
const res = await handler(new Request('https://example.com/x', { method: 'POST' }))
|
|
303
|
+
expect(res.status).toBe(500)
|
|
304
|
+
const body = (await res.json()) as { error: string }
|
|
305
|
+
expect(body.error).toBe('configuration_error')
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('throws at wrap-time when a tool tries to use session intent', () => {
|
|
309
|
+
// Local PaymentRequired doesn't model `intent: 'session'`, but we
|
|
310
|
+
// surface the limitation if a caller hands us a shape that does.
|
|
311
|
+
// Cast through `unknown` since the local type doesn't expose the
|
|
312
|
+
// discriminator yet.
|
|
313
|
+
const tool: Tool = {
|
|
314
|
+
id: 'svo.pay.session',
|
|
315
|
+
name: 'Session Tool',
|
|
316
|
+
description: 'Hypothetical session-intent pricing',
|
|
317
|
+
category: 'data',
|
|
318
|
+
parameters: [],
|
|
319
|
+
pricing: {
|
|
320
|
+
// Pretend a future widening allows this shape.
|
|
321
|
+
intent: 'session',
|
|
322
|
+
$type: 'PaymentRequired',
|
|
323
|
+
amount: '1.00',
|
|
324
|
+
currency: 'USDC',
|
|
325
|
+
accepts: ['mpp'],
|
|
326
|
+
recipient: '0xfeed',
|
|
327
|
+
} as unknown as Tool['pricing'],
|
|
328
|
+
handler: async () => ({}),
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
expect(() => wrapTool(undefined, fakePaymentBrokerOk(), tool)).toThrow(
|
|
332
|
+
/session.*not yet supported/i
|
|
333
|
+
)
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it('translates AuthRequirement: oauth -> minLevel 1 with scopes', () => {
|
|
337
|
+
const out = __toIdAuthRequirement({ scopes: ['email:send', 'admin'], required: 'oauth' })
|
|
338
|
+
expect(out).toEqual({ minLevel: 1, scopes: ['email:send', 'admin'] })
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it('translates AuthRequirement: none -> minLevel 0, no scopes when empty', () => {
|
|
342
|
+
const out = __toIdAuthRequirement({ scopes: [], required: 'none' })
|
|
343
|
+
expect(out).toEqual({ minLevel: 0 })
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('translates PaymentRequired: x402 + mpp -> charge intent with two RailQuotes', () => {
|
|
347
|
+
const out = __toIdPaymentRequired({
|
|
348
|
+
$type: 'PaymentRequired',
|
|
349
|
+
amount: '0.05',
|
|
350
|
+
currency: 'USDC',
|
|
351
|
+
accepts: ['x402', 'mpp'],
|
|
352
|
+
recipient: '0xfeed',
|
|
353
|
+
})
|
|
354
|
+
if (!('intent' in out) || out.intent !== 'charge') {
|
|
355
|
+
throw new Error('expected charge intent')
|
|
356
|
+
}
|
|
357
|
+
expect(out.accepts).toHaveLength(2)
|
|
358
|
+
expect(out.accepts[0].rail.protocol).toBe('x402')
|
|
359
|
+
expect(out.accepts[0].rail.method).toBe('exact')
|
|
360
|
+
expect(out.accepts[1].rail.protocol).toBe('mpp')
|
|
361
|
+
expect(out.accepts[1].rail.method).toBe('tempo')
|
|
362
|
+
// amount + payTo flow through unchanged.
|
|
363
|
+
expect(out.accepts[0].amount).toBe('0.05')
|
|
364
|
+
expect(out.accepts[0].payTo).toBe('0xfeed')
|
|
365
|
+
})
|
|
366
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"outDir": "dist",
|
|
8
4
|
"rootDir": "src",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"declarationMap": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"resolveJsonModule": true
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"types": ["@cloudflare/workers-types", "node"]
|
|
17
7
|
},
|
|
18
8
|
"include": ["src/**/*"],
|
|
19
9
|
"exclude": ["node_modules", "dist", "test"]
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
|
|
2
|
+
|
|
3
|
+
export default defineWorkersConfig({
|
|
4
|
+
test: {
|
|
5
|
+
// CRITICAL: Limit concurrency to prevent resource exhaustion
|
|
6
|
+
maxConcurrency: 1,
|
|
7
|
+
maxWorkers: 1,
|
|
8
|
+
minWorkers: 1,
|
|
9
|
+
fileParallelism: false,
|
|
10
|
+
|
|
11
|
+
poolOptions: {
|
|
12
|
+
workers: {
|
|
13
|
+
wrangler: { configPath: './wrangler.jsonc' },
|
|
14
|
+
miniflare: {
|
|
15
|
+
compatibilityDate: '2025-01-20',
|
|
16
|
+
compatibilityFlags: ['nodejs_compat_v2'],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
include: ['src/**/*.test.ts', 'test/**/*.test.ts'],
|
|
22
|
+
|
|
23
|
+
// Coverage configuration
|
|
24
|
+
coverage: {
|
|
25
|
+
provider: 'v8',
|
|
26
|
+
reporter: ['text', 'json', 'html'],
|
|
27
|
+
include: ['src/**/*.ts'],
|
|
28
|
+
exclude: ['**/*.test.ts', '**/__tests__/**', '**/node_modules/**'],
|
|
29
|
+
thresholds: {
|
|
30
|
+
statements: 65,
|
|
31
|
+
branches: 60,
|
|
32
|
+
functions: 60,
|
|
33
|
+
lines: 65,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
})
|
package/wrangler.jsonc
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
// digital-tools Worker configuration
|
|
3
|
+
// The default export (ToolService) extends WorkerEntrypoint
|
|
4
|
+
// All public methods are automatically exposed via RPC
|
|
5
|
+
"name": "digital-tools",
|
|
6
|
+
"main": "dist/worker.js",
|
|
7
|
+
"compatibility_date": "2025-01-20",
|
|
8
|
+
"compatibility_flags": ["nodejs_compat_v2"]
|
|
9
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 .org.ai
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vapi Voice AI Provider
|
|
3
|
-
*
|
|
4
|
-
* Concrete implementation of VoiceProvider using Vapi REST API.
|
|
5
|
-
* Supports voice AI for phone calls, web calls, and chat interactions.
|
|
6
|
-
*
|
|
7
|
-
* @see https://docs.vapi.ai/
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import type { VoiceProvider, ProviderConfig, ProviderInfo } from '../types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Vapi provider info
|
|
13
|
-
*/
|
|
14
|
-
export declare const vapiInfo: ProviderInfo;
|
|
15
|
-
/**
|
|
16
|
-
* Create Vapi voice provider
|
|
17
|
-
*/
|
|
18
|
-
export declare function createVapiProvider(config: ProviderConfig): VoiceProvider;
|
|
19
|
-
/**
|
|
20
|
-
* Vapi provider definition
|
|
21
|
-
*/
|
|
22
|
-
export declare const vapiProvider: {
|
|
23
|
-
info: ProviderInfo;
|
|
24
|
-
factory: import("../types.js").ProviderFactory<VoiceProvider>;
|
|
25
|
-
register: () => void;
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=vapi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vapi.d.ts","sourceRoot":"","sources":["../../../src/providers/voice/vapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAEd,YAAY,EASb,MAAM,aAAa,CAAA;AAKpB;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,YAStB,CAAA;AA8FD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,aAAa,CA4fxE;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;CAExB,CAAA"}
|