@outlit/pi 2.1.12 → 3.0.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/README.md CHANGED
@@ -22,7 +22,8 @@ pi
22
22
  The default extension registers the default customer intelligence tools from `@outlit/tools`:
23
23
 
24
24
  - `outlit_list_customers`
25
- - `outlit_list_users`
25
+ - `outlit_list_customer_fields`
26
+ - `outlit_list_people`
26
27
  - `outlit_get_customer`
27
28
  - `outlit_get_timeline`
28
29
  - `outlit_list_facts`
@@ -31,9 +32,9 @@ The default extension registers the default customer intelligence tools from `@o
31
32
  - `outlit_list_sources`
32
33
  - `outlit_search_customer_context`
33
34
 
34
- SQL and the other Pi-supported Platform capabilities are available from `@outlit/tools`, but the default Pi policy intentionally stays focused on customer intelligence. A custom Pi extension can opt into every Pi-supported tool with `piToolNames`, including customer relationship and Attention reads, customer ownership and access actions, product-facing Feature list, create, archive, and customer-usage tools, plus safe integration setup, destination, activation, workspace-settings actions, and `outlit_submit_feedback` product feedback intake. The default and analytical policies remain unchanged.
35
+ SQL and the other Pi-supported Platform capabilities are available from `@outlit/tools`, but the default Pi policy intentionally stays focused on customer intelligence. A custom Pi extension can opt into every Pi-supported tool with `piToolNames`, including task reads and actions, customer ownership and access actions, product-facing Feature list, create and archive tools, `outlit_list_toolsets` and `outlit_load_toolset`, plus safe integration setup, destination, activation, workspace-settings actions, and `outlit_submit_feedback` product feedback intake. The default and analytical policies remain unchanged.
35
36
 
36
- For analytical agents that need cohorts, usage trends, revenue filters, activation gaps, or aggregate checks, import `analyticalToolNames`. It combines the default customer intelligence tools with `outlit_schema` and `outlit_query` without exposing every customer tool:
37
+ For analytical agents that need cohorts, usage trends, revenue filters, activation gaps, or aggregate checks, import `analyticalToolNames`. It combines the default customer intelligence tools with `outlit_get_schema` and `outlit_query` without exposing every customer tool:
37
38
 
38
39
  ```ts
39
40
  import { analyticalToolNames, createOutlitPiExtension } from "@outlit/pi"
@@ -53,11 +54,23 @@ pi install npm:@outlit/pi
53
54
 
54
55
  The skill gives the model generic guidance for choosing between customer records, users, timelines, facts, search, sources, and SQL when SQL tools are enabled. It does not add CLI or MCP instructions; it assumes the Outlit tools registered by this package are the available interface.
55
56
 
56
- The facts tool supports `factTypes` filters for narrowing structured evidence. Public filters include customer-memory facts and relationship transitions such as `CONTACT_DEPARTURE`, `CONTACT_POSITION_CHANGE`, and `CONTACT_DISENGAGEMENT`. Anomaly detector fact types are not supported as public filters because customers may not have configured core actions, activation paths, or funnels.
57
+ The facts tool supports `filters.types` for narrowing structured evidence (all filter values are lowercase). Public filters include customer-memory facts and relationship transitions such as `contact_departure`, `contact_position_change`, and `contact_disengagement`. Anomaly detector fact types are not supported as public filters because customers may not have configured core actions, activation paths, or funnels.
57
58
 
58
59
  ## Custom Toolsets
59
60
 
60
- Create a small Pi extension when you want a narrower or broader toolset:
61
+ Create a small Pi extension when you want a narrower or broader toolset. Core groups its tools into toolsets (`core`, `work`, `identity`, `admin`, `meta`); `toolsets` registers every tool in the ones you name, and combines with `toolNames` when you pass both:
62
+
63
+ ```ts
64
+ import { createOutlitPiExtension } from "@outlit/pi"
65
+
66
+ export default createOutlitPiExtension({
67
+ toolsets: ["core", "work"],
68
+ })
69
+ ```
70
+
71
+ A tool result that comes with a deprecation or an input notice from Outlit (for example a limit lowered to the maximum) carries it as a second text block after the JSON.
72
+
73
+ To register every Pi-supported tool:
61
74
 
