@qwen-code/channel-msteams 0.0.0-stage → 0.28.1-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.
@@ -0,0 +1,90 @@
1
+ import { CloudAdapter } from '@microsoft/agents-hosting';
2
+ import { normalizeActivity, teamsServiceUrls, TeamsActivityError, } from './activity.js';
3
+ export const MAX_BODY_BYTES = 1024 * 1024;
4
+ class ResponseBuffer {
5
+ result = { status: 200, headers: {} };
6
+ headersSent = false;
7
+ writableEnded = false;
8
+ status(code) {
9
+ this.result.status = code;
10
+ return this;
11
+ }
12
+ setHeader(name, value) {
13
+ this.result.headers[name] = value;
14
+ return this;
15
+ }
16
+ send(body) {
17
+ this.result.body = body;
18
+ this.headersSent = true;
19
+ return this;
20
+ }
21
+ end() {
22
+ this.writableEnded = true;
23
+ return this;
24
+ }
25
+ }
26
+ export function createTeamsAdapter(config) {
27
+ if (!config.appId || !config.appPassword || !config.tenantId) {
28
+ throw new Error('Teams requires appId, appPassword, and tenantId.');
29
+ }
30
+ const adapter = new CloudAdapter({
31
+ // A flat SDK config is ignored when the host defines Connections__*.
32
+ connections: new Map([
33
+ [
34
+ 'serviceConnection',
35
+ {
36
+ clientId: config.appId,
37
+ clientSecret: config.appPassword,
38
+ tenantId: config.tenantId,
39
+ validateIssuer: true,
40
+ },
41
+ ],
42
+ ]),
43
+ connectionsMap: [{ serviceUrl: '*', connection: 'serviceConnection' }],
44
+ }, undefined, undefined, { validateServiceUrl: true }, teamsServiceUrls);
45
+ // The SDK default swallows turn errors, acknowledging failed durable acceptance.
46
+ adapter.onTurnError = async (_context, error) => {
47
+ throw error;
48
+ };
49
+ return adapter;
50
+ }
51
+ export async function handleTeamsWebhook(adapter, name, config, acceptInbound, input) {
52
+ if (Buffer.byteLength(JSON.stringify(input.body), 'utf8') > MAX_BODY_BYTES)
53
+ return { status: 413, headers: {} };
54
+ const request = {
55
+ method: 'POST',
56
+ headers: input.headers,
57
+ body: input.body,
58
+ };
59
+ const response = new ResponseBuffer();
60
+ let authorized = false;
61
+ try {
62
+ await adapter.authorizeRequest(request, response, (error) => {
63
+ if (error)
64
+ throw error;
65
+ authorized = true;
66
+ });
67
+ if (!authorized || !request.user)
68
+ return { ...response.result, status: 401 };
69
+ await adapter.process(request, response, async (context) => {
70
+ const event = normalizeActivity(name, config, context.activity);
71
+ if (event)
72
+ await acceptInbound(event);
73
+ });
74
+ return response.result;
75
+ }
76
+ catch (error) {
77
+ return {
78
+ status: error instanceof TeamsActivityError ? 400 : authorized ? 503 : 401,
79
+ headers: {},
80
+ };
81
+ }
82
+ }
83
+ export function createTeamsIngress(name, credentials, acceptInbound) {
84
+ const config = { ...credentials };
85
+ const adapter = createTeamsAdapter(config);
86
+ return {
87
+ handleWebhook: (input) => handleTeamsWebhook(adapter, name, config, acceptInbound, input),
88
+ };
89
+ }
90
+ //# sourceMappingURL=ingress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingress.js","sourceRoot":"","sources":["../src/ingress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AASvB,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,MAAM,cAAc;IAClB,MAAM,GAAyB,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC5D,WAAW,GAAG,KAAK,CAAC;IACpB,aAAa,GAAG,KAAK,CAAC;IACtB,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS,CAAC,IAAY,EAAE,KAAa;QACnC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAClC,O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EAAE;SACZ,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,WAA6B,EAC7B,aAA0D;IAE1D,MAAM,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO;QACL,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CACvB,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC;KAClE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { TeamsReferenceStore, TeamsTarget } from './types.js';
2
+ /** Atomic files for one process; shared hosts must supply their own durable store. */
3
+ export declare class FileTeamsReferenceStore implements TeamsReferenceStore {
4
+ private readonly directory;
5
+ constructor(directory: string);
6
+ private path;
7
+ get(key: string): Promise<TeamsTarget | undefined>;
8
+ set(key: string, target: TeamsTarget): Promise<void>;
9
+ }
@@ -0,0 +1,39 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ /** Atomic files for one process; shared hosts must supply their own durable store. */
5
+ export class FileTeamsReferenceStore {
6
+ directory;
7
+ constructor(directory) {
8
+ this.directory = directory;
9
+ }
10
+ path(key) {
11
+ return join(this.directory, `${createHash('sha256').update(key).digest('hex')}.json`);
12
+ }
13
+ async get(key) {
14
+ try {
15
+ return JSON.parse(await readFile(this.path(key), 'utf8'));
16
+ }
17
+ catch (error) {
18
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
19
+ return undefined;
20
+ throw error;
21
+ }
22
+ }
23
+ async set(key, target) {
24
+ await mkdir(this.directory, { recursive: true, mode: 0o700 });
25
+ const path = this.path(key);
26
+ const temporary = `${path}.${randomUUID()}.tmp`;
27
+ try {
28
+ await writeFile(temporary, JSON.stringify(target), {
29
+ mode: 0o600,
30
+ flag: 'wx',
31
+ });
32
+ await rename(temporary, path);
33
+ }
34
+ finally {
35
+ await rm(temporary, { force: true });
36
+ }
37
+ }
38
+ }
39
+ //# sourceMappingURL=reference-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-store.js","sourceRoot":"","sources":["../src/reference-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,sFAAsF;AACtF,MAAM,OAAO,uBAAuB;IACL;IAA7B,YAA6B,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAE1C,IAAI,CAAC,GAAW;QACtB,OAAO,IAAI,CACT,IAAI,CAAC,SAAS,EACd,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CACzD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAgB,CAAC;QAC3E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;gBACtE,OAAO,SAAS,CAAC;YACnB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAmB;QACxC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,UAAU,EAAE,MAAM,CAAC;QAChD,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;gBACjD,IAAI,EAAE,KAAK;gBACX,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,80 @@
1
+ import type { ConversationReference } from '@microsoft/agents-activity';
2
+ import type { ChannelBaseOptions, ChannelConfig, Envelope } from '@qwen-code/channel-base';
3
+ export interface TeamsCredentials {
4
+ appId: string;
5
+ appPassword: string;
6
+ tenantId: string;
7
+ }
8
+ export interface TeamsConfig extends ChannelConfig, TeamsCredentials {
9
+ webhookPort?: number;
10
+ webhookPath?: string;
11
+ }
12
+ export interface TeamsTarget {
13
+ readonly chatId: string;
14
+ readonly threadId?: string;
15
+ readonly reference: ConversationReference;
16
+ }
17
+ export interface TeamsInboundEvent {
18
+ readonly version: 1;
19
+ readonly eventId: string;
20
+ readonly activityId: string;
21
+ readonly tenantId: string;
22
+ readonly actorId: string;
23
+ readonly envelope: Readonly<Envelope>;
24
+ readonly target: TeamsTarget;
25
+ }
26
+ export interface TeamsReferenceStore {
27
+ get(key: string): Promise<TeamsTarget | undefined>;
28
+ set(key: string, target: TeamsTarget): Promise<void>;
29
+ }
30
+ export interface TeamsSendContext {
31
+ readonly event?: TeamsInboundEvent;
32
+ readonly target: TeamsTarget;
33
+ readonly kind: 'response' | 'system';
34
+ readonly text: string;
35
+ readonly fullText: string;
36
+ readonly chunkIndex: number;
37
+ readonly chunkCount: number;
38
+ }
39
+ export type TeamsSendReceipt = TeamsSendContext & ({
40
+ readonly state: 'sent';
41
+ readonly platformMessageId: string;
42
+ } | {
43
+ readonly state: 'known_failed' | 'unknown';
44
+ });
45
+ export type TeamsPromptOutcome = {
46
+ readonly status: 'completed';
47
+ readonly resultText: string;
48
+ } | {
49
+ readonly status: 'failed';
50
+ readonly error: unknown;
51
+ };
52
+ export interface TeamsHost {
53
+ /** Persist or consume the verified event before resolving. Never wait for a prompt. */
54
+ acceptInbound(event: TeamsInboundEvent): Promise<void>;
55
+ /** Await authorization and durable submitting state immediately before bridge.prompt. */
56
+ beforePrompt(event: TeamsInboundEvent, sessionId: string): Promise<void>;
57
+ /** Bridge completion, separate from platform delivery. Never replay an uncertain submission. */
58
+ onPromptSettled(event: TeamsInboundEvent, sessionId: string, outcome: TeamsPromptOutcome): Promise<void>;
59
+ /** Revalidate authorization and persist send intent. Throw to prevent this send. */
60
+ beforeSend(context: TeamsSendContext): Promise<void>;
61
+ /** Persist the actual receipt before resolving. A failure leaves delivery unknown. */
62
+ onSendReceipt(receipt: TeamsSendReceipt): Promise<void>;
63
+ }
64
+ export interface TeamsChannelOptions extends ChannelBaseOptions {
65
+ /** Supplying a host disables the plugin-owned HTTP listener. */
66
+ host?: TeamsHost;
67
+ referenceStore?: TeamsReferenceStore;
68
+ }
69
+ export interface TeamsWebhookRequest {
70
+ headers: Record<string, string | string[] | undefined>;
71
+ body: Record<string, unknown>;
72
+ }
73
+ export interface TeamsWebhookResponse {
74
+ status: number;
75
+ headers: Record<string, string>;
76
+ body?: unknown;
77
+ }
78
+ export interface TeamsIngress {
79
+ handleWebhook(input: TeamsWebhookRequest): Promise<TeamsWebhookResponse>;
80
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@qwen-code/channel-msteams",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.28.1-preview.1",
4
+ "description": "Microsoft Teams channel adapter for Qwen Code",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/QwenLM/qwen-code.git",
8
+ "directory": "packages/channels/msteams"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "type": "module",
12
+ "engines": {
13
+ "node": ">=22.12.0"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "qwen-extension.json",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "dependencies": {
30
+ "@microsoft/agents-hosting": "1.9.1",
31
+ "@microsoft/agents-activity": "1.9.1"
32
+ },
33
+ "devDependencies": {
34
+ "typescript": "^5.0.0",
35
+ "@qwen-code/channel-base": "0.28.1-preview.1"
36
+ },
37
+ "peerDependencies": {
38
+ "@qwen-code/channel-base": "0.23.0 || 0.28.1-preview.1"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc --build",
42
+ "test": "vitest run",
43
+ "test:ci": "vitest run"
44
+ }
6
45
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "qwen-channel-msteams",
3
+ "version": "0.28.1-preview.1",
4
+ "channels": {
5
+ "msteams": {
6
+ "entry": "dist/index.js",
7
+ "displayName": "Microsoft Teams"
8
+ }
9
+ }
10
+ }