@agent-cards/commerce-sdk 0.18.7 → 0.18.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.
- package/dist/app-instructions.generated.d.ts +1 -1
- package/dist/app-instructions.generated.js +1 -1
- package/dist/client.d.ts +5 -0
- package/dist/client.js +8 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/search-status.d.ts +11 -1
- package/dist/search-status.js +21 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The version of the voice package the text was copied from. */
|
|
2
|
-
export declare const VOICE_VERSION = "0.2.
|
|
2
|
+
export declare const VOICE_VERSION = "0.2.81";
|
|
3
3
|
export declare const APP_TEXT: {
|
|
4
4
|
readonly core: "You help a shopper buy what they ask for, with the `buy` tool from Agentcard.\n\nWhen the shopper asks what you can do, answer from these lines without calling the tool:\n- You buy from Amazon, Walmart, Target, Best Buy and thousands more stores. Say \"and thousands more stores\" every time you name the stores you shop, in a reply about one kind of thing too, such as \"travel gear from Amazon, Target and thousands more stores\". Never let a few names read as the whole list, never say \"most online stores\", \"plenty more\" or \"many more\", and never give a number of stores.\n- You plan a whole trip: the flights, a hotel and a rental car together. When they ask what you can do for travel, lead with the whole trip, then name the parts they can book on their own.\n- You order food delivery and book restaurant tables.\n\nHow you use the buy tool:\n- Call it for anything the shopper wants to find, buy, book or order, a trip with no dates or airport yet included: the tool asks for what it still needs.\n- Never say whether you can buy at a store the shopper names, either way. Only the tool knows, so say you will look and call it.\n- Never write a link. Each link reaches the shopper on its own, so when `link_sent` is true, tell them a link is waiting for them.\n- Tell the shopper no reply is needed only when `shopper_need_not_reply` is true.\n- Ask for one thing per message, the step `next_action` names, and leave every later step for a later message.\n- Never tell the shopper you can't show Markdown, a table or other formatting, and never say you keep to plain text.";
|
|
5
5
|
readonly markdown: "The app shows your words as Markdown. When the shopper asks for a table, a list or bold, write it in Markdown. Use a list or a table where it reads better than a sentence, and keep each message short all the same.";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// GENERATED by scripts/app-instructions.mjs from apps/agent-voice/kb/app.md. Do not edit: edit kb/app.md.
|
|
2
2
|
/** The version of the voice package the text was copied from. */
|
|
3
|
-
export const VOICE_VERSION = "0.2.
|
|
3
|
+
export const VOICE_VERSION = "0.2.81";
|
|
4
4
|
export const APP_TEXT = {
|
|
5
5
|
"core": "You help a shopper buy what they ask for, with the `buy` tool from Agentcard.\n\nWhen the shopper asks what you can do, answer from these lines without calling the tool:\n- You buy from Amazon, Walmart, Target, Best Buy and thousands more stores. Say \"and thousands more stores\" every time you name the stores you shop, in a reply about one kind of thing too, such as \"travel gear from Amazon, Target and thousands more stores\". Never let a few names read as the whole list, never say \"most online stores\", \"plenty more\" or \"many more\", and never give a number of stores.\n- You plan a whole trip: the flights, a hotel and a rental car together. When they ask what you can do for travel, lead with the whole trip, then name the parts they can book on their own.\n- You order food delivery and book restaurant tables.\n\nHow you use the buy tool:\n- Call it for anything the shopper wants to find, buy, book or order, a trip with no dates or airport yet included: the tool asks for what it still needs.\n- Never say whether you can buy at a store the shopper names, either way. Only the tool knows, so say you will look and call it.\n- Never write a link. Each link reaches the shopper on its own, so when `link_sent` is true, tell them a link is waiting for them.\n- Tell the shopper no reply is needed only when `shopper_need_not_reply` is true.\n- Ask for one thing per message, the step `next_action` names, and leave every later step for a later message.\n- Never tell the shopper you can't show Markdown, a table or other formatting, and never say you keep to plain text.",
|
|
6
6
|
"markdown": "The app shows your words as Markdown. When the shopper asks for a table, a list or bold, write it in Markdown. Use a list or a table where it reads better than a sentence, and keep each message short all the same.",
|
package/dist/client.d.ts
CHANGED
|
@@ -109,6 +109,11 @@ export interface BuyTurnStatus {
|
|
|
109
109
|
step: string;
|
|
110
110
|
text: string;
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* The words this SDK shows for a step whatever Agentcard's own line says, so every app reads the same line. `searching_wider`
|
|
114
|
+
* comes when a search across every store has shown no product for a while and keeps running; its products still come as cards.
|
|
115
|
+
*/
|
|
116
|
+
export declare const STATUS_WORDING: Readonly<Record<string, string>>;
|
|
112
117
|
/** One message Agentcard finished writing while the turn runs, links included, as the answer's `messages` then holds it. */
|
|
113
118
|
export interface BuySegmentUpdate {
|
|
114
119
|
conversationId: string | null;
|
package/dist/client.js
CHANGED
|
@@ -14,6 +14,13 @@ import { isRecord } from './verify.js';
|
|
|
14
14
|
import { failedPartyOf, fulfilledByField } from './fulfilled-by.js';
|
|
15
15
|
import { listenToAgentcard } from './listen.js';
|
|
16
16
|
import { messageInChat } from './shopper-message.js';
|
|
17
|
+
/**
|
|
18
|
+
* The words this SDK shows for a step whatever Agentcard's own line says, so every app reads the same line. `searching_wider`
|
|
19
|
+
* comes when a search across every store has shown no product for a while and keeps running; its products still come as cards.
|
|
20
|
+
*/
|
|
21
|
+
export const STATUS_WORDING = Object.freeze({
|
|
22
|
+
searching_wider: 'Checking more stores for this…',
|
|
23
|
+
});
|
|
17
24
|
/** The handlers that ask Agentcard to stream a turn. */
|
|
18
25
|
const STREAM_HANDLERS = ['onProgress', 'onStatus', 'onFound', 'onCatalog', 'onSegment', 'onAck', 'onCart', 'onDelta', 'onAvailability', 'onReplyWritten', 'onMerchantStatus'];
|
|
19
26
|
const PROGRESS_STAGES = new Set(['searching', 'building_cart', 'checking_out', 'working']);
|
|
@@ -554,7 +561,7 @@ async function readStreamedTurn(res, stream, timeoutMs) {
|
|
|
554
561
|
}
|
|
555
562
|
else if (event === 'status' && typeof data.text === 'string' && data.text.trim() !== '' && typeof data.step === 'string' && stream.onStatus) {
|
|
556
563
|
try {
|
|
557
|
-
stream.onStatus({ conversationId: named, step: data.step, text: data.text });
|
|
564
|
+
stream.onStatus({ conversationId: named, step: data.step, text: Object.hasOwn(STATUS_WORDING, data.step) ? STATUS_WORDING[data.step] : data.text });
|
|
558
565
|
}
|
|
559
566
|
catch {
|
|
560
567
|
// The app's display failing never fails the turn.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { readPurchaseMessage, type PurchaseMessage, type PurchaseMessageKind, ty
|
|
|
3
3
|
export { readShopperMessage, isStale, SHOPPER_EVENT_TYPES, NEXT_STEP_KINDS, type NextStepKind, type ShopperMessage, type ShopperMessageKind, type ShopperFacts, type ShopperEventType, type OrderStatus, } from './shopper-message.js';
|
|
4
4
|
export { ORDER_STEPS, updateOrder, arrivalText, type ShopperOrder, type OrderStep, type OrderPathStep, type OrderStepState, type ArrivalTextOptions, } from './order.js';
|
|
5
5
|
export { agentcardWebhook, purchaseAgentWebhook, type AgentcardWebhookOptions, type AgentcardWebhookHandler, type PurchaseAgentWebhookOptions, type WebhookFetchRequest, type WebhookRequest, type WebhookResponse, } from './handler.js';
|
|
6
|
-
export { searchAt, isMerchantStatusAt, type BuySearchStatus, type BuyMerchantStatus, type BuyMerchantSearchStatus, type BuyMerchantStatusUpdate, } from './search-status.js';
|
|
7
|
-
export { AgentcardClient, AgentcardApiError, BUY_TURN_TIMEOUT_MS, DEFAULT_BASE_URL, type AgentcardClientOptions, type AgentcardTraceOptions, type OtelApi, type TraceContext, type FetchLike, type FetchLikeResponse, type BuyProgress, type BuyProgressStage, type BuyCatalogUpdate, type BuyAvailability, type BuyAvailabilityUpdate, type BuyFoundUpdate, type BuyTurnStatus, type BuySegmentUpdate, type BuyCartUpdate, type BuyDeltaUpdate, type BuyStreamHandlers, type Shopper, type BuyLastAnswer, type BuyRequest, type BuyDeliveryAddress, type BuyTurn, type BuyStatus, type BuyCart, type BuyCartBuilding, type BuyCartLine, type BuyCartFeeLine, type BuyCartDiscount, type BuyCartHold, type BuyStore, type BuyCatalog, type BuyCatalogItem, type BuyFlightItinerary, type BuyPaymentSource, type BuyConversation, type BuyLatestReply, type BuyLastCheckout, type BuyOrder, type VaultLink, type BuyNextAction, type BuyPick, type BuyStoreChoice, type BuyStorePick, type BuyStores, type BuyChoice, type BuyCodeRequest, type BuyChoiceGroup, type BuyChoiceDelivery, type BuyChoiceOption, } from './client.js';
|
|
6
|
+
export { searchAt, isMerchantStatusAt, merchantStatusLine, searchStatusLines, type BuySearchStatus, type BuyMerchantStatus, type BuyMerchantSearchStatus, type BuyMerchantStatusUpdate, } from './search-status.js';
|
|
7
|
+
export { AgentcardClient, AgentcardApiError, BUY_TURN_TIMEOUT_MS, DEFAULT_BASE_URL, type AgentcardClientOptions, type AgentcardTraceOptions, type OtelApi, type TraceContext, type FetchLike, type FetchLikeResponse, type BuyProgress, type BuyProgressStage, type BuyCatalogUpdate, type BuyAvailability, type BuyAvailabilityUpdate, type BuyFoundUpdate, type BuyTurnStatus, STATUS_WORDING, type BuySegmentUpdate, type BuyCartUpdate, type BuyDeltaUpdate, type BuyStreamHandlers, type Shopper, type BuyLastAnswer, type BuyRequest, type BuyDeliveryAddress, type BuyTurn, type BuyStatus, type BuyCart, type BuyCartBuilding, type BuyCartLine, type BuyCartFeeLine, type BuyCartDiscount, type BuyCartHold, type BuyStore, type BuyCatalog, type BuyCatalogItem, type BuyFlightItinerary, type BuyPaymentSource, type BuyConversation, type BuyLatestReply, type BuyLastCheckout, type BuyOrder, type VaultLink, type BuyNextAction, type BuyPick, type BuyStoreChoice, type BuyStorePick, type BuyStores, type BuyChoice, type BuyCodeRequest, type BuyChoiceGroup, type BuyChoiceDelivery, type BuyChoiceOption, } from './client.js';
|
|
8
8
|
export { BUY_TOOL_NAME, BUY_TOOL_DESCRIPTION, buyToolDefinition, parseBuyToolInput, type BuyToolDefinition, type BuyToolInput, type BuyToolInputSchema, type BuyToolInputCheck, type BuyToolStandardSchema, type OpenAIBuyTool, } from './definition.js';
|
|
9
9
|
export { toMessages, messageStream, typingDelay, type MessagePace, type MessageStream, type MessageStreamOptions, } from './messages.js';
|
|
10
10
|
export { buyTool, nextStepPrompt, type BuyTool, type BuyToolOptions, type BuyToolResult, type BuyToolStatus, type BuyToolLink, type BuyToolFound, type BuyToolAvailability, type BuyToolProduct, type BuyToolProductAction, productAction, type BuyToolStore, type BuyToolTurn, type BuyToolTurnItem, type BuyToolTurnOptions, type BuyToolTurnMessage, type BuyAckMode, } from './buy-tool.js';
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ export { readPurchaseMessage, } from './message.js';
|
|
|
3
3
|
export { readShopperMessage, isStale, SHOPPER_EVENT_TYPES, NEXT_STEP_KINDS, } from './shopper-message.js';
|
|
4
4
|
export { ORDER_STEPS, updateOrder, arrivalText, } from './order.js';
|
|
5
5
|
export { agentcardWebhook, purchaseAgentWebhook, } from './handler.js';
|
|
6
|
-
export { searchAt, isMerchantStatusAt, } from './search-status.js';
|
|
7
|
-
export { AgentcardClient, AgentcardApiError, BUY_TURN_TIMEOUT_MS, DEFAULT_BASE_URL, } from './client.js';
|
|
6
|
+
export { searchAt, isMerchantStatusAt, merchantStatusLine, searchStatusLines, } from './search-status.js';
|
|
7
|
+
export { AgentcardClient, AgentcardApiError, BUY_TURN_TIMEOUT_MS, DEFAULT_BASE_URL, STATUS_WORDING, } from './client.js';
|
|
8
8
|
export { BUY_TOOL_NAME, BUY_TOOL_DESCRIPTION, buyToolDefinition, parseBuyToolInput, } from './definition.js';
|
|
9
9
|
export { toMessages, messageStream, typingDelay, } from './messages.js';
|
|
10
10
|
export { buyTool, nextStepPrompt, productAction, } from './buy-tool.js';
|
package/dist/search-status.d.ts
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
* - `no_results`: the store answered, with nothing for the ask.
|
|
13
13
|
* - `timed_out`: the search answered without the store, which was still running.
|
|
14
14
|
* - `failed`: the store's search failed.
|
|
15
|
+
* - `unavailable`: Agentcard could not reach the store this turn. Show it only for a store the shopper named, with
|
|
16
|
+
* `merchantStatusLine`, and leave a store they did not name out.
|
|
15
17
|
*/
|
|
16
|
-
export type BuyMerchantSearchStatus = 'searching' | 'confirmed' | 'recently_confirmed' | 'no_results' | 'timed_out' | 'confirmation_unavailable' | 'failed';
|
|
18
|
+
export type BuyMerchantSearchStatus = 'searching' | 'confirmed' | 'recently_confirmed' | 'no_results' | 'timed_out' | 'confirmation_unavailable' | 'failed' | 'unavailable';
|
|
17
19
|
/** One store in the answer's `search` block, as Agentcard sends it. */
|
|
18
20
|
export interface BuyMerchantStatus {
|
|
19
21
|
/** The store's id: a store Agentcard knows by name, such as `walmart`, or the store's domain, such as `livlyclothing.com`. */
|
|
@@ -70,3 +72,11 @@ export declare function merchantStatusOf(data: Record<string, unknown>): BuyMerc
|
|
|
70
72
|
export declare function searchAt(search: BuySearchStatus | null, store: string): BuySearchStatus | null;
|
|
71
73
|
/** Whether a `merchant` event is about the store you name, as `searchAt` matches it. */
|
|
72
74
|
export declare function isMerchantStatusAt(update: BuyMerchantStatusUpdate, store: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The line to show the shopper for one store's status, or null for none. A store the shopper named (`named`, by its domain, id
|
|
77
|
+
* or name) that reads `unavailable` reads `still loading Walmart`; every other store and status reads nothing, so a store
|
|
78
|
+
* the shopper did not name drops out quietly while other stores fill the answer.
|
|
79
|
+
*/
|
|
80
|
+
export declare function merchantStatusLine(store: BuyMerchantStatus | BuyMerchantStatusUpdate, named: string | readonly string[]): string | null;
|
|
81
|
+
/** Every line `merchantStatusLine` gives for the turn's stores, in the order their searches started; none when `search` is null. */
|
|
82
|
+
export declare function searchStatusLines(search: BuySearchStatus | null, named: string | readonly string[]): string[];
|
package/dist/search-status.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Where each store a turn searches stands: the `merchant` events of a streamed turn, one each time a store's status changes, and
|
|
3
3
|
* the `search` block of the answer, every store at once.
|
|
4
4
|
*/
|
|
5
|
-
const MERCHANT_STATUSES = new Set(['searching', 'confirmed', 'recently_confirmed', 'no_results', 'timed_out', 'confirmation_unavailable', 'failed']);
|
|
5
|
+
const MERCHANT_STATUSES = new Set(['searching', 'confirmed', 'recently_confirmed', 'no_results', 'timed_out', 'confirmation_unavailable', 'failed', 'unavailable']);
|
|
6
6
|
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
7
7
|
const text = (v) => (typeof v === 'string' && v !== '' ? v : null);
|
|
8
8
|
const count = (v) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? Math.round(v) : 0);
|
|
@@ -76,3 +76,23 @@ export function isMerchantStatusAt(update, store) {
|
|
|
76
76
|
const want = storeKey(store);
|
|
77
77
|
return storeKey(update.merchant) === want || storeKey(update.merchantName) === want;
|
|
78
78
|
}
|
|
79
|
+
/** Whether a store, as a line or an update carries it, is one of the stores you name, as `searchAt` matches them. */
|
|
80
|
+
function isNamed(store, named) {
|
|
81
|
+
const name = 'merchant_name' in store ? store.merchant_name : store.merchantName;
|
|
82
|
+
const keys = new Set([storeKey(store.merchant), storeKey(name)]);
|
|
83
|
+
return (typeof named === 'string' ? [named] : named).some((n) => keys.has(storeKey(n)));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The line to show the shopper for one store's status, or null for none. A store the shopper named (`named`, by its domain, id
|
|
87
|
+
* or name) that reads `unavailable` reads `still loading Walmart`; every other store and status reads nothing, so a store
|
|
88
|
+
* the shopper did not name drops out quietly while other stores fill the answer.
|
|
89
|
+
*/
|
|
90
|
+
export function merchantStatusLine(store, named) {
|
|
91
|
+
if (store.status !== 'unavailable' || !isNamed(store, named))
|
|
92
|
+
return null;
|
|
93
|
+
return `still loading ${'merchant_name' in store ? store.merchant_name : store.merchantName}`;
|
|
94
|
+
}
|
|
95
|
+
/** Every line `merchantStatusLine` gives for the turn's stores, in the order their searches started; none when `search` is null. */
|
|
96
|
+
export function searchStatusLines(search, named) {
|
|
97
|
+
return (search?.merchants ?? []).flatMap((m) => merchantStatusLine(m, named) ?? []);
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-cards/commerce-sdk",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.8",
|
|
4
4
|
"description": "Give your agent one tool that buys for your shoppers at real stores, and post each purchase update Agentcard sends into the shopper's chat, over a connection your server opens or a webhook endpoint.",
|
|
5
5
|
"homepage": "https://opencommerce.sh",
|
|
6
6
|
"type": "module",
|