62
75
  ```ts
63
76
  import { createOutlitPiExtension, piToolNames } from "@outlit/pi"
@@ -38,9 +38,7 @@ function createOutlitPiExtension(options = {}) {
38
38
  };
39
39
  }
40
40
  function createOutlitPiTools(options = {}) {
41
- return resolveToolNames(options.toolNames).map(
42
- (toolName) => createOutlitPiTool(toolName, options)
43
- );
41
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
44
42
  }
45
43
  function createOutlitPiTool(toolName, options = {}) {
46
44
  if (!(0, import_tools.isPublicToolName)(toolName)) {
@@ -58,13 +56,17 @@ function createOutlitPiTool(toolName, options = {}) {
58
56
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
59
57
  parameters: toPiToolParameters(contract.inputSchema),
60
58
  async execute(_toolCallId, params) {
59
+ let responseInfo;
61
60
  const client = (0, import_tools.createOutlitClient)({
62
61
  apiKey: resolveApiKey(options),
63
62
  baseUrl: resolveBaseUrl(options),
64
- fetch: options.fetch
63
+ fetch: options.fetch,
64
+ onResponse: (info) => {
65
+ responseInfo = info;
66
+ }
65
67
  });
66
68
  const result = await client.callTool(toolName, normalizeToolInput(params));
67
- return formatToolResult(toolName, result);
69
+ return formatToolResult(toolName, result, responseInfo);
68
70
  }
69
71
  };
70
72
  }
@@ -78,8 +80,11 @@ function toPiToolParameters(inputSchema) {
78
80
  function formatOutlitToolLabel(toolName) {
79
81
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
80
82
  }
81
- function resolveToolNames(toolNames) {
82
- const names = toolNames ?? import_tools.defaultToolNames;
83
+ function resolveToolNames(options) {
84
+ const names = [
85
+ ...options.toolNames ?? (options.toolsets ? [] : import_tools.defaultToolNames),
86
+ ...options.toolsets ? (0, import_tools.toolNamesInToolsets)(options.toolsets) : []
87
+ ];
83
88
  return [...new Set(names)].map((name) => {
84
89
  if (!(0, import_tools.isPublicToolName)(name)) {
85
90
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -110,9 +115,21 @@ function normalizeToolInput(params) {
110
115
  }
111
116
  return params;
112
117
  }
113
- function formatToolResult(toolName, result) {
118
+ function responseNotices(info) {
119
+ if (!info) return [];
120
+ return [
121
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
122
+ ...info.notices
123
+ ];
124
+ }
125
+ function formatToolResult(toolName, result, info) {
126
+ const notices = responseNotices(info);
114
127
  return {
115
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
128
+ content: [
129
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
130
+ // After the result, so a reader of the first block still gets the JSON alone.
131
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
132
+ ],
116
133
  details: {
117
134
  toolName,
118
135
  result
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/extension.ts","../src/index.ts"],"sourcesContent":["import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n","import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type PiToolName,\n piToolNames,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBASO;AA4JP,IAAAA,gBAMO;AA/JA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAkB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,QAAQ,SAAS,EAAE;AAAA,IAAI,CAAC,aAC9C,mBAAmB,UAAU,OAAO;AAAA,EACtC;AACF;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,KAAC,+BAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAAc,IAAI,QAAQ,GAAG;AAChC,UAAM,IAAI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QAAQ,MAAM,KAAK,gBAAgB,QAAQ,IAAI,kBAAkB,CAAC;AAEjG,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,GAAG,kBAAkB,sCAAsC;AAAA,EAC7E;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,SAA2C;AACjE,SACE,gBAAgB,QAAQ,OAAO,KAC/B,gBAAgB,QAAQ,IAAI,kBAAkB,CAAC,KAC/C;AAEJ;AAEA,SAAS,gBAAgB,OAA+C;AACtE,QAAM,UAAU,OAAO,KAAK;AAC5B,SAAO,UAAU,UAAU;AAC7B;AAEA,SAAS,mBAAmB,QAA0C;AACpE,MAAI,WAAW,QAAW;AACxB,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG;AAC1E,UAAM,IAAI,UAAU,wCAAwC;AAAA,EAC9D;AAEA,SAAO;AACT;AAEA,SAAS,iBACP,UACA,QACsC;AACtC,SAAO;AAAA,IACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC;AAAA,IACnF,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAaA,IAAO,cAAQ,wBAAwB;;;AD5KvC,IAAO,oBAAQ,wBAAwB;","names":["import_tools"]}
1
+ {"version":3,"sources":["../src/extension.ts","../src/index.ts"],"sourcesContent":["import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n","import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAYO;AAwLP,IAAAA,gBAOO;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OA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A,QACA,MACsC;AACtC,QAAM,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;;;AD5MvC,IAAO,oBAAQ,wBAAwB;","names":["import_tools"]}
package/dist/extension.js CHANGED
@@ -5,14 +5,16 @@ import {
5
5
  defaultToolNames,
6
6
  getPublicToolContract,
7
7
  isPublicToolName,
8
- piToolNames
8
+ piToolNames,
9
+ toolNamesInToolsets
9
10
  } from "@outlit/tools";
10
11
  import {
11
12
  analyticalToolNames,
12
13
  defaultToolNames as defaultToolNames2,
13
14
  piToolNames as piToolNames2,
14
15
  piToolNames as piToolNames3,
15
- sqlToolNames
16
+ sqlToolNames,
17
+ toolsetNames
16
18
  } from "@outlit/tools";
17
19
  var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
18
20
  var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
@@ -25,9 +27,7 @@ function createOutlitPiExtension(options = {}) {
25
27
  };
26
28
  }
27
29
  function createOutlitPiTools(options = {}) {
28
- return resolveToolNames(options.toolNames).map(
29
- (toolName) => createOutlitPiTool(toolName, options)
30
- );
30
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
31
31
  }
32
32
  function createOutlitPiTool(toolName, options = {}) {
33
33
  if (!isPublicToolName(toolName)) {
@@ -45,13 +45,17 @@ function createOutlitPiTool(toolName, options = {}) {
45
45
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
46
46
  parameters: toPiToolParameters(contract.inputSchema),
47
47
  async execute(_toolCallId, params) {
48
+ let responseInfo;
48
49
  const client = createOutlitClient({
49
50
  apiKey: resolveApiKey(options),
50
51
  baseUrl: resolveBaseUrl(options),
51
- fetch: options.fetch
52
+ fetch: options.fetch,
53
+ onResponse: (info) => {
54
+ responseInfo = info;
55
+ }
52
56
  });
53
57
  const result = await client.callTool(toolName, normalizeToolInput(params));
54
- return formatToolResult(toolName, result);
58
+ return formatToolResult(toolName, result, responseInfo);
55
59
  }
56
60
  };
57
61
  }
@@ -65,8 +69,11 @@ function toPiToolParameters(inputSchema) {
65
69
  function formatOutlitToolLabel(toolName) {
66
70
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
67
71
  }
68
- function resolveToolNames(toolNames) {
69
- const names = toolNames ?? defaultToolNames;
72
+ function resolveToolNames(options) {
73
+ const names = [
74
+ ...options.toolNames ?? (options.toolsets ? [] : defaultToolNames),
75
+ ...options.toolsets ? toolNamesInToolsets(options.toolsets) : []
76
+ ];
70
77
  return [...new Set(names)].map((name) => {
71
78
  if (!isPublicToolName(name)) {
72
79
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -97,9 +104,21 @@ function normalizeToolInput(params) {
97
104
  }
98
105
  return params;
99
106
  }
100
- function formatToolResult(toolName, result) {
107
+ function responseNotices(info) {
108
+ if (!info) return [];
109
+ return [
110
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
111
+ ...info.notices
112
+ ];
113
+ }
114
+ function formatToolResult(toolName, result, info) {
115
+ const notices = responseNotices(info);
101
116
  return {
102
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
117
+ content: [
118
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
119
+ // After the result, so a reader of the first block still gets the JSON alone.
120
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
121
+ ],
103
122
  details: {
104
123
  toolName,
105
124
  result
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/extension.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type PiToolName,\n piToolNames,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AA4JP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,OACK;AA/JA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAkB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,QAAQ,SAAS,EAAE;AAAA,IAAI,CAAC,aAC9C,mBAAmB,UAAU,OAAO;AAAA,EACtC;AACF;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,CAAC,iBAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAA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AAc,SAA2C;AAChE,QAAM,SAAS,gBAAgB,QAAQ,MAAM,KAAK,gBAAgB,QAAQ,IAAI,kBAAkB,CAAC;AAEjG,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,GAAG,kBAAkB,sCAAsC;AAAA,EAC7E;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,SAA2C;AACjE,SACE,gBAAgB,QAAQ,OAAO,KAC/B,gBAAgB,QAAQ,IAAI,kBAAkB,CAAC,KAC/C;AAEJ;AAEA,SAAS,gBAAgB,OAA+C;AACtE,QAAM,UAAU,OAAO,KAAK;AAC5B,SAAO,UAAU,UAAU;AAC7B;AAEA,SAAS,mBAAmB,QAA0C;AACpE,MAAI,WAAW,QAAW;AACxB,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG;AAC1E,UAAM,IAAI,UAAU,wCAAwC;AAAA,EAC9D;AAEA,SAAO;AACT;AAEA,SAAS,iBACP,UACA,QACsC;AACtC,SAAO;AAAA,IACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC;AAAA,IACnF,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAaA,IAAO,cAAQ,wBAAwB;;;AC5KvC,IAAO,oBAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/extension.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAEA;AAAA,OACK;AAwLP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;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,IACL,GAAI,KAAK,cAAc,CAAC,GAAG,KAAK,YAAY,OAAO,WAAW,KAAK,YAAY,KAAK,GAAG,IAAI,CAAC;AAAA,IAC5F,GAAG,KAAK;AAAA,EACV;AACF;AAEA,SAAS,iBACP,UACA,QACA,MACsC;AACtC,QAAM,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;;;AC5MvC,IAAO,oBAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
package/dist/index.cjs CHANGED
@@ -31,7 +31,8 @@ __export(src_exports, {
31
31
  defaultToolNames: () => import_tools2.defaultToolNames,
32
32
  formatOutlitToolLabel: () => formatOutlitToolLabel,
33
33
  piToolNames: () => import_tools2.piToolNames,
34
- sqlToolNames: () => import_tools2.sqlToolNames
34
+ sqlToolNames: () => import_tools2.sqlToolNames,
35
+ toolsetNames: () => import_tools2.toolsetNames
35
36
  });
36
37
  module.exports = __toCommonJS(src_exports);
37
38
  var import_tools = require("@outlit/tools");
@@ -47,9 +48,7 @@ function createOutlitPiExtension(options = {}) {
47
48
  };
48
49
  }
49
50
  function createOutlitPiTools(options = {}) {
50
- return resolveToolNames(options.toolNames).map(
51
- (toolName) => createOutlitPiTool(toolName, options)
52
- );
51
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
53
52
  }
54
53
  function createOutlitPiTool(toolName, options = {}) {
55
54
  if (!(0, import_tools.isPublicToolName)(toolName)) {
@@ -67,13 +66,17 @@ function createOutlitPiTool(toolName, options = {}) {
67
66
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
68
67
  parameters: toPiToolParameters(contract.inputSchema),
69
68
  async execute(_toolCallId, params) {
69
+ let responseInfo;
70
70
  const client = (0, import_tools.createOutlitClient)({
71
71
  apiKey: resolveApiKey(options),
72
72
  baseUrl: resolveBaseUrl(options),
73
- fetch: options.fetch
73
+ fetch: options.fetch,
74
+ onResponse: (info) => {
75
+ responseInfo = info;
76
+ }
74
77
  });
75
78
  const result = await client.callTool(toolName, normalizeToolInput(params));
76
- return formatToolResult(toolName, result);
79
+ return formatToolResult(toolName, result, responseInfo);
77
80
  }
78
81
  };
79
82
  }
@@ -87,8 +90,11 @@ function toPiToolParameters(inputSchema) {
87
90
  function formatOutlitToolLabel(toolName) {
88
91
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
89
92
  }
90
- function resolveToolNames(toolNames) {
91
- const names = toolNames ?? import_tools.defaultToolNames;
93
+ function resolveToolNames(options) {
94
+ const names = [
95
+ ...options.toolNames ?? (options.toolsets ? [] : import_tools.defaultToolNames),
96
+ ...options.toolsets ? (0, import_tools.toolNamesInToolsets)(options.toolsets) : []
97
+ ];
92
98
  return [...new Set(names)].map((name) => {
93
99
  if (!(0, import_tools.isPublicToolName)(name)) {
94
100
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -119,9 +125,21 @@ function normalizeToolInput(params) {
119
125
  }
120
126
  return params;
121
127
  }
122
- function formatToolResult(toolName, result) {
128
+ function responseNotices(info) {
129
+ if (!info) return [];
130
+ return [
131
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
132
+ ...info.notices
133
+ ];
134
+ }
135
+ function formatToolResult(toolName, result, info) {
136
+ const notices = responseNotices(info);
123
137
  return {
124
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
138
+ content: [
139
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
140
+ // After the result, so a reader of the first block still gets the JSON alone.
141
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
142
+ ],
125
143
  details: {
126
144
  toolName,
127
145
  result
@@ -144,6 +162,7 @@ var src_default = createOutlitPiExtension();
144
162
  defaultToolNames,
145
163
  formatOutlitToolLabel,
146
164
  piToolNames,
147
- sqlToolNames
165
+ sqlToolNames,
166
+ toolsetNames
148
167
  });
149
168
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type PiToolName,\n piToolNames,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBASO;AA4JP,IAAAA,gBAMO;AA/JA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAkB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,QAAQ,SAAS,EAAE;AAA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ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAYO;AAwLP,IAAAA,gBAOO;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;A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AS,gBAAgB,MAAqD;AAC5E,MAAI,CAAC,KAAM,QAAO,CAAC;AACnB,SAAO;AAAA,IACL,GAAI,KAAK,cAAc,CAAC,GAAG,KAAK,YAAY,OAAO,WAAW,KAAK,YAAY,KAAK,GAAG,IAAI,CAAC;AAAA,IAC5F,GAAG,KAAK;AAAA,EACV;AACF;AAEA,SAAS,iBACP,UACA,QACA,MACsC;AACtC,QAAM,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;","names":["import_tools"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ExtensionAPI, ToolDefinition } from '@mariozechner/pi-coding-agent';
2
- import { OutlitToolsFetch, PiToolName } from '@outlit/tools';
3
- export { PiToolName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames } from '@outlit/tools';
2
+ import { OutlitToolsFetch, PiToolName, ToolsetName } from '@outlit/tools';
3
+ export { PiToolName, ToolsetName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames, toolsetNames } from '@outlit/tools';
4
4
  import { TSchema } from '@sinclair/typebox';
5
5
 
6
6
  declare const OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
@@ -10,6 +10,11 @@ type OutlitPiExtensionOptions = {
10
10
  baseUrl?: string;
11
11
  fetch?: OutlitToolsFetch;
12
12
  toolNames?: readonly PiToolName[];
13
+ /**
14
+ * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`
15
+ * too, both apply; with neither, the default read-only tools are registered.
16
+ */
17
+ toolsets?: readonly ToolsetName[];
13
18
  };
