@specstream/ai-sdk 0.1.2 → 0.1.4

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/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** The SpecStream REST calls the tools share: read a request, price it, start it within a maximum, read its rows. */
2
2
  export declare const DEFAULT_BASE_URL = "https://api.specstream.ai";
3
- export declare const USER_AGENT = "@specstream/ai-sdk/0.1.2";
3
+ export declare const USER_AGENT = "@specstream/ai-sdk/0.1.3";
4
4
  /** A list runs for up to about five minutes, so the tools wait a little longer than that by default. */
5
5
  export declare const DEFAULT_WAIT_SECONDS = 420;
6
6
  export declare const DEFAULT_POLL_INTERVAL_SECONDS = 3;
@@ -82,12 +82,19 @@ type Cell = {
82
82
  } | null;
83
83
  };
84
84
  type RawRecord = {
85
+ entity_id?: unknown;
85
86
  ordinal?: number | null;
86
87
  details?: Cell[] | null;
87
88
  cells?: Cell[] | null;
88
89
  };
89
- /** One row as flat fields: each column's label holds what the list shows, plus where the row was read. */
90
- export declare function flattenRow(findId: string, record: RawRecord): ListRow;
90
+ /** The API's flat row for a record: its fields with each value's page and the row's source page. */
91
+ type FlatRow = Record<string, unknown>;
92
+ /**
93
+ * One row as flat fields: each column's label holds what the list shows. The page of each value (<field>_source)
94
+ * and of the fact that put the row in the list (source_url, checked_at) come from the API's flat row, so every
95
+ * tool shows the same pages.
96
+ */
97
+ export declare function flattenRow(findId: string, record: RawRecord, flat?: FlatRow): ListRow;
91
98
  /** The low-level client the tools are built on. Use it directly when you want the calls without a model. */
92
99
  export declare class SpecStreamClient {
93
100
  readonly baseUrl: string;
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** The SpecStream REST calls the tools share: read a request, price it, start it within a maximum, read its rows. */
2
2
  export const DEFAULT_BASE_URL = "https://api.specstream.ai";
3
- export const USER_AGENT = "@specstream/ai-sdk/0.1.2";
3
+ export const USER_AGENT = "@specstream/ai-sdk/0.1.3";
4
4
  /** A list runs for up to about five minutes, so the tools wait a little longer than that by default. */
5
5
  export const DEFAULT_WAIT_SECONDS = 420;
6
6
  export const DEFAULT_POLL_INTERVAL_SECONDS = 3;
@@ -29,16 +29,29 @@ function dollars(cents) {
29
29
  export function listLink(findId) {
30
30
  return `https://specstream.ai/workspace/collections/${encodeURIComponent(findId)}`;
31
31
  }
32
- /** One row as flat fields: each column's label holds what the list shows, plus where the row was read. */
33
- export function flattenRow(findId, record) {
32
+ /** Each value's page in the API's flat row: <field>_source beside the <field> it belongs to. */
33
+ function sourcesOf(flat) {
34
+ const sources = {};
35
+ for (const [key, value] of Object.entries(flat ?? {})) {
36
+ if (key.endsWith("_source") && Object.prototype.hasOwnProperty.call(flat, key.slice(0, -7)))
37
+ sources[key] = value;
38
+ }
39
+ return sources;
40
+ }
41
+ /**
42
+ * One row as flat fields: each column's label holds what the list shows. The page of each value (<field>_source)
43
+ * and of the fact that put the row in the list (source_url, checked_at) come from the API's flat row, so every
44
+ * tool shows the same pages.
45
+ */
46
+ export function flattenRow(findId, record, flat) {
34
47
  const row = { list_id: findId, position: record.ordinal ?? null };
35
- let source = null;
48
+ const sources = sourcesOf(flat);
36
49
  const cells = record.details?.length ? record.details : (record.cells ?? []);
37
50
  for (const cell of cells) {
38
51
  let label = String(cell.label || cell.column_id || "").trim();
39
52
  if (!label)
40
53
  continue;
41
- if (RESERVED.has(label))
54
+ if (RESERVED.has(label) || label in sources)
42
55
  label = `${label} (column)`;
43
56
  let value;
44
57
  if (cell.absence)
@@ -48,12 +61,10 @@ export function flattenRow(findId, record) {
48
61
  else
49
62
  value = cell.value ?? "";
50
63
  row[label] = value;
51
- const provenance = cell.provenance || {};
52
- if (source === null && String(provenance.source_url || "").startsWith("http"))
53
- source = provenance;
54
64
  }
55
- row.source_url = source ? (source.source_url ?? "") : "";
56
- row.checked_at = source ? (source.observed_at ?? "") : "";
65
+ Object.assign(row, sources);
66
+ row.source_url = flat?.source_url ?? "";
67
+ row.checked_at = flat?.checked_at ?? "";
57
68
  row.list_link = listLink(findId);
58
69
  return row;
59
70
  }
@@ -148,8 +159,10 @@ export class SpecStreamClient {
148
159
  const query = new URLSearchParams({ limit: "100", ...(cursor ? { cursor } : {}) });
149
160
  const page = (await this.request("GET", `/v1/finds/${encodeURIComponent(findId)}/rows?${query}`, undefined, { abortSignal })) ?? {};
150
161
  status = typeof page.status === "string" && page.status ? page.status : status;
151
- for (const record of Array.isArray(page.rows) ? page.rows : [])
152
- rows.push(flattenRow(findId, record));
162
+ const flat = new Map((Array.isArray(page.flat_rows) ? page.flat_rows : []).map((item) => [String(item.id), item]));
163
+ for (const record of Array.isArray(page.rows) ? page.rows : []) {
164
+ rows.push(flattenRow(findId, record, flat.get(`${findId}:${String(record.entity_id)}`)));
165
+ }
153
166
  const next = typeof page.next_cursor === "string" && page.next_cursor ? page.next_cursor : null;
154
167
  if (!next || next === cursor)
155
168
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specstream/ai-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Give a Vercel AI SDK agent lead lists, company lists and grants from the live web. Every row comes with its source, priced per match.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,11 +60,11 @@
60
60
  "homepage": "https://specstream.ai/docs/vercel-ai-sdk",
61
61
  "repository": {
62
62
  "type": "git",
63
- "url": "git+https://github.com/Specstreamai/specstream-tools.git",
63
+ "url": "git+https://github.com/specstream/specstream-tools.git",
64
64
  "directory": "packages/ai-sdk"
65
65
  },
66
66
  "bugs": {
67
- "url": "https://github.com/Specstreamai/specstream-tools/issues"
67
+ "url": "https://github.com/specstream/specstream-tools/issues"
68
68
  },
69
69
  "publishConfig": {
70
70
  "access": "public"