@ui-calling/adk 0.0.0-stage → 0.1.0-preview.1
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/LICENSE +21 -0
- package/README.md +17 -2
- package/dist/index.d.ts +33 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 San Pau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ui-calling/adk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ui-calling surfaces as a toolset for Google's Agent Development Kit for TypeScript (`@google/adk` 2.5 or later).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { LlmAgent } from "@google/adk";
|
|
7
|
+
import { WOKEN_TURN, adkToolset } from "@ui-calling/adk";
|
|
8
|
+
|
|
9
|
+
const agent = new LlmAgent({
|
|
10
|
+
name: "shop", model: "gemini-3.5-flash-lite", instruction,
|
|
11
|
+
tools: [adkToolset(ui, { onLink: (link, ctx) => links.get(ctx.sessionId)?.push(link) })],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// A turn a screen event started: also offers stay_silent, for this turn only.
|
|
15
|
+
runner.runAsync({ userId: e.subject, sessionId: e.conversationId, newMessage, stateDelta: WOKEN_TURN });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
One agent serves every user: each tool runs for the ADK session it's called in (`conversationId` = `sessionId`, `subject` = `userId`), so a screen event names the session to wake. The guide: `npx ui-calling guide agent`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReadonlyContext, Context, BaseToolset } from '@google/adk';
|
|
2
|
+
import { Who, SurfaceLink, UiCalling } from '@ui-calling/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pass as `stateDelta` on a turn a screen event started: `runner.runAsync({ userId, sessionId, newMessage, stateDelta: WOKEN_TURN })`.
|
|
6
|
+
* The toolset then also offers `stay_silent`. A `temp:` key lasts only that turn, so the next user message never sees it.
|
|
7
|
+
*/
|
|
8
|
+
declare const WOKEN_TURN: {
|
|
9
|
+
readonly "temp:ui_calling_woken": true;
|
|
10
|
+
};
|
|
11
|
+
type AdkAdapterOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Who the tools run for. Defaults to ADK's own session: `{ conversationId: ctx.sessionId, subject: ctx.userId }`,
|
|
14
|
+
* so an event's `conversationId` and `subject` are the `sessionId` and `userId` to run the woken turn with.
|
|
15
|
+
*/
|
|
16
|
+
who?: (ctx: ReadonlyContext) => Who;
|
|
17
|
+
/** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */
|
|
18
|
+
filter?: (toolName: string, ctx: ReadonlyContext) => boolean;
|
|
19
|
+
/** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */
|
|
20
|
+
onLink?: (link: SurfaceLink, ctx: Context) => void;
|
|
21
|
+
/** Called when the model calls `stay_silent`. The turn ends there: send nothing for it, whatever text came before. */
|
|
22
|
+
onSilent?: (reason: string, ctx: Context) => void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Surfaces as an ADK toolset. One agent serves every user: the tools read who they run for from the session.
|
|
26
|
+
*
|
|
27
|
+
* const agent = new LlmAgent({ name: "shop", model: "gemini-3.5-flash-lite", instruction,
|
|
28
|
+
* tools: [adkToolset(ui, { onLink: (link, ctx) => links.get(ctx.sessionId)?.push(link) })] });
|
|
29
|
+
*/
|
|
30
|
+
declare function adkToolset(ui: UiCalling, opts?: AdkAdapterOptions): BaseToolset;
|
|
31
|
+
|
|
32
|
+
export { WOKEN_TURN, adkToolset };
|
|
33
|
+
export type { AdkAdapterOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { BaseTool, BaseToolset } from "@google/adk";
|
|
3
|
+
var WOKEN_TURN = { "temp:ui_calling_woken": true };
|
|
4
|
+
function adkToolset(ui, opts = {}) {
|
|
5
|
+
return new UiCallingToolset(ui, opts);
|
|
6
|
+
}
|
|
7
|
+
var defaultWho = (ctx) => ({ conversationId: ctx.sessionId, subject: ctx.userId });
|
|
8
|
+
var UiCallingToolset = class extends BaseToolset {
|
|
9
|
+
constructor(ui, opts) {
|
|
10
|
+
super();
|
|
11
|
+
this.ui = ui;
|
|
12
|
+
this.opts = opts;
|
|
13
|
+
}
|
|
14
|
+
ui;
|
|
15
|
+
opts;
|
|
16
|
+
// Asked on every model call, so the list follows the turn: stay_silent only when woken, the filter per user.
|
|
17
|
+
async getTools(ctx) {
|
|
18
|
+
const woken = ctx?.state.get(Object.keys(WOKEN_TURN)[0]) === true;
|
|
19
|
+
const filter = ctx && this.opts.filter ? (name) => this.opts.filter(name, ctx) : void 0;
|
|
20
|
+
return this.ui.tools({ woken, filter }).map((spec) => new SurfaceTool(this.ui, spec, this.opts, filter));
|
|
21
|
+
}
|
|
22
|
+
async close() {
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var SurfaceTool = class extends BaseTool {
|
|
26
|
+
constructor(ui, spec, opts, filter) {
|
|
27
|
+
super({ name: spec.name, description: spec.description });
|
|
28
|
+
this.ui = ui;
|
|
29
|
+
this.spec = spec;
|
|
30
|
+
this.opts = opts;
|
|
31
|
+
this.filter = filter;
|
|
32
|
+
}
|
|
33
|
+
ui;
|
|
34
|
+
spec;
|
|
35
|
+
opts;
|
|
36
|
+
filter;
|
|
37
|
+
// `parametersJsonSchema` takes JSON Schema as is; `parameters` is Gemini's narrower OpenAPI subset.
|
|
38
|
+
_getDeclaration() {
|
|
39
|
+
return { name: this.name, description: this.description, parametersJsonSchema: this.spec.input_schema };
|
|
40
|
+
}
|
|
41
|
+
async runAsync({ args, toolContext }) {
|
|
42
|
+
const run = await this.ui.runTool(this.name, args, (this.opts.who ?? defaultWho)(toolContext), this.filter);
|
|
43
|
+
if (run.ok && run.silent) {
|
|
44
|
+
toolContext.actions.skipSummarization = true;
|
|
45
|
+
this.opts.onSilent?.(run.reason, toolContext);
|
|
46
|
+
} else if (run.ok) this.opts.onLink?.(run.link, toolContext);
|
|
47
|
+
return JSON.parse(run.content);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
WOKEN_TURN,
|
|
52
|
+
adkToolset
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { BaseTool, BaseToolset, type Context, type ReadonlyContext, type RunAsyncToolRequest } from \"@google/adk\";\nimport type { SurfaceLink, ToolSpec, UiCalling, Who } from \"@ui-calling/core\";\n\n/**\n * Pass as `stateDelta` on a turn a screen event started: `runner.runAsync({ userId, sessionId, newMessage, stateDelta: WOKEN_TURN })`.\n * The toolset then also offers `stay_silent`. A `temp:` key lasts only that turn, so the next user message never sees it.\n */\nexport const WOKEN_TURN = { \"temp:ui_calling_woken\": true } as const;\n\nexport type AdkAdapterOptions = {\n /**\n * Who the tools run for. Defaults to ADK's own session: `{ conversationId: ctx.sessionId, subject: ctx.userId }`,\n * so an event's `conversationId` and `subject` are the `sessionId` and `userId` to run the woken turn with.\n */\n who?: (ctx: ReadonlyContext) => Who;\n /** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */\n filter?: (toolName: string, ctx: ReadonlyContext) => boolean;\n /** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */\n onLink?: (link: SurfaceLink, ctx: Context) => void;\n /** Called when the model calls `stay_silent`. The turn ends there: send nothing for it, whatever text came before. */\n onSilent?: (reason: string, ctx: Context) => void;\n};\n\n/**\n * Surfaces as an ADK toolset. One agent serves every user: the tools read who they run for from the session.\n *\n * const agent = new LlmAgent({ name: \"shop\", model: \"gemini-3.5-flash-lite\", instruction,\n * tools: [adkToolset(ui, { onLink: (link, ctx) => links.get(ctx.sessionId)?.push(link) })] });\n */\nexport function adkToolset(ui: UiCalling, opts: AdkAdapterOptions = {}): BaseToolset {\n return new UiCallingToolset(ui, opts);\n}\n\nconst defaultWho = (ctx: ReadonlyContext): Who => ({ conversationId: ctx.sessionId, subject: ctx.userId });\n\nclass UiCallingToolset extends BaseToolset {\n constructor(\n private ui: UiCalling,\n private opts: AdkAdapterOptions,\n ) {\n super();\n }\n\n // Asked on every model call, so the list follows the turn: stay_silent only when woken, the filter per user.\n async getTools(ctx?: ReadonlyContext): Promise<BaseTool[]> {\n const woken = ctx?.state.get(Object.keys(WOKEN_TURN)[0]!) === true;\n const filter = ctx && this.opts.filter ? (name: string) => this.opts.filter!(name, ctx) : undefined;\n return this.ui.tools({ woken, filter }).map((spec) => new SurfaceTool(this.ui, spec, this.opts, filter));\n }\n\n async close() {}\n}\n\nclass SurfaceTool extends BaseTool {\n constructor(\n private ui: UiCalling,\n private spec: ToolSpec,\n private opts: AdkAdapterOptions,\n private filter?: (toolName: string) => boolean,\n ) {\n super({ name: spec.name, description: spec.description });\n }\n\n // `parametersJsonSchema` takes JSON Schema as is; `parameters` is Gemini's narrower OpenAPI subset.\n override _getDeclaration() {\n return { name: this.name, description: this.description, parametersJsonSchema: this.spec.input_schema };\n }\n\n async runAsync({ args, toolContext }: RunAsyncToolRequest) {\n const run = await this.ui.runTool(this.name, args, (this.opts.who ?? defaultWho)(toolContext), this.filter);\n if (run.ok && run.silent) {\n // End the turn here: no extra model call to hear it say nothing.\n toolContext.actions.skipSummarization = true;\n this.opts.onSilent?.(run.reason, toolContext);\n } else if (run.ok) this.opts.onLink?.(run.link, toolContext);\n // The model reads this object as the tool output; failures say why instead of throwing.\n return JSON.parse(run.content) as Record<string, unknown>;\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,mBAAiF;AAO7F,IAAM,aAAa,EAAE,yBAAyB,KAAK;AAsBnD,SAAS,WAAW,IAAe,OAA0B,CAAC,GAAgB;AACnF,SAAO,IAAI,iBAAiB,IAAI,IAAI;AACtC;AAEA,IAAM,aAAa,CAAC,SAA+B,EAAE,gBAAgB,IAAI,WAAW,SAAS,IAAI,OAAO;AAExG,IAAM,mBAAN,cAA+B,YAAY;AAAA,EACzC,YACU,IACA,MACR;AACA,UAAM;AAHE;AACA;AAAA,EAGV;AAAA,EAJU;AAAA,EACA;AAAA;AAAA,EAMV,MAAM,SAAS,KAA4C;AACzD,UAAM,QAAQ,KAAK,MAAM,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC,CAAE,MAAM;AAC9D,UAAM,SAAS,OAAO,KAAK,KAAK,SAAS,CAAC,SAAiB,KAAK,KAAK,OAAQ,MAAM,GAAG,IAAI;AAC1F,WAAO,KAAK,GAAG,MAAM,EAAE,OAAO,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,IAAI,YAAY,KAAK,IAAI,MAAM,KAAK,MAAM,MAAM,CAAC;AAAA,EACzG;AAAA,EAEA,MAAM,QAAQ;AAAA,EAAC;AACjB;AAEA,IAAM,cAAN,cAA0B,SAAS;AAAA,EACjC,YACU,IACA,MACA,MACA,QACR;AACA,UAAM,EAAE,MAAM,KAAK,MAAM,aAAa,KAAK,YAAY,CAAC;AALhD;AACA;AACA;AACA;AAAA,EAGV;AAAA,EANU;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAMD,kBAAkB;AACzB,WAAO,EAAE,MAAM,KAAK,MAAM,aAAa,KAAK,aAAa,sBAAsB,KAAK,KAAK,aAAa;AAAA,EACxG;AAAA,EAEA,MAAM,SAAS,EAAE,MAAM,YAAY,GAAwB;AACzD,UAAM,MAAM,MAAM,KAAK,GAAG,QAAQ,KAAK,MAAM,OAAO,KAAK,KAAK,OAAO,YAAY,WAAW,GAAG,KAAK,MAAM;AAC1G,QAAI,IAAI,MAAM,IAAI,QAAQ;AAExB,kBAAY,QAAQ,oBAAoB;AACxC,WAAK,KAAK,WAAW,IAAI,QAAQ,WAAW;AAAA,IAC9C,WAAW,IAAI,GAAI,MAAK,KAAK,SAAS,IAAI,MAAM,WAAW;AAE3D,WAAO,KAAK,MAAM,IAAI,OAAO;AAAA,EAC/B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui-calling/adk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-preview.1",
|
|
4
|
+
"description": "Use ui-calling surfaces as tools with Google's Agent Development Kit (ADK) for TypeScript.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/pausanchez/ui-calling.git",
|
|
9
|
+
"directory": "packages/adk"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/pausanchez/ui-calling#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/pausanchez/ui-calling/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ui-calling",
|
|
17
|
+
"adk",
|
|
18
|
+
"google",
|
|
19
|
+
"gemini",
|
|
20
|
+
"tools"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"ui-calling-source": "./src/index.ts",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup"
|
|
38
|
+
},
|
|
39
|
+
"tsup": {
|
|
40
|
+
"entry": {
|
|
41
|
+
"index": "src/index.ts"
|
|
42
|
+
},
|
|
43
|
+
"format": [
|
|
44
|
+
"esm"
|
|
45
|
+
],
|
|
46
|
+
"dts": true,
|
|
47
|
+
"clean": true,
|
|
48
|
+
"sourcemap": true,
|
|
49
|
+
"target": "es2022",
|
|
50
|
+
"removeNodeProtocol": false
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@ui-calling/core": "^0.1.0-preview.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@google/adk": ">=2.5.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@google/adk": "^2.5.0"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
64
|
+
}
|