14
19
  type OutlitPiRegistry = Pick<ExtensionAPI, "registerTool">;
15
20
  type OutlitPiToolDetails = {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ExtensionAPI, ToolDefinition } from '@mariozechner/pi-coding-agent';
2
- import { OutlitToolsFetch, PiToolName } from '@outlit/tools';
3
- export { PiToolName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames } from '@outlit/tools';
2
+ import { OutlitToolsFetch, PiToolName, ToolsetName } from '@outlit/tools';
3
+ export { PiToolName, ToolsetName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames, toolsetNames } from '@outlit/tools';
4
4
  import { TSchema } from '@sinclair/typebox';
5
5
 
6
6
  declare const OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
@@ -10,6 +10,11 @@ type OutlitPiExtensionOptions = {
10
10
  baseUrl?: string;
11
11
  fetch?: OutlitToolsFetch;
12
12
  toolNames?: readonly PiToolName[];
13
+ /**
14
+ * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`
15
+ * too, both apply; with neither, the default read-only tools are registered.
16
+ */
17
+ toolsets?: readonly ToolsetName[];
13
18
  };
14
19
  type OutlitPiRegistry = Pick<ExtensionAPI, "registerTool">;
15
20
  type OutlitPiToolDetails = {
package/dist/index.js CHANGED
@@ -5,14 +5,16 @@ import {
5
5
  defaultToolNames,
6
6
  getPublicToolContract,
7
7
  isPublicToolName,
8
- piToolNames
8
+ piToolNames,
9
+ toolNamesInToolsets
9
10
  } from "@outlit/tools";
10
11
  import {
11
12
  analyticalToolNames,
12
13
  defaultToolNames as defaultToolNames2,
13
14
  piToolNames as piToolNames2,
14
15
  piToolNames as piToolNames3,
15
- sqlToolNames
16
+ sqlToolNames,
17
+ toolsetNames
16
18
  } from "@outlit/tools";
17
19
  var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
18
20
  var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
@@ -25,9 +27,7 @@ function createOutlitPiExtension(options = {}) {
25
27
  };
26
28
  }
27
29
  function createOutlitPiTools(options = {}) {
28
- return resolveToolNames(options.toolNames).map(
29
- (toolName) => createOutlitPiTool(toolName, options)
30
- );
30
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
31
31
  }
32
32
  function createOutlitPiTool(toolName, options = {}) {
33
33
  if (!isPublicToolName(toolName)) {
@@ -45,13 +45,17 @@ function createOutlitPiTool(toolName, options = {}) {
45
45
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
46
46
  parameters: toPiToolParameters(contract.inputSchema),
47
47
  async execute(_toolCallId, params) {
48
+ let responseInfo;
48
49
  const client = createOutlitClient({
49
50
  apiKey: resolveApiKey(options),
50
51
  baseUrl: resolveBaseUrl(options),
51
- fetch: options.fetch
52
+ fetch: options.fetch,
53
+ onResponse: (info) => {
54
+ responseInfo = info;
55
+ }
52
56
  });
53
57
  const result = await client.callTool(toolName, normalizeToolInput(params));
54
- return formatToolResult(toolName, result);
58
+ return formatToolResult(toolName, result, responseInfo);
55
59
  }
56
60
  };
57
61
  }
@@ -65,8 +69,11 @@ function toPiToolParameters(inputSchema) {
65
69
  function formatOutlitToolLabel(toolName) {
66
70
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
67
71
  }
68
- function resolveToolNames(toolNames) {
69
- const names = toolNames ?? defaultToolNames;
72
+ function resolveToolNames(options) {
73
+ const names = [
74
+ ...options.toolNames ?? (options.toolsets ? [] : defaultToolNames),
75
+ ...options.toolsets ? toolNamesInToolsets(options.toolsets) : []
76
+ ];
70
77
  return [...new Set(names)].map((name) => {
71
78
  if (!isPublicToolName(name)) {
72
79
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -97,9 +104,21 @@ function normalizeToolInput(params) {
97
104
  }
98
105
  return params;
99
106
  }
100
- function formatToolResult(toolName, result) {
107
+ function responseNotices(info) {
108
+ if (!info) return [];
109
+ return [
110
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
111
+ ...info.notices
112
+ ];
113
+ }
114
+ function formatToolResult(toolName, result, info) {
115
+ const notices = responseNotices(info);
101
116
  return {
102
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
117
+ content: [
118
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
119
+ // After the result, so a reader of the first block still gets the JSON alone.
120
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
121
+ ],
103
122
  details: {
104
123
  toolName,
105
124
  result
@@ -122,6 +141,7 @@ export {
122
141
  defaultToolNames2 as defaultToolNames,
123
142
  formatOutlitToolLabel,
124
143
  piToolNames2 as piToolNames,
125
- sqlToolNames
144
+ sqlToolNames,
145
+ toolsetNames
126
146
  };
127
147
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type PiToolName,\n piToolNames,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AA4JP;AAAA,EACE;AAAA,EACA,oBAA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A,SAAS,iBACP,UACA,QACsC;AACtC,SAAO;AAAA,IACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC;AAAA,IACnF,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAaA,IAAO,cAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAEA;AAAA,OACK;AAwLP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC;AAC1F;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,CAAC,iBAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAAc,IAAI,QAAQ,GAAG;AAChC,UAAM,IAAI,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACpE;AAEA,QAAM,WAAW,sBAAsB,QAAQ;AAC/C,QAAM,QAAQ,sBAAsB,QAAQ;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,aAAa,SAAS;AAAA,IACtB,eAAe,GAAG,KAAK,KAAK,UAAU,SAAS,WAAW,CAAC;AAAA,IAC3D,YAAY,mBAAmB,SAAS,WAAW;AAAA,IACnD,MAAM,QAAQ,aAAa,QAAQ;AACjC,UAAI;AACJ,YAAM,SAA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"name": "@outlit/pi",
3
- "version": "2.1.12",
3
+ "version": "3.0.0",
4
4
  "description": "Pi package for Outlit customer intelligence tools and skill guidance",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Outlit AI",
@@ -66,7 +66,7 @@
66
66
  "test": "vitest run"
67
67
  },
68
68
  "dependencies": {
69
- "@outlit/tools": "^2.4.0"
69
+ "@outlit/tools": "^3.0.0"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@mariozechner/pi-coding-agent": "*",
@@ -13,19 +13,23 @@ Do not invent customer state when Outlit can answer it. Call out sparse or messy
13
13
 
14
14
  ## Tool Choice
15
15
 
16
- - Use `outlit_list_customers` to discover customers for portfolio, segment, risk, revenue, trial, or account-health questions.
17
- - Use `outlit_list_users` for user-level questions or when a customer answer depends on individual users.
16
+ - Use `outlit_list_customers` to discover customers for portfolio, segment, risk, revenue, trial, or account-health questions. `filters.partOf` lists one customer's direct subsidiaries with their ARR.
17
+ - Use `outlit_list_customer_fields` to find a CRM, support tool or trait field and the values customers hold before filtering `outlit_list_customers` by it (`filters.fields`) or returning it (`fields`). Filters live under `filters`; page with `page.nextCursor`.
18
+ - Use `outlit_list_people` for questions about the people at customers: who the champion or decision maker is, who went quiet, who last spoke to us. Pass `customer` for one account, which also lists the people its CRM companies link to. Filters live under `filters`; each person carries `lastCommunication` (the latest conversation they took part in, never product use).
18
19
  - Use `outlit_get_customer` before deep analysis of a named customer or account.
19
- - Use `outlit_get_timeline` when order, recency, activity sequence, meetings, messages, product usage, support, or billing chronology matters.
20
- - Use `outlit_list_facts` to browse structured account facts, known signals, open issues, health indicators, relationship notes, activation, billing, or renewal context. Narrow with `status`, `sourceTypes`, and `factTypes` when you know what evidence class you need.
21
- - Use `outlit_get_fact` when you already have a fact id and need the canonical fact payload.
20
+ Each included section reports a `status`: only `available` has `data`; `empty`, `not_connected`, `not_synced` and `unavailable` say why there is none, which is not the same as zero. Money values carry `formatted` text; show it as is.
21
+ Ask for what the answer needs with `include`: `relationship` (a summary and up to eight current statements), `features` (product-event features), `meters` (Autumn metered quantities) and `credits` (credit pools with balance and burn rate). `hierarchy` is the parent company and direct subsidiaries the CRM records. `features`, `meters`, `credits` and `hierarchy`'s children come in pages of 25; page one with its own `limit` and `cursor`.
22
+ - Use `outlit_get_timeline` when order, recency, activity sequence, meetings, messages, product usage, support, or billing chronology matters. Filters live under `filters`: `channels` (lowercase, such as `communication` or `product`), `eventTypes`, and a window as `within` or `after` with an optional `before`. Page with `page.nextCursor`.
23
+ - Use `outlit_list_facts` to browse structured account facts, known signals, open issues, health indicators, relationship notes, activation, billing, or renewal context. Narrow with `filters.status`, `filters.sourceTypes`, `filters.types`, and `filters.categories` when you know what evidence class you need; all values are lowercase.
24
+ - Use `outlit_get_fact` when you already have a fact id and need the canonical fact payload; it returns `{ customer, fact }`, and `include: ["evidence"]` lists every source the fact cites.
22
25
  - Use `outlit_search_customer_context` for fuzzy or thematic questions such as pricing concern, blocked integration, not using, renewal, champion left, negative sentiment, expansion, implementation, or support escalation.
23
- - Use `outlit_list_sources` to discover the source artifacts available for a customer before retrieving one in full.
24
- - Use `outlit_get_source` when a fact or search result needs stronger evidence from the underlying source artifact.
25
- - Use `outlit_get_customer_features` for exact, customer-level Feature observations. Treat unavailable coverage as unknown, not zero usage.
26
+ - Use `outlit_list_sources` to discover the source artifacts available for a customer before retrieving one in full. Narrow with `filters` (`sourceTypes`, `after`, `before`, `participant`, `provider`, `hasTranscript`).
27
+ - Use `outlit_get_source` when a fact or search result needs stronger evidence from the underlying source artifact. Pass the `source { type, id }` that the timeline event, fact, search result or source listing returned, as it came. Content is `content.data.segments`, a page at a time (`content.data.page`).
28
+ - Use `outlit_get_customer` with `include: ["features"]` for exact, customer-level Feature observations. Treat unavailable coverage as unknown, not zero usage.
26
29
  - Use `outlit_list_features` to inspect the confirmed workspace taxonomy, historical evidence, eligible sources, and event candidates.
27
30
  - Use `outlit_create_feature` only when the user explicitly asks to configure one confirmed product capability from one exact event rule. Outlit creates the supporting usage metrics internally.
28
31
  - Use `outlit_archive_feature` only when the user explicitly asks to archive a feature and supplies the current opaque id and revision. The MVP has no restore operation and rejects archiving the final active feature.
32
+ - Use `outlit_list_toolsets` when a tool you need is not in your list; `outlit_load_toolset` summarizes one toolset's tools, and with `tools` (at most 10 names) returns their full definitions.
29
33
  - Use `outlit_submit_feedback` when the user wants to report an Outlit product bug, idea, or friction. Feedback is product intake, not a support ticket or a guaranteed reply. Put diagnostics in `context`, never secrets or unnecessary customer data.
30
34
 
31
35
  Use customer lookups before SQL. SQL is for aggregates, joins, cohorts, time-series analysis, and custom reporting.
@@ -33,23 +37,24 @@ Use customer lookups before SQL. SQL is for aggregates, joins, cohorts, time-ser
33
37
  ## Facts vs Search vs Timeline
34
38
 
35
39
  - Use `outlit_list_facts` to list what Outlit already knows about an account.
36
- - Use `factTypes` for specific public fact classes such as `CHURN_RISK`, `EXPANSION`, `PRODUCT_USAGE`, `CONTACT_DEPARTURE`, `CONTACT_POSITION_CHANGE`, or `CONTACT_DISENGAGEMENT` when those are relevant. Do not request anomaly detector fact types such as `CORE_ACTION_DECAY`, `CADENCE_BREAK`, `QUIET_ACCOUNT`, `ACTIVATION_RATE_DROP`, or `FUNNEL_DROPOFF` as filters.
40
+ - Use `filters.types` for specific public fact classes such as `churn_risk`, `expansion`, `product_usage`, `contact_departure`, `contact_position_change`, or `contact_disengagement` when those are relevant. Do not request anomaly detector fact types such as `core_action_decay`, `cadence_break`, `quiet_account`, `activation_rate_drop`, or `funnel_dropoff` as filters.
37
41
  - Use `outlit_get_fact` when you already have a fact id and need that exact fact.
38
- - Use `outlit_search_customer_context` for a specific question or theme, including cross-customer questions.
42
+ - Use `outlit_search_customer_context` for a specific question or theme, including cross-customer questions. `limit` caps the results; `filters` take `sourceTypes`, `after` and `before`. An empty result carries `coverage.searched`, which says what was searched.
39
43
  - Use `outlit_get_source` when you need the exact email, call, calendar event, ticket, or other source artifact behind a fact or search hit.
40
44
  - Use `outlit_get_timeline` when order and sequence matter.
41
45
 
42
46
  ## SQL Tools
43
47
 
44
- Only use SQL if `outlit_schema` and `outlit_query` are available in the current Pi session.
48
+ Only use SQL if `outlit_get_schema` and `outlit_query` are available in the current Pi session.
45
49
 
46
- - Call `outlit_schema` before writing SQL.
50
+ - Call `outlit_get_schema` before writing SQL. `topic: "examples"` returns worked queries that run as written.
47
51
  - Prefer customer lookups, facts, timeline, and search before SQL for account-specific analysis.
48
52
  - Use SQL for aggregates, cohorts, joins, custom reporting, and questions that need exact counts or revenue math.
49
53
  - Use the query patterns in the SQL reference. Do not assume another database's date or JSON helpers.
50
54
  - Add explicit time filters for event queries.
51
55
  - Use `LIMIT`.
52
- - Divide money fields in cents by `100` for display.
56
+ - Money columns are minor units: divide `arr_amount` by `10^arr_decimals`, and never add amounts across `arr_currency`.
57
+ - A result page holds at most `limit` rows (default 100, max 1000); send `page.nextCursor` with the same SQL for the next page.
53
58
  - Request only the fields needed for the answer.
54
59
 
55
60
  For supported query patterns, read [references/sql-reference.md](references/sql-reference.md).
@@ -2,14 +2,14 @@
2
2
 
3
3
  Use this when writing or debugging `outlit_query` queries.
4
4
 
5
- Always inspect schema first with `outlit_schema`.
5
+ Always inspect schema first with `outlit_get_schema` (`topic: "examples"` has worked queries).
6
6
 
7
7
  ## Views
8
8
 
9
9
  - `activity`: product and communication activity
10
- - `customers`: customer attributes, billing, revenue (`arr_cents` with `arr_currency`; `mrr_cents` is deprecated)
10
+ - `customers`: customer attributes, billing, revenue (`arr_amount` in minor units with `arr_currency` and `arr_decimals`; `arr_cents` and `mrr_cents` are deprecated)
11
11
  - `users`: user attributes and journey stages
12
- - `revenue`: daily MRR snapshots
12
+ - `revenue`: ARR daily, one row per customer per UTC day since 2026-11-06 (`snapshot_date`, `arr_amount`, `arr_currency`, `arr_decimals`, `arr_estimated`, `revenue_lifecycle`, customer id, name, domain and status); a day with no row was not computed. It has no MRR columns
13
13
 
14
14
  ## Useful Patterns
15
15
 
@@ -20,7 +20,7 @@ toStartOfMonth(occurred_at)
20
20
  dateDiff('day', first_seen_at, now())
21
21
  occurred_at >= now() - INTERVAL 30 DAY
22
22
  countIf(billing_status = 'PAYING')
23
- sumIf(arr_cents, billing_status = 'PAYING' AND arr_currency = 'USD')
23
+ sumIf(arr_amount, billing_status = 'PAYING' AND arr_currency = 'USD')
24
24
  JSONExtractString(properties, 'path')
25
25
  JSONExtractString(traits, 'plan')
26
26
  ```
@@ -35,7 +35,9 @@ Use the patterns above instead of unsupported date helpers like `DATE_SUB()`.
35
35
  - Add time filters for event queries.
36
36
  - Use `LIMIT`.
37
37
  - Prefer specific columns over `SELECT *`.
38
- - Divide cents by `100` for display.
38
+ - Divide `arr_amount` by `10^arr_decimals` for display, and group by `arr_currency`: amounts in different currencies never add.
39
+ - Count `activity` rows with `uniqExact(event_id)`, not `count()`.
40
+ - Pages hold at most `limit` rows (default 100, max 1000); send `page.nextCursor` with the same SQL for the next page.
39
41
 
40
42
  ## Use SQL When
41
43